From b4179dec4dc0ab94de36d1f98ff21bad3fb9429e Mon Sep 17 00:00:00 2001 From: routersys Date: Sun, 1 Nov 2026 13:13:59 +0900 Subject: [PATCH] =?UTF-8?q?=E8=A8=AD=E5=AE=9A=E3=81=AE=E7=AF=84=E5=9B=B2?= =?UTF-8?q?=E3=81=A8=E5=AE=B9=E9=87=8F=E3=81=AE=E5=8D=98=E4=BD=8D=E3=82=92?= =?UTF-8?q?=E5=AE=9A=E6=95=B0=E3=81=8B=E3=82=89=E5=B0=8E=E3=81=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- UndoTree/UndoTreeRecordStore.cs | 6 +++++- UndoTree/UndoTreeRecorder.cs | 2 +- UndoTree/UndoTreeSettings.cs | 16 +++++++++++++--- UndoTree/UndoTreeSettingsView.xaml | 6 +++--- UndoTree/UndoTreeSettingsViewModel.cs | 18 +++++++++++++++--- 5 files changed, 37 insertions(+), 11 deletions(-) diff --git a/UndoTree/UndoTreeRecordStore.cs b/UndoTree/UndoTreeRecordStore.cs index fc19615..36faf89 100644 --- a/UndoTree/UndoTreeRecordStore.cs +++ b/UndoTree/UndoTreeRecordStore.cs @@ -10,6 +10,10 @@ internal sealed class UndoTreeRecordStore(string directory) { const string Extension = ".json"; const string TemporaryExtension = ".tmp"; + const int NameLength = 32; + + public const long BytesPerKilobyte = 1024; + public const long BytesPerMegabyte = BytesPerKilobyte * BytesPerKilobyte; static readonly Lazy DefaultStore = new(() => new UndoTreeRecordStore(Path.Combine(AppDirectories.UserResourceDirectory, "cache", "UndoTree"))); static readonly JsonSerializerOptions Options = new() { WriteIndented = false }; @@ -24,7 +28,7 @@ internal sealed class UndoTreeRecordStore(string directory) { var normalized = Path.GetFullPath(projectPath).ToUpperInvariant(); var hash = Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(normalized))); - return Path.Combine(Directory, hash[..32] + Extension); + return Path.Combine(Directory, hash[..NameLength] + Extension); } public bool Exists(string projectPath) diff --git a/UndoTree/UndoTreeRecorder.cs b/UndoTree/UndoTreeRecorder.cs index 0712c66..455d34b 100644 --- a/UndoTree/UndoTreeRecorder.cs +++ b/UndoTree/UndoTreeRecorder.cs @@ -75,7 +75,7 @@ internal sealed class UndoTreeRecorder : IDisposable var file = new UndoTreeRecordFile(UndoTreeRecordFile.CurrentVersion, path, previous, history.ToRecord()); var settings = UndoTreeSettings.Default; var retentionDays = settings.RetentionDays; - var maxBytes = settings.MaxTotalSizeMegabytes * 1024L * 1024L; + var maxBytes = settings.MaxTotalSizeMegabytes * UndoTreeRecordStore.BytesPerMegabyte; var prune = !pruned; pruned = true; return () => diff --git a/UndoTree/UndoTreeSettings.cs b/UndoTree/UndoTreeSettings.cs index 63fbeda..4e839d6 100644 --- a/UndoTree/UndoTreeSettings.cs +++ b/UndoTree/UndoTreeSettings.cs @@ -4,6 +4,16 @@ namespace UndoTree; internal class UndoTreeSettings : SettingsBase { + public const int NodesMinimum = 20; + public const int NodesMaximum = 5000; + public const int NodesDefault = 2000; + public const int RetentionDaysMinimum = 1; + public const int RetentionDaysMaximum = 365; + public const int RetentionDaysDefault = 30; + public const int TotalSizeMegabytesMinimum = 1; + public const int TotalSizeMegabytesMaximum = 1024; + public const int TotalSizeMegabytesDefault = 64; + public override SettingsCategory Category => SettingsCategory.Tool; public override string Name => Texts.UndoTree; @@ -12,7 +22,7 @@ internal class UndoTreeSettings : SettingsBase public override object? SettingView => new UndoTreeSettingsView { DataContext = new UndoTreeSettingsViewModel() }; - public int MaxNodes { get; set => Set(ref field, Math.Clamp(value, 20, 5000)); } = 2000; + public int MaxNodes { get; set => Set(ref field, Math.Clamp(value, NodesMinimum, NodesMaximum)); } = NodesDefault; public bool FollowCurrent { get; set => Set(ref field, value); } = true; @@ -28,9 +38,9 @@ internal class UndoTreeSettings : SettingsBase public bool SaveHistory { get; set => Set(ref field, value); } - public int RetentionDays { get; set => Set(ref field, Math.Clamp(value, 1, 365)); } = 30; + public int RetentionDays { get; set => Set(ref field, Math.Clamp(value, RetentionDaysMinimum, RetentionDaysMaximum)); } = RetentionDaysDefault; - public int MaxTotalSizeMegabytes { get; set => Set(ref field, Math.Clamp(value, 1, 1024)); } = 64; + public int MaxTotalSizeMegabytes { get; set => Set(ref field, Math.Clamp(value, TotalSizeMegabytesMinimum, TotalSizeMegabytesMaximum)); } = TotalSizeMegabytesDefault; public ConflictPolicy ConflictPolicy { get; set => Set(ref field, value); } = ConflictPolicy.Skip; diff --git a/UndoTree/UndoTreeSettingsView.xaml b/UndoTree/UndoTreeSettingsView.xaml index 642f114..b8f7f01 100644 --- a/UndoTree/UndoTreeSettingsView.xaml +++ b/UndoTree/UndoTreeSettingsView.xaml @@ -79,7 +79,7 @@