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

+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
}
}