From 669e3a762be069861d1e5929339d3bf138a240c6 Mon Sep 17 00:00:00 2001 From: Sean Kaim Date: Thu, 12 May 2016 15:08:55 -0400 Subject: [PATCH 1/8] Removed PSTaskDialog instances & code cleanup --- mRemoteV1/App/Import.cs | 11 ++-- .../UI/Forms/OptionsPages/AdvancedPage.cs | 58 +++++++++---------- 2 files changed, 32 insertions(+), 37 deletions(-) diff --git a/mRemoteV1/App/Import.cs b/mRemoteV1/App/Import.cs index f6ca7f009..e125c898e 100644 --- a/mRemoteV1/App/Import.cs +++ b/mRemoteV1/App/Import.cs @@ -6,7 +6,6 @@ using System.Windows.Forms; using mRemoteNG.Config.Import; using mRemoteNG.Connection.Protocol; using mRemoteNG.Container; -using mRemoteNG.Tools; using mRemoteNG.Tree; using Microsoft.VisualBasic; using PSTaskDialog; @@ -87,11 +86,9 @@ namespace mRemoteNG.App } catch (Exception ex) { - cTaskDialog.ShowTaskDialogBox(Application.ProductName, - Language.strImportFileFailedMainInstruction, - string.Format(Language.strImportFileFailedContent, fileName), - MiscTools.GetExceptionMessageRecursive(ex), "", "", "", "", eTaskDialogButtons.OK, - eSysIcons.Error, eSysIcons.Error); + MessageBox.Show(string.Format(Language.strImportFileFailedContent, fileName), Language.strImportFileFailedMainInstruction, + MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); + Runtime.MessageCollector.AddExceptionMessage("App.Import.ImportFromFile() failed:1", ex, logOnly: true); } } @@ -107,7 +104,7 @@ namespace mRemoteNG.App } catch (Exception ex) { - Runtime.MessageCollector.AddExceptionMessage("App.Import.ImportFromFile() failed.", ex, logOnly: true); + Runtime.MessageCollector.AddExceptionMessage("App.Import.ImportFromFile() failed:2", ex, logOnly: true); } } diff --git a/mRemoteV1/UI/Forms/OptionsPages/AdvancedPage.cs b/mRemoteV1/UI/Forms/OptionsPages/AdvancedPage.cs index e831ee899..7ac0ef69d 100644 --- a/mRemoteV1/UI/Forms/OptionsPages/AdvancedPage.cs +++ b/mRemoteV1/UI/Forms/OptionsPages/AdvancedPage.cs @@ -1,12 +1,11 @@ using System; using System.IO; using System.Windows.Forms; +using mRemoteNG.App; using mRemoteNG.App.Info; using mRemoteNG.Config.Putty; using mRemoteNG.Connection.Protocol; -using mRemoteNG.My; using mRemoteNG.Tools; -using PSTaskDialog; namespace mRemoteNG.UI.Forms.OptionsPages { @@ -48,51 +47,51 @@ namespace mRemoteNG.UI.Forms.OptionsPages { base.SaveSettings(); - chkWriteLogFile.Checked = mRemoteNG.Settings.Default.WriteLogFile; + chkWriteLogFile.Checked = Settings.Default.WriteLogFile; - chkEncryptCompleteFile.Checked = mRemoteNG.Settings.Default.EncryptCompleteConnectionsFile; - chkAutomaticallyGetSessionInfo.Checked = mRemoteNG.Settings.Default.AutomaticallyGetSessionInfo; - chkAutomaticReconnect.Checked = mRemoteNG.Settings.Default.ReconnectOnDisconnect; - numPuttyWaitTime.Value = mRemoteNG.Settings.Default.MaxPuttyWaitTime; + chkEncryptCompleteFile.Checked = Settings.Default.EncryptCompleteConnectionsFile; + chkAutomaticallyGetSessionInfo.Checked = Settings.Default.AutomaticallyGetSessionInfo; + chkAutomaticReconnect.Checked = Settings.Default.ReconnectOnDisconnect; + numPuttyWaitTime.Value = Settings.Default.MaxPuttyWaitTime; - chkUseCustomPuttyPath.Checked = mRemoteNG.Settings.Default.UseCustomPuttyPath; - txtCustomPuttyPath.Text = mRemoteNG.Settings.Default.CustomPuttyPath; + chkUseCustomPuttyPath.Checked = Settings.Default.UseCustomPuttyPath; + txtCustomPuttyPath.Text = Settings.Default.CustomPuttyPath; SetPuttyLaunchButtonEnabled(); - numUVNCSCPort.Value = mRemoteNG.Settings.Default.UVNCSCPort; + numUVNCSCPort.Value = Settings.Default.UVNCSCPort; - txtXULrunnerPath.Text = mRemoteNG.Settings.Default.XULRunnerPath; + txtXULrunnerPath.Text = Settings.Default.XULRunnerPath; } public override void SaveSettings() { - mRemoteNG.Settings.Default.WriteLogFile = chkWriteLogFile.Checked; - mRemoteNG.Settings.Default.EncryptCompleteConnectionsFile = chkEncryptCompleteFile.Checked; - mRemoteNG.Settings.Default.AutomaticallyGetSessionInfo = chkAutomaticallyGetSessionInfo.Checked; - mRemoteNG.Settings.Default.ReconnectOnDisconnect = chkAutomaticReconnect.Checked; + Settings.Default.WriteLogFile = chkWriteLogFile.Checked; + Settings.Default.EncryptCompleteConnectionsFile = chkEncryptCompleteFile.Checked; + Settings.Default.AutomaticallyGetSessionInfo = chkAutomaticallyGetSessionInfo.Checked; + Settings.Default.ReconnectOnDisconnect = chkAutomaticReconnect.Checked; var puttyPathChanged = false; - if (mRemoteNG.Settings.Default.CustomPuttyPath != txtCustomPuttyPath.Text) + if (Settings.Default.CustomPuttyPath != txtCustomPuttyPath.Text) { puttyPathChanged = true; - mRemoteNG.Settings.Default.CustomPuttyPath = txtCustomPuttyPath.Text; + Settings.Default.CustomPuttyPath = txtCustomPuttyPath.Text; } - if (mRemoteNG.Settings.Default.UseCustomPuttyPath != chkUseCustomPuttyPath.Checked) + if (Settings.Default.UseCustomPuttyPath != chkUseCustomPuttyPath.Checked) { puttyPathChanged = true; - mRemoteNG.Settings.Default.UseCustomPuttyPath = chkUseCustomPuttyPath.Checked; + Settings.Default.UseCustomPuttyPath = chkUseCustomPuttyPath.Checked; } if (puttyPathChanged) { - PuttyBase.PuttyPath = mRemoteNG.Settings.Default.UseCustomPuttyPath ? mRemoteNG.Settings.Default.CustomPuttyPath : GeneralAppInfo.PuttyPath; + PuttyBase.PuttyPath = Settings.Default.UseCustomPuttyPath ? Settings.Default.CustomPuttyPath : GeneralAppInfo.PuttyPath; Sessions.AddSessionsToTree(); } - mRemoteNG.Settings.Default.MaxPuttyWaitTime = (int) numPuttyWaitTime.Value; - mRemoteNG.Settings.Default.UVNCSCPort = (int) numUVNCSCPort.Value; - mRemoteNG.Settings.Default.XULRunnerPath = txtXULrunnerPath.Text; + Settings.Default.MaxPuttyWaitTime = (int) numPuttyWaitTime.Value; + Settings.Default.UVNCSCPort = (int) numUVNCSCPort.Value; + Settings.Default.XULRunnerPath = txtXULrunnerPath.Text; - mRemoteNG.Settings.Default.Save(); + Settings.Default.Save(); } #endregion @@ -135,8 +134,7 @@ namespace mRemoteNG.UI.Forms.OptionsPages try { var puttyProcess = new PuttyProcessController(); - var fileName = ""; - fileName = chkUseCustomPuttyPath.Checked ? txtCustomPuttyPath.Text : GeneralAppInfo.PuttyPath; + var fileName = chkUseCustomPuttyPath.Checked ? txtCustomPuttyPath.Text : GeneralAppInfo.PuttyPath; puttyProcess.Start(fileName); puttyProcess.SetControlText("Button", "&Cancel", "&Close"); puttyProcess.SetControlVisible("Button", "&Open", false); @@ -144,8 +142,9 @@ namespace mRemoteNG.UI.Forms.OptionsPages } catch (Exception ex) { - cTaskDialog.MessageBox(Convert.ToString(Application.ProductName), Language.strErrorCouldNotLaunchPutty, - "", ex.Message, "", "", eTaskDialogButtons.OK, eSysIcons.Error, eSysIcons.Error); + MessageBox.Show(Language.strErrorCouldNotLaunchPutty, Application.ProductName, + MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); + Runtime.MessageCollector.AddExceptionMessage(Language.strErrorCouldNotLaunchPutty, ex, logOnly: true); } } @@ -165,8 +164,7 @@ namespace mRemoteNG.UI.Forms.OptionsPages private void SetPuttyLaunchButtonEnabled() { - var puttyPath = ""; - puttyPath = chkUseCustomPuttyPath.Checked ? txtCustomPuttyPath.Text : GeneralAppInfo.PuttyPath; + var puttyPath = chkUseCustomPuttyPath.Checked ? txtCustomPuttyPath.Text : GeneralAppInfo.PuttyPath; var exists = false; try From 634df366bdf37d3261c9ba113e4ea291b10e1464 Mon Sep 17 00:00:00 2001 From: amaterasu48 Date: Thu, 12 May 2016 14:59:39 -0700 Subject: [PATCH 2/8] Removed PSTaskDialog.dll reference added pure .NET Form that mimics PSTaskDialog. No more dependency to it, so we shouldn't see the unexpected error. --- mRemoteV1/App/Import.cs | 8 +- mRemoteV1/App/Runtime.cs | 8 +- mRemoteV1/App/Startup.cs | 56 +- .../Config/Connections/ConnectionsLoader.cs | 120 ++-- .../UI/Forms/OptionsPages/UpdatesPage.cs | 8 +- mRemoteV1/UI/Forms/frmMain.cs | 11 +- mRemoteV1/UI/TaskDialog/CommandButton.cs | 249 +++++++ .../UI/TaskDialog/CommandButton.designer.cs | 36 + mRemoteV1/UI/TaskDialog/cTaskDialog.cs | 353 ++++++++++ mRemoteV1/UI/TaskDialog/frmTaskDialog.cs | 440 ++++++++++++ .../UI/TaskDialog/frmTaskDialog.designer.cs | 334 ++++++++++ mRemoteV1/UI/TaskDialog/frmTaskDialog.resx | 344 ++++++++++ mRemoteV1/UI/TaskDialog/green_arrow1.png | Bin 0 -> 511 bytes mRemoteV1/UI/TaskDialog/green_arrow2.png | Bin 0 -> 501 bytes mRemoteV1/UI/Window/ConnectionWindow.cs | 625 +++++++++--------- mRemoteV1/mRemoteV1.csproj | 23 +- 16 files changed, 2192 insertions(+), 423 deletions(-) create mode 100644 mRemoteV1/UI/TaskDialog/CommandButton.cs create mode 100644 mRemoteV1/UI/TaskDialog/CommandButton.designer.cs create mode 100644 mRemoteV1/UI/TaskDialog/cTaskDialog.cs create mode 100644 mRemoteV1/UI/TaskDialog/frmTaskDialog.cs create mode 100644 mRemoteV1/UI/TaskDialog/frmTaskDialog.designer.cs create mode 100644 mRemoteV1/UI/TaskDialog/frmTaskDialog.resx create mode 100644 mRemoteV1/UI/TaskDialog/green_arrow1.png create mode 100644 mRemoteV1/UI/TaskDialog/green_arrow2.png diff --git a/mRemoteV1/App/Import.cs b/mRemoteV1/App/Import.cs index e125c898e..5fdb2dd9b 100644 --- a/mRemoteV1/App/Import.cs +++ b/mRemoteV1/App/Import.cs @@ -7,8 +7,8 @@ using mRemoteNG.Config.Import; using mRemoteNG.Connection.Protocol; using mRemoteNG.Container; using mRemoteNG.Tree; +using mRemoteNG.UI.TaskDialog; using Microsoft.VisualBasic; -using PSTaskDialog; namespace mRemoteNG.App { @@ -192,11 +192,11 @@ namespace mRemoteNG.App } else { - cTaskDialog.ShowCommandBox(Application.ProductName, Language.strImportLocationMainInstruction, + CTaskDialog.ShowCommandBox(Application.ProductName, Language.strImportLocationMainInstruction, Language.strImportLocationContent, "", "", "", string.Format(Language.strImportLocationCommandButtons, Constants.vbLf, rootTreeNode.Text, - selectedTreeNode.Text), true, eSysIcons.Question, 0); - switch (cTaskDialog.CommandButtonResult) + selectedTreeNode.Text), true, ESysIcons.Question, 0); + switch (CTaskDialog.CommandButtonResult) { case 0: // Root parentTreeNode = rootTreeNode; diff --git a/mRemoteV1/App/Runtime.cs b/mRemoteV1/App/Runtime.cs index 87e3c1d4b..e8f4c2b4d 100644 --- a/mRemoteV1/App/Runtime.cs +++ b/mRemoteV1/App/Runtime.cs @@ -12,7 +12,6 @@ using mRemoteNG.Messages; using mRemoteNG.Tools; using mRemoteNG.Tree; using mRemoteNG.UI.Window; -using PSTaskDialog; using System; using System.Collections; using System.Collections.Generic; @@ -23,6 +22,7 @@ using System.Windows.Forms; using System.Xml; using mRemoteNG.My; using mRemoteNG.UI.Forms; +using mRemoteNG.UI.TaskDialog; using WeifenLuo.WinFormsUI.Docking; @@ -628,8 +628,8 @@ namespace mRemoteNG.App { MessageCollector.AddExceptionMessage(Language.strLoadFromSqlFailed, ex); string commandButtons = string.Join("|", new[] {Language.strCommandTryAgain, Language.strCommandOpenConnectionFile, string.Format(Language.strCommandExitProgram, Application.ProductName)}); - cTaskDialog.ShowCommandBox(Application.ProductName, Language.strLoadFromSqlFailed, Language.strLoadFromSqlFailedContent, MiscTools.GetExceptionMessageRecursive(ex), "", "", commandButtons, false, eSysIcons.Error, eSysIcons.Error); - switch (cTaskDialog.CommandButtonResult) + CTaskDialog.ShowCommandBox(Application.ProductName, Language.strLoadFromSqlFailed, Language.strLoadFromSqlFailedContent, MiscTools.GetExceptionMessageRecursive(ex), "", "", commandButtons, false, ESysIcons.Error, ESysIcons.Error); + switch (CTaskDialog.CommandButtonResult) { case 0: LoadConnections(withDialog, update); @@ -653,7 +653,7 @@ namespace mRemoteNG.App } MessageCollector.AddExceptionMessage(string.Format(Language.strConnectionsFileCouldNotBeLoaded, connectionsLoader.ConnectionFileName), ex); - if (!(connectionsLoader.ConnectionFileName == GetStartupConnectionFileName())) + if (connectionsLoader.ConnectionFileName != GetStartupConnectionFileName()) { LoadConnections(withDialog, update); return ; diff --git a/mRemoteV1/App/Startup.cs b/mRemoteV1/App/Startup.cs index a9ad7e7b5..96b8e5c55 100644 --- a/mRemoteV1/App/Startup.cs +++ b/mRemoteV1/App/Startup.cs @@ -6,7 +6,6 @@ using mRemoteNG.My; using mRemoteNG.Tools; using mRemoteNG.Tree; using mRemoteNG.UI.Window; -using PSTaskDialog; using System; using System.ComponentModel; using System.Diagnostics; @@ -18,6 +17,7 @@ using System.Windows.Forms; using WeifenLuo.WinFormsUI.Docking; using mRemoteNG.Config.Connections; using mRemoteNG.UI.Forms; +using mRemoteNG.UI.TaskDialog; namespace mRemoteNG.App { @@ -38,7 +38,7 @@ namespace mRemoteNG.App bool isFipsPolicyEnabled = false; // Windows XP/Windows Server 2003 - regKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("System\\CurrentControlSet\\Control\\Lsa"); + regKey = Registry.LocalMachine.OpenSubKey("System\\CurrentControlSet\\Control\\Lsa"); if (regKey != null) { if ((int)regKey.GetValue("FIPSAlgorithmPolicy") != 0) @@ -48,7 +48,7 @@ namespace mRemoteNG.App } // Windows Vista/Windows Server 2008 and newer - regKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("System\\CurrentControlSet\\Control\\Lsa\\FIPSAlgorithmPolicy"); + regKey = Registry.LocalMachine.OpenSubKey("System\\CurrentControlSet\\Control\\Lsa\\FIPSAlgorithmPolicy"); if (regKey != null) { if ((int)regKey.GetValue("Enabled") != 0) @@ -60,12 +60,12 @@ namespace mRemoteNG.App if (isFipsPolicyEnabled) { MessageBox.Show(frmMain.Default, string.Format(Language.strErrorFipsPolicyIncompatible, (new Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase()).Info.ProductName), (new Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase()).Info.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); - System.Environment.Exit(1); + Environment.Exit(1); } } private static void CheckLenovoAutoScrollUtility() { - if (!mRemoteNG.Settings.Default.CompatibilityWarnLenovoAutoScrollUtility) + if (!Settings.Default.CompatibilityWarnLenovoAutoScrollUtility) { return; } @@ -83,10 +83,10 @@ namespace mRemoteNG.App return; } - cTaskDialog.MessageBox(System.Windows.Forms.Application.ProductName, Language.strCompatibilityProblemDetected, string.Format(Language.strCompatibilityLenovoAutoScrollUtilityDetected, System.Windows.Forms.Application.ProductName), "", "", Language.strCheckboxDoNotShowThisMessageAgain, eTaskDialogButtons.OK, eSysIcons.Warning, eSysIcons.Warning); - if (cTaskDialog.VerificationChecked) + CTaskDialog.MessageBox(Application.ProductName, Language.strCompatibilityProblemDetected, string.Format(Language.strCompatibilityLenovoAutoScrollUtilityDetected, Application.ProductName), "", "", Language.strCheckboxDoNotShowThisMessageAgain, ETaskDialogButtons.Ok, ESysIcons.Warning, ESysIcons.Warning); + if (CTaskDialog.VerificationChecked) { - mRemoteNG.Settings.Default.CompatibilityWarnLenovoAutoScrollUtility = false; + Settings.Default.CompatibilityWarnLenovoAutoScrollUtility = false; } } @@ -152,7 +152,7 @@ namespace mRemoteNG.App } public static void LogStartupData() { - if (mRemoteNG.Settings.Default.WriteLogFile) + if (Settings.Default.WriteLogFile) { LogApplicationData(); LogCmdLineArgs(); @@ -224,7 +224,7 @@ namespace mRemoteNG.App #if !PORTABLE Runtime.Log.InfoFormat("{0} {1} starting.", System.Windows.Forms.Application.ProductName, System.Windows.Forms.Application.ProductVersion); #else - Runtime.Log.InfoFormat("{0} {1} {2} starting.", System.Windows.Forms.Application.ProductName, System.Windows.Forms.Application.ProductVersion, Language.strLabelPortableEdition); + Runtime.Log.InfoFormat("{0} {1} {2} starting.", Application.ProductName, Application.ProductVersion, Language.strLabelPortableEdition); #endif } private static void LogCmdLineArgs() @@ -233,7 +233,7 @@ namespace mRemoteNG.App } private static void LogCLRData() { - Runtime.Log.InfoFormat("Microsoft .NET CLR {0}", System.Environment.Version.ToString()); + Runtime.Log.InfoFormat("Microsoft .NET CLR {0}", Environment.Version.ToString()); } private static void LogCultureData() { @@ -243,7 +243,7 @@ namespace mRemoteNG.App public static void CreateConnectionsProvider() { - if (mRemoteNG.Settings.Default.UseSQLServer == true) + if (Settings.Default.UseSQLServer == true) { SqlConnectionsProvider _sqlConnectionsProvider = new SqlConnectionsProvider(); } @@ -260,8 +260,8 @@ namespace mRemoteNG.App return; } - DateTime nextUpdateCheck = Convert.ToDateTime(mRemoteNG.Settings.Default.CheckForUpdatesLastCheck.Add(TimeSpan.FromDays(Convert.ToDouble(mRemoteNG.Settings.Default.CheckForUpdatesFrequencyDays)))); - if (!mRemoteNG.Settings.Default.UpdatePending && DateTime.UtcNow < nextUpdateCheck) + DateTime nextUpdateCheck = Convert.ToDateTime(Settings.Default.CheckForUpdatesLastCheck.Add(TimeSpan.FromDays(Convert.ToDouble(Settings.Default.CheckForUpdatesFrequencyDays)))); + if (!Settings.Default.UpdatePending && DateTime.UtcNow < nextUpdateCheck) { return; } @@ -414,46 +414,46 @@ namespace mRemoteNG.App { if (File.Exists((new Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase()).Info.DirectoryPath + "\\" + cmd[ConsParam])) { - mRemoteNG.Settings.Default.LoadConsFromCustomLocation = true; - mRemoteNG.Settings.Default.CustomConsPath = (new Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase()).Info.DirectoryPath + "\\" + cmd[ConsParam]; + Settings.Default.LoadConsFromCustomLocation = true; + Settings.Default.CustomConsPath = (new Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase()).Info.DirectoryPath + "\\" + cmd[ConsParam]; return; } - else if (File.Exists(App.Info.ConnectionsFileInfo.DefaultConnectionsPath + "\\" + cmd[ConsParam])) + else if (File.Exists(Info.ConnectionsFileInfo.DefaultConnectionsPath + "\\" + cmd[ConsParam])) { - mRemoteNG.Settings.Default.LoadConsFromCustomLocation = true; - mRemoteNG.Settings.Default.CustomConsPath = App.Info.ConnectionsFileInfo.DefaultConnectionsPath + "\\" + cmd[ConsParam]; + Settings.Default.LoadConsFromCustomLocation = true; + Settings.Default.CustomConsPath = Info.ConnectionsFileInfo.DefaultConnectionsPath + "\\" + cmd[ConsParam]; return; } } else { - mRemoteNG.Settings.Default.LoadConsFromCustomLocation = true; - mRemoteNG.Settings.Default.CustomConsPath = cmd[ConsParam]; + Settings.Default.LoadConsFromCustomLocation = true; + Settings.Default.CustomConsPath = cmd[ConsParam]; return; } } if (!string.IsNullOrEmpty(ResetPosParam)) { - mRemoteNG.Settings.Default.MainFormKiosk = false; - mRemoteNG.Settings.Default.MainFormLocation = new Point(999, 999); - mRemoteNG.Settings.Default.MainFormSize = new Size(900, 600); - mRemoteNG.Settings.Default.MainFormState = FormWindowState.Normal; + Settings.Default.MainFormKiosk = false; + Settings.Default.MainFormLocation = new Point(999, 999); + Settings.Default.MainFormSize = new Size(900, 600); + Settings.Default.MainFormState = FormWindowState.Normal; } if (!string.IsNullOrEmpty(ResetPanelsParam)) { - mRemoteNG.Settings.Default.ResetPanels = true; + Settings.Default.ResetPanels = true; } if (!string.IsNullOrEmpty(NoReconnectParam)) { - mRemoteNG.Settings.Default.NoReconnect = true; + Settings.Default.NoReconnect = true; } if (!string.IsNullOrEmpty(ResetToolbarsParam)) { - mRemoteNG.Settings.Default.ResetToolbars = true; + Settings.Default.ResetToolbars = true; } } catch (Exception ex) diff --git a/mRemoteV1/Config/Connections/ConnectionsLoader.cs b/mRemoteV1/Config/Connections/ConnectionsLoader.cs index 69b4e0d28..0406db855 100644 --- a/mRemoteV1/Config/Connections/ConnectionsLoader.cs +++ b/mRemoteV1/Config/Connections/ConnectionsLoader.cs @@ -4,7 +4,6 @@ using mRemoteNG.Connection.Protocol.ICA; using mRemoteNG.Connection.Protocol.VNC; using mRemoteNG.Connection.Protocol.RDP; using mRemoteNG.My; -using PSTaskDialog; using System; using System.Data; using System.Data.SqlClient; @@ -19,6 +18,7 @@ using mRemoteNG.Connection.Protocol; using mRemoteNG.Images; using mRemoteNG.UI.Forms; using mRemoteNG.Tree.Root; +using mRemoteNG.UI.TaskDialog; namespace mRemoteNG.Config.Connections { @@ -90,8 +90,8 @@ namespace mRemoteNG.Config.Connections public string ConnectionFileName { - get { return this._ConnectionFileName; } - set { this._ConnectionFileName = value; } + get { return _ConnectionFileName; } + set { _ConnectionFileName = value; } } public TreeNode RootTreeNode {get; set;} @@ -100,8 +100,8 @@ namespace mRemoteNG.Config.Connections public ContainerList ContainerList { - get { return this._ContainerList; } - set { this._ContainerList = value; } + get { return _ContainerList; } + set { _ContainerList = value; } } public ConnectionList PreviousConnectionList @@ -188,19 +188,19 @@ namespace mRemoteNG.Config.Connections const double maxSupportedSchemaVersion = 2.5; if (confVersion > maxSupportedSchemaVersion) { - cTaskDialog.ShowTaskDialogBox( + CTaskDialog.ShowTaskDialogBox( frmMain.Default, - System.Windows.Forms.Application.ProductName, + Application.ProductName, "Incompatible database schema", - $"The database schema on the server is not supported. Please upgrade to a newer version of {System.Windows.Forms.Application.ProductName}.", + $"The database schema on the server is not supported. Please upgrade to a newer version of {Application.ProductName}.", string.Format("Schema Version: {1}{0}Highest Supported Version: {2}", Environment.NewLine, confVersion.ToString(), maxSupportedSchemaVersion.ToString()), "", "", "", "", - eTaskDialogButtons.OK, - eSysIcons.Error, - eSysIcons.Error + ETaskDialogButtons.Ok, + ESysIcons.Error, + ESysIcons.Error ); throw (new Exception($"Incompatible database schema (schema version {confVersion}).")); } @@ -236,7 +236,7 @@ namespace mRemoteNG.Config.Connections RootTreeNode.Expand(); //expand containers - foreach (ContainerInfo contI in this._ContainerList) + foreach (ContainerInfo contI in _ContainerList) { if (contI.IsExpanded == true) { @@ -312,7 +312,7 @@ namespace mRemoteNG.Config.Connections conI.TreeNode = tNode; //conI.Parent = _previousContainer 'NEW - this.ConnectionList.Add(conI); + ConnectionList.Add(conI); tNode.Tag = conI; @@ -322,7 +322,7 @@ namespace mRemoteNG.Config.Connections if (prevCon != null) { - foreach (Connection.Protocol.ProtocolBase prot in prevCon.OpenConnections) + foreach (ProtocolBase prot in prevCon.OpenConnections) { prot.InterfaceControl.Info = conI; conI.OpenConnections.Add(prot); @@ -402,8 +402,8 @@ namespace mRemoteNG.Config.Connections } } - this._ContainerList.Add(contI); - this.ConnectionList.Add(conI); + _ContainerList.Add(contI); + ConnectionList.Add(conI); tNode.Tag = contI; tNode.ImageIndex = (int)TreeImageType.Container; @@ -501,7 +501,7 @@ namespace mRemoteNG.Config.Connections connectionInfo.Icon = Convert.ToString(sqlRd["Icon"]); connectionInfo.Panel = Convert.ToString(sqlRd["Panel"]); - if (this.confVersion > 1.5) //1.6 + if (confVersion > 1.5) //1.6 { connectionInfo.ICAEncryption = (ProtocolICA.EncryptionStrength)Tools.MiscTools.StringToEnum(typeof(ProtocolICA.EncryptionStrength), Convert.ToString(sqlRd["ICAEncryptionStrength"])); connectionInfo.Inheritance.ICAEncryption = Convert.ToBoolean(sqlRd["InheritICAEncryptionStrength"]); @@ -511,7 +511,7 @@ namespace mRemoteNG.Config.Connections connectionInfo.Inheritance.PostExtApp = Convert.ToBoolean(sqlRd["InheritPostExtApp"]); } - if (this.confVersion > 1.6) //1.7 + if (confVersion > 1.6) //1.7 { connectionInfo.VNCCompression = (ProtocolVNC.Compression)Tools.MiscTools.StringToEnum(typeof(ProtocolVNC.Compression), Convert.ToString(sqlRd["VNCCompression"])); connectionInfo.VNCEncoding = (ProtocolVNC.Encoding)Tools.MiscTools.StringToEnum(typeof(ProtocolVNC.Encoding), Convert.ToString(sqlRd["VNCEncoding"])); @@ -537,13 +537,13 @@ namespace mRemoteNG.Config.Connections connectionInfo.Inheritance.VNCViewOnly = Convert.ToBoolean(sqlRd["InheritVNCViewOnly"]); } - if (this.confVersion > 1.7) //1.8 + if (confVersion > 1.7) //1.8 { connectionInfo.RDPAuthenticationLevel = (ProtocolRDP.AuthenticationLevel)Tools.MiscTools.StringToEnum(typeof(ProtocolRDP.AuthenticationLevel), Convert.ToString(sqlRd["RDPAuthenticationLevel"])); connectionInfo.Inheritance.RDPAuthenticationLevel = Convert.ToBoolean(sqlRd["InheritRDPAuthenticationLevel"]); } - if (this.confVersion > 1.8) //1.9 + if (confVersion > 1.8) //1.9 { connectionInfo.RenderingEngine = (HTTPBase.RenderingEngine)Tools.MiscTools.StringToEnum(typeof(HTTPBase.RenderingEngine), Convert.ToString(sqlRd["RenderingEngine"])); connectionInfo.MacAddress = Convert.ToString(sqlRd["MacAddress"]); @@ -551,19 +551,19 @@ namespace mRemoteNG.Config.Connections connectionInfo.Inheritance.MacAddress = Convert.ToBoolean(sqlRd["InheritMacAddress"]); } - if (this.confVersion > 1.9) //2.0 + if (confVersion > 1.9) //2.0 { connectionInfo.UserField = Convert.ToString(sqlRd["UserField"]); connectionInfo.Inheritance.UserField = Convert.ToBoolean(sqlRd["InheritUserField"]); } - if (this.confVersion > 2.0) //2.1 + if (confVersion > 2.0) //2.1 { connectionInfo.ExtApp = Convert.ToString(sqlRd["ExtApp"]); connectionInfo.Inheritance.ExtApp = Convert.ToBoolean(sqlRd["InheritExtApp"]); } - if (this.confVersion >= 2.2) + if (confVersion >= 2.2) { connectionInfo.RDGatewayUsageMethod = (ProtocolRDP.RDGatewayUsageMethod)Tools.MiscTools.StringToEnum(typeof(ProtocolRDP.RDGatewayUsageMethod), Convert.ToString(sqlRd["RDGatewayUsageMethod"])); connectionInfo.RDGatewayHostname = Convert.ToString(sqlRd["RDGatewayHostname"]); @@ -578,7 +578,7 @@ namespace mRemoteNG.Config.Connections connectionInfo.Inheritance.RDGatewayDomain = Convert.ToBoolean(sqlRd["InheritRDGatewayDomain"]); } - if (this.confVersion >= 2.3) + if (confVersion >= 2.3) { connectionInfo.EnableFontSmoothing = Convert.ToBoolean(sqlRd["EnableFontSmoothing"]); connectionInfo.EnableDesktopComposition = Convert.ToBoolean(sqlRd["EnableDesktopComposition"]); @@ -619,7 +619,7 @@ namespace mRemoteNG.Config.Connections #region XML private string DecryptCompleteFile() { - StreamReader sRd = new StreamReader(this._ConnectionFileName); + StreamReader sRd = new StreamReader(_ConnectionFileName); string strCons = ""; strCons = sRd.ReadToEnd(); @@ -686,19 +686,19 @@ namespace mRemoteNG.Config.Connections } // SECTION 1. Create a DOM Document and load the XML data into it. - this.xDom = new XmlDocument(); + xDom = new XmlDocument(); if (cons != "") { xDom.LoadXml(cons); } else { - xDom.Load(this._ConnectionFileName); + xDom.Load(_ConnectionFileName); } if (xDom.DocumentElement.HasAttribute("ConfVersion")) { - this.confVersion = Convert.ToDouble(xDom.DocumentElement.Attributes["ConfVersion"].Value.Replace(",", "."), CultureInfo.InvariantCulture); + confVersion = Convert.ToDouble(xDom.DocumentElement.Attributes["ConfVersion"].Value.Replace(",", "."), CultureInfo.InvariantCulture); } else { @@ -708,19 +708,19 @@ namespace mRemoteNG.Config.Connections const double maxSupportedConfVersion = 2.5; if (confVersion > maxSupportedConfVersion) { - cTaskDialog.ShowTaskDialogBox( + CTaskDialog.ShowTaskDialogBox( frmMain.Default, - System.Windows.Forms.Application.ProductName, + Application.ProductName, "Incompatible connection file format", - string.Format("The format of this connection file is not supported. Please upgrade to a newer version of {0}.", System.Windows.Forms.Application.ProductName), + string.Format("The format of this connection file is not supported. Please upgrade to a newer version of {0}.", Application.ProductName), string.Format("{1}{0}File Format Version: {2}{0}Highest Supported Version: {3}", Environment.NewLine, ConnectionFileName, confVersion.ToString(), maxSupportedConfVersion.ToString()), "", "", "", "", - eTaskDialogButtons.OK, - eSysIcons.Error, - eSysIcons.Error + ETaskDialogButtons.Ok, + ESysIcons.Error, + ESysIcons.Error ); throw (new Exception(string.Format("Incompatible connection file format (file format version {0}).", confVersion))); } @@ -755,7 +755,7 @@ namespace mRemoteNG.Config.Connections RootTreeNode.Tag = rootInfo; } - if (this.confVersion > 1.3) //1.4 + if (confVersion > 1.3) //1.4 { if (Security.Crypt.Decrypt(Convert.ToString(xDom.DocumentElement.Attributes["Protected"].Value), pW) != "ThisIsNotProtected") { @@ -798,7 +798,7 @@ namespace mRemoteNG.Config.Connections RootTreeNode.Expand(); //expand containers - foreach (ContainerInfo contI in this._ContainerList) + foreach (ContainerInfo contI in _ContainerList) { if (contI.IsExpanded == true) { @@ -831,7 +831,7 @@ namespace mRemoteNG.Config.Connections } catch (Exception ex) { - App.Runtime.IsConnectionsFileLoaded = false; + Runtime.IsConnectionsFileLoaded = false; Runtime.MessageCollector.AddMessage(Messages.MessageClass.ErrorMsg, Language.strLoadFromXmlFailed + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace, true); throw; } @@ -945,7 +945,7 @@ namespace mRemoteNG.Config.Connections try { XmlNode xmlnode = xxNode; - if (this.confVersion > 0.1) //0.2 + if (confVersion > 0.1) //0.2 { connectionInfo.Name = xmlnode.Attributes["Name"].Value; connectionInfo.Description = xmlnode.Attributes["Descr"].Value; @@ -957,7 +957,7 @@ namespace mRemoteNG.Config.Connections connectionInfo.DisplayThemes = bool.Parse(xmlnode.Attributes["DisplayThemes"].Value); connectionInfo.CacheBitmaps = bool.Parse(xmlnode.Attributes["CacheBitmaps"].Value); - if (this.confVersion < 1.1) //1.0 - 0.1 + if (confVersion < 1.1) //1.0 - 0.1 { if (Convert.ToBoolean(xmlnode.Attributes["Fullscreen"].Value) == true) { @@ -970,9 +970,9 @@ namespace mRemoteNG.Config.Connections } } - if (this.confVersion > 0.2) //0.3 + if (confVersion > 0.2) //0.3 { - if (this.confVersion < 0.7) + if (confVersion < 0.7) { if (Convert.ToBoolean(xmlnode.Attributes["UseVNC"].Value) == true) { @@ -991,9 +991,9 @@ namespace mRemoteNG.Config.Connections connectionInfo.Protocol = ProtocolType.RDP; } - if (this.confVersion > 0.3) //0.4 + if (confVersion > 0.3) //0.4 { - if (this.confVersion < 0.7) + if (confVersion < 0.7) { if (Convert.ToBoolean(xmlnode.Attributes["UseVNC"].Value) == true) connectionInfo.Port = Convert.ToInt32(xmlnode.Attributes["VNCPort"].Value); @@ -1005,7 +1005,7 @@ namespace mRemoteNG.Config.Connections } else { - if (this.confVersion < 0.7) + if (confVersion < 0.7) { if (Convert.ToBoolean(xmlnode.Attributes["UseVNC"].Value) == true) connectionInfo.Port = (int)ProtocolVNC.Defaults.Port; @@ -1015,7 +1015,7 @@ namespace mRemoteNG.Config.Connections connectionInfo.UseConsoleSession = false; } - if (this.confVersion > 0.4) //0.5 and 0.6 + if (confVersion > 0.4) //0.5 and 0.6 { connectionInfo.RedirectDiskDrives = bool.Parse(xmlnode.Attributes["RedirectDiskDrives"].Value); connectionInfo.RedirectPrinters = bool.Parse(xmlnode.Attributes["RedirectPrinters"].Value); @@ -1030,23 +1030,23 @@ namespace mRemoteNG.Config.Connections connectionInfo.RedirectSmartCards = false; } - if (this.confVersion > 0.6) //0.7 + if (confVersion > 0.6) //0.7 { connectionInfo.Protocol = (ProtocolType)Tools.MiscTools.StringToEnum(typeof(ProtocolType), xmlnode.Attributes["Protocol"].Value); connectionInfo.Port = Convert.ToInt32(xmlnode.Attributes["Port"].Value); } - if (this.confVersion > 0.9) //1.0 + if (confVersion > 0.9) //1.0 { connectionInfo.RedirectKeys = bool.Parse(xmlnode.Attributes["RedirectKeys"].Value); } - if (this.confVersion > 1.1) //1.2 + if (confVersion > 1.1) //1.2 { connectionInfo.PuttySession = xmlnode.Attributes["PuttySession"].Value; } - if (this.confVersion > 1.2) //1.3 + if (confVersion > 1.2) //1.3 { connectionInfo.Colors = (ProtocolRDP.RDPColors)Tools.MiscTools.StringToEnum(typeof(ProtocolRDP.RDPColors), xmlnode.Attributes["Colors"].Value); connectionInfo.Resolution = (ProtocolRDP.RDPResolutions)Tools.MiscTools.StringToEnum(typeof(ProtocolRDP.RDPResolutions), Convert.ToString(xmlnode.Attributes["Resolution"].Value)); @@ -1076,7 +1076,7 @@ namespace mRemoteNG.Config.Connections connectionInfo.RedirectSound = (ProtocolRDP.RDPSounds) Convert.ToInt32(xmlnode.Attributes["RedirectSound"].Value); } - if (this.confVersion > 1.2) //1.3 + if (confVersion > 1.2) //1.3 { connectionInfo.Inheritance = new ConnectionInfoInheritance(connectionInfo); connectionInfo.Inheritance.CacheBitmaps = bool.Parse(xmlnode.Attributes["InheritCacheBitmaps"].Value); @@ -1110,12 +1110,12 @@ namespace mRemoteNG.Config.Connections connectionInfo.Panel = Language.strGeneral; } - if (this.confVersion > 1.4) //1.5 + if (confVersion > 1.4) //1.5 { connectionInfo.PleaseConnect = bool.Parse(xmlnode.Attributes["Connected"].Value); } - if (this.confVersion > 1.5) //1.6 + if (confVersion > 1.5) //1.6 { connectionInfo.ICAEncryption = (ProtocolICA.EncryptionStrength)Tools.MiscTools.StringToEnum(typeof(ProtocolICA.EncryptionStrength), xmlnode.Attributes["ICAEncryptionStrength"].Value); connectionInfo.Inheritance.ICAEncryption = bool.Parse(xmlnode.Attributes["InheritICAEncryptionStrength"].Value); @@ -1125,7 +1125,7 @@ namespace mRemoteNG.Config.Connections connectionInfo.Inheritance.PostExtApp = bool.Parse(xmlnode.Attributes["InheritPostExtApp"].Value); } - if (this.confVersion > 1.6) //1.7 + if (confVersion > 1.6) //1.7 { connectionInfo.VNCCompression = (ProtocolVNC.Compression)Tools.MiscTools.StringToEnum(typeof(ProtocolVNC.Compression), xmlnode.Attributes["VNCCompression"].Value); connectionInfo.VNCEncoding = (ProtocolVNC.Encoding)Tools.MiscTools.StringToEnum(typeof(ProtocolVNC.Encoding), Convert.ToString(xmlnode.Attributes["VNCEncoding"].Value)); @@ -1151,13 +1151,13 @@ namespace mRemoteNG.Config.Connections connectionInfo.Inheritance.VNCViewOnly = bool.Parse(xmlnode.Attributes["InheritVNCViewOnly"].Value); } - if (this.confVersion > 1.7) //1.8 + if (confVersion > 1.7) //1.8 { connectionInfo.RDPAuthenticationLevel = (ProtocolRDP.AuthenticationLevel)Tools.MiscTools.StringToEnum(typeof(ProtocolRDP.AuthenticationLevel), xmlnode.Attributes["RDPAuthenticationLevel"].Value); connectionInfo.Inheritance.RDPAuthenticationLevel = bool.Parse(xmlnode.Attributes["InheritRDPAuthenticationLevel"].Value); } - if (this.confVersion > 1.8) //1.9 + if (confVersion > 1.8) //1.9 { connectionInfo.RenderingEngine = (HTTPBase.RenderingEngine)Tools.MiscTools.StringToEnum(typeof(HTTPBase.RenderingEngine), xmlnode.Attributes["RenderingEngine"].Value); connectionInfo.MacAddress = xmlnode.Attributes["MacAddress"].Value; @@ -1165,19 +1165,19 @@ namespace mRemoteNG.Config.Connections connectionInfo.Inheritance.MacAddress = bool.Parse(xmlnode.Attributes["InheritMacAddress"].Value); } - if (this.confVersion > 1.9) //2.0 + if (confVersion > 1.9) //2.0 { connectionInfo.UserField = xmlnode.Attributes["UserField"].Value; connectionInfo.Inheritance.UserField = bool.Parse(xmlnode.Attributes["InheritUserField"].Value); } - if (this.confVersion > 2.0) //2.1 + if (confVersion > 2.0) //2.1 { connectionInfo.ExtApp = xmlnode.Attributes["ExtApp"].Value; connectionInfo.Inheritance.ExtApp = bool.Parse(xmlnode.Attributes["InheritExtApp"].Value); } - if (this.confVersion > 2.1) //2.2 + if (confVersion > 2.1) //2.2 { // Get settings connectionInfo.RDGatewayUsageMethod = (ProtocolRDP.RDGatewayUsageMethod)Tools.MiscTools.StringToEnum(typeof(ProtocolRDP.RDGatewayUsageMethod), Convert.ToString(xmlnode.Attributes["RDGatewayUsageMethod"].Value)); @@ -1196,7 +1196,7 @@ namespace mRemoteNG.Config.Connections connectionInfo.Inheritance.RDGatewayDomain = bool.Parse(xmlnode.Attributes["InheritRDGatewayDomain"].Value); } - if (this.confVersion > 2.2) //2.3 + if (confVersion > 2.2) //2.3 { // Get settings connectionInfo.EnableFontSmoothing = bool.Parse(xmlnode.Attributes["EnableFontSmoothing"].Value); @@ -1223,7 +1223,7 @@ namespace mRemoteNG.Config.Connections } catch (Exception ex) { - Runtime.MessageCollector.AddMessage(Messages.MessageClass.ErrorMsg, string.Format(Language.strGetConnectionInfoFromXmlFailed, connectionInfo.Name, this.ConnectionFileName, ex.Message), false); + Runtime.MessageCollector.AddMessage(Messages.MessageClass.ErrorMsg, string.Format(Language.strGetConnectionInfoFromXmlFailed, connectionInfo.Name, ConnectionFileName, ex.Message), false); } return connectionInfo; } diff --git a/mRemoteV1/UI/Forms/OptionsPages/UpdatesPage.cs b/mRemoteV1/UI/Forms/OptionsPages/UpdatesPage.cs index 1d00c70c4..7494aeadc 100644 --- a/mRemoteV1/UI/Forms/OptionsPages/UpdatesPage.cs +++ b/mRemoteV1/UI/Forms/OptionsPages/UpdatesPage.cs @@ -7,8 +7,8 @@ using mRemoteNG.App.Update; using mRemoteNG.My; using mRemoteNG.Security; using mRemoteNG.Tools; +using mRemoteNG.UI.TaskDialog; using mRemoteNG.UI.Window; -using PSTaskDialog; namespace mRemoteNG.UI.Forms.OptionsPages { @@ -246,13 +246,13 @@ namespace mRemoteNG.UI.Forms.OptionsPages throw e.Error; } - cTaskDialog.ShowCommandBox(this, Convert.ToString(Application.ProductName), + CTaskDialog.ShowCommandBox(this, Convert.ToString(Application.ProductName), Language.strProxyTestSucceeded, "", Language.strButtonOK, false); } catch (Exception ex) { - cTaskDialog.ShowCommandBox(this, Convert.ToString(Application.ProductName), Language.strProxyTestFailed, - MiscTools.GetExceptionMessageRecursive(ex), "", "", "", Language.strButtonOK, false, eSysIcons.Error, + CTaskDialog.ShowCommandBox(this, Convert.ToString(Application.ProductName), Language.strProxyTestFailed, + MiscTools.GetExceptionMessageRecursive(ex), "", "", "", Language.strButtonOK, false, ESysIcons.Error, 0); } } diff --git a/mRemoteV1/UI/Forms/frmMain.cs b/mRemoteV1/UI/Forms/frmMain.cs index 65151b040..21c462b82 100644 --- a/mRemoteV1/UI/Forms/frmMain.cs +++ b/mRemoteV1/UI/Forms/frmMain.cs @@ -15,8 +15,8 @@ using mRemoteNG.Messages; using mRemoteNG.Themes; using mRemoteNG.Tools; using mRemoteNG.Tree; +using mRemoteNG.UI.TaskDialog; using mRemoteNG.UI.Window; -using PSTaskDialog; using WeifenLuo.WinFormsUI.Docking; namespace mRemoteNG.UI.Forms @@ -300,13 +300,12 @@ namespace mRemoteNG.UI.Forms private static void ApplyMenuColors(ToolStripItemCollection itemCollection) { - var menuItem = default(ToolStripMenuItem); - foreach (ToolStripItem item in itemCollection) + foreach (ToolStripItem item in itemCollection) { item.BackColor = ThemeManager.ActiveTheme.MenuBackgroundColor; item.ForeColor = ThemeManager.ActiveTheme.MenuTextColor; - menuItem = item as ToolStripMenuItem; + var menuItem = item as ToolStripMenuItem; if (menuItem != null) { ApplyMenuColors(menuItem.DropDownItems); @@ -365,8 +364,8 @@ namespace mRemoteNG.UI.Forms if (openConnections > 0 && (Settings.Default.ConfirmCloseConnection == (int)ConfirmCloseEnum.All | (Settings.Default.ConfirmCloseConnection == (int)ConfirmCloseEnum.Multiple & openConnections > 1) || Settings.Default.ConfirmCloseConnection == (int)ConfirmCloseEnum.Exit)) { - var result = cTaskDialog.MessageBox(this, Application.ProductName, Language.strConfirmExitMainInstruction, "", "", "", Language.strCheckboxDoNotShowThisMessageAgain, eTaskDialogButtons.YesNo, eSysIcons.Question, eSysIcons.Question); - if (cTaskDialog.VerificationChecked) + var result = CTaskDialog.MessageBox(this, Application.ProductName, Language.strConfirmExitMainInstruction, "", "", "", Language.strCheckboxDoNotShowThisMessageAgain, ETaskDialogButtons.YesNo, ESysIcons.Question, ESysIcons.Question); + if (CTaskDialog.VerificationChecked) { Settings.Default.ConfirmCloseConnection--; } diff --git a/mRemoteV1/UI/TaskDialog/CommandButton.cs b/mRemoteV1/UI/TaskDialog/CommandButton.cs new file mode 100644 index 000000000..d96949f77 --- /dev/null +++ b/mRemoteV1/UI/TaskDialog/CommandButton.cs @@ -0,0 +1,249 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.Text; +using System.Windows.Forms; + +namespace mRemoteNG.UI.TaskDialog +{ + public partial class CommandButton : Button + { + //-------------------------------------------------------------------------------- + #region PRIVATE MEMBERS + //-------------------------------------------------------------------------------- + Image imgArrow1 = null; + Image imgArrow2 = null; + + const int LEFT_MARGIN = 10; + const int TOP_MARGIN = 10; + const int ARROW_WIDTH = 19; + + enum eButtonState { Normal, MouseOver, Down } + eButtonState m_State = eButtonState.Normal; + + #endregion + + //-------------------------------------------------------------------------------- + #region PUBLIC PROPERTIES + //-------------------------------------------------------------------------------- + // Override this to make sure the control is invalidated (repainted) when 'Text' is changed + public override string Text + { + get { return base.Text; } + set + { + base.Text = value; + if (m_autoHeight) + this.Height = GetBestHeight(); + this.Invalidate(); + } + } + + // SmallFont is the font used for secondary lines + Font m_smallFont; + public Font SmallFont { get { return m_smallFont; } set { m_smallFont = value; } } + + // AutoHeight determines whether the button automatically resizes itself to fit the Text + bool m_autoHeight = true; + [Browsable(true)] + [Category("Behavior")] + [DefaultValue(true)] + public bool AutoHeight { get { return m_autoHeight; } set { m_autoHeight = value; if (m_autoHeight) this.Invalidate(); } } + + #endregion + + //-------------------------------------------------------------------------------- + #region CONSTRUCTOR + //-------------------------------------------------------------------------------- + public CommandButton() + { + InitializeComponent(); + base.Font = new Font("Arial", 11.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, (byte)0); + m_smallFont = new Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, (byte)0); + } + + #endregion + + //-------------------------------------------------------------------------------- + #region PUBLIC ROUTINES + //-------------------------------------------------------------------------------- + public int GetBestHeight() + { + return (TOP_MARGIN * 2) + (int)GetSmallTextSizeF().Height + (int)GetLargeTextSizeF().Height; + } + #endregion + + //-------------------------------------------------------------------------------- + #region PRIVATE ROUTINES + //-------------------------------------------------------------------------------- + string GetLargeText() + { + string[] lines = this.Text.Split(new char[] { '\n' }); + return lines[0]; + } + + string GetSmallText() + { + if (this.Text.IndexOf('\n') < 0) + return ""; + + string s = this.Text; + string[] lines = s.Split(new char[] { '\n' }); + s = ""; + for (int i = 1; i < lines.Length; i++) + s += lines[i] + "\n"; + return s.Trim(new char[] { '\n' }); + } + + SizeF GetLargeTextSizeF() + { + int x = LEFT_MARGIN + ARROW_WIDTH + 5; + SizeF mzSize = new SizeF(this.Width - x - LEFT_MARGIN, 5000.0F); // presume RIGHT_MARGIN = LEFT_MARGIN + Graphics g = Graphics.FromHwnd(this.Handle); + SizeF textSize = g.MeasureString(GetLargeText(), base.Font, mzSize); + return textSize; + } + + SizeF GetSmallTextSizeF() + { + string s = GetSmallText(); + if (s == "") return new SizeF(0, 0); + int x = LEFT_MARGIN + ARROW_WIDTH + 8; // <- indent small text slightly more + SizeF mzSize = new SizeF(this.Width - x - LEFT_MARGIN, 5000.0F); // presume RIGHT_MARGIN = LEFT_MARGIN + Graphics g = Graphics.FromHwnd(this.Handle); + SizeF textSize = g.MeasureString(s, m_smallFont, mzSize); + return textSize; + } + #endregion + + //-------------------------------------------------------------------------------- + #region OVERRIDEs + //-------------------------------------------------------------------------------- + protected override void OnCreateControl() + { + base.OnCreateControl(); + imgArrow1 = new Bitmap(this.GetType(), "green_arrow1.png"); + imgArrow2 = new Bitmap(this.GetType(), "green_arrow2.png"); + } + + //-------------------------------------------------------------------------------- + protected override void OnPaint(PaintEventArgs e) + { + e.Graphics.SmoothingMode = SmoothingMode.HighQuality; + e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; + + LinearGradientBrush brush; + LinearGradientMode mode = LinearGradientMode.Vertical; + + Rectangle newRect = new Rectangle(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - 1, ClientRectangle.Height - 1); + Color text_color = SystemColors.WindowText; + + Image img = imgArrow1; + + if (Enabled) + { + switch (m_State) + { + case eButtonState.Normal: + e.Graphics.FillRectangle(Brushes.White, newRect); + if (base.Focused) + e.Graphics.DrawRectangle(new Pen(Color.SkyBlue, 1), newRect); + else + e.Graphics.DrawRectangle(new Pen(Color.White, 1), newRect); + text_color = Color.DarkBlue; + break; + + case eButtonState.MouseOver: + brush = new LinearGradientBrush(newRect, Color.White, Color.WhiteSmoke, mode); + e.Graphics.FillRectangle(brush, newRect); + e.Graphics.DrawRectangle(new Pen(Color.Silver, 1), newRect); + img = imgArrow2; + text_color = Color.Blue; + break; + + case eButtonState.Down: + brush = new LinearGradientBrush(newRect, Color.WhiteSmoke, Color.White, mode); + e.Graphics.FillRectangle(brush, newRect); + e.Graphics.DrawRectangle(new Pen(Color.DarkGray, 1), newRect); + text_color = Color.DarkBlue; + break; + } + } + else + { + brush = new LinearGradientBrush(newRect, Color.WhiteSmoke, Color.Gainsboro, mode); + e.Graphics.FillRectangle(brush, newRect); + e.Graphics.DrawRectangle(new Pen(Color.DarkGray, 1), newRect); + text_color = Color.DarkBlue; + } + + string largetext = this.GetLargeText(); + string smalltext = this.GetSmallText(); + + SizeF szL = GetLargeTextSizeF(); + //e.Graphics.DrawString(largetext, base.Font, new SolidBrush(text_color), new RectangleF(new PointF(LEFT_MARGIN + imgArrow1.Width + 5, TOP_MARGIN), szL)); + TextRenderer.DrawText(e.Graphics, largetext, base.Font, new Rectangle(LEFT_MARGIN + imgArrow1.Width + 5, TOP_MARGIN, (int)szL.Width, (int)szL.Height), text_color, TextFormatFlags.Default); + + if (smalltext != "") + { + SizeF szS = GetSmallTextSizeF(); + e.Graphics.DrawString(smalltext, m_smallFont, new SolidBrush(text_color), new RectangleF(new PointF(LEFT_MARGIN + imgArrow1.Width + 8, TOP_MARGIN + (int)szL.Height), szS)); + } + + e.Graphics.DrawImage(img, new Point(LEFT_MARGIN, TOP_MARGIN + (int)(szL.Height / 2) - (int)(img.Height / 2))); + } + + //-------------------------------------------------------------------------------- + protected override void OnMouseLeave(System.EventArgs e) + { + m_State = eButtonState.Normal; + this.Invalidate(); + base.OnMouseLeave(e); + } + + //-------------------------------------------------------------------------------- + protected override void OnMouseEnter(System.EventArgs e) + { + m_State = eButtonState.MouseOver; + this.Invalidate(); + base.OnMouseEnter(e); + } + + //-------------------------------------------------------------------------------- + protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e) + { + m_State = eButtonState.MouseOver; + this.Invalidate(); + base.OnMouseUp(e); + } + + //-------------------------------------------------------------------------------- + protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e) + { + m_State = eButtonState.Down; + this.Invalidate(); + base.OnMouseDown(e); + } + + //-------------------------------------------------------------------------------- + protected override void OnSizeChanged(EventArgs e) + { + if (m_autoHeight) + { + int h = GetBestHeight(); + if (this.Height != h) + { + this.Height = h; + return; + } + } + base.OnSizeChanged(e); + } + #endregion + + //-------------------------------------------------------------------------------- + } +} diff --git a/mRemoteV1/UI/TaskDialog/CommandButton.designer.cs b/mRemoteV1/UI/TaskDialog/CommandButton.designer.cs new file mode 100644 index 000000000..525f380cf --- /dev/null +++ b/mRemoteV1/UI/TaskDialog/CommandButton.designer.cs @@ -0,0 +1,36 @@ +namespace mRemoteNG.UI.TaskDialog +{ + partial class CommandButton + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + } + + #endregion + } +} diff --git a/mRemoteV1/UI/TaskDialog/cTaskDialog.cs b/mRemoteV1/UI/TaskDialog/cTaskDialog.cs new file mode 100644 index 000000000..0b0189e63 --- /dev/null +++ b/mRemoteV1/UI/TaskDialog/cTaskDialog.cs @@ -0,0 +1,353 @@ +using System; +using System.Windows.Forms; + +namespace mRemoteNG.UI.TaskDialog +{ + //-------------------------------------------------------------------------------- + + #region PUBLIC enums + + //-------------------------------------------------------------------------------- + public enum ESysIcons + { + Information, + Question, + Warning, + Error + } + + public enum ETaskDialogButtons + { + YesNo, + YesNoCancel, + OkCancel, + Ok, + Close, + Cancel, + None + } + + #endregion + + //-------------------------------------------------------------------------------- + public static class CTaskDialog + { + // PUBLIC static values... + public static bool VerificationChecked; + public static int RadioButtonResult = -1; + public static int CommandButtonResult = -1; + public static int EmulatedFormWidth = 450; + public static bool ForceEmulationMode = false; + public static bool UseToolWindowOnXp = true; + public static bool PlaySystemSounds = true; + public static EventHandler OnTaskDialogShown = null; + public static EventHandler OnTaskDialogClosed = null; + + //-------------------------------------------------------------------------------- + + //-------------------------------------------------------------------------------- + + #region ShowTaskDialogBox + + //-------------------------------------------------------------------------------- + public static DialogResult ShowTaskDialogBox(IWin32Window owner, + string title, + string mainInstruction, + string content, + string expandedInfo, + string footer, + string verificationText, + string radioButtons, + string commandButtons, + ETaskDialogButtons buttons, + ESysIcons mainIcon, + ESysIcons footerIcon, + int defaultIndex) + + { + DialogResult result; + OnTaskDialogShown?.Invoke(null, EventArgs.Empty); + + using (var td = new frmTaskDialog()) + { + td.Title = title; + td.MainInstruction = mainInstruction; + td.Content = content; + td.ExpandedInfo = expandedInfo; + td.Footer = footer; + td.RadioButtons = radioButtons; + td.CommandButtons = commandButtons; + td.Buttons = buttons; + td.MainIcon = mainIcon; + td.FooterIcon = footerIcon; + td.VerificationText = verificationText; + td.Width = EmulatedFormWidth; + td.DefaultButtonIndex = defaultIndex; + td.BuildForm(); + result = td.ShowDialog(owner); + + RadioButtonResult = td.RadioButtonIndex; + CommandButtonResult = td.CommandButtonClickedIndex; + VerificationChecked = td.VerificationCheckBoxChecked; + } + + OnTaskDialogClosed?.Invoke(null, EventArgs.Empty); + return result; + } + + //-------------------------------------------------------------------------------- + // Overloaded versions... + //-------------------------------------------------------------------------------- + public static DialogResult ShowTaskDialogBox(IWin32Window owner, + string title, + string mainInstruction, + string content, + string expandedInfo, + string footer, + string verificationText, + string radioButtons, + string commandButtons, + ETaskDialogButtons buttons, + ESysIcons mainIcon, + ESysIcons footerIcon) + { + return ShowTaskDialogBox(owner, title, mainInstruction, content, expandedInfo, footer, verificationText, + radioButtons, commandButtons, buttons, mainIcon, footerIcon, 0); + } + + public static DialogResult ShowTaskDialogBox(string title, + string mainInstruction, + string content, + string expandedInfo, + string footer, + string verificationText, + string radioButtons, + string commandButtons, + ETaskDialogButtons buttons, + ESysIcons mainIcon, + ESysIcons footerIcon) + { + return ShowTaskDialogBox(null, title, mainInstruction, content, expandedInfo, footer, verificationText, + radioButtons, commandButtons, buttons, mainIcon, footerIcon, 0); + } + + #endregion + + //-------------------------------------------------------------------------------- + + #region MessageBox + + //-------------------------------------------------------------------------------- + public static DialogResult MessageBox(IWin32Window owner, + string title, + string mainInstruction, + string content, + string expandedInfo, + string footer, + string verificationText, + ETaskDialogButtons buttons, + ESysIcons mainIcon, + ESysIcons footerIcon) + { + return ShowTaskDialogBox(owner, title, mainInstruction, content, expandedInfo, footer, verificationText, "", + "", buttons, mainIcon, footerIcon); + } + + //-------------------------------------------------------------------------------- + // Overloaded versions... + //-------------------------------------------------------------------------------- + public static DialogResult MessageBox(string title, + string mainInstruction, + string content, + string expandedInfo, + string footer, + string verificationText, + ETaskDialogButtons buttons, + ESysIcons mainIcon, + ESysIcons footerIcon) + { + return ShowTaskDialogBox(null, title, mainInstruction, content, expandedInfo, footer, verificationText, "", + "", buttons, mainIcon, footerIcon); + } + + public static DialogResult MessageBox(IWin32Window owner, + string title, + string mainInstruction, + string content, + ETaskDialogButtons buttons, + ESysIcons mainIcon) + { + return MessageBox(owner, title, mainInstruction, content, "", "", "", buttons, mainIcon, + ESysIcons.Information); + } + + public static DialogResult MessageBox(string title, + string mainInstruction, + string content, + ETaskDialogButtons buttons, + ESysIcons mainIcon) + { + return MessageBox(null, title, mainInstruction, content, "", "", "", buttons, mainIcon, + ESysIcons.Information); + } + + //-------------------------------------------------------------------------------- + + #endregion + + //-------------------------------------------------------------------------------- + + #region ShowRadioBox + + //-------------------------------------------------------------------------------- + public static int ShowRadioBox(IWin32Window owner, + string title, + string mainInstruction, + string content, + string expandedInfo, + string footer, + string verificationText, + string radioButtons, + ESysIcons mainIcon, + ESysIcons footerIcon, + int defaultIndex) + { + var res = ShowTaskDialogBox(owner, title, mainInstruction, content, expandedInfo, footer, verificationText, + radioButtons, "", ETaskDialogButtons.OkCancel, mainIcon, footerIcon, defaultIndex); + if (res == DialogResult.OK) + return RadioButtonResult; + return -1; + } + + //-------------------------------------------------------------------------------- + // Overloaded versions... + //-------------------------------------------------------------------------------- + public static int ShowRadioBox(string title, + string mainInstruction, + string content, + string expandedInfo, + string footer, + string verificationText, + string radioButtons, + ESysIcons mainIcon, + ESysIcons footerIcon, + int defaultIndex) + { + var res = ShowTaskDialogBox(null, title, mainInstruction, content, expandedInfo, footer, verificationText, + radioButtons, "", ETaskDialogButtons.OkCancel, mainIcon, footerIcon, defaultIndex); + if (res == DialogResult.OK) + return RadioButtonResult; + return -1; + } + + public static int ShowRadioBox(IWin32Window owner, + string title, + string mainInstruction, + string content, + string expandedInfo, + string footer, + string verificationText, + string radioButtons, + ESysIcons mainIcon, + ESysIcons footerIcon) + { + return ShowRadioBox(owner, title, mainInstruction, content, expandedInfo, footer, verificationText, + radioButtons, ESysIcons.Question, ESysIcons.Information, 0); + } + + public static int ShowRadioBox(IWin32Window owner, + string title, + string mainInstruction, + string content, + string radioButtons, + int defaultIndex) + { + return ShowRadioBox(owner, title, mainInstruction, content, "", "", "", radioButtons, ESysIcons.Question, + ESysIcons.Information, defaultIndex); + } + + public static int ShowRadioBox(IWin32Window owner, + string title, + string mainInstruction, + string content, + string radioButtons) + { + return ShowRadioBox(owner, title, mainInstruction, content, "", "", "", radioButtons, ESysIcons.Question, + ESysIcons.Information, 0); + } + + public static int ShowRadioBox(string title, + string mainInstruction, + string content, + string radioButtons) + { + return ShowRadioBox(null, title, mainInstruction, content, "", "", "", radioButtons, ESysIcons.Question, + ESysIcons.Information, 0); + } + + #endregion + + //-------------------------------------------------------------------------------- + + #region ShowCommandBox + + //-------------------------------------------------------------------------------- + public static int ShowCommandBox(IWin32Window owner, + string title, + string mainInstruction, + string content, + string expandedInfo, + string footer, + string verificationText, + string commandButtons, + bool showCancelButton, + ESysIcons mainIcon, + ESysIcons footerIcon) + { + var res = ShowTaskDialogBox(owner, title, mainInstruction, content, expandedInfo, footer, verificationText, + "", commandButtons, showCancelButton ? ETaskDialogButtons.Cancel : ETaskDialogButtons.None, + mainIcon, footerIcon); + if (res == DialogResult.OK) + return CommandButtonResult; + return -1; + } + + //-------------------------------------------------------------------------------- + // Overloaded versions... + //-------------------------------------------------------------------------------- + public static int ShowCommandBox(string title, + string mainInstruction, + string content, + string expandedInfo, + string footer, + string verificationText, + string commandButtons, + bool showCancelButton, + ESysIcons mainIcon, + ESysIcons footerIcon) + { + var res = ShowTaskDialogBox(null, title, mainInstruction, content, expandedInfo, footer, verificationText, + "", commandButtons, showCancelButton ? ETaskDialogButtons.Cancel : ETaskDialogButtons.None, + mainIcon, footerIcon); + if (res == DialogResult.OK) + return CommandButtonResult; + return -1; + } + + public static int ShowCommandBox(IWin32Window owner, string title, string mainInstruction, string content, + string commandButtons, bool showCancelButton) + { + return ShowCommandBox(owner, title, mainInstruction, content, "", "", "", commandButtons, showCancelButton, + ESysIcons.Question, ESysIcons.Information); + } + + public static int ShowCommandBox(string title, string mainInstruction, string content, string commandButtons, + bool showCancelButton) + { + return ShowCommandBox(null, title, mainInstruction, content, "", "", "", commandButtons, showCancelButton, + ESysIcons.Question, ESysIcons.Information); + } + + #endregion + } +} \ No newline at end of file diff --git a/mRemoteV1/UI/TaskDialog/frmTaskDialog.cs b/mRemoteV1/UI/TaskDialog/frmTaskDialog.cs new file mode 100644 index 000000000..f0cba241e --- /dev/null +++ b/mRemoteV1/UI/TaskDialog/frmTaskDialog.cs @@ -0,0 +1,440 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; + +namespace mRemoteNG.UI.TaskDialog +{ + public partial class frmTaskDialog : Form + { + //-------------------------------------------------------------------------------- + #region PRIVATE members + //-------------------------------------------------------------------------------- + ESysIcons _mainIcon = ESysIcons.Question; + ESysIcons _footerIcon = ESysIcons.Warning; + + string _mainInstruction = "Main Instruction Text"; + int _mainInstructionHeight = 0; + Font _mainInstructionFont = new Font("Arial", 11.75F, FontStyle.Regular, GraphicsUnit.Point, (byte)0); + + List _radioButtonCtrls = new List(); + string _radioButtons = ""; + int _initialRadioButtonIndex = 0; + + List