Skip to content

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

Clone bridge files on other drives too

NotProtonNot64b067fb7986
diff --git a/app/Sources/NotProtonApp/Model/RunnerInstaller.swift b/app/Sources/NotProtonApp/Model/RunnerInstaller.swift
index 341b32b..f4f24be 100644
--- a/app/Sources/NotProtonApp/Model/RunnerInstaller.swift
+++ b/app/Sources/NotProtonApp/Model/RunnerInstaller.swift
@@ -149,7 +149,8 @@ enum RunnerInstaller {
guard info.st_mode & S_IFMT == S_IFDIR else { throw POSIXError(.ENOTDIR) }
for name in try templateDirectoryNames(root) where !kept.contains(name) {
- guard name.wholeMatch(of: #/crossover-[A-Za-z0-9.-]+-(x86_64|aarch64)-unix/#) != nil else { continue }
+ let template = name.wholeMatch(of: #/crossover-[A-Za-z0-9.-]+-(x86_64|aarch64)-unix/#) != nil
+ guard template || (builds.isEmpty && name == SupportPaths.bridgeCacheFolder) else { continue }
do {
try removeTemplateEntry(name, in: root, device: info.st_dev)
} catch {
diff --git a/app/Sources/NotProtonApp/Support/SupportPaths.swift b/app/Sources/NotProtonApp/Support/SupportPaths.swift
index cbcb75b..00c26c9 100644
--- a/app/Sources/NotProtonApp/Support/SupportPaths.swift
+++ b/app/Sources/NotProtonApp/Support/SupportPaths.swift
@@ -63,6 +63,7 @@ enum SupportPaths {
}
static let prefixTemplateFolder = "notproton-template"
+ static let bridgeCacheFolder = "bridge"
enum Steam {
static var app: URL { URL(filePath: "/Applications/Steam.app") }
diff --git a/app/Sources/NotProtonApp/SystemStatus.swift b/app/Sources/NotProtonApp/SystemStatus.swift
index 6ba75df..a047579 100644
--- a/app/Sources/NotProtonApp/SystemStatus.swift
+++ b/app/Sources/NotProtonApp/SystemStatus.swift
@@ -517,6 +517,7 @@ final class SystemStatus {
private(set) var runnerSizes: [String: Int64] = [:]
private(set) var templateSizes: [String: [CompatTool.Flavor: Int64]] = [:]
private(set) var templateCleanupFailure: String?
+ private(set) var bridgeCopyBytes: Int64 = 0
func refreshRunnerStorage(
runners: URL = SupportPaths.runners, libraries: [SteamLibrary] = PrefixStore.libraries(),
@@ -532,6 +533,14 @@ final class SystemStatus {
? RunnerInstaller.removeStalePrefixTemplates(runners: runners, libraries: libraries, reportBusy: false) : []
var sizes: [String: Int64] = [:]
var templates: [String: [CompatTool.Flavor: Int64]] = [:]
+ let bridgeCopies = libraries.reduce(Int64(0)) { total, library in
+ let folder = library.compatdata.appending(path: SupportPaths.prefixTemplateFolder)
+ var info = stat()
+ guard lstat(folder.path(percentEncoded: false), &info) == 0,
+ info.st_mode & S_IFMT == S_IFDIR else { return total }
+ return total + PrefixStore.directoryBytes(
+ folder.appending(path: SupportPaths.bridgeCacheFolder), metric: .allocated)
+ }
for build in RunnerStore.clonedBuilds(in: runners) {
sizes[build] = known[build] ?? RunnerStore.cloneSize(forBuild: build, runners: runners)
templates[build] = libraries.reduce(into: [:]) { totals, library in
@@ -545,10 +554,11 @@ final class SystemStatus {
}
}
}
- return (sizes, templates, failures)
+ return (sizes, templates, failures, bridgeCopies)
}.value
runnerSizes = measured.0
templateSizes = measured.1
templateCleanupFailure = measured.2.isEmpty ? nil : measured.2.map(\.detail).joined(separator: "\n")
+ bridgeCopyBytes = measured.3
}
}
diff --git a/app/Sources/NotProtonApp/Views/StatusView.swift b/app/Sources/NotProtonApp/Views/StatusView.swift
index 9f64096..f807fa9 100644
--- a/app/Sources/NotProtonApp/Views/StatusView.swift
+++ b/app/Sources/NotProtonApp/Views/StatusView.swift
@@ -718,7 +718,11 @@ struct StatusView: View {
}
} else if payload.isComplete {
Section("NotProton Components") {
- StatusRow(title: "Components", value: "Ready.", tone: .ok)
+ StatusRow(
+ title: "Components", value: "Ready.", tone: .ok,
+ trailing: status.bridgeCopyBytes > 0
+ ? "Copies on other drives \(status.bridgeCopyBytes.formatted(.byteCount(style: .file)))" : nil
+ )
}
} else if payload.isEmpty {
Section("NotProton Components") {
diff --git a/app/Tests/NotProtonAppTests/TemplateCleanupTests.swift b/app/Tests/NotProtonAppTests/TemplateCleanupTests.swift
index bcb6605..9ae2ea4 100644
--- a/app/Tests/NotProtonAppTests/TemplateCleanupTests.swift
+++ b/app/Tests/NotProtonAppTests/TemplateCleanupTests.swift
@@ -65,6 +65,43 @@ struct TemplateCleanupTests {
}
}
+ @Test("The drive's bridge copy stays while any build is set up and goes with the last")
+ func bridgeCacheGoesWithLastBuild() throws {
+ let layout = try Layout()
+ defer { try? FileManager.default.removeItem(at: layout.root) }
+ let cache = layout.folder.appending(path: SupportPaths.bridgeCacheFolder)
+ try FileManager.default.createDirectory(at: cache.appending(path: "x86_64-unix"), withIntermediateDirectories: true)
+ try Data("bridge".utf8).write(to: cache.appending(path: "x86_64-unix/lsteamclient.so"))
+
+ #expect(RunnerInstaller.removePrefixTemplates(keeping: ["26.3.0.39832"], libraries: [layout.library]).isEmpty)
+ #expect(FileManager.default.fileExists(atPath: cache.appending(path: "x86_64-unix/lsteamclient.so").path))
+ #expect(FileManager.default.fileExists(atPath: layout.template.path))
+
+ #expect(RunnerInstaller.removePrefixTemplates(keeping: [], libraries: [layout.library]).isEmpty)
+ #expect(!FileManager.default.fileExists(atPath: cache.path))
+ #expect(!FileManager.default.fileExists(atPath: layout.template.path))
+ }
+
+ @MainActor
+ @Test("The bridge copies on every drive are counted once")
+ func countsBridgeCopies() async throws {
+ let layout = try Layout()
+ defer { try? FileManager.default.removeItem(at: layout.root) }
+ let other = SteamLibrary(root: layout.root.appending(path: "second-library"))
+ for library in [layout.library, other] {
+ let cache = library.compatdata.appending(path: SupportPaths.prefixTemplateFolder)
+ .appending(path: SupportPaths.bridgeCacheFolder)
+ try FileManager.default.createDirectory(at: cache, withIntermediateDirectories: true)
+ try Data(repeating: 7, count: 4 << 20).write(to: cache.appending(path: "steam.exe"))
+ }
+ let status = SystemStatus()
+
+ await status.refreshRunnerStorage(runners: layout.runners, libraries: [layout.library, other], cleanTemplates: false)
+
+ #expect(status.bridgeCopyBytes >= 8 << 20)
+ #expect(status.bridgeCopyBytes < 9 << 20)
+ }
+
@Test("Linked template children are unlinked without touching their targets")
func unlinksChildrenOnly() throws {
let layout = try Layout()
diff --git a/dylib/feats/compat_run.sh b/dylib/feats/compat_run.sh
index 7e02039..bc9ffd4 100755
--- a/dylib/feats/compat_run.sh
+++ b/dylib/feats/compat_run.sh
@@ -848,13 +848,12 @@ verify_runner() {
echo "=== runner is missing $arch/$name, set up the runner in NotProton ===" >> "$log" 2>&1 || true
done
}
-# Clone rather than copy where the filesystem allows it.
install_lsteamclient_trigger() {
src="$bridge_src/i386-windows/lsteamclient.dll"
dst="$WINEPREFIX/drive_c/windows/syswow64/lsteamclient.dll"
[ -f "$src" ] && [ -d "$WINEPREFIX/drive_c/windows/syswow64" ] || return 0
cmp -s "$src" "$dst" && return 0
- if cp -c -f "$src" "$dst" 2>/dev/null || cp -f "$src" "$dst"; then
+ if place_bridge_file i386-windows/lsteamclient.dll "$dst"; then
echo "=== installed syswow64 lsteamclient trigger ===" >> "$log" 2>&1 || true
else
echo "=== could not install the syswow64 lsteamclient trigger ===" >> "$log" 2>&1 || true
@@ -867,7 +866,7 @@ install_legacy_steam_dll() {
dst="$WINEPREFIX/drive_c/windows/syswow64/Steam.dll"
[ -f "$src" ] && [ -d "$WINEPREFIX/drive_c/windows/syswow64" ] || return 0
cmp -s "$src" "$dst" && return 0
- if cp -c -f "$src" "$dst" 2>/dev/null || cp -f "$src" "$dst"; then
+ if place_bridge_file legacycompat/Steam.dll "$dst"; then
echo "=== installed legacy Steam.dll ===" >> "$log" 2>&1 || true
else
echo "=== could not install the legacy Steam.dll ===" >> "$log" 2>&1 || true
@@ -886,16 +885,43 @@ install_legacycompat() {
[ -f "$f" ] || continue
b=$(basename "$f")
cmp -s "$f" "$dst/$b" && continue
- { cp -c -f "$f" "$dst/$b" 2>/dev/null || cp -f "$f" "$dst/$b"; } && \
+ cp -c -f "$f" "$dst/$b" && \
echo "=== installed legacycompat/$b ===" >> "$log" 2>&1
done
}
bridge_files="steamclient64.dll steamclient.dll tier0_s64.dll vstdlib_s64.dll"
bridge_files="$bridge_files lsteamclient.dll lsteamclient.so steam.exe"
+# A clone cannot cross drives, so a prefix on another drive clones from a copy of the
+# bridge kept beside that drive's templates.
+bridge_origin() {
+ origin="$bridge_src/$1"
+ [ -n "$bridge_cache" ] || return 0
+ cached="$bridge_cache/$1"
+ for d in "${bridge_cache%/*}" "$bridge_cache" "${cached%/*}"; do
+ [ ! -L "$d" ] || return 0
+ done
+ mkdir -p "${cached%/*}" 2>/dev/null || return 0
+ if ! cmp -s "$origin" "$cached"; then
+ if ! { cp -p "$origin" "$cached.$$" && mv -f "$cached.$$" "$cached"; } 2>/dev/null; then
+ rm -f "$cached.$$"
+ return 0
+ fi
+ fi
+ origin="$cached"
+}
+place_bridge_file() {
+ bridge_origin "$1"
+ cp -c -fp "$origin" "$2" 2>/dev/null || cp -fp "$bridge_src/$1" "$2"
+}
if [ -d "$bridge_src" ] && [ -n "$WINEPREFIX" ]; then
stage_step="bridge staging"
mkdir -p "$prefix_steam"
+ bridge_cache=""
+ if [ -n "$STEAM_COMPAT_DATA_PATH" ] && ! same_volume "$bridge_src" "$STEAM_COMPAT_DATA_PATH" \
+ && volume_clones "$STEAM_COMPAT_DATA_PATH"; then
+ bridge_cache="$(dirname "$STEAM_COMPAT_DATA_PATH")/notproton-template/bridge"
+ fi
bridge_matches=1
for f in $bridge_files; do
src="$bridge_src/$f"
@@ -911,17 +937,17 @@ if [ -d "$bridge_src" ] && [ -n "$WINEPREFIX" ]; then
echo "=== bridge already staged ===" >> "$log" 2>&1 || true
else
for f in $bridge_files; do
- src="$bridge_src/$f"
+ rel="$f"
if [ "$f" = lsteamclient.so ]; then
- src="$bridge_src/${wine_unix##*/}/$f"
+ rel="${wine_unix##*/}/$f"
fi
+ src="$bridge_src/$rel"
if [ ! -f "$src" ]; then
echo "=== bridge missing $f ===" >> "$log" 2>&1 || true
continue
fi
cmp -s "$src" "$prefix_steam/$f" && continue
- { cp -c -fp "$src" "$prefix_steam/$f" 2>/dev/null \
- || cp -fp "$src" "$prefix_steam/$f"; } || \
+ place_bridge_file "$rel" "$prefix_steam/$f" || \
echo "=== failed to stage $f ===" >> "$log" 2>&1
done
fi
diff --git a/dylib/tests/bridgecheck.sh b/dylib/tests/bridgecheck.sh
index 02c3d0a..ac5ea31 100644
--- a/dylib/tests/bridgecheck.sh
+++ b/dylib/tests/bridgecheck.sh
@@ -11,7 +11,9 @@ case "$block" in
*) echo "FAIL: the bridge staging block not found in $SRC"; exit 1 ;;
esac
block=$(printf '%s\n' "$block" | sed '$d')
-body="$block
+body='same_volume() { [ -z "$cross" ]; }
+volume_clones() { :; }
+'"$block
fi"
work=$(mktemp -d)
@@ -35,11 +37,14 @@ unlogged() { if grep -qxF "$2" "$work/log"; then bad "$1" "no [$2]" "$(cat "$wor
prefix="$work/pfx"
steam="$prefix/drive_c/Program Files (x86)/Steam"
+compat=""
+cross=""
stage() {
: > "$work/log"
env bridge_src="$work/bridge" WINEPREFIX="$prefix" prefix_steam="$steam" \
log="$work/log" body="$body" wine_unix="$wine_unix" \
+ STEAM_COMPAT_DATA_PATH="$compat" cross="$cross" \
sh -ec 'eval "$body"; echo reached' > "$work/out" 2>&1 || true
}
staged() {
@@ -105,6 +110,50 @@ stage
is "the launch goes on" reached "$(cat "$work/out")"
logged "the missing file is logged" "=== bridge missing steam.exe ==="
is "the other files are copied" 5 "$(staged)"
+printf 'bridge steam.exe\n' > "$work/bridge/steam.exe"
+
+echo "== a prefix on the same drive clones from the bridge itself"
+rm -rf "$prefix"
+compat="$work/library/compatdata/1"
+cache="$work/library/compatdata/notproton-template/bridge"
+stage
+is "every file is copied" 6 "$(staged)"
+is "no copy of the bridge is made" no "$([ -e "$cache" ] && echo yes || echo no)"
+
+echo "== a prefix on another drive clones from that drive's copy"
+rm -rf "$prefix"
+cross=1
+stage
+is "the launch goes on" reached "$(cat "$work/out")"
+is "every file is copied" 6 "$(staged)"
+is "the drive keeps a copy of steam.exe" "bridge steam.exe" "$(cat "$cache/steam.exe" 2>/dev/null)"
+is "the drive keeps the unix library under its architecture" "updated x86_64 bridge" \
+ "$(cat "$cache/x86_64-unix/lsteamclient.so" 2>/dev/null)"
+is "no temporary copies are left" "" "$(find "$cache" -name '*.[0-9]*' 2>/dev/null)"
+
+echo "== a changed bridge file refreshes the drive's copy"
+printf 'bridge steam.exe, newer build\n' > "$work/bridge/steam.exe"
+stage
+is "the drive's copy is replaced" "bridge steam.exe, newer build" "$(cat "$cache/steam.exe" 2>/dev/null)"
+is "the prefix receives the new file" "bridge steam.exe, newer build" "$(cat "$steam/steam.exe" 2>/dev/null)"
+
+echo "== a linked copy on the drive is not used"
+rm -rf "$prefix" "$cache"
+mkdir -p "$work/elsewhere"
+ln -s "$work/elsewhere" "$cache"
+stage
+is "every file is copied" 6 "$(staged)"
+is "nothing is written through the link" "" "$(ls "$work/elsewhere")"
+rm "$cache"
+
+echo "== a drive that cannot hold a copy still gets the bridge"
+rm -rf "$prefix"
+mkdir -p "${cache%/*}"
+chmod 500 "${cache%/*}"
+stage
+chmod 700 "${cache%/*}"
+is "the launch goes on" reached "$(cat "$work/out")"
+is "every file is copied" 6 "$(staged)"
[ "$fails" -eq 0 ] || { echo "==> bridgecheck: $fails failure(s)"; exit 1; }
echo "==> bridgecheck: the bridge stages on fresh, current, stale and incomplete prefixes"