Skip to content

Commit cea6339

Browse files
committed
Detect Steam installation folder automatically using registry entries and add support for multiple Steam library folders
1 parent ac3bcdd commit cea6339

File tree

1 file changed

+39
-5
lines changed

1 file changed

+39
-5
lines changed

app.py

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@
1616
import webbrowser
1717
from datetime import datetime
1818
from modules.MapExporter import exportMap
19+
import winreg
20+
from pathlib import Path
21+
from modules.vdfutils import parse_vdf
1922

2023
# global settings
2124
settings = json.loads(open("res/settings.json").read())
2225
gameDef = json.loads(open("res/gameDef.json").read())
2326
gameDefCustom = json.loads(open("res/gameDef.json").read())
2427
version = open("res/version.txt").read().split("\n")[0]
28+
steamAppsDirs = []
2529

2630
class App:
2731
def __init__(self, root: tk.Tk):
@@ -68,7 +72,7 @@ def __init__(self, root: tk.Tk):
6872
helpMenu = tk.Menu(menuBar, tearoff=0)
6973
helpMenu.add_command(label="Corvid on Github", command=lambda: webbrowser.open("https://github.com/KILLTUBE/corvid"))
7074
helpMenu.add_command(label="Corvid wiki", command=lambda: webbrowser.open("https://github.com/KILLTUBE/corvid/wiki"))
71-
helpMenu.add_command(label="Video tutorial", command=lambda: alert.showwarning(title="Warning", message="Video tutorial is not ready yet."))
75+
helpMenu.add_command(label="Video tutorial", command=lambda: webbrowser.open("https://www.youtube.com/watch?v=izALMNZjgkA"))
7276
#helpMenu.add_command(label="Check for new versions", command=lambda: print("Checking for new versions..."))
7377
helpMenu.add_separator()
7478
helpMenu.add_command(label="Support me on Patreon", command=lambda: webbrowser.open("https://www.patreon.com/johndoe_"))
@@ -291,8 +295,12 @@ def __init__(self, root: tk.Tk):
291295
for gameDir in settings["gameDirs"]:
292296
self.gameDirList.insert(0, gameDir)
293297

294-
def setSteamDir(self):
295-
dir = filedialog.askdirectory(title="Set your Steam directory")
298+
def setSteamDir(self, _dir=""):
299+
if _dir == "":
300+
dir = filedialog.askdirectory(title="Set your Steam directory")
301+
else:
302+
dir = _dir
303+
296304
if dir is not None:
297305
settings["steamDir"] = dir
298306
open("res/settings.json", "w").write(json.dumps(settings, indent=4))
@@ -361,10 +369,18 @@ def convertButton_command(self):
361369

362370
# add the vpk files and the directories of the current game in the list
363371
for vpk in gameDef[self.currentGame.get()]["vpkFiles"]:
364-
vpkFiles.append(settings["steamDir"] + "/steamapps/common/" + gameDef[self.currentGame.get()]["gameRoot"] + "/" + vpk)
372+
for appDir in steamAppsDirs:
373+
vpkPath = appDir + "/steamapps/common/" + gameDef[self.currentGame.get()]["gameRoot"] + "/" + vpk
374+
if os.path.isfile(vpkPath):
375+
vpkFiles.append(vpkPath)
376+
break
365377

366378
for dir in gameDef[self.currentGame.get()]["gameDirs"]:
367-
gameDirs.append(settings["steamDir"] + "/steamapps/common/" + gameDef[self.currentGame.get()]["gameRoot"] + "/" + dir)
379+
for appDir in steamAppsDirs:
380+
dirPath = appDir + "/steamapps/common/" + gameDef[self.currentGame.get()]["gameRoot"] + "/" + dir
381+
if os.path.isdir(dirPath):
382+
gameDirs.append(dirPath)
383+
break
368384

369385
vmfPath = self.vmfPath.get()
370386
# check if the selected file is a valid VMF file
@@ -482,12 +498,30 @@ def write(self, str):
482498
root = tk.Tk()
483499
app = App(root)
484500

501+
if settings["steamDir"] == "":
502+
try:
503+
hkey = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\WOW6432Node\Valve\Steam")
504+
steamDir = winreg.QueryValueEx(hkey, "InstallPath")[0]
505+
steamDir = Path(steamDir).as_posix()
506+
app.setSteamDir(steamDir)
507+
except:
508+
pass
509+
485510
while settings["steamDir"] == "":
486511
alert.showwarning(
487512
"Warning",
488513
message="It appears that this is your first time using Corvid.\n\n"
489514
+ "Please set your Steam directory in the next dialogue."
490515
)
491516
app.setSteamDir()
517+
518+
steamAppsDirs.append(settings["steamDir"])
519+
520+
try:
521+
libraryFolders = parse_vdf(open(f'{settings["steamDir"]}/steamapps/libraryfolders.vdf').read())["LibraryFolders"]
522+
for i in range(1, len(libraryFolders) - 1):
523+
steamAppsDirs.append(Path(libraryFolders[str(i)]).as_posix());
524+
except:
525+
pass
492526

493527
root.mainloop()

0 commit comments

Comments
 (0)