-
-
Notifications
You must be signed in to change notification settings - Fork 289
/
Copy pathrunner.py
1285 lines (1072 loc) · 44.1 KB
/
runner.py
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
# runner.py
#
# Copyright 2020 brombinmirko <send@mirko.pm>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os, logging, subprocess, urllib.request, json, tarfile, time, shutil, re, hashlib
from glob import glob
from threading import Thread
from pathlib import Path
from datetime import date
from .download import BottlesDownloadEntry
from .pages.list import BottlesListEntry
from .utils import UtilsTerminal
'''
Set the default logging level
'''
logging.basicConfig(level=logging.DEBUG)
class RunAsync(Thread):
def __init__(self, task_name, task_func, task_args=False):
Thread.__init__(self)
self.task_name = task_name
self.task_func = task_func
self.task_args = task_args
def run(self):
logging.debug('Running async job `%s`.' % self.task_name)
if not self.task_args:
self.task_func()
else:
self.task_func(self.task_args)
class BottlesRunner:
'''
Define repositories URLs
TODO: search for vanilla wine binary repository
'''
repository = "https://github.com/lutris/wine/releases"
repository_api = "https://api.github.com/repos/lutris/wine/releases"
proton_repository = "https://github.com/GloriousEggroll/proton-ge-custom/releases"
proton_repository_api = "https://api.github.com/repos/GloriousEggroll/proton-ge-custom/releases"
dxvk_repository = "https://github.com/doitsujin/dxvk/releases"
dxvk_repository_api = "https://api.github.com/repos/doitsujin/dxvk/releases"
dependencies_repository = "https://raw.githubusercontent.com/bottlesdevs/dependencies/main/"
dependencies_repository_index = "%s/index.json" % dependencies_repository
'''
Define local path for temp and runners
'''
temp_path = "%s/.local/share/bottles/temp" % Path.home()
runners_path = "%s/.local/share/bottles/runners" % Path.home()
bottles_path = "%s/.local/share/bottles/bottles" % Path.home()
dxvk_path = "%s/.local/share/bottles/dxvk" % Path.home()
'''
Do not implement dxgi.dll <https://github.com/doitsujin/dxvk/wiki/DXGI>
'''
dxvk_dlls = [
"d3d10core.dll",
"d3d11.dll",
"d3d9.dll",
]
runners_available = []
dxvk_available = []
local_bottles = {}
'''
Structure of bottle configuration file
'''
sample_configuration = {
"Name": "",
"Runner": "",
"Path": "",
"Custom_Path": False,
"Environment": "",
"Creation_Date": "",
"Update_Date": "",
"Parameters": {
"dxvk": False,
"dxvk_hud": False,
"esync": False,
"fsync": False,
"aco_compiler": False,
"discrete_gpu": False,
"virtual_desktop": False,
"virtual_desktop_res": "1280x720",
"pulseaudio_latency": False,
"environment_variables": "",
"dll_overrides": ""
},
"Installed_Dependencies" : [],
"Programs" : {}
}
environments = {
"gaming": {
"Runner": "wine",
"Parameters": {
"dxvk": True,
"esync": True,
"discrete_gpu": True,
"pulseaudio_latency": True
}
},
"software": {
"Runner": "wine",
"Parameters": {
"dxvk": True
}
}
}
supported_dependencies = {}
def __init__(self, window, **kwargs):
super().__init__(**kwargs)
'''
Common variables
'''
self.window = window
self.settings = window.settings
self.utils_conn = window.utils_conn
self.check_runners(install_latest=False)
self.check_dxvk(install_latest=False)
self.fetch_dependencies()
self.check_bottles()
self.clear_temp()
'''
Performs all checks in one async shot
'''
def async_checks(self):
self.check_runners_dir()
self.check_runners()
self.check_dxvk()
self.check_bottles()
self.fetch_dependencies()
def checks(self):
a = RunAsync('checks', self.async_checks);a.start()
'''
Clear temp path
'''
def clear_temp(self, force=False):
logging.info("Cleaning the temp path.")
if self.settings.get_boolean("temp") or force:
for f in os.listdir(self.temp_path):
os.remove(os.path.join(self.temp_path, f))
'''
Check if standard directories not exists, then create
'''
def check_runners_dir(self):
try:
if not os.path.isdir(self.runners_path):
logging.info("Runners path doens't exist, creating now.")
os.makedirs(self.runners_path, exist_ok=True)
if not os.path.isdir(self.bottles_path):
logging.info("Bottles path doens't exist, creating now.")
os.makedirs(self.bottles_path, exist_ok=True)
if not os.path.isdir(self.dxvk_path):
logging.info("Dxvk path doens't exist, creating now.")
os.makedirs(self.dxvk_path, exist_ok=True)
if not os.path.isdir(self.temp_path):
logging.info("Temp path doens't exist, creating now.")
os.makedirs(self.temp_path, exist_ok=True)
except:
return False
return True
'''
Get latest runner updates
'''
def get_runner_updates(self):
updates = {}
if self.utils_conn.check_connection():
'''
wine
'''
with urllib.request.urlopen(self.repository_api) as url:
releases = json.loads(url.read().decode())
for release in [releases[0], releases[1], releases[2]]:
tag = release["tag_name"]
file = release["assets"][0]["name"]
if "%s-x86_64" % tag not in self.runners_available:
updates[tag] = file
else:
logging.info("Latest runner is `%s` and is already installed." % tag)
'''
proton
'''
with urllib.request.urlopen(self.proton_repository_api) as url:
releases = json.loads(url.read().decode())
for release in [releases[0], releases[1], releases[2]]:
tag = release["tag_name"]
file = release["assets"][0]["name"]
if "Proton-%s" % tag not in self.runners_available:
updates[tag] = file
else:
logging.info("Latest runner is `%s` and is already installed." % tag)
'''
Send a notificationif the user settings allow it
'''
if self.settings.get_boolean("notifications"):
if len(updates) == 0:
self.window.send_notification("Download manager",
"No runner updates available.",
"software-installed-symbolic")
return updates
'''
Get latest dxvk updates
'''
def get_dxvk_updates(self):
updates = {}
if self.utils_conn.check_connection():
with urllib.request.urlopen(self.dxvk_repository_api) as url:
releases = json.loads(url.read().decode())
for release in [releases[0], releases[1], releases[2]]:
tag = release["tag_name"]
file = release["assets"][0]["name"]
if "dxvk-%s" % tag[1:] not in self.dxvk_available:
updates[tag] = file
else:
logging.info("Latest dxvk is `%s` and is already installed." % tag)
'''
Send a notificationif the user settings allow it
'''
if self.settings.get_boolean("notifications"):
if len(updates) == 0:
self.window.send_notification("Download manager",
"No dxvk updates available.",
"software-installed-symbolic")
return updates
'''
Extract a component archive
'''
def extract_component(self, component, archive):
if component in ["runner", "runner:proton"]: path = self.runners_path
if component == "dxvk": path = self.dxvk_path
archive = tarfile.open("%s/%s" % (self.temp_path, archive))
archive.extractall(path)
'''
Download a specific component release
'''
def download_component(self, component, tag, file, rename=False, checksum=False):
if component == "runner": repository = self.repository
if component == "runner:proton": repository = self.proton_repository
if component == "dxvk": repository = self.dxvk_repository
if component == "dependency":
repository = self.dependencies_repository
download_url = tag
else:
download_url = "%s/download/%s/%s" % (repository, tag, file)
'''
Check if file already exists in temp path then do not
download it again
'''
file = rename if rename else file
if os.path.isfile("%s/%s" % (self.temp_path, file)):
logging.info("File `%s` already exists in temp, skipping." % file)
else:
urllib.request.urlretrieve(download_url, "%s/%s" % (self.temp_path, file))
'''
The `rename` parameter mean that downloaded file should be
renamed to another name
'''
if rename:
logging.info("Renaming `%s` to `%s`." % (file, rename))
file_path = "%s/%s" % (self.temp_path, rename)
os.rename("%s/%s" % (self.temp_path, file), file_path)
else:
file_path = "%s/%s" % (self.temp_path, file)
'''
Compare checksums to check file corruption
'''
if checksum:
checksum = checksum.lower()
local_checksum = hashlib.md5()
with open(file_path, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
local_checksum.update(chunk)
local_checksum = local_checksum.hexdigest().lower()
if local_checksum != checksum:
logging.info("Downloaded file `%s` looks corrupted." % file)
logging.info("Source checksum: `%s` downloaded: `%s`" % (
checksum, local_checksum))
self.window.send_notification(
"Bottles",
"Downloaded file `%s` looks corrupted. Try again." % file,
"dialog-error-symbolic")
os.remove(file_path)
return False
return True
'''
Localy install a new component (runner, dxvk, ..) async
'''
def async_install_component(self, args):
component, tag, file = args
'''
Send a notification for download start if the
user settings allow it
'''
if self.settings.get_boolean("notifications"):
self.window.send_notification("Download manager",
"Installing `%s` runner …" % tag,
"document-save-symbolic")
'''
Add a new entry to the download manager
'''
if component == "runner": file_name = tag
if component == "runner:proton": file_name = "proton-%s" % tag
if component == "dxvk": file_name = "dxvk-%s" % tag
download_entry = BottlesDownloadEntry(file_name=file_name, stoppable=False)
self.window.box_downloads.add(download_entry)
logging.info("Installing the `%s` component." % tag)
'''
Run the progressbar update async
'''
a = RunAsync('pulse', download_entry.pulse);a.start()
'''
Download and extract the component archive
'''
self.download_component(component, tag, file)
self.extract_component(component, file)
'''
Clear available component list and do the check again
'''
if component in ["runner", "runner:proton"]:
self.runners_available = []
self.check_runners()
if component == "dxvk":
self.dxvk_available = []
self.check_dxvk()
'''
Send a notification for download end if the
user settings allow it
'''
if self.settings.get_boolean("notifications"):
self.window.send_notification("Download manager",
"Installation of `%s` component finished!" % tag,
"software-installed-symbolic")
'''
Remove the entry from the download manager
'''
download_entry.destroy()
'''
Update components
'''
if component in ["runner", "runner:proton"]:
self.window.page_preferences.update_runners()
if component == "dxvk":
self.window.page_preferences.update_dxvk()
def install_component(self, component, tag, file):
if self.utils_conn.check_connection(True):
a = RunAsync('install', self.async_install_component, [component,
tag,
file])
a.start()
'''
Method for deoendency installations
'''
def async_install_dependency(self, args):
configuration, dependency, widget = args
'''
Set UI to not usable
'''
self.window.set_usable_ui(False)
'''
Send a notification for download start if the
user settings allow it
'''
if self.settings.get_boolean("notifications"):
self.window.send_notification("Download manager",
"Installing %s in %s bottle …" % (
dependency[0],
configuration.get("Name")
),
"document-save-symbolic")
'''
Add a new entry to the download manager
'''
download_entry = BottlesDownloadEntry(dependency[0], stoppable=False)
self.window.box_downloads.add(download_entry)
logging.info("Installing the `%s` dependency for `%s` bottle." % (
dependency[0], configuration.get("Name")
))
'''
Run the progressbar update async
'''
a = RunAsync('pulse', download_entry.pulse);a.start()
'''
Get dependency manifest from repository
'''
dependency_manifest = self.fetch_dependency_manifest(dependency[0])
'''
Execute installation steps
'''
for step in dependency_manifest.get("Steps"):
print(step["action"])
'''
Step type: delete_sys32_dlls
'''
if step["action"] == "delete_sys32_dlls":
for dll in step["dlls"]:
try:
logging.info("Removing `%s` dll from system32 for `%s` bottle" % (
dll, configuration.get("Name")
))
os.remove("%s/%s/drive_c/windows/system32/%s" % (
self.bottles_path, configuration.get("Name"), dll))
except:
logging.info("`%s` dll not found for `%s` bottle, failed to remove from system32."% (
dll, configuration.get("Name")
))
'''
Step type: install_exe, install_msi
'''
if step["action"] in ["install_exe", "install_msi"]:
download = self.download_component("dependency",
step.get("url"),
step.get("file_name"),
step.get("rename"),
checksum=step.get("file_checksum"))
if download:
if step.get("rename"):
file = step.get("rename")
else:
file = step.get("file_name")
self.run_executable(configuration, "%s/%s" % (
self.temp_path, file))
else:
widget.btn_install.set_sensitive(True)
return False
'''
Add dependency to the bottle configuration
'''
if dependency[0] not in configuration.get("Installed_Dependencies"):
if configuration.get("Installed_Dependencies"):
dependencies = configuration["Installed_Dependencies"]+[dependency[0]]
else:
dependencies = [dependency[0]]
self.update_configuration(configuration,"Installed_Dependencies", dependencies)
'''
Remove the entry from the download manager
'''
download_entry.destroy()
'''
Hide installation button and show remove button
'''
widget.btn_install.set_visible(False)
widget.btn_remove.set_visible(True)
widget.btn_remove.set_sensitive(True)
'''
Set UI to usable again
'''
self.window.set_usable_ui(True)
def install_dependency(self, configuration, dependency, widget):
if self.utils_conn.check_connection(True):
a = RunAsync('install_dependency',
self.async_install_dependency, [configuration,
dependency,
widget])
a.start()
def remove_dependency(self, configuration, dependency, widget):
logging.info("Removing `%s` dependency from `%s` bottle configuration." % (
dependency[0], configuration.get("Name")))
'''
Prompt the uninstaller
'''
self.run_uninstaller(configuration)
'''
Remove dependency to the bottle configuration
'''
configuration["Installed_Dependencies"].remove(dependency[0])
self.update_configuration(configuration,
"Installed_Dependencies",
configuration["Installed_Dependencies"])
'''
Show installation button and hide remove button
'''
widget.btn_install.set_visible(True)
widget.btn_remove.set_visible(False)
'''
Check localy available runners
'''
def check_runners(self, install_latest=True):
runners = glob("%s/*/" % self.runners_path)
self.runners_available = []
for runner in runners:
self.runners_available.append(runner.split("/")[-2])
if len(self.runners_available) > 0:
logging.info("Runners found: \n%s" % ', '.join(
self.runners_available))
'''
If there are no locally installed runners, download the latest
builds for Wine and Proton from the GitHub repositories.
A very special thanks to Lutris & GloriousEggroll for builds <3!
'''
if len(self.runners_available) == 0 and install_latest:
logging.info("No runners found.")
'''
Fetch runners from repository only if connected
'''
if self.utils_conn.check_connection():
'''
Wine
'''
with urllib.request.urlopen(self.repository_api) as url:
releases = json.loads(url.read().decode())
tag = releases[0]["tag_name"]
file = releases[0]["assets"][0]["name"]
self.install_component("runner", tag, file)
'''
Proton
with urllib.request.urlopen(self.proton_repository_api) as url:
releases = json.loads(url.read().decode())
tag = releases[0]["tag_name"]
file = releases[0]["assets"][0]["name"]
self.install_component("runner:proton", tag, file)
'''
'''
Sort runners_available and dxvk_available alphabetically
'''
self.runners_available = sorted(self.runners_available, reverse=True)
self.dxvk_available = sorted(self.dxvk_available, reverse=True)
'''
Check localy available dxvk
'''
def check_dxvk(self, install_latest=True):
dxvk_list = glob("%s/*/" % self.dxvk_path)
self.dxvk_available = []
for dxvk in dxvk_list: self.dxvk_available.append(dxvk.split("/")[-2])
if len(self.dxvk_available) > 0:
logging.info("Dxvk found: \n%s" % ', '.join(self.dxvk_available))
if len(self.dxvk_available) == 0 and install_latest:
logging.info("No dxvk found.")
'''
Fetch dxvk from repository only if connected
'''
if self.utils_conn.check_connection():
with urllib.request.urlopen(self.dxvk_repository_api) as url:
releases = json.loads(url.read().decode())
tag = releases[0]["tag_name"]
file = releases[0]["assets"][0]["name"]
self.install_component("dxvk", tag, file)
'''
Get installed programs
'''
def get_programs(self, configuration):
bottle = "%s/%s" % (self.bottles_path, configuration.get("Name"))
results = glob("%s/drive_c/users/*/Start Menu/Programs/**/*.lnk" % bottle, recursive=True)
results += glob("%s/drive_c/ProgramData/Microsoft/Windows/Start Menu/Programs/**/*.lnk" % bottle, recursive=True)
installed_programs = []
'''
For any .lnk file, check for executable path inside
'''
for program in results:
path = program.split("/")[-1]
if path not in ["Uninstall.lnk"]:
executable_path = ""
try:
with open(program, "r", encoding='utf-8', errors='ignore') as lnk:
lnk = lnk.read()
executable_path = re.search('C:(.*).exe', lnk).group(0)
if executable_path.find("ninstall") < 0:
path = path.replace(".lnk", "")
installed_programs.append([path, executable_path])
except:
logging.info("Cannot get executable for `%s`." % path)
return installed_programs
'''
Fetch online dependencies
'''
def fetch_dependencies(self):
if self.utils_conn.check_connection():
with urllib.request.urlopen(self.dependencies_repository_index) as url:
index = json.loads(url.read())
for dependency in index.items():
self.supported_dependencies[dependency[0]] = dependency[1]
'''
Fetch dependency manifest online
'''
def fetch_dependency_manifest(self, dependency_name):
if self.utils_conn.check_connection():
with urllib.request.urlopen("%s/%s.json" % (
self.dependencies_repository, dependency_name
)) as url:
return json.loads(url.read())
return False
'''
Check local bottles
'''
def check_bottles(self):
bottles = glob("%s/*/" % self.bottles_path)
'''
For each bottle add the path name to the `local_bottles` variable
and append the configuration
'''
for bottle in bottles:
bottle_name_path = bottle.split("/")[-2]
try:
configuration_file = open('%s/bottle.json' % bottle)
configuration_file_json = json.load(configuration_file)
configuration_file.close()
except:
configuration_file_json = self.sample_configuration
configuration_file_json["Broken"] = True
configuration_file_json["Name"] = bottle_name_path
configuration_file_json["Environment"] = "Undefined"
self.local_bottles[bottle_name_path] = configuration_file_json
if len(self.local_bottles) > 0:
logging.info("Bottles found: \n%s" % ', '.join(self.local_bottles))
'''
Update parameters in bottle configuration file
'''
def update_configuration(self, configuration, key, value, scope=False):
logging.info("Setting `%s` parameter to `%s` for `%s` Bottle…" % (
key, value, configuration.get("Name")))
if configuration.get("Custom_Path"):
bottle_complete_path = configuration.get("Path")
else:
bottle_complete_path = "%s/%s" % (self.bottles_path,
configuration.get("Path"))
if scope:
configuration[scope][key] = value
else:
configuration[key] = value
with open("%s/bottle.json" % bottle_complete_path,
"w") as configuration_file:
json.dump(configuration, configuration_file, indent=4)
configuration_file.close()
self.window.page_list.update_bottles()
return configuration
'''
Create a new wineprefix async
'''
def async_create_bottle(self, args):
logging.info("Creating the wineprefix…")
name, environment, path, runner = args
if not runner: runner = self.runners_available[0]
runner_name = runner
'''
If runner is proton, files are located to the dist path
'''
if runner.startswith("Proton"): runner = "%s/dist" % runner
'''
Define reusable variables
'''
buffer_output = self.window.page_create.buffer_output
iter = buffer_output.get_end_iter()
'''
Check if there is at least one runner and dxvk installed, else
install latest releases
'''
if 0 in [len(self.runners_available), len(self.dxvk_available)]:
buffer_output.insert(iter, "Runner and/or dxvk not found, installing latest version…\n")
iter = buffer_output.get_end_iter()
self.window.page_preferences.set_dummy_runner()
self.window.show_runners_preferences_view()
return self.async_checks()
'''
Set UI to not usable
'''
self.window.set_usable_ui(False)
'''
Define bottle parameters
'''
bottle_name = name
bottle_name_path = bottle_name.replace(" ", "-")
if path == "":
bottle_custom_path = False
bottle_complete_path = "%s/%s" % (self.bottles_path, bottle_name_path)
else:
bottle_custom_path = True
bottle_complete_path = path
'''
Run the progressbar update async
'''
a = RunAsync('pulse', self.window.page_create.pulse);a.start()
buffer_output.insert(iter, "The wine configuration is being updated…\n")
iter = buffer_output.get_end_iter()
'''
Prepare and execute the command
'''
command = "WINEPREFIX={path} WINEARCH=win64 {runner} wineboot".format(
path = bottle_complete_path,
runner = "%s/%s/bin/wine64" % (self.runners_path, runner)
)
'''
Get the command output and add to the buffer
'''
process = subprocess.Popen(command,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
process_output = process.stdout.read().decode("utf-8")
buffer_output.insert(iter, process_output)
iter = buffer_output.get_end_iter()
'''
Generate bottle configuration file
'''
buffer_output.insert(iter, "\nGenerating Bottle configuration file…")
iter = buffer_output.get_end_iter()
configuration = self.sample_configuration
configuration["Name"] = bottle_name
configuration["Runner"] = runner_name
if path == "":
configuration["Path"] = bottle_name_path
else:
configuration["Path"] = bottle_complete_path
configuration["Custom_Path"] = bottle_custom_path
configuration["Environment"] = environment
configuration["Creation_Date"] = str(date.today())
configuration["Update_Date"] = str(date.today())
'''
Apply environment configuration
'''
buffer_output.insert(iter, "\nApplying `%s` environment configuration.." % environment)
iter = buffer_output.get_end_iter()
if environment != "Custom":
environment_parameters = self.environments[environment.lower()]["Parameters"]
for parameter in configuration["Parameters"]:
if parameter in environment_parameters:
configuration["Parameters"][parameter] = environment_parameters[parameter]
'''
Save bottle configuration
'''
with open("%s/bottle.json" % bottle_complete_path,
"w") as configuration_file:
json.dump(configuration, configuration_file, indent=4)
configuration_file.close()
'''
Perform dxvk installation if configured
'''
if configuration["Parameters"]["dxvk"]:
buffer_output.insert(iter, "\nInstalling dxvk..")
iter = buffer_output.get_end_iter()
self.install_dxvk(configuration)
'''
Set the list button visible and set UI to usable again
'''
buffer_output.insert_markup(
iter,
"\n<span foreground='green'>%s</span>" % "Your new bottle with name `%s` is now ready!" % bottle_name,
-1)
iter = buffer_output.get_end_iter()
self.window.page_create.set_status("created")
self.window.set_usable_ui(True)
'''
Clear local bottles list and do the check again
'''
self.local_bottles = {}
self.check_bottles()
def create_bottle(self, name, environment, path=False, runner=False):
a = RunAsync('create', self.async_create_bottle, [name,
environment,
path,
runner])
a.start()
'''
Get latest installed runner
'''
def get_latest_runner(self, runner_type="wine"):
if runner_type == "wine":
latest_runner = [idx for idx in self.runners_available if idx.lower().startswith("lutris")][0]
else:
latest_runner = [idx for idx in self.runners_available if idx.lower().startswith("proton")][0]
return latest_runner
'''
Get human size
'''
def get_human_size(self, size):
for unit in ['','Ki','Mi','Gi','Ti','Pi','Ei','Zi']:
if abs(size) < 1024.0:
return "%3.1f%s%s" % (size, unit, 'B')
size /= 1024.0
return "%.1f%s%s" % (size, 'Yi', 'B')
'''
Get path size
'''
def get_path_size(self, path, human=True):
path = Path(path)
size = sum(f.stat().st_size for f in path.glob('**/*') if f.is_file())
if human: return self.get_human_size(size)
return size
'''
Get disk size
'''
def get_disk_size(self, human=True):
'''
TODO: disk should be taken from configuration Path
'''
disk_total, disk_used, disk_free = shutil.disk_usage('/')
if human:
disk_total = self.get_human_size(disk_total)
disk_used = self.get_human_size(disk_used)
disk_free = self.get_human_size(disk_free)
return {
"total": disk_total,
"used": disk_free,
"free": disk_free,
}
'''
Get bottle path size
'''
def get_bottle_size(self, configuration, human=True):
path = configuration.get("Path")
runner = configuration.get("Runner")
if not configuration.get("Custom_Path"):
path = "%s/%s" % (self.bottles_path, path)
return self.get_path_size(path, human)
'''
Delete a wineprefix
'''
def async_delete_bottle(self, args):
logging.info("Deleting the wineprefix…")
configuration = args[0]
'''
Delete path with all files
'''
path = configuration.get("Path")
if path != "":
if not configuration.get("Custom_Path"):
path = "%s/%s" % (self.bottles_path, path)
shutil.rmtree(path)
def delete_bottle(self, configuration):
a = RunAsync('delete', self.async_delete_bottle, [configuration]);a.start()
'''
Repair a bottle generating a new configuration
'''
def repair_bottle(self, configuration):
logging.info("Trying to repair the `%s` bottle.." % configuration.get("Name"))
bottle_complete_path = "%s/%s" % (self.bottles_path,
configuration.get("Name"))
'''
Creating a new configuration, using path name as bottle name
and Custom as environment
'''
new_configuration = self.sample_configuration
new_configuration["Name"] = configuration.get("Name")
new_configuration["Runner"] = self.runners_available[0]
new_configuration["Path"] = configuration.get("Name")
new_configuration["Environment"] = "Custom"
new_configuration["Creation_Date"] = str(date.today())
new_configuration["Update_Date"] = str(date.today())