From 49264b03261726d11cfe7aac17efb32d95ea91cf Mon Sep 17 00:00:00 2001 From: N0VAN0M4LY <224130499+N0VAN0M4LY@users.noreply.github.com> Date: Fri, 4 Dec 2026 20:38:08 +0800 Subject: [PATCH] feat(launcher): add client origin marker and stock restore removal flow Write a self-describing wtoffline/client.json origin marker (copy, hardlink, or in-place) on install, space-saving compaction, and hardlink-detaching updates, and read it with lightweight hardlink nlink sampling when inspecting existing folders. Allow deleting existing folders only when backed by a valid copy/hardlink marker outside Steam and disjoint from all registered source paths, and add an atomic restore-stock-and-remove option that restores the four stock core files and removes only wto_ws.{dll,cfg,log} and wtoffline/. --- .../services/copies/copy-file-maintenance.ts | 14 +- .../main/services/copies/copy-maintenance.ts | 181 +++--------- .../src/main/services/copies/copy-removal.ts | 272 ++++++++++++++++++ .../game-folder/inspect-game-folder.ts | 7 + .../main/services/install/client-marker.ts | 114 ++++++++ .../main/services/install/data-location.ts | 27 +- .../main/services/install/hardlink-files.ts | 28 ++ .../src/main/services/install/install-game.ts | 74 ++--- .../src/renderer/src/i18n/locales/en.json | 12 + .../src/renderer/src/i18n/locales/zh-CN.json | 12 + .../src/pages/copies/CopyMaintenance.tsx | 1 + .../pages/copies/CopyMaintenanceControls.tsx | 68 ++++- .../src/pages/copies/useCopyMaintenance.ts | 5 +- apps/launcher/src/shared/schemas/install.ts | 11 + .../src/shared/schemas/maintenance.ts | 7 +- 15 files changed, 626 insertions(+), 207 deletions(-) create mode 100644 apps/launcher/src/main/services/copies/copy-removal.ts create mode 100644 apps/launcher/src/main/services/install/client-marker.ts 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 6744074..ffa511f 100644 --- a/apps/launcher/src/main/services/copies/copy-file-maintenance.ts +++ b/apps/launcher/src/main/services/copies/copy-file-maintenance.ts @@ -7,6 +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 { readClientMarker, writeClientMarker } from '../install/client-marker.ts'; import { copyPlannedFiles, isInSkippedSourceFolder, planCopy, type CopyPlan } from '../install/copy-game.ts'; import { fileHash, @@ -69,7 +70,7 @@ export async function updateFromSource(record: InstallRecord, root: string, sign signal.throwIfAborted(); const check = await checkPatches(game.path, record.dataPath); signal.throwIfAborted(); - return changeCopyFiles(root, async (incoming) => { + const updated = await changeCopyFiles(root, async (incoming) => { report('copying', 0, copy.totalBytes); let lastReport = 0; await copyPlannedFiles(game.path, incoming, copy, signal, ({ doneBytes }) => { @@ -104,6 +105,13 @@ export async function updateFromSource(record: InstallRecord, root: string, sign lastCheckedAt: new Date().toISOString(), sourceFiles: inventory, ...(preserveHardlinks ? { hardlinkedFiles } : linked.length ? { hardlinkedFiles: [] } : {}), }))); + if (!preserveHardlinks && linked.length > 0) { + const marker = await readClientMarker(root); + if (marker?.origin === 'hardlink' || (marker === null && record.method === 'copy')) { + await writeClientMarker(root, 'copy'); + } + } + return updated; } interface UpdateFilePlan { @@ -188,7 +196,7 @@ export async function compactCopy(record: InstallRecord, root: string, signal: A const total = candidates.reduce((bytes, file) => bytes + file.bytes, 0); const dataPath = await canonicalCopyPath(record.dataPath); const linked = new Map((record.hardlinkedFiles ?? []).map((path) => [key(path), path])); - return changeCopyFiles(root, async (incoming) => { + const updated = await changeCopyFiles(root, async (incoming) => { const replacements: string[] = []; const unchanged = new Map(); let checked = 0; @@ -225,6 +233,8 @@ export async function compactCopy(record: InstallRecord, root: string, signal: A report('applying', total, total); return { replace: replacements, remove: [] }; }, () => updateCopyRecord(record.id, (latest) => ({ ...latest, hardlinkedFiles: [...linked.values()] }))); + await writeClientMarker(root, 'hardlink'); + return updated; } async function canShareVolume(sourcePath: string, root: string): Promise { diff --git a/apps/launcher/src/main/services/copies/copy-maintenance.ts b/apps/launcher/src/main/services/copies/copy-maintenance.ts index ec8e00d..0323406 100644 --- a/apps/launcher/src/main/services/copies/copy-maintenance.ts +++ b/apps/launcher/src/main/services/copies/copy-maintenance.ts @@ -1,21 +1,29 @@ -import { readdir, rm } from 'node:fs/promises'; -import { isAbsolute, join, parse, relative, resolve } from 'node:path'; -import { app } from 'electron'; +import { isAbsolute, relative } from 'node:path'; import { isInSteamLibrary } from '@wto/patcher'; import { AppError } from '@shared/errors.ts'; import type { Copies, InstallRecord } from '@shared/schemas/install.ts'; import type { MaintenanceInfo, MaintenanceProgress, MaintenanceRequest } from '@shared/schemas/maintenance.ts'; +import { detectHardlinkedResources, readClientMarker } from '../install/client-marker.ts'; import { installationInProgress } from '../install/install-game.ts'; -import { canonicalCopyPath, copyPathContains, listCopies, removeCopyRecord, steamLibraryNeedsConfirmation, updateCopyRecord } from '../install/install-record.ts'; +import { canonicalCopyPath, listCopies, steamLibraryNeedsConfirmation, updateCopyRecord } from '../install/install-record.ts'; import { checkPatches } from '../install/patch-check.ts'; -import { STOCK_BACKUP_FOLDER } from '../install/stock-backup.ts'; import { gameProcessRunning, launchInProgress } from '../launch/launch-controller.ts'; import { readInstalledLab } from '../launch/lab-handoff.ts'; import { localServerReady } from '../launch/local-server.ts'; -import { fileInfo } from './change-copy-files.ts'; import { compactCopy, convertibleCopy, isNewer, repair, updateFromSource, updatePreservesSpaceSaving, type Report } from './copy-file-maintenance.ts'; +import { + canDeleteCopyFiles, + canRestoreStock, + checkedRoot, + failLocation, + removeCopy, + resolveClientOrigin, + withCanonicalSources, +} from './copy-removal.ts'; import { readSource, setCopySource } from './copy-source.ts'; +export { canDeleteCopyFiles, canRestoreStock, resolveClientOrigin } from './copy-removal.ts'; + let current: { stop: AbortController; interruptible: boolean; @@ -35,9 +43,23 @@ export function cancelMaintenance(): void { } export async function maintenanceInfo(id: string): Promise { - const record = await requireCopy(id); - const source = await readSource(record); - const [copyPath, dataPath] = await Promise.all([canonicalCopyPath(record.copyPath), canonicalCopyPath(record.dataPath)]); + const registry = await listCopies(); + const record = registry.copies.find((copy) => copy.id === id); + if (!record) throw new AppError('copy_not_found'); + const [source, copyPath, dataPath, canonicalCopies] = await Promise.all([ + readSource(record), + canonicalCopyPath(record.copyPath), + canonicalCopyPath(record.dataPath), + withCanonicalSources(registry.copies), + ]); + const [diskMarker, hasHardlinkedResources, canRestoreAndRemove] = await Promise.all([ + readClientMarker(copyPath), + detectHardlinkedResources(copyPath), + canRestoreStock(record, copyPath), + ]); + const clientOrigin = resolveClientOrigin(record, diskMarker); + const canDeleteFiles = canDeleteCopyFiles(record, copyPath, clientOrigin, registry.copies) && + canDeleteCopyFiles(record, copyPath, clientOrigin, canonicalCopies); const copyInSteam = isInSteamLibrary(record.copyPath) || isInSteamLibrary(copyPath); const dataInSteam = isInSteamLibrary(record.dataPath) || isInSteamLibrary(dataPath); return { @@ -47,6 +69,10 @@ export async function maintenanceInfo(id: string): Promise { spaceSavingAvailable: source !== null && await convertibleCopy(record, source, record.copyPath), steamConfirmationRequired: steamLibraryNeedsConfirmation(record, copyPath, dataPath), steamLocations: copyInSteam || dataInSteam ? { copyPath, dataPath, copyInSteam, dataInSteam } : null, + clientOrigin, + hasHardlinkedResources, + canDeleteFiles, + canRestoreAndRemove, }; } @@ -90,17 +116,22 @@ export async function maintainCopy( } } -/** Only launcher-created copies outside any Steam library may have their game folder deleted on disk. */ -export function canDeleteCopyFiles(record: InstallRecord, root: string): boolean { - return record.method === 'copy' && !isInSteamLibrary(record.copyPath) && !isInSteamLibrary(root); -} - async function performMaintenance(request: MaintenanceRequest, signal: AbortSignal, report: Report): Promise { const { id, operation, steamLocations } = request; const record = await requireCopy(id); if (operation === 'set-source') return setCopySource(record, request.sourcePath); if (operation === 'delete') { - return remove(record, request.deleteFiles === true, request.deleteData === true, signal, report); + return removeCopy( + record, + { + deleteFiles: request.deleteFiles === true, + restoreStock: request.restoreStock === true, + deleteData: request.deleteData === true, + }, + signal, + report, + labServerUses, + ); } const root = await checkedRoot(record); @@ -140,42 +171,6 @@ async function requireCopy(id: string): Promise { return record; } -function failLocation(reason: string, details: Record): never { - console.warn('[copies] maintenance_location:', reason, details); - throw new AppError('maintenance_location'); -} - -async function checkedRoot(record: InstallRecord): Promise { - const root = await safeFolder(record.copyPath, true); - const backup = await canonicalCopyPath(record.stockBackupPath); - const expectedBackup = join(root, STOCK_BACKUP_FOLDER); - if (relative(expectedBackup, backup) !== '') { - failLocation('stock_backup_outside_copy', { root, expectedBackup, backup, recordedBackup: record.stockBackupPath }); - } - if (record.sourcePath) { - const source = await canonicalCopyPath(record.sourcePath); - if (copyPathContains(source, root) || copyPathContains(root, source)) { - failLocation('copy_overlaps_source', { root, source, sourcePath: record.sourcePath }); - } - } - return root; -} - -async function safeFolder(path: string, steamAllowed = false): Promise { - const root = await canonicalCopyPath(path); - const inSteam = isInSteamLibrary(path) || isInSteamLibrary(root); - const appPath = await canonicalCopyPath(app.getAppPath()); - const userDataPath = await canonicalCopyPath(app.getPath('userData')); - if (!isAbsolute(path) || root === parse(root).root || (!steamAllowed && inSteam) || - copyPathContains(root, appPath) || copyPathContains(root, userDataPath)) { - failLocation('unsafe_folder', { path, root, inSteam, steamAllowed, appPath, userDataPath }); - } - if ((!steamAllowed || !inSteam) && (await fileInfo(path))?.isSymbolicLink()) { - failLocation('folder_is_symlink', { path, root }); - } - return root; -} - async function labServerUses(root: string): Promise { const lab = await readInstalledLab().catch(() => null); if (!lab || relative(lab.copyPath, root) !== '') return false; @@ -188,87 +183,3 @@ async function recordCheck(record: InstallRecord, folder: string): Promise { - const canonicalRoot = await canonicalCopyPath(record.copyPath); - if (await gameProcessRunning(signal) || await labServerUses(canonicalRoot)) { - throw new AppError('maintenance_busy'); - } - signal.throwIfAborted(); - - // Pure list removal touches no files on disk and skips copyPath/stockBackup checks - // so missing, moved, or damaged client registrations can always be removed safely. - if (!deleteFiles && !deleteData) { - report('applying'); - return removeCopyRecord(record.id); - } - - const copyInSteam = isInSteamLibrary(record.copyPath) || isInSteamLibrary(canonicalRoot); - if (copyInSteam) { - failLocation(deleteFiles ? 'delete_files_blocked_in_steam' : 'delete_data_blocked_in_steam', { - method: record.method, - copyPath: record.copyPath, - root: canonicalRoot, - }); - } - - if (deleteFiles && !canDeleteCopyFiles(record, canonicalRoot)) { - failLocation('delete_files_blocked_for_method', { - method: record.method, - copyPath: record.copyPath, - root: canonicalRoot, - }); - } - - const root = deleteFiles ? await checkedRoot(record) : canonicalRoot; - if (deleteFiles && !canDeleteCopyFiles(record, root)) { - failLocation('delete_files_blocked', { method: record.method, copyPath: record.copyPath, root }); - } - - const data = deleteData ? await safeFolder(record.dataPath, false) : await canonicalCopyPath(record.dataPath); - const source = record.sourcePath ? await canonicalCopyPath(record.sourcePath) : null; - const stockBackup = await canonicalCopyPath(record.stockBackupPath); - if (deleteData) { - const rawRoot = resolve(record.copyPath); - const overlapsSource = source !== null && (copyPathContains(data, source) || copyPathContains(source, data)); - const containsCopy = deleteFiles - ? relative(data, root) !== '' && copyPathContains(data, root) - : copyPathContains(data, root) || copyPathContains(data, rawRoot) || copyPathContains(data, stockBackup); - if (overlapsSource || containsCopy) { - failLocation('delete_data_overlaps_source_or_copy', { root, data, source, stockBackup, deleteFiles }); - } - } - - report('applying'); - if (deleteFiles) { - if (!deleteData && copyPathContains(root, data)) { - await removeExcept(root, data); - } else { - await rm(root, { recursive: true, force: true }); - } - } - if (deleteData && (!deleteFiles || !copyPathContains(root, data))) { - await rm(data, { recursive: true, force: true }); - } - return removeCopyRecord(record.id); -} - -/** Keep the data folder in place when it was chosen inside this copy. */ -async function removeExcept(folder: string, kept: string): Promise { - if (relative(folder, kept) === '' || !(await fileInfo(folder))) return; - for (const entry of await readdir(folder, { withFileTypes: true })) { - const path = join(folder, entry.name); - if (copyPathContains(path, kept)) { - if (!entry.isDirectory()) failLocation('kept_data_ancestor_not_directory', { folder, kept, path }); - await removeExcept(path, kept); - } else { - await rm(path, { recursive: true, force: true }); - } - } -} diff --git a/apps/launcher/src/main/services/copies/copy-removal.ts b/apps/launcher/src/main/services/copies/copy-removal.ts new file mode 100644 index 0000000..a900b86 --- /dev/null +++ b/apps/launcher/src/main/services/copies/copy-removal.ts @@ -0,0 +1,272 @@ +import { constants } from 'node:fs'; +import { dirname, isAbsolute, join, parse, relative, resolve } from 'node:path'; +import { app } from 'electron'; +import { GAME_FILES, isInSteamLibrary } from '@wto/patcher'; +import { AppError } from '@shared/errors.ts'; +import type { ClientOrigin, Copies, InstallRecord } from '@shared/schemas/install.ts'; +import { rawFs } from '../../util/raw-fs.ts'; +import { readClientMarker, type ClientMarker } from '../install/client-marker.ts'; +import { canonicalCopyPath, copyPathContains, listCopies, removeCopyRecord } from '../install/install-record.ts'; +import { requireStockBackupLocation, STOCK_BACKUP_FOLDER } from '../install/stock-backup.ts'; +import { gameProcessRunning } from '../launch/launch-controller.ts'; +import { changeCopyFiles, fileInfo, stagedPath } from './change-copy-files.ts'; +import type { Report } from './copy-file-maintenance.ts'; + +const OFFLINE_HOOK_FILES = ['wto_ws.dll', 'wto_ws.cfg', 'wto_ws.log'] as const; + +export interface RemoveCopyOptions { + readonly deleteFiles: boolean; + readonly restoreStock: boolean; + readonly deleteData: boolean; +} + +export function failLocation(reason: string, details: Record): never { + console.warn('[copies] maintenance_location:', reason, details); + throw new AppError('maintenance_location'); +} + +/** + * Resolve the effective client origin by preferring a valid on-disk marker while + * keeping in-place registrations conservatively locked as `in-place`. + */ +export function resolveClientOrigin( + record: InstallRecord, + diskMarker: ClientMarker | null, +): ClientOrigin | null { + if (record.method === 'in-place') return 'in-place'; + if (diskMarker) return diskMarker.origin; + if (record.method === 'copy') return record.hardlinkedFiles?.length ? 'hardlink' : 'copy'; + return null; +} + +/** + * Only launcher-created copies or existing folders carrying a valid copy/hardlink marker + * outside any Steam library and disjoint from every registered copy's sourcePath may be deleted. + */ +export function canDeleteCopyFiles( + record: InstallRecord, + root: string, + effectiveOrigin: ClientOrigin | null, + allCopies: readonly InstallRecord[] = [], +): boolean { + if (isInSteamLibrary(record.copyPath) || isInSteamLibrary(root)) return false; + if (effectiveOrigin !== 'copy' && effectiveOrigin !== 'hardlink') return false; + const normalizedRoot = resolve(root); + const normalizedCopyPath = resolve(record.copyPath); + const sources = record.sourcePath + ? [record.sourcePath, ...allCopies.map((copy) => copy.sourcePath)] + : allCopies.map((copy) => copy.sourcePath); + for (const candidate of sources) { + if (!candidate) continue; + const source = resolve(candidate); + if (pathsOverlap(normalizedRoot, source) || pathsOverlap(normalizedCopyPath, source)) { + return false; + } + } + return true; +} + +/** Check that `record` has a safe root and all four original core files readable in wtoffline/stock. */ +export async function canRestoreStock(record: InstallRecord, root: string): Promise { + try { + const safeRoot = await checkedRoot(record); + const canonicalRoot = await canonicalCopyPath(root); + if (relative(safeRoot, canonicalRoot) !== '') return false; + const backup = await requireStockBackupLocation(safeRoot); + const fsPromises = rawFs().promises; + for (const file of Object.values(GAME_FILES)) { + const stockFile = join(backup, file); + const info = await fileInfo(stockFile); + if (!info?.isFile()) return false; + await fsPromises.access(stockFile, constants.R_OK); + } + return true; + } catch { + return false; + } +} + +/** Resolve every copy's `sourcePath` through symlinks/junctions for overlap checks. */ +export async function withCanonicalSources(copies: readonly InstallRecord[]): Promise { + return Promise.all(copies.map(async (copy) => ( + copy.sourcePath ? { ...copy, sourcePath: await canonicalCopyPath(copy.sourcePath) } : copy + ))); +} + +export async function checkedRoot(record: InstallRecord): Promise { + const root = await safeFolder(record.copyPath, true); + const backup = await canonicalCopyPath(record.stockBackupPath); + const expectedBackup = join(root, STOCK_BACKUP_FOLDER); + if (relative(expectedBackup, backup) !== '') { + failLocation('stock_backup_outside_copy', { root, expectedBackup, backup, recordedBackup: record.stockBackupPath }); + } + if (record.sourcePath) { + const source = await canonicalCopyPath(record.sourcePath); + if (pathsOverlap(source, root)) { + failLocation('copy_overlaps_source', { root, source, sourcePath: record.sourcePath }); + } + } + return root; +} + +export async function safeFolder(path: string, steamAllowed = false): Promise { + const root = await canonicalCopyPath(path); + const inSteam = isInSteamLibrary(path) || isInSteamLibrary(root); + const appPath = await canonicalCopyPath(app.getAppPath()); + const userDataPath = await canonicalCopyPath(app.getPath('userData')); + if (!isAbsolute(path) || root === parse(root).root || (!steamAllowed && inSteam) || + copyPathContains(root, appPath) || copyPathContains(root, userDataPath)) { + failLocation('unsafe_folder', { path, root, inSteam, steamAllowed, appPath, userDataPath }); + } + if ((!steamAllowed || !inSteam) && (await fileInfo(path))?.isSymbolicLink()) { + failLocation('folder_is_symlink', { path, root }); + } + return root; +} + +export async function removeCopy( + record: InstallRecord, + options: RemoveCopyOptions, + signal: AbortSignal, + report: Report, + labServerUses: (root: string) => Promise, +): Promise { + const { deleteFiles, restoreStock, deleteData } = options; + if (deleteFiles && restoreStock) { + failLocation('delete_files_and_restore_stock_conflict', { id: record.id }); + } + + const canonicalRoot = await canonicalCopyPath(record.copyPath); + if (await gameProcessRunning(signal) || await labServerUses(canonicalRoot)) { + throw new AppError('maintenance_busy'); + } + signal.throwIfAborted(); + + // Pure list removal touches no files on disk and skips copyPath/stockBackup checks + // so missing, moved, or damaged client registrations can always be removed safely. + if (!deleteFiles && !deleteData && !restoreStock) { + report('applying'); + return removeCopyRecord(record.id); + } + + const copyInSteam = isInSteamLibrary(record.copyPath) || isInSteamLibrary(canonicalRoot); + if ((deleteFiles || deleteData) && copyInSteam) { + failLocation(deleteFiles ? 'delete_files_blocked_in_steam' : 'delete_data_blocked_in_steam', { + method: record.method, + copyPath: record.copyPath, + root: canonicalRoot, + }); + } + + let root = canonicalRoot; + if (deleteFiles) { + const allCopies = (await listCopies()).copies; + const canonicalCopies = await withCanonicalSources(allCopies); + const initialOrigin = resolveClientOrigin(record, await readClientMarker(canonicalRoot)); + if (!canDeleteCopyFiles(record, canonicalRoot, initialOrigin, allCopies) || + !canDeleteCopyFiles(record, canonicalRoot, initialOrigin, canonicalCopies)) { + failLocation('delete_files_blocked', { method: record.method, origin: initialOrigin, copyPath: record.copyPath, root: canonicalRoot }); + } + root = await checkedRoot(record); + const verifiedOrigin = resolveClientOrigin(record, await readClientMarker(root)); + if (!canDeleteCopyFiles(record, root, verifiedOrigin, allCopies) || + !canDeleteCopyFiles(record, root, verifiedOrigin, canonicalCopies)) { + failLocation('delete_files_blocked', { method: record.method, origin: verifiedOrigin, copyPath: record.copyPath, root }); + } + } else if (restoreStock) { + root = await checkedRoot(record); + if (!(await canRestoreStock(record, root))) { + failLocation('restore_stock_unavailable', { copyPath: record.copyPath, root, stockBackupPath: record.stockBackupPath }); + } + } + + const data = deleteData ? await safeFolder(record.dataPath, false) : await canonicalCopyPath(record.dataPath); + const source = record.sourcePath ? await canonicalCopyPath(record.sourcePath) : null; + const stockBackup = await canonicalCopyPath(record.stockBackupPath); + if (deleteData) { + const rawRoot = resolve(record.copyPath); + const overlapsSource = source !== null && pathsOverlap(data, source); + const containsCopy = deleteFiles + ? relative(data, root) !== '' && copyPathContains(data, root) + : copyPathContains(data, root) || copyPathContains(data, rawRoot) || copyPathContains(data, stockBackup); + if (overlapsSource || containsCopy) { + failLocation('delete_data_overlaps_source_or_copy', { root, data, source, stockBackup, deleteFiles, restoreStock }); + } + } + + report('applying'); + const fsPromises = rawFs().promises; + if (restoreStock) { + await restoreStockAndCleanOfflineFiles(root, data, deleteData); + } else if (deleteFiles) { + if (!deleteData && copyPathContains(root, data)) { + await removeExcept(root, data); + } else { + await fsPromises.rm(root, { recursive: true, force: true }); + } + } + if (deleteData && (!deleteFiles || !copyPathContains(root, data))) { + await fsPromises.rm(data, { recursive: true, force: true }); + } + return removeCopyRecord(record.id); +} + +/** + * Atomically restore the four stock core files from `wtoffline/stock`, then remove + * only launcher-created hook files and the `wtoffline` folder without touching base game files. + */ +async function restoreStockAndCleanOfflineFiles(root: string, data: string, deleteData: boolean): Promise { + const fsPromises = rawFs().promises; + const backup = await requireStockBackupLocation(root); + await changeCopyFiles(root, async (incoming) => { + const files = Object.values(GAME_FILES); + for (const file of files) { + const sourceFile = join(backup, file); + if (!(await fileInfo(sourceFile))?.isFile()) { + failLocation('stock_backup_source_missing', { root, file, sourceFile }); + } + const targetFile = join(incoming, file); + await fsPromises.mkdir(dirname(targetFile), { recursive: true }); + await fsPromises.copyFile(sourceFile, targetFile); + } + return { replace: files, remove: [] }; + }, async () => undefined); + + const exeDir = dirname(GAME_FILES.executable); + for (const name of OFFLINE_HOOK_FILES) { + const hookFile = await stagedPath(root, join(exeDir, name)); + const info = await fileInfo(hookFile); + if (info && !info.isDirectory()) { + await fsPromises.rm(hookFile, { force: true }); + } + } + + const wtofflineFolder = await stagedPath(root, dirname(STOCK_BACKUP_FOLDER)); + const wtofflineInfo = await fileInfo(wtofflineFolder); + if (wtofflineInfo?.isDirectory()) { + if (!deleteData && copyPathContains(wtofflineFolder, data)) { + await removeExcept(wtofflineFolder, data); + } else { + await fsPromises.rm(wtofflineFolder, { recursive: true, force: true }); + } + } +} + +function pathsOverlap(left: string, right: string): boolean { + return copyPathContains(left, right) || copyPathContains(right, left); +} + +/** Keep the data folder in place when it was chosen inside this copy. */ +async function removeExcept(folder: string, kept: string): Promise { + if (relative(folder, kept) === '' || !(await fileInfo(folder))) return; + const fsPromises = rawFs().promises; + for (const entry of await fsPromises.readdir(folder, { withFileTypes: true })) { + const path = join(folder, entry.name); + if (copyPathContains(path, kept)) { + if (!entry.isDirectory()) failLocation('kept_data_ancestor_not_directory', { folder, kept, path }); + await removeExcept(path, kept); + } else { + await fsPromises.rm(path, { recursive: true, force: true }); + } + } +} diff --git a/apps/launcher/src/main/services/game-folder/inspect-game-folder.ts b/apps/launcher/src/main/services/game-folder/inspect-game-folder.ts index d1aa5dd..0567d14 100644 --- a/apps/launcher/src/main/services/game-folder/inspect-game-folder.ts +++ b/apps/launcher/src/main/services/game-folder/inspect-game-folder.ts @@ -3,6 +3,7 @@ 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 { detectHardlinkedResources, readClientMarker } from '../install/client-marker.ts'; import { STOCK_BACKUP_FOLDER } from '../install/stock-backup.ts'; import { resourcePaths } from '../resources/resource-paths.ts'; @@ -61,6 +62,10 @@ export async function inspectGameFolder(path: string): Promise; + +/** Cap on qualifying resource files inspected when sampling for hard links. */ +const MAX_RESOURCE_SAMPLES = 64; + +export function clientMarkerPath(copyFolder: string): string { + return join(copyFolder, CLIENT_MARKER_FILE); +} + +/** + * Safely read and validate `/wtoffline/client.json`. + * Returns `null` when missing, unreadable, malformed, or schema-invalid without throwing. + */ +export async function readClientMarker(copyFolder: string): Promise { + try { + const text = await rawFs().promises.readFile(clientMarkerPath(copyFolder), 'utf8'); + const parsed = ClientMarkerSchema.safeParse(JSON.parse(text) as unknown); + return parsed.success ? parsed.data : null; + } catch { + return null; + } +} + +/** + * Atomically write `/wtoffline/client.json`. + * Preserves `createdAt` and records `updatedAt` when updating an existing valid marker. + */ +export async function writeClientMarker(copyFolder: string, origin: ClientOrigin): Promise { + const existing = await readClientMarker(copyFolder); + const now = new Date().toISOString(); + const marker: ClientMarker = existing + ? { + format: 1, + origin, + createdBy: 'wtoffline-launcher', + createdAt: existing.createdAt, + updatedAt: now, + } + : { + format: 1, + origin, + createdBy: 'wtoffline-launcher', + createdAt: now, + }; + await writeJsonAtomic(clientMarkerPath(copyFolder), marker); + return marker; +} + +/** + * Lightweight probe for hard-linked read-only resource packs under allowed content directories. + * Returns `true` as soon as a single qualifying resource reports `nlink >= 2`, or `false` on + * missing/unreadable directories or when no sampled resource is hard-linked. + */ +export async function detectHardlinkedResources(copyFolder: string): Promise { + const fsPromises = rawFs().promises; + const rules = hardlinkResourceRules(); + const queue: Array<{ absDir: string; relDir: string }> = rules.allowedDirectories.map((dir) => { + const clean = dir.replace(/\/+$/, ''); + return { absDir: join(copyFolder, clean), relDir: clean }; + }); + let sampled = 0; + + while (queue.length > 0 && sampled < MAX_RESOURCE_SAMPLES) { + const current = queue.shift()!; + let entries; + try { + entries = await fsPromises.readdir(current.absDir, { withFileTypes: true }); + } catch { + continue; + } + + for (const entry of entries) { + if (entry.isSymbolicLink()) continue; + const absPath = join(current.absDir, entry.name); + const relPath = `${current.relDir}/${entry.name}`; + if (entry.isDirectory()) { + queue.push({ absDir: absPath, relDir: relPath }); + continue; + } + if (!entry.isFile()) continue; + + const lower = entry.name.toLowerCase(); + if (!rules.allowedExtensions.some((ext) => lower.endsWith(ext))) continue; + + try { + const stats = await fsPromises.lstat(absPath); + if (!stats.isFile() || !isHardlinkableResource(relPath, stats.size)) continue; + if (stats.nlink >= 2) return true; + sampled += 1; + if (sampled >= MAX_RESOURCE_SAMPLES) return false; + } catch { + continue; + } + } + } + return false; +} diff --git a/apps/launcher/src/main/services/install/data-location.ts b/apps/launcher/src/main/services/install/data-location.ts index b4a00d1..defa9a5 100644 --- a/apps/launcher/src/main/services/install/data-location.ts +++ b/apps/launcher/src/main/services/install/data-location.ts @@ -1,6 +1,31 @@ import { readdir } from 'node:fs/promises'; -import { join } from 'node:path'; +import { dirname, join } from 'node:path'; import { AppError } from '@shared/errors.ts'; +import type { DataFolderProblem } from '@shared/schemas/install.ts'; +import { copyPathContains } from './install-record.ts'; +import { STOCK_BACKUP_FOLDER } from './stock-backup.ts'; + +/** + * Validate where the offline data folder sits relative to the client and stock folders. + * A subfolder inside the client (outside wtoffline/) is allowed, while setting dataPath to the + * client folder itself or an ancestor of it would mix game files into the data root. + */ +export function dataFolderProblem( + dataPath: string, + copyPath: string | null, + sourcePath: string | null, + externalStockPath: string | null, +): DataFolderProblem | null { + if (copyPath && (copyPathContains(dataPath, copyPath) || + copyPathContains(join(copyPath, dirname(STOCK_BACKUP_FOLDER)), dataPath))) { + return 'overlaps_client'; + } + if ((sourcePath && copyPathContains(sourcePath, dataPath)) || + (externalStockPath && copyPathContains(externalStockPath, dataPath))) { + return 'overlaps_stock'; + } + return null; +} /** A data tree must keep the server's saves, logs and caches inside the selected folder. */ export async function requireUnredirectedData(root: string): Promise { diff --git a/apps/launcher/src/main/services/install/hardlink-files.ts b/apps/launcher/src/main/services/install/hardlink-files.ts index b3199d7..0d0c424 100644 --- a/apps/launcher/src/main/services/install/hardlink-files.ts +++ b/apps/launcher/src/main/services/install/hardlink-files.ts @@ -1,7 +1,11 @@ import { createHash } from 'node:crypto'; import { createReadStream, type BigIntStats } from 'node:fs'; import { link, lstat } from 'node:fs/promises'; +import { join } from 'node:path'; +import { isHardlinkableResource } from '@wto/patcher'; import { AppError } from '@shared/errors.ts'; +import type { InstallProgress } from '@shared/schemas/install.ts'; +import type { CopyPlan } from './copy-game.ts'; export type ResourceMatchResult = | { readonly status: 'already-linked'; readonly copyStamp: BigIntStats; readonly sourceStamp: BigIntStats } @@ -83,3 +87,27 @@ function sameIdentityAndContents(left: BigIntStats, right: BigIntStats): boolean return right.isFile() && left.dev === right.dev && left.ino === right.ino && left.size === right.size && left.mtimeNs === right.mtimeNs; } + +/** Collect and stat every eligible read-only resource pack in `plan` before hard-linking. */ +export async function prepareHardlinks( + source: string, + plan: CopyPlan, + signal: AbortSignal, + report: (progress: InstallProgress) => void, +): Promise> { + const candidates = plan.files.filter((file) => isHardlinkableResource(file.relativePath, file.bytes)); + const totalBytes = candidates.reduce((total, file) => total + file.bytes, 0); + const links = new Map(); + let doneBytes = 0; + let doneFiles = 0; + report({ phase: 'verifying', doneBytes, totalBytes, doneFiles, totalFiles: candidates.length }); + for (const file of candidates) { + const verified = await statHardlinkResource(join(source, file.relativePath), file.bytes, signal); + if (verified) links.set(file.relativePath, verified); + doneBytes += file.bytes; + doneFiles += 1; + report({ phase: 'verifying', doneBytes, totalBytes, doneFiles, totalFiles: candidates.length }); + } + if (!links.size) throw new AppError('hardlink_no_match'); + return links; +} diff --git a/apps/launcher/src/main/services/install/install-game.ts b/apps/launcher/src/main/services/install/install-game.ts index 8e686f4..2255285 100644 --- a/apps/launcher/src/main/services/install/install-game.ts +++ b/apps/launcher/src/main/services/install/install-game.ts @@ -1,19 +1,21 @@ -import type { BigIntStats } from 'node:fs'; import { access, mkdir } from 'node:fs/promises'; -import { dirname, isAbsolute, join, relative } from 'node:path'; +import { dirname, isAbsolute, relative } from 'node:path'; import { app } from 'electron'; -import { isHardlinkableResource, isInSteamLibrary } from '@wto/patcher'; +import { isInSteamLibrary } from '@wto/patcher'; import { AppError } from '@shared/errors.ts'; -import type { DataFolderProblem, InstallProgress, InstallRecord, InstallRequest, PatchCheck } from '@shared/schemas/install.ts'; +import type { ClientOrigin, InstallProgress, InstallRecord, InstallRequest, PatchCheck } from '@shared/schemas/install.ts'; import { inspectGameFolder } from '../game-folder/inspect-game-folder.ts'; import { freeBytes, inspectTargetFolder, sameVolume } from '../game-folder/inspect-target-folder.ts'; -import { copyPlannedFiles, planCopy, removeInterruptedCopy, type CopyPlan } from './copy-game.ts'; -import { requireUnredirectedData } from './data-location.ts'; +import { readClientMarker, writeClientMarker } from './client-marker.ts'; +import { copyPlannedFiles, planCopy, removeInterruptedCopy } from './copy-game.ts'; +import { dataFolderProblem, requireUnredirectedData } from './data-location.ts'; import { discardDecalCache, importDecalCache } from './decals.ts'; -import { statHardlinkResource } from './hardlink-files.ts'; +import { prepareHardlinks } from './hardlink-files.ts'; import { canonicalCopyPath, copyPathContains, requireAvailableCopy, writeInstallRecord } from './install-record.ts'; import { checkPatches } from './patch-check.ts'; -import { backUpStockFiles, installStockSource, refreshStockBackup, refreshStockBackupFrom, requireStockBackupLocation, STOCK_BACKUP_FOLDER } from './stock-backup.ts'; +import { backUpStockFiles, installStockSource, refreshStockBackup, refreshStockBackupFrom, requireStockBackupLocation } from './stock-backup.ts'; + +export { dataFolderProblem } from './data-location.ts'; /** * Install the offline version: check the patches against the player's game, @@ -101,6 +103,16 @@ async function install(request: InstallRequest, signal: AbortSignal, report: (pr ? await refreshStockBackup(copyPath) : await backUpStockFiles(copyPath); + // Record launcher-created client origin on disk; never overwrite or fabricate a marker for existing folders. + let detectedOrigin: ClientOrigin | undefined; + if (request.method === 'copy') { + await writeClientMarker(copyPath, useHardLinks ? 'hardlink' : 'copy'); + } else if (request.method === 'in-place') { + await writeClientMarker(copyPath, 'in-place'); + } else { + detectedOrigin = (await readClientMarker(copyPath))?.origin; + } + report({ phase: 'recording', doneBytes: 0, totalBytes: 0, doneFiles: 0, totalFiles: 0 }); const record: InstallRecord = { id: request.id, @@ -116,6 +128,7 @@ async function install(request: InstallRequest, signal: AbortSignal, report: (pr installedAt: new Date().toISOString(), lastCheckedAt: new Date().toISOString(), ...(decalCacheId ? { decalCacheId } : {}), + ...(detectedOrigin ? { detectedOrigin } : {}), ...copied, }; await writeInstallRecord(record); @@ -176,28 +189,6 @@ async function inspectInstallation(request: InstallRequest) { return { version: game.version, requestedCopyPath, copyPath, dataPath, sourcePath, externalStockPath, target, useHardLinks, copyInSteam, dataInSteam }; } -/** - * Validate where the offline data folder sits relative to the client and stock folders. - * A subfolder inside the client (outside wtoffline/) is allowed, while setting dataPath to the - * client folder itself or an ancestor of it would mix game files into the data root. - */ -export function dataFolderProblem( - dataPath: string, - copyPath: string | null, - sourcePath: string | null, - externalStockPath: string | null, -): DataFolderProblem | null { - if (copyPath && (copyPathContains(dataPath, copyPath) || - copyPathContains(join(copyPath, dirname(STOCK_BACKUP_FOLDER)), dataPath))) { - return 'overlaps_client'; - } - if ((sourcePath && copyPathContains(sourcePath, dataPath)) || - (externalStockPath && copyPathContains(externalStockPath, dataPath))) { - return 'overlaps_stock'; - } - return null; -} - async function resolveExternalStockSource(stockSourcePath: string, expectedVersion: string | null) { const stockGame = await requireGameFolder(stockSourcePath); if (stockGame.needsStockSource) throw new AppError('stock_source_invalid'); @@ -265,29 +256,6 @@ async function copyGame( } } -async function prepareHardlinks( - source: string, - plan: CopyPlan, - signal: AbortSignal, - report: (progress: InstallProgress) => void, -): Promise> { - const candidates = plan.files.filter((file) => isHardlinkableResource(file.relativePath, file.bytes)); - const totalBytes = candidates.reduce((total, file) => total + file.bytes, 0); - const links = new Map(); - let doneBytes = 0; - let doneFiles = 0; - report({ phase: 'verifying', doneBytes, totalBytes, doneFiles, totalFiles: candidates.length }); - for (const file of candidates) { - const verified = await statHardlinkResource(join(source, file.relativePath), file.bytes, signal); - if (verified) links.set(file.relativePath, verified); - doneBytes += file.bytes; - doneFiles += 1; - report({ phase: 'verifying', doneBytes, totalBytes, doneFiles, totalFiles: candidates.length }); - } - if (!links.size) throw new AppError('hardlink_no_match'); - return links; -} - async function requireGameFolder(path: string) { const game = await inspectGameFolder(path); if (game.missingFiles.length) throw new AppError('not_a_game_folder', { path }); diff --git a/apps/launcher/src/renderer/src/i18n/locales/en.json b/apps/launcher/src/renderer/src/i18n/locales/en.json index 66c69ba..00849ed 100644 --- a/apps/launcher/src/renderer/src/i18n/locales/en.json +++ b/apps/launcher/src/renderer/src/i18n/locales/en.json @@ -264,15 +264,27 @@ "remove": "Remove client", "removeAction": "Remove…", "removeCopyHint": "Removes from the launcher list by default without deleting files on disk.", + "removeRestoreHint": "Removes from the launcher list by default; optionally restores original files and removes offline patch files while keeping the base game.", "removeUnlinkHint": "Removes only from the launcher list without deleting game files on disk.", "removeSteamHint": "Removes only from the launcher list. Steam game files and the data folder stay in place.", "removeCopyNotice": "Removes {{path}} from the launcher list. All game files and data on disk are kept by default.", "removeListOnlyNotice": "Removes {{path}} from the launcher list only. Game files on disk will not be deleted.", "removeSteamNotice": "Removes {{path}} from the launcher list only. Steam game files and data on disk will not be deleted.", + "originCopy": "Detected client type: full copy (created as an independent copy by the launcher).", + "originHardlink": "Detected client type: space-saving hard-linked copy (read-only resource packs are shared; deleting this copy does not affect the original game folder).", + "originInPlace": "Detected client type: in-place installation (full folder deletion is disabled to protect the base game).", + "originUnknown": "Detected client type: existing folder of unknown origin (no client identity marker found; full folder deletion is disabled for safety).", + "originUnknownHardlinked": "Detected client type: existing folder of unknown origin (hard-linked resources were detected without a client identity marker; full folder deletion is disabled for safety).", "deleteFiles": "Also delete the client folder at {{path}}", + "deleteHardlinkHint": "Note: This client shares read-only resource packs via hard links; deleting the copy folder will not affect the original game folder.", "deleteFilesWarning": "This will permanently delete all files in the copied client folder at {{path}}. This action cannot be undone.", + "deleteHardlinkWarning": "This will permanently delete all files in the hard-linked copy folder at {{path}} (the original game folder is unaffected). This action cannot be undone.", + "restoreStock": "Restore original files and remove offline patch files (keep base game)", + "restoreStockHint": "Restores the 4 original core files from wtoffline\\stock and removes wtoffline\\ along with network hook files (wto_ws.dll / wto_ws.cfg / wto_ws.log). No base game files are deleted.", "deleteData": "Also delete the data folder at {{path}} (contains saves, settings, and logs)", + "openFolder": "Open folder", "confirmRemove": "Remove from list", + "confirmRestore": "Restore and remove", "confirmDelete": "Confirm deletion", "phase": { "checking": "Checking the client", diff --git a/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json b/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json index 10ebcad..bf83c00 100644 --- a/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json +++ b/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json @@ -264,15 +264,27 @@ "remove": "移除客户端", "removeAction": "移除…", "removeCopyHint": "默认仅从启动器列表移除,不会删除磁盘文件。", + "removeRestoreHint": "默认仅从启动器列表移除;也可选还原为原版并清理离线补丁文件(保留游戏本体)。", "removeUnlinkHint": "仅从启动器列表移除,不会删除磁盘上的游戏文件。", "removeSteamHint": "仅从启动器列表移除,Steam 游戏文件和数据目录将留在原处。", "removeCopyNotice": "将从启动器列表移除 {{path}}。默认保留磁盘上的所有游戏文件和数据。", "removeListOnlyNotice": "将仅从启动器列表移除 {{path}},不会删除磁盘上的游戏文件。", "removeSteamNotice": "将仅从启动器列表移除 {{path}},不会删除磁盘上的 Steam 游戏文件和数据目录。", + "originCopy": "识别结果:完整复制副本(由启动器独立复制创建)。", + "originHardlink": "识别结果:省空间硬链接副本(只读资源包与原版共享,删除副本不会影响原版游戏目录)。", + "originInPlace": "识别结果:原位安装目录(为保护原版游戏本体,不支持直接删除整个文件夹)。", + "originUnknown": "识别结果:未知来源的已有目录(缺少客户端身份标记,为保护游戏文件不支持直接删除整个文件夹)。", + "originUnknownHardlinked": "识别结果:未知来源的已有目录(检测到硬链接资源包,但缺少客户端身份标记;为保护原版目录不支持直接删除整个文件夹)。", "deleteFiles": "同时删除客户端文件夹 {{path}}", + "deleteHardlinkHint": "提示:此客户端使用同盘硬链接共享资源包,删除副本文件夹不会影响原版游戏目录。", "deleteFilesWarning": "将永久删除客户端副本文件夹 {{path}} 中的全部文件,此操作无法撤销。", + "deleteHardlinkWarning": "将永久删除硬链接副本文件夹 {{path}} 中的全部文件(不会影响原版游戏目录),此操作无法撤销。", + "restoreStock": "还原为原版并清理离线补丁文件(保留游戏本体)", + "restoreStockHint": "将从 wtoffline\\stock 恢复原版 4 个核心文件,并删除 wtoffline\\ 目录与网络钩子文件(wto_ws.dll / wto_ws.cfg / wto_ws.log),绝不删除其他游戏本体文件。", "deleteData": "同时删除数据文件夹 {{path}}(包含存档、配置与日志)", + "openFolder": "打开所在文件夹", "confirmRemove": "从列表移除", + "confirmRestore": "还原并移除", "confirmDelete": "确认删除", "phase": { "checking": "正在检查客户端", diff --git a/apps/launcher/src/renderer/src/pages/copies/CopyMaintenance.tsx b/apps/launcher/src/renderer/src/pages/copies/CopyMaintenance.tsx index 5e352dc..48634c3 100644 --- a/apps/launcher/src/renderer/src/pages/copies/CopyMaintenance.tsx +++ b/apps/launcher/src/renderer/src/pages/copies/CopyMaintenance.tsx @@ -65,6 +65,7 @@ export function CopyMaintenance({ record, maintenance, onError }: CopyMaintenanc options={removal} onOptionsChange={setRemoval} onRemove={(options) => run('delete', options)} + onOpenFolder={() => { ipcInvoke('app:openFolder', { path: record.copyPath }).catch(onError); }} /> {active && } {result &&

{t(`copies.maintenance.result.${result}`)}

} diff --git a/apps/launcher/src/renderer/src/pages/copies/CopyMaintenanceControls.tsx b/apps/launcher/src/renderer/src/pages/copies/CopyMaintenanceControls.tsx index 65cb9be..f8c7a7f 100644 --- a/apps/launcher/src/renderer/src/pages/copies/CopyMaintenanceControls.tsx +++ b/apps/launcher/src/renderer/src/pages/copies/CopyMaintenanceControls.tsx @@ -70,6 +70,7 @@ export function CopyMaintenanceActions({ record, info, busy, onRun, onChooseSour export interface CopyRemovalOptions { readonly deleteFiles: boolean; + readonly restoreStock: boolean; readonly deleteData: boolean; } @@ -77,24 +78,44 @@ interface CopyRemovalProps extends CopyMaintenanceControlsProps { readonly options: CopyRemovalOptions | null; readonly onOptionsChange: (options: CopyRemovalOptions | null) => void; readonly onRemove: (options: CopyRemovalOptions) => void; + readonly onOpenFolder: () => void; } -export function CopyRemoval({ record, info, busy, options, onOptionsChange, onRemove }: CopyRemovalProps) { +function clientOriginNoteKey(info: MaintenanceInfo): string { + if (info.clientOrigin === 'copy') return 'copies.maintenance.originCopy'; + if (info.clientOrigin === 'hardlink') return 'copies.maintenance.originHardlink'; + if (info.clientOrigin === 'in-place') return 'copies.maintenance.originInPlace'; + return info.hasHardlinkedResources + ? 'copies.maintenance.originUnknownHardlinked' + : 'copies.maintenance.originUnknown'; +} + +export function CopyRemoval({ record, info, busy, options, onOptionsChange, onRemove, onOpenFolder }: CopyRemovalProps) { const { t } = useTranslation(); const steam = info?.steamLocations; const copyInSteam = steam?.copyInSteam === true; const dataInSteam = steam?.dataInSteam === true; - const canDeleteFiles = info !== null && record.method === 'copy' && !copyInSteam; + const canDeleteFiles = info?.canDeleteFiles === true; + const isHardlinkCopy = info?.clientOrigin === 'hardlink'; + const canRestoreAndRemove = info !== null && !canDeleteFiles && info.canRestoreAndRemove; const canDeleteData = info !== null && !copyInSteam && !dataInSteam; const willDeleteFiles = canDeleteFiles && options?.deleteFiles === true; + const willRestoreStock = canRestoreAndRemove && options?.restoreStock === true; const willDeleteData = canDeleteData && options?.deleteData === true; - const willDeleteAny = willDeleteFiles || willDeleteData; - const action = t(willDeleteAny ? 'copies.maintenance.confirmDelete' : 'copies.maintenance.confirmRemove'); + const action = t( + willDeleteFiles || willDeleteData + ? 'copies.maintenance.confirmDelete' + : willRestoreStock + ? 'copies.maintenance.confirmRestore' + : 'copies.maintenance.confirmRemove', + ); const rowHint = copyInSteam ? t('copies.maintenance.removeSteamHint') - : record.method === 'copy' + : canDeleteFiles ? t('copies.maintenance.removeCopyHint') - : t('copies.maintenance.removeUnlinkHint'); + : canRestoreAndRemove + ? t('copies.maintenance.removeRestoreHint') + : t('copies.maintenance.removeUnlinkHint'); const confirmNotice = copyInSteam ? t('copies.maintenance.removeSteamNotice', { path: steam?.copyPath ?? record.copyPath }) : canDeleteFiles @@ -105,25 +126,39 @@ export function CopyRemoval({ record, info, busy, options, onOptionsChange, onRe <> {options && (

{confirmNotice}

+ {info &&

{t(clientOriginNoteKey(info))}

} {canDeleteFiles && ( - + <> + + {isHardlinkCopy &&

{t('copies.maintenance.deleteHardlinkHint')}

} + )} {willDeleteFiles && ( -

{t('copies.maintenance.deleteFilesWarning', { path: record.copyPath })}

+

{t(isHardlinkCopy ? 'copies.maintenance.deleteHardlinkWarning' : 'copies.maintenance.deleteFilesWarning', { path: record.copyPath })}

)} + {canRestoreAndRemove && ( + <> + +

{t('copies.maintenance.restoreStockHint')}

+ + )} {canDeleteData && (