diff --git a/mRemoteV1/App/Initialization/CredsAndConsSetup.cs b/mRemoteV1/App/Initialization/CredsAndConsSetup.cs index 72446191..1ffce6c6 100644 --- a/mRemoteV1/App/Initialization/CredsAndConsSetup.cs +++ b/mRemoteV1/App/Initialization/CredsAndConsSetup.cs @@ -20,8 +20,8 @@ namespace mRemoteNG.App.Initialization public void LoadCredsAndCons() { - if (Settings.Default.FirstStart && !Settings.Default.LoadConsFromCustomLocation && !File.Exists(Runtime.GetStartupConnectionFileName())) - Runtime.ConnectionsService.NewConnections(Runtime.GetStartupConnectionFileName()); + if (Settings.Default.FirstStart && !Settings.Default.LoadConsFromCustomLocation && !File.Exists(Runtime.ConnectionsService.GetStartupConnectionFileName())) + Runtime.ConnectionsService.NewConnections(Runtime.ConnectionsService.GetStartupConnectionFileName()); LoadCredentialRepositoryList(); LoadDefaultConnectionCredentials(); diff --git a/mRemoteV1/App/Runtime.cs b/mRemoteV1/App/Runtime.cs index 6287d5f0..ada996e2 100644 --- a/mRemoteV1/App/Runtime.cs +++ b/mRemoteV1/App/Runtime.cs @@ -28,6 +28,13 @@ namespace mRemoteNG.App public static class Runtime { #region Public Properties + + #if PORTABLE + public static bool IsPortableEdition { get; } = true; + #else + public static bool IsPortableEdition { get; } = false; + #endif + public static WindowList WindowList { get; set; } public static MessageCollector MessageCollector { get; } = new MessageCollector(); public static NotificationAreaIcon NotificationAreaIcon { get; set; } @@ -80,7 +87,7 @@ namespace mRemoteNG.App } else { - connectionsLoader.ConnectionFileName = GetStartupConnectionFileName(); + connectionsLoader.ConnectionFileName = ConnectionsService.GetStartupConnectionFileName(); } CreateBackupFile(connectionsLoader.ConnectionFileName); @@ -96,7 +103,7 @@ namespace mRemoteNG.App } else { - if (connectionsLoader.ConnectionFileName == GetDefaultStartupConnectionFileName()) + if (connectionsLoader.ConnectionFileName == ConnectionsService.GetDefaultStartupConnectionFileName()) { Settings.Default.LoadConsFromCustomLocation = false; } @@ -139,14 +146,14 @@ namespace mRemoteNG.App } MessageCollector.AddExceptionMessage(string.Format(Language.strConnectionsFileCouldNotBeLoaded, connectionsLoader.ConnectionFileName), ex); - if (connectionsLoader.ConnectionFileName != GetStartupConnectionFileName()) + if (connectionsLoader.ConnectionFileName != ConnectionsService.GetStartupConnectionFileName()) { LoadConnections(withDialog); } else { MessageBox.Show(FrmMain.Default, - string.Format(Language.strErrorStartupConnectionFileLoad, Environment.NewLine, Application.ProductName, GetStartupConnectionFileName(), MiscTools.GetExceptionMessageRecursive(ex)), + string.Format(Language.strErrorStartupConnectionFileLoad, Environment.NewLine, Application.ProductName, ConnectionsService.GetStartupConnectionFileName(), MiscTools.GetExceptionMessageRecursive(ex)), @"Could not load startup file.", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } @@ -205,22 +212,6 @@ namespace mRemoteNG.App } } - private static string GetDefaultStartupConnectionFileName() - { - var newPath = ConnectionsFileInfo.DefaultConnectionsPath + "\\" + ConnectionsFileInfo.DefaultConnectionsFile; -#if !PORTABLE - var oldPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\" + Application.ProductName + "\\" + ConnectionsFileInfo.DefaultConnectionsFile; - // ReSharper disable once ConvertIfStatementToReturnStatement - if (File.Exists(oldPath)) return oldPath; -#endif - return newPath; - } - - public static string GetStartupConnectionFileName() - { - return Settings.Default.LoadConsFromCustomLocation == false ? GetDefaultStartupConnectionFileName() : Settings.Default.CustomConsPath; - } - public static void SaveConnectionsAsync() { var t = new Thread(SaveConnectionsBGd); @@ -248,7 +239,7 @@ namespace mRemoteNG.App var connectionsSaver = new ConnectionsSaver(); if (!Settings.Default.UseSQLServer) - connectionsSaver.ConnectionFileName = GetStartupConnectionFileName(); + connectionsSaver.ConnectionFileName = ConnectionsService.GetStartupConnectionFileName(); connectionsSaver.SaveFilter = new SaveFilter(); connectionsSaver.ConnectionTreeModel = ConnectionTreeModel; @@ -303,7 +294,7 @@ namespace mRemoteNG.App connectionsSave.SaveConnections(); - if (saveFileDialog.FileName == GetDefaultStartupConnectionFileName()) + if (saveFileDialog.FileName == ConnectionsService.GetDefaultStartupConnectionFileName()) { Settings.Default.LoadConsFromCustomLocation = false; } diff --git a/mRemoteV1/Connection/ConnectionsService.cs b/mRemoteV1/Connection/ConnectionsService.cs index ec0c4ffc..de666129 100644 --- a/mRemoteV1/Connection/ConnectionsService.cs +++ b/mRemoteV1/Connection/ConnectionsService.cs @@ -50,16 +50,25 @@ namespace mRemoteNG.Connection } } - private static string GetDefaultStartupConnectionFileName() + public string GetStartupConnectionFileName() { - var newPath = ConnectionsFileInfo.DefaultConnectionsPath + "\\" + ConnectionsFileInfo.DefaultConnectionsFile; -#if !PORTABLE - var oldPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\" + Application.ProductName + "\\" + ConnectionsFileInfo.DefaultConnectionsFile; - // ReSharper disable once ConvertIfStatementToReturnStatement - if (File.Exists(oldPath)) return oldPath; -#endif - return newPath; + return Settings.Default.LoadConsFromCustomLocation == false ? GetDefaultStartupConnectionFileName() : Settings.Default.CustomConsPath; } + public string GetDefaultStartupConnectionFileName() + { + return Runtime.IsPortableEdition ? GetDefaultStartupConnectionFileNamePortableEdition() : GetDefaultStartupConnectionFileNameNormalEdition(); + } + + private string GetDefaultStartupConnectionFileNameNormalEdition() + { + var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\" + Application.ProductName + "\\" + ConnectionsFileInfo.DefaultConnectionsFile; + return File.Exists(appDataPath) ? appDataPath : GetDefaultStartupConnectionFileNamePortableEdition(); + } + + private string GetDefaultStartupConnectionFileNamePortableEdition() + { + return ConnectionsFileInfo.DefaultConnectionsPath + "\\" + ConnectionsFileInfo.DefaultConnectionsFile; + } } } \ No newline at end of file diff --git a/mRemoteV1/UI/Window/ConfigWindow.cs b/mRemoteV1/UI/Window/ConfigWindow.cs index 6d445a8f..4e27138b 100644 --- a/mRemoteV1/UI/Window/ConfigWindow.cs +++ b/mRemoteV1/UI/Window/ConfigWindow.cs @@ -744,7 +744,7 @@ namespace mRemoteNG.UI.Window case "Password": if (rootInfo.Password) { - var passwordName = Settings.Default.UseSQLServer ? Language.strSQLServer.TrimEnd(':') : Path.GetFileName(Runtime.GetStartupConnectionFileName()); + var passwordName = Settings.Default.UseSQLServer ? Language.strSQLServer.TrimEnd(':') : Path.GetFileName(Runtime.ConnectionsService.GetStartupConnectionFileName()); var password = MiscTools.PasswordDialog(passwordName); if (password.Length == 0)