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.
This commit is contained in:
1 parent
a2fdcc1f15
commit
1d3e47b082
11 files changed
+99
-24
No files matched your search
@@ -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<GameFolderInspection | null> {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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<Copies> {
|
||||
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);
|
||||
|
||||
@@ -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<GameFolderInspection | null> {
|
||||
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<Copies> {
|
||||
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<GameFolderInspection> {
|
||||
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 };
|
||||
}
|
||||
@@ -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.",
|
||||
|
||||
@@ -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": "安装来源在更新过程中发生变化。请在在线版更新完成后重试。",
|
||||
|
||||
@@ -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 })}
|
||||
/>
|
||||
<CopyRemoval
|
||||
|
||||
@@ -12,12 +12,20 @@ interface CopyMaintenanceControlsProps {
|
||||
|
||||
interface CopyMaintenanceActionsProps extends CopyMaintenanceControlsProps {
|
||||
readonly onRun: (operation: 'update' | 'compact' | 'check' | 'repair') => void;
|
||||
readonly onChooseSource: () => void;
|
||||
readonly onConfirmSteam: (locations: NonNullable<MaintenanceRequest['steamLocations']>) => 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
|
||||
</button>
|
||||
</Notice>
|
||||
)}
|
||||
<Row label={t('copies.maintenance.update')} hint={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('copies.maintenance.noSource')}>
|
||||
<Row label={t('copies.maintenance.update')} hint={record.sourcePath ? <>{record.sourcePath}<br />{updateHint}</> : updateHint}>
|
||||
<button type="button" className="button" disabled={busy} onClick={onChooseSource}>
|
||||
{t(record.sourcePath ? 'copies.maintenance.changeSource' : 'copies.maintenance.setSource')}
|
||||
</button>
|
||||
<button type="button" className={info?.updateAvailable ? 'button button-primary' : 'button'}
|
||||
disabled={busy || !info?.updateAvailable} onClick={() => onRun('update')}>
|
||||
{t('copies.maintenance.updateAction')}
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { MaintenanceProgress, MaintenanceRequest } from '@shared/schemas/ma
|
||||
import { AppIpcError, ipcInvoke, ipcOn } from '../../ipc.ts';
|
||||
|
||||
export type MaintenanceOperation = MaintenanceRequest['operation'];
|
||||
export type MaintenanceOptions = Pick<IpcInput<'copies:maintain'>, 'deleteData' | 'steamLocations'>;
|
||||
export type MaintenanceOptions = Pick<IpcInput<'copies:maintain'>, 'deleteData' | 'steamLocations' | 'sourcePath'>;
|
||||
|
||||
export interface MaintenanceOutcome {
|
||||
readonly copyId: string;
|
||||
|
||||
@@ -45,6 +45,8 @@ export const APP_ERROR_CODES = [
|
||||
'maintenance_busy',
|
||||
'maintenance_location',
|
||||
'maintenance_no_update',
|
||||
'maintenance_source_invalid',
|
||||
'maintenance_source_overlap',
|
||||
'maintenance_cancelled',
|
||||
'maintenance_failed',
|
||||
'maintenance_source_changed',
|
||||
|
||||
@@ -150,7 +150,7 @@ export type InstallProgress = z.output<typeof InstallProgressSchema>;
|
||||
export const InstallRecordSchema = z.object({
|
||||
id: CopyIdSchema,
|
||||
name: CopyNameSchema,
|
||||
/** Recorded only for a separate source copied during installation. */
|
||||
/** Separate online installation used as the read-only update source. */
|
||||
sourcePath: z.string().min(1).nullable(),
|
||||
method: z.enum(INSTALL_METHODS),
|
||||
copyPath: z.string(),
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { z } from 'zod';
|
||||
import { CopyIdSchema } from './install.ts';
|
||||
|
||||
export const MaintenanceOperationSchema = z.enum(['check', 'repair', 'update', 'compact', 'delete', 'confirm-steam']);
|
||||
export const MaintenanceOperationSchema = z.enum(['check', 'repair', 'update', 'compact', 'delete', 'confirm-steam', 'set-source']);
|
||||
export const MaintenanceRequestSchema = z.object({
|
||||
id: CopyIdSchema,
|
||||
operation: MaintenanceOperationSchema,
|
||||
deleteData: z.boolean().default(false),
|
||||
sourcePath: z.string().min(1).optional(),
|
||||
steamLocations: z.object({
|
||||
copyPath: z.string().min(1),
|
||||
dataPath: z.string().min(1),
|
||||
|
||||
Reference in new issue
Block a user