From 2bbb0962a150faf16febfad1e14395e694ea1a77 Mon Sep 17 00:00:00 2001 From: Timmoc Date: Tue, 26 Nov 2024 15:51:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=80appdata=E7=81=8C=E7=9F=B3=EF=BC=8C?= =?UTF-8?q?=E5=85=AC=E7=A7=81=E9=92=A5=E5=AF=B9=E7=8E=B0=E5=AD=98=E5=82=A8?= =?UTF-8?q?=E4=BA=8Eappdata=E7=9B=AE=E5=BD=95=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config.py | 8 ++++++-- tool/DownloadPathTool.py | 12 ++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/config/config.py b/config/config.py index 6804a94..d1dc48c 100644 --- a/config/config.py +++ b/config/config.py @@ -1,7 +1,11 @@ from enum import Enum, auto + +from tool.DownloadPathTool import get_config_path + port = 8426 -priKeySavePath = "./private.pem" -pubKeySavePath = "./public.pem" +configPath = get_config_path() +priKeySavePath = f"{configPath}/private.pem" +pubKeySavePath = f"{configPath}/public.pem" class EncryptType(Enum): AES_ECB = auto() diff --git a/tool/DownloadPathTool.py b/tool/DownloadPathTool.py index b365591..988195a 100644 --- a/tool/DownloadPathTool.py +++ b/tool/DownloadPathTool.py @@ -3,6 +3,18 @@ import sys import winreg from pathlib import Path +def get_config_path(): + if sys.platform == 'win32': + # 展开环境变量并转换为标准格式 + download_dir = Path(os.path.expandvars("%appdata%/fst")).resolve() + else: + # 对于非 Windows 系统,使用 ~\Downloads 作为默认下载目录 + home_dir = Path.home() + download_dir = home_dir / 'fst' + dir_path = Path(download_dir) + if not dir_path.exists(): + dir_path.mkdir(parents=True, exist_ok=True) + return str(download_dir) def get_download_directory(): if sys.platform == 'win32':