Skip to content

Commit 7fa5f4a

Browse files
committed
Feature: Configure backup retention
1 parent babd44a commit 7fa5f4a

File tree

9 files changed

+150
-14
lines changed

9 files changed

+150
-14
lines changed

Source/NETworkManager.Localization/Resources/Strings.Designer.cs

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/NETworkManager.Localization/Resources/Strings.resx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3951,4 +3951,14 @@ If you click Cancel, the profile file will remain unencrypted.</value>
39513951
<data name="CouldNotParseX" xml:space="preserve">
39523952
<value>Could not parse "{0}".</value>
39533953
</data>
3954+
<data name="MaximumNumberOfBackups" xml:space="preserve">
3955+
<value>Maximum Number of Backups</value>
3956+
</data>
3957+
<data name="HelpMessage_SettingsMaximumNumberOfBackups" xml:space="preserve">
3958+
<value>The number of settings backups that are retained before the oldest one is deleted.
3959+
3960+
An automatic backup is only created once a day, before saving a change.
3961+
3962+
The value 0 disables the creation of automatic backups. Backups that have already been created are not deleted.</value>
3963+
</data>
39543964
</root>

Source/NETworkManager.Models/Network/NetworkInterface.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,6 @@ private static void RemoveIPAddressFromNetworkInterface(NetworkInterfaceConfig c
527527

528528
#endregion
529529

530-
531530
#region Events
532531

533532
/// <summary>

Source/NETworkManager.Settings/GlobalStaticConfiguration.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ public static class GlobalStaticConfiguration
4646
public static string ZipFileExtensionFilter => "ZIP Archive (*.zip)|*.zip";
4747
public static string XmlFileExtensionFilter => "XML-File (*.xml)|*.xml";
4848

49-
// Backup settings
50-
public static int Backup_MaximumNumberOfBackups => 10;
51-
5249
#endregion
5350

5451
#region Default settings
@@ -74,18 +71,21 @@ public static class GlobalStaticConfiguration
7471
public static bool Status_ShowWindowOnNetworkChange => true;
7572
public static int Status_WindowCloseTime => 10;
7673

77-
// HotKey
74+
// Settings: HotKey
7875
public static int HotKey_ShowWindowKey => 79;
7976
public static int HotKey_ShowWindowModifier => 3;
8077

81-
// Update
78+
// Settings: Update
8279
public static bool Update_CheckForUpdatesAtStartup => true;
83-
8480
public static bool Update_CheckForPreReleases => false;
85-
86-
// Experimental
8781
public static bool Experimental_EnableExperimentalFeatures => false;
8882

83+
// Settings: Profiles
84+
public static int Profiles_MaximumNumberOfBackups => 10;
85+
86+
// Settings: Settings
87+
public static int Settings_MaximumNumberOfBackups => 10;
88+
8989
// Application: Dashboard
9090
public static string Dashboard_PublicIPv4Address => "1.1.1.1";
9191
public static string Dashboard_PublicIPv6Address => "2606:4700:4700::1111";

Source/NETworkManager.Settings/SettingsInfo.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,37 @@ public string Profiles_LastSelected
582582
}
583583
}
584584

585+
private int _profiles_MaximumNumberOfBackups = GlobalStaticConfiguration.Profiles_MaximumNumberOfBackups;
586+
587+
public int Profiles_MaximumNumberOfBackups
588+
{
589+
get => _profiles_MaximumNumberOfBackups;
590+
set
591+
{
592+
if (value == _profiles_MaximumNumberOfBackups)
593+
return;
594+
595+
_profiles_MaximumNumberOfBackups = value;
596+
OnPropertyChanged();
597+
}
598+
}
599+
600+
// Settings
601+
private int _settings_MaximumNumberOfBackups = GlobalStaticConfiguration.Settings_MaximumNumberOfBackups;
602+
603+
public int Settings_MaximumNumberOfBackups
604+
{
605+
get => _settings_MaximumNumberOfBackups;
606+
set
607+
{
608+
if (value == _settings_MaximumNumberOfBackups)
609+
return;
610+
611+
_settings_MaximumNumberOfBackups = value;
612+
OnPropertyChanged();
613+
}
614+
}
615+
585616
#endregion
586617

587618
#region Others

Source/NETworkManager.Settings/SettingsManager.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,16 @@ private static void SerializeToFile(string filePath)
265265
/// called as part of a daily maintenance routine.</remarks>
266266
private static void CreateDailyBackupIfNeeded()
267267
{
268+
var maxBackups = Current.Settings_MaximumNumberOfBackups;
269+
270+
// Check if backups are disabled
271+
if (maxBackups == 0)
272+
{
273+
Log.Debug("Daily backups are disabled. Skipping backup creation...");
274+
275+
return;
276+
}
277+
268278
var currentDate = DateTime.Now.Date;
269279

270280
if (Current.LastBackup < currentDate)
@@ -284,7 +294,7 @@ private static void CreateDailyBackupIfNeeded()
284294
// Cleanup old backups
285295
CleanupBackups(GetSettingsBackupFolderLocation(),
286296
GetSettingsFileName(),
287-
GlobalStaticConfiguration.Backup_MaximumNumberOfBackups);
297+
maxBackups);
288298

289299
Current.LastBackup = currentDate;
290300
}

Source/NETworkManager/ViewModels/SettingsProfilesViewModel.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public class SettingsProfilesViewModel : ViewModelBase
2222

2323
public Action CloseAction { get; set; }
2424

