From 1d3e47b082ed377da178198a9308e3c1d25c701e Mon Sep 17 00:00:00 2001 From: N0VAN0M4LY <224130499+N0VAN0M4LY@users.noreply.github.com> Date: Fri, 4 Dec 2026 00:11:55 +0800 Subject: [PATCH] feat(launcher): allow changing the online update source Let registered clients set or replace their online installation source from the maintenance page. Validate the source and persist its path before refreshing the available update status. Verified launcher and workspace type checks, a launcher build, and an incremental update of a registered client using local game snapshots. --- .../services/copies/copy-file-maintenance.ts | 12 +---- .../main/services/copies/copy-maintenance.ts | 5 +- .../src/main/services/copies/copy-source.ts | 52 +++++++++++++++++++ .../src/renderer/src/i18n/locales/en.json | 7 +++ .../src/renderer/src/i18n/locales/zh-CN.json | 7 +++ .../src/pages/copies/CopyMaintenance.tsx | 10 +++- .../pages/copies/CopyMaintenanceControls.tsx | 21 +++++--- .../src/pages/copies/useCopyMaintenance.ts | 2 +- apps/launcher/src/shared/errors.ts | 2 + apps/launcher/src/shared/schemas/install.ts | 2 +- .../src/shared/schemas/maintenance.ts | 3 +- 11 files changed, 99 insertions(+), 24 deletions(-) create mode 100644 apps/launcher/src/main/services/copies/copy-source.ts diff --git a/apps/launcher/src/main/services/copies/copy-file-maintenance.ts b/apps/launcher/src/main/services/copies/copy-file-maintenance.ts index b4e07e3..5b8fef5 100644 --- a/apps/launcher/src/main/services/copies/copy-file-maintenance.ts +++ b/apps/launcher/src/main/services/copies/copy-file-maintenance.ts @@ -21,20 +21,10 @@ import { canonicalCopyPath, copyPathContains, listCopies, updateCopyRecord } fro import { checkPatches } from '../install/patch-check.ts'; import { STOCK_BACKUP_FOLDER } from '../install/stock-backup.ts'; import { changeCopyFiles, fileInfo, stagedPath } from './change-copy-files.ts'; +import { readSource } from './copy-source.ts'; export type Report = (phase: MaintenanceProgress['phase'], doneBytes?: number, totalBytes?: number) => void; -export async function readSource(record: InstallRecord): Promise { - if (!record.sourcePath) return null; - try { - const game = await inspectGameFolder(record.sourcePath); - return game.missingFiles.length > 0 ? null : game; - } catch (error) { - if (error instanceof AppError) return null; - throw error; - } -} - export function isNewer(source: GameFolderInspection | null, version: string | null): boolean { return !!source?.version && !!version && compareVersions(source.version, version) > 0; } diff --git a/apps/launcher/src/main/services/copies/copy-maintenance.ts b/apps/launcher/src/main/services/copies/copy-maintenance.ts index 3537fdc..db6521d 100644 --- a/apps/launcher/src/main/services/copies/copy-maintenance.ts +++ b/apps/launcher/src/main/services/copies/copy-maintenance.ts @@ -13,7 +13,8 @@ import { gameProcessRunning, launchInProgress } from '../launch/launch-controlle import { readInstalledLab } from '../launch/lab-handoff.ts'; import { localServerReady } from '../launch/local-server.ts'; import { fileInfo } from './change-copy-files.ts'; -import { compactCopy, convertibleCopy, isNewer, readSource, repair, updateFromSource, updatePreservesSpaceSaving, type Report } from './copy-file-maintenance.ts'; +import { compactCopy, convertibleCopy, isNewer, repair, updateFromSource, updatePreservesSpaceSaving, type Report } from './copy-file-maintenance.ts'; +import { readSource, setCopySource } from './copy-source.ts'; let current: { stop: AbortController; @@ -92,6 +93,8 @@ export async function maintainCopy( async function performMaintenance(request: MaintenanceRequest, signal: AbortSignal, report: Report): Promise { const { id, operation, steamLocations } = request; const record = await requireCopy(id); + if (operation === 'set-source') return setCopySource(record, request.sourcePath); + const root = await checkedRoot(record); const dataPath = await canonicalCopyPath(record.dataPath); const needsConfirmation = steamLibraryNeedsConfirmation(record, root, dataPath); diff --git a/apps/launcher/src/main/services/copies/copy-source.ts b/apps/launcher/src/main/services/copies/copy-source.ts new file mode 100644 index 0000000..21e3085 --- /dev/null +++ b/apps/launcher/src/main/services/copies/copy-source.ts @@ -0,0 +1,52 @@ +import { isAbsolute, join } from 'node:path'; +import { AppError } from '@shared/errors.ts'; +import type { Copies, GameFolderInspection, InstallRecord } from '@shared/schemas/install.ts'; +import { inspectGameFolder } from '../game-folder/inspect-game-folder.ts'; +import { canonicalCopyPath, copyPathContains, updateCopyRecord } from '../install/install-record.ts'; +import { fileInfo } from './change-copy-files.ts'; + +export async function readSource(record: InstallRecord): Promise { + if (!record.sourcePath) return null; + try { + return await inspectSource(record, record.sourcePath); + } catch (error) { + if (error instanceof AppError) return null; + throw error; + } +} + +export async function setCopySource(record: InstallRecord, path: string | undefined): Promise { + const source = await inspectSource(record, path); + return updateCopyRecord(record.id, (latest) => { + if (latest.copyPath !== record.copyPath || latest.dataPath !== record.dataPath) { + throw new AppError('maintenance_location'); + } + return { ...latest, sourcePath: source.resolvedPath }; + }); +} + +async function inspectSource(record: InstallRecord, path: string | undefined): Promise { + if (!path || !isAbsolute(path)) throw new AppError('maintenance_source_invalid'); + const [game, copyPath, dataPath] = await Promise.all([ + inspectGameFolder(path), canonicalCopyPath(record.copyPath), canonicalCopyPath(record.dataPath), + ]); + const source = game.resolvedPath; + const overlapsCopy = copyPathContains(source, copyPath) || copyPathContains(copyPath, source); + if (overlapsCopy || copyPathContains(source, dataPath)) { + throw new AppError('maintenance_source_overlap'); + } + if (game.missingFiles.length || !game.version || game.hasOfflineBackup || game.needsStockSource) { + throw new AppError('maintenance_source_invalid'); + } + + // Verify that the directory has game resources beyond the four files used for patching. + const [content, languages, missions] = await Promise.all([ + fileInfo(join(source, 'content')), + fileInfo(join(source, 'lang.vromfs.bin')), + fileInfo(join(source, 'mis.vromfs.bin')), + ]); + if (!content?.isDirectory() || !languages?.isFile() || !missions?.isFile()) { + throw new AppError('maintenance_source_invalid'); + } + return { ...game, path: source }; +} diff --git a/apps/launcher/src/renderer/src/i18n/locales/en.json b/apps/launcher/src/renderer/src/i18n/locales/en.json index e5662a9..26b69ff 100644 --- a/apps/launcher/src/renderer/src/i18n/locales/en.json +++ b/apps/launcher/src/renderer/src/i18n/locales/en.json @@ -239,6 +239,10 @@ "maintenance": { "update": "Update from online installation", "updateAction": "Update client", + "setSource": "Set source…", + "changeSource": "Change source…", + "chooseSource": "Choose the online installation folder", + "sourceNotSet": "No online installation source is configured.", "newVersion": "Version {{version}} is available from the installation source.", "updateKeepsSpaceSaving": "Version {{version}} is available. Updating continues sharing read-only resource archives with the source.", "updateDetaches": "Version {{version}} is available. Because the client and source are on different volumes, updating copies shared resources into independent files and requires additional space.", @@ -271,6 +275,7 @@ }, "result": { "confirm-steam": "Steam locations confirmed.", + "set-source": "Online installation source saved.", "check": "Patch check complete.", "repair": "Original files restored.", "update": "Client updated.", @@ -819,6 +824,8 @@ "maintenance_busy": "Maintenance requires the game, local server and other client operations to be stopped.", "maintenance_location": "The operation would affect files outside the registered client or data folder.", "maintenance_no_update": "A newer version is unavailable at the installation source.", + "maintenance_source_invalid": "Choose a complete online game installation folder.", + "maintenance_source_overlap": "The online installation source must be separate from the offline client and its data folder.", "maintenance_cancelled": "The client update was cancelled.", "maintenance_failed": "Client maintenance failed. See the launcher log.", "maintenance_source_changed": "The installation source changed during the update. Retry once its update is complete.", diff --git a/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json b/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json index 17ced17..d32c09a 100644 --- a/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json +++ b/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json @@ -239,6 +239,10 @@ "maintenance": { "update": "从在线版更新", "updateAction": "更新客户端", + "setSource": "设置来源…", + "changeSource": "更换来源…", + "chooseSource": "选择在线版安装目录", + "sourceNotSet": "尚未设置在线版安装来源。", "newVersion": "安装来源已更新至 {{version}}。", "updateKeepsSpaceSaving": "安装来源中有新版本 {{version}}。更新时会继续与原版共用只读资源包。", "updateDetaches": "安装来源中有新版本 {{version}}。当前与安装来源不在同一磁盘卷,更新会把共享资源复制为独立文件,需要额外空间。", @@ -271,6 +275,7 @@ }, "result": { "confirm-steam": "已确认 Steam 目录。", + "set-source": "在线版安装来源已保存。", "check": "补丁检查已完成。", "repair": "原版文件已还原。", "update": "客户端已更新。", @@ -819,6 +824,8 @@ "maintenance_busy": "维护前需结束游戏、本地服务器和其他客户端操作。", "maintenance_location": "操作会影响登记的客户端或数据目录之外的文件。", "maintenance_no_update": "安装来源没有可用的新版本。", + "maintenance_source_invalid": "请选择完整的在线版游戏安装目录。", + "maintenance_source_overlap": "在线版安装来源必须与离线客户端和数据目录分开。", "maintenance_cancelled": "客户端更新已取消。", "maintenance_failed": "客户端维护失败。请查看启动器日志。", "maintenance_source_changed": "安装来源在更新过程中发生变化。请在在线版更新完成后重试。", diff --git a/apps/launcher/src/renderer/src/pages/copies/CopyMaintenance.tsx b/apps/launcher/src/renderer/src/pages/copies/CopyMaintenance.tsx index 6cc4ab5..5bb637a 100644 --- a/apps/launcher/src/renderer/src/pages/copies/CopyMaintenance.tsx +++ b/apps/launcher/src/renderer/src/pages/copies/CopyMaintenance.tsx @@ -22,17 +22,24 @@ export function CopyMaintenance({ record, maintenance, onError }: CopyMaintenanc useEffect(() => { let mounted = true; + setInfo(null); ipcInvoke('copies:maintenanceInfo', { id: record.id }).then((value) => { if (mounted) setInfo(value); }).catch(onError); return () => { mounted = false; }; - }, [record.id, record.gameVersion, record.steamLibraryConfirmation, maintenance.revision, onError]); + }, [record.id, record.gameVersion, record.sourcePath, record.steamLibraryConfirmation, maintenance.revision, onError]); const run = (operation: MaintenanceOperation, options: MaintenanceOptions = {}): void => { if (operation === 'delete') setRemoval(null); maintenance.run(record.id, operation, options); }; + const chooseUpdateSource = (): void => { + ipcInvoke('dialog:pickFolder', { title: t('copies.maintenance.chooseSource') }).then(({ path }) => { + if (path) run('set-source', { sourcePath: path }); + }).catch(onError); + }; + const active = maintenance.active; const busy = active !== null; const result = maintenance.lastResult?.copyId === record.id ? maintenance.lastResult.outcome : null; @@ -44,6 +51,7 @@ export function CopyMaintenance({ record, maintenance, onError }: CopyMaintenanc info={info} busy={busy} onRun={run} + onChooseSource={chooseUpdateSource} onConfirmSteam={(steamLocations) => run('confirm-steam', { steamLocations })} /> void; + readonly onChooseSource: () => void; readonly onConfirmSteam: (locations: NonNullable) => void; } -export function CopyMaintenanceActions({ record, info, busy, onRun, onConfirmSteam }: CopyMaintenanceActionsProps) { +export function CopyMaintenanceActions({ record, info, busy, onRun, onChooseSource, onConfirmSteam }: CopyMaintenanceActionsProps) { const { t, i18n } = useTranslation(); const steam = info?.steamLocations; + const updateHint = info?.sourceVersion + ? t(info.updateAvailable + ? (record.hardlinkedFiles?.length + ? (info.updatePreservesSpaceSaving ? 'copies.maintenance.updateKeepsSpaceSaving' : 'copies.maintenance.updateDetaches') + : 'copies.maintenance.newVersion') + : 'copies.maintenance.currentVersion', { version: info.sourceVersion }) + : t(record.sourcePath ? (info ? 'copies.maintenance.noSource' : 'copies.maintenance.phase.checking') : 'copies.maintenance.sourceNotSet'); return ( <> {info?.steamConfirmationRequired && steam && ( @@ -30,13 +38,10 @@ export function CopyMaintenanceActions({ record, info, busy, onRun, onConfirmSte )} - + {record.sourcePath}
{updateHint} : updateHint}> +