The only downloader you need. 下载器的集大成者。
TypeScript asyncasynciobittorentbtcross-platformdownload-managerdownloaderfluent-designftphttp3magnetpyqtpyside6pythonqtquicreactsoftwarestreaming
refactor(paths): 统一命名与类型
XiaoYouChRa2fb418ca9cc
diff --git a/Ghost-Downloader-3.py b/Ghost-Downloader-3.pyindex 16ace657..14d75d02 100644--- a/Ghost-Downloader-3.py+++ b/Ghost-Downloader-3.py@@ -53,7 +53,7 @@ def startApp(application, isSilent=False):import shutilfrom PySide6.QtGui import QIconfrom app.config.cfg import cfg- from app.config.paths import executableDir+ from app.config.paths import EXECUTABLE_DIRfrom app.view.shell.clipboard_listener import ClipboardListenerfrom app.signal_bus import signalBusfrom app.startup import loadEngine, createServices, loadPacks, startEngine, bindNotifications, checkUpdateAtStartup, stopEngine@@ -79,7 +79,7 @@ def startApp(application, isSilent=False):coroutineRunner, categoryService, speedMeter = loadEngine(application)- appDir = executableDir.parent.parent if sys.platform == "darwin" else executableDir+ appDir = EXECUTABLE_DIR.parent.parent if sys.platform == "darwin" else EXECUTABLE_DIRbackupDir = appDir.parent / f"{appDir.name}_backup"if backupDir.is_dir():shutil.rmtree(backupDir, ignore_errors=True)diff --git a/app/config/__init__.py b/app/config/__init__.pyindex e803f8ed..7fc9d7f2 100644--- a/app/config/__init__.py+++ b/app/config/__init__.py@@ -1,3 +1,3 @@from app.config.cfg import cfg, proxy, BASE_HEADERS-from app.config.paths import executableDir, APP_DATA_DIR+from app.config.paths import EXECUTABLE_DIR, APP_DATA_DIRfrom app.config.constants import VERSION, AUTHOR, DESKTOP_IDdiff --git a/app/config/cfg.py b/app/config/cfg.pyindex 4bdc6ebe..15118e08 100644--- a/app/config/cfg.py+++ b/app/config/cfg.py@@ -229,7 +229,7 @@ class Config(QConfig):# 下载downloadFolder = ConfigItem("GeneralDownload", "DownloadFolder",- "/storage/emulated/0/Download" if IS_ANDROID else DOWNLOAD_DIR,+ "/storage/emulated/0/Download" if IS_ANDROID else str(DOWNLOAD_DIR),FolderValidator(),)memoryDownloadFolders = ConfigItem(diff --git a/app/config/paths.py b/app/config/paths.pyindex 2d8f235f..0aadb4a4 100644--- a/app/config/paths.py+++ b/app/config/paths.py@@ -6,38 +6,39 @@ from pathlib import Pathfrom platformdirs import user_data_path, user_downloads_path-executableDir = (+EXECUTABLE_DIR = (Path(sys.executable).resolve().parentif "__compiled__" in globals()else Path("."))-APP_DATA_DIR: str = (- str(executableDir / "GhostDownloader")- if (executableDir / "GhostDownloader").is_dir()- else str(user_data_path("GhostDownloader", appauthor=False))+APP_DATA_DIR = (+ EXECUTABLE_DIR / "GhostDownloader"+ if (EXECUTABLE_DIR / "GhostDownloader").is_dir()+ else user_data_path("GhostDownloader", appauthor=False))-PORTABLE_PATH = executableDir / "GhostDownloader"+PORTABLE_DIR = EXECUTABLE_DIR / "GhostDownloader"-SEED_FEATURES_DIR = executableDir / "features"+SEED_FEATURES_DIR = EXECUTABLE_DIR / "features"FEATURES_DIR = (SEED_FEATURES_DIRif "__compiled__" not in globals()- else Path(APP_DATA_DIR) / "features"+ else APP_DATA_DIR / "features")-USER_PATH = user_data_path("GhostDownloader", appauthor=False)+USER_DATA_DIR = user_data_path("GhostDownloader", appauthor=False)++DOWNLOAD_DIR = user_downloads_path()-DOWNLOAD_DIR: str = str(user_downloads_path())def isPortable() -> bool:- return APP_DATA_DIR == str(PORTABLE_PATH)+ return APP_DATA_DIR == PORTABLE_DIRdef migrate(target: Path) -> None:from loguru import loggerlogger.remove()- source = Path(APP_DATA_DIR)+ source = APP_DATA_DIRtarget.mkdir(parents=True, exist_ok=True)shutil.copytree(source, target, dirs_exist_ok=True)if isPortable():diff --git a/app/platform/file_association.py b/app/platform/file_association.pyindex e3f069e2..5839ef6a 100644--- a/app/platform/file_association.py+++ b/app/platform/file_association.py@@ -9,7 +9,7 @@ from loguru import loggerfrom PySide6.QtCore import QCoreApplicationfrom app.config.constants import DESKTOP_ID-from app.config.paths import executableDir+from app.config.paths import EXECUTABLE_DIRif sys.platform == "win32":import ctypes@@ -32,7 +32,7 @@ def register(fileTypes: list[FileType]) -> None:def _registerWindows(fileTypes: list[FileType]) -> None:command = f'"{QCoreApplication.applicationFilePath().replace("/", chr(92))}" "%1"'for fileType in fileTypes:- iconPath = str(executableDir / "app" / "assets" / "file_icons" / f"{fileType.icon}.ico").replace("/", "\\")+ iconPath = str(EXECUTABLE_DIR / "app" / "assets" / "file_icons" / f"{fileType.icon}.ico").replace("/", "\\")for ext in fileType.extensions:progId = f"GhostDownloader{ext}"for regPath, regValue in (diff --git a/app/services/browser_service.py b/app/services/browser_service.pyindex fcb1a498..2eeb10ec 100644--- a/app/services/browser_service.py+++ b/app/services/browser_service.py@@ -26,7 +26,7 @@ from app.models.task import MergeTaskOptions, PageTaskOptionsif TYPE_CHECKING:from app.models.task import Task, TaskOptions, ResourceTaskOptions-EXTENSION_UNPACK_DIR = Path(APP_DATA_DIR) / "browser_extension"+EXTENSION_UNPACK_DIR = APP_DATA_DIR / "browser_extension"async def extractBrowserExtension(loadCrx) -> Path:diff --git a/app/services/task_service.py b/app/services/task_service.pyindex 2444b64e..51879ac5 100644--- a/app/services/task_service.py+++ b/app/services/task_service.py@@ -23,7 +23,7 @@ class TaskStore:def __init__(self):self._tasks: dict[str, Task] = {}self._loaded = False- self._path = Path(APP_DATA_DIR) / "tasks.jsonl"+ self._path = APP_DATA_DIR / "tasks.jsonl"def add(self, task: Task) -> None:self._tasks[task.taskId] = taskdiff --git a/app/services/update_service.py b/app/services/update_service.pyindex dd8deba5..50883fb1 100644--- a/app/services/update_service.py+++ b/app/services/update_service.py@@ -17,7 +17,7 @@ from app.signal import Signalfrom loguru import loggerfrom app.config.constants import VERSION-from app.config.paths import APP_DATA_DIR, FEATURES_DIR, executableDir+from app.config.paths import APP_DATA_DIR, FEATURES_DIR, EXECUTABLE_DIRfrom app.platform.android import IS_ANDROIDfrom app.platform.filesystem import matchChecksumfrom app.models.pack import PackManifest@@ -28,7 +28,7 @@ from app.update import APP_REPO, isNewerif TYPE_CHECKING:from app.services.coroutine_runner import CoroutineRunner-STAGING_DIR = Path(APP_DATA_DIR) / "update_staging"+STAGING_DIR = APP_DATA_DIR / "update_staging"OS_MAP = {"win32": "Windows", "darwin": "macOS", "linux": "Linux"}MACHINE_MAP = {"AMD64": "x86_64", "x86_64": "x86_64", "aarch64": "arm64", "arm64": "arm64"}@@ -286,12 +286,12 @@ class UpdateService:def _startUpdater(self) -> None:updaterName = "updater.exe" if sys.platform == "win32" else "updater"- updaterPath = executableDir / updaterName+ updaterPath = EXECUTABLE_DIR / updaterNameif not updaterPath.is_file():logger.error("updater not found: {}", updaterPath)return- appDir = executableDir.parent.parent if sys.platform == "darwin" else executableDir+ appDir = EXECUTABLE_DIR.parent.parent if sys.platform == "darwin" else EXECUTABLE_DIRpatchPath = STAGING_DIR / "patch.hdiff"stagingNewDir = STAGING_DIR / "app_new"diff --git a/app/startup.py b/app/startup.pyindex 124c2b72..7d161218 100644--- a/app/startup.py+++ b/app/startup.py@@ -28,9 +28,9 @@ def loadEngine(application):from PySide6.QtCore import QResource, QTimerfrom shiboken6 import isValid- from app.config.paths import executableDir+ from app.config.paths import EXECUTABLE_DIR- QResource.registerResource(str(executableDir / "app" / "assets" / "resources.rcc"))+ QResource.registerResource(str(EXECUTABLE_DIR / "app" / "assets" / "resources.rcc"))loadTranslators(application)diff --git a/app/view/pages/setting_page.py b/app/view/pages/setting_page.pyindex e873e8cb..73291846 100644--- a/app/view/pages/setting_page.py+++ b/app/view/pages/setting_page.py@@ -493,9 +493,9 @@ class SettingPage(ScrollArea):setRunAtLogin(enabled)def _onMigrateClicked(self) -> None:- from app.config.paths import isPortable, migrate, PORTABLE_PATH, USER_PATH+ from app.config.paths import isPortable, migrate, PORTABLE_DIR, USER_DATA_DIR- target = USER_PATH if isPortable() else PORTABLE_PATH+ target = USER_DATA_DIR if isPortable() else PORTABLE_DIRmode = self.tr("用户模式") if isPortable() else self.tr("Portable 模式")dialog = MessageBox(self.tr("切换数据存储模式"),diff --git a/features/bittorrent_pack/session.py b/features/bittorrent_pack/session.pyindex 4863ab5b..2f75713c 100644--- a/features/bittorrent_pack/session.py+++ b/features/bittorrent_pack/session.py@@ -300,7 +300,7 @@ class BTSession(QObject):def _loadDhtState(self) -> lt.session_params:from app.config.paths import APP_DATA_DIR- path = Path(APP_DATA_DIR) / DHT_STATE_FILE+ path = APP_DATA_DIR / DHT_STATE_FILEif path.exists():try:return lt.read_session_params(@@ -318,7 +318,7 @@ class BTSession(QObject):state = self._session.save_state(lt.save_state_flags_t.save_dht_state)- (Path(APP_DATA_DIR) / DHT_STATE_FILE).write_bytes(+ (APP_DATA_DIR / DHT_STATE_FILE).write_bytes(lt.bencode(state))except Exception as e:diff --git a/features/ed2k_pack/session.py b/features/ed2k_pack/session.pyindex 60441e9d..4c46f1c4 100644--- a/features/ed2k_pack/session.py+++ b/features/ed2k_pack/session.py@@ -136,7 +136,7 @@ class ED2kSession:raise TaskError("{name} 未安装,请在设置中安装", name=ed2kRuntime.name)- client = Client(Path(path), Path(APP_DATA_DIR) / "ed2k_data")+ client = Client(Path(path), APP_DATA_DIR / "ed2k_data")await client.start(Settings(enableDht=ed2kConfig.enableDht.value,enableUpnp=ed2kConfig.enableUpnp.value,diff --git a/features/yt_dlp_pack/config.py b/features/yt_dlp_pack/config.pyindex 3e6ee5d9..a2961b1b 100644--- a/features/yt_dlp_pack/config.py+++ b/features/yt_dlp_pack/config.py@@ -26,7 +26,7 @@ AUTH_COOKIE_NAMES = ("LOGIN_INFO", "SAPISID", "__Secure-1PAPISID", "__Secure-3PAdef cookieFile() -> Path:- return Path(APP_DATA_DIR) / "YtDlp" / "cookies.txt"+ return APP_DATA_DIR / "YtDlp" / "cookies.txt"def hasCookieFile() -> bool: