Skip to content

Commit

Permalink
starvalve: skip update command
Browse files Browse the repository at this point in the history
  • Loading branch information
yretenai committed Dec 23, 2024
1 parent 4ca291e commit 2e63146
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 7 deletions.
6 changes: 3 additions & 3 deletions Sources/Starvalve/ApplicationContentFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ public struct ACFAppState: OptionSet, Sendable, Hashable, CustomStringConvertibl

/// Whether or not an update recently succeeded.
public enum ACFUpdateResult: UInt, CustomStringConvertible {
case failure
case success
case failure

/// a textual representation of this enum.
public var description: String {
switch self {
case .failure: "success"
case .success: "failure"
case .success: "success"
case .failure: "failure"
}
}
}
Expand Down
17 changes: 14 additions & 3 deletions Sources/StarvalveControl/Commands/ListAppsCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ struct ListAppsCommand: ParsableCommand {
@Flag(help: "Print detailed app information")
var detailed: Bool = false

@Argument(help: "App ids to process")
var appIds: [UInt] = []

@OptionGroup var globals: GlobalOptions

func run() {
Expand All @@ -29,11 +32,19 @@ struct ListAppsCommand: ParsableCommand {
for library in libraries.entries {
var knownPaths: Set<URL> = []

for (appId, appSize) in library.apps.sorted(by: { left, right in
var appIds = library.apps.sorted(by: { left, right in
left.value > right.value
}) {
})

if !self.appIds.isEmpty {
appIds = appIds.filter({ item in
self.appIds.contains(item.key)
})
}

for (appId, appSize) in appIds {
guard let appInfo = AppInfo(libraryPath: library.path, appId: appId) else {
print("app \(appId, color: .magenta)")
print("⚠️ app \(appId, color: .magenta) has a missing manifest")
continue
}

Expand Down
68 changes: 68 additions & 0 deletions Sources/StarvalveControl/Commands/SkipUpdateCommand.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// SPDX-FileCopyrightText: 2024 Legiayayana <[email protected]>
// SPDX-License-Identifier: EUPL-1.2

import ArgumentParser
import Foundation
import Starvalve

struct SkipUpdateCommand: ParsableCommand {
static let configuration = CommandConfiguration(
commandName: "skip",
abstract: "Skips updates for steam apps"
)

@Argument(help: "App ids to process")
var appIds: [UInt]

@OptionGroup var globals: GlobalOptions

func run() {
let steam = SteamHelper(steamPath: globals.steamPath)

guard let libraries = steam.libraryFolders else {
print("⚠️ Steam libraries failed to parse.")
return
}

for library in libraries.entries {
var appIds = library.apps.sorted(by: { left, right in
left.value > right.value
})

appIds = appIds.filter({ item in
self.appIds.contains(item.key)
})

for (appId, _) in appIds {
guard let appInfo = AppInfo(libraryPath: library.path, appId: appId) else {
print("⚠️ app \(appId, color: .magenta) has a missing manifest")
continue
}

var acf = appInfo.acf
guard acf.stateFlags.contains(.updateRequired) || acf.stateFlags.contains(.updateOptional) else {
print("app \(acf.name, color: .green) (\(appId, color: .magenta)) does not need to be updated")
continue
}

acf.stateFlags = [.fullyInstalled]
acf.scheduledAutoUpdate = Date(timeIntervalSince1970: 0)
acf.buildID = acf.targetBuildID
acf.targetBuildID = 0
acf.bytesToDownload = 0
acf.bytesDownloaded = 0
acf.bytesToStage = 0
acf.bytesStaged = 0
acf.stagingSize = 0
acf.updateResult = .success

guard (try? TextVDF.write(url: appInfo.acfPath, vdf: acf.vdf())) != nil else {
print("⚠️ could not write file for appmanifest \(acf.name)")
continue
}

print("app \(acf.name, color: .green) (\(appId, color: .magenta)) has update state reset")
}
}
}
}
3 changes: 2 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ SPDX-License-Identifier: EUPL-1.2
- [ ] `uninstall [appid...]` command (uninstall a game without running uninstall scripts)
- [ ] `args <appid> <args>` command (edit game launch arguments)
- [ ] `move <appid> <library>` command (move game from one library to another)
- [x] `list` command (list installed games)
- [ ] `skip <appid>` command (cancel steam update)
- [x] `list <appid...>` command (list installed games)
- [x] `library list` command (list libraries)
- [x] `library label <library> <label>` command (set library label)
- [x] `library purge <library>` command (delete an entire library)
Expand Down

0 comments on commit 2e63146

Please sign in to comment.