Skip to content
Merged
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
37 changes: 22 additions & 15 deletions Source/NETworkManager.Profiles/ProfileManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using NETworkManager.Settings;
using log4net;
using NETworkManager.Models.Network;
using NETworkManager.Settings;
using NETworkManager.Utilities;
using System;
using System.Collections.Generic;
Expand All @@ -13,19 +15,8 @@ namespace NETworkManager.Profiles;

public static class ProfileManager
{
#region Constructor

/// <summary>
/// Static constructor. Load all profile files on startup.
/// </summary>
static ProfileManager()
{
LoadProfileFiles();
}

#endregion

#region Variables
private static readonly ILog Log = LogManager.GetLogger(typeof(ProfileManager));

/// <summary>
/// Profiles directory name.
Expand Down Expand Up @@ -84,6 +75,18 @@ private set

#endregion

#region Constructor

/// <summary>
/// Static constructor. Load all profile files on startup.
/// </summary>
static ProfileManager()
{
LoadProfileFiles();
}

#endregion

#region Events

/// <summary>
Expand Down Expand Up @@ -202,7 +205,7 @@ public static void CreateEmptyProfileFile(string profileName)

Directory.CreateDirectory(GetProfilesFolderLocation());

SerializeToFile(profileFileInfo.Path, new List<GroupInfo>());
SerializeToFile(profileFileInfo.Path, []);

ProfileFiles.Add(profileFileInfo);
}
Expand All @@ -219,7 +222,6 @@ public static void RenameProfileFile(ProfileFileInfo profileFileInfo, string new
if (LoadedProfileFile != null && LoadedProfileFile.Equals(profileFileInfo))
{
Save();

switchProfile = true;
}

Expand Down Expand Up @@ -472,7 +474,12 @@ private static void Load(ProfileFileInfo profileFileInfo)
public static void Save()
{
if (LoadedProfileFile == null)
{
Log.Warn("Cannot save profiles because no profile file is loaded. The profile file may be encrypted and not yet unlocked.");

return;
}


Directory.CreateDirectory(GetProfilesFolderLocation());

Expand Down
3 changes: 3 additions & 0 deletions Source/NETworkManager.Settings/GlobalStaticConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ 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 Down
81 changes: 51 additions & 30 deletions Source/NETworkManager.Settings/SettingsInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,27 @@ public string Version
}
}

/// <summary>
/// Private field for the <see cref="LastBackup" /> property.
/// </summary>
private DateTime _lastBackup = DateTime.MinValue;

/// <summary>
/// Stores the date of the last backup of the settings file.
/// </summary>
public DateTime LastBackup
{
get => _lastBackup;
set
{
if (value == _lastBackup)
return;

_lastBackup = value;
OnPropertyChanged();
}
}

#region General

// General
Expand Down Expand Up @@ -1216,7 +1237,7 @@ public ExportFileType IPScanner_ExportFileType

#region Port Scanner

private ObservableCollection<string> _portScanner_HostHistory = new();
private ObservableCollection<string> _portScanner_HostHistory = [];

public ObservableCollection<string> PortScanner_HostHistory
{
Expand All @@ -1231,7 +1252,7 @@ public ObservableCollection<string> PortScanner_HostHistory
}
}

private ObservableCollection<string> _portScanner_PortHistory = new();
private ObservableCollection<string> _portScanner_PortHistory = [];

public ObservableCollection<string> PortScanner_PortHistory
{
Expand All @@ -1246,7 +1267,7 @@ public ObservableCollection<string> PortScanner_PortHistory
}
}

private ObservableCollection<PortProfileInfo> _portScanner_PortProfiles = new();
private ObservableCollection<PortProfileInfo> _portScanner_PortProfiles = [];

