feat(launcher): prompt for stock source when adding patched client without backup

This commit is contained in:
N0VAN0M4LY committed 2026-11-30 20:59:38 +08:00
1 parent 39228c6e75
commit bfedc3d27e
13 files changed
+195 -41

No files matched your search

@@ -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, installStockSource, refreshStockBackup, requireStockBackupLocation, stockBackupPath } from './stock-backup.ts';
import { backUpStockFiles, backUpStockFilesFrom, installStockSource, refreshStockBackup, requireStockBackupLocation, stockBackupPath } from './stock-backup.ts';
/**
* Install the offline version: check the patches against the player's game,
@@ -57,19 +57,25 @@ export function cancelInstall(): boolean {
}
/** Which patches fit the game in `gameFolder`, for the window to show before installing. */
export async function checkGameFolder(gameFolder: string, dataPath: string): Promise<PatchCheck> {
const { resolvedPath, version } = await requireGameFolder(gameFolder);
const stock = await installStockSource(resolvedPath, version);
export async function checkGameFolder(gameFolder: string, dataPath: string, stockSourcePath?: string): Promise<PatchCheck> {
const game = await requireGameFolder(gameFolder);
const stock = stockSourcePath
? await resolveExternalStockSource(stockSourcePath, game.version)
: game.needsStockSource
? (() => { throw new AppError('stock_source_invalid'); })()
: await installStockSource(game.resolvedPath, game.version);
const data = await canonicalCopyPath(dataPath);
await requireUnredirectedData(data);
return checkPatches(stock.path, data);
}
async function install(request: InstallRequest, signal: AbortSignal, report: (progress: InstallProgress) => void): Promise<InstallRecord> {
const { version, requestedCopyPath, copyPath, dataPath, sourcePath, target, useHardLinks, copyInSteam, dataInSteam } =
const { version, requestedCopyPath, copyPath, dataPath, sourcePath, externalStockPath, target, useHardLinks, copyInSteam, dataInSteam } =
await inspectInstallation(request);
report({ phase: 'checking', doneBytes: 0, totalBytes: 0, doneFiles: 0, totalFiles: 0 });
const stock = await installStockSource(sourcePath, version);
const stock = externalStockPath
? { path: externalStockPath, refresh: false }
: await installStockSource(sourcePath, version);
await mkdir(dataPath, { recursive: true });
const check = await checkPatches(stock.path, dataPath);
const essential = check.unavailable.filter((patch) => patch.essential);
@@ -88,9 +94,11 @@ async function install(request: InstallRequest, signal: AbortSignal, report: (pr
: undefined;
report({ phase: 'backing-up', doneBytes: 0, totalBytes: 0, doneFiles: 0, totalFiles: 0 });
const stockBackup = (request.method === 'in-place' || request.method === 'existing') && stock.refresh
? await refreshStockBackup(copyPath)
: await backUpStockFiles(copyPath);
const stockBackup = externalStockPath
? await backUpStockFilesFrom(copyPath, externalStockPath)
: (request.method === 'in-place' || request.method === 'existing') && stock.refresh
? await refreshStockBackup(copyPath)
: await backUpStockFiles(copyPath);
report({ phase: 'recording', doneBytes: 0, totalBytes: 0, doneFiles: 0, totalFiles: 0 });
const record: InstallRecord = {
@@ -120,13 +128,22 @@ async function install(request: InstallRequest, signal: AbortSignal, report: (pr
async function inspectInstallation(request: InstallRequest) {
const gameFolder = request.method === 'copy' ? request.sourcePath : request.gamePath;
const game = await requireGameFolder(gameFolder);
let externalStockPath: string | null = null;
if (request.method === 'copy') {
if (game.needsStockSource) throw new AppError('stock_source_invalid');
} else if (request.stockSourcePath) {
externalStockPath = (await resolveExternalStockSource(request.stockSourcePath, game.version)).path;
} else if (game.needsStockSource) {
throw new AppError('stock_source_invalid');
}
const requestedCopyPath = request.method === 'copy' ? request.copyPath : request.gamePath;
const [copyPath, dataPath, sourcePath] = await Promise.all([
canonicalCopyPath(requestedCopyPath), canonicalCopyPath(request.dataPath), canonicalCopyPath(gameFolder),
]);
await requireAvailableCopy(request.id, copyPath, dataPath);
if (!isAbsolute(request.dataPath) || copyPathContains(stockBackupPath(copyPath), dataPath) ||
(request.method === 'copy' && copyPathContains(sourcePath, dataPath))) {
(request.method === 'copy' && copyPathContains(sourcePath, dataPath)) ||
(externalStockPath && copyPathContains(externalStockPath, dataPath))) {
throw new AppError('target_not_usable', { problem: 'overlaps_stock' });
}
@@ -145,7 +162,16 @@ async function inspectInstallation(request: InstallRequest) {
throw new AppError('steam_library_not_confirmed');
}
await Promise.all([requireStockBackupLocation(copyPath), requireUnredirectedData(dataPath)]);
return { version: game.version, requestedCopyPath, copyPath, dataPath, sourcePath, target, useHardLinks, copyInSteam, dataInSteam };
return { version: game.version, requestedCopyPath, copyPath, dataPath, sourcePath, externalStockPath, target, useHardLinks, copyInSteam, dataInSteam };
}
async function resolveExternalStockSource(stockSourcePath: string, expectedVersion: string | null) {
const stockGame = await requireGameFolder(stockSourcePath);
if (stockGame.needsStockSource) throw new AppError('stock_source_invalid');
if (expectedVersion !== null && stockGame.version !== null && expectedVersion !== stockGame.version) {
throw new AppError('stock_source_version_mismatch', { expected: expectedVersion, actual: stockGame.version });
}
return installStockSource(stockGame.resolvedPath, stockGame.version);
}
async function copyGame(