From 713f7d805252b55f4a6fb0eceb57b2950db79a77 Mon Sep 17 00:00:00 2001 From: GOXF <785937070@qq.com> Date: Mon, 30 Nov 2026 14:04:35 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BE=BF=E6=90=BA=E7=89=88=E6=94=B9?= =?UTF-8?q?=E7=94=A8=E4=B8=8A=E6=B8=B8=E5=AE=9E=E7=8E=B0=EF=BC=9ABotArk-Da?= =?UTF-8?q?ta=20=E8=87=AA=E5=8A=A8=E6=94=B9=E5=90=8D=E4=B8=BA=20BotArkData?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - goxfPortable.ts 改为调用上游 resolveUserDataDir(--user-data-dir / BotArkData / .botark-portable),仍是第一个 import,并锁 sessionData;index.ts 去掉重复判定。 - 新增 goxfPortableMigrate.ts:启动时把旧 BotArk-Data 原地改名为 BotArkData(新目录不存在或只有 README 时);两边都有数据不动;改名失败本次用旧目录。 - 更新器、更新助手、清单脚本过渡期两个名字都当数据目录;zip 包改放 .botark-portable 标记。 - 仅 Windows 便携构建启用自更新(PORTABLE_DIR)。 --- .github/workflows/goxf-portable.yml | 11 ++-- AGENTS.md | 4 +- electron-builder.config.cjs | 2 +- handoff/decisions.md | 6 +++ scripts/goxf-manifest.mjs | 4 +- src/main/goxfMihomo.ts | 2 +- src/main/goxfPerf.ts | 2 +- src/main/goxfPortable.ts | 71 ++++++++++++++----------- src/main/goxfPortableMigrate.test.ts | 64 ++++++++++++++++++++++ src/main/goxfPortableMigrate.ts | 66 +++++++++++++++++++++++ src/main/goxfSessionCookieLogic.test.ts | 2 +- src/main/goxfUpdateHelper.test.ts | 6 +-- src/main/goxfUpdateHelper.ts | 6 +-- src/main/goxfUpdateLogic.test.ts | 2 +- src/main/goxfUpdateLogic.ts | 6 +-- src/main/goxfUpdater.ts | 10 ++-- src/main/hark/harkFrameLog.ts | 2 +- src/main/index.ts | 21 +------- 18 files changed, 208 insertions(+), 79 deletions(-) create mode 100644 src/main/goxfPortableMigrate.test.ts create mode 100644 src/main/goxfPortableMigrate.ts diff --git a/.github/workflows/goxf-portable.yml b/.github/workflows/goxf-portable.yml index f989a89f..1c42598d 100644 --- a/.github/workflows/goxf-portable.yml +++ b/.github/workflows/goxf-portable.yml @@ -6,8 +6,8 @@ name: GOXF Portable # only the newest 5 dev prereleases (and tags) are kept # manual dispatch → run artifact only # Assets per release (read by src/main/goxfUpdater.ts): -# BotArk-Portable--win-x64.zip full program folder (+ empty BotArk-Data) -# manifest-BotArk-Portable--win-x64.json every program file: path, sha256, size (BotArk-Data excluded) +# BotArk-Portable--win-x64.zip full program folder (+ .botark-portable marker) +# manifest-BotArk-Portable--win-x64.json every program file: path, sha256, size (BotArkData excluded) # patch-BotArk-Portable--win-x64.zip the whole resources/ folder; applied file-by-file when the # runtime (everything outside resources/) matches the manifest # *Portable*.exe single-exe build @@ -135,7 +135,7 @@ jobs: env: CSC_IDENTITY_AUTO_DISCOVERY: 'false' run: npx electron-builder --config electron-builder.config.cjs --win portable dir --x64 --publish never - - name: Zip the unpacked folder (BotArk-Data inside marks it portable) + delta manifest and patch + - name: Zip the unpacked folder (.botark-portable marks it portable) + delta manifest and patch shell: pwsh run: | $ver = $env:GOXF_TAG.Substring(1) @@ -146,8 +146,9 @@ jobs: Compress-Archive -Path release/win-unpacked/resources -DestinationPath "release/patch-$name.zip" $root = Join-Path $env:RUNNER_TEMP $name Copy-Item -Recurse release/win-unpacked $root - New-Item -ItemType Directory -Path (Join-Path $root 'BotArk-Data') | Out-Null - Set-Content -Encoding utf8 -Path (Join-Path $root 'BotArk-Data/README.txt') -Value 'BotArk portable data folder. Keep it next to BotArk.exe; copy the whole folder to move BotArk with your accounts.' + # Upstream's marker: data goes to BotArkData next to BotArk.exe (created on first start). + # No empty BotArkData folder: an update from an old build must not shadow its BotArk-Data. + Set-Content -Encoding utf8 -Path (Join-Path $root '.botark-portable') -Value 'BotArk portable: data lives in BotArkData next to BotArk.exe. Copy the whole folder to move BotArk with your accounts.' Compress-Archive -Path $root -DestinationPath "release/$name.zip" - name: Publish fork release if: github.event_name == 'push' diff --git a/AGENTS.md b/AGENTS.md index 3279f31c..d372efdc 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -15,7 +15,7 @@ ## 机器与身份 - 云电脑:写代码、跑门槛、开 PR。 -- 一台本地 Windows 机器,身份 = 开发:只做真机事项(运行、zip 便携版自更新 BotArk-Data\update.log、perf.log、真实账号登录)。路径、通道见服务器。测试包解压到单独目录,用它自己的 BotArk-Data;命令用绝对路径。 +- 一台本地 Windows 机器,身份 = 开发:只做真机事项(运行、zip 便携版自更新 BotArkData\update.log、perf.log、真实账号登录)。路径、通道见服务器。测试包解压到单独目录,用它自己的 BotArkData;命令用绝对路径。 ## 发版 见 skills/release:合并即出测试版并报版本号;正式版先升 goxfBuild、打 tag,要用户同意。 @@ -24,7 +24,7 @@ 设计规范 docs/goxf-design.md。界面改动先出效果图(skills/ui-mock),用户说「开工」才写代码。 ## 红线 -- 不碰用户自己在用的 BotArk 和它的 BotArk-Data;不动用户已开的窗口,不碰桌面 1。 +- 不碰用户自己在用的 BotArk 和它的 BotArkData(旧版叫 BotArk-Data);不动用户已开的窗口,不碰桌面 1。 - 不用用户的真实账号替他发消息、开项目,测试前先问。 - 服务器只读取,改动要用户同意。 - 例外(用户 2026-11-28 定):服务器地址和 root 账号名可以出现在本公开仓库;令牌、密码、真实数据仍不进仓库。 diff --git a/electron-builder.config.cjs b/electron-builder.config.cjs index 445049d0..8e249576 100644 --- a/electron-builder.config.cjs +++ b/electron-builder.config.cjs @@ -89,7 +89,7 @@ module.exports = { artifactName: '${productName}-${version}-${arch}.${ext}' }, win: { - // GOXF fork: + portable (data lives in /BotArk-Data, see src/main/goxfPortable.ts). + // GOXF fork: + portable (data lives in /BotArkData, see src/main/goxfPortable.ts). target: [ { target: 'nsis', arch: ['x64'] }, { target: 'portable', arch: ['x64'] } diff --git a/handoff/decisions.md b/handoff/decisions.md index cb365a4b..180e9a1e 100644 --- a/handoff/decisions.md +++ b/handoff/decisions.md @@ -26,3 +26,9 @@ ## 2026-11-29 采用通用对接规范 - 规则进 AGENTS.md,交接拆成 state / decisions / log,项目技能进 skills/,私密信息和机器身份放服务器 /root/ops/projects/botark.md。理由:任何 AI 只发开场白就能接手,内容不丢、不乱。 + +## 2026-11-30 便携版改用上游实现 +- 数据目录判定用上游 `portableDataDir.ts`(`--user-data-dir` / `BotArkData` / `.botark-portable`),`goxfPortable.ts` 只做薄壳并仍是第一个 import,额外锁 sessionData。 +- 旧 `BotArk-Data` 启动时原地改名为 `BotArkData`(新目录不存在或只有 README 才改;两边都有数据则不动、用新的;改名失败则本次直接用旧目录)。理由:用户要跟上游,数据不能丢。 +- 自用更新器、zip 文件夹版、增量补丁、goxf 产物名保留;过渡期更新器两个名字都当数据目录保留。zip 包改放 `.botark-portable` 标记,不再带空数据文件夹(防止旧版更新时空文件夹挡住旧数据)。 +- 退回 v0.17.1-goxf 及更早:先退出,把 `BotArkData` 改回 `BotArk-Data`(目录里有说明文件)。 diff --git a/scripts/goxf-manifest.mjs b/scripts/goxf-manifest.mjs index ab0a901e..736da5cc 100644 --- a/scripts/goxf-manifest.mjs +++ b/scripts/goxf-manifest.mjs @@ -1,7 +1,7 @@ #!/usr/bin/env node // GOXF fork: delta-update manifest for the portable folder (read by src/main/goxfUpdater.ts). // Usage: node scripts/goxf-manifest.mjs -// Lists every file under programDir except BotArk-Data: { path (forward slashes), sha256, size }. +// Lists every file under programDir except the data folder (BotArkData, old BotArk-Data): { path (forward slashes), sha256, size }. import { createHash } from 'node:crypto' import { createReadStream, readdirSync, statSync, writeFileSync } from 'node:fs' import { join, relative, sep } from 'node:path' @@ -26,7 +26,7 @@ for (const entry of readdirSync(dir, { recursive: true, withFileTypes: true })) if (!entry.isFile()) continue const full = join(entry.parentPath ?? entry.path, entry.name) const path = relative(dir, full).split(sep).join('/') - if (path === 'BotArk-Data' || path.startsWith('BotArk-Data/')) continue + if (/^(BotArkData|BotArk-Data)(\/|$)/.test(path)) continue files.push({ path, sha256: await sha256(full), size: statSync(full).size }) } if (files.length === 0) throw new Error(`no files under ${dir}`) diff --git a/src/main/goxfMihomo.ts b/src/main/goxfMihomo.ts index ecd20261..8882df72 100644 --- a/src/main/goxfMihomo.ts +++ b/src/main/goxfMihomo.ts @@ -2,7 +2,7 @@ * GOXF fork: the user-installed Mihomo kernel and its processes. * * - Kernel: pinned official asset (goxfMihomoAssets), SHA-256 checked, unpacked - * into userData/mihomo/bin (portable: BotArk-Data). Never on PATH, never + * into userData/mihomo/bin (portable: BotArkData). Never on PATH, never * downloaded without the user pressing a button. * - Processes: one per Mihomo-served pool entry, loopback mixed inbound with * random credentials, loopback controller with a random secret. The config goes diff --git a/src/main/goxfPerf.ts b/src/main/goxfPerf.ts index 8bcec5a7..8577c3d5 100644 --- a/src/main/goxfPerf.ts +++ b/src/main/goxfPerf.ts @@ -1,6 +1,6 @@ /** * GOXF fork only: startup time + memory log for portable builds. - * Writes to /perf.log so a real Windows run gives numbers + * Writes to /perf.log so a real Windows run gives numbers * before we optimize memory or speed. No-op outside portable mode. */ import { appendFileSync, statSync, renameSync } from 'node:fs' diff --git a/src/main/goxfPortable.ts b/src/main/goxfPortable.ts index 2ba80b24..e7709b49 100644 --- a/src/main/goxfPortable.ts +++ b/src/main/goxfPortable.ts @@ -1,48 +1,59 @@ /** - * GOXF fork only: portable mode. + * GOXF fork: portable mode, on upstream's resolver (src/main/portableDataDir.ts). * - * electron-builder's portable launcher extracts the app to a temp dir and sets - * PORTABLE_EXECUTABLE_DIR = folder holding the portable .exe - * PORTABLE_EXECUTABLE_FILE = full path of the portable .exe - * When present, keep all data (accounts, sessions, persist: partitions) in - * /BotArk-Data so it travels with the exe. + * Upstream picks the data folder: --user-data-dir, then /BotArkData for + * electron-builder's portable exe (PORTABLE_EXECUTABLE_DIR), then a BotArkData + * folder or .botark-portable marker next to BotArk.exe (zip build), then the + * legacy bothub folder, else the default. Before that, an old fork BotArk-Data + * folder is renamed to BotArkData (goxfPortableMigrate.ts). * * Imported FIRST in src/main/index.ts so it runs before any module touches * userData and before app ready (setPath after ready does not move sessions). */ -import { existsSync, mkdirSync } from 'node:fs' import { dirname, join } from 'node:path' import { app } from 'electron' +import { resolveUserDataDir } from './portableDataDir' +import { migrateLegacyPortableDir, type PortableMigration } from './goxfPortableMigrate' -const DATA_DIR_NAME = 'BotArk-Data' - -/** - * Zip build (unpacked folder): no launcher env, so a `BotArk-Data` folder - * shipped next to BotArk.exe is the portable marker. - */ -function zipPortableDir(): string | null { - if (!app.isPackaged) return null - const dir = dirname(process.execPath) - return existsSync(join(dir, DATA_DIR_NAME)) ? dir : null +function programDir(): string | null { + const launcherDir = (process.env.PORTABLE_EXECUTABLE_DIR || '').trim() + if (launcherDir) return launcherDir + return app.isPackaged && process.platform !== 'darwin' ? dirname(app.getPath('exe')) : null } -export const PORTABLE_DIR = (process.env.PORTABLE_EXECUTABLE_DIR || '').trim() || zipPortableDir() +const anchor = programDir() +export const PORTABLE_MIGRATION: PortableMigration = anchor ? migrateLegacyPortableDir(anchor) : { kind: 'none' } + +const resolution = PORTABLE_MIGRATION.kind === 'failed' + ? { source: 'portable' as const, dir: PORTABLE_MIGRATION.legacy, warning: undefined } + : resolveUserDataDir({ + argv: process.argv, + env: process.env, + platform: process.platform, + execPath: process.execPath, + exePath: app.getPath('exe'), + appDataPath: app.getPath('appData'), + defaultUserDataPath: app.getPath('userData') + }) +if (resolution.warning) console.warn(resolution.warning) +if (PORTABLE_MIGRATION.kind !== 'none') console.warn('[goxf] portable data folder:', JSON.stringify(PORTABLE_MIGRATION)) + +/** Where accounts, sessions and the goxf logs live in a portable build; null otherwise. */ +export const PORTABLE_DATA_DIR = resolution.source === 'portable' ? resolution.dir : null +/** Program folder the self-updater replaces (Windows portable builds only). */ +export const PORTABLE_DIR = PORTABLE_DATA_DIR && process.platform === 'win32' ? dirname(PORTABLE_DATA_DIR) : null /** Only set for the single-exe build; the zip build cannot self-replace. */ export const PORTABLE_FILE = (process.env.PORTABLE_EXECUTABLE_FILE || '').trim() || null -export const PORTABLE_DATA_DIR = PORTABLE_DIR ? join(PORTABLE_DIR, DATA_DIR_NAME) : null export function isPortable(): boolean { - return PORTABLE_DIR !== null + return PORTABLE_DATA_DIR !== null } -if (PORTABLE_DATA_DIR) { - try { - mkdirSync(PORTABLE_DATA_DIR, { recursive: true }) - app.setPath('userData', PORTABLE_DATA_DIR) - // Session data (cookies, IndexedDB, Partitions/) defaults to - // userData; pin it explicitly so every persist: partition lands here too. - app.setPath('sessionData', PORTABLE_DATA_DIR) - } catch (error) { - console.error('[goxf] portable data dir unavailable, using default userData:', error) - } +try { + app.setPath('userData', resolution.dir) + // Session data (cookies, IndexedDB, Partitions/) defaults to + // userData; pin it explicitly so every persist: partition lands here too. + app.setPath('sessionData', resolution.dir) +} catch (error) { + console.error('[goxf] could not set the data folder, using default userData:', error) } diff --git a/src/main/goxfPortableMigrate.test.ts b/src/main/goxfPortableMigrate.test.ts new file mode 100644 index 00000000..39da45b5 --- /dev/null +++ b/src/main/goxfPortableMigrate.test.ts @@ -0,0 +1,64 @@ +import { mkdirSync, mkdtempSync, readdirSync, rmSync, writeFileSync, existsSync, readFileSync } from 'node:fs' +import { tmpdir } from 'node:os' +import { join } from 'node:path' +import { afterEach, describe, expect, it } from 'vitest' +import { migrateLegacyPortableDir, RENAMED_NOTE } from './goxfPortableMigrate' + +const dirs: string[] = [] +const program = () => { + const dir = mkdtempSync(join(tmpdir(), 'goxf-migrate-')) + dirs.push(dir) + return dir +} +afterEach(() => { + for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true }) +}) + +const seed = (dir: string, file = 'accounts.json') => { + mkdirSync(join(dir, 'Partitions'), { recursive: true }) + writeFileSync(join(dir, file), '{"a":1}') +} + +describe('migrateLegacyPortableDir', () => { + it('does nothing without an old BotArk-Data', () => { + const root = program() + expect(migrateLegacyPortableDir(root)).toEqual({ kind: 'none' }) + expect(readdirSync(root)).toEqual([]) + }) + + it('renames BotArk-Data to BotArkData and leaves a note', () => { + const root = program() + seed(join(root, 'BotArk-Data')) + expect(migrateLegacyPortableDir(root)).toMatchObject({ kind: 'renamed' }) + expect(existsSync(join(root, 'BotArk-Data'))).toBe(false) + expect(readFileSync(join(root, 'BotArkData', 'accounts.json'), 'utf8')).toBe('{"a":1}') + expect(existsSync(join(root, 'BotArkData', 'Partitions'))).toBe(true) + expect(existsSync(join(root, 'BotArkData', RENAMED_NOTE))).toBe(true) + }) + + it('replaces an empty BotArkData (or one with only a README)', () => { + const root = program() + seed(join(root, 'BotArk-Data')) + mkdirSync(join(root, 'BotArkData')) + writeFileSync(join(root, 'BotArkData', 'README.txt'), 'x') + expect(migrateLegacyPortableDir(root)).toMatchObject({ kind: 'renamed' }) + expect(existsSync(join(root, 'BotArkData', 'accounts.json'))).toBe(true) + expect(existsSync(join(root, 'BotArkData', 'README.txt'))).toBe(false) + }) + + it('leaves both alone when both hold data', () => { + const root = program() + seed(join(root, 'BotArk-Data')) + seed(join(root, 'BotArkData'), 'other.json') + expect(migrateLegacyPortableDir(root)).toMatchObject({ kind: 'both' }) + expect(existsSync(join(root, 'BotArk-Data', 'accounts.json'))).toBe(true) + expect(existsSync(join(root, 'BotArkData', 'other.json'))).toBe(true) + }) + + it('is a no-op on the second start', () => { + const root = program() + seed(join(root, 'BotArk-Data')) + migrateLegacyPortableDir(root) + expect(migrateLegacyPortableDir(root)).toEqual({ kind: 'none' }) + }) +}) diff --git a/src/main/goxfPortableMigrate.ts b/src/main/goxfPortableMigrate.ts new file mode 100644 index 00000000..788aef1d --- /dev/null +++ b/src/main/goxfPortableMigrate.ts @@ -0,0 +1,66 @@ +/** + * GOXF fork only: one-time move of the old portable data folder to upstream's name. + * + * Fork builds up to v0.17.1-goxf kept portable data in /BotArk-Data; + * upstream (v0.18.0, src/main/portableDataDir.ts) uses /BotArkData. + * Runs before upstream's resolver so it finds the data under the new name. + * Rename only (same folder, no copy). Rolling back to an old fork build means + * renaming the folder back; RENAMED_NOTE inside says so. + */ +import { existsSync, readdirSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs' +import { join } from 'node:path' + +export const LEGACY_DATA_DIRNAME = 'BotArk-Data' +export const DATA_DIRNAME = 'BotArkData' +export const RENAMED_NOTE = '从 BotArk-Data 改名而来.txt' + +export type PortableMigration = + | { kind: 'none' } + | { kind: 'renamed'; from: string; to: string } + /** Both folders hold data: nothing moved, the new one is used. */ + | { kind: 'both'; legacy: string; current: string } + /** The rename failed (e.g. files in use); this run uses the old folder as is. */ + | { kind: 'failed'; legacy: string; error: string } + +const isDir = (p: string) => { + try { + return statSync(p).isDirectory() + } catch { + return false + } +} + +/** Empty, or only what a package ships in it (a README). */ +function isEmptyDataDir(dir: string): boolean { + try { + return readdirSync(dir).every((name) => /^readme(\.txt|\.md)?$/i.test(name)) + } catch { + return false + } +} + +export function migrateLegacyPortableDir(programDir: string): PortableMigration { + const legacy = join(programDir, LEGACY_DATA_DIRNAME) + if (!isDir(legacy)) return { kind: 'none' } + const current = join(programDir, DATA_DIRNAME) + if (existsSync(current)) { + if (!isDir(current) || !isEmptyDataDir(current)) return { kind: 'both', legacy, current } + } + try { + // An empty BotArkData (e.g. brought by a package) gives way to the real data. + if (existsSync(current)) rmSync(current, { recursive: true, force: true }) + renameSync(legacy, current) + } catch (error) { + return { kind: 'failed', legacy, error: error instanceof Error ? error.message : String(error) } + } + try { + writeFileSync( + join(current, RENAMED_NOTE), + `${new Date().toISOString()} BotArk 把数据文件夹 BotArk-Data 改名为 BotArkData(跟随上游便携版)。\r\n` + + '如需退回 v0.17.1-goxf 及更早版本,先退出 BotArk,再把本文件夹改回 BotArk-Data。\r\n' + ) + } catch { + /* the note is optional */ + } + return { kind: 'renamed', from: legacy, to: current } +} diff --git a/src/main/goxfSessionCookieLogic.test.ts b/src/main/goxfSessionCookieLogic.test.ts index c34d5671..e95b5ee0 100644 --- a/src/main/goxfSessionCookieLogic.test.ts +++ b/src/main/goxfSessionCookieLogic.test.ts @@ -3,7 +3,7 @@ import { accountPartitionName, sessionOnly, toSetDetails } from './goxfSessionCo describe('accountPartitionName', () => { it('accepts account partitions by storage path or bare name', () => { - expect(accountPartitionName('C:\\BotArk-Data\\Partitions\\bothub-account-acc_1'.replace(/\\/g, '/'))).toBe('bothub-account-acc_1') + expect(accountPartitionName('C:\\BotArkData\\Partitions\\bothub-account-acc_1'.replace(/\\/g, '/'))).toBe('bothub-account-acc_1') expect(accountPartitionName('bothub-account-x-2')).toBe('bothub-account-x-2') }) it('skips other partitions and the default session', () => { diff --git a/src/main/goxfUpdateHelper.test.ts b/src/main/goxfUpdateHelper.test.ts index 4854c986..cc4185e6 100644 --- a/src/main/goxfUpdateHelper.test.ts +++ b/src/main/goxfUpdateHelper.test.ts @@ -9,7 +9,7 @@ import { HELPER_SOURCE, type HelperJob } from './goxfUpdateHelper' function setup(): { root: string; app: string; data: string; job: Omit } { const root = mkdtempSync(join(tmpdir(), 'botark-helper-')) const app = join(root, 'BotArk') - const data = join(app, 'BotArk-Data') + const data = join(app, 'BotArkData') mkdirSync(join(app, 'resources'), { recursive: true }) mkdirSync(data) writeFileSync(join(app, 'BotArk.exe'), 'old exe') @@ -30,7 +30,7 @@ function setup(): { root: string; app: string; data: string; job: Omit { - it('full: replaces the app, keeps BotArk-Data, writes ready, drops the lock and zip', () => { + it('full: replaces the app, keeps BotArkData, writes ready, drops the lock and zip', () => { const { root, app, data, job } = setup() const src = join(job.stageDir, 'BotArk') mkdirSync(join(src, 'resources'), { recursive: true }) diff --git a/src/main/goxfUpdateHelper.ts b/src/main/goxfUpdateHelper.ts index 4e0db51a..464eda7b 100644 --- a/src/main/goxfUpdateHelper.ts +++ b/src/main/goxfUpdateHelper.ts @@ -1,13 +1,13 @@ /** * GOXF zip self-update without PowerShell. * - * The app writes HELPER_SOURCE to BotArk-Data/update-helper.cjs plus a job file, then runs it with an + * The app writes HELPER_SOURCE to BotArkData/update-helper.cjs plus a job file, then runs it with an * Electron exe in Node mode (ELECTRON_RUN_AS_NODE=1): the new staged BotArk.exe for a full update, the * current one for a delta (a delta never touches the runtime, and Node mode opens no app.asar). * The helper logs to update.log with the same appendFileSync the app uses, and writes `ready` first, * so the app only quits once the helper is really running. * - * Full: move every old top-level entry (except BotArk-Data and our temp files) aside, copy the new + * Full: move every old top-level entry (except BotArkData / old BotArk-Data and our temp files) aside, copy the new * app in (copy, not move: the helper itself runs from the staged folder), relaunch. * Delta: move each changed resources/ file aside and the staged one in, relaunch. * Any failure puts the old files back and relaunches the old version. @@ -114,7 +114,7 @@ try { log('moved ' + undo.length + ' old entries aside') phase = 'in' for (const name of fs.readdirSync(job.srcDir)) { - if (name === 'BotArk-Data') continue + if (name === 'BotArkData' || name === 'BotArk-Data') continue retry('copy ' + name, () => fs.cpSync(path.join(job.srcDir, name), path.join(job.appDir, name), { recursive: true, force: true })) } } else { diff --git a/src/main/goxfUpdateLogic.test.ts b/src/main/goxfUpdateLogic.test.ts index faeb09a2..fa0e3f3f 100644 --- a/src/main/goxfUpdateLogic.test.ts +++ b/src/main/goxfUpdateLogic.test.ts @@ -167,7 +167,7 @@ describe('buildReplaceScript', () => { oldExe: 'D:\\工具\\BotArk.exe', newExe: 'D:\\工具\\.BotArk.exe.new', pid: 1234.9, - logFile: 'D:\\工具\\BotArk-Data\\portable-update.log' + logFile: 'D:\\工具\\BotArkData\\portable-update.log' }) expect(s).toContain("$old = 'D:\\工具\\BotArk.exe'") expect(s).toContain('$appPid = 1234') diff --git a/src/main/goxfUpdateLogic.ts b/src/main/goxfUpdateLogic.ts index 78312083..2f12fe7b 100644 --- a/src/main/goxfUpdateLogic.ts +++ b/src/main/goxfUpdateLogic.ts @@ -8,7 +8,7 @@ * "Upstream has an update" → upstream latest tag > version * "My fork has an update" → (base, build) of newest v*-goxf.* release > (version, goxfBuild) * - * Channels (setting in BotArk-Data/goxf-update.json, default stable) + * Channels (setting in BotArkData/goxf-update.json, default stable) * stable = non-prerelease v*-goxf.N releases, compared by (base, build) as above * test = also CI prereleases v-goxf.dev. from every push to goxf/portable; * newest by published_at, offered when it is a different build published after ours @@ -202,7 +202,7 @@ export interface PromptInput { upstreamLatest: GitHubRelease | null /** GOXF /releases list (null when the check failed). */ forkReleases: GitHubRelease[] | null - /** 'exe' = electron-builder portable launcher, 'zip' = unpacked folder with BotArk-Data next to it. */ + /** 'exe' = electron-builder portable launcher, 'zip' = unpacked folder with BotArkData next to it. */ portable: PortableKind platform: string /** Default 'stable'. */ @@ -339,7 +339,7 @@ export const isUpdateLockFresh = (lockMtimeMs: number, nowMs: number): boolean = /** * Delta update. CI ships, next to the full zip: - * manifest-.json every file of the program folder (BotArk-Data excluded): { path, sha256, size } + * manifest-.json every file of the program folder (BotArkData excluded): { path, sha256, size } * patch-.zip the whole resources/ folder (app.asar, app.asar.unpacked, …): what changes between our builds * Everything outside resources/ is the Electron runtime. If every runtime file on disk matches the manifest, * only the patch is downloaded and only resources/ files whose sha256 differs are replaced; otherwise full zip. diff --git a/src/main/goxfUpdater.ts b/src/main/goxfUpdater.ts index 2716381e..5fd8c9b8 100644 --- a/src/main/goxfUpdater.ts +++ b/src/main/goxfUpdater.ts @@ -13,7 +13,7 @@ * manual relaunch from grabbing the files mid-swap (see exitIfUpdating) * otherwise: open the release page * Channel stable/test (see goxfUpdateLogic) is persisted in /goxf-update.json. - * Every update writes BotArk-Data/update.log; update-pending.json lets the next start tell a failed swap. + * Every update writes BotArkData/update.log; update-pending.json lets the next start tell a failed swap. * Exposes the same registerUpdaterIpc/startAutoUpdater as ./updater so index.ts only swaps one import. */ import { spawn } from 'node:child_process' @@ -144,7 +144,7 @@ function takePendingFailure(): string | null { return null } logUpdate(`update to ${target} did not take; still ${currentVersion()}`) - return `上次更新到 v${target} 没有成功,已保留 v${currentVersion()}。详情见 BotArk-Data/update.log` + return `上次更新到 v${target} 没有成功,已保留 v${currentVersion()}。详情见 BotArkData/update.log` } catch { return null } @@ -170,7 +170,7 @@ export function exitIfUpdating(): void { process.exit(0) } -/** 'exe' = single portable exe (launcher env), 'zip' = unpacked folder with BotArk-Data beside BotArk.exe. */ +/** 'exe' = single portable exe (launcher env), 'zip' = unpacked folder with BotArkData beside BotArk.exe. */ const portableKind = (): PortableKind => (PORTABLE_FILE ? 'exe' : PORTABLE_DIR ? 'zip' : null) const portableSelfUpdate = (): boolean => process.platform === 'win32' && portableKind() !== null @@ -540,7 +540,7 @@ async function installPortable(): Promise { renameSync(partial, ready) logUpdate(`downloaded ${changed ? `delta (${changed.length} files)` : 'full'}: ${asset.name}`) const exeName = basename(process.execPath) - const logFile = join(dir, 'BotArk-Data', 'update.log') + const logFile = join(PORTABLE_DATA_DIR ?? join(dir, 'BotArkData'), 'update.log') if (zipMode) { broadcastGoxf({ type: 'portable-extracting', version: target }) await unzip(ready, stage, abort.signal) @@ -574,7 +574,7 @@ async function installPortable(): Promise { backupDir: join(dir, UPDATE_BACKUP_DIR), srcDir: src, files: changed?.map((f) => f.path), - keep: ['BotArk-Data', UPDATE_STAGE_DIR, UPDATE_BACKUP_DIR, basename(ready)] + keep: ['BotArkData', 'BotArk-Data', UPDATE_STAGE_DIR, UPDATE_BACKUP_DIR, basename(ready)] }, changed ? process.execPath : join(src!, exeName)) } else { const body = buildReplaceScript({ oldExe: PORTABLE_FILE!, newExe: ready, pid: process.pid, logFile }) diff --git a/src/main/hark/harkFrameLog.ts b/src/main/hark/harkFrameLog.ts index b7c3644e..33873c62 100644 --- a/src/main/hark/harkFrameLog.ts +++ b/src/main/hark/harkFrameLog.ts @@ -1,6 +1,6 @@ /** * GOXF fork only: a small diagnostic log of Hark /sync/conversation frames. - * Writes /hark-frames.log (portable builds only) so we can see which + * Writes /hark-frames.log (portable builds only) so we can see which * field carries the web app's live status line when BotArk shows only 「处理中…」. * Records op names, snapshot keys and any narration/activity/status-like values, capped at 1 MB. */ diff --git a/src/main/index.ts b/src/main/index.ts index 77af3695..4d3c3688 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -1,5 +1,5 @@ // GOXF fork: must stay the first import (moves userData next to a portable exe before anything reads it). -import { isPortable } from './goxfPortable' +import './goxfPortable' import { DISPLAY_LOCALE_CHANNEL } from '@shared/displayLocale' import { getNativeDisplayLocale, setNativeDisplayLocale } from './nativeDisplayCopy' import { registerSlackIpc, stopSlack } from './slack/slackIpc' @@ -45,7 +45,6 @@ import { hasPopouts, registerPopoutIpc, restorePopouts } from './goxfPopout' import { openInApp, registerInAppIpc } from './goxfInApp' import { allowHarkLiveViewFrames } from './goxfLiveView' import { hideToTray, registerTrayIpc, startTray } from './goxfTray' -import { resolveUserDataDir } from './portableDataDir' try { app.commandLine?.appendSwitch?.('disable-blink-features', 'AutomationControlled') @@ -121,24 +120,6 @@ app.on('open-url', (event, url) => { dispatchCueCallback(url) }) -// GOXF fork: goxfPortable (first import) already pinned userData for our portable builds; upstream's -// resolver handles --user-data-dir and the legacy bothub dir for everything else. -if (!isPortable()) { - const userDataResolution = resolveUserDataDir({ - argv: process.argv, - env: process.env, - platform: process.platform, - execPath: process.execPath, - exePath: app.getPath('exe'), - appDataPath: app.getPath('appData'), - defaultUserDataPath: app.getPath('userData') - }) - if (userDataResolution.warning) { - console.warn(userDataResolution.warning) - } - app.setPath('userData', userDataResolution.dir) -} - // Two instances share userData and race on every JSON store and on // Chromium's profile; hand the second launch over to the first. exitIfUpdating() From ec6c9b7e4f0132a1184a9e95e240416bba287db5 Mon Sep 17 00:00:00 2001 From: GOXF <785937070@qq.com> Date: Mon, 30 Nov 2026 14:07:38 +0000 Subject: [PATCH 2/2] =?UTF-8?q?goxfPortable:=20=E5=8D=95=E5=85=83=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E9=87=8C=E6=97=A0=20electron=20app=20=E6=97=B6?= =?UTF-8?q?=E8=B7=B3=E8=BF=87=E5=88=A4=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/goxfPortable.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/goxfPortable.ts b/src/main/goxfPortable.ts index e7709b49..7525af03 100644 --- a/src/main/goxfPortable.ts +++ b/src/main/goxfPortable.ts @@ -10,7 +10,7 @@ * Imported FIRST in src/main/index.ts so it runs before any module touches * userData and before app ready (setPath after ready does not move sessions). */ -import { dirname, join } from 'node:path' +import { dirname } from 'node:path' import { app } from 'electron' import { resolveUserDataDir } from './portableDataDir' import { migrateLegacyPortableDir, type PortableMigration } from './goxfPortableMigrate' @@ -24,7 +24,11 @@ function programDir(): string | null { const anchor = programDir() export const PORTABLE_MIGRATION: PortableMigration = anchor ? migrateLegacyPortableDir(anchor) : { kind: 'none' } -const resolution = PORTABLE_MIGRATION.kind === 'failed' +// Unit tests import this module with a stubbed electron; there is nothing to resolve then. +const hasElectronApp = typeof app?.getPath === 'function' +const resolution = !hasElectronApp + ? { source: 'default' as const, dir: '', warning: undefined } + : PORTABLE_MIGRATION.kind === 'failed' ? { source: 'portable' as const, dir: PORTABLE_MIGRATION.legacy, warning: undefined } : resolveUserDataDir({ argv: process.argv, @@ -49,7 +53,7 @@ export function isPortable(): boolean { return PORTABLE_DATA_DIR !== null } -try { +if (hasElectronApp) try { app.setPath('userData', resolution.dir) // Session data (cookies, IndexedDB, Partitions/) defaults to // userData; pin it explicitly so every persist: partition lands here too.