public ObservableCollection<PortProfileInfo> PortScanner_PortProfiles
{
Expand Down Expand Up @@ -1400,7 +1421,7 @@ public ExportFileType PortScanner_ExportFileType

#region Ping Monitor

private ObservableCollection<string> _pingMonitor_HostHistory = new();
private ObservableCollection<string> _pingMonitor_HostHistory = [];

public ObservableCollection<string> PingMonitor_HostHistory
{
Expand Down Expand Up @@ -1569,7 +1590,7 @@ public double PingMonitor_ProfileWidth

#region Traceroute

private ObservableCollection<string> _traceroute_HostHistory = new();
private ObservableCollection<string> _traceroute_HostHistory = [];

public ObservableCollection<string> Traceroute_HostHistory
{
Expand Down Expand Up @@ -1999,7 +2020,7 @@ public ExportFileType DNSLookup_ExportFileType

#region Remote Desktop

private ObservableCollection<string> _remoteDesktop_HostHistory = new();
private ObservableCollection<string> _remoteDesktop_HostHistory = [];

public ObservableCollection<string> RemoteDesktop_HostHistory
{
Expand Down Expand Up @@ -2579,7 +2600,7 @@ public double RemoteDesktop_ProfileWidth

#region PowerShell

private ObservableCollection<string> _powerShell_HostHistory = new();
private ObservableCollection<string> _powerShell_HostHistory = [];

public ObservableCollection<string> PowerShell_HostHistory
{
Expand Down Expand Up @@ -2689,7 +2710,7 @@ public double PowerShell_ProfileWidth

#region PuTTY

private ObservableCollection<string> _puTTY_HostHistory = new();
private ObservableCollection<string> _puTTY_HostHistory = [];

public ObservableCollection<string> PuTTY_HostHistory
{
Expand Down Expand Up @@ -2839,7 +2860,7 @@ public string PuTTY_AdditionalCommandLine
}
}

private ObservableCollection<string> _puTTY_SerialLineHistory = new();
private ObservableCollection<string> _puTTY_SerialLineHistory = [];

public ObservableCollection<string> PuTTY_SerialLineHistory
{
Expand All @@ -2854,7 +2875,7 @@ public ObservableCollection<string> PuTTY_SerialLineHistory
}
}

private ObservableCollection<string> _puTTY_PortHistory = new();
private ObservableCollection<string> _puTTY_PortHistory = [];

public ObservableCollection<string> PuTTY_PortHistory
{
Expand All @@ -2869,7 +2890,7 @@ public ObservableCollection<string> PuTTY_PortHistory
}
}

private ObservableCollection<string> _puTTY_BaudHistory = new();
private ObservableCollection<string> _puTTY_BaudHistory = [];

public ObservableCollection<string> PuTTY_BaudHistory
{
Expand All @@ -2884,7 +2905,7 @@ public ObservableCollection<string> PuTTY_BaudHistory
}
}

private ObservableCollection<string> _puTTY_UsernameHistory = new();
private ObservableCollection<string> _puTTY_UsernameHistory = [];

public ObservableCollection<string> PuTTY_UsernameHistory
{
Expand All @@ -2899,7 +2920,7 @@ public ObservableCollection<string> PuTTY_UsernameHistory
}
}

private ObservableCollection<string> _puTTY_PrivateKeyFileHistory = new();
private ObservableCollection<string> _puTTY_PrivateKeyFileHistory = [];

public ObservableCollection<string> PuTTY_PrivateKeyFileHistory
{
Expand All @@ -2914,7 +2935,7 @@ public ObservableCollection<string> PuTTY_PrivateKeyFileHistory
}
}

private ObservableCollection<string> _puTTY_ProfileHistory = new();
private ObservableCollection<string> _puTTY_ProfileHistory = [];

public ObservableCollection<string> PuTTY_ProfileHistory
{
Expand Down Expand Up @@ -3069,7 +3090,7 @@ public int PuTTY_RawPort

#region TigerVNC

private ObservableCollection<string> _tigerVNC_HostHistory = new();
private ObservableCollection<string> _tigerVNC_HostHistory = [];

public ObservableCollection<string> TigerVNC_HostHistory
{
Expand All @@ -3084,7 +3105,7 @@ public ObservableCollection<string> TigerVNC_HostHistory
}
}

private ObservableCollection<int> _tigerVNC_PortHistory = new();
private ObservableCollection<int> _tigerVNC_PortHistory = [];

public ObservableCollection<int> TigerVNC_PortHistory
{
Expand Down Expand Up @@ -3163,7 +3184,7 @@ public int TigerVNC_Port

#region Web Console

private ObservableCollection<string> _webConsole_UrlHistory = new();
private ObservableCollection<string> _webConsole_UrlHistory = [];

public ObservableCollection<string> WebConsole_UrlHistory
{
Expand Down Expand Up @@ -3257,7 +3278,7 @@ public bool WebConsole_IsPasswordSaveEnabled

#region SNMP

private ObservableCollection<string> _snmp_HostHistory = new();
private ObservableCollection<string> _snmp_HostHistory = [];

public ObservableCollection<string> SNMP_HostHistory
{
Expand All @@ -3272,7 +3293,7 @@ public ObservableCollection<string> SNMP_HostHistory
}
}

private ObservableCollection<string> _snmp_OidHistory = new();
private ObservableCollection<string> _snmp_OidHistory = [];

public ObservableCollection<string> SNMP_OidHistory
{
Expand All @@ -3287,7 +3308,7 @@ public ObservableCollection<string> SNMP_OidHistory
}
}

