feat(perf): サムネイルキャッシュの即時ロードおよびデコード負荷極小化の実装
This commit is contained in:
1 parent
ec4d718311
commit
6447fc2635
1 file changed
+38
@@ -2979,6 +2979,43 @@ namespace GameLauncher.Services
|
|||||||
/// 実行ファイルまたはフォルダからアプリアイコン・サムネイルを取得します。
|
/// 実行ファイルまたはフォルダからアプリアイコン・サムネイルを取得します。
|
||||||
/// exeと同階層のThumbnailsフォルダにPNG画像としてキャッシュし、2回目以降は超高速に表示します。
|
/// exeと同階層のThumbnailsフォルダにPNG画像としてキャッシュし、2回目以降は超高速に表示します。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <summary>
|
||||||
|
/// Thumbnails フォルダからハッシュに対応するキャッシュ画像を瞬時に取得します。
|
||||||
|
/// 存在しない場合はディスクのアイコン抽出を行わず即座に null を返します(起動時の即時サムネイル表示用)。
|
||||||
|
/// </summary>
|
||||||
|
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)
|
public static ImageSource? LoadIcon(string? exePath, string? fallbackDir = null)
|
||||||
{
|
{
|
||||||
var keyPath = !string.IsNullOrEmpty(exePath) ? exePath : fallbackDir;
|
var keyPath = !string.IsNullOrEmpty(exePath) ? exePath : fallbackDir;
|
||||||
@@ -3003,6 +3040,7 @@ namespace GameLauncher.Services
|
|||||||
bmp.BeginInit();
|
bmp.BeginInit();
|
||||||
bmp.UriSource = new Uri(thumbPath);
|
bmp.UriSource = new Uri(thumbPath);
|
||||||
bmp.CacheOption = BitmapCacheOption.OnLoad;
|
bmp.CacheOption = BitmapCacheOption.OnLoad;
|
||||||
|
bmp.DecodePixelWidth = 88;
|
||||||
bmp.EndInit();
|
bmp.EndInit();
|
||||||
bmp.Freeze();
|
bmp.Freeze();
|
||||||
return bmp;
|
return bmp;
|
||||||
|
|||||||
Reference in new issue
Block a user