Skip to content

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

Reuse existing game launchers when possible

NotProtonNot71765b2c145a
diff --git a/.github/workflows/app.yml b/.github/workflows/app.yml
index f8cb701..fa19327 100644
--- a/.github/workflows/app.yml
+++ b/.github/workflows/app.yml
@@ -119,6 +119,7 @@ jobs:
make -s routecheck
make -s bridgecheck
make -s gamedrivecheck
+ make -s launchercheck
make -s seedcheck
- name: Run the Swift tests
diff --git a/Makefile b/Makefile
index d77cd85..6cff7b7 100644
--- a/Makefile
+++ b/Makefile
@@ -64,7 +64,7 @@ DEPS := $(OBJS:.o=.d)
tests-list overlay-shim overlay-shim-install overlay-shim-tests \
overlay-shim-bench iconmaker icon \
appinfo helpers-install ntdll-resolve bridge runcheck compatcheck \
- compatsvc-check scriptcheck envcheck buildcheck settingscheck routecheck bridgecheck gamedrivecheck launch-shell FORCE
+ compatsvc-check scriptcheck envcheck buildcheck settingscheck routecheck bridgecheck gamedrivecheck launchercheck launch-shell FORCE
APP_PAYLOAD := app/Sources/NotProtonApp/Resources/payload
@@ -120,6 +120,10 @@ gamedrivecheck:
@if [ ! -f dylib/tests/gamedrivecheck.sh ]; then $(call SKIP,gamedrivecheck,dylib/tests/gamedrivecheck.sh); exit 0; fi; \
sh dylib/tests/gamedrivecheck.sh dylib/feats/compat_run.sh
+launchercheck:
+ @if [ ! -f dylib/tests/launchercheck.sh ]; then $(call SKIP,launchercheck,dylib/tests/launchercheck.sh); exit 0; fi; \
+ sh dylib/tests/launchercheck.sh dylib/feats/compat_run.sh
+
# runcheck owns compat_run.sh, whose warnings wait for a change that can move
# the embedded __text baseline
SCRIPTS := $(shell git ls-files '*.sh' 2>/dev/null | grep -v '^dylib/feats/compat_run\.sh$$')
diff --git a/dylib/feats/compat_run.sh b/dylib/feats/compat_run.sh
index ec3c5cc..7731141 100755
--- a/dylib/feats/compat_run.sh
+++ b/dylib/feats/compat_run.sh
@@ -1171,12 +1171,16 @@ fi
[ -z "$game_name" ] && game_name="Steam Game"
# shellcheck disable=SC1003 # the pair deletes a literal backslash, not a quote
bundle_name=$(printf '%s' "$game_name" | tr -d '/:"`$\\')
+bundle_name=${bundle_name#"${bundle_name%%[!.]*}"}
+[ -n "$bundle_name" ] || bundle_name="Steam Game"
game_name_xml=$(printf '%s' "$game_name" | sed -e 's/&/\&amp;/g' -e 's/</\&lt;/g' -e 's/>/\&gt;/g')
loader_root="$HOME/Library/Application Support/notproton/launchers/$app_id"
mkdir -p "$loader_root"
loader_app="$loader_root/$bundle_name.app"
-rm -rf "$loader_root"/*.app
-loader_contents="$loader_app/Contents"
+find "$loader_root" -maxdepth 1 -name '.build.*' -mmin +60 -exec rm -rf {} + 2>/dev/null || true
+loader_work=$(mktemp -d "$loader_root/.build.XXXXXX")
+loader_stage="$loader_work/new/$bundle_name.app"
+loader_contents="$loader_stage/Contents"
loader_macos="$loader_contents/MacOS"
loader_res="$loader_contents/Resources"
mkdir -p "$loader_macos" "$loader_res"
@@ -1299,7 +1303,7 @@ for f in "$wine_unix"/*; do
done
ln "$WINELOADER" "$loader_macos/wine" 2>/dev/null || cp "$WINELOADER" "$loader_macos/wine"
if [ -x "$loader_macos/wine" ]; then
- WINELOADER="$loader_macos/wine"
+ WINELOADER="$loader_app/Contents/MacOS/wine"
echo "loader staged in bundle for game mode" >> "$log" 2>&1 || true
else
echo "loader staging failed, game mode unavailable" >> "$log" 2>&1 || true
@@ -1325,6 +1329,69 @@ exit \$?
LAUNCHER
chmod +x "$loader_macos/launcher"
+bundle_listing() {
+ (cd "$1" && find . | LC_ALL=C sort | while IFS= read -r p; do
+ if [ -L "$p" ]; then
+ printf 'l %s %s\n' "$p" "$(readlink "$p")"
+ elif [ -d "$p" ]; then
+ printf 'd %s\n' "$p"
+ else
+ printf 'f %s %s %s\n' "$p" "$(stat -f %Lp "$p")" "$(cksum < "$p")"
+ fi
+ done)
+}
+install_bundle() (
+ exec 7>> "$loader_root/.lock"
+ /usr/bin/lockf -s -t 30 7 || exit 1
+ same=""
+ for b in "$loader_root"/*.app; do
+ if [ "$b" = "$loader_app" ] && [ -d "$b" ] && [ ! -L "$b" ] &&
+ [ "$(bundle_listing "$b")" = "$(bundle_listing "$loader_stage")" ]; then
+ same=1
+ fi
+ done
+ if [ -n "$same" ]; then
+ for b in "$loader_root"/*.app "$loader_root"/.[!.]*.app; do
+ if [ "$b" != "$loader_app" ]; then rm -rf "$b" || true; fi
+ done
+ echo "launcher bundle unchanged" >> "$log" 2>&1 || true
+ else
+ stage_identity=$(stat -f '%d:%i' "$loader_stage") || exit 1
+ loader_backup=$(mktemp -d "$loader_root/.backup.XXXXXX") || exit 1
+ finish_bundle() {
+ result=$?
+ trap - EXIT
+ trap '' HUP INT TERM
+ installed_identity=$(stat -f '%d:%i' "$loader_app" 2>/dev/null) || installed_identity=""
+ if [ "$installed_identity" != "$stage_identity" ]; then
+ for saved in "$loader_backup"/* "$loader_backup"/.[!.]*; do
+ [ -e "$saved" ] || [ -L "$saved" ] || continue
+ mv "$saved" "$loader_root/${saved##*/}" || result=1
+ done
+ rmdir "$loader_backup" 2>/dev/null || result=1
+ else
+ rm -rf "$loader_backup" || true
+ fi
+ rm -rf "$loader_work" || true
+ exit "$result"
+ }
+ trap 'finish_bundle' EXIT
+ trap 'exit 129' HUP
+ trap 'exit 130' INT
+ trap 'exit 143' TERM
+ for b in "$loader_root"/*.app "$loader_root"/.[!.]*.app "$loader_app"; do
+ if [ -e "$b" ] || [ -L "$b" ]; then
+ mv "$b" "$loader_backup/${b##*/}" || exit 1
+ fi
+ done
+ mv "$loader_stage" "$loader_app" || exit 1
+ echo "launcher bundle updated" >> "$log" 2>&1 || true
+ finish_bundle
+ fi
+ rm -rf "$loader_work" || true
+)
+install_bundle
+
wine_helpers='winedevice\.exe|services\.exe|plugplay\.exe|svchost\.exe'
wine_helpers="$wine_helpers|rpcss\.exe|explorer\.exe|steam\.exe"
wine_helpers="$wine_helpers|winemenubuilder\.exe|conhost\.exe|start\.exe"
diff --git a/dylib/tests/launchercheck.sh b/dylib/tests/launchercheck.sh
new file mode 100644
index 0000000..1031aff
--- /dev/null
+++ b/dylib/tests/launchercheck.sh
@@ -0,0 +1,221 @@
+#!/bin/sh
+# shellcheck disable=SC2016,SC2034,SC2154
+set -e
+SRC="${1:-$(dirname "$0")/../feats/compat_run.sh}"
+[ -f "$SRC" ] || { echo "launchercheck: $SRC not present, skipped"; exit 0; }
+
+funcs=$(sed -n '/^bundle_listing() {$/,/^install_bundle$/p' "$SRC" | sed '$d')
+name_lines=$(sed -n '/^bundle_name=\$(printf/,/^\[ -n "\$bundle_name" \] || bundle_name=/p' "$SRC")
+launcher_body=$(sed -n '/^cat > "\$loader_macos\/launcher" <<LAUNCHER$/,/^LAUNCHER$/p' "$SRC" | sed 1d)
+loader_line=$(grep -A1 '^if \[ -x "\$loader_macos/wine" \]; then$' "$SRC" | sed -n 2p)
+[ -n "$funcs" ] || { echo "FAIL: bundle functions not found"; exit 1; }
+[ -n "$name_lines" ] || { echo "FAIL: bundle name lines not found"; exit 1; }
+[ -n "$launcher_body" ] || { echo "FAIL: launcher script not found"; exit 1; }
+eval "$funcs"
+
+fails=0
+ok() { printf ' ok %s\n' "$1"; }
+bad() { printf ' FAIL %s\n want [%s]\n got [%s]\n' "$1" "$2" "$3"; fails=$((fails + 1)); }
+is() { if [ "$2" = "$3" ]; then ok "$1"; else bad "$1" "$2" "$3"; fi; }
+
+T=$(mktemp -d)
+trap 'rm -rf "$T"' EXIT
+mkdir -p "$T/runner"
+printf 'a' > "$T/runner/a.so"
+printf 'b' > "$T/runner/b.so"
+log="$T/log"
+loader_root="$T/launchers"
+mkdir -p "$loader_root"
+
+stage() {
+ loader_app="$loader_root/$1.app"
+ loader_work=$(mktemp -d "$loader_root/.build.XXXXXX")
+ loader_stage="$loader_work/new/$1.app"
+ mkdir -p "$loader_stage/Contents/MacOS" "$loader_stage/Contents/Resources"
+ printf '%s' "${2:-plist}" > "$loader_stage/Contents/Info.plist"
+ printf 'icon' > "$loader_stage/Contents/Resources/game.icns"
+ ln -sfn "$T/runner/${3:-a.so}" "$loader_stage/Contents/MacOS/x.so"
+ printf '#!/bin/sh\n' > "$loader_stage/Contents/MacOS/launcher"
+ chmod "${4:-755}" "$loader_stage/Contents/MacOS/launcher"
+ : > "$log"
+}
+build() {
+ stage "$@"
+ install_bundle
+}
+apps() { (cd "$loader_root" && for b in *.app; do [ -e "$b" ] && printf '%s|' "$b"; done; true); }
+plist_inode() { stat -f %i "$loader_app/Contents/Info.plist"; }
+leftover() { (cd "$loader_root" && n=0 && for b in .build.*; do [ -e "$b" ] && n=$((n + 1)); done; echo "$n"); }
+
+echo "== final paths =="
+case "$launcher_body" in *loader_stage*|*loader_contents*|*loader_macos*|*loader_work*) bad "launcher has no staging paths" "none" "staging path" ;; *) ok "launcher has no staging paths" ;; esac
+is "WINELOADER points at the installed bundle" ' WINELOADER="$loader_app/Contents/MacOS/wine"' "$loader_line"
+
+echo "== bundle names =="
+for pair in '.hack//G.U. Last Recode|hackG.U. Last Recode' '...|Steam Game' '//|Steam Game' 'Half-Life 2|Half-Life 2' 'a.b|a.b'; do
+ game_name=${pair%%|*}
+ eval "$name_lines"
+ is "name [${pair%%|*}]" "${pair#*|}" "$bundle_name"
+done
+
+echo "== first launch =="
+build "Game"
+is "bundle created" "Game.app|" "$(apps)"
+is "logged as updated" "launcher bundle updated" "$(cat "$log")"
+is "work folder removed" "0" "$(leftover)"
+
+echo "== same content =="
+before=$(plist_inode)
+build "Game"
+is "logged as unchanged" "launcher bundle unchanged" "$(cat "$log")"
+is "bundle kept in place" "$before" "$(plist_inode)"
+is "work folder removed" "0" "$(leftover)"
+
+echo "== changes replace the bundle =="
+build "Game" "plist2"
+is "plist change" "launcher bundle updated" "$(cat "$log")"
+is "new plist in place" "plist2" "$(cat "$loader_app/Contents/Info.plist")"
+build "Game" "plist2" "b.so"
+is "symlink target change" "launcher bundle updated" "$(cat "$log")"
+is "new symlink in place" "$T/runner/b.so" "$(readlink "$loader_app/Contents/MacOS/x.so")"
+build "Game" "plist2" "b.so" 644
+is "mode change" "launcher bundle updated" "$(cat "$log")"
+build "Game" "plist2" "b.so" 644
+is "then unchanged" "launcher bundle unchanged" "$(cat "$log")"
+rm "$loader_app/Contents/Resources/game.icns"
+build "Game" "plist2" "b.so" 644
+is "missing file" "launcher bundle updated" "$(cat "$log")"
+
+echo "== renames =="
+build "Other Name"
+is "old name removed" "Other Name.app|" "$(apps)"
+build "OTHER NAME"
+is "case-only rename" "OTHER NAME.app|" "$(apps)"
+is "case-only rename replaced" "launcher bundle updated" "$(cat "$log")"
+build "OTHER NAME"
+is "then unchanged" "launcher bundle unchanged" "$(cat "$log")"
+
+echo "== stray bundles =="
+mkdir -p "$loader_root/Stray.app"
+build "OTHER NAME"
+is "stray removed when unchanged" "OTHER NAME.app|" "$(apps)"
+is "still unchanged" "launcher bundle unchanged" "$(cat "$log")"
+
+mkdir -p "$loader_root/.Hidden.app"
+build "OTHER NAME"
+is "hidden stray removed when unchanged" "0" "$(find "$loader_root" -maxdepth 1 -name '.Hidden.app' | wc -l | tr -d ' ')"
+mkdir -p "$loader_root/.Hidden.app"
+build "OTHER NAME" "plist3"
+is "hidden stray removed when updated" "0" "$(find "$loader_root" -maxdepth 1 -name '.Hidden.app' | wc -l | tr -d ' ')"
+build "OTHER NAME"
+
+echo "== awkward names =="
+name='Sonic Adventure™ 2 [x]*? '
+build "$name"
+build "$name"
+is "glob characters and trailing space" "launcher bundle unchanged" "$(cat "$log")"
+is "only that bundle" "$name.app|" "$(apps)"
+
+echo "== hardlink and copy compare equal =="
+mkdir -p "$T/a" "$T/b"
+printf 'wine' > "$T/loader"
+ln "$T/loader" "$T/a/wine"
+cp "$T/loader" "$T/b/wine"
+is "same listing" "$(bundle_listing "$T/a")" "$(bundle_listing "$T/b")"
+
+echo "== lock =="
+build "OTHER NAME"
+if /usr/bin/lockf -s -t 0 "$loader_root/.lock" true; then ok "lock released"; else bad "lock released" "free" "held"; fi
+
+echo "== case twin =="
+rm -rf "$loader_root"/*.app
+mkdir -p "$loader_root/Twin.APP"
+if [ -d "$loader_root/Twin.app" ]; then
+ build "Twin"
+ is "twin replaced" "Twin.app|" "$(apps)"
+else
+ ok "volume is case-sensitive, skipped"
+fi
+
+echo "== symlinked bundle =="
+mkdir -p "$T/elsewhere.app"
+rm -rf "$loader_root"/*.app
+ln -s "$T/elsewhere.app" "$loader_root/Linked.app"
+build "Linked"
+is "symlink replaced by a real bundle" "launcher bundle updated" "$(cat "$log")"
+if [ -L "$loader_root/Linked.app" ]; then bad "not a symlink" "dir" "symlink"; else ok "not a symlink"; fi
+if [ -d "$T/elsewhere.app" ]; then ok "symlink target untouched"; else bad "symlink target untouched" "present" "gone"; fi
+
+echo "== lock contention =="
+build "Original"
+before=$(plist_inode)
+stage "Replacement"
+exec 8>> "$loader_root/.lock"
+/usr/bin/lockf -s -t 0 8
+if (exec 8>&-; install_bundle); then
+ bad "busy lock refuses installation" "failure" "success"
+else
+ ok "busy lock refuses installation"
+fi
+is "locked bundle untouched" "$before" "$(stat -f %i "$loader_root/Original.app/Contents/Info.plist")"
+is "no replacement without lock" "Original.app|" "$(apps)"
+exec 8>&-
+install_bundle
+is "retry after unlock succeeds" "Replacement.app|" "$(apps)"
+
+echo "== rollback =="
+for failure in install backup signal signal-installed missing-stage restore; do
+ build "Original"
+ before=$(plist_inode)
+ mkdir -p "$loader_root/.Hidden.app" "$loader_root/Stray.app"
+ stage "Replacement"
+ staged_inode=$(stat -f %i "$loader_stage/Contents/Info.plist")
+ if env funcs="$funcs" failure="$failure" loader_root="$loader_root" loader_app="$loader_app" \
+ loader_work="$loader_work" loader_stage="$loader_stage" log="$log" /bin/sh -c '
+ set -e
+ eval "$funcs"
+ mv() {
+ case "$failure" in
+ install|restore) [ "$1" != "$loader_stage" ] || return 1 ;;
+ backup) [ "$1" != "$loader_root/Stray.app" ] || return 1 ;;
+ missing-stage)
+ if [ "$1" = "$loader_stage" ]; then rm -rf "$loader_stage"; return 1; fi ;;
+ esac
+ if [ "$failure" = restore ]; then
+ case "$1" in "$loader_root"/.backup.*/Original.app) return 1 ;; esac
+ fi
+ command mv "$@" || return 1
+ if [ "$failure" = signal ] && [ "$1" = "$loader_root/Original.app" ]; then
+ /bin/sh -c '\''kill -TERM "$PPID"'\''
+ fi
+ if [ "$failure" = signal-installed ] && [ "$1" = "$loader_stage" ]; then
+ /bin/sh -c '\''kill -TERM "$PPID"'\''
+ fi
+ }
+ install_bundle
+ '; then
+ bad "$failure reports failure" "failure" "success"
+ else
+ ok "$failure reports failure"
+ fi
+ if [ "$failure" = signal-installed ]; then
+ is "signal after rename keeps new bundle" "$staged_inode" "$(plist_inode)"
+ is "signal after rename does not nest old bundles" "Replacement.app|" "$(apps)"
+ is "signal after rename cleans staging" "0" "$(leftover)"
+ if /usr/bin/lockf -s -t 0 "$loader_root/.lock" true; then ok "$failure releases lock"; else bad "$failure releases lock" "free" "held"; fi
+ continue
+ fi
+ if [ "$failure" = restore ]; then
+ is "failed rollback preserves backup" "$before" "$(stat -f %i "$loader_root"/.backup.*/Original.app/Contents/Info.plist)"
+ mv "$loader_root"/.backup.*/Original.app "$loader_root/Original.app"
+ rmdir "$loader_root"/.backup.*
+ fi
+ is "$failure keeps original name and inode" "$before" "$(stat -f %i "$loader_root/Original.app/Contents/Info.plist")"
+ is "$failure restores visible bundles" "Original.app|Stray.app|" "$(apps)"
+ if [ -d "$loader_root/.Hidden.app" ]; then ok "$failure keeps hidden bundle"; else bad "$failure keeps hidden bundle" "present" "missing"; fi
+ if /usr/bin/lockf -s -t 0 "$loader_root/.lock" true; then ok "$failure releases lock"; else bad "$failure releases lock" "free" "held"; fi
+ is "$failure cleans staging" "0" "$(leftover)"
+done
+
+[ "$fails" -eq 0 ] || { echo "launchercheck: $fails failed"; exit 1; }
+echo "launchercheck: all passed"