private ObservableCollection<SNMPOIDProfileInfo> _snmp_OidProfiles = new();
private ObservableCollection<SNMPOIDProfileInfo> _snmp_OidProfiles = [];

public ObservableCollection<SNMPOIDProfileInfo> SNMP_OidProfiles
{
Expand Down Expand Up @@ -3681,7 +3702,7 @@ public int WakeOnLAN_Port
}
}

private ObservableCollection<string> _wakeOnLan_MACAddressHistory = new();
private ObservableCollection<string> _wakeOnLan_MACAddressHistory = [];

public ObservableCollection<string> WakeOnLan_MACAddressHistory
{
Expand All @@ -3696,7 +3717,7 @@ public ObservableCollection<string> WakeOnLan_MACAddressHistory
}
}

private ObservableCollection<string> _wakeOnLan_BroadcastHistory = new();
private ObservableCollection<string> _wakeOnLan_BroadcastHistory = [];

public ObservableCollection<string> WakeOnLan_BroadcastHistory
{
Expand Down Expand Up @@ -3745,7 +3766,7 @@ public double WakeOnLAN_ProfileWidth

#region Whois

private ObservableCollection<string> _whois_DomainHistory = new();
private ObservableCollection<string> _whois_DomainHistory = [];

public ObservableCollection<string> Whois_DomainHistory
{
Expand Down Expand Up @@ -3824,7 +3845,7 @@ public ExportFileType Whois_ExportFileType

#region IP Geolocation

private ObservableCollection<string> _ipGeolocation_HostHistory = new();
private ObservableCollection<string> _ipGeolocation_HostHistory = [];

public ObservableCollection<string> IPGeolocation_HostHistory
{
Expand Down Expand Up @@ -3905,7 +3926,7 @@ public ExportFileType IPGeolocation_ExportFileType

#region Calculator

private ObservableCollection<string> _subnetCalculator_Calculator_SubnetHistory = new();
private ObservableCollection<string> _subnetCalculator_Calculator_SubnetHistory = [];

public ObservableCollection<string> SubnetCalculator_Calculator_SubnetHistory
{
Expand All @@ -3924,7 +3945,7 @@ public ObservableCollection<string> SubnetCalculator_Calculator_SubnetHistory

#region Subnetting

private ObservableCollection<string> _subnetCalculator_Subnetting_SubnetHistory = new();
private ObservableCollection<string> _subnetCalculator_Subnetting_SubnetHistory = [];

public ObservableCollection<string> SubnetCalculator_Subnetting_SubnetHistory
{
Expand All @@ -3939,7 +3960,7 @@ public ObservableCollection<string> SubnetCalculator_Subnetting_SubnetHistory
}
}

private ObservableCollection<string> _subnetCalculator_Subnetting_NewSubnetmaskHistory = new();
private ObservableCollection<string> _subnetCalculator_Subnetting_NewSubnetmaskHistory = [];

public ObservableCollection<string> SubnetCalculator_Subnetting_NewSubnetmaskHistory
{
Expand Down Expand Up @@ -3989,7 +4010,7 @@ public ExportFileType SubnetCalculator_Subnetting_ExportFileType

#region WideSubnet

private ObservableCollection<string> _subnetCalculator_WideSubnet_Subnet1 = new();
private ObservableCollection<string> _subnetCalculator_WideSubnet_Subnet1 = [];

public ObservableCollection<string> SubnetCalculator_WideSubnet_Subnet1
{
Expand All @@ -4004,7 +4025,7 @@ public ObservableCollection<string> SubnetCalculator_WideSubnet_Subnet1
}
}

private ObservableCollection<string> _subnetCalculator_WideSubnet_Subnet2 = new();
private ObservableCollection<string> _subnetCalculator_WideSubnet_Subnet2 = [];

public ObservableCollection<string> SubnetCalculator_WideSubnet_Subnet2
{
Expand All @@ -4025,7 +4046,7 @@ public ObservableCollection<string> SubnetCalculator_WideSubnet_Subnet2

#region Bit Calculator

private ObservableCollection<string> _bitCalculator_InputHistory = new();
private ObservableCollection<string> _bitCalculator_InputHistory = [];

public ObservableCollection<string> BitCalculator_InputHistory
{
Expand Down
Loading