From 456236c2724de6ecc60865918a6ea27fa98febf7 Mon Sep 17 00:00:00 2001 From: BornToBeRoot Date: Sun, 29 Mar 2020 08:14:31 +0200 Subject: [PATCH 1/2] PuTTY logging added --- .../Resources/Strings.Designer.cs | 18 ++++++ .../Resources/Strings.resx | 6 ++ Source/NETworkManager.Models/PuTTY/PuTTY.cs | 4 ++ .../PuTTY/PuTTYSessionInfo.cs | 45 +++++++++++++- .../Application/PuTTY.cs | 3 + .../NETworkManager.Profiles.csproj | 1 + Source/NETworkManager.Profiles/ProfileInfo.cs | 8 +++ .../NETworkManager.Profiles/ProfileManager.cs | 34 +--------- .../Application/PuTTY.cs | 11 +++- .../GlobalStaticConfiguration.cs | 1 + .../NETworkManager.Settings/SettingsInfo.cs | 30 +++++++++ Source/NETworkManager/ProfileDialogManager.cs | 6 +- .../ViewModels/ProfileViewModel.cs | 62 ++++++++++++++++++- .../ViewModels/PuTTYHostViewModel.cs | 18 ++++-- .../ViewModels/PuTTYSettingsViewModel.cs | 62 +++++++++++++++---- .../Views/IPScannerSettingsView.xaml | 2 +- .../NETworkManager/Views/ProfileDialog.xaml | 34 ++++++++-- .../Views/PuTTYSettingsView.xaml | 11 ++++ 18 files changed, 296 insertions(+), 60 deletions(-) diff --git a/Source/NETworkManager.Localization/Resources/Strings.Designer.cs b/Source/NETworkManager.Localization/Resources/Strings.Designer.cs index 73e5ed99da..d1fe211a08 100644 --- a/Source/NETworkManager.Localization/Resources/Strings.Designer.cs +++ b/Source/NETworkManager.Localization/Resources/Strings.Designer.cs @@ -2553,6 +2553,15 @@ public static string EnableEncryptionDots { } } + /// + /// Looks up a localized string similar to Enable session log. + /// + public static string EnableSessionLog { + get { + return ResourceManager.GetString("EnableSessionLog", resourceCulture); + } + } + /// /// Looks up a localized string similar to Encryption. /// @@ -6443,6 +6452,15 @@ public static string Service { } } + /// + /// Looks up a localized string similar to Session log file name. + /// + public static string SessionLogFileName { + get { + return ResourceManager.GetString("SessionLogFileName", resourceCulture); + } + } + /// /// Looks up a localized string similar to Set Master Password. /// diff --git a/Source/NETworkManager.Localization/Resources/Strings.resx b/Source/NETworkManager.Localization/Resources/Strings.resx index 8499b0e24d..d009ba8658 100644 --- a/Source/NETworkManager.Localization/Resources/Strings.resx +++ b/Source/NETworkManager.Localization/Resources/Strings.resx @@ -2851,4 +2851,10 @@ URL: https://github.com/BornToBeRoot/NETworkManager/tree/master/Documentation Window + + Enable session log + + + Session log file name + \ No newline at end of file diff --git a/Source/NETworkManager.Models/PuTTY/PuTTY.cs b/Source/NETworkManager.Models/PuTTY/PuTTY.cs index ab9fa5c0b0..bde3331398 100644 --- a/Source/NETworkManager.Models/PuTTY/PuTTY.cs +++ b/Source/NETworkManager.Models/PuTTY/PuTTY.cs @@ -34,6 +34,10 @@ public static string BuildCommandLine(PuTTYSessionInfo profileInfo) if (!string.IsNullOrEmpty(profileInfo.Username)) command += $" -l {profileInfo.Username}"; + // Session log + if (profileInfo.EnableSessionLog) + command += $" -sessionlog {'"'}{ profileInfo.SessionLogFullName}{'"'}"; + // Additional commands if (!string.IsNullOrEmpty(profileInfo.AdditionalCommandLine)) command += $" {profileInfo.AdditionalCommandLine}"; diff --git a/Source/NETworkManager.Models/PuTTY/PuTTYSessionInfo.cs b/Source/NETworkManager.Models/PuTTY/PuTTYSessionInfo.cs index 07e99a895a..56a810a460 100644 --- a/Source/NETworkManager.Models/PuTTY/PuTTYSessionInfo.cs +++ b/Source/NETworkManager.Models/PuTTY/PuTTYSessionInfo.cs @@ -2,16 +2,59 @@ namespace NETworkManager.Models.PuTTY { + /// + /// Stores informations about a putty session. + /// public class PuTTYSessionInfo { + /// + /// Full path to the PuTTY.exe on the filesystem. + /// public string ApplicationFilePath { get; set; } + + /// + /// Mode (SSH, Telnet, etc.), which is used to establish the connection. + /// public ConnectionMode Mode { get; set; } + + /// + /// Hostname or SerialLine. Depends on the . + /// public string HostOrSerialLine { get; set; } + + /// + /// Port or Baud. Depends on the . + /// public int PortOrBaud { get; set; } - public string Profile { get; set; } + + /// + /// Username for login. + /// public string Username { get; set; } + + /// + /// PuTTY profile to use. + /// + public string Profile { get; set; } + + /// + /// Enables session log. + /// + public bool EnableSessionLog { get; set; } + + /// + /// Path and filename of the session log file (e.g. "C:\..\PuTTY.log"). + /// + public string SessionLogFullName { get; set; } + + /// + /// Additional command line argument. Everything putty can handle. + /// public string AdditionalCommandLine { get; set; } + /// + /// Initializes a new instance of the class. + /// public PuTTYSessionInfo() { diff --git a/Source/NETworkManager.Profiles/Application/PuTTY.cs b/Source/NETworkManager.Profiles/Application/PuTTY.cs index cbd3d2b33e..e13c32af8b 100644 --- a/Source/NETworkManager.Profiles/Application/PuTTY.cs +++ b/Source/NETworkManager.Profiles/Application/PuTTY.cs @@ -1,5 +1,6 @@ using NETworkManager.Models.PuTTY; using NETworkManager.Settings; +using System.IO; namespace NETworkManager.Profiles.Application { @@ -14,6 +15,8 @@ public static PuTTYSessionInfo CreateSessionInfo(ProfileInfo profileInfo) PortOrBaud = profileInfo.PuTTY_OverridePortOrBaud ? profileInfo.PuTTY_PortOrBaud : Settings.Application.PuTTY.GetPortOrBaudByConnectionMode(profileInfo.PuTTY_ConnectionMode), Username = profileInfo.PuTTY_OverrideUsername ? profileInfo.PuTTY_Username : SettingsManager.Current.PuTTY_Username, Profile = profileInfo.PuTTY_OverrideProfile ? profileInfo.PuTTY_Profile : SettingsManager.Current.PuTTY_Profile, + EnableSessionLog = profileInfo.PuTTY_OverrideEnableSessionLog ? profileInfo.PuTTY_EnableSessionLog : SettingsManager.Current.PuTTY_EnableSessionLog, + SessionLogFullName = Path.Combine(Settings.Application.PuTTY.LogPath, profileInfo.PuTTY_OverrideSessionLogFileName ? profileInfo.PuTTY_SessionLogFileName : SettingsManager.Current.PuTTY_SessionLogFileName), AdditionalCommandLine = profileInfo.PuTTY_OverrideAdditionalCommandLine ? profileInfo.PuTTY_AdditionalCommandLine : SettingsManager.Current.PuTTY_AdditionalCommandLine }; diff --git a/Source/NETworkManager.Profiles/NETworkManager.Profiles.csproj b/Source/NETworkManager.Profiles/NETworkManager.Profiles.csproj index ac3eae60fa..25da5ce5e3 100644 --- a/Source/NETworkManager.Profiles/NETworkManager.Profiles.csproj +++ b/Source/NETworkManager.Profiles/NETworkManager.Profiles.csproj @@ -21,6 +21,7 @@ DEBUG;TRACE prompt 4 + bin\Debug\NETworkManager.Profiles.xml pdbonly diff --git a/Source/NETworkManager.Profiles/ProfileInfo.cs b/Source/NETworkManager.Profiles/ProfileInfo.cs index 91722e385a..0bd465baab 100644 --- a/Source/NETworkManager.Profiles/ProfileInfo.cs +++ b/Source/NETworkManager.Profiles/ProfileInfo.cs @@ -124,8 +124,13 @@ public class ProfileInfo public string PuTTY_Username { get; set; } public bool PuTTY_OverrideProfile { get; set; } public string PuTTY_Profile { get; set; } + public bool PuTTY_OverrideEnableSessionLog { get; set; } + public bool PuTTY_EnableSessionLog { get; set; } + public bool PuTTY_OverrideSessionLogFileName { get; set; } + public string PuTTY_SessionLogFileName { get; set; } = GlobalStaticConfiguration.PuTTY_SessionLogFileName; public bool PuTTY_OverrideAdditionalCommandLine { get; set; } public string PuTTY_AdditionalCommandLine { get; set; } + public bool TigerVNC_Enabled { get; set; } public bool TigerVNC_InheritHost { get; set; } = true; @@ -149,6 +154,9 @@ public class ProfileInfo public bool Whois_InheritHost { get; set; } = true; public string Whois_Domain { get; set; } + /// + /// Initializes a new instance of the class. + /// public ProfileInfo() { diff --git a/Source/NETworkManager.Profiles/ProfileManager.cs b/Source/NETworkManager.Profiles/ProfileManager.cs index 27e29cefa1..dcd610df94 100644 --- a/Source/NETworkManager.Profiles/ProfileManager.cs +++ b/Source/NETworkManager.Profiles/ProfileManager.cs @@ -10,9 +10,6 @@ namespace NETworkManager.Profiles { - /// - /// - /// public static class ProfileManager { #region Variables @@ -36,24 +33,12 @@ public static class ProfileManager /// public static string ProfilesEncryptionIdentifier => ".encrypted"; - /// - /// - /// public static string TagIdentifier => "tag="; - /// - /// - /// public static ObservableCollection ProfileFiles { get; set; } = new ObservableCollection(); - /// - /// - /// private static ProfileFileInfo _profileFileInfo; - /// - /// - /// public static ProfileFileInfo LoadedProfileFile { get => _profileFileInfo; @@ -66,25 +51,12 @@ public static ProfileFileInfo LoadedProfileFile } } - /// - /// - /// public static ObservableCollection Profiles { get; set; } = new ObservableCollection(); - - /// - /// - /// + public static bool ProfilesChanged { get; set; } - /// - /// - /// public static event EventHandler OnProfileFileChangedEvent; - /// - /// - /// - /// private static void ProfileFileChanged(ProfileFileInfo profileFileInfo) { OnProfileFileChangedEvent?.Invoke(null, new ProfileFileInfoArgs(profileFileInfo)); @@ -118,10 +90,6 @@ public static string GetPortableProfilesLocation() return Path.Combine(Path.GetDirectoryName(AssemblyManager.Current.Location) ?? throw new InvalidOperationException(), ProfilesFolderName); } - /// - /// - /// - /// public static string GetProfilesLocation() { return ConfigurationManager.Current.IsPortable ? GetPortableProfilesLocation() : GetProfilesLocationNotPortable(); diff --git a/Source/NETworkManager.Settings/Application/PuTTY.cs b/Source/NETworkManager.Settings/Application/PuTTY.cs index b80a48330d..43e9990e81 100644 --- a/Source/NETworkManager.Settings/Application/PuTTY.cs +++ b/Source/NETworkManager.Settings/Application/PuTTY.cs @@ -1,9 +1,18 @@ -using static NETworkManager.Models.PuTTY.PuTTY; +using System; +using System.IO; +using static NETworkManager.Models.PuTTY.PuTTY; namespace NETworkManager.Settings.Application { public static class PuTTY { + public static string LogPath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), AssemblyManager.Current.Name, "PuTTY_LogFiles"); + + public static void CreateLogPath() + { + Directory.CreateDirectory(LogPath); + } + public static int GetPortOrBaudByConnectionMode(ConnectionMode mode) { var portOrBaud = 0; diff --git a/Source/NETworkManager.Settings/GlobalStaticConfiguration.cs b/Source/NETworkManager.Settings/GlobalStaticConfiguration.cs index 78cc1b8f1f..a91129ff65 100644 --- a/Source/NETworkManager.Settings/GlobalStaticConfiguration.cs +++ b/Source/NETworkManager.Settings/GlobalStaticConfiguration.cs @@ -118,6 +118,7 @@ public static class GlobalStaticConfiguration // Application: PuTTY public static PuTTY.ConnectionMode PuTTY_DefaultConnectionMode => PuTTY.ConnectionMode.SSH; + public static string PuTTY_SessionLogFileName = "&H_&Y&M&D_&T.log"; public static int PuTTY_SSHPort => 22; public static string PuTTY_SerialLine => "COM1"; public static int PuTTY_TelnetPort => 23; diff --git a/Source/NETworkManager.Settings/SettingsInfo.cs b/Source/NETworkManager.Settings/SettingsInfo.cs index 3084ded5f5..4749019bb9 100644 --- a/Source/NETworkManager.Settings/SettingsInfo.cs +++ b/Source/NETworkManager.Settings/SettingsInfo.cs @@ -2589,6 +2589,36 @@ public string PuTTY_Profile } } + private bool _puTTY_EnableSessionLog; + public bool PuTTY_EnableSessionLog + { + get => _puTTY_EnableSessionLog; + set + { + if (value == _puTTY_EnableSessionLog) + return; + + _puTTY_EnableSessionLog = value; + OnPropertyChanged(); + SettingsChanged = true; + } + } + + private string _puTTY_SessionLogFileName = GlobalStaticConfiguration.PuTTY_SessionLogFileName; + public string PuTTY_SessionLogFileName + { + get => _puTTY_SessionLogFileName; + set + { + if (value == _puTTY_SessionLogFileName) + return; + + _puTTY_SessionLogFileName = value; + OnPropertyChanged(); + SettingsChanged = true; + } + } + private string _puTTY_AdditionalCommandLine; public string PuTTY_AdditionalCommandLine { diff --git a/Source/NETworkManager/ProfileDialogManager.cs b/Source/NETworkManager/ProfileDialogManager.cs index 0db0cb7b36..603bf3f464 100644 --- a/Source/NETworkManager/ProfileDialogManager.cs +++ b/Source/NETworkManager/ProfileDialogManager.cs @@ -156,7 +156,7 @@ public static async void ShowEditGroupDialog(IProfileManager viewModel, IDialogC public static void AddProfile(ProfileViewModel instance) { - ProfileManager.AddProfile(new ProfileInfo + ProfileManager.AddProfile(new ProfileInfo { Name = instance.Name?.Trim(), Host = instance.Host?.Trim(), @@ -267,6 +267,10 @@ public static void AddProfile(ProfileViewModel instance) PuTTY_Username = instance.PuTTY_Username?.Trim(), PuTTY_OverrideProfile = instance.PuTTY_OverrideProfile, PuTTY_Profile = instance.PuTTY_Profile?.Trim(), + PuTTY_OverrideEnableSessionLog = instance.PuTTY_OverrideEnableSessionLog, + PuTTY_EnableSessionLog = instance.PuTTY_EnableSessionLog, + PuTTY_OverrideSessionLogFileName = instance.PuTTY_OverrideSessionLogFileName, + PuTTY_SessionLogFileName = instance.PuTTY_SessionLogFileName, PuTTY_OverrideAdditionalCommandLine = instance.PuTTY_OverrideAdditionalCommandLine, PuTTY_AdditionalCommandLine = instance.PuTTY_AdditionalCommandLine?.Trim(), diff --git a/Source/NETworkManager/ViewModels/ProfileViewModel.cs b/Source/NETworkManager/ViewModels/ProfileViewModel.cs index d97ff76efb..76a5d424e4 100644 --- a/Source/NETworkManager/ViewModels/ProfileViewModel.cs +++ b/Source/NETworkManager/ViewModels/ProfileViewModel.cs @@ -22,7 +22,7 @@ public class ProfileViewModel : ViewModelBase #region Variables private readonly bool _isLoading; public ICollectionView ProfileViews { get; } - + #region General private string _name; public string Name @@ -1649,6 +1649,62 @@ public string PuTTY_Profile } } + private bool _puTTY_OverrideEnableSessionLog; + public bool PuTTY_OverrideEnableSessionLog + { + get => _puTTY_OverrideEnableSessionLog; + set + { + if (value == _puTTY_OverrideEnableSessionLog) + return; + + _puTTY_OverrideEnableSessionLog = value; + OnPropertyChanged(); + } + } + + private bool _puTTY_EnableSessionLog; + public bool PuTTY_EnableSessionLog + { + get => _puTTY_EnableSessionLog; + set + { + if (value == _puTTY_EnableSessionLog) + return; + + _puTTY_EnableSessionLog = value; + OnPropertyChanged(); + } + } + + private bool _puTTY_OverrideSessionLogFileName; + public bool PuTTY_OverrideSessionLogFileName + { + get => _puTTY_OverrideSessionLogFileName; + set + { + if (value == _puTTY_OverrideSessionLogFileName) + return; + + _puTTY_OverrideSessionLogFileName = value; + OnPropertyChanged(); + } + } + + private string _puTTY_SessionLogFileName; + public string PuTTY_SessionLogFileName + { + get => _puTTY_SessionLogFileName; + set + { + if (value == _puTTY_SessionLogFileName) + return; + + _puTTY_SessionLogFileName = value; + OnPropertyChanged(); + } + } + private bool _puTTY_OverrideAdditionalCommandLine; public bool PuTTY_OverrideAdditionalCommandLine { @@ -2105,6 +2161,10 @@ public ProfileViewModel(Action saveCommand, Action _profile; + set + { + if (value == _profile) + return; - private string _additionalCommandLine; - public string AdditionalCommandLine + if (!_isLoading) + SettingsManager.Current.PuTTY_Profile = value; + + _profile = value; + OnPropertyChanged(); + } + } + + private bool _enableSessionLog; + public bool EnableSessionLog { - get => _additionalCommandLine; + get => _enableSessionLog; set { - if (value == _additionalCommandLine) + if (value == _enableSessionLog) return; if (!_isLoading) - SettingsManager.Current.PuTTY_AdditionalCommandLine = value; + SettingsManager.Current.PuTTY_EnableSessionLog = value; - _additionalCommandLine = value; + _enableSessionLog = value; OnPropertyChanged(); } } - private string _profile; - public string Profile + private string _sessionLogFileName; + public string SessionLogFileName { - get => _profile; + get => _sessionLogFileName; set { - if (value == _profile) + if (value == _sessionLogFileName) return; if (!_isLoading) - SettingsManager.Current.PuTTY_Profile = value; + SettingsManager.Current.PuTTY_SessionLogFileName = value; - _profile = value; + _sessionLogFileName = value; OnPropertyChanged(); } } + private string _additionalCommandLine; + public string AdditionalCommandLine + { + get => _additionalCommandLine; + set + { + if (value == _additionalCommandLine) + return; + + if (!_isLoading) + SettingsManager.Current.PuTTY_AdditionalCommandLine = value; + + _additionalCommandLine = value; + OnPropertyChanged(); + } + } + + private string _serialLine; public string SerialLine { @@ -310,6 +344,8 @@ private void LoadSettings() IsConfigured = File.Exists(ApplicationFilePath); Username = SettingsManager.Current.PuTTY_Username; Profile = SettingsManager.Current.PuTTY_Profile; + EnableSessionLog = SettingsManager.Current.PuTTY_EnableSessionLog; + SessionLogFileName = SettingsManager.Current.PuTTY_SessionLogFileName; AdditionalCommandLine = SettingsManager.Current.PuTTY_AdditionalCommandLine; SerialLine = SettingsManager.Current.PuTTY_SerialLine; SSHPort = SettingsManager.Current.PuTTY_SSHPort; diff --git a/Source/NETworkManager/Views/IPScannerSettingsView.xaml b/Source/NETworkManager/Views/IPScannerSettingsView.xaml index dc8db8cbfc..6b228a49e7 100644 --- a/Source/NETworkManager/Views/IPScannerSettingsView.xaml +++ b/Source/NETworkManager/Views/IPScannerSettingsView.xaml @@ -7,7 +7,7 @@ xmlns:validators="clr-namespace:NETworkManager.Validators;assembly=NETworkManager.Validators" xmlns:viewModels="clr-namespace:NETworkManager.ViewModels" xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks" - xmlns:utilities="clr-namespace:NETworkManager.Utilities" + xmlns:utilities="clr-namespace:NETworkManager.Utilities;assembly=NETworkManager.Utilities" xmlns:localization="clr-namespace:NETworkManager.Localization.Resources;assembly=NETworkManager.Localization" xmlns:dialogs="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro" dialogs:DialogParticipation.Register="{Binding}" diff --git a/Source/NETworkManager/Views/ProfileDialog.xaml b/Source/NETworkManager/Views/ProfileDialog.xaml index af0726f77f..2c5ce40a3c 100644 --- a/Source/NETworkManager/Views/ProfileDialog.xaml +++ b/Source/NETworkManager/Views/ProfileDialog.xaml @@ -1063,6 +1063,10 @@ + + + + @@ -1143,7 +1147,7 @@ - + @@ -1153,7 +1157,7 @@ - + @@ -1183,8 +1187,20 @@ - - + + + + + + + + + + + + + + @@ -1667,6 +1683,16 @@ + + + + + + + + + + diff --git a/Source/NETworkManager/Views/PuTTYSettingsView.xaml b/Source/NETworkManager/Views/PuTTYSettingsView.xaml index d9b0e41fd6..e0b5b15707 100644 --- a/Source/NETworkManager/Views/PuTTYSettingsView.xaml +++ b/Source/NETworkManager/Views/PuTTYSettingsView.xaml @@ -41,6 +41,17 @@ + + + + + + + + + + + From 7c98d6298dbfdad7a658357a029efd198bccd4fd Mon Sep 17 00:00:00 2001 From: BornToBeRoot Date: Sun, 29 Mar 2020 08:56:04 +0200 Subject: [PATCH 2/2] Update --- .../Resources/Strings.Designer.cs | 9 ++++++++ .../Resources/Strings.resx | 3 +++ .../Application/PuTTY.cs | 3 ++- .../Application/PuTTY.cs | 11 +--------- .../GlobalStaticConfiguration.cs | 3 ++- .../NETworkManager.Settings/SettingsInfo.cs | 15 +++++++++++++ .../DirectoryCreator.cs | 21 +++++++++++++++++++ .../NETworkManager.Utilities.csproj | 1 + .../NETworkManager/Controls/PuTTYControl.xaml | 2 +- .../Controls/PuTTYControl.xaml.cs | 3 +++ .../Controls/RemoteDesktopControl.xaml | 2 +- .../Controls/TightVNCControl.xaml | 2 +- .../Controls/WebConsoleControl.xaml | 2 +- .../ViewModels/PingHostViewModel.cs | 1 - .../ViewModels/PuTTYHostViewModel.cs | 9 +++----- .../ViewModels/PuTTYSettingsViewModel.cs | 18 ++++++++++++++++ .../ViewModels/TigerVNCHostViewModel.cs | 1 - .../Views/PuTTYSettingsView.xaml | 12 ++++++++++- 18 files changed, 93 insertions(+), 25 deletions(-) create mode 100644 Source/NETworkManager.Utilities/DirectoryCreator.cs diff --git a/Source/NETworkManager.Localization/Resources/Strings.Designer.cs b/Source/NETworkManager.Localization/Resources/Strings.Designer.cs index d1fe211a08..ee9c686dee 100644 --- a/Source/NETworkManager.Localization/Resources/Strings.Designer.cs +++ b/Source/NETworkManager.Localization/Resources/Strings.Designer.cs @@ -6461,6 +6461,15 @@ public static string SessionLogFileName { } } + /// + /// Looks up a localized string similar to Session log path. + /// + public static string SessionLogPath { + get { + return ResourceManager.GetString("SessionLogPath", resourceCulture); + } + } + /// /// Looks up a localized string similar to Set Master Password. /// diff --git a/Source/NETworkManager.Localization/Resources/Strings.resx b/Source/NETworkManager.Localization/Resources/Strings.resx index d009ba8658..825db83901 100644 --- a/Source/NETworkManager.Localization/Resources/Strings.resx +++ b/Source/NETworkManager.Localization/Resources/Strings.resx @@ -2857,4 +2857,7 @@ URL: https://github.com/BornToBeRoot/NETworkManager/tree/master/Documentation Session log file name + + Session log path + \ No newline at end of file diff --git a/Source/NETworkManager.Profiles/Application/PuTTY.cs b/Source/NETworkManager.Profiles/Application/PuTTY.cs index e13c32af8b..ae1fabb2e8 100644 --- a/Source/NETworkManager.Profiles/Application/PuTTY.cs +++ b/Source/NETworkManager.Profiles/Application/PuTTY.cs @@ -1,6 +1,7 @@ using NETworkManager.Models.PuTTY; using NETworkManager.Settings; using System.IO; +using System; namespace NETworkManager.Profiles.Application { @@ -16,7 +17,7 @@ public static PuTTYSessionInfo CreateSessionInfo(ProfileInfo profileInfo) Username = profileInfo.PuTTY_OverrideUsername ? profileInfo.PuTTY_Username : SettingsManager.Current.PuTTY_Username, Profile = profileInfo.PuTTY_OverrideProfile ? profileInfo.PuTTY_Profile : SettingsManager.Current.PuTTY_Profile, EnableSessionLog = profileInfo.PuTTY_OverrideEnableSessionLog ? profileInfo.PuTTY_EnableSessionLog : SettingsManager.Current.PuTTY_EnableSessionLog, - SessionLogFullName = Path.Combine(Settings.Application.PuTTY.LogPath, profileInfo.PuTTY_OverrideSessionLogFileName ? profileInfo.PuTTY_SessionLogFileName : SettingsManager.Current.PuTTY_SessionLogFileName), + SessionLogFullName = Environment.ExpandEnvironmentVariables(Path.Combine(SettingsManager.Current.PuTTY_SessionLogPath, profileInfo.PuTTY_OverrideSessionLogFileName ? profileInfo.PuTTY_SessionLogFileName : SettingsManager.Current.PuTTY_SessionLogFileName)), AdditionalCommandLine = profileInfo.PuTTY_OverrideAdditionalCommandLine ? profileInfo.PuTTY_AdditionalCommandLine : SettingsManager.Current.PuTTY_AdditionalCommandLine }; diff --git a/Source/NETworkManager.Settings/Application/PuTTY.cs b/Source/NETworkManager.Settings/Application/PuTTY.cs index 43e9990e81..b80a48330d 100644 --- a/Source/NETworkManager.Settings/Application/PuTTY.cs +++ b/Source/NETworkManager.Settings/Application/PuTTY.cs @@ -1,18 +1,9 @@ -using System; -using System.IO; -using static NETworkManager.Models.PuTTY.PuTTY; +using static NETworkManager.Models.PuTTY.PuTTY; namespace NETworkManager.Settings.Application { public static class PuTTY { - public static string LogPath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), AssemblyManager.Current.Name, "PuTTY_LogFiles"); - - public static void CreateLogPath() - { - Directory.CreateDirectory(LogPath); - } - public static int GetPortOrBaudByConnectionMode(ConnectionMode mode) { var portOrBaud = 0; diff --git a/Source/NETworkManager.Settings/GlobalStaticConfiguration.cs b/Source/NETworkManager.Settings/GlobalStaticConfiguration.cs index a91129ff65..47350c86f3 100644 --- a/Source/NETworkManager.Settings/GlobalStaticConfiguration.cs +++ b/Source/NETworkManager.Settings/GlobalStaticConfiguration.cs @@ -118,7 +118,8 @@ public static class GlobalStaticConfiguration // Application: PuTTY public static PuTTY.ConnectionMode PuTTY_DefaultConnectionMode => PuTTY.ConnectionMode.SSH; - public static string PuTTY_SessionLogFileName = "&H_&Y&M&D_&T.log"; + public static string PuTTY_SessionLogPath => Path.Combine("%LocalAppData%", AssemblyManager.Current.Name, "PuTTY_LogFiles"); + public static string PuTTY_SessionLogFileName => "&H_&Y-&M-&D_&T.log"; public static int PuTTY_SSHPort => 22; public static string PuTTY_SerialLine => "COM1"; public static int PuTTY_TelnetPort => 23; diff --git a/Source/NETworkManager.Settings/SettingsInfo.cs b/Source/NETworkManager.Settings/SettingsInfo.cs index 4749019bb9..5e8e356a8d 100644 --- a/Source/NETworkManager.Settings/SettingsInfo.cs +++ b/Source/NETworkManager.Settings/SettingsInfo.cs @@ -2604,6 +2604,21 @@ public bool PuTTY_EnableSessionLog } } + private string _puTTY_SessionLogPath = GlobalStaticConfiguration.PuTTY_SessionLogPath; + public string PuTTY_SessionLogPath + { + get => _puTTY_SessionLogPath; + set + { + if (value == _puTTY_SessionLogPath) + return; + + _puTTY_SessionLogPath = value; + OnPropertyChanged(); + SettingsChanged = true; + } + } + private string _puTTY_SessionLogFileName = GlobalStaticConfiguration.PuTTY_SessionLogFileName; public string PuTTY_SessionLogFileName { diff --git a/Source/NETworkManager.Utilities/DirectoryCreator.cs b/Source/NETworkManager.Utilities/DirectoryCreator.cs new file mode 100644 index 0000000000..0ab5d43a56 --- /dev/null +++ b/Source/NETworkManager.Utilities/DirectoryCreator.cs @@ -0,0 +1,21 @@ +using System; +using System.IO; + + +namespace NETworkManager.Utilities +{ + /// + /// Contains methods to create a directory with sub directories. + /// + public static class DirectoryCreator + { + /// + /// Create a directory with subdirectories and resolve environment variables. + /// + /// Path like "%AppDataLocal%\Folder1". + public static void CreateWithEnvironmentVariables(string path) + { + Directory.CreateDirectory(Environment.ExpandEnvironmentVariables(path)); + } + } +} diff --git a/Source/NETworkManager.Utilities/NETworkManager.Utilities.csproj b/Source/NETworkManager.Utilities/NETworkManager.Utilities.csproj index fc3f3d1c2f..0847626fb1 100644 --- a/Source/NETworkManager.Utilities/NETworkManager.Utilities.csproj +++ b/Source/NETworkManager.Utilities/NETworkManager.Utilities.csproj @@ -52,6 +52,7 @@ + diff --git a/Source/NETworkManager/Controls/PuTTYControl.xaml b/Source/NETworkManager/Controls/PuTTYControl.xaml index 66cc2c59f6..d0bfbc3d93 100644 --- a/Source/NETworkManager/Controls/PuTTYControl.xaml +++ b/Source/NETworkManager/Controls/PuTTYControl.xaml @@ -6,7 +6,7 @@ xmlns:converters="clr-namespace:NETworkManager.Converters;assembly=NETworkManager.Converters" xmlns:windowsForms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" xmlns:localization="clr-namespace:NETworkManager.Localization.Resources;assembly=NETworkManager.Localization" - xmlns:networkManagerControls="clr-namespace:NETworkManager.Controls" + xmlns:networkManagerControls="clr-namespace:NETworkManager.Controls;assembly=NETworkManager" xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls" mah:DialogParticipation.Register="{Binding}" mc:Ignorable="d" Loaded="UserControl_Loaded" d:DataContext="{d:DesignInstance networkManagerControls:PuTTYControl}"> diff --git a/Source/NETworkManager/Controls/PuTTYControl.xaml.cs b/Source/NETworkManager/Controls/PuTTYControl.xaml.cs index ccb684ae46..a929e0dcdf 100644 --- a/Source/NETworkManager/Controls/PuTTYControl.xaml.cs +++ b/Source/NETworkManager/Controls/PuTTYControl.xaml.cs @@ -122,6 +122,9 @@ private async void Connect() { IsConnecting = true; + // Create log path + DirectoryCreator.CreateWithEnvironmentVariables(SettingsManager.Current.PuTTY_SessionLogPath); + var info = new ProcessStartInfo { FileName = _sessionInfo.ApplicationFilePath, diff --git a/Source/NETworkManager/Controls/RemoteDesktopControl.xaml b/Source/NETworkManager/Controls/RemoteDesktopControl.xaml index beae7450c5..7fafd5357c 100644 --- a/Source/NETworkManager/Controls/RemoteDesktopControl.xaml +++ b/Source/NETworkManager/Controls/RemoteDesktopControl.xaml @@ -7,7 +7,7 @@ xmlns:converters="clr-namespace:NETworkManager.Converters;assembly=NETworkManager.Converters" xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls" xmlns:localization="clr-namespace:NETworkManager.Localization.Resources;assembly=NETworkManager.Localization" - xmlns:networkManagerControls="clr-namespace:NETworkManager.Controls" + xmlns:networkManagerControls="clr-namespace:NETworkManager.Controls;assembly=NETworkManager" mc:Ignorable="d" Loaded="UserControl_Loaded" d:DataContext="{d:DesignInstance networkManagerControls:RemoteDesktopControl}"> diff --git a/Source/NETworkManager/Controls/TightVNCControl.xaml b/Source/NETworkManager/Controls/TightVNCControl.xaml index 5a5664a18d..2348f9cc46 100644 --- a/Source/NETworkManager/Controls/TightVNCControl.xaml +++ b/Source/NETworkManager/Controls/TightVNCControl.xaml @@ -6,7 +6,7 @@ xmlns:converters="clr-namespace:NETworkManager.Converters;assembly=NETworkManager.Converters" xmlns:windowsForms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" xmlns:localization="clr-namespace:NETworkManager.Localization.Resources;assembly=NETworkManager.Localization" - xmlns:networkManagerControls="clr-namespace:NETworkManager.Controls" + xmlns:networkManagerControls="clr-namespace:NETworkManager.Controls;assembly=NETworkManager" xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls" mah:DialogParticipation.Register="{Binding}" mc:Ignorable="d" Loaded="UserControl_Loaded" d:DataContext="{d:DesignInstance networkManagerControls:TigerVNCControl}"> diff --git a/Source/NETworkManager/Controls/WebConsoleControl.xaml b/Source/NETworkManager/Controls/WebConsoleControl.xaml index 144608c3d9..be03df2973 100644 --- a/Source/NETworkManager/Controls/WebConsoleControl.xaml +++ b/Source/NETworkManager/Controls/WebConsoleControl.xaml @@ -3,7 +3,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:networkManagerControls="clr-namespace:NETworkManager.Controls" + xmlns:networkManagerControls="clr-namespace:NETworkManager.Controls;assembly=NETworkManager" xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls" xmlns:localization="clr-namespace:NETworkManager.Localization.Resources;assembly=NETworkManager.Localization" xmlns:converters="clr-namespace:NETworkManager.Converters;assembly=NETworkManager.Converters" diff --git a/Source/NETworkManager/ViewModels/PingHostViewModel.cs b/Source/NETworkManager/ViewModels/PingHostViewModel.cs index 03ecd496dd..2416a06bc2 100644 --- a/Source/NETworkManager/ViewModels/PingHostViewModel.cs +++ b/Source/NETworkManager/ViewModels/PingHostViewModel.cs @@ -13,7 +13,6 @@ using System.Windows; using NETworkManager.Profiles; using System.Windows.Threading; -using NETworkManager.Settings; using NETworkManager.Models; namespace NETworkManager.ViewModels diff --git a/Source/NETworkManager/ViewModels/PuTTYHostViewModel.cs b/Source/NETworkManager/ViewModels/PuTTYHostViewModel.cs index 4987b04a12..9eaaf0665e 100644 --- a/Source/NETworkManager/ViewModels/PuTTYHostViewModel.cs +++ b/Source/NETworkManager/ViewModels/PuTTYHostViewModel.cs @@ -381,7 +381,7 @@ private async void Connect(string host = null) Username = instance.Username, Profile = instance.Profile, EnableSessionLog = SettingsManager.Current.PuTTY_EnableSessionLog, - SessionLogFullName = Path.Combine(Settings.Application.PuTTY.LogPath, SettingsManager.Current.PuTTY_SessionLogFileName), + SessionLogFullName = Environment.ExpandEnvironmentVariables(Path.Combine(SettingsManager.Current.PuTTY_SessionLogPath, SettingsManager.Current.PuTTY_SessionLogFileName)), AdditionalCommandLine = instance.AdditionalCommandLine }; @@ -410,7 +410,7 @@ private void ConnectProfile() private void ConnectProfileExternal() { // Create log path - Directory.CreateDirectory(Settings.Application.PuTTY.LogPath); + DirectoryCreator.CreateWithEnvironmentVariables(SettingsManager.Current.PuTTY_SessionLogPath); var info = new ProcessStartInfo { @@ -423,9 +423,6 @@ private void ConnectProfileExternal() private void Connect(PuTTYSessionInfo profileInfo, string header = null) { - // Create log path - Settings.Application.PuTTY.CreateLogPath(); - // Add PuTTY path here... profileInfo.ApplicationFilePath = SettingsManager.Current.PuTTY_ApplicationFilePath; @@ -511,7 +508,7 @@ private static void AddProfileToHistory(string host) // Fill with the new items list.ForEach(x => SettingsManager.Current.PuTTY_ProfileHistory.Add(x)); } - + private void StartDelayedSearch() { if (!IsSearching) diff --git a/Source/NETworkManager/ViewModels/PuTTYSettingsViewModel.cs b/Source/NETworkManager/ViewModels/PuTTYSettingsViewModel.cs index a88536f3c3..1e99fd9de8 100644 --- a/Source/NETworkManager/ViewModels/PuTTYSettingsViewModel.cs +++ b/Source/NETworkManager/ViewModels/PuTTYSettingsViewModel.cs @@ -185,6 +185,23 @@ public bool EnableSessionLog } } + private string _sessionLogPath; + public string SessionLogPath + { + get => _sessionLogPath; + set + { + if (value == _sessionLogPath) + return; + + if (!_isLoading) + SettingsManager.Current.PuTTY_SessionLogPath = value; + + _sessionLogPath = value; + OnPropertyChanged(); + } + } + private string _sessionLogFileName; public string SessionLogFileName { @@ -345,6 +362,7 @@ private void LoadSettings() Username = SettingsManager.Current.PuTTY_Username; Profile = SettingsManager.Current.PuTTY_Profile; EnableSessionLog = SettingsManager.Current.PuTTY_EnableSessionLog; + SessionLogPath = SettingsManager.Current.PuTTY_SessionLogPath; SessionLogFileName = SettingsManager.Current.PuTTY_SessionLogFileName; AdditionalCommandLine = SettingsManager.Current.PuTTY_AdditionalCommandLine; SerialLine = SettingsManager.Current.PuTTY_SerialLine; diff --git a/Source/NETworkManager/ViewModels/TigerVNCHostViewModel.cs b/Source/NETworkManager/ViewModels/TigerVNCHostViewModel.cs index 8ba6f39f79..54c93704ec 100644 --- a/Source/NETworkManager/ViewModels/TigerVNCHostViewModel.cs +++ b/Source/NETworkManager/ViewModels/TigerVNCHostViewModel.cs @@ -16,7 +16,6 @@ using NETworkManager.Models.TigerVNC; using NETworkManager.Profiles; using System.Windows.Threading; -using NETworkManager.Settings; using NETworkManager.Models; using NETworkManager.Models.EventSystem; diff --git a/Source/NETworkManager/Views/PuTTYSettingsView.xaml b/Source/NETworkManager/Views/PuTTYSettingsView.xaml index e0b5b15707..b0ee523b77 100644 --- a/Source/NETworkManager/Views/PuTTYSettingsView.xaml +++ b/Source/NETworkManager/Views/PuTTYSettingsView.xaml @@ -42,12 +42,22 @@ + + + + + + + + + + - +