forked from GloriousEggroll/proton-ge-custom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
proton
executable file
·1500 lines (1299 loc) · 61.6 KB
/
proton
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
#script to launch Wine with the correct environment
import fcntl
import array
import filecmp
import fnmatch
import json
import os
import shutil
import errno
import stat
import subprocess
import sys
import tarfile
from ctypes import CDLL
from ctypes import POINTER
from ctypes import Structure
from ctypes import addressof
from ctypes import cast
from ctypes import c_int
from ctypes import c_char_p
from ctypes import c_void_p
from filelock import FileLock
from random import randrange
#To enable debug logging, copy "user_settings.sample.py" to "user_settings.py"
#and edit it if needed.
CURRENT_PREFIX_VERSION="6.14-GE-3"
PFX="Proton: "
ld_path_var = "LD_LIBRARY_PATH"
def nonzero(s):
return len(s) > 0 and s != "0"
def prepend_to_env_str(env, variable, prepend_str, separator):
if not variable in env:
env[variable] = prepend_str
else:
env[variable] = prepend_str + separator + env[variable]
def append_to_env_str(env, variable, append_str, separator):
if not variable in env:
env[variable] = append_str
else:
env[variable] = env[variable] + separator + append_str
def log(msg):
sys.stderr.write(PFX + msg + os.linesep)
sys.stderr.flush()
def file_is_wine_builtin_dll(path):
if os.path.islink(path):
contents = os.readlink(path)
if os.path.dirname(contents).endswith(('/lib/wine/i386-windows', '/lib64/wine/x86_64-windows')):
# This may be a broken link to a dll in a removed Proton install
return True
if not os.path.exists(path):
return False
try:
sfile = open(path, "rb")
sfile.seek(0x40)
tag = sfile.read(20)
return tag.startswith((b"Wine placeholder DLL", b"Wine builtin DLL"))
except IOError:
return False
def makedirs(path):
try:
os.makedirs(path)
except OSError:
#already exists
pass
def merge_user_dir(src, dst):
extant_dirs = []
for src_dir, dirs, files in os.walk(src):
dst_dir = src_dir.replace(src, dst, 1)
#as described below, avoid merging game save subdirs, too
child_of_extant_dir = False
for dir_ in extant_dirs:
if dir_ in dst_dir:
child_of_extant_dir = True
break
if child_of_extant_dir:
continue
#we only want to copy into directories which don't already exist. games
#may not react well to two save directory instances being merged.
if not os.path.exists(dst_dir) or os.path.samefile(dst_dir, dst):
makedirs(dst_dir)
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):
try_copy(src_file, dst_file, copy_metadata=True)
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):
try_copy(src_file, dst_file, copy_metadata=True)
else:
extant_dirs += dst_dir
def try_copy(src, dst, add_write_perm=True, copy_metadata=True, optional=False):
try:
if os.path.isdir(dst):
dstfile = dst + "/" + os.path.basename(src)
if os.path.lexists(dstfile):
os.remove(dstfile)
else:
dstfile = dst
if os.path.lexists(dst):
os.remove(dst)
if copy_metadata:
shutil.copy2(src, dst)
else:
shutil.copy(src, dst)
if add_write_perm:
new_mode = os.lstat(dstfile).st_mode | stat.S_IWUSR | stat.S_IWGRP
os.chmod(dstfile, new_mode)
except FileNotFoundError as e:
if optional:
log('Error while copying to \"' + dst + '\": ' + e.strerror)
else:
raise
except PermissionError as e:
if e.errno == errno.EPERM:
#be forgiving about permissions errors; if it's a real problem, things will explode later anyway
log('Error while copying to \"' + dst + '\": ' + e.strerror)
else:
raise
def try_copyfile(src, dst):
try:
if os.path.isdir(dst):
dstfile = dst + "/" + os.path.basename(src)
if os.path.lexists(dstfile):
os.remove(dstfile)
elif os.path.lexists(dst):
os.remove(dst)
shutil.copyfile(src, dst)
except PermissionError as e:
if e.errno == errno.EPERM:
#be forgiving about permissions errors; if it's a real problem, things will explode later anyway
log('Error while copying to \"' + dst + '\": ' + e.strerror)
else:
raise
def getmtimestr(*path_fragments):
path = os.path.join(*path_fragments)
try:
return str(os.path.getmtime(path))
except IOError:
return "0"
def try_get_game_library_dir():
if not "STEAM_COMPAT_INSTALL_PATH" in g_session.env or \
not "STEAM_COMPAT_LIBRARY_PATHS" in g_session.env:
return None
#find library path which is a subset of the game path
library_paths = g_session.env["STEAM_COMPAT_LIBRARY_PATHS"].split(":")
for l in library_paths:
if l in g_session.env["STEAM_COMPAT_INSTALL_PATH"]:
return l
return None
# Function to find the installed location of DLL files for use by Wine/Proton
# from the NVIDIA Linux driver
#
# See https://gitlab.steamos.cloud/steamrt/steam-runtime-tools/-/issues/71 for
# background on the chosen method of DLL discovery.
#
# On success, returns a str() of the absolute-path to the directory at which DLL
# files are stored
#
# On failure, returns None
def find_nvidia_wine_dll_dir():
try:
libdl = CDLL("libdl.so.2")
except (OSError):
return None
try:
libglx_nvidia = CDLL("libGLX_nvidia.so.0")
except OSError:
return None
# from dlinfo(3)
#
# struct link_map {
# ElfW(Addr) l_addr; /* Difference between the
# address in the ELF file and
# the address in memory */
# char *l_name; /* Absolute pathname where
# object was found */
# ElfW(Dyn) *l_ld; /* Dynamic section of the
# shared object */
# struct link_map *l_next, *l_prev;
# /* Chain of loaded objects */
#
# /* Plus additional fields private to the
# implementation */
# };
RTLD_DI_LINKMAP = 2
class link_map(Structure):
_fields_ = [("l_addr", c_void_p), ("l_name", c_char_p), ("l_ld", c_void_p)]
# from dlinfo(3)
#
# int dlinfo (void *restrict handle, int request, void *restrict info)
dlinfo_func = libdl.dlinfo
dlinfo_func.argtypes = c_void_p, c_int, c_void_p
dlinfo_func.restype = c_int
# Allocate a link_map object
glx_nvidia_info_ptr = POINTER(link_map)()
# Run dlinfo(3) on the handle to libGLX_nvidia.so.0, storing results at the
# address represented by glx_nvidia_info_ptr
if dlinfo_func(libglx_nvidia._handle,
RTLD_DI_LINKMAP,
addressof(glx_nvidia_info_ptr)) != 0:
return None
# Grab the contents our of our pointer
glx_nvidia_info = cast(glx_nvidia_info_ptr, POINTER(link_map)).contents
# Decode the path to our library to a str()
if glx_nvidia_info.l_name is None:
return None
try:
libglx_nvidia_path = os.fsdecode(glx_nvidia_info.l_name)
except UnicodeDecodeError:
return None
# Follow any symlinks to the actual file
libglx_nvidia_realpath = os.path.realpath(libglx_nvidia_path)
# Go to the relative path ./nvidia/wine from our library
nvidia_wine_dir = os.path.join(os.path.dirname(libglx_nvidia_realpath), "nvidia", "wine")
# Check that nvngx.dll exists here, or fail
if os.path.exists(os.path.join(nvidia_wine_dir, "nvngx.dll")):
return nvidia_wine_dir
return None
EXT2_IOC_GETFLAGS = 0x80086601
EXT2_IOC_SETFLAGS = 0x40086602
EXT4_CASEFOLD_FL = 0x40000000
def set_dir_casefold_bit(dir_path):
dr = os.open(dir_path, 0o644)
if dr < 0:
return
try:
dat = array.array('I', [0])
if fcntl.ioctl(dr, EXT2_IOC_GETFLAGS, dat, True) >= 0:
dat[0] = dat[0] | EXT4_CASEFOLD_FL
fcntl.ioctl(dr, EXT2_IOC_SETFLAGS, dat, False)
except (OSError, IOError):
#no problem
pass
os.close(dr)
class Proton:
def __init__(self, base_dir):
self.base_dir = base_dir + "/"
self.dist_dir = self.path("files/")
self.bin_dir = self.path("files/bin/")
self.lib_dir = self.path("files/lib/")
self.lib64_dir = self.path("files/lib64/")
self.fonts_dir = self.path("files/share/fonts/")
self.wine_fonts_dir = self.path("files/share/wine/fonts/")
self.version_file = self.path("version")
self.default_pfx_dir = self.path("files/share/default_pfx/")
self.user_settings_file = self.path("user_settings.py")
self.wine_bin = self.bin_dir + "wine"
self.wine64_bin = self.bin_dir + "wine64"
self.wineserver_bin = self.bin_dir + "wineserver"
self.dist_lock = FileLock(self.path("dist.lock"), timeout=-1)
def path(self, d):
return self.base_dir + d
def cleanup_legacy_dist(self):
old_dist_dir = self.path("dist/")
if os.path.exists(old_dist_dir):
with self.dist_lock:
if os.path.exists(old_dist_dir):
shutil.rmtree(old_dist_dir)
def do_steampipe_fixups(self):
fixups_json = self.path("steampipe_fixups.json")
fixups_mtime = self.path("files/steampipe_fixups_mtime")
if os.path.exists(fixups_json):
with self.dist_lock:
import steampipe_fixups
current_fixup_mtime = None
if os.path.exists(fixups_mtime):
with open(fixups_mtime, "r") as f:
current_fixup_mtime = f.readline().strip()
new_fixup_mtime = getmtimestr(fixups_json)
if current_fixup_mtime != new_fixup_mtime:
result_code = steampipe_fixups.do_restore(self.base_dir, fixups_json)
if result_code == 0:
with open(fixups_mtime, "w") as f:
f.write(new_fixup_mtime + "\n")
def missing_default_prefix(self):
'''Check if the default prefix dir is missing. Returns true if missing, false if present'''
return not os.path.isdir(self.default_pfx_dir)
def make_default_prefix(self):
with self.dist_lock:
local_env = dict(g_session.env)
if self.missing_default_prefix():
#make default prefix
local_env["WINEPREFIX"] = self.default_pfx_dir
local_env["WINEDEBUG"] = "-all"
g_session.run_proc([self.wine64_bin, "wineboot"], local_env)
g_session.run_proc([self.wineserver_bin, "-w"], local_env)
class CompatData:
def __init__(self, compatdata):
self.base_dir = compatdata + "/"
self.prefix_dir = self.path("pfx/")
self.version_file = self.path("version")
self.config_info_file = self.path("config_info")
self.tracked_files_file = self.path("tracked_files")
self.prefix_lock = FileLock(self.path("pfx.lock"), timeout=-1)
def path(self, d):
return self.base_dir + d
def remove_tracked_files(self):
if not os.path.exists(self.tracked_files_file):
log("Prefix has no tracked_files??")
return
with open(self.tracked_files_file, "r") as tracked_files:
dirs = []
for f in tracked_files:
path = self.prefix_dir + f.strip()
if os.path.exists(path):
if os.path.isfile(path) or os.path.islink(path):
os.remove(path)
else:
dirs.append(path)
for d in dirs:
try:
os.rmdir(d)
except OSError:
#not empty
pass
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 + " (" + self.base_dir + ")")
if old_ver is None:
return
if not '-' in old_ver:
#How can this happen??
log("Prefix has an invalid version?! You may want to back up user files and delete this prefix.")
#If it does, just let the Wine upgrade happen and hope it works...
return
try:
old_proton_ver, old_prefix_ver = old_ver.split('-')
old_proton_maj, old_proton_min = old_proton_ver.split('.')
new_proton_ver, new_prefix_ver = CURRENT_PREFIX_VERSION.split('-')
new_proton_maj, new_proton_min = new_proton_ver.split('.')
if int(new_proton_maj) < int(old_proton_maj) or \
(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(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"), 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(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(self.prefix_dir)
return
#replace broken .NET installations with wine-mono support
if os.path.exists(self.prefix_dir + "/drive_c/windows/Microsoft.NET/NETFXRepair.exe") and \
file_is_wine_builtin_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(self.prefix_dir + "/drive_c/windows/Microsoft.NET")
#prior to prefix version 4.11-2, all controllers were xbox controllers. wipe out the old registry entries.
if (int(old_proton_maj) < 4 or (int(old_proton_maj) == 4 and int(old_proton_min) == 11)) and \
int(old_prefix_ver) < 2:
log("Removing old xinput registry entries.")
with open(self.prefix_dir + "system.reg", "r") as reg_in:
with open(self.prefix_dir + "system.reg.new", "w") as reg_out:
for line in reg_in:
if line[0] == '[' and "CurrentControlSet" in line and "IG_" in line:
if "DeviceClasses" in line:
reg_out.write(line.replace("DeviceClasses", "DeviceClasses_old"))
elif "Enum" in line:
reg_out.write(line.replace("Enum", "Enum_old"))
else:
reg_out.write(line)
try:
os.rename(self.prefix_dir + "system.reg", self.prefix_dir + "system.reg.old")
except OSError:
os.remove(self.prefix_dir + "system.reg")
pass
try:
os.rename(self.prefix_dir + "system.reg.new", self.prefix_dir + "system.reg")
except OSError:
log("Unable to write new registry file to " + self.prefix_dir + "system.reg")
pass
# Prior to prefix version 6.3-3, ShellExecute* APIs used DDE.
# Wipe out old registry entries.
if int(old_proton_maj) < 6 or (int(old_proton_maj) == 6 and int(old_proton_min) < 3) or \
(int(old_proton_maj) == 6 and int(old_proton_min) == 3 and int(old_prefix_ver) < 3):
delete_keys = {
"[Software\\\\Classes\\\\htmlfile\\\\shell\\\\open\\\\ddeexec",
"[Software\\\\Classes\\\\pdffile\\\\shell\\\\open\\\\ddeexec",
"[Software\\\\Classes\\\\xmlfile\\\\shell\\\\open\\\\ddeexec",
"[Software\\\\Classes\\\\ftp\\\\shell\\\\open\\\\ddeexec",
"[Software\\\\Classes\\\\http\\\\shell\\\\open\\\\ddeexec",
"[Software\\\\Classes\\\\https\\\\shell\\\\open\\\\ddeexec",
}
dde_wb = '@="\\"C:\\\\windows\\\\system32\\\\winebrowser.exe\\" -nohome"'
sysreg_fp = self.prefix_dir + "system.reg"
new_sysreg_fp = self.prefix_dir + "system.reg.new"
log("Removing ShellExecute DDE registry entries.")
with open(sysreg_fp, "r") as reg_in:
with open(new_sysreg_fp, "w") as reg_out:
for line in reg_in:
if line[:line.find("ddeexec")+len("ddeexec")] in delete_keys:
reg_out.write(line.replace("ddeexec", "ddeexec_old", 1))
elif line.rstrip() == dde_wb:
reg_out.write(line.replace("-nohome", "%1"))
else:
reg_out.write(line)
# Slightly randomize backup file name to avoid colliding with
# other backups.
backup_sysreg_fp = "{}system.reg.{:x}.old".format(self.prefix_dir, randrange(16 ** 8))
try:
os.rename(sysreg_fp, backup_sysreg_fp)
except OSError:
log("Failed to back up old system.reg. Simply deleting it.")
os.remove(sysreg_fp)
pass
try:
os.rename(new_sysreg_fp, sysreg_fp)
except OSError:
log("Unable to write new registry file to " + sysreg_fp)
pass
stale_builtins = [self.prefix_dir + "/drive_c/windows/system32/amd_ags_x64.dll",
self.prefix_dir + "/drive_c/windows/syswow64/amd_ags_x64.dll" ]
for builtin in stale_builtins:
if os.path.lexists(builtin) and file_is_wine_builtin_dll(builtin):
log("Removing stale builtin " + builtin)
os.remove(builtin)
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 pfx_copy(self, src, dst, dll_copy=False):
if os.path.islink(src):
contents = os.readlink(src)
if os.path.dirname(contents).endswith(('/lib/wine/i386-windows', '/lib64/wine/x86_64-windows')):
# wine builtin dll
# make the destination an absolute symlink
contents = os.path.normpath(os.path.join(os.path.dirname(src), contents))
if dll_copy:
try_copyfile(src, dst)
else:
os.symlink(contents, dst)
else:
try_copyfile(src, dst)
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):
self.pfx_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):
self.pfx_copy(src_file, dst_file)
tracked_files.write(rel_dir + file_ + "\n")
def update_builtin_libs(self, dll_copy_patterns):
dll_copy_patterns = dll_copy_patterns.split(',')
prev_tracked_files = set()
with open(self.tracked_files_file, "r") as tracked_files:
for line in tracked_files:
prev_tracked_files.add(line.strip())
with open(self.tracked_files_file, "a") 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.lexists(dst_dir):
os.makedirs(dst_dir)
tracked_files.write(rel_dir + "\n")
for file_ in files:
src_file = os.path.join(src_dir, file_)
dst_file = os.path.join(dst_dir, file_)
if not file_is_wine_builtin_dll(src_file):
# Not a builtin library
continue
if file_is_wine_builtin_dll(dst_file):
os.unlink(dst_file)
elif os.path.lexists(dst_file):
# builtin library was replaced
continue
else:
os.makedirs(dst_dir, exist_ok=True)
dll_copy = any(fnmatch.fnmatch(file_, pattern) for pattern in dll_copy_patterns)
self.pfx_copy(src_file, dst_file, dll_copy)
tracked_name = rel_dir + file_
if tracked_name not in prev_tracked_files:
tracked_files.write(tracked_name + "\n")
def create_fonts_symlinks(self):
fontsmap = [
( g_proton.fonts_dir, "LiberationSans-Regular.ttf", "arial.ttf" ),
( g_proton.fonts_dir, "LiberationSans-Bold.ttf", "arialbd.ttf" ),
( g_proton.fonts_dir, "LiberationSerif-Regular.ttf", "times.ttf" ),
( g_proton.fonts_dir, "LiberationMono-Regular.ttf", "cour.ttf" ),
( g_proton.fonts_dir, "LiberationMono-Bold.ttf", "courbd.ttf" ),
( g_proton.fonts_dir, "msyh.ttf", "msyh.ttf" ),
( g_proton.fonts_dir, "simsun.ttc", "simsun.ttc" ),
( g_proton.fonts_dir, "msgothic.ttc", "msgothic.ttc" ),
( g_proton.fonts_dir, "malgun.ttf", "malgun.ttf" ),
( g_proton.fonts_dir, "NotoSansArabic-Regular.ttf", "NotoSansArabic-Regular.ttf" ),
( g_proton.wine_fonts_dir, "tahoma.ttf", "tahoma.ttf" ),
]
windowsfonts = self.prefix_dir + "/drive_c/windows/Fonts"
makedirs(windowsfonts)
for p in fontsmap:
lname = os.path.join(windowsfonts, p[2])
fname = os.path.join(p[0], p[1])
if os.path.lexists(lname):
if os.path.islink(lname):
os.remove(lname)
os.symlink(fname, lname)
else:
os.symlink(fname, lname)
def migrate_user_paths(self):
#move winxp-style paths to vista+ paths. we can't do this in
#upgrade_pfx because Steam may drop cloud files here at any time.
for (old, new, link) in \
[
(self.prefix_dir + "drive_c/users/steamuser/Local Settings/Application Data",
self.prefix_dir + "drive_c/users/steamuser/AppData/Local",
"../AppData/Local"),
(self.prefix_dir + "drive_c/users/steamuser/Application Data",
self.prefix_dir + "drive_c/users/steamuser/AppData/Roaming",
"./AppData/Roaming"),
(self.prefix_dir + "drive_c/users/steamuser/My Documents",
self.prefix_dir + "drive_c/users/steamuser/Documents",
"./Documents"),
]:
if os.path.lexists(old) and not os.path.islink(old):
merge_user_dir(src=old, dst=new)
os.rename(old, old + " BACKUP")
if not os.path.lexists(old):
makedirs(os.path.dirname(old))
os.symlink(src=link, dst=old)
elif os.path.islink(old) and not (os.readlink(old) == link):
os.remove(old)
os.symlink(src=link, dst=old)
def setup_prefix(self):
with self.prefix_lock:
if os.path.exists(self.version_file):
with open(self.version_file, "r") as f:
old_ver = f.readline().strip()
else:
old_ver = None
self.upgrade_pfx(old_ver)
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(self.prefix_dir + "/dosdevices"):
makedirs(self.prefix_dir + "/dosdevices")
set_dir_casefold_bit(self.prefix_dir + "/dosdevices")
if not os.path.exists(self.prefix_dir + "/user.reg"):
self.copy_pfx()
if not os.path.lexists(self.prefix_dir + "/dosdevices/c:"):
os.symlink("../drive_c", self.prefix_dir + "/dosdevices/c:")
if not os.path.lexists(self.prefix_dir + "/dosdevices/z:"):
os.symlink("/", self.prefix_dir + "/dosdevices/z:")
self.migrate_user_paths()
# collect configuration info
steamdir = os.environ["STEAM_COMPAT_CLIENT_INSTALL_PATH"]
use_wined3d = "wined3d" in g_session.compat_config
use_dxvk_dxgi = not use_wined3d and \
not ("WINEDLLOVERRIDES" in g_session.env and "dxgi=b" in g_session.env["WINEDLLOVERRIDES"])
use_nvapi = 'enablenvapi' in g_session.compat_config
builtin_dll_copy = os.environ.get("PROTON_DLL_COPY",
#dxsetup redist
"d3dcompiler_*.dll," +
"d3dcsx*.dll," +
"d3dx*.dll," +
"x3daudio*.dll," +
"xactengine*.dll," +
"xapofx*.dll," +
"xaudio*.dll," +
"xinput*.dll," +
"devenum.dll," +
#directshow
"amstream.dll," +
"qasf.dll," +
"qcap.dll," +
"qdvd.dll," +
"qedit.dll," +
"quartz.dll," +
#directplay
"dplay.dll," +
"dplaysvr.exe," +
"dplayx.dll," +
"dpmodemx.dll," +
"dpnaddr.dll," +
"dpnet.dll," +
"dpnlobby.dll," +
"dpnhpast.dll," +
"dpnhupnp.dll," +
"dpnsvr.exe," +
"dpwsockx.dll," +
"dpvoice.dll," +
#directmusic
"dmband.dll," +
"dmcompos.dll," +
"dmime.dll," +
"dmloader.dll," +
"dmscript.dll," +
"dmstyle.dll," +
"dmsynth.dll," +
"dmusic.dll," +
"dmusic32.dll," +
"dsound.dll," +
"dswave.dll," +
#vcruntime redist
"atl1*.dll," +
"concrt1*.dll," +
"msvcp1*.dll," +
"msvcr1*.dll," +
"vcamp1*.dll," +
"vcomp1*.dll," +
"vccorlib1*.dll," +
"vcruntime1*.dll," +
"api-ms-win-crt-conio-l1-1-0.dll," +
"api-ms-win-crt-heap-l1-1-0.dll," +
"api-ms-win-crt-locale-l1-1-0.dll," +
"api-ms-win-crt-math-l1-1-0.dll," +
"api-ms-win-crt-runtime-l1-1-0.dll," +
"api-ms-win-crt-stdio-l1-1-0.dll," +
"ucrtbase.dll," +
#some games balk at ntdll symlink(?)
"ntdll.dll," +
#some games require official vulkan loader
"vulkan-1.dll," +
#wmp9
"dispex.dll," +
"jscript.dll," +
"scrobj.dll," +
"scrrun.dll," +
"vbscript.dll," +
"cscript.exe," +
"wscript.exe," +
"wshom.ocx," +
"9SeriesDefault.wmz," +
"9SeriesDefault_.wmz," +
"9xmigrat.dll," +
"advpack.dll," +
"asferror.dll," +
"blackbox.dll," +
"CEWMDM.dll," +
"Compact.wmz," +
"control.xml," +
"custsat.dll," +
"drm.cat," +
"drm.inf," +
"DRMClien.dll," +
"DrmStor.dll," +
"drmv2clt.dll," +
"dw15.exe," +
"dwintl.dll," +
"engsetup.exe," +
"eula.txt," +
"fhg.inf," +
"iexpress.inf," +
"l3codeca.acm," +
"LAPRXY.DLL," +
"logagent.exe," +
"migrate.dll," +
"migrate.exe," +
"MP43DMOD.DLL," +
"MP4SDMOD.DLL," +
"MPG4DMOD.DLL," +
"mpvis.DLL," +
"msdmo.dll," +
"msnetobj.dll," +
"msoobci.dll," +
"MsPMSNSv.dll," +
"MsPMSP.dll," +
"MSSCP.dll," +
"MSWMDM.dll," +
"mymusic.inf," +
"npdrmv2.dll," +
"npdrmv2.zip," +
"NPWMSDrm.dll," +
"PidGen.dll," +
"Plylst1.wpl," +
"Plylst10.wpl," +
"Plylst11.wpl," +
"Plylst12.wpl," +
"Plylst13.wpl," +
"Plylst14.wpl," +
"Plylst15.wpl," +
"Plylst2.wpl," +
"Plylst3.wpl," +
"Plylst4.wpl," +
"Plylst5.wpl," +
"Plylst6.wpl," +
"Plylst7.wpl," +
"Plylst8.wpl," +
"Plylst9.wpl," +
"plyr_err.chm," +
"qasf.dll," +
"QuickSilver.wmz," +
"Revert.wmz," +
"roxio.inf," +
"rsl.dll," +
"setup_wm.cat," +
"setup_wm.exe," +
"setup_wm.inf," +
"skins.inf," +
"skinsmui.inf," +
"unicows.dll," +
"unregmp2.exe," +
"w95inf16.dll," +
"w95inf32.dll," +
"wm1033.lng," +
"WMADMOD.DLL," +
"WMADMOE.DLL," +
"WMASF.DLL," +
"wmburn.exe," +
"wmburn.rxc," +
"wmdm.cat," +
"wmdm.inf," +
"WMDMLOG.dll," +
"WMDMPS.dll," +
"wmerror.dll," +
"wmexpack.cat," +
"wmexpack.inf," +
"WMFSDK.cat," +
"WMFSDK.inf," +
"wmidx.dll," +
"WMNetMgr.dll," +
"wmp.cat," +
"wmp.dll," +
"wmp.inf," +
"wmp.ocx," +
"wmpasf.dll," +
"wmpband.dll," +
"wmpcd.dll," +
"wmpcore.dll," +
"wmpdxm.dll," +
"wmplayer.adm," +
"wmplayer.chm," +
"wmplayer.exe," +
"wmploc.DLL," +
"WMPNS.dll," +
"wmpns.jar," +
"wmpshell.dll," +
"wmpui.dll," +
"WMSDMOD.DLL," +
"WMSDMOE2.DLL," +
"WMSPDMOD.DLL," +
"WMSPDMOE.DLL," +
"WMVCORE.DLL," +
"WMVDMOD.DLL," +
"WMVDMOE2.DLL"
)
# If any of this info changes, we must rerun the tasks below
prefix_info = '\n'.join((
CURRENT_PREFIX_VERSION,
g_proton.fonts_dir,
g_proton.lib_dir,
g_proton.lib64_dir,
steamdir,
getmtimestr(steamdir, 'legacycompat', 'steamclient.dll'),
getmtimestr(steamdir, 'legacycompat', 'steamclient64.dll'),
getmtimestr(steamdir, 'legacycompat', 'Steam.dll'),
g_proton.default_pfx_dir,
getmtimestr(g_proton.default_pfx_dir, 'system.reg'),
str(use_wined3d),
str(use_dxvk_dxgi),
builtin_dll_copy,
str(use_nvapi),
))
# check whether any prefix config has changed
try:
with open(self.config_info_file, "r") as f:
old_prefix_info = f.read()
except IOError:
old_prefix_info = ""
if old_ver != CURRENT_PREFIX_VERSION or old_prefix_info != prefix_info:
# update builtin dll symlinks or copies
self.update_builtin_libs(builtin_dll_copy)
with open(self.config_info_file, "w") as f:
f.write(prefix_info)
with open(self.version_file, "w") as f:
f.write(CURRENT_PREFIX_VERSION + "\n")
#create font files symlinks
self.create_fonts_symlinks()
with open(self.tracked_files_file, "a") as tracked_files:
#copy steam files into place
steam_dir = "drive_c/Program Files (x86)/Steam/"
dst = self.prefix_dir + steam_dir
makedirs(dst)
filestocopy = [("steamclient.dll", "steamclient.dll"),
("steamclient64.dll", "steamclient64.dll"),
("GameOverlayRenderer64.dll", "GameOverlayRenderer64.dll"),
("SteamService.exe", "steam.exe"),
("Steam.dll", "Steam.dll")]
for (src,tgt) in filestocopy:
srcfile = steamdir + '/legacycompat/' + src
if os.path.isfile(srcfile):
dstfile = dst + tgt
if os.path.isfile(dstfile):
os.remove(dstfile)
else:
tracked_files.write(steam_dir + tgt + "\n")
try_copy(srcfile, dstfile)
filestocopy = [("steamclient64.dll", "steamclient64.dll"),
("GameOverlayRenderer.dll", "GameOverlayRenderer.dll"),
("GameOverlayRenderer64.dll", "GameOverlayRenderer64.dll")]
for (src,tgt) in filestocopy:
srcfile = g_proton.path(src)
if os.path.isfile(srcfile):
dstfile = dst + tgt
if os.path.isfile(dstfile):
os.remove(dstfile)
else:
tracked_files.write(steam_dir + tgt + "\n")
try_copy(srcfile, dstfile)
#copy openvr files into place
dst = self.prefix_dir + "/drive_c/vrclient/bin/"
makedirs(dst)
try_copy(g_proton.lib_dir + "wine/i386-windows/vrclient.dll", dst)
try_copy(g_proton.lib64_dir + "wine/x86_64-windows/vrclient_x64.dll", dst)
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/")
makedirs(self.prefix_dir + "/drive_c/openxr/")
try_copy(g_proton.default_pfx_dir + "drive_c/openxr/wineopenxr64.json", self.prefix_dir + "/drive_c/openxr/")
if use_wined3d:
dxvkfiles = ["dxvk_config"]
wined3dfiles = ["d3d11", "d3d10", "d3d10core", "d3d10_1", "d3d9"]
else:
dxvkfiles = ["dxvk_config", "d3d11", "d3d10", "d3d10core", "d3d10_1", "d3d9"]
wined3dfiles = []
if use_dxvk_dxgi:
dxvkfiles.append("dxgi")
else:
wined3dfiles.append("dxgi")
for f in wined3dfiles:
try_copy(g_proton.default_pfx_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",
self.prefix_dir + "drive_c/windows/syswow64/" + f + ".dll")
for f in dxvkfiles:
try_copy(g_proton.lib64_dir + "wine/dxvk/" + f + ".dll",
self.prefix_dir + "drive_c/windows/system32/" + f + ".dll")
try_copy(g_proton.lib_dir + "wine/dxvk/" + f + ".dll",
self.prefix_dir + "drive_c/windows/syswow64/" + f + ".dll")
g_session.dlloverrides[f] = "n"
# If the user requested the NVAPI be available, copy it into place.
# If they didn't, clean up any stray nvapi DLLs.
if use_nvapi:
try_copy(g_proton.lib64_dir + "wine/nvapi/nvapi64.dll",
self.prefix_dir + "drive_c/windows/system32/nvapi64.dll")
try_copy(g_proton.lib_dir + "wine/nvapi/nvapi.dll",
self.prefix_dir + "drive_c/windows/syswow64/nvapi.dll")
g_session.dlloverrides["nvapi64"] = "n"
g_session.dlloverrides["nvapi"] = "n"
else:
nvapi64_dll = self.prefix_dir + "drive_c/windows/system32/nvapi64.dll"
nvapi32_dll = self.prefix_dir + "drive_c/windows/syswow64/nvapi.dll"
if os.path.exists(nvapi64_dll):
os.unlink(nvapi64_dll)
if os.path.exists(nvapi32_dll):
os.unlink(nvapi32_dll)
# Try to detect known DLLs that ship with the NVIDIA Linux Driver
# and add them into the prefix
nvidia_wine_dll_dir = find_nvidia_wine_dll_dir()
if nvidia_wine_dll_dir:
for dll in ["_nvngx.dll", "nvngx.dll"]:
try_copy(nvidia_wine_dll_dir + "/" + dll,
self.prefix_dir + "drive_c/windows/system32/" + dll,
optional=True)
try_copy(g_proton.lib64_dir + "wine/vkd3d-proton/d3d12.dll",
self.prefix_dir + "drive_c/windows/system32/d3d12.dll")
try_copy(g_proton.lib_dir + "wine/vkd3d-proton/d3d12.dll",
self.prefix_dir + "drive_c/windows/syswow64/d3d12.dll")
gamedrive_path = self.prefix_dir + "dosdevices/s:"