Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit
Swift apple-silicond3dmetaldxmtdxvkgame-porting-toolkitgptkmac-gamingmacosmetalfxrosetta-2steamsteam-playwinewinecx
Map drive S: on fresh prefixes and remove it when the game leaves its library
NotProtonNot931e79ffd0ff
diff --git a/dylib/feats/compat_run.sh b/dylib/feats/compat_run.shindex 7c4aa08..1214d32 100755--- a/dylib/feats/compat_run.sh+++ b/dylib/feats/compat_run.sh@@ -675,6 +675,9 @@ prefix_is_bare() ([ -e "$node" ] || [ -L "$node" ] || continuepart="$relative/${node##*/}"if [ -L "$node" ]; then+ if [ "$part" = /dosdevices/s: ] && [ "$(readlink "$node")" = "$(game_drive_record)" ]; then+ continue+ ficase "$part:$(readlink "$node")" in/dosdevices/c::../drive_c|/dosdevices/z::/|/drive_c/users/crossover:steamuser|\'/drive_c/users/steamuser/My Documents:./Documents'|\@@ -789,10 +792,35 @@ prepare_prefix_directory() {mkdir -p "$WINEPREFIX"}+game_drive_record() {+ record="$STEAM_COMPAT_DATA_PATH/notproton-game-drive"+ [ -f "$record" ] && [ ! -L "$record" ] && cat "$record" 2>/dev/null+}++record_game_drive() {+ record="$STEAM_COMPAT_DATA_PATH/notproton-game-drive"+ [ "$(game_drive_record)" != "$1" ] && [ ! -L "$record" ] || return 0+ { printf '%s\n' "$1" > "$record.new" && mv -f "$record.new" "$record"; } 2>/dev/null \+ || rm -f "$record.new" 2>/dev/null || true+}++restart_for_drive() {+ # Wine only picks up a new drive when it starts.+ without_lock_fds "$WINESERVER" -k >> "$log" 2>&1 || true+ without_lock_fds "$WINESERVER" -w >> "$log" 2>&1 || true+}++unmap_game_drive() {+ [ -L "$drive" ] && [ "$(readlink "$drive")" = "$(game_drive_record)" ] || return 0+ rm -f "$drive" || return 0+ rm -f "$STEAM_COMPAT_DATA_PATH/notproton-game-drive" 2>/dev/null || true+ echo "=== removed drive S:, the game is not in a Steam library ===" >> "$log" 2>&1 || true+ restart_for_drive+}+# Like Proton, the game's Steam library gets drive S: so the game does not run from Z:.map_game_drive() {drive="$WINEPREFIX/dosdevices/s:"- owned="$STEAM_COMPAT_DATA_PATH/notproton-game-drive"[ -d "$WINEPREFIX/dosdevices" ] && [ ! -L "$WINEPREFIX/dosdevices" ] || return 0library=""set -f@@ -807,7 +835,10 @@ map_game_drive() {doneIFS=$old_ifsset +f- [ -n "$library" ] || return 0+ if [ -z "$library" ]; then+ unmap_game_drive+ return 0+ fitarget=$libraryif real=$(cd -P -- "$library" 2>/dev/null && pwd) && [ "${real##*/}" = steamapps ]; thenparent=${real%/*}@@ -819,10 +850,10 @@ map_game_drive() {if [ -L "$drive" ]; thencurrent=$(readlink "$drive") || return 0if [ "$current" = "$target" ]; then- printf '%s\n' "$target" > "$owned" 2>/dev/null || true+ record_game_drive "$target"return 0fi- if [ "$current" != "$(cat "$owned" 2>/dev/null)" ]; then+ if [ "$current" != "$(game_drive_record)" ]; thenecho "=== drive S: already points to $current, left in place ===" >> "$log" 2>&1 || truereturn 0fi@@ -832,8 +863,9 @@ map_game_drive() {return 0fiif ln -s "$target" "$drive" 2>> "$log"; then- printf '%s\n' "$target" > "$owned" 2>/dev/null || true+ record_game_drive "$target"echo "=== mapped drive S: to $target ===" >> "$log" 2>&1 || true+ restart_for_driveelseecho "=== could not map drive S: to $target ===" >> "$log" 2>&1 || truefi@@ -868,8 +900,11 @@ if [ -n "$STEAM_COMPAT_DATA_PATH" ]; thenexit 1fiecho "video: RetinaMode=${NOTPROTON_RETINA:-0}" >> "$log" 2>&1 || true+ stage_step="game drive"+ map_game_drivestage_step="prefix settings"import_prefix_settings+ # A prefix that Wine built just now only has dosdevices from this point on.stage_step="game drive"map_game_drivefidiff --git a/dylib/tests/gamedrivecheck.sh b/dylib/tests/gamedrivecheck.shindex fbeff1f..e72b94b 100644--- a/dylib/tests/gamedrivecheck.sh+++ b/dylib/tests/gamedrivecheck.sh@@ -4,8 +4,10 @@ set -eSRC="${1:-$(dirname "$0")/../feats/compat_run.sh}"[ -f "$SRC" ] || { echo "gamedrivecheck: $SRC not present, skipped"; exit 0; }-body=$(sed -n '/^map_game_drive() {/,/^}/p' "$SRC")+body=$(sed -n '/^game_drive_record() {/,/^}/p;/^record_game_drive() {/,/^}/p;/^restart_for_drive() {/,/^}/p;/^unmap_game_drive() {/,/^}/p;/^map_game_drive() {/,/^}/p' "$SRC")[ -n "$body" ] || { echo "FAIL: map_game_drive not found in $SRC"; exit 1; }+body='without_lock_fds() { printf "%s\n" "${1##*/} $2" >> "$restarts"; }+'"$body"work=$(cd "$(mktemp -d)" && pwd -P)trap 'rm -rf "$work"' EXIT@@ -26,32 +28,38 @@ libs="$work/elsewhere/steamapps:$lib/steamapps/"run() {: > "$work/log"- env WINEPREFIX="$prefix" STEAM_COMPAT_DATA_PATH="$compat" log="$work/log" body="$body" \+ : > "$work/restarts"+ env restarts="$work/restarts" WINESERVER=/runner/wineserver WINEPREFIX="$prefix" STEAM_COMPAT_DATA_PATH="$compat" log="$work/log" body="$body" \STEAM_COMPAT_INSTALL_PATH="$1" STEAM_COMPAT_LIBRARY_PATHS="$2" \- sh -ec 'eval "$body"; map_game_drive; echo reached' > "$work/out" 2>&1 || true+ extra="${3:-}" sh -ec 'eval "$body"; eval "$extra"; map_game_drive; echo reached' > "$work/out" 2>&1 || true}target() { readlink "$drive" 2>/dev/null || echo none; }+restarted() { tr '\n' ' ' < "$work/restarts"; }echo "== the library holding the game becomes S:"run "$lib/steamapps/common/Some Game" "$libs"is "S: points at the library root" "$lib" "$(target)"is "the launch continues" reached "$(tail -1 "$work/out")"is "the mapping is recorded" "$lib" "$(cat "$compat/notproton-game-drive")"+is "wine restarts to see S:" "wineserver -k wineserver -w " "$(restarted)"echo "== a second launch leaves it alone"run "$lib/steamapps/common/Some Game" "$libs"is "S: is unchanged" "$lib" "$(target)"is "nothing is logged" "" "$(cat "$work/log")"+is "wine is not restarted" "" "$(restarted)"echo "== a moved game follows its library"run "$other/steamapps/common/Some Game" "$libs:$other/steamapps"is "S: points at the new library" "$other" "$(target)"+is "wine restarts to see the move" "wineserver -k wineserver -w " "$(restarted)"echo "== a user's own S: is kept"rm -f "$drive"ln -s /tmp "$drive"run "$lib/steamapps/common/Some Game" "$libs"is "S: still points at /tmp" /tmp "$(target)"+is "wine is not restarted" "" "$(restarted)"is "the launch continues" reached "$(tail -1 "$work/out")"echo "== an S: folder is kept"@@ -59,28 +67,85 @@ rm -f "$drive"mkdir "$drive"run "$lib/steamapps/common/Some Game" "$libs"is "S: is still a folder" yes "$([ -d "$drive" ] && [ ! -L "$drive" ] && echo yes)"+is "the launch continues" reached "$(tail -1 "$work/out")"rmdir "$drive"+echo "== a game that left every library loses its S:"+run "$lib/steamapps/common/Some Game" "$libs"+run "$work/loose/Some Game" "$libs"+is "no S:" none "$(target)"+is "the record is gone" no "$([ -e "$compat/notproton-game-drive" ] && echo yes || echo no)"+is "wine restarts to drop S:" "wineserver -k wineserver -w " "$(restarted)"+is "the launch continues" reached "$(tail -1 "$work/out")"+echo "== a game outside every library gets no S:"-rm -f "$compat/notproton-game-drive"run "$work/loose/Some Game" "$libs"is "no S:" none "$(target)"is "the launch continues" reached "$(tail -1 "$work/out")"+is "wine is not restarted" "" "$(restarted)"++echo "== a user's own S: survives a game outside every library"+ln -s /tmp "$drive"+run "$work/loose/Some Game" "$libs"+is "S: still points at /tmp" /tmp "$(target)"+is "wine is not restarted" "" "$(restarted)"+rm -f "$drive"++echo "== a recorded S: deleted by hand comes back"+run "$lib/steamapps/common/Some Game" "$libs"+rm -f "$drive"+run "$lib/steamapps/common/Some Game" "$libs"+is "S: points at the library root" "$lib" "$(target)"+is "wine restarts to see S:" "wineserver -k wineserver -w " "$(restarted)"++echo "== a failed link keeps the launch going without a restart"+rm -f "$drive"+run "$lib/steamapps/common/Some Game" "$libs" 'ln() { return 1; }'+is "no S:" none "$(target)"+is "the failure is logged" yes "$(grep -q 'could not map drive S:' "$work/log" && echo yes)"+is "wine is not restarted" "" "$(restarted)"+is "the launch continues" reached "$(tail -1 "$work/out")"++echo "== empty library entries are skipped"+run "$lib/steamapps/common/Some Game" "::$lib/steamapps::"+is "S: points at the library root" "$lib" "$(target)"+is "the launch continues" reached "$(tail -1 "$work/out")"+rm -f "$drive"++echo "== a library whose parent is not writable maps steamapps itself"+mkdir -p "$work/locked/steamapps/common/Some Game"+chmod a-w "$work/locked"+run "$work/locked/steamapps/common/Some Game" "$work/locked/steamapps"+chmod u+w "$work/locked"+is "S: points at steamapps" "$work/locked/steamapps" "$(target)"+is "the launch continues" reached "$(tail -1 "$work/out")"+rm -f "$drive"++echo "== a library on another volume than its parent maps steamapps itself"+mkdir -p "$work/far/steamapps/common/Some Game"+run "$work/far/steamapps/common/Some Game" "$work/far/steamapps" \+ 'stat() { case "$3" in */steamapps) echo 2 ;; *) echo 1 ;; esac; }'+is "S: points at steamapps" "$work/far/steamapps" "$(target)"+is "the launch continues" reached "$(tail -1 "$work/out")"+rm -f "$drive"echo "== a library whose name only starts the same does not match"run "$lib/steamapps2/common/Some Game" "$lib/steamapps"is "no S:" none "$(target)"+is "the launch continues" reached "$(tail -1 "$work/out")"echo "== a library path that is not a steamapps folder maps as is"mkdir -p "$work/flat/common/Some Game"run "$work/flat/common/Some Game" "$work/flat"is "S: points at the library itself" "$work/flat" "$(target)"+is "the launch continues" reached "$(tail -1 "$work/out")"rm -f "$drive"echo "== a prefix without dosdevices is left for wine to build"mv "$prefix/dosdevices" "$prefix/dosdevices.off"run "$lib/steamapps/common/Some Game" "$libs"is "no dosdevices created" no "$([ -e "$prefix/dosdevices" ] && echo yes || echo no)"+is "the launch continues" reached "$(tail -1 "$work/out")"mv "$prefix/dosdevices.off" "$prefix/dosdevices"[ "$fails" -eq 0 ] || { echo "gamedrivecheck: $fails failed"; exit 1; }diff --git a/dylib/tests/seedcheck.sh b/dylib/tests/seedcheck.shindex 3352cbb..9b02b49 100644--- a/dylib/tests/seedcheck.sh+++ b/dylib/tests/seedcheck.sh@@ -198,6 +198,23 @@ check prefix_is_bareln -s /outside "$WINEPREFIX/dosdevices/d:"check test "$(prefix_is_bare && echo unsafe || echo refused)" = refused+fixture+mkdir -p "$WINEPREFIX/dosdevices" "$template_dir/pfx/dosdevices"+for dir in "$WINEPREFIX" "$template_dir/pfx"; do+ ln -s ../drive_c "$dir/dosdevices/c:"+ ln -s / "$dir/dosdevices/z:"+done+ln -s /library "$WINEPREFIX/dosdevices/s:"+check test "$(prefix_is_bare && echo unsafe || echo refused)" = refused+printf '/elsewhere\n' > "$STEAM_COMPAT_DATA_PATH/notproton-game-drive"+check test "$(prefix_is_bare && echo unsafe || echo refused)" = refused+printf '/library\n' > "$STEAM_COMPAT_DATA_PATH/notproton-game-drive"+check prefix_is_bare+copy_template_into_prefix+check test -f "$WINEPREFIX/system.reg"+check test "$(readlink "$WINEPREFIX/dosdevices/s:")" = /library+check test "$(readlink "$WINEPREFIX/dosdevices/c:")" = ../drive_c+fixturemkdir -p "$WINEPREFIX/drive_c/users/steamuser"mkfifo "$WINEPREFIX/drive_c/users/steamuser/fifo"