Skip to content

Commit

Permalink
修复开机自启时目录错误
Browse files Browse the repository at this point in the history
  • Loading branch information
DLmaster361 committed Jan 7, 2025
1 parent 04fd2b1 commit 1ea9d10
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 42 deletions.
15 changes: 7 additions & 8 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ class AppConfig:

def __init__(self) -> None:

self.app_path = Path.cwd() # 获取软件根目录
self.app_path_sys = os.path.realpath(sys.argv[0]) # 获取软件自身的路径
self.app_name = os.path.basename(self.app_path) # 获取软件自身的名称
self.app_path = Path(sys.argv[0]).resolve().parent # 获取软件根目录
self.app_path_sys = str(Path(sys.argv[0]).resolve()) # 获取软件自身的路径

self.database_path = self.app_path / "data/data.db"
self.config_path = self.app_path / "config/config.json"
Expand All @@ -70,6 +69,7 @@ def initialize(self) -> None:

# 检查目录
(self.app_path / "config").mkdir(parents=True, exist_ok=True)
(self.app_path / "data").mkdir(parents=True, exist_ok=True)
# (self.app_path / "data/MAAconfig/simple").mkdir(parents=True, exist_ok=True)
# (self.app_path / "data/MAAconfig/beta").mkdir(parents=True, exist_ok=True)
# (self.app_path / "data/MAAconfig/Default").mkdir(parents=True, exist_ok=True)
Expand Down Expand Up @@ -195,9 +195,7 @@ def check_database(self) -> None:
def open_database(self, mode: str, index: str = None) -> None:
"""打开数据库"""

if self.if_database_opened:
self.close_database()

self.close_database()
if mode == "Maa":
self.db = sqlite3.connect(
self.app_path / f"config/{mode}Config/{index}/user_date.db"
Expand All @@ -208,8 +206,9 @@ def open_database(self, mode: str, index: str = None) -> None:
def close_database(self) -> None:
"""关闭数据库"""

self.cur.close()
self.db.close()
if self.if_database_opened:
self.cur.close()
self.db.close()
self.if_database_opened = False

def clear_maa_config(self) -> None:
Expand Down
6 changes: 3 additions & 3 deletions app/services/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def set_SelfStart(self):
winreg.KEY_ALL_ACCESS | winreg.KEY_WRITE | winreg.KEY_CREATE_SUB_KEY,
)
winreg.SetValueEx(
key, self.config.app_name, 0, winreg.REG_SZ, self.config.app_path_sys
key, "AUTO_MAA主程序", 0, winreg.REG_SZ, self.config.app_path_sys
)
winreg.CloseKey(key)
elif (
Expand All @@ -89,7 +89,7 @@ def set_SelfStart(self):
winreg.KEY_SET_VALUE,
winreg.KEY_ALL_ACCESS | winreg.KEY_WRITE | winreg.KEY_CREATE_SUB_KEY,
)
winreg.DeleteValue(key, self.config.app_name)
winreg.DeleteValue(key, "AUTO_MAA主程序")
winreg.CloseKey(key)

def is_startup(self):
Expand All @@ -103,7 +103,7 @@ def is_startup(self):
)

try:
value, _ = winreg.QueryValueEx(key, self.config.app_name)
value, _ = winreg.QueryValueEx(key, "AUTO_MAA主程序")
winreg.CloseKey(key)
return True
except FileNotFoundError:
Expand Down
1 change: 0 additions & 1 deletion app/ui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ def __init__(
)

self.splashScreen.finish()
self.show_main()

if self.config.global_config.get(self.config.global_config.update_IfAutoUpdate):
result = self.setting.check_update()
Expand Down
50 changes: 20 additions & 30 deletions app/utils/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,20 @@

print("Packaging AUTO_MAA main program ...")

result = subprocess.run(
f"powershell -Command nuitka --standalone --onefile --mingw64"
f" --enable-plugins=pyside6 --windows-console-mode=disable"
f" --onefile-tempdir-spec=%TEMP%\\AUTO_MAA"
f" --windows-icon-from-ico=resources\\icons\\AUTO_MAA.ico"
f" --company-name='AUTO_MAA Team' --product-name=AUTO_MAA"
os.system(
"powershell -Command python -m nuitka --standalone --onefile --mingw64"
" --enable-plugins=pyside6 --windows-console-mode=disable"
" --onefile-tempdir-spec='{TEMP}\\AUTO_MAA'"
" --windows-icon-from-ico=resources\\icons\\AUTO_MAA.ico"
" --company-name='AUTO_MAA Team' --product-name=AUTO_MAA"
f" --file-version={version["main_version"]}"
f" --product-version={version["main_version"]}"
f" --file-description='AUTO_MAA Component'"
f" --copyright='Copyright © 2024 DLmaster361'"
f" --assume-yes-for-downloads --output-filename=AUTO_MAA"
f" --remove-output main.py",
shell=True,
capture_output=True,
text=True,
" --file-description='AUTO_MAA Component'"
" --copyright='Copyright © 2024 DLmaster361'"
" --assume-yes-for-downloads --output-filename=AUTO_MAA"
" --remove-output main.py"
)

print(result.stdout)
print(result.stderr)
print("AUTO_MAA main program packaging completed !")

shutil.copy(root_path / "app/utils/Updater.py", root_path)
Expand All @@ -80,25 +75,20 @@

print("Packaging AUTO_MAA update program ...")

result = subprocess.run(
f"powershell -Command nuitka --standalone --onefile --mingw64"
f" --enable-plugins=pyside6 --windows-console-mode=disable"
f" --onefile-tempdir-spec=%TEMP%\\AUTO_MAA_Updater"
f" --windows-icon-from-ico=resources\\icons\\AUTO_MAA_Updater.ico"
f" --company-name='AUTO_MAA Team' --product-name=AUTO_MAA"
os.system(
"powershell -Command python -m nuitka --standalone --onefile --mingw64"
" --enable-plugins=pyside6 --windows-console-mode=disable"
" --onefile-tempdir-spec='{TEMP}\\AUTO_MAA_Updater'"
" --windows-icon-from-ico=resources\\icons\\AUTO_MAA_Updater.ico"
" --company-name='AUTO_MAA Team' --product-name=AUTO_MAA"
f" --file-version={version["updater_version"]}"
f" --product-version={version["main_version"]}"
f" --file-description='AUTO_MAA Component'"
f" --copyright='Copyright © 2024 DLmaster361'"
f" --assume-yes-for-downloads --output-filename=Updater"
f" --remove-output Updater.py",
shell=True,
capture_output=True,
text=True,
" --file-description='AUTO_MAA Component'"
" --copyright='Copyright © 2024 DLmaster361'"
" --assume-yes-for-downloads --output-filename=Updater"
" --remove-output Updater.py"
)

print(result.stdout)
print(result.stderr)
print("AUTO_MAA update program packaging completed !")

(root_path / "Updater.py").unlink()
Expand Down
1 change: 1 addition & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@
application.installTranslator(translator)

window = AUTO_MAA(config=config, notify=notify, crypto=crypto, system=system)
window.show_main()
window.setting.check_PASSWORD()
sys.exit(application.exec())

0 comments on commit 1ea9d10

Please sign in to comment.