fix(launcher): detect stale stock backups and distinguish missing backups on launch
Read the live executable version in inspectGameFolder instead of masking externally updated folders behind an older wtoffline/stock backup, and atomically refresh stale or unreadable backups during install, external stock import, and relocation. Log exact copy/stock/recorded versions on launch mismatches and report a dedicated launch_stock_missing error when wtoffline/stock/win64/aces.exe is missing or unreadable. Checked: root typecheck, launcher typecheck, zh-CN/en locale key parity (616/616), and launcher electron-vite build.
This commit is contained in:
1 parent
f3d04d137f
commit
c55ec4ed57
8 files changed
+67
-22
No files matched your search
@@ -2,7 +2,7 @@ import { AppError } from '@shared/errors.ts';
|
||||
import type { Copies } from '@shared/schemas/install.ts';
|
||||
import { inspectGameFolder } from '../game-folder/inspect-game-folder.ts';
|
||||
import { hydrateCopiesStatus, relocateCopyRecord } from '../install/install-record.ts';
|
||||
import { backUpStockFiles } from '../install/stock-backup.ts';
|
||||
import { backUpStockFiles, installStockSource, refreshStockBackup } from '../install/stock-backup.ts';
|
||||
|
||||
/**
|
||||
* Re-point an existing registered client to its moved folder while keeping its id, name, saves,
|
||||
@@ -12,7 +12,10 @@ export async function relocateCopy(id: string, newPath: string): Promise<Copies>
|
||||
const game = await inspectGameFolder(newPath);
|
||||
if (game.missingFiles.length) throw new AppError('not_a_game_folder', { path: newPath });
|
||||
if (game.needsStockSource) throw new AppError('stock_source_invalid');
|
||||
const stockBackupPath = await backUpStockFiles(game.resolvedPath);
|
||||
const stock = await installStockSource(game.resolvedPath, game.version);
|
||||
const stockBackupPath = stock.refresh
|
||||
? await refreshStockBackup(game.resolvedPath)
|
||||
: await backUpStockFiles(game.resolvedPath);
|
||||
const updated = await relocateCopyRecord(id, {
|
||||
copyPath: newPath,
|
||||
stockBackupPath,
|
||||
|
||||
@@ -23,28 +23,43 @@ export async function inspectGameFolder(path: string): Promise<GameFolderInspect
|
||||
if (!(await exists(join(resolved, file)))) missingFiles.push(file);
|
||||
}
|
||||
const stockRoot = join(resolved, STOCK_BACKUP_FOLDER);
|
||||
let hasOfflineBackup = true;
|
||||
let hasStockFiles = true;
|
||||
for (const file of required) {
|
||||
if (!(await exists(join(stockRoot, file)))) {
|
||||
hasOfflineBackup = false;
|
||||
hasStockFiles = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
const resources = resourcePaths();
|
||||
const executablePath = hasOfflineBackup
|
||||
? join(stockRoot, GAME_FILES.executable)
|
||||
: join(resolved, GAME_FILES.executable);
|
||||
const executableBytes = (!hasOfflineBackup && missingFiles.includes(GAME_FILES.executable))
|
||||
const liveExeBytes = missingFiles.includes(GAME_FILES.executable)
|
||||
? null
|
||||
: await readBytes(executablePath);
|
||||
const version = executableBytes ? readVersionFromBytes(executableBytes) : null;
|
||||
: await readBytes(join(resolved, GAME_FILES.executable));
|
||||
const liveVersion = liveExeBytes ? readVersionFromBytes(liveExeBytes) : null;
|
||||
const backupExeBytes = hasStockFiles
|
||||
? await readBytes(join(stockRoot, GAME_FILES.executable))
|
||||
: null;
|
||||
const backupVersion = backupExeBytes ? readVersionFromBytes(backupExeBytes) : null;
|
||||
|
||||
// Always report the live executable's version when readable so an externally updated client
|
||||
// (for example, an in-place folder updated by the official launcher) is never masked by a stale
|
||||
// wtoffline/stock backup.
|
||||
const version = liveVersion ?? backupVersion;
|
||||
const hasOfflineBackup = hasStockFiles && backupVersion !== null && (liveVersion === null || backupVersion === liveVersion);
|
||||
const liveExePatched = liveExeBytes !== null && liveExeBytes.includes(PATCHED_EXE_MARKER);
|
||||
|
||||
let needsStockSource = false;
|
||||
if (!hasOfflineBackup && missingFiles.length === 0) {
|
||||
const exeDir = join(resolved, dirname(GAME_FILES.executable));
|
||||
const hasMarkerFile = (await Promise.all(
|
||||
PATCH_MARKER_FILES.map((file) => exists(join(exeDir, file))),
|
||||
)).some(Boolean);
|
||||
needsStockSource = hasMarkerFile || (executableBytes !== null && executableBytes.includes(PATCHED_EXE_MARKER));
|
||||
if (hasStockFiles && backupVersion !== null && liveVersion !== null && backupVersion !== liveVersion) {
|
||||
// A stale stock backup only needs an external stock source if the live executable is already
|
||||
// patched; an unpatched live executable can refresh wtoffline/stock directly during install.
|
||||
needsStockSource = liveExePatched;
|
||||
} else {
|
||||
const exeDir = join(resolved, dirname(GAME_FILES.executable));
|
||||
const hasMarkerFile = (await Promise.all(
|
||||
PATCH_MARKER_FILES.map((file) => exists(join(exeDir, file))),
|
||||
)).some(Boolean);
|
||||
needsStockSource = hasMarkerFile || liveExePatched;
|
||||
}
|
||||
}
|
||||
return {
|
||||
path,
|
||||
|
||||
@@ -12,7 +12,7 @@ import { discardDecalCache, importDecalCache } from './decals.ts';
|
||||
import { hardlinkResource, hasHardlinkEvidence, verifyHardlinkResource } from './hardlink-files.ts';
|
||||
import { canonicalCopyPath, copyPathContains, requireAvailableCopy, writeInstallRecord } from './install-record.ts';
|
||||
import { checkPatches } from './patch-check.ts';
|
||||
import { backUpStockFiles, backUpStockFilesFrom, installStockSource, refreshStockBackup, requireStockBackupLocation, stockBackupPath } from './stock-backup.ts';
|
||||
import { backUpStockFiles, installStockSource, refreshStockBackup, refreshStockBackupFrom, requireStockBackupLocation, stockBackupPath } from './stock-backup.ts';
|
||||
|
||||
/**
|
||||
* Install the offline version: check the patches against the player's game,
|
||||
@@ -95,7 +95,7 @@ async function install(request: InstallRequest, signal: AbortSignal, report: (pr
|
||||
|
||||
report({ phase: 'backing-up', doneBytes: 0, totalBytes: 0, doneFiles: 0, totalFiles: 0 });
|
||||
const stockBackup = externalStockPath
|
||||
? await backUpStockFilesFrom(copyPath, externalStockPath)
|
||||
? await refreshStockBackupFrom(copyPath, externalStockPath)
|
||||
: (request.method === 'in-place' || request.method === 'existing') && stock.refresh
|
||||
? await refreshStockBackup(copyPath)
|
||||
: await backUpStockFiles(copyPath);
|
||||
|
||||
@@ -50,22 +50,36 @@ export async function backUpStockFilesFrom(copyFolder: string, sourceFolder: str
|
||||
return backup;
|
||||
}
|
||||
|
||||
/** A new game version must pass the patch checks before replacing an existing stock backup. */
|
||||
/** A new game version or damaged backup must pass the patch checks before replacing wtoffline/stock. */
|
||||
export async function installStockSource(copyFolder: string, version: string | null) {
|
||||
const backup = await requireStockBackupLocation(copyFolder);
|
||||
if (!await exists(join(backup, GAME_FILES.executable))) return { path: copyFolder, refresh: await exists(backup) };
|
||||
const backedUpVersion = executableVersion(await readFile(join(backup, GAME_FILES.executable)));
|
||||
return version !== null && backedUpVersion !== version ? { path: copyFolder, refresh: true } : { path: backup, refresh: false };
|
||||
const backupExe = join(backup, GAME_FILES.executable);
|
||||
if (!await exists(backupExe)) return { path: copyFolder, refresh: await exists(backup) };
|
||||
let backedUpVersion: string | null = null;
|
||||
try {
|
||||
backedUpVersion = executableVersion(await readFile(backupExe));
|
||||
} catch (error) {
|
||||
console.warn('[stock-backup] unreadable backed-up executable, will refresh:', backupExe, error);
|
||||
return { path: copyFolder, refresh: true };
|
||||
}
|
||||
return backedUpVersion === null || (version !== null && backedUpVersion !== version)
|
||||
? { path: copyFolder, refresh: true }
|
||||
: { path: backup, refresh: false };
|
||||
}
|
||||
|
||||
export async function refreshStockBackup(copyFolder: string): Promise<string> {
|
||||
return refreshStockBackupFrom(copyFolder, copyFolder);
|
||||
}
|
||||
|
||||
/** Replace wtoffline/stock atomically with the four stock files from `sourceFolder`. */
|
||||
export async function refreshStockBackupFrom(copyFolder: string, sourceFolder: string): Promise<string> {
|
||||
const backup = await requireStockBackupLocation(copyFolder);
|
||||
return await changeCopyFiles(copyFolder, async (incoming) => {
|
||||
const replace = Object.values(GAME_FILES).map((file) => join(STOCK_BACKUP_FOLDER, file));
|
||||
for (const file of Object.values(GAME_FILES)) {
|
||||
const target = join(incoming, STOCK_BACKUP_FOLDER, file);
|
||||
await mkdir(dirname(target), { recursive: true });
|
||||
await copyFile(join(copyFolder, file), target);
|
||||
await copyFile(join(sourceFolder, file), target);
|
||||
}
|
||||
return { replace, remove: [] };
|
||||
}, async () => backup);
|
||||
|
||||
@@ -144,6 +144,10 @@ async function planLaunch(job: LaunchJob, record: InstallRecord, settings: Setti
|
||||
}
|
||||
const currentVersion = await readVersion(record.copyPath, signal);
|
||||
if (!currentVersion || currentVersion !== record.gameVersion) {
|
||||
console.warn(
|
||||
`[launch] client version changed: recorded=${record.gameVersion ?? 'unknown'}, ` +
|
||||
`actual=${currentVersion ?? 'missing'} (${record.copyPath})`,
|
||||
);
|
||||
update(job, { phase: 'version-changed', actualVersion: currentVersion });
|
||||
return null;
|
||||
}
|
||||
@@ -171,6 +175,11 @@ async function planLaunch(job: LaunchJob, record: InstallRecord, settings: Setti
|
||||
]);
|
||||
signal.throwIfAborted();
|
||||
if (!copyVersion || copyVersion !== stockVersion) {
|
||||
console.warn(
|
||||
`[launch] copy/stock version mismatch: copy=${copyVersion ?? 'missing'} (${copyPath}), ` +
|
||||
`stock=${stockVersion ?? 'missing'} (${stockPath})`,
|
||||
);
|
||||
if (!lab && !stockVersion) throw new AppError('launch_stock_missing');
|
||||
throw new AppError(lab ? 'launch_lab_version' : 'launch_stock_version');
|
||||
}
|
||||
if (games) throw new AppError('launch_game_running');
|
||||
|
||||
@@ -706,6 +706,7 @@
|
||||
"launch_steam_confirmation_required": "Confirm the Steam locations in Client Maintenance before launching.",
|
||||
"launch_location": "The client, stock backup, or data folder location is invalid.",
|
||||
"launch_stock_version": "The stock backup and client versions do not match.",
|
||||
"launch_stock_missing": "The original file backup (wtoffline\\stock) is missing or unreadable. Check your security software, or remove this client entry and add it again.",
|
||||
"launch_build_failed": "The game files could not be generated.",
|
||||
"launch_build_unavailable": "The build found unavailable patches that require review.",
|
||||
"launch_port_busy": "The local server port is already in use.",
|
||||
|
||||
@@ -706,6 +706,7 @@
|
||||
"launch_steam_confirmation_required": "请在客户端维护中确认 Steam 目录后再启动。",
|
||||
"launch_location": "客户端、原版文件备份或数据目录的位置无效。",
|
||||
"launch_stock_version": "原版文件备份的版本与客户端不一致。",
|
||||
"launch_stock_missing": "缺少或无法读取原版文件备份(wtoffline\\stock)。请检查安全软件拦截记录,或移除此客户端登记后重新添加。",
|
||||
"launch_build_failed": "无法生成游戏文件。",
|
||||
"launch_build_unavailable": "生成游戏文件时发现需要重新确认的不可用补丁。",
|
||||
"launch_port_busy": "本地服务器端口已被占用。",
|
||||
|
||||
@@ -59,6 +59,8 @@ export const APP_ERROR_CODES = [
|
||||
'launch_steam_confirmation_required',
|
||||
'launch_location',
|
||||
'launch_stock_version',
|
||||
/** The wtoffline/stock backup executable is missing or unreadable before launch. */
|
||||
'launch_stock_missing',
|
||||
'launch_build_failed',
|
||||
'launch_build_unavailable',
|
||||
'launch_port_busy',
|
||||
|
||||
Reference in new issue
Block a user