25+
private readonly bool _isLoading;
26+
2527
private string _location;
2628

2729
public string Location
@@ -67,24 +69,46 @@ public ProfileFileInfo SelectedProfileFile
6769
}
6870
}
6971

72+
private int _maximumNumberOfBackups;
73+
74+
public int MaximumNumberOfBackups
75+
{
76+
get => _maximumNumberOfBackups;
77+
set
78+
{
79+
if (value == _maximumNumberOfBackups)
80+
return;
81+
82+
if (!_isLoading)
83+
SettingsManager.Current.Profiles_MaximumNumberOfBackups = value;
84+
85+
_maximumNumberOfBackups = value;
86+
OnPropertyChanged();
87+
}
88+
}
7089
#endregion
7190

7291
#region Constructor, LoadSettings
7392

7493
public SettingsProfilesViewModel()
7594
{
95+
_isLoading = true;
96+
7697
ProfileFiles = new CollectionViewSource { Source = ProfileManager.ProfileFiles }.View;
7798
ProfileFiles.SortDescriptions.Add(
7899
new SortDescription(nameof(ProfileFileInfo.Name), ListSortDirection.Ascending));
79100

80101
SelectedProfileFile = ProfileFiles.Cast<ProfileFileInfo>().FirstOrDefault();
81102

82103
LoadSettings();
104+
105+
_isLoading = false;
83106
}
84107

85108
private void LoadSettings()
86109
{
87110
Location = ProfileManager.GetProfilesFolderLocation();
111+
MaximumNumberOfBackups = SettingsManager.Current.Profiles_MaximumNumberOfBackups;
88112
}
89113

90114
#endregion

Source/NETworkManager/ViewModels/SettingsSettingsViewModel.cs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
using MahApps.Metro.SimpleChildWindow;
2-
using NETworkManager.Localization.Resources;
1+
using NETworkManager.Localization.Resources;
32
using NETworkManager.Settings;
43
using NETworkManager.Utilities;
5-
using NETworkManager.Views;
64
using System;
75
using System.Diagnostics;
86
using System.Threading.Tasks;
@@ -16,6 +14,8 @@ public class SettingsSettingsViewModel : ViewModelBase
1614
#region Variables
1715
public Action CloseAction { get; set; }
1816

17+
private readonly bool _isLoading;
18+
1919
private string _location;
2020

2121
public string Location
@@ -30,18 +30,42 @@ public string Location
3030
OnPropertyChanged();
3131
}
3232
}
33+
34+
private int _maximumNumberOfBackups;
35+
36+
public int MaximumNumberOfBackups
37+
{
38+
get => _maximumNumberOfBackups;
39+
set
40+
{
41+
if (value == _maximumNumberOfBackups)
42+
return;
43+
44+
if (!_isLoading)
45+
SettingsManager.Current.Settings_MaximumNumberOfBackups = value;
46+
47+
_maximumNumberOfBackups = value;
48+
OnPropertyChanged();
49+
}
50+
}
51+
3352
#endregion
3453

3554
#region Constructor, LoadSettings
3655

3756
public SettingsSettingsViewModel()
3857
{
58+
_isLoading = true;
59+
3960
LoadSettings();
61+
62+
_isLoading = false;
4063
}
4164

4265
private void LoadSettings()
4366
{
4467
Location = SettingsManager.GetSettingsFolderLocation();
68+
MaximumNumberOfBackups = SettingsManager.Current.Settings_MaximumNumberOfBackups;
4569
}
4670

4771
#endregion

Source/NETworkManager/Views/SettingsSettingsView.xaml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
67
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
78
xmlns:viewModels="clr-namespace:NETworkManager.ViewModels"
89
xmlns:localization="clr-namespace:NETworkManager.Localization.Resources;assembly=NETworkManager.Localization"
@@ -30,8 +31,23 @@
3031
</Grid>
3132
</Button.Content>
3233
</Button>
34+
<TextBlock Style="{StaticResource HeaderTextBlock}" Text="{x:Static localization:Strings.Backup}" />
35+
<StackPanel Orientation="Horizontal" Margin="0,0,0,20">
36+
<TextBlock Text="{x:Static localization:Strings.MaximumNumberOfBackups}"
37+
Style="{StaticResource CenterTextBlock}"
38+
Margin="0,0,0,10" />
39+
<mah:NumericUpDown Value="{Binding MaximumNumberOfBackups}" Minimum="0" Maximum="100" Interval="1"/>
40+
<Rectangle Width="24" Height="24"
41+
ToolTip="{x:Static localization:Strings.HelpMessage_SettingsMaximumNumberOfBackups}"
42+
Style="{StaticResource HelpImageRectangle}" Margin="10,0,0,0">
43+
<Rectangle.Resources>
44+
<Style TargetType="{x:Type ToolTip}" BasedOn="{StaticResource HelpToolTip}" />
45+
</Rectangle.Resources>
46+
</Rectangle>
47+
</StackPanel>
3348
<TextBlock Style="{StaticResource HeaderTextBlock}" Text="{x:Static localization:Strings.Reset}" />
3449
<Button Content="{x:Static localization:Strings.Reset}" Command="{Binding ResetSettingsCommand}"
35-
IsEnabled="{Binding SettingsExists}" Style="{StaticResource DefaultButton}" HorizontalAlignment="Left" />
50+
Style="{StaticResource DefaultButton}" HorizontalAlignment="Left"
51+
/>
3652
</StackPanel>
3753
</UserControl>

0 commit comments

Comments
 (0)