diff --git a/mRemoteNGTests/Config/Connections/XmlConnectionsLoaderTests.cs b/mRemoteNGTests/Config/Connections/XmlConnectionsLoaderTests.cs new file mode 100644 index 000000000..fa83cc400 --- /dev/null +++ b/mRemoteNGTests/Config/Connections/XmlConnectionsLoaderTests.cs @@ -0,0 +1,21 @@ +using mRemoteNG.Config.Connections; +using mRemoteNGTests.TestHelpers; +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace mRemoteNGTests.Config.Connections +{ + class XmlConnectionsLoaderTests + { + [Test] + public void ThrowsFileNotFound() + { + Assert.Throws(() => (new XmlConnectionsLoader(FileTestHelpers.NewTempFilePath())).Load()); + } + } +} diff --git a/mRemoteV1/App/Runtime.cs b/mRemoteV1/App/Runtime.cs index 5a650713c..d7449c4b9 100644 --- a/mRemoteV1/App/Runtime.cs +++ b/mRemoteV1/App/Runtime.cs @@ -138,7 +138,49 @@ namespace mRemoteNG.App if (ex is FileNotFoundException && !withDialog) { MessageCollector.AddExceptionMessage(string.Format(Language.strConnectionsFileCouldNotBeLoadedNew, connectionsLoader.ConnectionFileName), ex, MessageClass.InformationMsg); - ConnectionsService.NewConnections(connectionsLoader.ConnectionFileName); + + string[] commandButtons = + { + Language.ConfigurationCreateNew, + Language.ConfigurationCustomPath, + Language.ConfigurationImportFile, + Language.strMenuExit + }; + + bool answered = false; + while (!answered) + { + try + { + CTaskDialog.ShowTaskDialogBox(GeneralAppInfo.ProductName, Language.ConfigurationFileNotFound, "", "", "", "", "", string.Join(" | ", commandButtons), ETaskDialogButtons.None, ESysIcons.Question, ESysIcons.Question); + + switch (CTaskDialog.CommandButtonResult) + { + case 0: + ConnectionsService.NewConnections(connectionsLoader.ConnectionFileName); + answered = true; + break; + case 1: + LoadConnections(true); + answered = true; + break; + case 2: + ConnectionsService.NewConnections(connectionsLoader.ConnectionFileName); + Import.ImportFromFile(ConnectionsService.ConnectionTreeModel.RootNodes[0]); + answered = true; + break; + case 3: + Application.Exit(); + answered = true; + break; + } + } + catch (Exception exc) + { + MessageCollector.AddExceptionMessage(string.Format(Language.strConnectionsFileCouldNotBeLoadedNew, connectionsLoader.ConnectionFileName), exc, MessageClass.InformationMsg); + } + + } return; } diff --git a/mRemoteV1/Config/Connections/XmlConnectionsLoader.cs b/mRemoteV1/Config/Connections/XmlConnectionsLoader.cs index e2cee0c60..2d29c5e43 100644 --- a/mRemoteV1/Config/Connections/XmlConnectionsLoader.cs +++ b/mRemoteV1/Config/Connections/XmlConnectionsLoader.cs @@ -4,6 +4,7 @@ using mRemoteNG.Config.DataProviders; using mRemoteNG.Config.Serializers; using mRemoteNG.Tools; using mRemoteNG.Tree; +using System.IO; namespace mRemoteNG.Config.Connections { @@ -16,6 +17,9 @@ namespace mRemoteNG.Config.Connections if (string.IsNullOrEmpty(connectionFilePath)) throw new ArgumentException($"{nameof(connectionFilePath)} cannot be null or empty"); + if (!File.Exists(connectionFilePath)) + throw new FileNotFoundException($"{connectionFilePath} does not exist"); + _connectionFilePath = connectionFilePath; } diff --git a/mRemoteV1/Connection/ConnectionsService.cs b/mRemoteV1/Connection/ConnectionsService.cs index b0912f88d..e02c48e23 100644 --- a/mRemoteV1/Connection/ConnectionsService.cs +++ b/mRemoteV1/Connection/ConnectionsService.cs @@ -33,6 +33,7 @@ namespace mRemoteNG.Connection ConnectionTreeModel = newConnectionsModel, ConnectionFileName = filename }; + connectionSaver.SaveFilter = new Security.SaveFilter(); connectionSaver.SaveConnections(); // Load config diff --git a/mRemoteV1/Resources/Language/Language.Designer.cs b/mRemoteV1/Resources/Language/Language.Designer.cs index d910f6195..d6744f9bb 100644 --- a/mRemoteV1/Resources/Language/Language.Designer.cs +++ b/mRemoteV1/Resources/Language/Language.Designer.cs @@ -1,4 +1,4 @@ -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by a tool. // Runtime Version:4.0.30319.42000 @@ -60,6 +60,42 @@ namespace mRemoteNG } } + /// + /// Looks up a localized string similar to Create a New Configuration File. + /// + internal static string ConfigurationCreateNew { + get { + return ResourceManager.GetString("ConfigurationCreateNew", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Use a Custom File Path. + /// + internal static string ConfigurationCustomPath { + get { + return ResourceManager.GetString("ConfigurationCustomPath", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The Configuration File is Missing.. + /// + internal static string ConfigurationFileNotFound { + get { + return ResourceManager.GetString("ConfigurationFileNotFound", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Import an Existing File. + /// + internal static string ConfigurationImportFile { + get { + return ResourceManager.GetString("ConfigurationImportFile", resourceCulture); + } + } + /// /// Looks up a localized string similar to Could not find external tool with name "{0}". /// @@ -68,8 +104,8 @@ namespace mRemoteNG return ResourceManager.GetString("CouldNotFindExternalTool", resourceCulture); } } - - /// + + /// /// Looks up a localized string similar to Credentials. /// internal static string Credentials { @@ -539,7 +575,7 @@ namespace mRemoteNG /// /// Looks up a localized string similar to You cannot import a normal connection file. - ///Please use File - Load Connections for normal connection files!. + ///Please use File - Open Connection File for normal connection files!. /// internal static string strCannotImportNormalSessionFile { get { @@ -677,7 +713,7 @@ namespace mRemoteNG /// Looks up a localized string similar to The (RDP) Sessions feature requires that you have a copy of eolwtscom.dll registered on your system. ///mRemoteNG ships with this component but it is not registered automatically if you do not use the mRemoteNG Installer. ///To register it manually, run the following command from an elevated command prompt: regsvr32 "C:\Program Files\mRemoteNG\eolwtscom.dll" (where C:\Program Files\mRemoteNG\ is the path to your mRemoteNG installation). - ///If this check still fails or you are unable to use the (RDP) Sessions feature [rest of string was truncated]";. + ///If this check still fails or you are unable to use the (RDP) Sessions feat [rest of string was truncated]";. /// internal static string strCcEOLFailed { get { @@ -698,7 +734,7 @@ namespace mRemoteNG /// Looks up a localized string similar to To use the Gecko Rendering Engine you need to have XULrunner 1.8.1.x and the path to the installation set in your Options. ///You can download XULrunner 1.8.1.3 here: ftp://ftp.mozilla.org/pub/xulrunner/releases/1.8.1.3/contrib/win32/ ///When you are finished downloading extract the package to a path of your choice. Then in mRemoteNG go to Tools - Options - Advanced and enter the correct path in the XULrunner path field. - ///If you are still not able to pass this check or use the Gecko Engine in mRemoteNG please cons [rest of string was truncated]";. + ///If you are still not able to pass this check or use the Gecko Engine in mRemoteNG please c [rest of string was truncated]";. /// internal static string strCcGeckoFailed { get { @@ -718,7 +754,7 @@ namespace mRemoteNG /// /// Looks up a localized string similar to ICA requires that the XenDesktop Online Plugin is installed and that the wfica.ocx library is registered. You can download the client here: http://www.citrix.com/download/ ///If you have the XenDesktop Online Plugin installed and the check still fails, try to register wfica.ocx manually. - ///To do this open up the run dialog (Start - Run) and enter the following: regsvr32 "c:\Program Files\Citrix\ICA Client\wfica.ocx" (Where c:\Program Files\Citrix\ICA Client\ is the path to your XenDesktop Online Plugin installat [rest of string was truncated]";. + ///To do this open up the run dialog (Start - Run) and enter the following: regsvr32 "c:\Program Files\Citrix\ICA Client\wfica.ocx" (Where c:\Program Files\Citrix\ICA Client\ is the path to your XenDesktop Online Plugin install [rest of string was truncated]";. /// internal static string strCcICAFailed { get { diff --git a/mRemoteV1/Resources/Language/Language.resx b/mRemoteV1/Resources/Language/Language.resx index 95979d604..100f22e3a 100644 --- a/mRemoteV1/Resources/Language/Language.resx +++ b/mRemoteV1/Resources/Language/Language.resx @@ -2598,4 +2598,16 @@ This page will walk you through the process of upgrading your connections file o Could not find external tool with name "{0}" + + Create a New Configuration File + + + The Configuration File is Missing. + + + Import an Existing File + + + Use a Custom File Path + \ No newline at end of file