feat(launcher): inspect game installation and destination folders

The install wizard needs to tell whether the chosen folder is a War
Thunder installation, which version it is, whether it is a Steam
library, and whether the folder for the copy can take it.

The patcher reads the game version from win64/aces.exe (the
VS_FIXEDFILEINFO block of its version resource) and works out the
versions every exe and GUI patch was verified on, from their
verified_on lists, so the version check follows the patch definitions
instead of a constant.

The launcher gets four IPC calls, each validated against the contract:
- dialog:pickFolder, a folder picker titled by the window;
- install:inspectGameFolder: missing game files, version, verified
  versions, Steam library;
- install:inspectTargetFolder: new or empty, not overlapping the stock
  installation, Steam library, free space on its drive, and whether it
  is on the stock installation's drive (the space saving copy needs
  that);
- install:measureFolder: bytes and files of the stock installation,
  regular files only, links not followed.
A folder that does not exist or cannot be read is the folder_unreadable
error code, translated in both languages. In development the patch
folders and the hook library come from this repository; the packaged
layout comes with the installer build.

Checked with both typechecks, the launcher build, and the calls made
from a running launcher window: the stock folder (2.61.0.37, verified),
a non-game folder, a missing path, a Steam library path, four target
folders (new, inside the stock folder, not empty, other drive) and the
size of the offline copy (96.9 GB in 10,972 files).
This commit is contained in:
N0VAN0M4LY committed 2026-11-29 03:36:00 +08:00
1 parent 38e9549e15
commit ab0d3b1f30
13 files changed
+310 -1

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
/**
* The game version of a stock folder, and the versions the patches were verified on
* (implementation notes: a version that differs is only pointed out, never refused).
*
* The version is the file version of win64/aces.exe: the VS_FIXEDFILEINFO block in its version
* resource, which Windows shows as "File version" (2.61.0.37 for the target build).
*/
import { loadPatches, PeImage } from '@wto/exepatch';
import { loadGuiPatches } from './gui-patch-definition.ts';
/** VS_FIXEDFILEINFO.dwSignature, little-endian. */
const FIXED_FILE_INFO_SIGNATURE = 0xfeef04bd;
const RESOURCE_SECTION = '.rsrc';
/** "major.minor.build.revision" from the executable's version resource, or null when it has none. */
export function executableVersion(executable: Uint8Array): string | null {
const image = new PeImage(executable);
if (!image.sections.some((section) => section.name === RESOURCE_SECTION)) return null;
const resources = image.sectionBytes(RESOURCE_SECTION);
const view = new DataView(resources.buffer, resources.byteOffset, resources.byteLength);
// The fixed file info is 4-byte aligned inside the VS_VERSIONINFO resource; its signature
// does not occur elsewhere in practice, and the struct version after it must be 1.0.
for (let offset = 0; offset + 16 <= resources.byteLength; offset += 4) {
if (view.getUint32(offset, true) !== FIXED_FILE_INFO_SIGNATURE) continue;
if (view.getUint32(offset + 4, true) !== 0x00010000) continue;
const high = view.getUint32(offset + 8, true);
const low = view.getUint32(offset + 12, true);
return [high >>> 16, high & 0xffff, low >>> 16, low & 0xffff].join('.');
}
return null;
}
/** The game versions every exe patch and every GUI patch names in `verified_on`. */
export function verifiedGameVersions(exePatches: string, guiPatches: string): string[] {
const lists = [
...loadPatches(exePatches).map((patch) => patch.verifiedOn),
...loadGuiPatches(guiPatches).map((patch) => patch.verifiedOn),
];
const [first, ...rest] = lists;
if (!first) return [];
return first.filter((version) => rest.every((list) => list.includes(version))).sort();
}
+1
View File
@@ -17,6 +17,7 @@ export { copyPlayerDecalCache, playerDecalCacheProblem } from './decals/player-d
export { blockingFailures, ESSENTIAL_FEATURES } from './essential-features.ts';
export { patchExecutable, type ExecutableResult } from './executable.ts';
export { assertWritableCopy, GAME_FILES, isInSteamLibrary, type WritableCopyOptions } from './game-copy.ts';
export { executableVersion, verifiedGameVersions } from './game-version.ts';
export { rebuildGuiPack, type GuiPackResult } from './gui-pack.ts';
export { loadGuiPatches, type GuiScriptEdit, type GuiScriptPatch } from './gui-patch-definition.ts';
export { ENGINE_SETTINGS_PATH, EXTRA_STORE_BUNDLE_GUID_MAP, EXTRA_STORE_BUNDLE_GUIDS, rebuildMainPack, type MainPackResult } from './main-pack.ts';