-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
64 lines (58 loc) · 2.49 KB
/
main.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
import webview
import os
import sys
import ctypes
import json
import inspect
import platform
def start_window(type, error=""):
import functions
if type == "normal":
window = webview.create_window(title='AL2 Factory Mod Manager', url='win/index.html', resizable=False, width=800, height=600)
for name, method in inspect.getmembers(functions.bind_func, predicate=inspect.isfunction):
window.expose(method)
webview.start()
elif type == "error":
ctypes.windll.user32.MessageBoxW(0, error, "AL2 Factory Mod Manager - Error", 0)
sys.exit(1)
def check_program_files():
programFiles = {
".\\win\\": False,
".\\settings.json": False
}
if not os.path.exists(".\\win\\") or not os.listdir(".\\win\\"):
return programFiles, "Error: Missing essential files in 'win' directory! Please reinstall the application."
for item in programFiles:
if not os.path.exists(item):
try:
if item == ".\\settings.json":
with open(item, 'w') as f:
gameDir = ""
if platform.system() == "Windows":
gameDir = "C:\\Program Files (x86)\\Steam\\steamapps\\common\\Assembly Line 2"
elif platform.system() == "Darwin":
gameDir = "/Applications/Assembly Line 2"
else:
gameDir = "/home/user/.local/share/Steam/steamapps/common/Assembly Line 2/"
json.dump({"theme": "dark", "gameDir": f"{gameDir}"}, f, indent=4)
elif "." in os.path.basename(item):
with open(item, 'w') as f:
pass
else:
os.mkdir(item)
programFiles[item] = True
except Exception as e:
return programFiles, f"Error creating '{item}': {str(e)}"
else:
programFiles[item] = True
return programFiles, ""
if __name__ == '__main__':
program_status, error_msg = check_program_files()
if error_msg:
print(error_msg, file=sys.stderr)
start_window("error", error_msg)
elif all(program_status.values()):
start_window("normal")
else:
print("Error: Unknown error occurred during initialization.", file=sys.stderr)
start_window("error", "Unknown error occurred during initialization.")