feat(launcher): auto-detect decal cache from selected or recorded game folder

Extend resolvePlayerDecalCacheFolder to resolve <game>/cache/content when the player picks a game root folder directly. Add read-only decals:detectSource IPC so the install wizard auto-fills a detected decal cache from the chosen source (with one-click reset to placeholders) and the client details view offers one-click import from the recorded online sourcePath.
This commit is contained in:
N0VAN0M4LY committed 2026-12-04 21:09:57 +08:00
1 parent 49264b0326
commit c3cf4e3707
12 files changed
+196 -31

No files matched your search

@@ -1,8 +1,8 @@
/**
* Decals and downloadable skins from the player's own online client: the player names the web
* cache folder of an installation they have played online with (<game>/cache/content, or its
* parent <game>/cache), and the build copies the cached textures into the game copy's
* cache/content. The offline version never looks for that folder itself.
* cache folder of an installation they have played online with (<game>/cache/content, its parent
* <game>/cache, or the game root <game>), and the build copies the cached textures into the game
* copy's cache/content. The offline version never looks for that folder itself.
*
* Two layouts exist across War Thunder builds (verified on 2.61.0.37 and 2.61.0.58):
* 1. Modern vromfs-indexed cache (2.61+): cache/content/ holds dldata_s.info and the downloaded
@@ -46,15 +46,16 @@ export interface PlayerDecalCache {
}
/**
* Resolve the actual cache/content folder when the player selects either <game>/cache/content
* or its parent <game>/cache folder.
* Resolve the actual cache/content folder when the player selects <game>/cache/content,
* its parent <game>/cache folder, or the game root <game>.
*/
export function resolvePlayerDecalCacheFolder(source: string): string {
if (!existsSync(source) || !statSync(source).isDirectory()) return source;
if (directDecalCacheProblem(source) === undefined) return source;
const nested = join(source, 'content');
if (existsSync(nested) && statSync(nested).isDirectory() && directDecalCacheProblem(nested) === undefined) {
return nested;
for (const candidate of [join(source, 'content'), join(source, WEB_CACHE_FOLDER)]) {
if (existsSync(candidate) && statSync(candidate).isDirectory() && directDecalCacheProblem(candidate) === undefined) {
return candidate;
}
}
return source;
}
@@ -76,9 +77,9 @@ export function ddsxPathForHash(hash: string): string | undefined {
}
/**
* Scan a player decal cache folder (cache/content, its parent cache folder, or an imported
* snapshot) and collect the normalized relative paths ("<first2>/<rest>.ddsx", lowercased) of
* all cached .ddsx files, skipping .wto-index.
* Scan a player decal cache folder (cache/content, its parent cache folder, the game root, or an
* imported snapshot) and collect the normalized relative paths ("<first2>/<rest>.ddsx", lowercased)
* of all cached .ddsx files, skipping .wto-index.
*/
export function scanCachedDdsxFiles(source: string): ReadonlySet<string> {
const folder = resolvePlayerDecalCacheFolder(source);
@@ -338,10 +339,22 @@ function readSnapshotIndexFiles(folder: string): readonly AddedFile[] | undefine
}
function hasCachedDdsxTextures(folder: string): boolean {
for (const entry of readdirSync(folder, { withFileTypes: true })) {
let entries;
try {
entries = readdirSync(folder, { withFileTypes: true });
} catch {
return false;
}
for (const entry of entries) {
if (!entry.isDirectory() || entry.name === SNAPSHOT_INDEX_DIR) continue;
const sub = join(folder, entry.name);
for (const child of readdirSync(sub, { withFileTypes: true })) {
let children;
try {
children = readdirSync(sub, { withFileTypes: true });
} catch {
continue;
}
for (const child of children) {
if (child.isFile() && child.name.toLowerCase().endsWith(DDSX_EXTENSION)) return true;
}
}
@@ -351,8 +364,14 @@ function hasCachedDdsxTextures(folder: string): boolean {
function findRegionalPack(contentFolder: string): string | undefined {
const parent = dirname(contentFolder);
if (parent === contentFolder || !existsSync(parent)) return undefined;
let entries;
try {
entries = readdirSync(parent, { withFileTypes: true });
} catch {
return undefined;
}
const candidates: Array<{ readonly path: string; readonly version: string; readonly mtimeMs: number }> = [];
for (const entry of readdirSync(parent, { withFileTypes: true })) {
for (const entry of entries) {
if (!entry.isDirectory() || entry.isSymbolicLink()) continue;
const match = BINARY_CACHE_DIR.exec(entry.name);
if (!match) continue;
@@ -395,7 +414,11 @@ function contains(parent: string, child: string): boolean {
}
function decalIndexes(folder: string): string[] {
return readdirSync(folder, { withFileTypes: true })
.filter((entry) => entry.isFile() && DECALS_INDEX_FILE.test(entry.name))
.map((entry) => entry.name);
try {
return readdirSync(folder, { withFileTypes: true })
.filter((entry) => entry.isFile() && DECALS_INDEX_FILE.test(entry.name))
.map((entry) => entry.name);
} catch {
return [];
}
}