ファイル
YMM4-ProxyForge/ZeroDiskProxy/ViewModels/SettingsViewModel.cs
T
routersys b9b0e1c2de 全UIテキストの多言語対応とYukkuriMovieMaker.Generatorサブモジュール導入による国際化基盤整備
全UIテキストをハードコードされた日本語文字列からTranslateクラス経由の多言語対応リソースへ完全移行しました。
YukkuriMovieMaker.Generatorをgitサブモジュールとして追加しソリューションファイルに組み込み、ソースジェネレータによるローカライズクラス自動生成の基盤を整えました。
ZeroDiskProxy/Localization/ディレクトリを新設し、[AutoGenLocalizer]属性を持つpartialクラスTranslateをTexts.csに定義しました。
.gitmodulesにYukkuriMovieMaker.GeneratorのGitHubリポジトリURLを登録し、サブモジュールとして管理します。
ZeroDiskProxy.slnxにYukkuriMovieMaker.Generatorプロジェクトを追加しました。
ProxyCacheManagerのプロキシ生成完了・キャンセル・失敗時のステータスメッセージをそれぞれTranslate.ProxyGenerationStatusCompleted・Translate.ProxyGenerationStatusCanceled・Translate.ProxyGenerationStatusFailedPrefixに置換しました。
ProxyGenerationItemの初期ステータス文字列をTranslate.ProxyGenerationStatusGeneratingに、格納先表示をTranslate.StorageMemory・Translate.StorageDiskに置換しました。
ZeroDiskProxySettings.NameプロパティをリテラルからTranslate.SettingsNameに変更しました。
SettingsViewModelの初期キャッシュ概要テキストをTranslate.CacheSummaryLoadingに変更しました。
キャッシュ削除ダイアログのメッセージをstring.Concatからstring.Format(Translate.CacheNoEntriesToDelete)およびstring.Format(Translate.CacheDeleteSummaryFormat, ...)に変更しました。
ダイアログタイトルをリテラルからTranslate.AppNameに変更しました。
プラグイン未初期化メッセージ・キャッシュ件数表示・メモリおよびディスク使用量表示・割当済メモリ表示をいずれもstring.FormatとTranslateキーに置き換えました。
CacheEntryViewModelのストレージ種別表示をTranslate.StorageMemory・Translate.StorageDiskに置換しました。
GenerationPopupView.xamlにxmlns:local名前空間宣言を追加し、ウィンドウタイトル・ヘッダ文言・空状態メッセージをすべて{x:Static local:Translate.XXX}バインディングに変更しました。
ZeroDiskProxySettingsView.xamlにxmlns:local名前空間宣言を追加し、設定カード説明文・全Expanderヘッダ・全ラベル・全ツールチップ・全ボタン文言・キャッシュ一覧ヘッダおよび空状態メッセージをすべて{x:Static local:Translate.XXX}バインディングに変更しました。
2026-03-24 09:56:03 +09:00

202 行
6.4 KiB
C#
Raw Blame 履歴

