From dd00c96e202b4ed468a3e0a315ff54090fb9b826 Mon Sep 17 00:00:00 2001 From: uduki Date: Tue, 20 Oct 2026 11:30:13 +0900 Subject: [PATCH] =?UTF-8?q?=E6=A9=9F=E8=83=BD=E6=94=B9=E5=96=84:=20?= =?UTF-8?q?=E9=AB=98=E9=80=9F=E3=82=B9=E3=82=AD=E3=83=A3=E3=83=B3=E9=80=A3?= =?UTF-8?q?=E6=90=BA=E3=81=A8=E3=82=A4=E3=83=B3=E3=83=A1=E3=83=A2=E3=83=AA?= =?UTF-8?q?=E3=83=97=E3=83=AC=E3=83=95=E3=82=A3=E3=83=AB=E3=82=BF=E3=81=AB?= =?UTF-8?q?=E3=82=88=E3=82=8B=E3=82=B2=E3=83=BC=E3=83=A0=E6=A4=9C=E5=87=BA?= =?UTF-8?q?=E5=87=A6=E7=90=86=E3=81=AE=E7=B5=B1=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Everything -> NTFS MFT -> 通常走査の順でフォールバックするパイプラインを構築し、インメモリプレフィルタにより無関係なフォルダのディスクI/Oを排除してゲーム検出を劇的に高速化しました。UIログにも適用エンジンを表示します。 --- MainWindow.xaml.cs | 7 ++ Services/GameScannerService.cs | 159 ++++++++++++++++++++++++++++++--- 2 files changed, 152 insertions(+), 14 deletions(-) diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index f208534..b3139fa 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -447,6 +447,13 @@ namespace GameLauncher this.lblStatusEngine.Text = status; }); }, + onLogMessage: log => + { + this.Dispatcher.Invoke(() => + { + this.AppendLog(log); + }); + }, ct: ct); // キャッシュの最終同期(削除されたゲームのブックマークもここで除去する) diff --git a/Services/GameScannerService.cs b/Services/GameScannerService.cs index 0201f59..3ef1add 100644 --- a/Services/GameScannerService.cs +++ b/Services/GameScannerService.cs @@ -944,12 +944,15 @@ namespace GameLauncher.Services /// /// 指定されたフォルダ一覧からツクール・ティラノ・Unityゲームを非同期で走査・検出します。 + /// Everything IPC または NTFS MFT (USN Journal) 直接読み取りを利用して爆速インデックスを生成し、 + /// インメモリプレフィルタによりディスクI/Oを極限まで抑えて高速検出します。 /// public async Task ScanDirectoriesAsync( IEnumerable targetPaths, IProgress progress, HashSet existingPaths, Action? onStatusUpdated = null, + Action? onLogMessage = null, CancellationToken ct = default) { await Task.Run(() => @@ -960,6 +963,63 @@ namespace GameLauncher.Services MaxDegreeOfParallelism = Math.Clamp(Environment.ProcessorCount * 2, 4, 16) }; + // 1. Everything / NTFS MFT による超高速スナップショット取得 + FastDirectorySnapshot? snapshot = null; + string engineName = string.Empty; + + if (EverythingSearchService.IsEverythingRunning()) + { + onStatusUpdated?.Invoke("Everything IPCによる高速スキャンを実行中..."); + try + { + snapshot = EverythingSearchService.TryScanTargetsFast(targetPaths); + if (snapshot != null && (snapshot.TotalDirectoryCount > 0 || snapshot.TotalFileCount > 0)) + { + engineName = "Everything (IPC高速走査)"; + } + else + { + snapshot = null; + } + } + catch + { + snapshot = null; + } + } + + if (snapshot == null) + { + onStatusUpdated?.Invoke("NTFS MFT (USN Journal) による高速スキャンを実行中..."); + try + { + snapshot = NtfsMftScanService.TryScanTargetsFast(targetPaths); + if (snapshot != null && (snapshot.TotalDirectoryCount > 0 || snapshot.TotalFileCount > 0)) + { + engineName = "NTFS MFT直接読み取り (USN Journal高速走査)"; + } + else + { + snapshot = null; + } + } + catch + { + snapshot = null; + } + } + + if (snapshot != null) + { + onStatusUpdated?.Invoke($"高速インデックス取得完了 ({engineName}): {snapshot.TotalDirectoryCount} フォルダ / {snapshot.TotalFileCount} ファイル"); + onLogMessage?.Invoke($"高速ファイルシステムインデックス [{engineName}] を取得しました({snapshot.TotalDirectoryCount} ディレクトリ, {snapshot.TotalFileCount} ファイル)。"); + } + else + { + onStatusUpdated?.Invoke("通常ディレクトリ走査を実行中..."); + onLogMessage?.Invoke("標準の並列ディレクトリ走査を実行します。"); + } + foreach (var targetPath in targetPaths) { if (ct.IsCancellationRequested) break; @@ -969,7 +1029,14 @@ namespace GameLauncher.Services List subDirs; try { - subDirs = [.. Directory.EnumerateDirectories(targetPath)]; + if (snapshot != null && snapshot.DirectoryExists(targetPath)) + { + subDirs = [.. snapshot.GetDirectories(targetPath)]; + } + else + { + subDirs = [.. Directory.EnumerateDirectories(targetPath)]; + } } catch { @@ -993,22 +1060,34 @@ namespace GameLauncher.Services } if (isExisting) return; - // ディレクトリ直下のゲームを検出 - var game = this.DetectGameInDirectory(dir); - if (game != null) + // スナップショットが存在する場合はインメモリプレフィルタでゲーム候補か判定 + if (snapshot == null || HasPotentialGameContent(dir, snapshot)) { - lock (existingPaths) + var game = this.DetectGameInDirectory(dir); + if (game != null) { - existingPaths.Add(dir); + lock (existingPaths) + { + existingPaths.Add(dir); + } + progress.Report(game); + return; } - progress.Report(game); - return; } // 1階層下も探索(アーカイブ解凍等でサブフォルダが入っているケース) try { - var childDirs = Directory.EnumerateDirectories(dir); + IEnumerable childDirs; + if (snapshot != null && snapshot.DirectoryExists(dir)) + { + childDirs = snapshot.GetDirectories(dir); + } + else + { + childDirs = Directory.EnumerateDirectories(dir); + } + foreach (var childDir in childDirs) { if (ct.IsCancellationRequested) break; @@ -1020,14 +1099,17 @@ namespace GameLauncher.Services } if (isChildExisting) continue; - var childGame = this.DetectGameInDirectory(childDir); - if (childGame != null) + if (snapshot == null || HasPotentialGameContent(childDir, snapshot)) { - lock (existingPaths) + var childGame = this.DetectGameInDirectory(childDir); + if (childGame != null) { - existingPaths.Add(childDir); + lock (existingPaths) + { + existingPaths.Add(childDir); + } + progress.Report(childGame); } - progress.Report(childGame); } } } @@ -1042,6 +1124,55 @@ namespace GameLauncher.Services }, ct); } + /// + /// スナップショットのメモリ情報を用いて、対象フォルダがゲームファイルを含む可能性があるか高速判定します。 + /// + private static bool HasPotentialGameContent(string dirPath, FastDirectorySnapshot snapshot) + { + var normalized = dirPath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); + + // 1. 直下のファイル群をメモリ上でチェック + if (snapshot.FilesByDir.TryGetValue(normalized, out var files)) + { + foreach (var f in files) + { + if (f.EndsWith(".exe", StringComparison.OrdinalIgnoreCase) || + f.EndsWith(".wolf", StringComparison.OrdinalIgnoreCase) || + f.EndsWith(".rgss3a", StringComparison.OrdinalIgnoreCase) || + f.EndsWith(".rgss2a", StringComparison.OrdinalIgnoreCase) || + f.EndsWith(".rgssad", StringComparison.OrdinalIgnoreCase) || + f.EndsWith(".html", StringComparison.OrdinalIgnoreCase) || + f.EndsWith(".htm", StringComparison.OrdinalIgnoreCase) || + f.Equals("package.json", StringComparison.OrdinalIgnoreCase) || + f.Equals("Game.ini", StringComparison.OrdinalIgnoreCase) || + f.Equals("UnityPlayer.dll", StringComparison.OrdinalIgnoreCase) || + f.Equals("data.xp3", StringComparison.OrdinalIgnoreCase)) + { + return true; + } + } + } + + // 2. 直下のサブディレクトリ名をメモリ上でチェック + if (snapshot.SubDirsByDir.TryGetValue(normalized, out var subDirs)) + { + foreach (var sub in subDirs) + { + var name = Path.GetFileName(sub); + if (name.Equals("data", StringComparison.OrdinalIgnoreCase) || + name.Equals("tyrano", StringComparison.OrdinalIgnoreCase) || + name.Equals("www", StringComparison.OrdinalIgnoreCase) || + name.EndsWith("_Data", StringComparison.OrdinalIgnoreCase) || + name.Equals("BasicData", StringComparison.OrdinalIgnoreCase) || + name.Equals("System", StringComparison.OrdinalIgnoreCase)) + { + return true; + } + } + } + + return false; + } /// /// 1つのディレクトリ内にツクール・ティラノまたはUnityゲームが存在するか判定し、対応するアイテムを生成します。 ///