121 lines
5.8 KiB
Markdown
121 lines
5.8 KiB
Markdown
# Windows 打包说明
|
||
|
||
本目录提供两级交付方式:
|
||
|
||
1. PyInstaller 便携目录:生成 `dist/DouyinGuaji-<version>/`,可直接复制给别人运行。
|
||
2. Inno Setup 安装包:基于便携目录生成 `DouyinGuaji-<version>-Setup.exe`。
|
||
|
||
## 生成便携目录
|
||
|
||
在项目根目录运行:
|
||
|
||
```powershell
|
||
powershell -NoProfile -ExecutionPolicy Bypass -File packaging\pyinstaller\build_windows.ps1
|
||
```
|
||
|
||
如果依赖已经装好,可以跳过安装依赖:
|
||
|
||
```powershell
|
||
powershell -NoProfile -ExecutionPolicy Bypass -File packaging\pyinstaller\build_windows.ps1 -SkipInstall
|
||
```
|
||
|
||
正式打包默认会先通过 Cython 编译 `douyin/` 和 `operations/` 核心模块,再让 PyInstaller 从 `build\cythonized-src\` 打包:
|
||
|
||
```powershell
|
||
powershell -NoProfile -ExecutionPolicy Bypass -File packaging\pyinstaller\build_windows.ps1 -SkipInstall
|
||
```
|
||
|
||
该流程会生成 `build\cythonized-src\`,其中核心模块以 `.pyd` 形式存在。该目录是中间产物,不要直接分发;最终仍然只分发 `dist\DouyinGuaji-<version>\` 或 Inno 生成的安装包。
|
||
|
||
如果只是小更新、想复用 PyInstaller 缓存来加快打包,可以额外加 `-ReuseCache`。注意:改到 `douyin/fudai`、`douyin/reservation`、`douyin/detection` 或 `douyin/stage` 时,Cython 核心仍会重新编译;`-ReuseCache` 主要复用 PyInstaller 的分析/收集缓存。
|
||
|
||
```powershell
|
||
powershell -NoProfile -ExecutionPolicy Bypass -File packaging\pyinstaller\build_windows.ps1 -SkipInstall -ReuseCache
|
||
```
|
||
|
||
如果需要继续使用旧的 PyArmor 路线,可额外加 `-UsePyArmor`。注意:PyArmor 试用版会在混淆文件头部留下 trial 标记,正式分发前建议购买/配置正式授权后重新打包。若 PyArmor 授权不可用,旧路线会失败并停止。
|
||
|
||
仅本机开发调试需要生成明文包时,才显式加 `-NoCythonForDevOnly`:
|
||
|
||
```powershell
|
||
powershell -NoProfile -ExecutionPolicy Bypass -File packaging\pyinstaller\build_windows.ps1 -SkipInstall -NoCythonForDevOnly
|
||
```
|
||
|
||
如果要尝试对根目录 exe 做 UPX 加壳/压缩,可额外加 `-PackExe -UpxDir <UPX目录>`:
|
||
|
||
```powershell
|
||
powershell -NoProfile -ExecutionPolicy Bypass -File packaging\pyinstaller\build_windows.ps1 -SkipInstall -PackExe -UpxDir C:\path\to\upx
|
||
```
|
||
|
||
当前 PyInstaller 生成的 exe 带 `GUARD_CF`,UPX 默认会拒绝压缩。脚本提供 `-PackExeForce` 仅用于实验;验证中它会导致 exe 启动失败并报 `Failed to load Python DLL`,脚本已加入加壳后 smoke 检查,失败会中止打包。正式分发不要启用 `-PackExeForce`。
|
||
|
||
如果要生成带本地授权的测试包,先生成当前机器的 `license.dat`:
|
||
|
||
```powershell
|
||
python -m tools.license_dev --output license.dat --days 30 --customer local
|
||
```
|
||
|
||
正式接入激活服务器后,`license.dat` 应由服务器签发;客户端只内置公钥。
|
||
|
||
输出目录:
|
||
|
||
```text
|
||
dist\DouyinGuaji-<version>\
|
||
```
|
||
|
||
主要文件:
|
||
|
||
- `DouyinGuajiGUI.exe`:数据看板版桌面 GUI 主入口
|
||
- `web_gui.exe`:Web GUI 服务入口
|
||
- `run_cli.exe`:后台运行入口,桌面 GUI / Web GUI 会调用它
|
||
- `assets/`、`webui/`、`config/`:运行所需资源
|
||
- `platform-tools/`:随包 ADB 运行组件,至少包含 `adb.exe`、`AdbWinApi.dll`、`AdbWinUsbApi.dll`
|
||
- `android-tools/`:随包手机侧辅助组件,当前包含 `ADBKeyboard.apk`
|
||
- `logs/`、`pic/`、`state/`:运行时输出目录
|
||
- `license.dat`:默认不随包分发;仅本地测试包需要时才使用 `-IncludeLicense` 显式复制
|
||
|
||
测试包如需临时带入本地 `license.dat`:
|
||
|
||
```powershell
|
||
powershell -NoProfile -ExecutionPolicy Bypass -File packaging\pyinstaller\build_windows.ps1 -SkipInstall -IncludeLicense
|
||
```
|
||
|
||
## 生成安装包
|
||
|
||
先安装 Inno Setup 6,并确保 `iscc.exe` 在 PATH 中,然后运行:
|
||
|
||
```powershell
|
||
iscc packaging\inno\douyin_guaji.iss /DMyAppVersion=3.3.3
|
||
```
|
||
|
||
输出目录:
|
||
|
||
```text
|
||
dist\installer\DouyinGuaji-3.3.3-Setup.exe
|
||
```
|
||
|
||
## 从零安装验收
|
||
|
||
打完便携包和安装包后,运行:
|
||
|
||
```powershell
|
||
powershell -NoProfile -ExecutionPolicy Bypass -File tools\ci\fresh_install_smoke.ps1
|
||
```
|
||
|
||
脚本会静默安装到 `artifacts\fresh_install_ci\DouyinGuajiApp`,并检查默认配置、随包 ADB、ADBKeyboard、WebGUI 首次卡密门禁、未授权运行接口拦截、Dashboard 首次启动不闪退。
|
||
|
||
验收报告:
|
||
|
||
```text
|
||
artifacts\fresh_install_ci\fresh_install_report.json
|
||
```
|
||
|
||
## 发给别人前检查
|
||
|
||
- 打包脚本会自动运行 `python -m tools.distribution_manifest dist\DouyinGuaji-<version>`,防止源码、调试产物、个人配置和旧日志混入分发目录。
|
||
- 最终分发目录只应保留根目录三个 exe、一个 `_internal/`、运行时白名单 `assets/`、运行时白名单 `webui/`、`platform-tools/` 中的 ADB 白名单文件、`android-tools/ADBKeyboard.apk`、`config/README.md`、`logs/.keep`、`pic/.keep`、`state/.keep`。正式分发不要包含 `license.dat`、`README.md`、`artifacts/`、`tests/`、源码目录、调试截图、临时模板或 debug/README 页面。
|
||
- 正式包会自带 ADB,不要求目标电脑额外安装 Android platform-tools 或配置 PATH。程序在需要中文输入且设备未安装 ADBKeyboard 时,会尝试从随包 `android-tools/ADBKeyboard.apk` 自动安装到手机。新电脑仍需要在手机上开启开发者选项/USB 调试并允许本机 RSA 授权;部分品牌手机首次 USB 识别还需要 Windows 能正确安装对应 USB 驱动。
|
||
- 首次启动 PaddleOCR 相关组件可能较慢,杀毒软件也可能扫描 exe。
|
||
- `config/default_config.json` 会随安装包复制为 `config/config.json`,只放正式默认值,不放个人设备、卡密或运行状态。
|
||
- 默认 Cython 编译后仍要以 `python -m tools.distribution_manifest dist\DouyinGuaji-<version>` 的结果为准;PASS 才能发给别人。使用 `-NoCythonForDevOnly` 生成的明文包禁止分发。
|