feat(scanner): 起動時フリーズ解消(完全非同期化)とステータスバー最下部プログレスバー連携

This commit is contained in:
armonica committed 2026-10-20 10:56:42 +09:00
1 parent 6447fc2635
commit dc03f5284a
3 files changed
+82 -69

No files matched your search

+2 -1
View File
@@ -1400,7 +1400,7 @@
<!-- 処理中プログレス表示エリア -->
<StackPanel Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center" Margin="10,0,16,0">
<ProgressBar x:Name="pbGlobalProgress" Width="150" Height="8" Minimum="0" Maximum="100" Visibility="Collapsed"
<ProgressBar x:Name="pbGlobalProgress" Width="180" Height="10" Minimum="0" Maximum="100" Visibility="Collapsed"
Background="#222233" Foreground="{StaticResource AccentPrimary}" BorderThickness="0" Margin="0,0,8,0"/>
<TextBlock x:Name="lblGlobalProgressText" Text="" FontSize="11" Foreground="{StaticResource AccentGreen}" VerticalAlignment="Center" Visibility="Collapsed"/>
</StackPanel>
@@ -1410,3 +1410,4 @@
</Border>
</Grid>
</Window>
+67 -7
View File
@@ -284,12 +284,19 @@ namespace GameLauncher
this.AppendLog("統合ゲームランチャー (Game Launcher) を起動しました。");
// 0. ツクール改造プラグインの動的検出
this._modService.LoadAvailablePlugins();
// プログレスバーの初期表示
this.pbGlobalProgress.Visibility = Visibility.Visible;
this.pbGlobalProgress.IsIndeterminate = true;
this.lblGlobalProgressText.Visibility = Visibility.Visible;
this.lblGlobalProgressText.Text = "キャッシュ読み込み中...";
this.lblStatusEngine.Text = "キャッシュ読み込み中...";
// 0. ツクール改造プラグインの動的検出(裏で実行しUIフリーズを回避)
await Task.Run(() => this._modService.LoadAvailablePlugins());
this.AppendLog($"ツクールプラグインフォルダから {this._modService.AvailablePlugins.Count} 件のプラグインを認識しました。");
// 1. キャッシュから全ゲームを瞬時にロードし、0秒で一覧に表示
var cached = this._scannerService.LoadCachedGamesFast();
// 1. キャッシュから全ゲームをバックグラウンドで瞬時にロード
var cached = await Task.Run(() => this._scannerService.LoadCachedGamesFast());
foreach (var item in cached)
{
if (item is TkoolGameItem tg)
@@ -303,6 +310,19 @@ namespace GameLauncher
this._gamesView.Refresh();
this.UpdateStatusLabels();
// サムネイルキャッシュが存在するものをバックグラウンド並列で即時適用(待たずに即時反映)
_ = Task.Run(() =>
{
Parallel.ForEach(cached, new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount }, item =>
{
var thumb = GameScannerService.LoadCachedThumbnailFast(item.ExecutablePath, item.RootDirectory);
if (thumb != null)
{
item.IconImage = thumb;
}
});
});
if (this._games.Count > 0)
{
int tkoolCount = this._games.Count(g => g is TkoolGameItem tg && tg.EngineType != TkoolEngineType.Tyrano && !tg.IsRgss && !tg.IsWolf && !tg.IsSrpgStudio && !tg.IsNwjs);
@@ -314,7 +334,7 @@ namespace GameLauncher
int unityCount = this._games.Count(g => g is UnityGameItem);
this.AppendLog($"キャッシュから計 {this._games.Count} 件(ツクールMV/MZ: {tkoolCount}, ツクールVX系: {rgssCount}, ティラノ: {tyranoCount}, ウディタ: {wolfCount}, SRPG Studio: {srpgCount}, NW.js: {nwjsCount}, Unity: {unityCount})を即時表示しました。(待たずに即起動可能です)");
this.lblStatusEngine.Text = "裏で更新・実在検証を実行中...";
this.lblStatusEngine.Text = "実在検証を実行中...";
}
else
{
@@ -335,10 +355,17 @@ namespace GameLauncher
try
{
this.lblLogActivity.Text = "● スキャン中...";
this.pbGlobalProgress.Visibility = Visibility.Visible;
this.lblGlobalProgressText.Visibility = Visibility.Visible;
// 2-1. 実在検証 & アイコン・セーブ情報エンリッチ
if (this._games.Count > 0)
{
this.pbGlobalProgress.IsIndeterminate = false;
this.pbGlobalProgress.Maximum = this._games.Count;
this.pbGlobalProgress.Value = 0;
this.lblGlobalProgressText.Text = $"実在検証中... (0/{this._games.Count})";
await this._scannerService.VerifyAndEnrichGamesAsync(
[.. this._games],
onGameUpdated: game =>
@@ -360,6 +387,17 @@ namespace GameLauncher
this.UpdateStatusLabels();
});
},
onProgress: (current, total, message) =>
{
this.Dispatcher.Invoke(() =>
{
this.pbGlobalProgress.IsIndeterminate = false;
this.pbGlobalProgress.Maximum = total;
this.pbGlobalProgress.Value = current;
this.lblGlobalProgressText.Text = message;
this.lblStatusEngine.Text = $"実在検証中 ({current * 100 / Math.Max(1, total)}%)";
});
},
ct: ct);
}
@@ -370,6 +408,10 @@ namespace GameLauncher
targetDirs.AddRange(this._config.TargetDirectories);
}
this.pbGlobalProgress.IsIndeterminate = true;
this.lblGlobalProgressText.Text = "新規ゲーム走査中...";
this.lblStatusEngine.Text = "新規フォルダ走査中...";
var progress = new Progress<GameItemBase>(newGame =>
{
this.Dispatcher.Invoke(() =>
@@ -393,28 +435,45 @@ namespace GameLauncher
});
});
await this._scannerService.ScanDirectoriesAsync(targetDirs, progress, this._scannedPaths, ct);
await this._scannerService.ScanDirectoriesAsync(
targetDirs,
progress,
this._scannedPaths,
onStatusUpdated: status =>
{
this.Dispatcher.Invoke(() =>
{
this.lblGlobalProgressText.Text = status;
this.lblStatusEngine.Text = status;
});
},
ct: ct);
// キャッシュの最終同期(削除されたゲームのブックマークもここで除去する)
this._scannerService.SaveCache(this._games);
this._scannerService.SaveBookmarks(this._games);
this.lblStatusEngine.Text = "準備完了";
this.lblLogActivity.Text = "";
this.pbGlobalProgress.Visibility = Visibility.Collapsed;
this.lblGlobalProgressText.Visibility = Visibility.Collapsed;
this.AppendLog($"スキャンが完了しました。総ゲーム数: {this._games.Count} 件。");
}
catch (OperationCanceledException)
{
this.lblStatusEngine.Text = "スキャン中断";
this.lblLogActivity.Text = "";
this.pbGlobalProgress.Visibility = Visibility.Collapsed;
this.lblGlobalProgressText.Visibility = Visibility.Collapsed;
}
catch (Exception ex)
{
this.lblStatusEngine.Text = "スキャンエラー";
this.lblLogActivity.Text = "";
this.pbGlobalProgress.Visibility = Visibility.Collapsed;
this.lblGlobalProgressText.Visibility = Visibility.Collapsed;
this.AppendLog($"スキャン中にエラーが発生しました: {ex.Message}");
}
}
private async void btnRescan_Click(object sender, RoutedEventArgs e)
{
this.btnRescan.IsEnabled = false;
@@ -2143,3 +2202,4 @@ namespace GameLauncher
#endregion
}
}
+13 -61
View File
@@ -229,67 +229,8 @@ namespace GameLauncher.Services
item.PluginSettings = new Dictionary<string, bool>(entry.PluginSettings, StringComparer.OrdinalIgnoreCase);
}
// 既存キャッシュの自動修復: ウディタの誤判定を修正
if (item.EngineType is TkoolEngineType.VX or TkoolEngineType.VXAce && HasWolfGame(item.RootDirectory, out var wolfDir))
{
item.EngineType = TkoolEngineType.Wolf;
item.HasRgssArchive = false;
item.IsRgssExtracted = false;
item.RgssArchivePath = null;
item.PluginsJsPath = string.Empty;
item.PluginsDirPath = string.Empty;
item.HasWolfArchive = File.Exists(Path.Combine(wolfDir, "Data.wolf")) ||
(Directory.Exists(wolfDir) && Directory.GetFiles(wolfDir, "*.wolf", SearchOption.TopDirectoryOnly).Length > 0);
item.IsWolfExtracted = Directory.Exists(Path.Combine(wolfDir, "Data"));
item.WolfProxyDll = File.Exists(Path.Combine(wolfDir, WolfModService.ProxyDllName));
item.IsModded = item.WolfProxyDll;
}
// 既存キャッシュの自動修復: SRPG Studio の誤判定 (VX/VXAce) を修正
if (item.EngineType is TkoolEngineType.VX or TkoolEngineType.VXAce && HasSrpgStudioGame(item.RootDirectory, out var srpgDir))
{
item.EngineType = TkoolEngineType.SrpgStudio;
item.HasRgssArchive = false;
item.IsRgssExtracted = false;
item.RgssArchivePath = null;
item.PluginsJsPath = string.Empty;
item.PluginsDirPath = string.Empty;
item.HasSrpgArchive = File.Exists(Path.Combine(srpgDir, "data.dts"));
item.IsSrpgExtracted = Directory.Exists(Path.Combine(srpgDir, "data_extracted")) || (Directory.Exists(Path.Combine(srpgDir, "Script")) && Directory.Exists(Path.Combine(srpgDir, "Plugin")));
item.SrpgArchivePath = item.HasSrpgArchive ? Path.Combine(srpgDir, "data.dts") : null;
item.SrpgProxyDll = File.Exists(Path.Combine(srpgDir, SrpgModService.ProxyDllName));
item.IsModded = item.SrpgProxyDll || SrpgModService.IsModScriptApplied(srpgDir);
}
// 既存キャッシュの自動修復: 文字化けタイトルの復元
if (item.EngineType is TkoolEngineType.VX or TkoolEngineType.VXAce)
{
if (item.Title.Contains('\uFFFD') || item.Title.Contains("◆G◆"))
{
FixRgssTitleFromIni(item);
}
}
// 既存キャッシュの自動修復: 実際にEVBで圧縮され解凍可能なもののみ IsEvbPacked を維持
if (Directory.Exists(item.RootDirectory))
{
string? actualEvbOutDir = null;
bool actualEvb = EvbDetector.IsEvbGame(item.RootDirectory);
bool actualEvbExtracted = actualEvb && EvbUnpackService.IsExtractionComplete(item.RootDirectory, out actualEvbOutDir);
item.IsEvbPacked = actualEvb;
item.IsEvbExtracted = actualEvbExtracted;
if (!actualEvb)
{
item.EvbExtractedDirPath = null;
item.EvbBackupPath = null;
item.EvbUnderlyingEngine = string.Empty;
}
else if (actualEvbExtracted && !string.IsNullOrEmpty(actualEvbOutDir))
{
item.EvbExtractedDirPath = actualEvbOutDir;
}
}
// 起動時のUIブロックを防ぐため、ディスクI/O(実在検証・誤判定修正)はバックグラウンドの
// VerifyAndEnrichGamesAsync に任せ、ここではキャッシュJSONから純粋にメモリ復元します。
list.Add(item);
}
}
@@ -663,6 +604,7 @@ namespace GameLauncher.Services
List<GameItemBase> games,
Action<GameItemBase> onGameUpdated,
Action<GameItemBase> onGameRemoved,
Action<int, int, string>? onProgress = null,
CancellationToken ct = default)
{
await Task.Run(() =>
@@ -670,8 +612,16 @@ namespace GameLauncher.Services
var copyList = games.ToList();
bool cacheNeedsSave = false;
int total = copyList.Count;
int processed = 0;
foreach (var game in copyList)
{
processed++;
if (onProgress != null && (processed % 5 == 0 || processed == total))
{
onProgress(processed, total, $"実在検証中... ({processed}/{total})");
}
if (ct.IsCancellationRequested) break;
// 実在検証
@@ -999,6 +949,7 @@ namespace GameLauncher.Services
IEnumerable<string> targetPaths,
IProgress<GameItemBase> progress,
HashSet<string> existingPaths,
Action<string>? onStatusUpdated = null,
CancellationToken ct = default)
{
await Task.Run(() =>
@@ -1013,6 +964,7 @@ namespace GameLauncher.Services
{
if (ct.IsCancellationRequested) break;
if (!Directory.Exists(targetPath)) continue;
onStatusUpdated?.Invoke($"新規フォルダ走査中: {Path.GetFileName(targetPath.TrimEnd('\\', '/'))}...");
List<string> subDirs;
try