Skip to content

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

Keep escaped quotes in names read from appmanifest

Alex0007f478d895511b
diff --git a/app/Sources/NotProtonApp/Model/PrefixStore.swift b/app/Sources/NotProtonApp/Model/PrefixStore.swift
index 2c8f4c5..5cd36e4 100644
--- a/app/Sources/NotProtonApp/Model/PrefixStore.swift
+++ b/app/Sources/NotProtonApp/Model/PrefixStore.swift
@@ -225,8 +225,18 @@ enum PrefixStore {
let manifest = library.steamapps.appending(path: "appmanifest_\(appID).acf")
guard let text = try? String(contentsOf: manifest, encoding: .utf8) else { return nil }
for line in text.split(separator: "\n") {
- let fields = line.split(separator: "\"").map(String.init)
- .filter { !$0.trimmingCharacters(in: .whitespaces).isEmpty }
+ // Steam escapes \" \\ \n and \t inside quoted values.
+ let fields = line.matches(of: #/"((?:[^"\\]|\\.)*)"/#)
+ .map {
+ String($0.1).replacing(#/\\(.)/#) { escape -> String in
+ switch escape.1 {
+ case "n": "\n"
+ case "t": "\t"
+ case "\\", "\"": String(escape.1)
+ default: String(escape.0)
+ }
+ }
+ }
if fields.count >= 2, fields[0] == key { return fields[1] }
}
return nil
diff --git a/app/Tests/NotProtonAppTests/PrefixStoreTests.swift b/app/Tests/NotProtonAppTests/PrefixStoreTests.swift
index 895bb66..93344ab 100644
--- a/app/Tests/NotProtonAppTests/PrefixStoreTests.swift
+++ b/app/Tests/NotProtonAppTests/PrefixStoreTests.swift
@@ -114,6 +114,49 @@ struct PrefixStoreTests {
#expect(orphan?.title == "App 1649240")
}
+ @Test("A quote inside the name survives the manifest's escaping")
+ func readsAnEscapedAppName() throws {
+ let dir = try scratchDirectory("pfx")
+ defer { try? FileManager.default.removeItem(at: dir) }
+ let library = SteamLibrary(root: dir)
+
+ try FileManager.default.createDirectory(
+ at: library.compatdata.appending(path: "5102100/pfx"), withIntermediateDirectories: true)
+ try write(
+ """
+ "AppState"
+ {
+ \t"appid"\t\t"5102100"
+ \t"name"\t\t"Rideshare \\"Stimulator\\" Demo"
+ \t"installdir"\t\t"RideshareStimulatorDemo"
+ }
+ """, to: library.steamapps.appending(path: "appmanifest_5102100.acf"))
+
+ let prefix = PrefixStore.all(libraries: [library]).first { $0.appID == "5102100" }
+ #expect(prefix?.name == "Rideshare \"Stimulator\" Demo")
+ }
+
+ @Test("Newline, tab and backslash escapes in the name are decoded")
+ func decodesManifestEscapes() throws {
+ let dir = try scratchDirectory("pfx")
+ defer { try? FileManager.default.removeItem(at: dir) }
+ let library = SteamLibrary(root: dir)
+
+ try FileManager.default.createDirectory(
+ at: library.compatdata.appending(path: "5102101/pfx"), withIntermediateDirectories: true)
+ try write(
+ """
+ "AppState"
+ {
+ \t"appid"\t\t"5102101"
+ \t"name"\t\t"One\\nTwo\\tThree\\\\Four\\qFive"
+ }
+ """, to: library.steamapps.appending(path: "appmanifest_5102101.acf"))
+
+ let prefix = PrefixStore.all(libraries: [library]).first { $0.appID == "5102101" }
+ #expect(prefix?.name == "One\nTwo\tThree\\Four\\qFive")
+ }
+
@Test("A non-Steam shortcut prefix is named from shortcuts.vdf")
func readsTheShortcutName() throws {
let dir = try scratchDirectory("pfx")