Skip to content

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

fix(engine): say which check failed for a bundled WineCX file (#1429)

Raymond Chin4fb952416326
diff --git a/app/Sources/BridgeplayApp/Model/FreeEngineWinecx.swift b/app/Sources/BridgeplayApp/Model/FreeEngineWinecx.swift
index b499a35..5a3947b 100644
--- a/app/Sources/BridgeplayApp/Model/FreeEngineWinecx.swift
+++ b/app/Sources/BridgeplayApp/Model/FreeEngineWinecx.swift
@@ -558,14 +558,10 @@ enum FreeEngineWinecx {
}
// Puts each bundled file, checked against its pin, over or beside the engine's own.
- static func installBundled(_ files: [WinecxBundledFile], root: URL) throws {
+ static func installBundled(_ files: [WinecxBundledFile], root: URL, bundle: Bundle = .module) throws {
let fm = FileManager.default
for file in files {
- guard let source = Bundle.module.url(forResource: file.resource, withExtension: file.ext),
- Digest.sha256IfPresent(source) == file.sha256
- else {
- throw StepFailure(step: step, detail: "Bridgeplay is missing its \(file.resource).\(file.ext).")
- }
+ let source = try bundledSource(file, in: bundle)
let destination = root.appending(path: file.path)
try fm.createDirectory(at: destination.deletingLastPathComponent(), withIntermediateDirectories: true)
try? fm.removeItem(at: destination)
@@ -573,6 +569,29 @@ enum FreeEngineWinecx {
}
}
+ // The app's copy of a bundled file. Each failure says which check failed (#1295 could
+ // not tell a missing file from a damaged one), and the log gets the path and hashes.
+ static func bundledSource(_ file: WinecxBundledFile, in bundle: Bundle = .module) throws -> URL {
+ let name = "\(file.resource).\(file.ext)"
+ guard let source = bundle.url(forResource: file.resource, withExtension: file.ext) else {
+ AppLog.note("bundled file: \(name) not found in \(bundle.bundleURL.path(percentEncoded: false))")
+ throw StepFailure(step: step, detail: "Bridgeplay is missing its \(name). Reinstall Bridgeplay.")
+ }
+ let path = source.path(percentEncoded: false)
+ let actual: String
+ do {
+ actual = try Digest.sha256(of: source)
+ } catch {
+ AppLog.note("bundled file: \(name) at \(path) can't be read: \(error.localizedDescription)")
+ throw StepFailure(step: step, detail: "Bridgeplay can't read its \(name). Reinstall Bridgeplay.")
+ }
+ guard actual == file.sha256 else {
+ AppLog.note("bundled file: \(name) at \(path) has sha256 \(actual), expected \(file.sha256)")
+ throw StepFailure(step: step, detail: "Bridgeplay's \(name) doesn't match its pinned checksum. Reinstall Bridgeplay.")
+ }
+ return source
+ }
+
private static func untar(_ archive: URL, into directory: URL) throws {
let result = try Shell.run("/usr/bin/tar", [
"-xf", archive.path(percentEncoded: false), "-C", directory.path(percentEncoded: false),
diff --git a/app/Tests/BridgeplayAppTests/FreeEngineWinecxTests.swift b/app/Tests/BridgeplayAppTests/FreeEngineWinecxTests.swift
index 48d6be0..732aa67 100644
--- a/app/Tests/BridgeplayAppTests/FreeEngineWinecxTests.swift
+++ b/app/Tests/BridgeplayAppTests/FreeEngineWinecxTests.swift
@@ -741,4 +741,43 @@ struct FreeEngineWinecxTests {
}
return lines.sorted()
}
+
+ // #1295: setup said "missing" for a file that could also be unreadable or changed.
+ @Test("A bundled file that is missing, unreadable or changed says which check failed")
+ func bundledSourceFailures() throws {
+ let dir = try makeDirectory("bundled")
+ defer { try? FileManager.default.removeItem(at: dir) }
+ let content = Data("pinned bundled file".utf8)
+ let fixture = dir.appending(path: "fixture.dll")
+ try content.write(to: fixture)
+ let bundle = try #require(Bundle(url: dir))
+ let pin = Digest.sha256(of: content)
+
+ func file(_ resource: String, _ sha256: String) -> WinecxBundledFile {
+ WinecxBundledFile(resource: resource, ext: "dll", path: "lib/wine/x86_64-windows/\(resource).dll",
+ sha256: sha256)
+ }
+ func detail(_ file: WinecxBundledFile) -> String? {
+ do {
+ _ = try FreeEngineWinecx.bundledSource(file, in: bundle)
+ return nil
+ } catch {
+ return (error as? StepFailure)?.detail
+ }
+ }
+
+ #expect(try FreeEngineWinecx.bundledSource(file("fixture", pin), in: bundle).lastPathComponent == "fixture.dll")
+ #expect(detail(file("absent", pin))?.contains("missing its absent.dll") == true)
+ #expect(detail(file("fixture", String(repeating: "0", count: 64)))?.contains("doesn't match") == true)
+
+ let root = try makeDirectory("bundled-root")
+ defer { try? FileManager.default.removeItem(at: root) }
+ try FreeEngineWinecx.installBundled([file("fixture", pin)], root: root, bundle: bundle)
+ #expect(Digest.sha256IfPresent(root.appending(path: "lib/wine/x86_64-windows/fixture.dll")) == pin)
+
+ let path = fixture.path(percentEncoded: false)
+ try FileManager.default.setAttributes([.posixPermissions: 0], ofItemAtPath: path)
+ defer { try? FileManager.default.setAttributes([.posixPermissions: 0o644], ofItemAtPath: path) }
+ #expect(detail(file("fixture", pin))?.contains("can't read") == true)
+ }
}