From 651b023d2a037a36dbe6360fb82fdf7e1640bf6b Mon Sep 17 00:00:00 2001 From: N0VAN0M4LY <224130499+N0VAN0M4LY@users.noreply.github.com> Date: Fri, 4 Dec 2026 00:47:29 +0800 Subject: [PATCH] fix(launcher): preserve skipped files during game updates Reuse source scan exclusions during stale-file cleanup so updates preserve user content and tool files copied by earlier installers. Verified with root and launcher typechecks and an update run against temporary folders. --- .../src/main/services/copies/copy-file-maintenance.ts | 7 +++++-- apps/launcher/src/main/services/install/copy-game.ts | 10 ++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/apps/launcher/src/main/services/copies/copy-file-maintenance.ts b/apps/launcher/src/main/services/copies/copy-file-maintenance.ts index 5b8fef5..6744074 100644 --- a/apps/launcher/src/main/services/copies/copy-file-maintenance.ts +++ b/apps/launcher/src/main/services/copies/copy-file-maintenance.ts @@ -7,7 +7,7 @@ import type { Copies, GameFolderInspection, InstallRecord } from '@shared/schema import type { MaintenanceProgress } from '@shared/schemas/maintenance.ts'; import { inspectGameFolder } from '../game-folder/inspect-game-folder.ts'; import { sameVolume } from '../game-folder/inspect-target-folder.ts'; -import { copyPlannedFiles, planCopy, type CopyPlan } from '../install/copy-game.ts'; +import { copyPlannedFiles, isInSkippedSourceFolder, planCopy, type CopyPlan } from '../install/copy-game.ts'; import { fileHash, linkVerifiedResource, @@ -57,7 +57,10 @@ export async function updateFromSource(record: InstallRecord, root: string, sign const linked = record.hardlinkedFiles ?? []; const linkedPaths = new Set(linked.map(key)); const preserveHardlinks = await updatePreservesSpaceSaving(record, game, root); - const remove = [...new Set([...(record.sourceFiles ?? []), ...linked])].filter((name) => !found.has(key(name))); + // Older installs may have tracked files in folders that source scans now skip. + const remove = [...new Set([...(record.sourceFiles ?? []), ...linked])].filter( + (name) => !found.has(key(name)) && !isInSkippedSourceFolder(name), + ); const { copy, linksToStage, hardlinkedFiles } = await planUpdateFiles( game.path, root, dataPath, plan, linkedPaths, preserveHardlinks, signal, ); diff --git a/apps/launcher/src/main/services/install/copy-game.ts b/apps/launcher/src/main/services/install/copy-game.ts index 7075573..44ebf42 100644 --- a/apps/launcher/src/main/services/install/copy-game.ts +++ b/apps/launcher/src/main/services/install/copy-game.ts @@ -1,5 +1,5 @@ import type { BigIntStats, Dirent } from 'node:fs'; -import { join, relative } from 'node:path'; +import { join, normalize, relative, sep } from 'node:path'; import { Transform } from 'node:stream'; import { pipeline } from 'node:stream/promises'; import { AppError } from '@shared/errors.ts'; @@ -42,6 +42,12 @@ const SKIPPED_SOURCE_FOLDERS = new Set([ ]); const LAUNCHER_EXECUTABLE_LOWER = 'wtoffline launcher.exe'; +/** Whether a relative path starts with a top-level entry excluded from source scans. */ +export function isInSkippedSourceFolder(relativePath: string): boolean { + const [topLevel = ''] = normalize(relativePath).split(sep, 1); + return SKIPPED_SOURCE_FOLDERS.has(topLevel.toLowerCase()); +} + function isLauncherFolder(entries: readonly Dirent[]): boolean { return entries.some((entry) => entry.isFile() && entry.name.toLowerCase() === LAUNCHER_EXECUTABLE_LOWER); } @@ -80,7 +86,7 @@ export async function planCopy(source: string): Promise { } for (const entry of entries) { const path = join(folder, entry.name); - if (folder === source && SKIPPED_SOURCE_FOLDERS.has(entry.name.toLowerCase())) continue; + if (folder === source && isInSkippedSourceFolder(entry.name)) continue; if (entry.isDirectory()) { pending.push(path); } else if (entry.isFile()) {