forked from moraroy/NonSteamLaunchers-On-Steam-Deck
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NSLGameScanner.py
1103 lines (929 loc) · 47 KB
/
NSLGameScanner.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/env python3
import os, re
import json
import shutil
import binascii
import ctypes
import zipfile
import time
import sys
import subprocess
import sqlite3
from urllib.request import urlopen
from urllib.request import urlretrieve
from base64 import b64encode
import xml.etree.ElementTree as ET
# Check the value of the DBUS_SESSION_BUS_ADDRESS environment variable
dbus_address = os.environ.get('DBUS_SESSION_BUS_ADDRESS')
if not dbus_address or not dbus_address.startswith('unix:path='):
# Set the value of the DBUS_SESSION_BUS_ADDRESS environment variable
dbus_address = f'unix:path=/run/user/{os.getuid()}/bus'
os.environ['DBUS_SESSION_BUS_ADDRESS'] = dbus_address
# Path to the env_vars file
env_vars_path = f"{os.environ['HOME']}/.config/systemd/user/env_vars"
# Check if the env_vars file exists
if not os.path.exists(env_vars_path):
print(f"Error: {env_vars_path} does not exist.")
sys.exit(1)
# Read variables from the file
with open(env_vars_path, 'r') as f:
lines = f.readlines()
for line in lines:
if line.startswith('export '):
line = line[7:] # Remove 'export '
name, value = line.strip().split('=', 1)
os.environ[name] = value
# Delete env_vars entries for Chrome shortcuts so that they're only added once
with open(env_vars_path, 'w') as f:
for line in lines:
if line.find('chromelaunchoptions') == -1 and line.find('websites_str') == -1:
f.write(line)
# Variables from NonSteamLaunchers.sh
steamid3 = os.environ['steamid3']
logged_in_home = os.environ['logged_in_home']
compat_tool_name = os.environ['compat_tool_name']
controller_config_path = os.environ['controller_config_path']
python_version = os.environ['python_version']
#Scanner Variables
epic_games_launcher = os.environ.get('epic_games_launcher', '')
ubisoft_connect_launcher = os.environ.get('ubisoft_connect_launcher', '')
ea_app_launcher = os.environ.get('ea_app_launcher', '')
gog_galaxy_launcher = os.environ.get('gog_galaxy_launcher', '')
bnet_launcher = os.environ.get('bnet_launcher', '')
amazon_launcher = os.environ.get('amazon_launcher', '')
#Variables of the Launchers
# Define the path of the Launchers
epicshortcutdirectory = os.environ.get('epicshortcutdirectory')
gogshortcutdirectory = os.environ.get('gogshortcutdirectory')
uplayshortcutdirectory = os.environ.get('uplayshortcutdirectory')
battlenetshortcutdirectory = os.environ.get('battlenetshortcutdirectory')
eaappshortcutdirectory = os.environ.get('eaappshortcutdirectory')
amazonshortcutdirectory = os.environ.get('amazonshortcutdirectory')
itchioshortcutdirectory = os.environ.get('itchioshortcutdirectory')
legacyshortcutdirectory = os.environ.get('legacyshortcutdirectory')
humbleshortcutdirectory = os.environ.get('humbleshortcutdirectory')
indieshortcutdirectory = os.environ.get('indieshortcutdirectory')
rockstarshortcutdirectory = os.environ.get('rockstarshortcutdirectory')
glyphshortcutdirectory = os.environ.get('glyphshortcutdirectory')
minecraftshortcutdirectory = os.environ.get('minecraftshortcutdirectory')
psplusshortcutdirectory = os.environ.get('psplusshortcutdirectory')
vkplayhortcutdirectory = os.environ.get('vkplayhortcutdirectory')
#Streaming
chromedirectory = os.environ.get('chromedirectory')
websites_str = os.environ.get('custom_websites_str')
custom_websites = websites_str.split(', ') if websites_str else []
# Define the parent folder
parent_folder = f"{logged_in_home}/.config/systemd/user/Modules"
sys.path.insert(0, os.path.expanduser(f"{logged_in_home}/.config/systemd/user/Modules"))
print(sys.path)
# Now that the requests module has been downloaded, you can import it
sys.path.insert(0, parent_folder)
import requests
import vdf
from steamgrid import SteamGridDB
print(sys.path)
#Set Up nslgamescanner.service
# Define the paths
service_path = f"{logged_in_home}/.config/systemd/user/nslgamescanner.service"
# Define the service file content
service_content = f"""
[Unit]
Description=NSL Game Scanner
[Service]
ExecStart=/usr/bin/python3 '{logged_in_home}/.config/systemd/user/NSLGameScanner.py'
Restart=always
RestartSec=10
StartLimitBurst=40
StartLimitInterval=240
[Install]
WantedBy=default.target
"""
# Check if the service file already exists
if not os.path.exists(service_path):
# Create the service file
with open(service_path, 'w') as f:
f.write(service_content)
print("Service file created.")
# Check if the service is already running
result = subprocess.run(['systemctl', '--user', 'is-active', 'nslgamescanner.service'], stdout=subprocess.PIPE)
if result.stdout.decode('utf-8').strip() != 'active':
# Reload the systemd manager configuration
subprocess.run(['systemctl', '--user', 'daemon-reload'])
# Enable the service to start on boot
subprocess.run(['systemctl', '--user', 'enable', 'nslgamescanner.service'])
# Start the service immediately
subprocess.run(['systemctl', '--user', 'start', 'nslgamescanner.service'])
print("Service started.")
else:
print("Service is already running.")
#Code
def get_steam_shortcut_id(exe_path, display_name):
unique_id = "".join([exe_path, display_name])
id_int = binascii.crc32(str.encode(unique_id)) | 0x80000000
signed = ctypes.c_int(id_int)
# print(f"Signed ID: {signed.value}")
return signed.value
def get_unsigned_shortcut_id(signed_shortcut_id):
unsigned = ctypes.c_uint(signed_shortcut_id)
# print(f"Unsigned ID: {unsigned.value}")
return unsigned.value
# Initialize an empty dictionary to serve as the cache
api_cache = {}
#API KEYS FOR NONSTEAMLAUNCHER USE ONLY
sgdb = SteamGridDB('36e4bedbfdda27f42f9ef4a44f80955c')
api_key = '36e4bedbfdda27f42f9ef4a44f80955c'
#GLOBAL VARS
created_shortcuts = []
new_shortcuts_added = False
shortcuts_updated = False
shortcut_id = None # Initialize shortcut_id
decky_shortcuts = {}
gridp64 = ""
grid64 = ""
logo64 = ""
hero64 = ""
# Load the existing shortcuts
with open(f"{logged_in_home}/.steam/root/userdata/{steamid3}/config/shortcuts.vdf", 'rb') as file:
shortcuts = vdf.binary_loads(file.read()).get('shortcuts', {})
# Print the existing shortcuts
if shortcuts:
# Print the shortcut information in JSON format
print(json.dumps(shortcuts), flush=True) # Print to stdout
# Open the config.vdf file
with open(f"{logged_in_home}/.steam/root/config/config.vdf", 'r') as file:
config_data = vdf.load(file)
def get_sgdb_art(game_id, app_id):
global grid64
global gridp64
global logo64
global hero64
print(f"Downloading icons artwork...")
download_artwork(game_id, api_key, "icons", app_id)
print(f"Downloading logos artwork...")
logo64 = download_artwork(game_id, api_key, "logos", app_id)
print(f"Downloading heroes artwork...")
hero64 = download_artwork(game_id, api_key, "heroes", app_id)
print("Downloading grids artwork of size 600x900...")
gridp64 = download_artwork(game_id, api_key, "grids", app_id, "600x900")
print("Downloading grids artwork of size 920x430...")
grid64 =download_artwork(game_id, api_key, "grids", app_id, "920x430")
def download_artwork(game_id, api_key, art_type, shortcut_id, dimensions=None):
# Create a cache key based on the function's arguments
cache_key = (game_id, art_type, dimensions)
# Check if the artwork already exists
if dimensions is not None:
filename = get_file_name(art_type, shortcut_id, dimensions)
else:
filename = get_file_name(art_type, shortcut_id)
file_path = f"{logged_in_home}/.steam/root/userdata/{steamid3}/config/grid/{filename}"
directory = os.path.dirname(file_path)
if not os.path.exists(directory):
os.makedirs(directory)
if os.path.exists(file_path):
print(f"Artwork for {game_id} already exists. Skipping download.")
with open(file_path, 'rb') as image_file:
return b64encode(image_file.read()).decode('utf-8')
# If the result is in the cache, use it
if cache_key in api_cache:
data = api_cache[cache_key]
else:
# If the result is not in the cache, make the API call
print(f"Game ID: {game_id}, API Key: {api_key}")
url = f"https://www.steamgriddb.com/api/v2/{art_type}/game/{game_id}"
if dimensions:
url += f"?dimensions={dimensions}"
headers = {'Authorization': f'Bearer {api_key}'}
print(f"Sending request to: {url}") # Added print statement
response = requests.get(url, headers=headers)
if response.status_code == 200:
data = response.json()
# Store the result in the cache
api_cache[cache_key] = data
else:
print(f"Error making API call: {response.status_code}")
# Store the failed status in the cache
api_cache[cache_key] = None
return
# Continue with the rest of your function using `data`
for artwork in data['data']:
image_url = artwork['thumb']
print(f"Downloading image from: {image_url}") # Added print statement
try:
response = requests.get(image_url, stream=True)
response.raise_for_status()
if response.status_code == 200:
with open(file_path, 'wb') as file:
file.write(response.content)
return b64encode(response.content).decode('utf-8')
except requests.exceptions.RequestException as e:
print(f"Error downloading image: {e}")
if art_type == 'icons':
download_artwork(game_id, api_key, 'icons_ico', shortcut_id)
def get_game_id(game_name):
print(f"Searching for game ID for: {game_name}")
games = sgdb.search_game(game_name)
for game in games:
if game.name == game_name: # Case-sensitive comparison
print(f"Found game ID: {game.id}")
return game.id
# Fallback: return the ID of the first game in the search results
if games:
print(f"No exact match found. Using game ID of the first result: {games[0].name}: {games[0].id}")
return games[0].id
print("No game ID found")
return "default_game_id" # Return a default value when no games are found
def get_file_name(art_type, shortcut_id, dimensions=None):
singular_art_type = art_type.rstrip('s')
if art_type == 'icons':
if os.path.exists(f"{logged_in_home}/.steam/root/userdata/{steamid3}/config/grid/{shortcut_id}-{singular_art_type}.png"):
return f"{shortcut_id}-{singular_art_type}.png"
else:
return f"{shortcut_id}-{singular_art_type}.ico"
elif art_type == 'grids':
if dimensions == '600x900':
return f"{shortcut_id}p.png"
else:
return f"{shortcut_id}.png"
elif art_type == 'heroes':
return f"{shortcut_id}_hero.png"
elif art_type == 'logos':
return f"{shortcut_id}_logo.png"
else:
return f"{shortcut_id}.png"
def is_match(name1, name2):
if name1 and name2:
return name1.lower() in name2.lower() or name2.lower() in name1.lower()
else:
return False
# Add or update the proton compatibility settings
def add_compat_tool(app_id, launchoptions):
if 'CompatToolMapping' not in config_data['InstallConfigStore']['Software']['Valve']['Steam']:
config_data['InstallConfigStore']['Software']['Valve']['Steam']['CompatToolMapping'] = {}
print(f"CompatToolMapping key not found in config.vdf, creating.")
if 'chrome' in launchoptions:
return False
elif str(app_id) in config_data['InstallConfigStore']['Software']['Valve']['Steam']['CompatToolMapping']:
config_data['InstallConfigStore']['Software']['Valve']['Steam']['CompatToolMapping'][str(app_id)]['name'] = f'{compat_tool_name}'
config_data['InstallConfigStore']['Software']['Valve']['Steam']['CompatToolMapping'][str(app_id)]['config'] = ''
config_data['InstallConfigStore']['Software']['Valve']['Steam']['CompatToolMapping'][str(app_id)]['priority'] = '250'
print(f"Updated CompatToolMapping entry for appid: {app_id}")
return compat_tool_name
else:
config_data['InstallConfigStore']['Software']['Valve']['Steam']['CompatToolMapping'][str(app_id)] = {'name': f'{compat_tool_name}', 'config': '', 'priority': '250'}
print(f"Created new CompatToolMapping entry for appid: {app_id}")
return compat_tool_name
def check_if_shortcut_exists(shortcut_id, display_name, exe_path, start_dir, launch_options):
# Check if the game already exists in the shortcuts using the id
if any(s.get('appid') == shortcut_id for s in shortcuts.values()):
print(f"Existing shortcut found based on shortcut ID for game {display_name}. Skipping creation.")
return True
# Check if the game already exists in the shortcuts using the fields (probably unnecessary)
if any(s.get('appname') == display_name and s.get('exe') == exe_path and s.get('StartDir') == start_dir and s.get('LaunchOptions') == launch_options for s in shortcuts.values()):
print(f"Existing shortcut found based on matching fields for game {display_name}. Skipping creation.")
return True
if any(s.get('AppName') == display_name and s.get('Exe') == exe_path and s.get('StartDir') == start_dir and s.get('LaunchOptions') == launch_options for s in shortcuts.values()):
print(f"Existing shortcut found based on matching fields for game {display_name}. Skipping creation.")
return True
#End of Code
#Start of Refactoring code from the .sh file
sys.path.insert(0, os.path.expanduser(f"{logged_in_home}/Downloads/NonSteamLaunchersInstallation/lib/python{python_version}/site-packages"))
print(sys.path)
# Create an empty dictionary to store the app IDs
app_ids = {}
#Create Shortcuts
def create_new_entry(shortcutdirectory, appname, launchoptions, startingdir):
global new_shortcuts_added
global shortcuts_updated
global created_shortcuts
global decky_shortcuts
global grid64
global gridp64
global logo64
global hero64
# Check if the launcher is installed
if not shortcutdirectory or not appname or not launchoptions or not startingdir:
print(f"{appname} is not installed. Skipping.")
return
exe_path = f"{shortcutdirectory}"
signed_shortcut_id = get_steam_shortcut_id(exe_path, appname)
unsigned_shortcut_id = get_unsigned_shortcut_id(signed_shortcut_id)
# Only store the app ID for specific launchers
if appname in ['Epic Games', 'Gog Galaxy', 'Ubisoft Connect', 'Battle.net', 'EA App', 'Amazon Games', 'itch.io', 'Legacy Games', 'Humble Bundle', 'IndieGala Client', 'Rockstar Games Launcher', 'Glyph', 'Minecraft: Java Edition', 'Playstation Plus', 'VK Play']:
app_ids[appname] = unsigned_shortcut_id
# Check if the game already exists in the shortcuts
if check_if_shortcut_exists(signed_shortcut_id, appname, exe_path, startingdir, launchoptions):
# Check if proton needs applying or updating
if add_compat_tool(unsigned_shortcut_id, launchoptions):
shortcuts_updated = True
return
#Get artwork
game_id = get_game_id(appname)
if game_id is not None:
get_sgdb_art(game_id, unsigned_shortcut_id)
# Create a new entry for the Steam shortcut
compatTool= add_compat_tool(unsigned_shortcut_id, launchoptions)
new_entry = {
'appid': str(signed_shortcut_id),
'appname': appname,
'exe': exe_path,
'StartDir': startingdir,
'icon': f"{logged_in_home}/.steam/root/userdata/{steamid3}/config/grid/{get_file_name('icons', unsigned_shortcut_id)}",
'LaunchOptions': launchoptions,
}
decky_entry = {
'appname': appname,
'exe': exe_path,
'StartDir': startingdir,
'icon': f"{logged_in_home}/.steam/root/userdata/{steamid3}/config/grid/{get_file_name('icons', unsigned_shortcut_id)}",
'LaunchOptions': launchoptions,
'CompatTool': compatTool,
'WideGrid': grid64,
'Grid': gridp64,
'Hero': hero64,
'Logo': logo64,
}
# Add the new entry to the shortcuts dictionary and add proton
shortcuts[str(signed_shortcut_id)] = new_entry
decky_shortcuts[appname] = decky_entry
print(f"Added new entry for {appname} to shortcuts.")
new_shortcuts_added = True
created_shortcuts.append(appname)
create_new_entry(os.environ.get('epicshortcutdirectory'), 'Epic Games', os.environ.get('epiclaunchoptions'), os.environ.get('epicstartingdir'))
create_new_entry(os.environ.get('gogshortcutdirectory'), 'Gog Galaxy', os.environ.get('goglaunchoptions'), os.environ.get('gogstartingdir'))
create_new_entry(os.environ.get('uplayshortcutdirectory'), 'Ubisoft Connect', os.environ.get('uplaylaunchoptions'), os.environ.get('uplaystartingdir'))
create_new_entry(os.environ.get('battlenetshortcutdirectory'), 'Battle.net', os.environ.get('battlenetlaunchoptions'), os.environ.get('battlenetstartingdir'))
create_new_entry(os.environ.get('eaappshortcutdirectory'), 'EA App', os.environ.get('eaapplaunchoptions'), os.environ.get('eaappstartingdir'))
create_new_entry(os.environ.get('amazonshortcutdirectory'), 'Amazon Games', os.environ.get('amazonlaunchoptions'), os.environ.get('amazonstartingdir'))
create_new_entry(os.environ.get('itchioshortcutdirectory'), 'itch.io', os.environ.get('itchiolaunchoptions'), os.environ.get('itchiostartingdir'))
create_new_entry(os.environ.get('legacyshortcutdirectory'), 'Legacy Games', os.environ.get('legacylaunchoptions'), os.environ.get('legacystartingdir'))
create_new_entry(os.environ.get('humbleshortcutdirectory'), 'Humble Bundle', os.environ.get('humblelaunchoptions'), os.environ.get('humblestartingdir'))
create_new_entry(os.environ.get('indieshortcutdirectory'), 'IndieGala Client', os.environ.get('indielaunchoptions'), os.environ.get('indiestartingdir'))
create_new_entry(os.environ.get('rockstarshortcutdirectory'), 'Rockstar Games Launcher', os.environ.get('rockstarlaunchoptions'), os.environ.get('rockstarstartingdir'))
create_new_entry(os.environ.get('glyphshortcutdirectory'), 'Glyph', os.environ.get('glyphlaunchoptions'), os.environ.get('glyphstartingdir'))
create_new_entry(os.environ.get('minecraftshortcutdirectory'), 'Minecraft: Java Edition', os.environ.get('minecraftlaunchoptions'), os.environ.get('minecraftstartingdir'))
create_new_entry(os.environ.get('psplusshortcutdirectory'), 'Playstation Plus', os.environ.get('pspluslaunchoptions'), os.environ.get('psplusstartingdir'))
create_new_entry(os.environ.get('vkplayhortcutdirectory'), 'VK Play', os.environ.get('vkplaylaunchoptions'), os.environ.get('vkplaystartingdir'))
create_new_entry(os.environ.get('chromedirectory'), 'Xbox Game Pass', os.environ.get('xboxchromelaunchoptions'), os.environ.get('chrome_startdir'))
create_new_entry(os.environ.get('chromedirectory'), 'GeForce Now', os.environ.get('geforcechromelaunchoptions'), os.environ.get('chrome_startdir'))
create_new_entry(os.environ.get('chromedirectory'), 'Netflix', os.environ.get('netlfixchromelaunchoptions'), os.environ.get('chrome_startdir'))
create_new_entry(os.environ.get('chromedirectory'), 'Hulu', os.environ.get('huluchromelaunchoptions'), os.environ.get('chrome_startdir'))
create_new_entry(os.environ.get('chromedirectory'), 'Disney+', os.environ.get('disneychromelaunchoptions'), os.environ.get('chrome_startdir'))
create_new_entry(os.environ.get('chromedirectory'), 'Amazon Prime Video', os.environ.get('amazonchromelaunchoptions'), os.environ.get('chrome_startdir'))
create_new_entry(os.environ.get('chromedirectory'), 'Youtube', os.environ.get('youtubechromelaunchoptions'), os.environ.get('chrome_startdir'))
create_new_entry(os.environ.get('chromedirectory'), 'Amazon Luna', os.environ.get('lunachromelaunchoptions'), os.environ.get('chrome_startdir'))
create_new_entry(os.environ.get('chromedirectory'), 'Twitch', os.environ.get('twitchchromelaunchoptions'), os.environ.get('chrome_startdir'))
create_new_entry(os.environ.get('chromedirectory'), 'movie-web', os.environ.get('moviewebchromelaunchoptions'), os.environ.get('chrome_startdir'))
# Iterate over each custom website
for custom_website in custom_websites:
# Check if the custom website is not an empty string
if custom_website:
# Remove any leading or trailing spaces from the custom website URL
custom_website = custom_website.strip()
# Remove the 'http://' or 'https://' prefix and the 'www.' prefix, if present
clean_website = custom_website.replace('http://', '').replace('https://', '').replace('www.', '')
# Define a regular expression pattern to extract the game name from the URL
pattern = r'/games/([\w-]+)'
# Use the regular expression to search for the game name in the custom website URL
match = re.search(pattern, custom_website)
# Check if a match was found
if match:
# Extract the game name from the match object
game_name = match.group(1)
# Replace hyphens with spaces
game_name = game_name.replace('-', ' ')
# Capitalize the first letter of each word in the game name
game_name = game_name.title()
else:
# Use the entire URL as the entry name
game_name = clean_website
# Define the launch options for this website
chromelaunch_options = f'run --branch=stable --arch=x86_64 --command=/app/bin/chrome --file-forwarding com.google.Chrome @@u @@ --window-size=1280,800 --force-device-scale-factor=1.00 --device-scale-factor=1.00 --kiosk https://{clean_website}/ --chrome-kiosk-type=fullscreen --no-first-run --enable-features=OverlayScrollbar'
# Call the create_new_entry function for this website
create_new_entry(os.environ['chromedirectory'], game_name, chromelaunch_options, os.environ['chrome_startdir'])
#End of Creating Launcher Shortcuts
# Iterate over each launcher in the app_ids dictionary
for launcher_name, appid in app_ids.items():
print(f"The app ID for {launcher_name} is {appid}")
# Get the app ID for the first launcher that the user chose to install
if app_ids:
appid = app_ids.get(launcher_name)
#Create User Friendly Symlinks for the launchers
# Define the path to the compatdata directory
compatdata_dir = f'{logged_in_home}/.local/share/Steam/steamapps/compatdata'
# Define a dictionary of original folder names
folder_names = {
'Epic Games': 'EpicGamesLauncher',
'Gog Galaxy': 'GogGalaxyLauncher',
'Ubisoft Connect': 'UplayLauncher',
'Battle.net': 'Battle.netLauncher',
'EA App': 'TheEAappLauncher',
'Amazon Games': 'AmazonGamesLauncher',
'itch.io': 'itchioLauncher',
'Legacy Games': 'LegacyGamesLauncher',
'Humble Bundle': 'HumbleGamesLauncher',
'IndieGala Client': 'IndieGalaLauncher',
'Rockstar Games Launcher': 'RockstarGamesLauncher',
'Minecraft: Java Edition': 'MinecraftLauncher',
'Playstation Plus': 'PlaystationPlusLauncher',
'VK Play': 'VKPlayLauncher',
}
# Iterate over each launcher in the folder_names dictionary
for launcher_name, folder in folder_names.items():
# Define the current path of the folder
current_path = os.path.join(compatdata_dir, folder)
# Check if the folder exists
if os.path.exists(current_path):
print(f'{launcher_name}: {folder} exists')
# Check if NonSteamLaunchers is already a symbolic link
if os.path.islink(current_path):
print(f'{launcher_name} is already a symbolic link')
else:
# Get the app ID for this launcher from the app_id_to_name dictionary
appid = app_ids.get(launcher_name)
# Define the new path of the folder
new_path = os.path.join(compatdata_dir, str(appid))
# Rename the folder
os.rename(current_path, new_path)
# Define the path of the symbolic link
symlink_path = os.path.join(compatdata_dir, folder)
# Create a symbolic link to the renamed folder
os.symlink(new_path, symlink_path)
else:
print(f'{launcher_name}: {folder} does not exist')
# Check if the NonSteamLaunchers folder exists
if app_ids and os.path.exists(os.path.join(compatdata_dir, 'NonSteamLaunchers')):
# Get the first app ID from the app_ids list
first_app_id = next(iter(app_ids.values()))
# Define the current path of the NonSteamLaunchers folder
current_path = os.path.join(compatdata_dir, 'NonSteamLaunchers')
# Check if NonSteamLaunchers is already a symbolic link
if os.path.islink(current_path):
print('NonSteamLaunchers is already a symbolic link')
else:
# Define the new path of the NonSteamLaunchers folder
new_path = os.path.join(compatdata_dir, str(first_app_id))
# Move the NonSteamLaunchers folder to the new path
shutil.move(current_path, new_path)
# Define the path of the symbolic link
symlink_path = os.path.join(compatdata_dir, 'NonSteamLaunchers')
# Create a symbolic link to the renamed NonSteamLaunchers folder
os.symlink(new_path, symlink_path)
#End of Refactoring python code from .sh file
# Print the existing shortcuts
print("Existing Shortcuts:")
for shortcut in shortcuts.values():
if shortcut.get('appname') is None:
print(f"AppID for {shortcut.get('AppName')}: {shortcut.get('appid')}")
else:
print(f"AppID for {shortcut.get('appname')}: {shortcut.get('appid')}")
#Scanners
# Epic Games Scanner
item_dir = f"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{epic_games_launcher}/pfx/drive_c/ProgramData/Epic/EpicGamesLauncher/Data/Manifests/"
dat_file_path = f"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{epic_games_launcher}/pfx/drive_c/ProgramData/Epic/UnrealEngineLauncher/LauncherInstalled.dat"
if os.path.exists(dat_file_path) and os.path.exists(item_dir):
with open(dat_file_path, 'r') as file:
dat_data = json.load(file)
#Epic Game Scanner
for item_file in os.listdir(item_dir):
if item_file.endswith('.item'):
with open(os.path.join(item_dir, item_file), 'r') as file:
item_data = json.load(file)
# Initialize variables
display_name = item_data['DisplayName']
app_name = item_data['AppName']
exe_path = f"\"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{epic_games_launcher}/pfx/drive_c/Program Files (x86)/Epic Games/Launcher/Portal/Binaries/Win32/EpicGamesLauncher.exe\""
start_dir = f"\"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{epic_games_launcher}/pfx/drive_c/Program Files (x86)/Epic Games/Launcher/Portal/Binaries/Win32/\""
launch_options = f"STEAM_COMPAT_DATA_PATH=\"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{epic_games_launcher}\" %command% -'com.epicgames.launcher://apps/{app_name}?action=launch&silent=true'"
# Check if the game is still installed
for game in dat_data['InstallationList']:
if game['AppName'] == item_data['AppName']:
create_new_entry(exe_path, display_name, launch_options, start_dir)
else:
print("Epic Games Launcher data not found. Skipping Epic Games Scanner.")
#End of the Epic Games Scanner
# Ubisoft Connect Scanner
def getUplayGameInfo(folderPath, filePath):
# Get the game IDs from the folder
listOfFiles = os.listdir(folderPath)
uplay_ids = [re.findall(r'\d+', str(entry))[0] for entry in listOfFiles if re.findall(r'\d+', str(entry))]
# Parse the registry file
game_dict = {}
with open(filePath, 'r') as file:
uplay_id = None
game_name = None
uplay_install_found = False
for line in file:
if "Uplay Install" in line:
uplay_id = re.findall(r'Uplay Install (\d+)', line)
if uplay_id:
uplay_id = uplay_id[0]
game_name = None # Reset game_name
uplay_install_found = True
if "DisplayName" in line and uplay_install_found:
game_name = re.findall(r'\"(.+?)\"', line.split("=")[1])
if game_name:
game_name = game_name[0]
uplay_install_found = False
if uplay_id and game_name and uplay_id in uplay_ids: # Add the game's info to the dictionary if its ID was found in the folder
game_dict[game_name] = uplay_id
uplay_id = None # Reset uplay_id
game_name = None # Reset game_name
return game_dict
# Define your paths
data_folder_path = f"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{ubisoft_connect_launcher}/pfx/drive_c/Program Files (x86)/Ubisoft/Ubisoft Game Launcher/data/"
registry_file_path = f"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{ubisoft_connect_launcher}/pfx/system.reg"
# Check if the paths exist
if not os.path.exists(data_folder_path) or not os.path.exists(registry_file_path):
print("One or more paths do not exist.")
print("Ubisoft Connect game data not found. Skipping Ubisoft Games Scanner.")
else:
game_dict = getUplayGameInfo(data_folder_path, registry_file_path)
for game, uplay_id in game_dict.items():
if uplay_id:
launch_options = f"STEAM_COMPAT_DATA_PATH=\"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{ubisoft_connect_launcher}/\" %command% \"uplay://launch/{uplay_id}/0\""
exe_path = f"\"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{ubisoft_connect_launcher}/pfx/drive_c/Program Files (x86)/Ubisoft/Ubisoft Game Launcher/upc.exe\""
start_dir = f"\"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{ubisoft_connect_launcher}/pfx/drive_c/Program Files (x86)/Ubisoft/Ubisoft Game Launcher/\""
create_new_entry(exe_path, game, launch_options, start_dir)
# End of Ubisoft Game Scanner
# EA App Game Scanner
def get_ea_app_game_info(installed_games, game_directory_path):
game_dict = {}
for game in installed_games:
xml_file = ET.parse(f"{game_directory_path}{game}/__Installer/installerdata.xml")
xml_root = xml_file.getroot()
ea_ids = None
game_name = None
for content_id in xml_root.iter('contentID'):
if ea_ids is None:
ea_ids = content_id.text
else:
ea_ids = ea_ids + ',' + content_id.text
for game_title in xml_root.iter('gameTitle'):
if game_name is None:
game_name = game_title.text
continue
for game_title in xml_root.iter('title'):
if game_name is None:
game_name = game_title.text
continue
if game_name is None:
game_name = game
if ea_ids: # Add the game's info to the dictionary if its ID was found in the folder
game_dict[game_name] = ea_ids
return game_dict
game_directory_path = f"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{ea_app_launcher}/pfx/drive_c/Program Files/EA Games/"
if not os.path.isdir(game_directory_path):
print("EA App game data not found. Skipping EA App Scanner.")
else:
installed_games = os.listdir(game_directory_path) # Get a list of game folders
game_dict = get_ea_app_game_info(installed_games, game_directory_path)
for game, ea_ids in game_dict.items():
launch_options = f"STEAM_COMPAT_DATA_PATH=\"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{ea_app_launcher}/\" %command% \"origin2://game/launch?offerIds={ea_ids}\""
exe_path = f"\"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{ea_app_launcher}/pfx/drive_c/Program Files/Electronic Arts/EA Desktop/EA Desktop/EALaunchHelper.exe\""
start_dir = f"\"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{ea_app_launcher}/pfx/drive_c/Program Files/Electronic Arts/EA Desktop/EA Desktop/\""
create_new_entry(exe_path, game, launch_options, start_dir)
#End of EA App Scanner
# Gog Galaxy Scanner
def getGogGameInfo(filePath):
# Check if the file contains any GOG entries
with open(filePath, 'r') as file:
if "GOG.com" not in file.read():
print("No GOG entries found in the registry file. Skipping GOG Galaxy Games Scanner.")
return {}
# If GOG entries exist, parse the registry file
game_dict = {}
with open(filePath, 'r') as file:
game_id = None
game_name = None
exe_path = None
for line in file:
split_line = line.split("=")
if len(split_line) > 1:
if "gameID" in line:
game_id = re.findall(r'\"(.+?)\"', split_line[1])
if game_id:
game_id = game_id[0]
if "gameName" in line:
game_name = re.findall(r'\"(.+?)\"', split_line[1])
if game_name:
game_name = game_name[0]
if "exe" in line and "GOG Galaxy" in line and not "unins000.exe" in line:
exe_path = re.findall(r'\"(.+?)\"', split_line[1])
if exe_path:
exe_path = exe_path[0].replace('\\\\', '\\')
if game_id and game_name and exe_path:
game_dict[game_name] = {'id': game_id, 'exe': exe_path}
game_id = None
game_name = None
exe_path = None
return game_dict
# Define your paths
gog_games_directory = f"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{gog_galaxy_launcher}/pfx/drive_c/Program Files (x86)/GOG Galaxy/Games"
registry_file_path = f"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{gog_galaxy_launcher}/pfx/system.reg"
# Check if the paths exist
if not os.path.exists(gog_games_directory) or not os.path.exists(registry_file_path):
print("One or more paths do not exist.")
print("GOG Galaxy game data not found. Skipping GOG Galaxy Games Scanner.")
else:
game_dict = getGogGameInfo(registry_file_path)
for game, game_info in game_dict.items():
if game_info['id']:
launch_options = f"STEAM_COMPAT_DATA_PATH=\"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{gog_galaxy_launcher}/\" %command% /command=runGame /gameId={game_info['id']} /path=\"{game_info['exe']}\""
exe_path = f"\"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{gog_galaxy_launcher}/pfx/drive_c/Program Files (x86)/GOG Galaxy/GalaxyClient.exe\""
start_dir = f"\"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{gog_galaxy_launcher}/pfx/drive_c/Program Files (x86)/GOG Galaxy/\""
create_new_entry(exe_path, game, launch_options, start_dir)
# End of Gog Galaxy Scanner
#Battle.net Scanner
# Define your mapping
flavor_mapping = {
"Blizzard Arcade Collection": "RTRO",
"Diablo": "D1",
"Diablo II: Resurrected": "OSI",
"Diablo III": "D3",
"Diablo IV": "Fen",
"Diablo Immortal (PC)": "ANBS",
"Hearthstone": "WTCG",
"Heroes of the Storm": "Hero",
"Overwatch": "Pro",
"Overwatch 2": "Pro",
"StarCraft": "S1",
"StarCraft 2": "S2",
"Warcraft: Orcs & Humans": "W1",
"Warcraft II: Battle.net Edition": "W2",
"Warcraft III: Reforged": "W3",
"World of Warcraft": "WoW",
"World of Warcraft Classic": "WoWC",
"Warcraft Arclight Rumble": "GRY",
"Call of Duty: Black Ops - Cold War": "ZEUS",
"Call of Duty: Black Ops 4": "VIPR",
"Call of Duty: Modern Warfare": "ODIN",
"Call of Duty": "AUKS",
"Call of Duty: MW 2 Campaign Remastered": "LAZR",
"Call of Duty: Vanguard": "FORE",
"Call of Duty: Modern Warfare III": "SPOT",
"Crash Bandicoot 4: It's About Time": "WLBY",
# Add more games here...
}
def get_flavor_from_file(game_path):
game_path = game_path.replace('\\', '/')
flavor_file = os.path.join(game_path, '_retail_', '.flavor.info')
if os.path.exists(flavor_file):
with open(flavor_file, 'r') as file:
for line in file:
if 'STRING' in line:
return line.split(':')[-1].strip().capitalize()
else:
print(f"Flavor file not found: {flavor_file}")
# Use the mapping as a fallback
game_name = os.path.basename(game_path)
print(f"Game name from file path: {game_name}")
return flavor_mapping.get(game_name, 'unknown')
def getBnetGameInfo(filePath):
# Check if the file contains any Battle.net entries
with open(filePath, 'r') as file:
if "Battle.net" not in file.read():
print("No Battle.net entries found in the registry file. Skipping Battle.net Games Scanner.")
return None
# If Battle.net entries exist, parse the registry file
game_dict = {}
with open(filePath, 'r') as file:
game_name = None
exe_path = None
publisher = None
contact = None
for line in file:
split_line = line.split("=")
if len(split_line) > 1:
if "Publisher" in line:
publisher = re.findall(r'\"(.+?)\"', split_line[1])
if publisher:
publisher = publisher[0]
# Skip if the publisher is not Blizzard Entertainment
if publisher != "Blizzard Entertainment":
game_name = None
exe_path = None
publisher = None
continue
if "Contact" in line:
contact = re.findall(r'\"(.+?)\"', split_line[1])
if contact:
contact = contact[0]
if "DisplayName" in line:
game_name = re.findall(r'\"(.+?)\"', split_line[1])
if game_name:
game_name = game_name[0]
if "InstallLocation" in line:
exe_path = re.findall(r'\"(.+?)\"', split_line[1])
if exe_path:
exe_path = exe_path[0].replace('\\\\', '\\')
# Skip if the install location is for the Battle.net launcher
if "Battle.net" in exe_path:
game_name = None
exe_path = None
publisher = None
continue
if game_name and exe_path and publisher == "Blizzard Entertainment" and contact == "Blizzard Support":
game_dict[game_name] = {'exe': exe_path}
print(f"Game added to dictionary: {game_name}")
game_name = None
exe_path = None
publisher = None
contact = None
# If no games were found, return None
if not game_dict:
print("No Battle.net games found. Skipping Battle.net Games Scanner.")
return None
return game_dict
# Define your paths
registry_file_path = f"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{bnet_launcher}/pfx/system.reg"
game_dict = {}
# Check if the paths exist
if not os.path.exists(registry_file_path):
print("One or more paths do not exist.")
print("Battle.net game data not found. Skipping Battle.net Games Scanner.")
else:
game_dict = getBnetGameInfo(registry_file_path)
if game_dict is None:
# Skip the rest of the Battle.net scanner
pass
else:
# Extract the flavor for each game and create the launch options
for game, game_info in game_dict.items():
game_info['flavor'] = get_flavor_from_file(game_info['exe'])
print(f"Flavor inferred: {game_info['flavor']}")
# Check if the game name is "Overwatch" and update it to "Overwatch 2"
if game == "Overwatch":
game = "Overwatch 2"
if game_info['flavor'] == "unknown":
pass
elif game_info['flavor']:
launch_options = f"STEAM_COMPAT_DATA_PATH=\"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{bnet_launcher}/\" %command% \"battlenet://{game_info['flavor']}\""
exe_path = f"\"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{bnet_launcher}/pfx/drive_c/Program Files (x86)/Battle.net/Battle.net.exe\" --exec=\"launch {game_info['flavor']}\""
start_dir = f"\"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{bnet_launcher}/pfx/drive_c/Program Files (x86)/Battle.net/\""
create_new_entry(exe_path, game, launch_options, start_dir)
# End of Battle.net Scanner
# Amazon Games Scanner
def get_sqlite_path():
# Specify the full path to the SQLite file
path = f"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{amazon_launcher}/pfx/drive_c/users/steamuser/AppData/Local/Amazon Games/Data/Games/Sql/GameInstallInfo.sqlite"
if os.path.exists(path):
return path
else:
print(f"Amazon GameInstallInfo.sqlite not found at {path}")
return None
def get_launcher_path():
# Specify the full path to the Amazon Games launcher executable
path = f"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{amazon_launcher}/pfx/drive_c/users/steamuser/AppData/Local/Amazon Games/App/Amazon Games.exe"
if os.path.exists(path):
return path
else:
print(f"Could not find Amazon Games.exe at {path}")
return None
def get_amazon_games():
sqllite_path = get_sqlite_path()
launcher_path = get_launcher_path()
if sqllite_path is None or launcher_path is None:
print("Skipping Amazon Games Scanner due to missing paths.")
return []
result = []
connection = sqlite3.connect(sqllite_path)
cursor = connection.cursor()
cursor.execute("SELECT Id, ProductTitle FROM DbSet WHERE Installed = 1")
for row in cursor.fetchall():
id, title = row
result.append({"id": id, "title": title, "launcher_path": launcher_path})
return result
amazon_games = get_amazon_games()
if amazon_games:
for game in amazon_games:
# Initialize variables
display_name = game['title']
exe_path = f"\"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{amazon_launcher}/pfx/drive_c/users/steamuser/AppData/Local/Amazon Games/App/Amazon Games.exe\""
start_dir = f"\"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{amazon_launcher}/pfx/drive_c/users/steamuser/AppData/Local/Amazon Games/App/\""
launch_options = f"STEAM_COMPAT_DATA_PATH=\"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{amazon_launcher}\" %command% -'amazon-games://play/{game['id']}'"
create_new_entry(exe_path, display_name, launch_options, start_dir)
#End of Amazon Games Scanner
# Only write back to the shortcuts.vdf and config.vdf files if new shortcuts were added or compattools changed
if new_shortcuts_added or shortcuts_updated:
print(f"Saving new config and shortcuts files")
conf = vdf.dumps(config_data, pretty=True)
with open(f"{logged_in_home}/.steam/root/config/config.vdf", 'w') as file:
file.write(conf)
with open(f"{logged_in_home}/.steam/root/userdata/{steamid3}/config/shortcuts.vdf", 'wb') as file:
file.write(vdf.binary_dumps(shortcuts))
# Load the configset_controller_neptune.vdf file
with open(f"{controller_config_path}", 'r') as f:
config = vdf.load(f)
# Add new entries for the games
for app_id in app_ids:
config['controller_config'][str(app_id)] = {
'workshop': 'workshop_id'
}
# Add new entries for the installed launchers and games
config['controller_config']['epic games'] = {
'workshop': '2800178806'
}
config['controller_config']['gog galaxy'] = {
'workshop': '2877189386'
}
config['controller_config']['ubisoft connect'] = {
'workshop': '2804140248'
}
config['controller_config']['amazon games'] = {
'workshop': '2871935783'