diff --git a/Services/GameScannerService.cs b/Services/GameScannerService.cs index fdae989..544aca8 100644 --- a/Services/GameScannerService.cs +++ b/Services/GameScannerService.cs @@ -2979,6 +2979,43 @@ namespace GameLauncher.Services /// 実行ファイルまたはフォルダからアプリアイコン・サムネイルを取得します。 /// exeと同階層のThumbnailsフォルダにPNG画像としてキャッシュし、2回目以降は超高速に表示します。 /// + /// + /// Thumbnails フォルダからハッシュに対応するキャッシュ画像を瞬時に取得します。 + /// 存在しない場合はディスクのアイコン抽出を行わず即座に null を返します(起動時の即時サムネイル表示用)。 + /// + public static ImageSource? LoadCachedThumbnailFast(string? exePath, string? fallbackDir = null) + { + var keyPath = !string.IsNullOrEmpty(exePath) ? exePath : fallbackDir; + if (string.IsNullOrEmpty(keyPath)) + { + return null; + } + + try + { + var thumbDir = AppPathHelper.GetThumbnailsDirectory(); + using var md5 = System.Security.Cryptography.MD5.Create(); + var hashBytes = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(keyPath.ToLowerInvariant())); + var hashStr = Convert.ToHexString(hashBytes); + var thumbPath = Path.Combine(thumbDir, $"{hashStr}.png"); + + if (File.Exists(thumbPath)) + { + var bmp = new BitmapImage(); + bmp.BeginInit(); + bmp.UriSource = new Uri(thumbPath); + bmp.CacheOption = BitmapCacheOption.OnLoad; + bmp.DecodePixelWidth = 88; + bmp.EndInit(); + bmp.Freeze(); + return bmp; + } + } + catch { } + + return null; + } + public static ImageSource? LoadIcon(string? exePath, string? fallbackDir = null) { var keyPath = !string.IsNullOrEmpty(exePath) ? exePath : fallbackDir; @@ -3003,6 +3040,7 @@ namespace GameLauncher.Services bmp.BeginInit(); bmp.UriSource = new Uri(thumbPath); bmp.CacheOption = BitmapCacheOption.OnLoad; + bmp.DecodePixelWidth = 88; bmp.EndInit(); bmp.Freeze(); return bmp;