From 975875265c316fcc590e78b720a5eeaf3c2f5172 Mon Sep 17 00:00:00 2001 From: Andrew Eikum Date: Mon, 29 Jul 2019 12:33:18 -0500 Subject: [PATCH] proton: Swap global CompatData references for instance --- proton | 117 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 58 insertions(+), 59 deletions(-) diff --git a/proton b/proton index 2383b65f..f56ea531 100755 --- a/proton +++ b/proton @@ -145,15 +145,15 @@ class CompatData: def path(self, d): return self.base_dir + d - def remove_tracked_files(self, prefix): - if not os.path.exists(prefix + "/tracked_files"): + def remove_tracked_files(self): + if not os.path.exists(self.tracked_files_file): log("Prefix has no tracked_files??") return - with open(prefix + "/tracked_files", "r") as tracked_files: + with open(self.tracked_files_file, "r") as tracked_files: dirs = [] for f in tracked_files: - path = prefix + "/pfx/" + f.strip() + path = self.prefix_dir + f.strip() if os.path.exists(path): if os.path.isfile(path) or os.path.islink(path): os.remove(path) @@ -166,14 +166,14 @@ class CompatData: #not empty pass - os.remove(prefix + "/tracked_files") - os.remove(prefix + "/version") + os.remove(self.tracked_files_file) + os.remove(self.version_file) def upgrade_pfx(self, old_ver): if old_ver == CURRENT_PREFIX_VERSION: return - log("Upgrading prefix from " + str(old_ver) + " to " + CURRENT_PREFIX_VERSION + " (" + g_compatdata.base_dir + ")") + log("Upgrading prefix from " + str(old_ver) + " to " + CURRENT_PREFIX_VERSION + " (" + self.base_dir + ")") if old_ver is None: return @@ -194,53 +194,54 @@ class CompatData: (int(new_proton_maj) == int(old_proton_maj) and \ int(new_proton_min) < int(old_proton_min)): log("Removing newer prefix") - if old_proton_ver == "3.7" and not os.path.exists(g_compatdata.tracked_files_file): + if old_proton_ver == "3.7" and not os.path.exists(self.tracked_files_file): #proton 3.7 did not generate tracked_files, so copy it into place first - try_copy(g_proton.path("proton_3.7_tracked_files"), g_compatdata.tracked_files_file) - self.remove_tracked_files(g_compatdata.base_dir) + try_copy(g_proton.path("proton_3.7_tracked_files"), self.tracked_files_file) + self.remove_tracked_files() return if old_proton_ver == "3.7" and old_prefix_ver == "1": - if not os.path.exists(g_compatdata.prefix_dir + "/drive_c/windows/syswow64/kernel32.dll"): + if not os.path.exists(self.prefix_dir + "/drive_c/windows/syswow64/kernel32.dll"): #shipped a busted 64-bit-only installation on 20180822. detect and wipe clean log("Detected broken 64-bit-only installation, re-creating prefix.") - shutil.rmtree(g_compatdata.prefix_dir) + shutil.rmtree(self.prefix_dir) return #replace broken .NET installations with wine-mono support - if os.path.exists(g_compatdata.prefix_dir + "/drive_c/windows/Microsoft.NET/NETFXRepair.exe") and \ - file_is_wine_fake_dll(g_compatdata.prefix_dir + "/drive_c/windows/system32/mscoree.dll"): + if os.path.exists(self.prefix_dir + "/drive_c/windows/Microsoft.NET/NETFXRepair.exe") and \ + file_is_wine_fake_dll(self.prefix_dir + "/drive_c/windows/system32/mscoree.dll"): log("Broken .NET installation detected, switching to wine-mono.") #deleting this directory allows wine-mono to work - shutil.rmtree(g_compatdata.prefix_dir + "/drive_c/windows/Microsoft.NET") + shutil.rmtree(self.prefix_dir + "/drive_c/windows/Microsoft.NET") except ValueError: log("Prefix has an invalid version?! You may want to back up user files and delete this prefix.") #Just let the Wine upgrade happen and hope it works... return - def mergedirs(self, src, dst, tracked_files): - for src_dir, dirs, files in os.walk(src): - rel_dir = src_dir.replace(src, "", 1).lstrip('/') - if len(rel_dir) > 0: - rel_dir = rel_dir + "/" - dst_dir = src_dir.replace(src, dst, 1) - if not os.path.exists(dst_dir): - os.makedirs(dst_dir) - tracked_files.write(rel_dir + "\n") - for dir_ in dirs: - src_file = os.path.join(src_dir, dir_) - dst_file = os.path.join(dst_dir, dir_) - if os.path.islink(src_file) and not os.path.exists(dst_file): - real_copy(src_file, dst_file) - for file_ in files: - src_file = os.path.join(src_dir, file_) - dst_file = os.path.join(dst_dir, file_) - if not os.path.exists(dst_file): - real_copy(src_file, dst_file) - tracked_files.write(rel_dir + file_ + "\n") + def copy_pfx(self): + with open(self.tracked_files_file, "w") as tracked_files: + for src_dir, dirs, files in os.walk(g_proton.default_pfx_dir): + rel_dir = src_dir.replace(g_proton.default_pfx_dir, "", 1).lstrip('/') + if len(rel_dir) > 0: + rel_dir = rel_dir + "/" + dst_dir = src_dir.replace(g_proton.default_pfx_dir, self.prefix_dir, 1) + if not os.path.exists(dst_dir): + os.makedirs(dst_dir) + tracked_files.write(rel_dir + "\n") + for dir_ in dirs: + src_file = os.path.join(src_dir, dir_) + dst_file = os.path.join(dst_dir, dir_) + if os.path.islink(src_file) and not os.path.exists(dst_file): + real_copy(src_file, dst_file) + for file_ in files: + src_file = os.path.join(src_dir, file_) + dst_file = os.path.join(dst_dir, file_) + if not os.path.exists(dst_file): + real_copy(src_file, dst_file) + tracked_files.write(rel_dir + file_ + "\n") - def create_fonts_symlinks(self, prefix_path): + def create_fonts_symlinks(self): fontsmap = [ ( "LiberationSans-Regular.ttf", "arial.ttf" ), ( "LiberationSans-Bold.ttf", "arialbd.ttf" ), @@ -248,7 +249,7 @@ class CompatData: ( "LiberationMono-Regular.ttf", "cour.ttf" ), ] - windowsfonts = prefix_path + "/drive_c/windows/Fonts" + windowsfonts = self.prefix_dir + "/drive_c/windows/Fonts" makedirs(windowsfonts) for p in fontsmap: lname = os.path.join(windowsfonts, p[1]) @@ -261,27 +262,25 @@ class CompatData: os.symlink(fname, lname) def setup_prefix(self, config_opts): - with g_compatdata.prefix_lock: - if os.path.exists(g_compatdata.version_file): - with open(g_compatdata.version_file, "r") as f: + with self.prefix_lock: + if os.path.exists(self.version_file): + with open(self.version_file, "r") as f: self.upgrade_pfx(f.readline().strip()) else: self.upgrade_pfx(None) - if not os.path.exists(g_compatdata.prefix_dir): - makedirs(g_compatdata.prefix_dir + "/drive_c") - set_dir_casefold_bit(g_compatdata.prefix_dir + "/drive_c") + if not os.path.exists(self.prefix_dir): + makedirs(self.prefix_dir + "/drive_c") + set_dir_casefold_bit(self.prefix_dir + "/drive_c") - if not os.path.exists(g_compatdata.prefix_dir + "/user.reg"): - #copy default prefix into place - with open(g_compatdata.tracked_files_file, "w") as tfiles: - self.mergedirs(g_proton.default_pfx_dir, g_compatdata.prefix_dir, tfiles) + if not os.path.exists(self.prefix_dir + "/user.reg"): + self.copy_pfx() - with open(g_compatdata.version_file, "w") as f: + with open(self.version_file, "w") as f: f.write(CURRENT_PREFIX_VERSION + "\n") #create font files symlinks - self.create_fonts_symlinks(g_compatdata.prefix_dir) + self.create_fonts_symlinks() #copy steam files into place if "STEAM_COMPAT_CLIENT_INSTALL_PATH" in os.environ: @@ -290,7 +289,7 @@ class CompatData: else: #linux-only fallback, really shouldn't get here steamdir = os.environ["HOME"] + ".steam/root/" - dst = g_compatdata.prefix_dir + "/drive_c/Program Files (x86)/" + dst = self.prefix_dir + "/drive_c/Program Files (x86)/" makedirs(dst + "Steam") filestocopy = ["steamclient.dll", "steamclient64.dll", @@ -303,13 +302,13 @@ class CompatData: try_copy(steamdir + "/legacycompat/" + f, dstfile) #copy openvr files into place - dst = g_compatdata.prefix_dir + "/drive_c/vrclient/bin/" + dst = self.prefix_dir + "/drive_c/vrclient/bin/" makedirs(dst) try_copy(g_proton.lib_dir + "wine/fakedlls/vrclient.dll", dst) try_copy(g_proton.lib64_dir + "wine/fakedlls/vrclient_x64.dll", dst) - try_copy(g_proton.lib_dir + "wine/dxvk/openvr_api_dxvk.dll", g_compatdata.prefix_dir + "/drive_c/windows/syswow64/") - try_copy(g_proton.lib64_dir + "wine/dxvk/openvr_api_dxvk.dll", g_compatdata.prefix_dir + "/drive_c/windows/system32/") + try_copy(g_proton.lib_dir + "wine/dxvk/openvr_api_dxvk.dll", self.prefix_dir + "/drive_c/windows/syswow64/") + try_copy(g_proton.lib64_dir + "wine/dxvk/openvr_api_dxvk.dll", self.prefix_dir + "/drive_c/windows/system32/") #parse linux openvr config and present it in win32 format to the app. #logic from openvr's CVRPathRegistry_Public::GetPaths @@ -352,10 +351,10 @@ class CompatData: except (TypeError, ValueError, OSError): log("Missing or invalid openvrpaths.vrpath file! " + str(sys.exc_info()[1])) - makedirs(g_compatdata.prefix_dir + "/drive_c/users/steamuser/Local Settings/Application Data/openvr") + makedirs(self.prefix_dir + "/drive_c/users/steamuser/Local Settings/Application Data/openvr") #remove existing file - vrpaths_name = g_compatdata.prefix_dir + "/drive_c/users/steamuser/Local Settings/Application Data/openvr/openvrpaths.vrpath" + vrpaths_name = self.prefix_dir + "/drive_c/users/steamuser/Local Settings/Application Data/openvr/openvrpaths.vrpath" if os.path.exists(vrpaths_name): os.remove(vrpaths_name) @@ -395,15 +394,15 @@ class CompatData: for f in wined3dfiles: try_copy(g_proton.default_pfx_dir + "drive_c/windows/system32/" + f + ".dll", - g_compatdata.prefix_dir + "drive_c/windows/system32/" + f + ".dll") + self.prefix_dir + "drive_c/windows/system32/" + f + ".dll") try_copy(g_proton.default_pfx_dir + "drive_c/windows/syswow64/" + f + ".dll", - g_compatdata.prefix_dir + "drive_c/windows/syswow64/" + f + ".dll") + self.prefix_dir + "drive_c/windows/syswow64/" + f + ".dll") for f in dxvkfiles: try_copy(g_proton.lib64_dir + "wine/dxvk/" + f + ".dll", - g_compatdata.prefix_dir + "drive_c/windows/system32/" + f + ".dll") + self.prefix_dir + "drive_c/windows/system32/" + f + ".dll") try_copy(g_proton.lib_dir + "wine/dxvk/" + f + ".dll", - g_compatdata.prefix_dir + "drive_c/windows/syswow64/" + f + ".dll") + self.prefix_dir + "drive_c/windows/syswow64/" + f + ".dll") dlloverrides[f] = "n"