Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Source/NETworkManager.Localization/Resources/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Source/NETworkManager.Localization/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3951,4 +3951,13 @@ If you click Cancel, the profile file will remain unencrypted.</value>
<data name="CouldNotParseX" xml:space="preserve">
<value>Could not parse "{0}".</value>
</data>
<data name="MaximumNumberOfBackups" xml:space="preserve">
<value>Maximum number of backups</value>
</data>
<data name="CreateDailyBackup" xml:space="preserve">
<value>Create daily backup</value>
</data>
<data name="HelpMessage_MaximumNumberOfBackups" xml:space="preserve">
<value>Number of backups that are retained before the oldest one is deleted.</value>
</data>
</root>
1 change: 0 additions & 1 deletion Source/NETworkManager.Models/Network/NetworkInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,6 @@ private static void RemoveIPAddressFromNetworkInterface(NetworkInterfaceConfig c

#endregion


#region Events

/// <summary>
Expand Down
60 changes: 42 additions & 18 deletions Source/NETworkManager.Profiles/ProfileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public static class ProfileManager
private const string ProfilesFolderName = "Profiles";

/// <summary>
/// Default profile name.
/// Profiles backups directory name.
/// </summary>
private const string ProfilesDefaultFileName = "Default";
private static string BackupFolderName => "Backups";

/// <summary>
/// Profiles backups directory name.
/// Default profile name.
/// </summary>
private static string BackupFolderName => "Backups";
private const string ProfilesDefaultFileName = "Default";

/// <summary>
/// Profile file extension.
Expand Down Expand Up @@ -290,14 +290,21 @@ public static void CreateEmptyProfileFile(string profileName)
/// <param name="newProfileName">New <see cref="ProfileFileInfo.Name" /> of the profile file.</param>
public static void RenameProfileFile(ProfileFileInfo profileFileInfo, string newProfileName)
{
// Check if the profile is currently in use
var switchProfile = false;

if (LoadedProfileFile != null && LoadedProfileFile.Equals(profileFileInfo))
{
Save();
switchProfile = true;
}

// Create backup
Backup(profileFileInfo.Path,
GetProfilesBackupFolderLocation(),
TimestampHelper.GetTimestampFilename(Path.GetFileName(profileFileInfo.Path)));

// Create new profile info with the new name
ProfileFileInfo newProfileFileInfo = new(newProfileName,
Path.Combine(GetProfilesFolderLocation(), $"{newProfileName}{Path.GetExtension(profileFileInfo.Path)}"),
profileFileInfo.IsEncrypted)
Expand All @@ -306,15 +313,18 @@ public static void RenameProfileFile(ProfileFileInfo profileFileInfo, string new
IsPasswordValid = profileFileInfo.IsPasswordValid
};

// Copy the profile file to the new location
File.Copy(profileFileInfo.Path, newProfileFileInfo.Path);
ProfileFiles.Add(newProfileFileInfo);

// Switch profile, if it was previously loaded
if (switchProfile)
{
Switch(newProfileFileInfo, false);
LoadedProfileFileChanged(LoadedProfileFile, true);
}

// Remove the old profile file
File.Delete(profileFileInfo.Path);
ProfileFiles.Remove(profileFileInfo);
}
Expand Down Expand Up @@ -353,6 +363,11 @@ public static void EnableEncryption(ProfileFileInfo profileFileInfo, SecureStrin
switchProfile = true;
}

// Create backup
Backup(profileFileInfo.Path,
GetProfilesBackupFolderLocation(),
TimestampHelper.GetTimestampFilename(Path.GetFileName(profileFileInfo.Path)));

// Create a new profile info with the encryption infos
var newProfileFileInfo = new ProfileFileInfo(profileFileInfo.Name,
Path.ChangeExtension(profileFileInfo.Path, ProfileFileExtensionEncrypted), true)
Expand All @@ -361,9 +376,9 @@ public static void EnableEncryption(ProfileFileInfo profileFileInfo, SecureStrin
IsPasswordValid = true
};

List<GroupInfo> profiles = Path.GetExtension(profileFileInfo.Path) == LegacyProfileFileExtension
? DeserializeFromXmlFile(profileFileInfo.Path)
: DeserializeFromFile(profileFileInfo.Path);
List<GroupInfo> profiles = Path.GetExtension(profileFileInfo.Path) == LegacyProfileFileExtension ?
DeserializeFromXmlFile(profileFileInfo.Path) :
DeserializeFromFile(profileFileInfo.Path);

// Save the encrypted file
var decryptedBytes = SerializeToByteArray(profiles);
Expand Down Expand Up @@ -409,7 +424,12 @@ public static void ChangeMasterPassword(ProfileFileInfo profileFileInfo, SecureS
switchProfile = true;
}

// Create a new profile info with the encryption infos
// Create backup
Backup(profileFileInfo.Path,
GetProfilesBackupFolderLocation(),
TimestampHelper.GetTimestampFilename(Path.GetFileName(profileFileInfo.Path)));

// Create new profile info with the encryption infos
var newProfileFileInfo = new ProfileFileInfo(profileFileInfo.Name,
Path.ChangeExtension(profileFileInfo.Path, ProfileFileExtensionEncrypted), true)
{
Expand All @@ -423,11 +443,9 @@ public static void ChangeMasterPassword(ProfileFileInfo profileFileInfo, SecureS
GlobalStaticConfiguration.Profile_EncryptionKeySize,
GlobalStaticConfiguration.Profile_EncryptionIterations);

List<GroupInfo> profiles;

profiles = IsXmlContent(decryptedBytes)
? DeserializeFromXmlByteArray(decryptedBytes)
: DeserializeFromByteArray(decryptedBytes);
List<GroupInfo> profiles = IsXmlContent(decryptedBytes) ?
DeserializeFromXmlByteArray(decryptedBytes) :
DeserializeFromByteArray(decryptedBytes);

// Save the encrypted file
decryptedBytes = SerializeToByteArray(profiles);
Expand Down Expand Up @@ -468,7 +486,12 @@ public static void DisableEncryption(ProfileFileInfo profileFileInfo, SecureStri
switchProfile = true;
}

// Create a new profile info
// Create backup
Backup(profileFileInfo.Path,
GetProfilesBackupFolderLocation(),
TimestampHelper.GetTimestampFilename(Path.GetFileName(profileFileInfo.Path)));

// Create new profile info
var newProfileFileInfo = new ProfileFileInfo(profileFileInfo.Name,
Path.ChangeExtension(profileFileInfo.Path, ProfileFileExtension));

Expand All @@ -478,9 +501,10 @@ public static void DisableEncryption(ProfileFileInfo profileFileInfo, SecureStri
GlobalStaticConfiguration.Profile_EncryptionKeySize,
GlobalStaticConfiguration.Profile_EncryptionIterations);

List<GroupInfo> profiles = IsXmlContent(decryptedBytes)
? DeserializeFromXmlByteArray(decryptedBytes)
: DeserializeFromByteArray(decryptedBytes);
List<GroupInfo> profiles = IsXmlContent(decryptedBytes) ?
DeserializeFromXmlByteArray(decryptedBytes) :
DeserializeFromByteArray(decryptedBytes);

// Save the decrypted profiles to the profile file
SerializeToFile(newProfileFileInfo.Path, profiles);

Expand Down
18 changes: 10 additions & 8 deletions Source/NETworkManager.Settings/GlobalStaticConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ public static class GlobalStaticConfiguration
public static string ZipFileExtensionFilter => "ZIP Archive (*.zip)|*.zip";
public static string XmlFileExtensionFilter => "XML-File (*.xml)|*.xml";

// Backup settings
public static int Backup_MaximumNumberOfBackups => 10;

#endregion

#region Default settings
Expand All @@ -74,18 +71,23 @@ public static class GlobalStaticConfiguration
public static bool Status_ShowWindowOnNetworkChange => true;
public static int Status_WindowCloseTime => 10;

// HotKey
// Settings: HotKey
public static int HotKey_ShowWindowKey => 79;
public static int HotKey_ShowWindowModifier => 3;

// Update
// Settings: Update
public static bool Update_CheckForUpdatesAtStartup => true;

public static bool Update_CheckForPreReleases => false;

// Experimental
public static bool Experimental_EnableExperimentalFeatures => false;

// Settings: Profiles
public static bool Profiles_IsDailyBackupEnabled => true;
public static int Profiles_MaximumNumberOfBackups => 10;

// Settings: Settings
public static bool Settings_IsDailyBackupEnabled => true;
public static int Settings_MaximumNumberOfBackups => 10;

// Application: Dashboard
public static string Dashboard_PublicIPv4Address => "1.1.1.1";
public static string Dashboard_PublicIPv6Address => "2606:4700:4700::1111";
Expand Down
61 changes: 61 additions & 0 deletions Source/NETworkManager.Settings/SettingsInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,67 @@ public string Profiles_LastSelected
}
}

