@@ -36,15 +36,114 @@ from ctypes import c_ssize_t
36
36
37
37
from filelock import FileLock
38
38
from random import randrange
39
+ from pathlib import Path
39
40
40
41
#To enable debug logging, copy "user_settings.sample.py" to "user_settings.py"
41
42
#and edit it if needed.
42
43
43
- CURRENT_PREFIX_VERSION = "ULWGL -Proton-9.0-200-1 "
44
+ CURRENT_PREFIX_VERSION = "UMU -Proton-9.0-200-2 "
44
45
45
46
PFX = "Proton: "
46
47
ld_path_var = "LD_LIBRARY_PATH"
47
48
49
+ def empty_directory (path ):
50
+ # Walk through the directory structure top-down (False)
51
+ for root , dirs , files in os .walk (path , topdown = False ):
52
+ # Remove files and symlinks to files
53
+ for name in files :
54
+ item_path = os .path .join (root , name )
55
+ if os .path .islink (item_path ):
56
+ os .remove (item_path ) # Remove symlink
57
+ else :
58
+ os .remove (item_path ) # Remove file
59
+ # Remove directories and symlinks to directories
60
+ for name in dirs :
61
+ item_path = os .path .join (root , name )
62
+ if os .path .islink (item_path ):
63
+ os .remove (item_path ) # Remove symlink
64
+ else :
65
+ os .rmdir (item_path ) # Remove directory
66
+
67
+ # If -steamdeck mode is enabled, try to copy existing game prefixes to steamdeck's prefix location -- this helps to preserve mods and saves across systems
68
+ # Note: this completely wipes the existing destination prefix and copies the source prefix over instead.
69
+
70
+ # source = game partition, destination = steamdeck prefix location
71
+ # From game partition to steamdeck (steamdeck enabled)
72
+ if os .getenv ("SteamDeck" ) == "1" and os .getenv ("COPYPREFIX" ) == "1" :
73
+ # Get the value of the STEAM_COMPAT_INSTALL_PATH environment variable
74
+ steam_compat_install_path = os .getenv ('STEAM_COMPAT_INSTALL_PATH' )
75
+
76
+ # Navigate up two directories
77
+ parent_directory = Path (steam_compat_install_path ).parents [1 ]
78
+
79
+ # Check if the "compatdata/<steam game>" folder exists and is not empty
80
+ compatdata_path = parent_directory / "compatdata" / str (os .environ .get ("SteamAppId" , 0 ))
81
+ if compatdata_path .exists () and os .listdir (compatdata_path ):
82
+ # Define the destination directory
83
+ steamdeck_compatdata = Path (os .environ ["STEAM_BASE_FOLDER" ]) / "steamapps" / "compatdata" / str (os .environ .get ("SteamAppId" , 0 ))
84
+
85
+ # Remove destination if it already exists:
86
+ if os .path .isdir (steamdeck_compatdata ) and os .listdir (steamdeck_compatdata ):
87
+ empty_directory (steamdeck_compatdata )
88
+
89
+ # Copy the "compatdata/<steam game>" folder to the destination directory
90
+ # Use dirs_exist_ok=True to avoid FileExistsError if the destination directory already exists
91
+ shutil .copytree (compatdata_path , steamdeck_compatdata , dirs_exist_ok = True , symlinks = True )
92
+
93
+ # Check if the "shadercache/<steam game>" folder exists and is not empty
94
+ shadercache_path = parent_directory / "shadercache" / str (os .environ .get ("SteamAppId" , 0 ))
95
+
96
+ if shadercache_path .exists () and os .listdir (shadercache_path ):
97
+ # Define the destination directory
98
+ steamdeck_shadercache = Path (os .environ ["STEAM_BASE_FOLDER" ]) / "steamapps" / "shadercache" / str (os .environ .get ("SteamAppId" , 0 ))
99
+
100
+ # Remove destination if it already exists:
101
+ if os .path .isdir (steamdeck_shadercache ) and os .listdir (steamdeck_shadercache ):
102
+ empty_directory (steamdeck_shadercache )
103
+
104
+ # Copy the "shadercache/<steam game>" folder to the destination directory
105
+ # Use dirs_exist_ok=True to avoid FileExistsError if the destination directory already exists
106
+ shutil .copytree (shadercache_path , steamdeck_shadercache , dirs_exist_ok = True , symlinks = True )
107
+
108
+ # source = steamdeck prefix location, destination = game partition
109
+ # From steamdeck to game partition (steamdeck disabled)
110
+ if os .getenv ("SteamDeck" ) == "0" or "SteamDeck" not in os .environ :
111
+ if os .getenv ("COPYPREFIX" ) == "1" :
112
+ # Get the value of the STEAM_COMPAT_INSTALL_PATH environment variable
113
+ steam_compat_install_path = os .getenv ('STEAM_COMPAT_INSTALL_PATH' )
114
+
115
+ # Navigate up two directories
116
+ parent_directory = Path (steam_compat_install_path ).parents [1 ]
117
+
118
+ # Check if the "compatdata/<steam game>" folder exists and is not empty
119
+ steamdeck_compatdata = Path (os .environ ["STEAM_BASE_FOLDER" ]) / "steamapps" / "compatdata" / str (os .environ .get ("SteamAppId" , 0 ))
120
+ if os .path .isdir (steamdeck_compatdata ) and os .listdir (steamdeck_compatdata ):
121
+ # Define the destination directory
122
+ compatdata_path = parent_directory / "compatdata" / str (os .environ .get ("SteamAppId" , 0 ))
123
+
124
+ # Remove destination if it already exists:
125
+ if os .path .isdir (compatdata_path ) and os .listdir (compatdata_path ):
126
+ empty_directory (compatdata_path )
127
+
128
+ # Copy the steamdeck_compatdata to the compatdata_path
129
+ # Use dirs_exist_ok=True to avoid FileExistsError if the destination directory already exists
130
+ shutil .copytree (steamdeck_compatdata , compatdata_path , dirs_exist_ok = True , symlinks = True )
131
+
132
+ # Similar logic for shadercache
133
+ steamdeck_shadercache = Path (os .environ ["STEAM_BASE_FOLDER" ]) / "steamapps" / "shadercache" / str (os .environ .get ("SteamAppId" , 0 ))
134
+
135
+ if os .path .isdir (steamdeck_shadercache ) and os .listdir (steamdeck_shadercache ):
136
+ # Define the destination directory
137
+ shadercache_path = parent_directory / "shadercache" / str (os .environ .get ("SteamAppId" , 0 ))
138
+
139
+ # Remove destination if it already exists:
140
+ if os .path .isdir (shadercache_path ) and os .listdir (shadercache_path ):
141
+ empty_directory (shadercache_path )
142
+
143
+ # Copy the steamdeck_shadercache to the shadercache_path
144
+ # Use dirs_exist_ok=True to avoid FileExistsError if the destination directory already exists
145
+ shutil .copytree (steamdeck_shadercache , shadercache_path , dirs_exist_ok = True , symlinks = True )
146
+
48
147
def file_exists (s , * , follow_symlinks ):
49
148
if follow_symlinks :
50
149
#'exists' returns False on broken symlinks
0 commit comments