feat(launcher): create dedicated WTOffline subfolder and default versioned client name

This commit is contained in:
N0VAN0M4LY committed 2026-11-30 21:13:33 +08:00
1 parent bfedc3d27e
commit 2820d40d87
7 files changed
+88 -11

No files matched your search

+3 -2
View File
@@ -9,7 +9,7 @@ import { cancelMaintenance, maintainCopy, maintenanceInfo, maintenanceInProgress
import { exportDiagnostics, openLogsFolder } from '../services/diagnostics/diagnostics.ts';
import { measureFolder } from '../services/game-folder/folder-size.ts';
import { inspectGameFolder, requireFolder } from '../services/game-folder/inspect-game-folder.ts';
import { inspectTargetFolder } from '../services/game-folder/inspect-target-folder.ts';
import { inspectPickedTargetFolder } from '../services/game-folder/inspect-target-folder.ts';
import { changeDecalSource, decalImportInProgress } from '../services/install/decals.ts';
import { cancelInstall, checkGameFolder, installGame, installationInProgress } from '../services/install/install-game.ts';
import { canonicalCopyPath, createCopyDraft, listCopies, readInstallRecord, renameCopy, setCurrentCopy } from '../services/install/install-record.ts';
@@ -63,7 +63,8 @@ export function registerIpcHandlers(): void {
handle('install:prepareCopy', () => createCopyDraft());
handle('install:inspectGameFolder', ({ path }) => inspectGameFolder(path));
handle('install:inspectTargetFolder', ({ path, stockPath }) => inspectTargetFolder(path, stockPath));
handle('install:inspectTargetFolder', ({ path, stockPath, version }) =>
inspectPickedTargetFolder(path, stockPath, version ?? null));
handle('install:inspectDataFolder', async ({ path }) => {
const resolved = await canonicalCopyPath(path);
return { path: resolved, inSteam: isInSteamLibrary(path) || isInSteamLibrary(resolved) };
@@ -1,11 +1,15 @@
import { readdir, stat, statfs } from 'node:fs/promises';
import { dirname, relative, resolve, isAbsolute } from 'node:path';
import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';
import { isInSteamLibrary } from '@wto/patcher';
import type { TargetFolderInspection } from '@shared/schemas/install.ts';
import { canonicalCopyPath } from '../install/install-record.ts';
import { canonicalCopyPath, listCopies } from '../install/install-record.ts';
const DEFAULT_SUBFOLDER = 'WTOffline';
const SUBFOLDER_PATTERN = /^wtoffline(?:[-_].+)?$/i;
const MAX_DUPLICATE_SUFFIX = 99;
/**
* Look at the folder the player chose for the game copy (install by copying): it must be new or
* Look at the exact folder for the game copy (install by copying): it must be new or
* empty, must not overlap the stock installation, and the drive must have room. Only reads.
*/
export async function inspectTargetFolder(path: string, stockPath: string): Promise<TargetFolderInspection> {
@@ -20,6 +24,60 @@ export async function inspectTargetFolder(path: string, stockPath: string): Prom
};
}
/**
* Resolve a player-picked parent folder into a dedicated `WTOffline` subfolder (falling back to
* `WTOffline-<version>` and `WTOffline-2`, `WTOffline-3`, ... when an earlier folder already has
* files or is registered), unless the picked folder is already an empty `WTOffline*` directory.
*/
export async function inspectPickedTargetFolder(
pickedPath: string,
stockPath: string,
version: string | null,
): Promise<TargetFolderInspection> {
const [picked, stock] = await Promise.all([canonicalCopyPath(pickedPath), canonicalCopyPath(stockPath)]);
if (contains(stock, picked) || contains(picked, stock)) {
return inspectTargetFolder(pickedPath, stockPath);
}
try {
const info = await stat(picked);
if (!info.isDirectory()) return inspectTargetFolder(pickedPath, stockPath);
} catch {
// Picked folder does not exist yet; still check it directly if it already looks like WTOffline*.
}
const registered = await registeredCopyPaths();
if (SUBFOLDER_PATTERN.test(basename(pickedPath)) && !registered.has(picked.toLowerCase())) {
const directProblem = await targetProblem(picked, stock);
if (directProblem === null) return inspectTargetFolder(pickedPath, stockPath);
}
const candidateNames = [DEFAULT_SUBFOLDER];
const safeVersion = version?.replace(/[^0-9A-Za-z._-]/g, '').trim();
if (safeVersion) candidateNames.push(`${DEFAULT_SUBFOLDER}-${safeVersion}`);
for (let i = 2; i <= MAX_DUPLICATE_SUFFIX; i += 1) {
candidateNames.push(`${DEFAULT_SUBFOLDER}-${i}`);
}
for (const name of candidateNames) {
const candidate = join(pickedPath, name);
const resolvedCandidate = await canonicalCopyPath(candidate);
if (registered.has(resolvedCandidate.toLowerCase())) continue;
const problem = await targetProblem(resolvedCandidate, stock);
if (problem === null) return inspectTargetFolder(candidate, stockPath);
}
return inspectTargetFolder(join(pickedPath, DEFAULT_SUBFOLDER), stockPath);
}
async function registeredCopyPaths(): Promise<Set<string>> {
try {
const { copies } = await listCopies();
const resolved = await Promise.all(copies.map((entry) => canonicalCopyPath(entry.copyPath).catch(() => entry.copyPath)));
return new Set(resolved.map((folder) => folder.toLowerCase()));
} catch {
return new Set();
}
}
/** Compare actual volumes, including directories reached through junctions. */
export async function sameVolume(left: string, right: string): Promise<boolean> {
const [first, second] = await Promise.all([volumeDevice(left), volumeDevice(right)]);
@@ -152,7 +152,8 @@
"spaceSavingPending": "Calculating how much space can be saved.",
"spaceSavingUnavailable": "This installation has no large resources eligible for space-saving copying.",
"sameVolumeRequired": "Select a destination on the same volume as the original installation.",
"targetTitle": "Select a folder for the client",
"targetTitle": "Select an install location (a WTOffline subfolder will be created)",
"targetSubfolderHint": "A dedicated WTOffline folder is automatically created under the selected location to keep game files organized.",
"inPlace": "In-place installation",
"inPlaceBody": "Uses the selected game folder directly as the client. Original files are backed up to wtoffline\\stock, and patches are applied on first launch.",
"existing": "Add existing client",
@@ -152,7 +152,8 @@
"spaceSavingPending": "正在估算可节省的空间。",
"spaceSavingUnavailable": "该安装目录没有可用于省空间复制的大型资源。",
"sameVolumeRequired": "请选择与原版位于同一磁盘卷的目标文件夹。",
"targetTitle": "选择存放客户端的文件夹",
"targetTitle": "选择安装位置(将自动创建 WTOffline 子文件夹)",
"targetSubfolderHint": "将在所选位置下自动创建独立的 WTOffline 文件夹存放游戏文件,避免文件散落。",
"inPlace": "原位安装",
"inPlaceBody": "使用所选游戏文件夹作为客户端。原版文件备份至 wtoffline\\stock,首次启动时将应用补丁。",
"existing": "添加已有客户端",
@@ -30,7 +30,7 @@ export function MethodStep({ source, sourceSize, choice, onChoice, onError }: Me
const choose = (method: Method): void => onChoice({ method, target: choice.target, steamConfirmed: false });
const inspectTarget = (path: string): void => {
onChoice((current) => ({ ...current, target: null, steamConfirmed: false }));
ipcInvoke('install:inspectTargetFolder', { path, stockPath: source.path })
ipcInvoke('install:inspectTargetFolder', { path, stockPath: source.path, version: source.version })
.then((target) => onChoice((current) => ({ ...current, target, steamConfirmed: false })))
.catch(onError);
};
@@ -43,6 +43,7 @@ export function MethodStep({ source, sourceSize, choice, onChoice, onError }: Me
const targetPicker = (
<>
<FolderField path={choice.target?.path ?? null} dialogTitle={t('method.targetTitle')} onChosen={inspectTarget} onError={onError} />
<p className="small">{t('method.targetSubfolderHint')}</p>
{choice.target && <TargetVerdict target={choice.target} sourceSize={sourceSize} method={choice.method} />}
{steamWarning}
</>
@@ -119,9 +119,20 @@ export function useInstallWizard({ onInstalled }: WizardOptions) {
const chooseSource = (found: GameFolderInspection | null): void => {
setSource(found);
setStockSource(null);
const defaultMethod = mode === 'existing' || found?.hasOfflineBackup || found?.needsStockSource ? 'existing' : 'copy';
const isExisting = mode === 'existing' || found?.hasOfflineBackup || found?.needsStockSource;
const defaultMethod = isExisting ? 'existing' : 'copy';
setChoice({ method: defaultMethod, target: null, steamConfirmed: false });
setName(found?.path.split(/[\\/]/).filter(Boolean).at(-1) ?? '');
if (!found) {
setName('');
return;
}
const folderName = found.path.split(/[\\/]/).filter(Boolean).at(-1) ?? '';
const genericName = /^(war thunder|wtoffline)$/i.test(folderName);
if (!isExisting || genericName || !folderName) {
setName(found.version ? `WTOffline ${found.version}` : 'WTOffline');
} else {
setName(folderName);
}
};
const install = (): void => {
+5 -1
View File
@@ -77,7 +77,11 @@ export const ipcContract = {
output: GameFolderInspectionSchema,
},
'install:inspectTargetFolder': {
input: z.object({ path: z.string().min(1), stockPath: z.string().min(1) }),
input: z.object({
path: z.string().min(1),
stockPath: z.string().min(1),
version: z.string().nullable().optional(),
}),
output: TargetFolderInspectionSchema,
},
'install:inspectDataFolder': {