Skip to content

Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit

fix(rebuild): let Steam rerun install scripts whose files the rebuild drops

raymondchins7796513bab71
diff --git a/app/Sources/NotProtonApp/Model/InstallScriptMarkers.swift b/app/Sources/NotProtonApp/Model/InstallScriptMarkers.swift
new file mode 100644
index 0000000..d502e4f
--- /dev/null
+++ b/app/Sources/NotProtonApp/Model/InstallScriptMarkers.swift
@@ -0,0 +1,100 @@
+// Steam runs a game's installscript.vdf "Run Process" entries (redistributables such as
+// the PlayStation PC SDK) only while the entry's HasRunKey value is missing. A rebuild
+// carries user.reg into a fresh prefix but none of what those installers put in
+// drive_c, so a carried HKCU marker would make Steam skip an installer whose files are
+// gone. Dropping the marker makes Steam run it again on the next launch.
+
+import Foundation
+
+enum InstallScriptMarkers {
+
+ struct Marker: Equatable {
+ let key: String
+ let value: String
+ }
+
+ // "Run Process" entries whose HasRunKey lives in HKEY_CURRENT_USER, with the key
+ // given relative to it, as user.reg names it.
+ static func markers(inScript text: String) -> [Marker] {
+ var markers: [Marker] = []
+ var path: [String] = []
+ var pending: String?
+ for raw in text.split(separator: "\n", omittingEmptySubsequences: true) {
+ let line = raw.trimmingCharacters(in: .whitespaces)
+ if line == "{" {
+ if let name = pending { path.append(name) }
+ pending = nil
+ continue
+ }
+ if line == "}" {
+ if !path.isEmpty { path.removeLast() }
+ pending = nil
+ continue
+ }
+ let fields = quoted(line)
+ if fields.count == 1 {
+ pending = fields[0]
+ } else if fields.count >= 2, fields[0].caseInsensitiveCompare("HasRunKey") == .orderedSame,
+ path.count >= 3, path[path.count - 2].caseInsensitiveCompare("Run Process") == .orderedSame
+ {
+ let key = fields[1].replacingOccurrences(of: "\\\\", with: "\\")
+ let hive = "HKEY_CURRENT_USER\\"
+ guard key.uppercased().hasPrefix(hive) else { continue }
+ markers.append(Marker(key: String(key.dropFirst(hive.count)), value: path[path.count - 1]))
+ }
+ }
+ return markers
+ }
+
+ // Returns the markers removed from the registry text.
+ static func clear(_ markers: [Marker], in registry: String) -> (text: String, removed: [Marker]) {
+ guard !markers.isEmpty else { return (registry, []) }
+ var removed: [Marker] = []
+ var section: String?
+ var out: [Substring] = []
+ for line in registry.split(separator: "\n", omittingEmptySubsequences: false) {
+ if line.hasPrefix("[") {
+ section = line.dropFirst().split(separator: "]", maxSplits: 1).first
+ .map { $0.replacingOccurrences(of: "\\\\", with: "\\") }
+ } else if let section, line.hasPrefix("\""),
+ let hit = markers.first(where: {
+ $0.key.caseInsensitiveCompare(section) == .orderedSame
+ && line.hasPrefix("\"\(escaped($0.value))\"=")
+ })
+ {
+ removed.append(hit)
+ continue
+ }
+ out.append(line)
+ }
+ return (out.joined(separator: "\n"), removed)
+ }
+
+ // Clears the markers of the app's install script from userReg. Returns the names of
+ // the entries Steam will run again.
+ @discardableResult
+ static func clear(userReg: URL, installDirectory: URL?) -> [String] {
+ guard let installDirectory,
+ let script = try? String(
+ contentsOf: installDirectory.appending(path: "installscript.vdf"), encoding: .utf8),
+ let registry = try? String(contentsOf: userReg, encoding: .utf8)
+ else { return [] }
+ let result = clear(markers(inScript: script), in: registry)
+ guard !result.removed.isEmpty else { return [] }
+ do {
+ try Data(result.text.utf8).write(to: userReg, options: .atomic)
+ } catch {
+ return []
+ }
+ return result.removed.map(\.value)
+ }
+
+ private static func quoted(_ line: String) -> [String] {
+ line.split(separator: "\"", omittingEmptySubsequences: false).enumerated()
+ .filter { $0.offset % 2 == 1 }.map { String($0.element) }
+ }
+
+ private static func escaped(_ name: String) -> String {
+ name.replacingOccurrences(of: "\\", with: "\\\\").replacingOccurrences(of: "\"", with: "\\\"")
+ }
+}
diff --git a/app/Sources/NotProtonApp/Model/PrefixRebuild.swift b/app/Sources/NotProtonApp/Model/PrefixRebuild.swift
index 6dba9a2..082bc76 100644
--- a/app/Sources/NotProtonApp/Model/PrefixRebuild.swift
+++ b/app/Sources/NotProtonApp/Model/PrefixRebuild.swift
@@ -82,6 +82,13 @@ extension PrefixTools {
)
}
+ let rerun = InstallScriptMarkers.clear(
+ userReg: fresh.appending(path: "user.reg"),
+ installDirectory: PrefixStore.installDirectory(of: prefix))
+ if !rerun.isEmpty {
+ AppLog.note("rebuild \(prefix.appID) Steam will rerun: \(rerun.joined(separator: ", "))")
+ }
+
let parked = fm.fileExists(atPath: prefix.pfx.path(percentEncoded: false))
let previous = backupSlot(in: prefix.root, at: now)
if parked {
diff --git a/app/Tests/NotProtonAppTests/InstallScriptMarkersTests.swift b/app/Tests/NotProtonAppTests/InstallScriptMarkersTests.swift
new file mode 100644
index 0000000..24f3a03
--- /dev/null
+++ b/app/Tests/NotProtonAppTests/InstallScriptMarkersTests.swift
@@ -0,0 +1,82 @@
+import Foundation
+import Testing
+
+@testable import NotProtonApp
+
+@Suite("Install script markers")
+struct InstallScriptMarkersTests {
+
+ // Marvel's Spider-Man 2's installscript.vdf, which put the PlayStation PC SDK in
+ // drive_c and recorded it in HKCU.
+ private static let script = """
+ "InstallScript"
+ {
+ \t"Run Process"
+ \t{
+ \t\t"PlayStation SDK 3.50"
+ \t\t{
+ \t\t\t"HasRunKey"\t\t"HKEY_CURRENT_USER\\\\SOFTWARE\\\\Insomniac Games\\\\Marvel's Spider-Man 2"
+ \t\t\t"Process 1"\t\t"%INSTALLDIR%\\\\install_pspc_sdk_runtime.bat"
+ \t\t}
+ \t\t"Machine Wide"
+ \t\t{
+ \t\t\t"HasRunKey"\t\t"HKEY_LOCAL_MACHINE\\\\Software\\\\Example"
+ \t\t}
+ \t}
+ \t"Firewall"
+ \t{
+ \t\t"Marvel's Spider-Man 2"\t\t"%INSTALLDIR%\\\\Spider-Man2.exe"
+ \t}
+ }
+ "kvsignatures"
+ {
+ \t"InstallScript"\t\t"87acaad9"
+ }
+ """
+
+ private static let registry = """
+ WINE REGISTRY Version 2
+
+ [Software\\\\Insomniac Games\\\\Marvel's Spider-Man 2] 1791694571
+ #time=1dd593cd5fa8332
+ "FirstRun"=dword:00000000
+ "PlayStation SDK 3.50"=dword:00000001
+ "ShowLauncher"=dword:00000000
+
+ [Software\\\\Other] 1791694571
+ "PlayStation SDK 3.50"=dword:00000001
+
+ """
+
+ @Test("Only HKCU Run Process markers are read, keyed as user.reg names them")
+ func readsMarkers() {
+ #expect(InstallScriptMarkers.markers(inScript: Self.script) == [
+ .init(key: "SOFTWARE\\Insomniac Games\\Marvel's Spider-Man 2", value: "PlayStation SDK 3.50")
+ ])
+ }
+
+ @Test("The marker goes and the game's other settings and keys stay")
+ func clearsOnlyTheMarker() {
+ let result = InstallScriptMarkers.clear(
+ InstallScriptMarkers.markers(inScript: Self.script), in: Self.registry)
+ #expect(result.removed.map(\.value) == ["PlayStation SDK 3.50"])
+ #expect(!result.text.contains("Spider-Man 2] 1791694571\n#time=1dd593cd5fa8332\n\"FirstRun\"=dword:00000000\n\"PlayStation"))
+ #expect(result.text.contains("\"FirstRun\"=dword:00000000\n\"ShowLauncher\"=dword:00000000"))
+ #expect(result.text.contains("[Software\\\\Other] 1791694571\n\"PlayStation SDK 3.50\"=dword:00000001"))
+ }
+
+ @Test("A game without an install script leaves user.reg untouched")
+ func noScript() throws {
+ let dir = FileManager.default.temporaryDirectory.appending(path: UUID().uuidString)
+ try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
+ defer { try? FileManager.default.removeItem(at: dir) }
+ let reg = dir.appending(path: "user.reg")
+ try Data(Self.registry.utf8).write(to: reg)
+ #expect(InstallScriptMarkers.clear(userReg: reg, installDirectory: dir).isEmpty)
+ #expect(try String(contentsOf: reg, encoding: .utf8) == Self.registry)
+
+ try Data(Self.script.utf8).write(to: dir.appending(path: "installscript.vdf"))
+ #expect(InstallScriptMarkers.clear(userReg: reg, installDirectory: dir) == ["PlayStation SDK 3.50"])
+ #expect(try !String(contentsOf: reg, encoding: .utf8).contains("Spider-Man 2] 1791694571\n#time=1dd593cd5fa8332\n\"FirstRun\"=dword:00000000\n\"PlayStation"))
+ }
+}