fix(copies): honor confirmed Steam locations
Bind confirmation to the selected copy and data paths throughout installation, launch, and maintenance. Validate redirected runtime data paths and recheck original files before refreshing an in-place backup. Verified by type checking and build. The acceptance checklist covers directory links and Steam confirmation.
This commit is contained in:
1 parent
84158f719d
commit
5a78b1fdf8
28 files changed
+813
-459
No files matched your search
@@ -5,15 +5,17 @@ import { app, BrowserWindow, shell } from 'electron';
|
||||
import { AccountStore, LOOPBACK } from '@wto/server';
|
||||
import { executableVersion, GAME_FILES, isInSteamLibrary } from '@wto/patcher';
|
||||
import { AppError } from '@shared/errors.ts';
|
||||
import type { InstallRecord } from '@shared/schemas/install.ts';
|
||||
import type { GameExit, LaunchState } from '@shared/schemas/launch.ts';
|
||||
import type { Settings } from '@shared/schemas/settings.ts';
|
||||
import { getSettings } from '../config/settings-store.ts';
|
||||
import { decalCachePath } from '../install/decals.ts';
|
||||
import { copyPathContains, readInstallRecord } from '../install/install-record.ts';
|
||||
import { canonicalCopyPath, copyPathContains, readInstallRecord } from '../install/install-record.ts';
|
||||
import { resourcePaths } from '../resources/resource-paths.ts';
|
||||
import { saveBackup } from '../saves/save-archive.ts';
|
||||
import { buildCopy } from './build-copy.ts';
|
||||
import { gameProcessRunning } from './game-process.ts';
|
||||
import { readInstalledLab, runLab } from './lab-handoff.ts';
|
||||
import { readInstalledLab, runLab, type Lab } from './lab-handoff.ts';
|
||||
import { localServerStatusUrl } from './local-server.ts';
|
||||
import { ordinaryLaunchPaths, runOrdinaryLaunch } from './ordinary-launch.ts';
|
||||
|
||||
@@ -104,61 +106,10 @@ async function launch(job: LaunchJob): Promise<void> {
|
||||
const [record, settings] = await Promise.all([readInstallRecord(), getSettings()]);
|
||||
if (!record) throw new AppError('launch_no_copy');
|
||||
job.copyId = record.id;
|
||||
const useLab = !app.isPackaged && settings.developerMode;
|
||||
if (isInSteamLibrary(record.copyPath)) throw new AppError('launch_copy_in_steam');
|
||||
const currentVersion = await readVersion(record.copyPath, signal);
|
||||
if (!currentVersion || currentVersion !== record.gameVersion) {
|
||||
update(job, { phase: 'version-changed', actualVersion: currentVersion });
|
||||
return;
|
||||
}
|
||||
|
||||
const lab = useLab ? await readInstalledLab() : null;
|
||||
const { copyPath, stockPath, dataPath } = lab ? {
|
||||
copyPath: lab.copyPath,
|
||||
stockPath: settings.labStockPath ?? record.stockBackupPath,
|
||||
dataPath: settings.labDataPath ?? record.dataPath,
|
||||
} : await ordinaryLaunchPaths(record);
|
||||
if (!isAbsolute(stockPath) || !isAbsolute(dataPath)) {
|
||||
throw new AppError('folder_unreadable', { path: !isAbsolute(stockPath) ? stockPath : dataPath });
|
||||
}
|
||||
if (isInSteamLibrary(dataPath) || copyPathContains(stockPath, dataPath)) {
|
||||
throw new AppError('launch_copy_in_steam');
|
||||
}
|
||||
const requestedPort = lab?.port ?? (settings.launchPortMode === 'fixed' ? settings.launchPort : 0);
|
||||
if (requestedPort) update(job, { phase: 'checking', port: requestedPort });
|
||||
const [copyVersion, stockVersion, games] = await Promise.all([
|
||||
lab ? readVersion(copyPath, signal) : currentVersion,
|
||||
readVersion(stockPath, signal),
|
||||
gameProcessRunning(signal),
|
||||
]);
|
||||
signal.throwIfAborted();
|
||||
if (!copyVersion || copyVersion !== stockVersion) {
|
||||
throw new AppError(lab ? 'launch_lab_version' : 'launch_stock_version');
|
||||
}
|
||||
if (games) throw new AppError('launch_game_running');
|
||||
const port = await selectPort(requestedPort);
|
||||
if (settings.autoSaveBackups) {
|
||||
for (const { userId } of new AccountStore(dataPath).all()) {
|
||||
signal.throwIfAborted();
|
||||
await saveBackup({ ...record, dataPath }, userId, 'launch');
|
||||
}
|
||||
}
|
||||
signal.throwIfAborted();
|
||||
update(job, { phase: 'building', port });
|
||||
await buildCopy({
|
||||
kind: 'build',
|
||||
stockPath,
|
||||
copyPath,
|
||||
dataPath,
|
||||
port,
|
||||
...resourcePaths(),
|
||||
...(record.decalCacheId ? { decalCache: decalCachePath(record.dataPath, record.decalCacheId) } : {}),
|
||||
acceptedUnavailable: record.unavailablePatches.map(({ patchId }) => patchId),
|
||||
}, signal, (filesWritten, filesTotal, file) => {
|
||||
if (!signal.aborted) update(job, {
|
||||
phase: 'building', port, filesWritten, filesTotal, ...(file === undefined ? {} : { file }),
|
||||
});
|
||||
});
|
||||
const plan = await planLaunch(job, record, settings);
|
||||
if (plan === null) return;
|
||||
const { lab, copyPath, stockPath, dataPath, port } = plan;
|
||||
await buildForLaunch(job, record, plan, settings.autoSaveBackups);
|
||||
|
||||
const publish = (phase: LaunchState['phase'], gameExit?: GameExit): void => {
|
||||
if (signal.aborted) return;
|
||||
@@ -176,6 +127,85 @@ async function launch(job: LaunchJob): Promise<void> {
|
||||
update(job, { phase: 'game-exited', gameExit });
|
||||
}
|
||||
|
||||
interface LaunchPlan {
|
||||
readonly lab: Lab | null;
|
||||
readonly copyPath: string;
|
||||
readonly stockPath: string;
|
||||
readonly dataPath: string;
|
||||
readonly steamLibraryConfirmed: boolean;
|
||||
readonly port: number;
|
||||
}
|
||||
|
||||
async function planLaunch(job: LaunchJob, record: InstallRecord, settings: Settings): Promise<LaunchPlan | null> {
|
||||
const signal = job.stop.signal;
|
||||
const useLab = !app.isPackaged && settings.developerMode;
|
||||
if (useLab && (isInSteamLibrary(record.copyPath) || isInSteamLibrary(await canonicalCopyPath(record.copyPath)))) {
|
||||
throw new AppError('launch_copy_in_steam');
|
||||
}
|
||||
const currentVersion = await readVersion(record.copyPath, signal);
|
||||
if (!currentVersion || currentVersion !== record.gameVersion) {
|
||||
update(job, { phase: 'version-changed', actualVersion: currentVersion });
|
||||
return null;
|
||||
}
|
||||
|
||||
const lab = useLab ? await readInstalledLab() : null;
|
||||
const { copyPath, stockPath, dataPath, steamLibraryConfirmed } = lab ? {
|
||||
copyPath: lab.copyPath,
|
||||
stockPath: settings.labStockPath ?? record.stockBackupPath,
|
||||
dataPath: settings.labDataPath ?? record.dataPath,
|
||||
steamLibraryConfirmed: false,
|
||||
} : await ordinaryLaunchPaths(record);
|
||||
if (!isAbsolute(stockPath) || !isAbsolute(dataPath)) {
|
||||
throw new AppError('folder_unreadable', { path: !isAbsolute(stockPath) ? stockPath : dataPath });
|
||||
}
|
||||
if (lab && (isInSteamLibrary(copyPath) || isInSteamLibrary(dataPath) || isInSteamLibrary(await canonicalCopyPath(dataPath)))) {
|
||||
throw new AppError('launch_copy_in_steam');
|
||||
}
|
||||
if (copyPathContains(stockPath, dataPath)) throw new AppError('launch_location');
|
||||
const requestedPort = lab?.port ?? (settings.launchPortMode === 'fixed' ? settings.launchPort : 0);
|
||||
if (requestedPort) update(job, { phase: 'checking', port: requestedPort });
|
||||
const [copyVersion, stockVersion, games] = await Promise.all([
|
||||
lab ? readVersion(copyPath, signal) : currentVersion,
|
||||
readVersion(stockPath, signal),
|
||||
gameProcessRunning(signal),
|
||||
]);
|
||||
signal.throwIfAborted();
|
||||
if (!copyVersion || copyVersion !== stockVersion) {
|
||||
throw new AppError(lab ? 'launch_lab_version' : 'launch_stock_version');
|
||||
}
|
||||
if (games) throw new AppError('launch_game_running');
|
||||
const port = await selectPort(requestedPort);
|
||||
return { lab, copyPath, stockPath, dataPath, steamLibraryConfirmed, port };
|
||||
}
|
||||
|
||||
async function buildForLaunch(job: LaunchJob, record: InstallRecord, plan: LaunchPlan, autoSaveBackups: boolean): Promise<void> {
|
||||
const signal = job.stop.signal;
|
||||
const { lab, copyPath, stockPath, dataPath, port, steamLibraryConfirmed } = plan;
|
||||
if (autoSaveBackups) {
|
||||
for (const { userId } of new AccountStore(dataPath).all()) {
|
||||
signal.throwIfAborted();
|
||||
await saveBackup({ ...record, dataPath }, userId, 'launch');
|
||||
}
|
||||
}
|
||||
signal.throwIfAborted();
|
||||
update(job, { phase: 'building', port });
|
||||
await buildCopy({
|
||||
kind: 'build',
|
||||
stockPath,
|
||||
copyPath,
|
||||
dataPath,
|
||||
port,
|
||||
steamLibraryConfirmed,
|
||||
...resourcePaths(),
|
||||
...(record.decalCacheId ? { decalCache: decalCachePath(lab ? record.dataPath : dataPath, record.decalCacheId) } : {}),
|
||||
acceptedUnavailable: record.unavailablePatches.map(({ patchId }) => patchId),
|
||||
}, signal, (filesWritten, filesTotal, file) => {
|
||||
if (!signal.aborted) update(job, {
|
||||
phase: 'building', port, filesWritten, filesTotal, ...(file === undefined ? {} : { file }),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function readVersion(folder: string, signal: AbortSignal): Promise<string | null> {
|
||||
try {
|
||||
return executableVersion(await readFile(join(folder, GAME_FILES.executable), { signal }));
|
||||
|
||||
Reference in new issue
Block a user