forked from Systemcluster/The-Witcher-3-Mod-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·96 lines (82 loc) · 3.06 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
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
'''Witcher 3 Mod Manager main module'''
# pylint: disable=invalid-name,missing-docstring,bare-except,broad-except,wildcard-import,unused-wildcard-import
import sys
import os
import re
from os import environ
from argparse import ArgumentParser
from PySide2.QtWidgets import QApplication, QMessageBox
from src.gui.main_window import CustomMainWindow
from src.gui.main_widget import CustomMainWidget
from src.gui.alerts import *
from src.util.util import *
from src.configuration.config import Configuration
from src.core.model import Model
from src.globals import data
from src.globals.constants import translate
if __name__ == "__main__":
# correct screen scaling
if "QT_DEVICE_PIXEL_RATIO" in environ:
del environ["QT_DEVICE_PIXEL_RATIO"]
environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "1"
documentsPath: str = ''
gamePath: str = ''
configPath: str = ''
try:
parser = ArgumentParser(description=getVersionString())
parser.add_argument(
"-d", "--debug", dest="debug", action="store_true", default=False,
help="show debug information on errors")
parser.add_argument(
"-v", "--version", dest="version", action="store_true", default=False,
help="show version information and exit")
dirs = parser.add_argument_group(
title='start overrides'
)
dirs.add_argument(
"-u", "--userdocuments", dest="userdocuments", type=str, default="",
help="override the documents path")
dirs.add_argument(
"-g", "--game", dest="game", type=str, default="",
help="override the game path")
dirs.add_argument(
"-c", "--config", dest="config", type=str, default="",
help="override the config path")
args = parser.parse_args()
data.debug = args.debug
if args.version:
print(getVersionString())
sys.exit()
documentsPath = args.userdocuments
gamePath = args.game
configPath = args.config
except Exception as e:
print(str(e))
data.app = QApplication(sys.argv)
data.config = Configuration(documentsPath, gamePath, configPath)
translateToChosenLanguage()
if not Configuration.getCorrectGamePath(data.config.gameexe):
if not reconfigureGamePath():
sys.exit(1)
try:
modModel = Model()
except IOError as err:
print(err, file=sys.stderr)
if MessageAlertOtherInstance() == QMessageBox.Yes:
modModel = Model(ignorelock=True)
else:
sys.exit(1)
except Exception as e:
MessageInitializationFailed(formatUserError(e))
sys.exit(1)
fixUserSettingsDuplicateBrackets()
mainWindow = CustomMainWindow()
mainWidget = CustomMainWidget(mainWindow, modModel)
mainWindow.dropCallback = mainWidget.installModFiles
data.app.setWindowIcon(getIcon("w3a.ico"))
mainWindow.show()
ret = data.app.exec_()
data.config.saveWindowSettings(mainWidget, mainWindow)
data.config.write()
modModel.write()
sys.exit(ret)