Skip to content

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

Add Winetricks to the prefix Tools menu

Logandb7315c3cf33
diff --git a/app/Sources/NotProtonApp/Model/PrefixTools.swift b/app/Sources/NotProtonApp/Model/PrefixTools.swift
index 7969955..83f516a 100644
--- a/app/Sources/NotProtonApp/Model/PrefixTools.swift
+++ b/app/Sources/NotProtonApp/Model/PrefixTools.swift
@@ -246,6 +246,70 @@ enum PrefixTools {
)
}
+ // Winetricks is LGPL, so it is downloaded rather than shipped.
+ static let winetricksRelease = "20260125"
+ static let winetricksSHA256 = "431f82fc74000e6c864409f1d8fb495d696c03928808e3e8acffc45179312a7b"
+ static let winetricksLogName = "winetricks.log"
+
+ static func winetricksVerbs(_ text: String) -> [String] {
+ text.split(whereSeparator: \.isWhitespace).map(String.init)
+ }
+
+ static func winetricks(_ verbs: [String], in prefix: WinePrefix) async throws -> URL {
+ let step = String(localized: "Run Winetricks")
+ let chosen = try resolvedTool(step: step, for: prefix)
+ let script = try await PinnedDownload.obtain(
+ file: "winetricks",
+ sha256: winetricksSHA256,
+ bases: [URL(string: "https://raw.githubusercontent.com/Winetricks/winetricks/\(winetricksRelease)/src")!],
+ into: SupportPaths.winetricksDownloads,
+ step: step,
+ from: "GitHub"
+ )
+ return try winetricks(
+ verbs, in: prefix, script: script,
+ runner: SupportPaths.clonedRoot(forBuild: chosen.build), flavor: chosen.tool.flavor
+ )
+ }
+
+ static func winetricks(
+ _ verbs: [String], in prefix: WinePrefix, script: URL, runner: URL,
+ flavor: CompatTool.Flavor = .fex
+ ) throws -> URL {
+ let step = String(localized: "Run Winetricks")
+ guard !verbs.isEmpty else {
+ throw StepFailure(step: step, detail: String(localized: "Enter at least one verb, like vcrun2022."))
+ }
+ // Under -q annihilate wipes the prefix and its saves without asking, prefix= switches to
+ // another prefix, and options like --self-update change winetricks itself.
+ if let refused = verbs.first(where: { $0 == "annihilate" || $0.hasPrefix("prefix=") || $0.hasPrefix("-") }) {
+ throw StepFailure(step: step, detail: String(localized: "NotProton does not run \(refused) with Winetricks."))
+ }
+ guard !PrefixStore.isInUse(prefix) else {
+ throw StepFailure(step: step, detail: String(localized: "\(prefix.title) is running. Quit the game first."))
+ }
+ let loader = try readyLoader(step: step, prefix: prefix, runner: runner, flavor: flavor)
+
+ // cabextract comes from the runner's bin, which environment() puts on PATH.
+ var environment = environment(prefix: prefix, runner: runner, flavor: flavor)
+ environment["WINE"] = loader.path(percentEncoded: false)
+
+ let log = prefix.root.appending(path: winetricksLogName)
+ let status = try Shell.logged(
+ "/bin/sh", [script.path(percentEncoded: false), "-q"] + verbs,
+ environment: environment, to: log
+ )
+ // Until the wineserver exits, the prefix still counts as in use.
+ _ = try? Shell.run(layout(runner: runner, flavor: flavor).server.path(percentEncoded: false), ["-w"], environment: environment)
+ guard status == 0 else {
+ throw StepFailure(
+ step: step,
+ detail: String(localized: "Winetricks stopped with status \(status). Its output is in \(log.path(percentEncoded: false)).")
+ )
+ }
+ return log
+ }
+
static func arguments(for executable: URL) -> [String]? {
let path = executable.path(percentEncoded: false)
switch executable.pathExtension.lowercased() {
diff --git a/app/Sources/NotProtonApp/PrefixesModel.swift b/app/Sources/NotProtonApp/PrefixesModel.swift
index f53ae7c..2509465 100644
--- a/app/Sources/NotProtonApp/PrefixesModel.swift
+++ b/app/Sources/NotProtonApp/PrefixesModel.swift
@@ -243,7 +243,7 @@ final class PrefixesModel {
@discardableResult
private func eachInTurn<Made: Sendable>(
_ targets: [WinePrefix],
- _ work: @escaping @Sendable (WinePrefix) throws -> Made,
+ _ work: @escaping @Sendable (WinePrefix) async throws -> Made,
saying sentence: ([Step<Made>]) -> String?
) async -> [Step<Made>] {
guard !targets.isEmpty else { return [] }
@@ -255,7 +255,7 @@ final class PrefixesModel {
var refused: [Error] = []
for prefix in targets {
do {
- let made = try await Task.detached { try work(prefix) }.value
+ let made = try await Task.detached { try await work(prefix) }.value
done.append((prefix: prefix, made: made))
} catch {
refused.append(error)
@@ -295,6 +295,14 @@ final class PrefixesModel {
}
}
+ func winetricks(_ text: String, in prefix: WinePrefix) async {
+ let verbs = PrefixTools.winetricksVerbs(text)
+ await eachInTurn([prefix], { try await PrefixTools.winetricks(verbs, in: $0) }) { done in
+ guard !done.isEmpty else { return nil }
+ return String(localized: "Winetricks ran \(verbs.joined(separator: " ")) in \(prefix.title).")
+ }
+ }
+
private func act(on prefix: WinePrefix, _ body: () throws -> String) {
forgetOutcome()
busy = [prefix.id]
diff --git a/app/Sources/NotProtonApp/Resources/Localization/Localizable.xcstrings b/app/Sources/NotProtonApp/Resources/Localization/Localizable.xcstrings
index a1c0785..5cf3349 100644
--- a/app/Sources/NotProtonApp/Resources/Localization/Localizable.xcstrings
+++ b/app/Sources/NotProtonApp/Resources/Localization/Localizable.xcstrings
@@ -1645,6 +1645,26 @@
}
}
},
+ "Enter at least one verb, like vcrun2022." : {
+ "localizations" : {
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "请至少输入一个组件,例如 vcrun2022。"
+ }
+ }
+ }
+ },
+ "Enter the Winetricks verbs to install in %@, separated by spaces." : {
+ "localizations" : {
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "输入要安装到“%@”中的 Winetricks 组件,用空格分隔。"
+ }
+ }
+ }
+ },
"Extracting" : {
"localizations" : {
"zh-Hans" : {
@@ -2178,22 +2198,32 @@
}
}
},
- "NotProton could not download the files it needs from Valve. Please try again later." : {
+ "NotProton could not download the files it needs from %@. Please try again later." : {
"localizations" : {
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
- "value" : "NotProton 无法从 Valve 下载所需文件。请稍后重试。"
+ "value" : "NotProton 无法从 %@ 下载所需文件。请稍后重试。"
}
}
}
},
- "NotProton could not reach Valve's servers. Please check your internet connection and try again." : {
+ "NotProton could not reach %@'s servers. Please check your internet connection and try again." : {
"localizations" : {
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
- "value" : "NotProton 无法连接 Valve 服务器。请检查网络连接,然后重试。"
+ "value" : "NotProton 无法连接 %@ 服务器。请检查网络连接,然后重试。"
+ }
+ }
+ }
+ },
+ "NotProton does not run %@ with Winetricks." : {
+ "localizations" : {
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "NotProton 不会通过 Winetricks 运行 %@。"
}
}
}
@@ -2918,6 +2948,16 @@
}
}
},
+ "Run Winetricks" : {
+ "localizations" : {
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "运行 Winetricks"
+ }
+ }
+ }
+ },
"Run a program or open a Wine tool in the selected prefix." : {
"localizations" : {
"zh-Hans" : {
@@ -3871,6 +3911,32 @@
}
}
},
+ "Winetricks" : {
+ "shouldTranslate" : false
+ },
+ "Winetricks ran %@ in %@." : {
+ "localizations" : {
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Winetricks 已在“%2$@”中运行 %1$@。"
+ }
+ }
+ }
+ },
+ "Winetricks stopped with status %d. Its output is in %@." : {
+ "localizations" : {
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Winetricks 已停止,状态码为 %d。输出位于 %@。"
+ }
+ }
+ }
+ },
+ "Winetricks…" : {
+ "shouldTranslate" : false
+ },
"You will not lose saves by using this tool." : {
"localizations" : {
"zh-Hans" : {
@@ -4060,6 +4126,9 @@
}
}
}
+ },
+ "vcrun2022 corefonts" : {
+ "shouldTranslate" : false
}
},
"version" : "1.0"
diff --git a/app/Sources/NotProtonApp/Support/PinnedDownload.swift b/app/Sources/NotProtonApp/Support/PinnedDownload.swift
index 5ebc48b..a0de345 100644
--- a/app/Sources/NotProtonApp/Support/PinnedDownload.swift
+++ b/app/Sources/NotProtonApp/Support/PinnedDownload.swift
@@ -22,6 +22,7 @@ enum PinnedDownload {
bases: [URL],
into downloads: URL,
step: String,
+ from source: String = "Valve",
report: @Sendable (Progress) -> Void = { _ in }
) async throws -> URL {
let archive = downloads.appending(path: file)
@@ -65,7 +66,7 @@ enum PinnedDownload {
}
AppLog.note("\(file) refused by all \(bases.count) hosts: \(refusals.joined(separator: ". "))")
- throw StepFailure(step: step, detail: reason(kinds))
+ throw StepFailure(step: step, detail: reason(kinds, from: source))
}
private enum Refusal {
@@ -74,13 +75,13 @@ enum PinnedDownload {
case answered
}
- private static func reason(_ kinds: Set<Refusal>) -> String {
+ private static func reason(_ kinds: Set<Refusal>, from source: String) -> String {
if kinds == [.mismatch] {
return String(localized: "Something is wrong with the downloaded files. Please check for a NotProton update.")
}
if kinds == [.unreachable] {
- return String(localized: "NotProton could not reach Valve's servers. Please check your internet connection and try again.")
+ return String(localized: "NotProton could not reach \(source)'s servers. Please check your internet connection and try again.")
}
- return String(localized: "NotProton could not download the files it needs from Valve. Please try again later.")
+ return String(localized: "NotProton could not download the files it needs from \(source). Please try again later.")
}
}
diff --git a/app/Sources/NotProtonApp/Support/Shell.swift b/app/Sources/NotProtonApp/Support/Shell.swift
index 7838506..4312c15 100644
--- a/app/Sources/NotProtonApp/Support/Shell.swift
+++ b/app/Sources/NotProtonApp/Support/Shell.swift
@@ -124,6 +124,29 @@ enum Shell {
try process.run()
}
+ static func logged(
+ _ executable: String,
+ _ arguments: [String],
+ environment: [String: String],
+ to log: URL
+ ) throws -> Int32 {
+ guard FileManager.default.createFile(atPath: log.path(percentEncoded: false), contents: nil)
+ else { throw CocoaError(.fileWriteUnknown, userInfo: [NSFilePathErrorKey: log.path(percentEncoded: false)]) }
+ let handle = try FileHandle(forWritingTo: log)
+ defer { try? handle.close() }
+
+ let process = Process()
+ process.executableURL = URL(filePath: executable)
+ process.arguments = arguments
+ process.environment = environment
+ process.standardInput = FileHandle.nullDevice
+ process.standardOutput = handle
+ process.standardError = handle
+ try process.run()
+ process.waitUntilExit()
+ return process.terminationStatus
+ }
+
static func processIsRunning(
named name: String, pgrep: String = "/usr/bin/pgrep",
drainTimeout: DispatchTimeInterval = outputDrainTimeout
diff --git a/app/Sources/NotProtonApp/Support/SupportPaths.swift b/app/Sources/NotProtonApp/Support/SupportPaths.swift
index df68d10..32d253f 100644
--- a/app/Sources/NotProtonApp/Support/SupportPaths.swift
+++ b/app/Sources/NotProtonApp/Support/SupportPaths.swift
@@ -38,6 +38,10 @@ enum SupportPaths {
home.appending(path: "Library/Caches/\(supportDirName)/valve-packages")
}
+ static var winetricksDownloads: URL {
+ home.appending(path: "Library/Caches/\(supportDirName)/winetricks")
+ }
+
static var deployedVersion: URL { support.appending(path: "dylib.version") }
// Read by the dylib at Steam launch, in np_compat_load_tool_list.
diff --git a/app/Sources/NotProtonApp/Views/PrefixesView.swift b/app/Sources/NotProtonApp/Views/PrefixesView.swift
index 6ee9614..ec3284e 100644
--- a/app/Sources/NotProtonApp/Views/PrefixesView.swift
+++ b/app/Sources/NotProtonApp/Views/PrefixesView.swift
@@ -7,6 +7,8 @@ struct PrefixesView: View {
@Environment(PrefixesModel.self) private var model
@Environment(\.colorSchemeContrast) private var contrast
@State private var sortOrder = [KeyPathComparator(\PrefixRow.lastUsed, order: .reverse)]
+ @State private var winetricksPrefix: WinePrefix?
+ @State private var winetricksVerbs = ""
var body: some View {
Group {
@@ -104,6 +106,25 @@ struct PrefixesView: View {
} message: {
Text(PrefixPrompt.backUpMessage(backingUp))
}
+ .alert(
+ "Winetricks",
+ isPresented: Binding(
+ get: { winetricksPrefix != nil },
+ set: { if !$0 { winetricksPrefix = nil } }
+ ),
+ presenting: winetricksPrefix
+ ) { prefix in
+ TextField("vcrun2022 corefonts", text: $winetricksVerbs)
+ Button("Install") {
+ let verbs = winetricksVerbs
+ Task { await model.winetricks(verbs, in: prefix) }
+ }
+ .keyboardShortcut(.defaultAction)
+ .disabled(PrefixTools.winetricksVerbs(winetricksVerbs).isEmpty)
+ Button("Cancel", role: .cancel) {}
+ } message: { prefix in
+ Text("Enter the Winetricks verbs to install in \(prefix.title), separated by spaces.")
+ }
}
private enum Question {
@@ -360,6 +381,9 @@ struct PrefixesView: View {
Button("Run Program…") {
if let prefix { model.chooseExecutable(for: prefix) }
}
+ Button("Winetricks…") {
+ winetricksPrefix = prefix
+ }
Divider()
ForEach(WineTool.allCases, id: \.self) { tool in
Button(tool.label) {
diff --git a/app/Tests/NotProtonAppTests/PrefixToolsTests.swift b/app/Tests/NotProtonAppTests/PrefixToolsTests.swift
index 8c9d2dd..da841f0 100644
--- a/app/Tests/NotProtonAppTests/PrefixToolsTests.swift
+++ b/app/Tests/NotProtonAppTests/PrefixToolsTests.swift
@@ -194,7 +194,6 @@ struct PrefixToolsTests {
let exe = dir.appending(path: "setup.exe")
try Data("MZ".utf8).write(to: exe)
- // No runner, which is the same refusal opening a tool gets.
#expect(throws: StepFailure.self) {
try PrefixTools.run(exe, in: samplePrefix(), runner: dir)
}
@@ -206,6 +205,33 @@ struct PrefixToolsTests {
}
}
+ @Test("Winetricks refuses before it runs when it cannot work or would leave the prefix")
+ func winetricksRefusesEarly() throws {
+ let dir = FileManager.default.temporaryDirectory.appending(path: "np-winetricks-\(UUID().uuidString)")
+ defer { try? FileManager.default.removeItem(at: dir) }
+ try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
+ let script = dir.appending(path: "winetricks")
+
+ #expect(PrefixTools.winetricksVerbs(" vcrun2022\tcorefonts \n") == ["vcrun2022", "corefonts"])
+
+ func refusal(_ verbs: String) -> String? {
+ do {
+ _ = try PrefixTools.winetricks(
+ PrefixTools.winetricksVerbs(verbs), in: samplePrefix(), script: script, runner: dir)
+ return nil
+ } catch {
+ return (error as? StepFailure)?.detail
+ }
+ }
+ #expect(refusal(" ")?.contains("at least one verb") == true)
+ #expect(refusal("vcrun2022 annihilate")?.contains("annihilate") == true)
+ #expect(refusal("prefix=other corefonts")?.contains("prefix=other") == true)
+ #expect(refusal("--self-update")?.contains("--self-update") == true)
+ #expect(refusal("corefonts")?.contains("No compatibility tool") == true)
+ #expect(!FileManager.default.fileExists(
+ atPath: samplePrefix().root.appending(path: PrefixTools.winetricksLogName).path(percentEncoded: false)))
+ }
+
@Test("Every kind offered by the file picker is a kind that can be run")
func pickerTypesMatchWhatRuns() {
let extensions = PrefixTools.runnableTypes.compactMap(\.preferredFilenameExtension)