-
Notifications
You must be signed in to change notification settings - Fork 0
/
faugus-launcher.py
3205 lines (2595 loc) · 131 KB
/
faugus-launcher.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
#!/usr/bin/python3
import os
import re
import shutil
import signal
import subprocess
import sys
import threading
import webbrowser
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0')
from gi.repository import Gtk, Gdk, GdkPixbuf, GLib
from PIL import Image
config_dir = os.getenv('XDG_CONFIG_HOME', os.path.expanduser('~/.config'))
faugus_launcher_dir = f'{config_dir}/faugus-launcher'
prefixes_dir = f'{faugus_launcher_dir}/prefixes'
icons_dir = f'{faugus_launcher_dir}/icons'
config_file_dir = f'{faugus_launcher_dir}/config.ini'
share_dir = os.getenv('XDG_DATA_HOME', os.path.expanduser('~/.local/share'))
app_dir = f'{share_dir}/applications'
faugus_png = "/usr/share/icons/faugus-launcher.png"
faugus_run = "/usr/bin/faugus-run"
faugus_proton_manager = "/usr/bin/faugus-proton-manager"
umu_run = "/usr/bin/umu-run"
def get_desktop_dir():
try:
# Run the command and capture its output
desktop_dir = subprocess.check_output(['xdg-user-dir', 'DESKTOP'], text=True).strip()
return desktop_dir
except FileNotFoundError:
print("xdg-user-dir not found; falling back to ~/Desktop")
# xdg-user-dir is not installed, fallback to ~/Desktop
return os.path.expanduser('~/Desktop')
except subprocess.CalledProcessError:
print("Error running xdg-user-dir; falling back to ~/Desktop")
# xdg-user-dir command failed for some other reason
return os.path.expanduser('~/Desktop')
desktop_dir = get_desktop_dir()
class Main(Gtk.Window):
def __init__(self):
# Initialize the main window with title and default size
Gtk.Window.__init__(self, title="Faugus Launcher")
self.set_default_size(400, 620)
self.set_resizable(False)
self.set_icon_from_file(faugus_png)
self.game_running = None
self.games = []
self.processos = {}
# Define the configuration path
config_path = faugus_launcher_dir
# Create the configuration directory if it doesn't exist
if not os.path.exists(config_path):
os.makedirs(config_path)
self.working_directory = config_path
os.chdir(self.working_directory)
config_file = config_file_dir
if not os.path.exists(config_file):
self.save_config("False", prefixes_dir, "False", "False", "False", "GE-Proton Latest (default)", "True")
self.games = []
# Create main box and its components
box_main = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
box_top = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
box_left = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
box_right = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
box_bottom = Gtk.Box()
# Create buttons for adding, editing, and deleting games
self.button_add = Gtk.Button(label="New")
self.button_add.connect("clicked", self.on_button_add_clicked)
self.button_add.set_can_focus(False)
self.button_add.set_size_request(50, 50)
self.button_add.set_margin_top(10)
self.button_add.set_margin_start(10)
self.button_add.set_margin_end(10)
self.button_edit = Gtk.Button(label="Edit")
self.button_edit.connect("clicked", self.on_button_edit_clicked)
self.button_edit.set_can_focus(False)
self.button_edit.set_size_request(50, 50)
self.button_edit.set_margin_top(10)
self.button_edit.set_margin_start(10)
self.button_edit.set_margin_end(10)
self.button_delete = Gtk.Button(label="Del")
self.button_delete.connect("clicked", self.on_button_delete_clicked)
self.button_delete.set_can_focus(False)
self.button_delete.set_size_request(50, 50)
self.button_delete.set_margin_top(10)
self.button_delete.set_margin_start(10)
self.button_delete.set_margin_end(10)
# Create button for killing processes
button_kill = Gtk.Button(label="Kill")
button_kill.connect("clicked", self.on_button_kill_clicked)
button_kill.set_can_focus(False)
button_kill.set_tooltip_text("Force close all running games")
button_kill.set_size_request(50, 50)
button_kill.set_margin_top(10)
button_kill.set_margin_end(10)
button_kill.set_margin_bottom(10)
# Create button for settings
button_settings = Gtk.Button()
button_settings.connect("clicked", self.on_button_settings_clicked)
button_settings.set_can_focus(False)
button_settings.set_size_request(50, 50)
button_settings.set_image(Gtk.Image.new_from_icon_name("open-menu-symbolic", Gtk.IconSize.BUTTON))
button_settings.set_margin_top(10)
button_settings.set_margin_start(10)
button_settings.set_margin_bottom(10)
# Create button for launching games
self.button_play = Gtk.Button()
self.button_play.connect("clicked", self.on_button_play_clicked)
self.button_play.set_can_focus(False)
self.button_play.set_size_request(150, 50)
self.button_play.set_image(Gtk.Image.new_from_icon_name("media-playback-start-symbolic", Gtk.IconSize.BUTTON))
self.button_play.set_margin_top(10)
self.button_play.set_margin_end(10)
self.button_play.set_margin_bottom(10)
self.entry_search = Gtk.Entry()
self.entry_search.set_placeholder_text("Search...")
self.entry_search.connect("changed", self.on_search_changed)
self.entry_search.set_size_request(-1, 50)
self.entry_search.set_margin_top(10)
self.entry_search.set_margin_start(10)
self.entry_search.set_margin_bottom(10)
self.entry_search.set_margin_end(10)
# Create scrolled window for game list
scroll_box = Gtk.ScrolledWindow()
scroll_box.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
scroll_box.set_margin_top(10)
scroll_box.set_margin_end(10)
self.last_clicked_row = None
self.last_click_time = 0
# Create list box for displaying games
self.game_list = Gtk.ListBox(halign=Gtk.Align.START, valign=Gtk.Align.START)
self.game_list.connect("button-release-event", self.on_button_release_event)
self.connect("key-press-event", self.on_key_press_event)
scroll_box.add(self.game_list)
self.load_games()
# Pack left and scrolled box into the top box
box_top.pack_start(box_left, False, True, 0)
box_top.pack_start(box_right, True, True, 0)
# Pack buttons into the left box
box_left.pack_start(self.button_add, False, False, 0)
box_left.pack_start(self.button_edit, False, False, 0)
box_left.pack_start(self.button_delete, False, False, 0)
box_right.pack_start(scroll_box, True, True, 0)
# Pack buttons and other components into the bottom box
box_bottom.pack_start(button_settings, False, False, 0)
box_bottom.pack_start(self.entry_search, True, True, 0)
box_bottom.pack_end(self.button_play, False, False, 0)
box_bottom.pack_end(button_kill, False, False, 0)
# Pack top and bottom boxes into the main box
box_main.pack_start(box_top, True, True, 0)
box_main.pack_end(box_bottom, False, True, 0)
self.add(box_main)
self.button_edit.set_sensitive(False)
self.button_delete.set_sensitive(False)
self.button_play.set_sensitive(False)
self.game_running2 = False
self.game_list.select_row(self.game_list.get_row_at_index(0))
self.update_button_sensitivity(self.game_list.get_selected_row())
# Set signal handler for child process termination
signal.signal(signal.SIGCHLD, self.on_child_process_closed)
def load_games(self):
# Load games from file
try:
with open("games.txt", "r") as file:
for line in file:
data = line.strip().split(";")
if len(data) >= 5:
title, path, prefix, launch_arguments, game_arguments = data[:5]
if len(data) >= 10:
mangohud = data[5]
gamemode = data[6]
sc_controller = data[7]
protonfix = data[8]
runner = data[9]
else:
mangohud = ""
gamemode = ""
sc_controller = ""
protonfix = ""
runner = ""
game = Game(title, path, prefix, launch_arguments, game_arguments, mangohud, gamemode,
sc_controller, protonfix, runner)
self.games.append(game)
self.games = sorted(self.games, key=lambda x: x.title.lower())
self.filtered_games = self.games[:] # Initialize filtered_games
self.game_list.foreach(Gtk.Widget.destroy)
for game in self.filtered_games:
self.add_item_list(game)
except FileNotFoundError:
pass
def add_item_list(self, game):
# Add a game item to the list
hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=6)
hbox.set_border_width(5)
hbox.set_size_request(400, -1)
# Handle the click event of the Create Shortcut button
title_formatted = re.sub(r'[^a-zA-Z0-9\s]', '', game.title)
title_formatted = title_formatted.replace(' ', '-')
title_formatted = '-'.join(title_formatted.lower().split())
game_icon = f'{icons_dir}/{title_formatted}.ico'
game_label = Gtk.Label.new(game.title)
if os.path.isfile(game_icon):
pass
else:
game_icon = faugus_png
pixbuf = GdkPixbuf.Pixbuf.new_from_file(game_icon)
scaled_pixbuf = pixbuf.scale_simple(40, 40, GdkPixbuf.InterpType.BILINEAR)
image = Gtk.Image.new_from_file(game_icon)
image.set_from_pixbuf(scaled_pixbuf)
image.set_margin_end(10)
#self.button_shortcut_icon.set_image(image)
hbox.pack_start(image, False, False, 0)
hbox.pack_start(game_label, False, False, 0)
listbox_row = Gtk.ListBoxRow()
listbox_row.add(hbox)
listbox_row.set_activatable(False)
listbox_row.set_can_focus(False)
listbox_row.set_selectable(True)
self.game_list.add(listbox_row)
hbox.set_halign(Gtk.Align.CENTER)
listbox_row.set_valign(Gtk.Align.START)
def on_search_changed(self, entry):
search_text = entry.get_text().lower()
# Filter games based on the search text
self.filtered_games = [game for game in self.games if search_text in game.title.lower()]
self.game_list.foreach(Gtk.Widget.destroy) # Clear the current list
if self.filtered_games: # If there are filtered games, add them
for game in self.filtered_games:
self.add_item_list(game)
# Select the first item in the list
self.game_list.select_row(self.game_list.get_row_at_index(0))
else: # If there are no games, add a message or leave the list empty
pass
self.game_list.show_all() # Show all items in the list, including the message
self.update_button_sensitivity(self.game_list.get_selected_row())
def on_key_press_event(self, listbox, event):
# Check for arrow key press
if event.keyval in (Gdk.KEY_Up, Gdk.KEY_Down):
# Grab focus on the ListBox to ensure navigation works
self.game_list.grab_focus()
# Get the list of rows in the ListBox
rows = self.game_list.get_children()
selected_row = self.game_list.get_selected_row()
# Handle Up arrow key
if event.keyval == Gdk.KEY_Up:
if selected_row:
current_index = rows.index(selected_row)
if current_index > 0:
self.game_list.select_row(rows[current_index - 1])
self.update_button_sensitivity(rows[current_index - 1])
# Handle Down arrow key
elif event.keyval == Gdk.KEY_Down:
if selected_row:
current_index = rows.index(selected_row)
if current_index < len(rows) - 1:
self.game_list.select_row(rows[current_index + 1])
self.update_button_sensitivity(rows[current_index + 1])
# Check for Enter key press
if event.keyval == Gdk.KEY_Return:
selected_row = self.game_list.get_selected_row()
if selected_row:
# Simulate double-click behavior
hbox = selected_row.get_child()
game_label = hbox.get_children()[1]
title = game_label.get_text()
# Check if the game is already running
if title not in self.processos:
widget = self.button_play
self.on_button_play_clicked(widget)
else:
dialog = Gtk.MessageDialog(title=title, text=f"'{title}' is already running.",
buttons=Gtk.ButtonsType.OK, parent=self)
dialog.set_resizable(False)
dialog.set_modal(True)
dialog.set_icon_from_file(faugus_png)
dialog.run()
dialog.destroy()
# Check for Delete key press
if event.keyval == Gdk.KEY_Delete:
selected_row = self.game_list.get_selected_row()
if selected_row:
self.on_button_delete_clicked(self.button_delete)
# Stop further event propagation
return True
def on_button_release_event(self, listbox, event):
# Handle button release event
if event.type == Gdk.EventType.BUTTON_RELEASE and event.button == Gdk.BUTTON_PRIMARY:
current_row = listbox.get_row_at_y(event.y)
current_time = event.time
if current_row == self.last_clicked_row and current_time - self.last_click_time < 500:
# Double-click detected
if current_row:
hbox = current_row.get_child()
game_label = hbox.get_children()[1]
title = game_label.get_text()
# Check if the game is already running
if title not in self.processos:
widget = self.button_play
self.on_button_play_clicked(widget)
else:
dialog = Gtk.MessageDialog(title=title, text=f"'{title}' is already running.",
buttons=Gtk.ButtonsType.OK, parent=self)
dialog.set_resizable(False)
dialog.set_modal(True)
dialog.set_icon_from_file(faugus_png)
dialog.run()
dialog.destroy()
else:
# Single-click, update last click details and enable buttons
self.last_clicked_row = current_row
self.last_click_time = current_time
self.update_button_sensitivity(current_row)
def update_button_sensitivity(self, row):
# Enable buttons based on the selected row
if row:
hbox = row.get_child()
game_label = hbox.get_children()[1]
title = game_label.get_text()
self.button_edit.set_sensitive(True)
self.button_delete.set_sensitive(True)
if title in self.processos:
self.button_play.set_sensitive(False)
self.button_play.set_image(
Gtk.Image.new_from_icon_name("media-playback-stop-symbolic", Gtk.IconSize.BUTTON))
else:
self.button_play.set_sensitive(True)
self.button_play.set_image(
Gtk.Image.new_from_icon_name("media-playback-start-symbolic", Gtk.IconSize.BUTTON))
else:
# Disable buttons if no row is selected
self.button_edit.set_sensitive(False)
self.button_delete.set_sensitive(False)
self.button_play.set_sensitive(False)
def load_close_onlaunch(self):
config_file = config_file_dir
close_onlaunch = False
if os.path.exists(config_file):
with open(config_file, 'r') as f:
config_data = f.read().splitlines()
config_dict = dict(line.split('=') for line in config_data)
close_onlaunch_value = config_dict.get('close-onlaunch', '').strip('"')
if close_onlaunch_value.lower() == 'true':
close_onlaunch = True
return close_onlaunch
def on_button_settings_clicked(self, widget):
# Handle add button click event
settings_dialog = Settings(self)
settings_dialog.connect("response", self.on_settings_dialog_response, settings_dialog)
settings_dialog.show()
def on_settings_dialog_response(self, dialog, response_id, settings_dialog):
self.checkbox_discrete_gpu = settings_dialog.checkbox_discrete_gpu
self.checkbox_close_after_launch = settings_dialog.checkbox_close_after_launch
self.entry_default_prefix = settings_dialog.entry_default_prefix
self.checkbox_mangohud = settings_dialog.checkbox_mangohud
self.checkbox_gamemode = settings_dialog.checkbox_gamemode
self.checkbox_sc_controller = settings_dialog.checkbox_sc_controller
self.combo_box_runner = settings_dialog.combo_box_runner
checkbox_state = self.checkbox_close_after_launch.get_active()
checkbox_discrete_gpu_state = self.checkbox_discrete_gpu.get_active()
default_prefix = self.entry_default_prefix.get_text()
mangohud_state = self.checkbox_mangohud.get_active()
gamemode_state = self.checkbox_gamemode.get_active()
sc_controller_state = self.checkbox_sc_controller.get_active()
default_runner = self.combo_box_runner.get_active_text()
# Handle dialog response
if response_id == Gtk.ResponseType.OK:
if default_prefix == "":
settings_dialog.entry_default_prefix.get_style_context().add_class("entry")
else:
self.save_config(checkbox_state, default_prefix, mangohud_state, gamemode_state, sc_controller_state, default_runner, checkbox_discrete_gpu_state)
settings_dialog.destroy()
else:
settings_dialog.destroy()
def on_button_play_clicked(self, widget):
if not (listbox_row := self.game_list.get_selected_row()):
return
# Get the selected game's title
hbox = listbox_row.get_child()
game_label = hbox.get_children()[1]
title = game_label.get_text()
# Find the selected game object
game = next((j for j in self.games if j.title == title), None)
if game:
# Format the title for command execution
title_formatted = re.sub(r'[^a-zA-Z0-9\s]', '', game.title)
title_formatted = title_formatted.replace(' ', '-')
title_formatted = '-'.join(title_formatted.lower().split())
# Extract game launch information
launch_arguments = game.launch_arguments
path = game.path
prefix = game.prefix
game_arguments = game.game_arguments
mangohud = game.mangohud
sc_controller = game.sc_controller
protonfix = game.protonfix
runner = game.runner
gamemode_enabled = os.path.exists("/usr/bin/gamemoderun") or os.path.exists("/usr/games/gamemoderun")
gamemode = game.gamemode if gamemode_enabled else ""
# Get the directory containing the executable
game_directory = os.path.dirname(path)
command_parts = []
# Add command parts if they are not empty
if mangohud:
command_parts.append(mangohud)
if sc_controller:
command_parts.append(sc_controller)
if prefix:
command_parts.append(f'WINEPREFIX={prefix}')
if protonfix:
command_parts.append(f'GAMEID={protonfix}')
else:
command_parts.append(f'GAMEID={title_formatted}')
if runner:
command_parts.append(f'PROTONPATH={runner}')
if gamemode:
command_parts.append(gamemode)
if launch_arguments:
command_parts.append(launch_arguments)
# Add the fixed command and remaining arguments
command_parts.append(f'"{umu_run}"')
if path:
command_parts.append(f'"{path}"')
if game_arguments:
command_parts.append(f'"{game_arguments}"')
# Join all parts into a single command
command = ' '.join(command_parts)
print(command)
# faugus-run path
faugus_run_path = faugus_run
# Launch the game with subprocess
if self.load_close_onlaunch():
subprocess.Popen([sys.executable, faugus_run_path, command], stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL, cwd=game_directory)
sys.exit()
else:
processo = subprocess.Popen([sys.executable, faugus_run_path, command], cwd=game_directory)
self.processos[title] = processo
self.button_play.set_sensitive(False)
self.button_play.set_image(
Gtk.Image.new_from_icon_name("media-playback-stop-symbolic", Gtk.IconSize.BUTTON))
def on_button_kill_clicked(self, widget):
# Handle kill button click event
subprocess.run(r"""
for pid in $(ls -l /proc/*/exe 2>/dev/null | grep -E 'wine(64)?-preloader|wineserver|winedevice.exe' | awk -F'/' '{print $3}'); do
kill -9 "$pid"
done
""", shell=True)
self.game_running = None
self.game_running2 = False
def on_button_add_clicked(self, widget):
file_path=""
# Handle add button click event
add_game_dialog = AddGame(self, self.game_running2, file_path)
add_game_dialog.connect("response", self.on_dialog_response, add_game_dialog)
add_game_dialog.show()
def on_button_edit_clicked(self, widget):
file_path=""
if not (listbox_row := self.game_list.get_selected_row()):
return
hbox = listbox_row.get_child()
game_label = hbox.get_children()[1]
title = game_label.get_text()
if game := next((j for j in self.games if j.title == title), None):
if game.title in self.processos:
self.game_running2 = True
else:
self.game_running2 = False
edit_game_dialog = AddGame(self, self.game_running2, file_path)
edit_game_dialog.connect("response", self.on_edit_dialog_response, edit_game_dialog, game)
edit_game_dialog.entry_title.set_text(game.title)
edit_game_dialog.entry_path.set_text(game.path)
edit_game_dialog.entry_prefix.set_text(game.prefix)
edit_game_dialog.entry_launch_arguments.set_text(game.launch_arguments)
edit_game_dialog.entry_game_arguments.set_text(game.game_arguments)
edit_game_dialog.set_title(f"Edit {game.title}")
edit_game_dialog.entry_protonfix.set_text(game.protonfix)
model = edit_game_dialog.combo_box_runner.get_model()
index_to_activate = 0
if game.runner == "GE-Proton":
game.runner = "GE-Proton Latest (default)"
for i, row in enumerate(model):
if row[0] == game.runner:
index_to_activate = i
break
if not game.runner:
index_to_activate = 1
edit_game_dialog.combo_box_runner.set_active(index_to_activate)
mangohud_status = False
gamemode_status = False
sc_controller_status = False
with open("games.txt", "r") as file:
for line in file:
fields = line.strip().split(";")
if len(fields) >= 8 and fields[0] == game.title:
mangohud_status = fields[5] == "MANGOHUD=1"
gamemode_status = fields[6] == "gamemoderun"
sc_controller_status = fields[7] == "SC_CONTROLLER=1"
mangohud_enabled = os.path.exists("/usr/bin/mangohud")
if mangohud_enabled:
edit_game_dialog.checkbox_mangohud.set_active(mangohud_status)
gamemode_enabled = os.path.exists("/usr/bin/gamemoderun") or os.path.exists("/usr/games/gamemoderun")
if gamemode_enabled:
edit_game_dialog.checkbox_gamemode.set_active(gamemode_status)
sc_controller_enabled = os.path.exists("/usr/bin/sc-controller") or os.path.exists(
"/usr/local/bin/sc-controller")
if sc_controller_enabled:
edit_game_dialog.checkbox_sc_controller.set_active(sc_controller_status)
edit_game_dialog.check_existing_shortcut()
image = self.set_image_shortcut_icon(game.title, edit_game_dialog.icons_path, edit_game_dialog.icon_temp)
edit_game_dialog.button_shortcut_icon.set_image(image)
edit_game_dialog.entry_title.set_sensitive(False)
if self.game_running2:
edit_game_dialog.button_winecfg.set_sensitive(False)
edit_game_dialog.button_winecfg.set_tooltip_text(f'{game.title} is running. Please close it first.')
edit_game_dialog.button_winetricks.set_sensitive(False)
edit_game_dialog.button_winetricks.set_tooltip_text(f'{game.title} is running. Please close it first.')
edit_game_dialog.button_run.set_sensitive(False)
edit_game_dialog.button_run.set_tooltip_text(f'{game.title} is running. Please close it first.')
edit_game_dialog.show()
def set_image_shortcut_icon(self, title, icons_path, icon_temp):
# Handle the click event of the Create Shortcut button
title_formatted = re.sub(r'[^a-zA-Z0-9\s]', '', title)
title_formatted = title_formatted.replace(' ', '-')
title_formatted = '-'.join(title_formatted.lower().split())
# Check if the icon file exists
icon_path = os.path.join(icons_path, f"{title_formatted}.ico")
if os.path.exists(icon_path):
shutil.copy(icon_path, icon_temp)
if not os.path.exists(icon_path):
icon_temp = faugus_png
pixbuf = GdkPixbuf.Pixbuf.new_from_file(icon_temp)
scaled_pixbuf = pixbuf.scale_simple(50, 50, GdkPixbuf.InterpType.BILINEAR)
image = Gtk.Image.new_from_file(icon_temp)
image.set_from_pixbuf(scaled_pixbuf)
return image
def on_button_delete_clicked(self, widget):
if not (listbox_row := self.game_list.get_selected_row()):
return
# Retrieve the selected game's title
hbox = listbox_row.get_child()
game_label = hbox.get_children()[1]
title = game_label.get_text()
if game := next((j for j in self.games if j.title == title), None):
# Display confirmation dialog
confirmation_dialog = ConfirmationDialog(self, title)
response = confirmation_dialog.run()
if response == Gtk.ResponseType.YES:
# Remove game and associated files if required
if confirmation_dialog.get_remove_prefix_state():
game_prefix = game.prefix
prefix_path = os.path.expanduser(game_prefix)
try:
shutil.rmtree(prefix_path)
except FileNotFoundError:
pass
# Remove the shortcut
self.remove_shortcut(game)
self.games.remove(game)
self.save_games()
self.update_list()
self.button_edit.set_sensitive(False)
self.button_delete.set_sensitive(False)
self.button_play.set_sensitive(False)
confirmation_dialog.destroy()
def on_dialog_response(self, dialog, response_id, add_game_dialog):
# Handle dialog response
if response_id == Gtk.ResponseType.OK:
if not add_game_dialog.validate_fields(entry="prefix"):
# If fields are not validated, return and keep the dialog open
return True
# Proceed with adding the game
# Get game information from dialog fields
title = add_game_dialog.entry_title.get_text()
path = add_game_dialog.entry_path.get_text()
launch_arguments = add_game_dialog.entry_launch_arguments.get_text()
game_arguments = add_game_dialog.entry_game_arguments.get_text()
prefix = add_game_dialog.entry_prefix.get_text()
protonfix = add_game_dialog.entry_protonfix.get_text()
runner = add_game_dialog.combo_box_runner.get_active_text()
title_formatted = re.sub(r'[^a-zA-Z0-9\s]', '', title)
title_formatted = title_formatted.replace(' ', '-')
title_formatted = '-'.join(title_formatted.lower().split())
# Concatenate game information
game_info = (f"{title};{path};{prefix};{launch_arguments};{game_arguments}")
# Determine mangohud and gamemode status
mangohud = "MANGOHUD=1" if add_game_dialog.checkbox_mangohud.get_active() else ""
gamemode = "gamemoderun" if add_game_dialog.checkbox_gamemode.get_active() else ""
sc_controller = "SC_CONTROLLER=1" if add_game_dialog.checkbox_sc_controller.get_active() else ""
if runner == "UMU-Proton Latest":
runner = ""
if runner == "GE-Proton Latest (default)":
runner = "GE-Proton"
game_info += f";{mangohud};{gamemode};{sc_controller};{protonfix};{runner}\n"
# Write game info to file
with open("games.txt", "a") as file:
file.write(game_info)
# Create Game object and update UI
game = Game(title, path, prefix, launch_arguments, game_arguments, mangohud, gamemode, sc_controller, protonfix, runner)
self.games.append(game)
# Determine the state of the shortcut checkbox
shortcut_state = add_game_dialog.checkbox_shortcut.get_active()
icon_temp = os.path.expanduser(add_game_dialog.icon_temp)
icon_final = f'{add_game_dialog.icons_path}/{title_formatted}.ico'
# Call add_remove_shortcut method
self.add_shortcut(game, shortcut_state, icon_temp, icon_final)
self.add_item_list(game)
self.update_list()
# Select the added game
self.select_game_by_title(title)
else:
if os.path.isfile(add_game_dialog.icon_temp):
os.remove(add_game_dialog.icon_temp)
if os.path.isdir(add_game_dialog.icon_directory):
shutil.rmtree(add_game_dialog.icon_directory)
add_game_dialog.destroy()
# Ensure the dialog is destroyed when canceled
add_game_dialog.destroy()
def select_game_by_title(self, title):
# Select an item from the list based on title
for row in self.game_list.get_children():
hbox = row.get_child()
game_label = hbox.get_children()[1]
if game_label.get_text() == title:
self.game_list.select_row(row)
break
self.button_edit.set_sensitive(True)
self.button_delete.set_sensitive(True)
self.button_play.set_sensitive(True)
self.button_play.set_image(
Gtk.Image.new_from_icon_name("media-playback-start-symbolic", Gtk.IconSize.BUTTON))
def on_edit_dialog_response(self, dialog, response_id, edit_game_dialog, game):
# Handle edit dialog response
if response_id == Gtk.ResponseType.OK:
if not edit_game_dialog.validate_fields(entry="prefix"):
# If fields are not validated, return and keep the dialog open
return True
# Update game object with new information
game.title = edit_game_dialog.entry_title.get_text()
game.path = edit_game_dialog.entry_path.get_text()
game.prefix = edit_game_dialog.entry_prefix.get_text()
game.launch_arguments = edit_game_dialog.entry_launch_arguments.get_text()
game.game_arguments = edit_game_dialog.entry_game_arguments.get_text()
game.mangohud = edit_game_dialog.checkbox_mangohud.get_active()
game.gamemode = edit_game_dialog.checkbox_gamemode.get_active()
game.sc_controller = edit_game_dialog.checkbox_sc_controller.get_active()
game.protonfix = edit_game_dialog.entry_protonfix.get_text()
game.runner = edit_game_dialog.combo_box_runner.get_active_text()
# Handle the click event of the Create Shortcut button
title_formatted = re.sub(r'[^a-zA-Z0-9\s]', '', game.title)
title_formatted = title_formatted.replace(' ', '-')
title_formatted = '-'.join(title_formatted.lower().split())
if game.runner == "UMU-Proton Latest":
game.runner = ""
if game.runner == "GE-Proton Latest (default)":
game.runner = "GE-Proton"
icon_temp = os.path.expanduser(edit_game_dialog.icon_temp)
icon_final = f'{edit_game_dialog.icons_path}/{title_formatted}.ico'
# Determine the state of the shortcut checkbox
shortcut_state = edit_game_dialog.checkbox_shortcut.get_active()
# Call add_remove_shortcut method
self.add_shortcut(game, shortcut_state, icon_temp, icon_final)
# Save changes and update UI
self.save_games()
self.update_list()
# Select the game that was edited
self.select_game_by_title(game.title)
else:
if os.path.isfile(edit_game_dialog.icon_temp):
os.remove(edit_game_dialog.icon_temp)
if os.path.isdir(edit_game_dialog.icon_directory):
shutil.rmtree(edit_game_dialog.icon_directory)
edit_game_dialog.destroy()
def add_shortcut(self, game, shortcut_state, icon_temp, icon_final):
# Check if the shortcut checkbox is checked
if not shortcut_state:
# Remove existing shortcut if it exists
self.remove_shortcut(game)
if os.path.isfile(os.path.expanduser(icon_temp)):
os.rename(os.path.expanduser(icon_temp), icon_final)
return
if os.path.isfile(os.path.expanduser(icon_temp)):
os.rename(os.path.expanduser(icon_temp), icon_final)
# Handle the click event of the Create Shortcut button
title_formatted = re.sub(r'[^a-zA-Z0-9\s]', '', game.title)
title_formatted = title_formatted.replace(' ', '-')
title_formatted = '-'.join(title_formatted.lower().split())
prefix = game.prefix
path = game.path
launch_arguments = game.launch_arguments
game_arguments = game.game_arguments
protonfix = game.protonfix
runner = game.runner
mangohud = "MANGOHUD=1" if game.mangohud else ""
gamemode = "gamemoderun" if game.gamemode else ""
sc_controller = "SC_CONTROLLER=1" if game.sc_controller else ""
# Check if the icon file exists
icons_path = icons_dir
new_icon_path = f"{icons_dir}/{title_formatted}.ico"
if not os.path.exists(new_icon_path):
new_icon_path = faugus_png
# Get the directory containing the executable
game_directory = os.path.dirname(path)
command_parts = []
# Add command parts if they are not empty
if mangohud:
command_parts.append(mangohud)
if sc_controller:
command_parts.append(sc_controller)
if prefix:
command_parts.append(f'WINEPREFIX={prefix}')
if protonfix:
command_parts.append(f'GAMEID={protonfix}')
else:
command_parts.append(f'GAMEID={title_formatted}')
if runner:
command_parts.append(f'PROTONPATH={runner}')
if gamemode:
command_parts.append(gamemode)
if launch_arguments:
command_parts.append(launch_arguments)
# Add the fixed command and remaining arguments
command_parts.append(f"'{umu_run}'")
if path:
command_parts.append(f"'{path}'")
if game_arguments:
command_parts.append(f"'{game_arguments}'")
# Join all parts into a single command
command = ' '.join(command_parts)
# Create a .desktop file
desktop_file_content = f"""[Desktop Entry]
Name={game.title}
Exec={faugus_run} "{command}"
Icon={new_icon_path}
Type=Application
Categories=Game;
Path={game_directory}
"""
# Check if the destination directory exists and create if it doesn't
applications_directory = app_dir
if not os.path.exists(applications_directory):
os.makedirs(applications_directory)
desktop_directory = desktop_dir
if not os.path.exists(desktop_directory):
os.makedirs(desktop_directory)
applications_shortcut_path = f"{app_dir}/{title_formatted}.desktop"
with open(applications_shortcut_path, 'w') as desktop_file:
desktop_file.write(desktop_file_content)
# Make the .desktop file executable
os.chmod(applications_shortcut_path, 0o755)
# Copy the shortcut to Desktop
desktop_shortcut_path = f"{desktop_dir}/{title_formatted}.desktop"
shutil.copy(applications_shortcut_path, desktop_shortcut_path)
def update_preview(self, dialog):
if file_path := dialog.get_preview_filename():
try:
# Create an image widget for the thumbnail
pixbuf = GdkPixbuf.Pixbuf.new_from_file(file_path)
# Resize the thumbnail if it's too large, maintaining the aspect ratio
max_width = 400
max_height = 400
width = pixbuf.get_width()
height = pixbuf.get_height()
if width > max_width or height > max_height:
# Calculate the new width and height while maintaining the aspect ratio
ratio = min(max_width / width, max_height / height)
new_width = int(width * ratio)
new_height = int(height * ratio)
pixbuf = pixbuf.scale_simple(new_width, new_height, GdkPixbuf.InterpType.BILINEAR)
image = Gtk.Image.new_from_pixbuf(pixbuf)
dialog.set_preview_widget(image)
dialog.set_preview_widget_active(True)
dialog.get_preview_widget().set_size_request(max_width, max_height)
except GLib.Error:
dialog.set_preview_widget_active(False)
else:
dialog.set_preview_widget_active(False)
def remove_shortcut(self, game):
# Remove existing shortcut if it exists
title_formatted = re.sub(r'[^a-zA-Z0-9\s]', '', game.title)
title_formatted = title_formatted.replace(' ', '-')
title_formatted = '-'.join(title_formatted.lower().split())
desktop_file_path = f"{app_dir}/{title_formatted}.desktop"
if os.path.exists(desktop_file_path):
os.remove(desktop_file_path)
# Remove shortcut from Desktop if exists
desktop_shortcut_path = f"{desktop_dir}/{title_formatted}.desktop"
if os.path.exists(desktop_shortcut_path):
os.remove(desktop_shortcut_path)
# Remove icon file
icon_file_path = f"{icons_dir}/{title_formatted}.ico"
if os.path.exists(icon_file_path):
os.remove(icon_file_path)
def remove_desktop_entry(self, game):
# Remove the .desktop file from ~/.local/share/applications/
desktop_file_path = f"{app_dir}/{game.title}.desktop"
if os.path.exists(desktop_file_path):
os.remove(desktop_file_path)
def remove_shortcut_from_desktop(self, game):
# Remove the shortcut from the desktop if it exists
desktop_link_path = f"{desktop_dir}/{game.title}.desktop"
if os.path.exists(desktop_link_path):
os.remove(desktop_link_path)
def update_list(self):
# Update the game list
for row in self.game_list.get_children():
self.game_list.remove(row)
self.games.clear()
self.load_games()
self.entry_search.set_text("")
self.show_all()
def on_child_process_closed(self, signum, frame):
for title, processo in list(self.processos.items()):
retcode = processo.poll()
if retcode is not None:
del self.processos[title]
listbox_row = self.game_list.get_selected_row()
if listbox_row:
hbox = listbox_row.get_child()
game_label = hbox.get_children()[1]
selected_title = game_label.get_text()
if selected_title not in self.processos:
self.button_play.set_sensitive(True)
self.button_play.set_image(
Gtk.Image.new_from_icon_name("media-playback-start-symbolic", Gtk.IconSize.BUTTON))
else:
self.button_play.set_sensitive(False)
self.button_play.set_image(
Gtk.Image.new_from_icon_name("media-playback-stop-symbolic", Gtk.IconSize.BUTTON))