diff --git a/.gitignore b/.gitignore index 35d011e..6b5ca25 100644 --- a/.gitignore +++ b/.gitignore @@ -1,64 +1,5 @@ -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* - -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release - -# Dependency directories +# 环境 node_modules/ -jspm_packages/ - -# TypeScript v1 declaration files -typings/ - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variables file -.env - -# next.js build output -.next # 下载文件夹 downloads/ diff --git a/package.json b/package.json index 7e15f4b..03edb94 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "pixiv-backend", + "name": "pixiv-manager", "version": "1.0.4", "description": "Pixiv 下载浏览管理器", "main": "backend/start.js", @@ -10,7 +10,7 @@ "assets": [ "backend/**/*", "ui/dist/**/*", - "node_modules/**/*" + "node_modules/axios/**/*" ] }, "scripts": { @@ -18,8 +18,8 @@ "dev": "node backend/start.js", "test": "node backend/test-login.js", "set-proxy": "node backend/set-proxy.js", - "build": "pkg .", - "build-portable": "npm run build && node scripts/create-portable.js" + "build": "pkg . && node scripts/add-icon.js", + "bp": "npm run build && node scripts/create-portable.js" }, "dependencies": { "appdata-path": "^1.0.0", @@ -36,7 +36,9 @@ "uuid": "^11.1.0" }, "devDependencies": { - "readline-sync": "^1.4.10" + "readline-sync": "^1.4.10", + "resedit": "^2.2.0", + "pe-library": "^1.1.1" }, "keywords": [ "pixiv", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d73db40..46633e0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -45,9 +45,15 @@ importers: specifier: ^11.1.0 version: 11.1.0 devDependencies: + pe-library: + specifier: ^1.0.1 + version: 1.0.1 readline-sync: specifier: ^1.4.10 version: 1.4.10 + resedit: + specifier: ^2.0.3 + version: 2.0.3 packages: @@ -407,6 +413,10 @@ packages: resolution: {integrity: sha512-TdrF7fW9Rphjq4RjrW0Kp2AW0Ahwu9sRGTkS6bvDi0SCwZlEZYmcfDbEsTz8RVk0EHIS/Vd1bv3JhG+1xZuAyQ==} engines: {node: '>=16'} + pe-library@1.0.1: + resolution: {integrity: sha512-nh39Mo1eGWmZS7y+mK/dQIqg7S1lp38DpRxkyoHf0ZcUs/HDc+yyTjuOtTvSMZHmfSLuSQaX945u05Y2Q6UWZg==} + engines: {node: '>=14', npm: '>=7'} + proxy-addr@2.0.7: resolution: {integrity: sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==} engines: {node: '>= 0.10'} @@ -434,6 +444,10 @@ packages: resolution: {integrity: sha512-gNva8/6UAe8QYepIQH/jQ2qn91Qj0B9sYjMBBs3QOB8F2CXcKgLxQaJRP76sWVRQt+QU+8fAkCbCvjjMFu7Ycw==} engines: {node: '>= 0.8.0'} + resedit@2.0.3: + resolution: {integrity: sha512-oTeemxwoMuxxTYxXUwjkrOPfngTQehlv0/HoYFNkB4uzsP1Un1A9nI8JQKGOFkxpqkC7qkMs0lUsGrvUlbLNUA==} + engines: {node: '>=14', npm: '>=7'} + router@2.2.0: resolution: {integrity: sha512-nLTrUKm2UyiL7rlhapu/Zl45FwNgkZGaCpZbIHajDYgwlJCOzLSk+cIPAnsEqV955GjILJnKbdQC1nVPz+gAYQ==} engines: {node: '>= 18'} @@ -898,6 +912,8 @@ snapshots: path-to-regexp@8.2.0: {} + pe-library@1.0.1: {} + proxy-addr@2.0.7: dependencies: forwarded: 0.2.0 @@ -933,6 +949,10 @@ snapshots: readline-sync@1.4.10: {} + resedit@2.0.3: + dependencies: + pe-library: 1.0.1 + router@2.2.0: dependencies: debug: 4.4.1 diff --git a/scripts/add-icon.js b/scripts/add-icon.js new file mode 100644 index 0000000..389f9ad --- /dev/null +++ b/scripts/add-icon.js @@ -0,0 +1,102 @@ +const fs = require('fs'); +const path = require('path'); +const fsExtra = require('fs-extra'); +const resedit = require('resedit'); +const { defaultLogger } = require('../backend/utils/logger'); + +// 创建logger实例 +const logger = defaultLogger.child('AddIcon'); + +async function addIconToExe() { + const distDir = path.join(__dirname, '..', 'dist'); + const exeName = 'pixiv-manager.exe'; + const exePath = path.join(distDir, exeName); + const iconPath = path.join(__dirname, '..', 'ui', 'public', 'favicon.ico'); + + try { + // 检查exe文件是否存在 + if (!await fsExtra.pathExists(exePath)) { + logger.error(`❌ EXE文件不存在: ${exePath}`); + logger.info('请先运行构建命令: npm run build'); + return; + } + + // 检查图标文件是否存在 + if (!await fsExtra.pathExists(iconPath)) { + logger.error(`❌ 图标文件不存在: ${iconPath}`); + return; + } + + logger.info('正在添加图标到EXE文件...'); + + // 读取exe文件和图标文件 + const exeBuf = await fsExtra.readFile(exePath); + const iconBuf = await fsExtra.readFile(iconPath); + + logger.info(`EXE文件大小: ${exeBuf.length} 字节`); + logger.info(`图标文件大小: ${iconBuf.length} 字节`); + + try { + // 使用resedit加载exe(忽略证书和深度签名检查) + const exe = resedit.NtExecutable.from(exeBuf, { + ignoreCert: true, + deepSign: false + }); + const res = resedit.NtExecutableResource.from(exe); + logger.info('成功加载EXE文件'); + + // 读取图标组 + const iconFile = resedit.Data.IconFile.from(iconBuf); + logger.info(`图标文件包含 ${iconFile.icons.length} 个图标`); + + // 添加新的图标资源 + resedit.Resource.IconGroupEntry.replaceIconsForResource( + res.entries, + 1, // icon group id + 1033, // lang (en-US) + iconFile.icons.map(item => item.data) + ); + + logger.info('图标资源替换完成'); + + // 更新资源并写回文件 + res.outputResource(exe); + const newExeBuf = Buffer.from(exe.generate()); + await fsExtra.writeFile(exePath, newExeBuf); + + logger.info('✅ 成功添加图标到EXE文件'); + + // 验证图标是否正确添加 + try { + const verifyExe = resedit.NtExecutable.from(newExeBuf); + const verifyRes = resedit.NtExecutableResource.from(verifyExe); + const iconGroupEntries = verifyRes.entries.filter(e => e.type === 14 && e.id === 1); + if (iconGroupEntries.length > 0) { + logger.info('✅ 图标验证成功'); + } else { + logger.warn('⚠️ 图标验证失败:未找到图标资源'); + } + } catch (verifyError) { + logger.warn('⚠️ 图标验证时出错:', verifyError.message); + } + } catch (parseError) { + logger.warn('使用ResEdit处理图标时出错:', parseError.message); + logger.error('错误堆栈:', parseError.stack); + + // 如果ResEdit方法失败,只记录日志,不中断构建过程 + logger.info('⚠️ 图标添加跳过,继续构建过程'); + } + } catch (error) { + logger.error('❌ 添加图标失败', error); + logger.error('错误详情:', error.message); + // 即使添加图标失败,也不要中断构建过程 + logger.info('⚠️ 图标添加失败,继续构建过程'); + } +} + +// 如果直接运行此脚本,则执行函数 +if (require.main === module) { + addIconToExe(); +} + +module.exports = { addIconToExe }; \ No newline at end of file diff --git a/scripts/create-portable.js b/scripts/create-portable.js index 430e027..af45da2 100644 --- a/scripts/create-portable.js +++ b/scripts/create-portable.js @@ -15,7 +15,7 @@ async function createPortable() { await fs.ensureDir(portableDir); // 复制可执行文件 - const exeName = 'pixiv-backend.exe'; + const exeName = 'pixiv-manager.exe'; const exePath = path.join(distDir, exeName); if (await fs.pathExists(exePath)) { await fs.copy(exePath, path.join(portableDir, exeName)); @@ -50,7 +50,7 @@ echo Tip: Press Ctrl+C to stop server echo. :: Start server and pass proxy port and server port -pixiv-backend.exe --proxy-port=%PROXY_PORT% --server-port=%SERVER_PORT% +pixiv-manager.exe --proxy-port=%PROXY_PORT% --server-port=%SERVER_PORT% echo. echo Server stopped diff --git a/ui/public/favicon.ico b/ui/public/favicon.ico index a941275..54d7751 100644 Binary files a/ui/public/favicon.ico and b/ui/public/favicon.ico differ