From f73c9c9d0281260fbac61ab409c7a3285becc02f Mon Sep 17 00:00:00 2001 From: Pedro Rodrigues Date: Fri, 15 Sep 2017 19:17:08 +0100 Subject: [PATCH] Refactored cons param, corrected fallback override on first initialization. Fixes 676 --- mRemoteV1/App/Startup.cs | 52 +++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/mRemoteV1/App/Startup.cs b/mRemoteV1/App/Startup.cs index 70135d543..ab1fdd00c 100644 --- a/mRemoteV1/App/Startup.cs +++ b/mRemoteV1/App/Startup.cs @@ -218,6 +218,30 @@ namespace mRemoteNG.App } } + /// + /// Returns a path to a file connections XML file for a given absolute or relative path + /// + /// The absolute or relative path to the connection XML file + /// string or null + private static string GetCustomConsPath(string ConsParam) + { + // early exit condition + if (string.IsNullOrEmpty(ConsParam)) + return null; + + // fallback paths + if (File.Exists(ConsParam)) + return ConsParam; + + if (File.Exists(GeneralAppInfo.HomePath + Path.DirectorySeparatorChar + ConsParam)) + return GeneralAppInfo.HomePath + Path.DirectorySeparatorChar + ConsParam; + + if (File.Exists(ConnectionsFileInfo.DefaultConnectionsPath + Path.DirectorySeparatorChar + ConsParam)) + return ConnectionsFileInfo.DefaultConnectionsPath + Path.DirectorySeparatorChar + ConsParam; + + // default case + return null; + } private static void ParseCommandLineArgs() { @@ -282,29 +306,13 @@ namespace mRemoteNG.App NoReconnectParam = "norc"; } - if (!string.IsNullOrEmpty(ConsParam)) + // Handle custom connection file location + Settings.Default.CustomConsPath = GetCustomConsPath(ConsParam); + if (Settings.Default.CustomConsPath != null) { - if (File.Exists(cmd[ConsParam])) - { - Settings.Default.LoadConsFromCustomLocation = true; - Settings.Default.CustomConsPath = cmd[ConsParam]; - return; - } - else - { - if (File.Exists(GeneralAppInfo.HomePath + "\\" + cmd[ConsParam])) - { - Settings.Default.LoadConsFromCustomLocation = true; - Settings.Default.CustomConsPath = GeneralAppInfo.HomePath + "\\" + cmd[ConsParam]; - return; - } - if (File.Exists(ConnectionsFileInfo.DefaultConnectionsPath + "\\" + cmd[ConsParam])) - { - Settings.Default.LoadConsFromCustomLocation = true; - Settings.Default.CustomConsPath = ConnectionsFileInfo.DefaultConnectionsPath + "\\" + cmd[ConsParam]; - return; - } - } + Settings.Default.LoadConsFromCustomLocation = true; + Settings.Default.Save(); + return; } if (!string.IsNullOrEmpty(ResetPosParam))