98 lines
2.7 KiB
Markdown
98 lines
2.7 KiB
Markdown
## 开发说明(开发 / 打包 / 安装 / 更新)
|
||
|
||
### 运行环境
|
||
|
||
- **系统**:Windows 10/11
|
||
- **Python**:建议与当前项目一致的版本(你本机是 3.14)
|
||
- **依赖**:见 `requirements.txt`
|
||
|
||
安装依赖:
|
||
|
||
```powershell
|
||
python -m pip install -r requirements.txt
|
||
python -m pip install pyinstaller
|
||
```
|
||
|
||
### 本地运行
|
||
|
||
```powershell
|
||
python main.py
|
||
```
|
||
|
||
### 版本号
|
||
|
||
- **版本号来源**:`app_info.py` 里的 `__VERSION__`
|
||
- **安装包 AppVersion**:由 `installer/build_installer.py` 自动从 `app_info.py` 注入到 `installer/niumasoftware.generated.iss`
|
||
|
||
### 数据库存储与结构升级(SQLite Migration)
|
||
|
||
- **数据文件位置**:默认在 `%APPDATA%\CleanDesktopOrganizer\data.db`(不在安装目录,不会被覆盖更新影响)
|
||
- **结构升级**:在 `db/database.py` 内通过 `schema_version` 做版本化迁移
|
||
- 新增表/字段/索引:新增一个迁移版本并提升 `LATEST_SCHEMA_VERSION`
|
||
- 启动时 `init_db()` 自动从旧版本迁移到最新
|
||
|
||
### 一键打包(推荐)
|
||
|
||
项目根目录直接运行:
|
||
|
||
```powershell
|
||
.\build_installer.bat
|
||
```
|
||
|
||
它会自动完成:
|
||
|
||
- 清理 `build/`、`dist/`
|
||
- PyInstaller 打包主程序(onedir)到 `dist\niumasoftware\`
|
||
- PyInstaller 打包更新助手(onefile)到 `dist\niumasoftware\update_helper.exe`
|
||
- 生成 `installer\niumasoftware.generated.iss`
|
||
- 若检测到 Inno Setup 的 `ISCC.exe`,则自动编译安装包
|
||
|
||
### 手动打包(PyInstaller)
|
||
|
||
主程序(onedir):
|
||
|
||
```powershell
|
||
python -m PyInstaller --noconfirm --onedir --name niumasoftware --windowed `
|
||
--icon "logo.ico" `
|
||
--add-data "assets;assets" `
|
||
--add-data "logo.png;." `
|
||
main.py
|
||
```
|
||
|
||
更新助手(onefile,统一输出到 `dist\niumasoftware`):
|
||
|
||
```powershell
|
||
python -m PyInstaller --noconfirm --onefile --name update_helper --console --distpath dist\niumasoftware `
|
||
--icon "logo.ico" `
|
||
update_helper.py
|
||
```
|
||
|
||
产物约定(用于安装包脚本):
|
||
|
||
- `dist\niumasoftware\niumasoftware.exe`
|
||
- `dist\niumasoftware\update_helper.exe`
|
||
|
||
### 生成安装包(Inno Setup)
|
||
|
||
1) 生成带版本号的最终脚本:
|
||
|
||
```powershell
|
||
python installer/build_installer.py
|
||
```
|
||
|
||
2) 用 Inno Setup Compiler 编译:
|
||
|
||
- `installer/niumasoftware.generated.iss`
|
||
|
||
### 全局安装后的静默覆盖更新(计划任务)
|
||
|
||
由于安装目录通常在 `Program Files`,普通权限无法覆盖 exe。
|
||
|
||
实现方式(已内置):
|
||
|
||
- 主程序下载更新到:`{commonappdata}\CleanDesktopOrganizer\updates\_update_new.exe`
|
||
- 写入请求:`{commonappdata}\CleanDesktopOrganizer\update_request.json`
|
||
- 触发计划任务:`schtasks /Run /TN CleanDesktopOrganizer\Update`
|
||
- 计划任务以 **SYSTEM** 执行 `{app}\update_helper.exe` 覆盖并重启
|
||
|