private bool _profiles_IsDailyBackupEnabled = GlobalStaticConfiguration.Profiles_IsDailyBackupEnabled;

public bool Profiles_IsDailyBackupEnabled
{
get => _profiles_IsDailyBackupEnabled;
set
{
if (value == _profiles_IsDailyBackupEnabled)
return;

_profiles_IsDailyBackupEnabled = value;
OnPropertyChanged();
}
}

private int _profiles_MaximumNumberOfBackups = GlobalStaticConfiguration.Profiles_MaximumNumberOfBackups;

public int Profiles_MaximumNumberOfBackups
{
get => _profiles_MaximumNumberOfBackups;
set
{
if (value == _profiles_MaximumNumberOfBackups)
return;

_profiles_MaximumNumberOfBackups = value;
OnPropertyChanged();
}
}

// Settings
private bool _settings_IsDailyBackupEnabled = GlobalStaticConfiguration.Settings_IsDailyBackupEnabled;

public bool Settings_IsDailyBackupEnabled
{
get => _settings_IsDailyBackupEnabled;
set
{
if (value == _settings_IsDailyBackupEnabled)
return;

_settings_IsDailyBackupEnabled = value;
OnPropertyChanged();
}
}

private int _settings_MaximumNumberOfBackups = GlobalStaticConfiguration.Settings_MaximumNumberOfBackups;

public int Settings_MaximumNumberOfBackups
{
get => _settings_MaximumNumberOfBackups;
set
{
if (value == _settings_MaximumNumberOfBackups)
return;

_settings_MaximumNumberOfBackups = value;
OnPropertyChanged();
}
}

#endregion

#region Others
Expand Down
10 changes: 9 additions & 1 deletion Source/NETworkManager.Settings/SettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,14 @@ private static void SerializeToFile(string filePath)
/// called as part of a daily maintenance routine.</remarks>
private static void CreateDailyBackupIfNeeded()
{
// Check if backups are disabled
if (!Current.Settings_IsDailyBackupEnabled)
{
Log.Debug("Daily backups are disabled. Skipping backup creation...");

return;
}

var currentDate = DateTime.Now.Date;

if (Current.LastBackup < currentDate)
Expand All @@ -284,7 +292,7 @@ private static void CreateDailyBackupIfNeeded()
// Cleanup old backups
CleanupBackups(GetSettingsBackupFolderLocation(),
GetSettingsFileName(),
GlobalStaticConfiguration.Backup_MaximumNumberOfBackups);
Current.Settings_MaximumNumberOfBackups);

Current.LastBackup = currentDate;
}
Expand Down
Loading