-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpath.py
More file actions
121 lines (100 loc) · 4.01 KB
/
path.py
File metadata and controls
121 lines (100 loc) · 4.01 KB
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
import os
from sys import exit
from tkinter import Tk
from tkinter import filedialog
import winreg
import vdf
from localization import get_localized_string, print_localized
def get_paths():
mods_paths = []
asset_folder_paths = []
documents_path = get_documents_root()
install_path = find_steam_app_install_path("286160")
possible_root_paths = [documents_path, install_path]
for path in possible_root_paths:
if os.path.isdir(os.path.join(path, "Mods", "Workshop")):
mods_paths.append(os.path.join(path, "Mods", "Workshop"))
if os.path.isdir(os.path.join(path, "Saves")):
mods_paths.append(os.path.join(path, "Saves"))
if os.path.isdir(os.path.join(path, "Mods", "Assetbundles")):
asset_folder_paths.append(os.path.join(path, "Mods", "Assetbundles"))
if os.path.isdir(os.path.join(path, "Mods", "Audio")):
asset_folder_paths.append(os.path.join(path, "Mods", "Audio"))
if os.path.isdir(os.path.join(path, "Mods", "Images")):
asset_folder_paths.append(os.path.join(path, "Mods", "Images"))
if os.path.isdir(os.path.join(path, "Mods", "Images Raw")):
asset_folder_paths.append(os.path.join(path, "Mods", "Images Raw"))
if os.path.isdir(os.path.join(path, "Mods", "Models")):
asset_folder_paths.append(os.path.join(path, "Mods", "Models"))
if os.path.isdir(os.path.join(path, "Mods", "Models Raw")):
asset_folder_paths.append(os.path.join(path, "Mods", "Models Raw"))
if os.path.isdir(os.path.join(path, "Mods", "PDF")):
asset_folder_paths.append(os.path.join(path, "Mods", "PDF"))
if os.path.isdir(os.path.join(path, "Mods", "Text")):
asset_folder_paths.append(os.path.join(path, "Mods", "Text"))
return mods_paths, asset_folder_paths
def get_mods_root_path():
path = os.path.expanduser("~/Documents/My Games/Tabletop Simulator/")
while True:
if os.path.isdir(os.path.join(path, "Mods")) and os.path.isdir(os.path.join(path, "Mods", "Workshop")):
break
elif path == "":
print_localized("no_folder")
exit(0)
else:
print_localized("show_file")
root = Tk()
root.withdraw()
path = filedialog.askdirectory(
initialdir=path,
title=get_localized_string("choose_root")
)
return path
def get_documents_root():
return os.path.expanduser("~/Documents/My Games/Tabletop Simulator/")
def find_steam_app_install_path(app_id):
steam_path = find_steam_install_path()
library_folders = [steam_path]
library_dict_path = os.path.join(steam_path, "steamapps", "libraryfolders.vdf")
v = vdf.load(open(library_dict_path))
lf = v["libraryfolders"]
i = 1
while True:
try:
entry = lf[str(i)]
folder_path = entry["path"]
library_folders.append(folder_path)
i += 1
except:
break
for library_folder in library_folders:
path = os.path.join(library_folder, "steamapps", "appmanifest_{}.acf".format(app_id))
if os.path.isfile(path):
manifest = vdf.load(open(path))
name = manifest["AppState"]["name"]
return os.path.join(library_folder, "steamapps", "common", name)
return ""
def find_steam_install_path():
try:
registry_key = winreg.OpenKey(
winreg.HKEY_LOCAL_MACHINE,
r"SOFTWARE\Wow6432Node\Valve\Steam",
0,
winreg.KEY_READ)
value, regtype = winreg.QueryValueEx(registry_key, "InstallPath")
winreg.CloseKey(registry_key)
return value
except:
pass
try:
registry_key = winreg.OpenKey(
winreg.HKEY_LOCAL_MACHINE,
r"SOFTWARE\Valve\Steam",
0,
winreg.KEY_READ)
value, regtype = winreg.QueryValueEx(registry_key, "InstallPath")
winreg.CloseKey(registry_key)
return value
except:
pass
return ""