機能改善: 高速スキャン連携とインメモリプレフィルタによるゲーム検出処理の統合
Everything -> NTFS MFT -> 通常走査の順でフォールバックするパイプラインを構築し、インメモリプレフィルタにより無関係なフォルダのディスクI/Oを排除してゲーム検出を劇的に高速化しました。UIログにも適用エンジンを表示します。
This commit is contained in:
1 parent
4c94cf814f
commit
dd00c96e20
2 files changed
+152
-14
No files matched your search
@@ -447,6 +447,13 @@ namespace GameLauncher
|
|||||||
this.lblStatusEngine.Text = status;
|
this.lblStatusEngine.Text = status;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
onLogMessage: log =>
|
||||||
|
{
|
||||||
|
this.Dispatcher.Invoke(() =>
|
||||||
|
{
|
||||||
|
this.AppendLog(log);
|
||||||
|
});
|
||||||
|
},
|
||||||
ct: ct);
|
ct: ct);
|
||||||
|
|
||||||
// キャッシュの最終同期(削除されたゲームのブックマークもここで除去する)
|
// キャッシュの最終同期(削除されたゲームのブックマークもここで除去する)
|
||||||
|
|||||||
+145
-14
@@ -944,12 +944,15 @@ namespace GameLauncher.Services
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 指定されたフォルダ一覧からツクール・ティラノ・Unityゲームを非同期で走査・検出します。
|
/// 指定されたフォルダ一覧からツクール・ティラノ・Unityゲームを非同期で走査・検出します。
|
||||||
|
/// Everything IPC または NTFS MFT (USN Journal) 直接読み取りを利用して爆速インデックスを生成し、
|
||||||
|
/// インメモリプレフィルタによりディスクI/Oを極限まで抑えて高速検出します。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public async Task ScanDirectoriesAsync(
|
public async Task ScanDirectoriesAsync(
|
||||||
IEnumerable<string> targetPaths,
|
IEnumerable<string> targetPaths,
|
||||||
IProgress<GameItemBase> progress,
|
IProgress<GameItemBase> progress,
|
||||||
HashSet<string> existingPaths,
|
HashSet<string> existingPaths,
|
||||||
Action<string>? onStatusUpdated = null,
|
Action<string>? onStatusUpdated = null,
|
||||||
|
Action<string>? onLogMessage = null,
|
||||||
CancellationToken ct = default)
|
CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
await Task.Run(() =>
|
await Task.Run(() =>
|
||||||
@@ -960,6 +963,63 @@ namespace GameLauncher.Services
|
|||||||
MaxDegreeOfParallelism = Math.Clamp(Environment.ProcessorCount * 2, 4, 16)
|
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)
|
foreach (var targetPath in targetPaths)
|
||||||
{
|
{
|
||||||
if (ct.IsCancellationRequested) break;
|
if (ct.IsCancellationRequested) break;
|
||||||
@@ -969,7 +1029,14 @@ namespace GameLauncher.Services
|
|||||||
List<string> subDirs;
|
List<string> subDirs;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
subDirs = [.. Directory.EnumerateDirectories(targetPath)];
|
if (snapshot != null && snapshot.DirectoryExists(targetPath))
|
||||||
|
{
|
||||||
|
subDirs = [.. snapshot.GetDirectories(targetPath)];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
subDirs = [.. Directory.EnumerateDirectories(targetPath)];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@@ -993,22 +1060,34 @@ namespace GameLauncher.Services
|
|||||||
}
|
}
|
||||||
if (isExisting) return;
|
if (isExisting) return;
|
||||||
|
|
||||||
// ディレクトリ直下のゲームを検出
|
// スナップショットが存在する場合はインメモリプレフィルタでゲーム候補か判定
|
||||||
var game = this.DetectGameInDirectory(dir);
|
if (snapshot == null || HasPotentialGameContent(dir, snapshot))
|
||||||
if (game != null)
|
|
||||||
{
|
{
|
||||||
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階層下も探索(アーカイブ解凍等でサブフォルダが入っているケース)
|
// 1階層下も探索(アーカイブ解凍等でサブフォルダが入っているケース)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var childDirs = Directory.EnumerateDirectories(dir);
|
IEnumerable<string> childDirs;
|
||||||
|
if (snapshot != null && snapshot.DirectoryExists(dir))
|
||||||
|
{
|
||||||
|
childDirs = snapshot.GetDirectories(dir);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
childDirs = Directory.EnumerateDirectories(dir);
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var childDir in childDirs)
|
foreach (var childDir in childDirs)
|
||||||
{
|
{
|
||||||
if (ct.IsCancellationRequested) break;
|
if (ct.IsCancellationRequested) break;
|
||||||
@@ -1020,14 +1099,17 @@ namespace GameLauncher.Services
|
|||||||
}
|
}
|
||||||
if (isChildExisting) continue;
|
if (isChildExisting) continue;
|
||||||
|
|
||||||
var childGame = this.DetectGameInDirectory(childDir);
|
if (snapshot == null || HasPotentialGameContent(childDir, snapshot))
|
||||||
if (childGame != null)
|
|
||||||
{
|
{
|
||||||
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);
|
}, ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// スナップショットのメモリ情報を用いて、対象フォルダがゲームファイルを含む可能性があるか高速判定します。
|
||||||
|
/// </summary>
|
||||||
|
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;
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 1つのディレクトリ内にツクール・ティラノまたはUnityゲームが存在するか判定し、対応するアイテムを生成します。
|
/// 1つのディレクトリ内にツクール・ティラノまたはUnityゲームが存在するか判定し、対応するアイテムを生成します。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in new issue
Block a user