このファイルには曖昧(ambiguous)なUnicode文字が含まれています
このファイルには、他の文字と見間違える可能性があるUnicode文字が含まれています。 それが意図的なものと考えられる場合は、この警告を無視して構いません。 それらの文字を表示するにはエスケープボタンを使用します。
using System.Collections.ObjectModel;
using System.Windows.Input;
using YukkuriMovieMaker.Commons;
using ZeroDiskProxy.Core;
using ZeroDiskProxy.Localization;
using ZeroDiskProxy.Plugin;
namespace ZeroDiskProxy.ViewModels;
internal sealed class SettingsViewModel : Bindable
{
private string _cacheSummaryText = Translate.CacheSummaryLoading;
public string CacheSummaryText
{
get => _cacheSummaryText;
set => Set(ref _cacheSummaryText, value);
}
private string _memoryUsageText = "";
public string MemoryUsageText
{
get => _memoryUsageText;
set => Set(ref _memoryUsageText, value);
}
private bool _hasCacheEntries;
public bool HasCacheEntries
{
get => _hasCacheEntries;
set => Set(ref _hasCacheEntries, value);
}
public ObservableCollection<CacheEntryViewModel> CacheEntries { get; } = [];
public ICommand ClearCacheCommand { get; }
public ICommand RefreshCacheInfoCommand { get; }
public ICommand RemoveCacheEntryCommand { get; }
internal SettingsViewModel()
{
ClearCacheCommand = new ActionCommand(ExecuteClearCache);
RefreshCacheInfoCommand = new ActionCommand(ExecuteRefreshCacheInfo);
RemoveCacheEntryCommand = new ActionCommand<CacheEntryViewModel>(ExecuteRemoveEntry);
ExecuteRefreshCacheInfo();
}
private void ExecuteClearCache()
{
var manager = PluginHost.Instance?.CacheManager;
if (manager is null)
return;
var (count, totalSize) = manager.ClearAll();
if (count == 0)
{
System.Windows.MessageBox.Show(
Translate.CacheNoEntriesToDelete,
Translate.AppName,
System.Windows.MessageBoxButton.OK,
System.Windows.MessageBoxImage.Information);
}
else
{
System.Windows.MessageBox.Show(
string.Format(
Translate.CacheDeleteSummaryFormat,
count.ToString("N0"),
FormatBytes(totalSize)),
Translate.AppName,
System.Windows.MessageBoxButton.OK,
System.Windows.MessageBoxImage.Information);
}
ExecuteRefreshCacheInfo();
}
private void ExecuteRefreshCacheInfo()
{
var manager = PluginHost.Instance?.CacheManager;
if (manager is null)
{
CacheSummaryText = Translate.CacheSummaryPluginNotInitialized;
MemoryUsageText = "";
HasCacheEntries = false;
return;
}
var (count, memSize, diskSize, memCount, diskCount) = manager.GetCacheInfo();
CacheSummaryText = string.Format(Translate.CacheSummaryCountFormat, count.ToString("N0"));
var usageText = string.Format(
Translate.CacheUsageMemoryAndDiskFormat,
memCount.ToString("N0"),
FormatBytes(memSize),
diskCount.ToString("N0"),
FormatBytes(diskSize));
var budget = PluginHost.Instance?.Budget;
if (budget is not null)
usageText = string.Concat(
usageText,
string.Format(Translate.CacheUsageAllocatedFormat, FormatBytes(budget.AllocatedBytes)));
MemoryUsageText = usageText;
CacheEntries.Clear();
var snapshots = manager.GetAllSnapshots();
foreach (var snap in snapshots)
CacheEntries.Add(new CacheEntryViewModel(snap));
HasCacheEntries = CacheEntries.Count > 0;
}
private void ExecuteRemoveEntry(CacheEntryViewModel? entry)
{
if (entry is null)
return;
var manager = PluginHost.Instance?.CacheManager;
if (manager is null)
return;
manager.RemoveProxy(entry.OriginalPath, entry.Scale);
ExecuteRefreshCacheInfo();
}
private static string FormatBytes(long bytes)
{
if (bytes <= 0)
return "0 B";
string[] sizes = ["B", "KB", "MB", "GB", "TB"];
double len = bytes;
int order = 0;
while (len >= 1024 && order < sizes.Length - 1)
{
order++;
len /= 1024;
}
return string.Concat(len.ToString("0.##"), " ", sizes[order]);
}
}
internal sealed class CacheEntryViewModel : Bindable
{
public string FileName { get; }
public string OriginalPath { get; }
public float Scale { get; }
public string Resolution { get; }
public bool IsInMemory { get; }
public string StorageType { get; }
public long DataSize { get; }
public string DataSizeText { get; }
public string CreatedAtText { get; }
public string LastAccessedText { get; }
public string ScaleText { get; }
internal CacheEntryViewModel(CacheEntrySnapshot snapshot)
{
FileName = snapshot.FileName;
OriginalPath = snapshot.OriginalPath;
Scale = snapshot.Scale;
Resolution = string.Concat(snapshot.ProxyWidth.ToString(), "×", snapshot.ProxyHeight.ToString());
IsInMemory = snapshot.IsInMemory;
StorageType = snapshot.IsInMemory ? Translate.StorageMemory : Translate.StorageDisk;
DataSize = snapshot.DataSize;
DataSizeText = FormatBytes(snapshot.DataSize);
CreatedAtText = snapshot.CreatedAt.ToLocalTime().ToString("HH:mm:ss");
LastAccessedText = snapshot.LastAccessedAt.ToLocalTime().ToString("HH:mm:ss");
ScaleText = string.Concat((snapshot.Scale * 100).ToString("F0"), "%");
}
private static string FormatBytes(long bytes)
{
if (bytes <= 0)
return "0 B";
string[] units = ["B", "KB", "MB", "GB", "TB"];
double value = bytes;
int order = 0;
while (value >= 1024 && order < units.Length - 1)
{
order++;
value /= 1024;
}
return string.Concat(value.ToString("0.##"), " ", units[order]);
}
}
internal sealed class ActionCommand(Action execute) : ICommand
{
public event EventHandler? CanExecuteChanged { add { } remove { } }
public bool CanExecute(object? parameter) => true;
public void Execute(object? parameter) => execute();
}
internal sealed class ActionCommand<T>(Action<T?> execute) : ICommand where T : class
{
public event EventHandler? CanExecuteChanged { add { } remove { } }
public bool CanExecute(object? parameter) => true;
public void Execute(object? parameter) => execute(parameter as T);
}