設定の範囲と容量の単位を定数から導く
このコミットが含まれているのは:
5ファイル変更
+37
-11
検索条件に一致するファイルはありません
@@ -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<UndoTreeRecordStore> 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)
|
||||
|
||||
@@ -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 () =>
|
||||
|
||||
@@ -4,6 +4,16 @@ namespace UndoTree;
|
||||
|
||||
internal class UndoTreeSettings : SettingsBase<UndoTreeSettings>
|
||||
{
|
||||
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<UndoTreeSettings>
|
||||
|
||||
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<UndoTreeSettings>
|
||||
|
||||
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;
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Grid.Column="0" Content="{x:Static local:Texts.MaxNodesLabel}" VerticalAlignment="Center"/>
|
||||
<c:TextBoxSlider Grid.Column="1" Value="{Binding Settings.MaxNodes, Mode=TwoWay}"
|
||||
Min="20" Max="5000" DefaultMin="100" DefaultMax="3000" Delta="10"
|
||||
Min="{Binding NodesMinimum, Mode=OneWay}" Max="{Binding NodesMaximum, Mode=OneWay}" DefaultMin="100" DefaultMax="3000" Delta="10"
|
||||
StringFormat="F0" Unit="" Width="200" VerticalAlignment="Center"/>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
@@ -101,7 +101,7 @@
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Grid.Column="0" Content="{x:Static local:Texts.RetentionDays}" VerticalAlignment="Center"/>
|
||||
<c:TextBoxSlider Grid.Column="1" Value="{Binding Settings.RetentionDays, Mode=TwoWay}"
|
||||
Min="1" Max="365" DefaultMin="7" DefaultMax="90" Delta="1"
|
||||
Min="{Binding RetentionDaysMinimum, Mode=OneWay}" Max="{Binding RetentionDaysMaximum, Mode=OneWay}" DefaultMin="7" DefaultMax="90" Delta="1"
|
||||
StringFormat="F0" Unit="{x:Static local:Texts.UnitDays}" Width="200" VerticalAlignment="Center"/>
|
||||
</Grid>
|
||||
<Grid>
|
||||
@@ -111,7 +111,7 @@
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Grid.Column="0" Content="{x:Static local:Texts.MaxTotalSize}" VerticalAlignment="Center"/>
|
||||
<c:TextBoxSlider Grid.Column="1" Value="{Binding Settings.MaxTotalSizeMegabytes, Mode=TwoWay}"
|
||||
Min="1" Max="1024" DefaultMin="16" DefaultMax="256" Delta="1"
|
||||
Min="{Binding TotalSizeMinimumMegabytes, Mode=OneWay}" Max="{Binding TotalSizeMaximumMegabytes, Mode=OneWay}" DefaultMin="16" DefaultMax="256" Delta="1"
|
||||
StringFormat="F0" Unit="{x:Static local:Texts.UnitMegabytes}" Width="200" VerticalAlignment="Center"/>
|
||||
</Grid>
|
||||
<Grid>
|
||||
|
||||
@@ -20,6 +20,18 @@ internal class UndoTreeSettingsViewModel : Bindable
|
||||
|
||||
public UndoTreeSettings Settings => UndoTreeSettings.Default;
|
||||
|
||||
public double NodesMinimum => UndoTreeSettings.NodesMinimum;
|
||||
|
||||
public double NodesMaximum => UndoTreeSettings.NodesMaximum;
|
||||
|
||||
public double RetentionDaysMinimum => UndoTreeSettings.RetentionDaysMinimum;
|
||||
|
||||
public double RetentionDaysMaximum => UndoTreeSettings.RetentionDaysMaximum;
|
||||
|
||||
public double TotalSizeMinimumMegabytes => UndoTreeSettings.TotalSizeMegabytesMinimum;
|
||||
|
||||
public double TotalSizeMaximumMegabytes => UndoTreeSettings.TotalSizeMegabytesMaximum;
|
||||
|
||||
public string RecordFolder => store.Directory;
|
||||
|
||||
public UndoTreeRecordUsage Usage { get; private set; } = new(0, 0);
|
||||
@@ -44,9 +56,9 @@ internal class UndoTreeSettingsViewModel : Bindable
|
||||
|
||||
internal static string FormatBytes(long bytes) => bytes switch
|
||||
{
|
||||
< 1024 => string.Create(CultureInfo.InvariantCulture, $"{bytes} B"),
|
||||
< 1024 * 1024 => string.Create(CultureInfo.InvariantCulture, $"{bytes / 1024.0:F1} KB"),
|
||||
_ => string.Create(CultureInfo.InvariantCulture, $"{bytes / (1024.0 * 1024.0):F1} MB"),
|
||||
< UndoTreeRecordStore.BytesPerKilobyte => string.Create(CultureInfo.InvariantCulture, $"{bytes} B"),
|
||||
< UndoTreeRecordStore.BytesPerMegabyte => string.Create(CultureInfo.InvariantCulture, $"{(double)bytes / UndoTreeRecordStore.BytesPerKilobyte:F1} KB"),
|
||||
_ => string.Create(CultureInfo.InvariantCulture, $"{(double)bytes / UndoTreeRecordStore.BytesPerMegabyte:F1} MB"),
|
||||
};
|
||||
|
||||
public void UpdateUsage()
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする