feat(launcher): prompt for stock source when adding patched client without backup
This commit is contained in:
1 parent
39228c6e75
commit
bfedc3d27e
13 files changed
+195
-41
No files matched your search
@@ -1,14 +1,18 @@
|
||||
import { access, readFile, realpath, stat } from 'node:fs/promises';
|
||||
import { join } from 'node:path';
|
||||
import { dirname, join } from 'node:path';
|
||||
import { executableVersion, GAME_FILES, isInSteamLibrary, recordedGameVersions } from '@wto/patcher';
|
||||
import { AppError } from '@shared/errors.ts';
|
||||
import type { GameFolderInspection } from '@shared/schemas/install.ts';
|
||||
import { STOCK_BACKUP_FOLDER } from '../install/stock-backup.ts';
|
||||
import { resourcePaths } from '../resources/resource-paths.ts';
|
||||
|
||||
const PATCH_MARKER_FILES = ['wto_ws.dll', 'wto_ws.cfg'] as const;
|
||||
const PATCHED_EXE_MARKER = Buffer.from('wto_ws.dll', 'ascii');
|
||||
|
||||
/**
|
||||
* Look at a folder the player chose as their War Thunder installation: is it one, which version,
|
||||
* whether it already has an offline stock backup, and whether it is inside a Steam library. Only reads.
|
||||
* whether it already has an offline stock backup, whether it is already patched without one,
|
||||
* and whether it is inside a Steam library. Only reads.
|
||||
*/
|
||||
export async function inspectGameFolder(path: string): Promise<GameFolderInspection> {
|
||||
await requireFolder(path);
|
||||
@@ -30,20 +34,42 @@ export async function inspectGameFolder(path: string): Promise<GameFolderInspect
|
||||
const executablePath = hasOfflineBackup
|
||||
? join(stockRoot, GAME_FILES.executable)
|
||||
: join(resolved, GAME_FILES.executable);
|
||||
const executableBytes = (!hasOfflineBackup && missingFiles.includes(GAME_FILES.executable))
|
||||
? null
|
||||
: await readBytes(executablePath);
|
||||
const version = executableBytes ? readVersionFromBytes(executableBytes) : null;
|
||||
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));
|
||||
}
|
||||
return {
|
||||
path,
|
||||
resolvedPath: resolved,
|
||||
missingFiles,
|
||||
version: !hasOfflineBackup && missingFiles.includes(GAME_FILES.executable) ? null : await readVersion(executablePath),
|
||||
version,
|
||||
verifiedVersions: recordedGameVersions(resources.patches),
|
||||
inSteamLibrary: isInSteamLibrary(path) || isInSteamLibrary(resolved),
|
||||
hasOfflineBackup,
|
||||
needsStockSource,
|
||||
};
|
||||
}
|
||||
|
||||
async function readVersion(executablePath: string): Promise<string | null> {
|
||||
async function readBytes(filePath: string): Promise<Buffer | null> {
|
||||
try {
|
||||
return executableVersion(await readFile(executablePath));
|
||||
return await readFile(filePath);
|
||||
} catch (error) {
|
||||
console.warn('[game-folder] reading the executable failed:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function readVersionFromBytes(bytes: Buffer): string | null {
|
||||
try {
|
||||
return executableVersion(bytes);
|
||||
} catch (error) {
|
||||
// Not a PE file, or unreadable: the folder is then not a usable installation, which the
|
||||
// missing version already says.
|
||||
|
||||
Reference in new issue
Block a user