diff --git a/mRemoteNG/App/Info/WindowsRegistryInfo.cs b/mRemoteNG/App/Info/WindowsRegistryInfo.cs new file mode 100644 index 000000000..0ecd22a14 --- /dev/null +++ b/mRemoteNG/App/Info/WindowsRegistryInfo.cs @@ -0,0 +1,21 @@ +using Microsoft.Win32; +using System.Runtime.Versioning; + +namespace mRemoteNG.App.Info +{ + [SupportedOSPlatform("windows")] + public static class WindowsRegistryInfo + { + #region general parameters + public const RegistryHive Hive = RegistryHive.LocalMachine; + public const string RootKey = "SOFTWARE\\mRemoteNG"; + #endregion + + #region subkey location parameters + + // Updates + public const string UpdateSubkey = RootKey + "\\Updates"; // Registry subkey for general update settings + public const string UpdateOptionsSubkey = RootKey + "\\Updates\\Options"; // Registry subkey for update options within the update settings + #endregion + } +} \ No newline at end of file diff --git a/mRemoteNG/Config/Settings/Registry/CommonRegistrySettings.cs b/mRemoteNG/Config/Settings/Registry/CommonRegistrySettings.cs new file mode 100644 index 000000000..21d980fc4 --- /dev/null +++ b/mRemoteNG/Config/Settings/Registry/CommonRegistrySettings.cs @@ -0,0 +1,62 @@ +using Microsoft.Win32; +using System.Runtime.Versioning; +using mRemoteNG.App.Info; +using mRemoteNG.Tools.WindowsRegistry; + +namespace mRemoteNG.Config.Settings.Registry +{ + [SupportedOSPlatform("windows")] + /// Static utility class that provides access to and management of registry settings on the local machine. + /// It abstracts complex registry operations and centralizes the handling of various registry keys. + /// Benefits: Simplified code, enhances maintainability, and ensures consistency. #ReadOnly + public static class CommonRegistrySettings + { + private static readonly IRegistryAdvancedRead _WindowsRegistry = new WindowsRegistryAdvanced(); + private static readonly RegistryHive _Hive = WindowsRegistryInfo.Hive; + + private const string __Update = WindowsRegistryInfo.UpdateSubkey; + private const string __Credential = WindowsRegistryInfo.CredentialSubkey; + + #region general update registry settings + /// + /// Indicates whether searching for updates is allowed. If false, there is no way to update directly from mRemoteNG. + /// + /// + /// Default value is true, which allows check for updates. + /// If the registry key is set to true, no action will be taken because the key is not needed. + /// + public static bool AllowCheckForUpdates { get; } = _WindowsRegistry.GetBoolValue(_Hive, __Update, nameof(AllowCheckForUpdates), true); + + /// + /// Indicates whether automatic search for updates is allowed. + /// + /// + /// Default value is true, which allows check for updates automaticaly. + /// If the registry key is set to true, no action will be taken because the key is not needed. + /// Important: If AllowCheckForUpdates is false, the default for this value (AllowCheckForUpdatesAutomatical) is also false, manual update checks are disabled. + /// + public static bool AllowCheckForUpdatesAutomatical { get; } = _WindowsRegistry.GetBoolValue(_Hive, __Update, nameof(AllowCheckForUpdatesAutomatical), AllowCheckForUpdates); + + /// + /// Indicates whether a manual search for updates is allowed. + /// + /// + /// The default value is true, enabling the manual check for updates. + /// If the registry key is set to true, no action will be taken because the key is not needed. + /// Important: If AllowCheckForUpdates is false, the default for this value (AllowCheckForUpdatesManual) is also false, manual update checks are disabled. + /// + public static bool AllowCheckForUpdatesManual { get; } = _WindowsRegistry.GetBoolValue(_Hive, __Update, nameof(AllowCheckForUpdatesManual), AllowCheckForUpdates); + + /// + /// Specifies whether a question about checking for updates is displayed at startup. + /// + /// + /// Important: If the registry entry is set to true, a popup will appear every time you start + /// + public static bool CheckForUpdatesAsked { get; } = _WindowsRegistry.GetBoolValue(_Hive, __Update, nameof(CheckForUpdatesAsked)); + #endregion + + + + } +} \ No newline at end of file diff --git a/mRemoteNG/Config/Settings/Registry/OptRegistryUpdatesPage.cs b/mRemoteNG/Config/Settings/Registry/OptRegistryUpdatesPage.cs new file mode 100644 index 000000000..18a623c26 --- /dev/null +++ b/mRemoteNG/Config/Settings/Registry/OptRegistryUpdatesPage.cs @@ -0,0 +1,86 @@ +using System.Runtime.Versioning; +using Microsoft.Win32; +using mRemoteNG.App.Info; +using mRemoteNG.Tools.WindowsRegistry; + +namespace mRemoteNG.Config.Settings.Registry +{ + [SupportedOSPlatform("windows")] + /// Static utility class that provides access to and management of registry settings on the local machine. + /// It abstracts complex registry operations and centralizes the handling of various registry keys. + /// Benefits: Simplified code, enhances maintainability, and ensures consistency. #ReadOnly + public sealed partial class OptRegistryUpdatesPage : WindowsRegistryAdvanced + { + /// + /// Specifies the number of days between update checks. + /// + public WindowsRegistryKeyInteger CheckForUpdatesFrequencyDays { get; } + + /// + /// Specifies the update channel for updates. + /// + /// + /// The update channel should be one of the predefined values: Stable, Preview, Nightly. + /// + public WindowsRegistryKeyString UpdateChannel { get; } + + /// + /// Indicates whether proxy usage for updates is enabled. + /// + public WindowsRegistryKeyBoolean UseProxyForUpdates { get; } + + /// + /// Specifies the proxy address for updates. + /// + public WindowsRegistryKeyString ProxyAddress { get; } + + /// + /// Specifies the proxy port for updates. + /// + public WindowsRegistryKeyInteger ProxyPort { get; } + + /// + /// Indicates whether proxy authentication is enabled. + /// + public WindowsRegistryKeyBoolean UseProxyAuthentication { get; } + + /// + /// Specifies the authentication username for the proxy. + /// + public WindowsRegistryKeyString ProxyAuthUser { get; } + + /// + /// Specifies the authentication password for the proxy. + /// + /// + /// Please only store encrypted passwords in the registry by using the password generator on the 'Credentials' options page. + /// + public string ProxyAuthPass { get; } + + public OptRegistryUpdatesPage() + { + RegistryHive hive = WindowsRegistryInfo.Hive; + string subKey = WindowsRegistryInfo.UpdateOptionsSubkey; + + CheckForUpdatesFrequencyDays = GetInteger(hive, subKey, nameof(CheckForUpdatesFrequencyDays)); + + UpdateChannel = GetStringValidated(hive, subKey, nameof(UpdateChannel), + new string[] { + UpdateChannelInfo.STABLE, + UpdateChannelInfo.PREVIEW, + UpdateChannelInfo.NIGHTLY + } + ,true + ); + + UseProxyForUpdates = GetBoolean(hive, subKey, nameof(UseProxyForUpdates)); + ProxyAddress = GetString(hive, subKey, nameof(ProxyAddress), null); + ProxyPort = GetInteger(hive, subKey, nameof(ProxyPort)); + + UseProxyAuthentication = GetBoolean(hive, subKey, nameof(UseProxyAuthentication)); + ProxyAuthUser = GetString(hive, subKey, nameof(ProxyAuthUser), null); + //Currently not supported: + //ProxyAuthPass = GetPassword(Hive, _SubKey, nameof(ProxyAuthPass)); + } + } +} \ No newline at end of file diff --git a/mRemoteNG/Language/Language.Designer.cs b/mRemoteNG/Language/Language.Designer.cs index 02c057514..cedf95c73 100644 --- a/mRemoteNG/Language/Language.Designer.cs +++ b/mRemoteNG/Language/Language.Designer.cs @@ -3387,6 +3387,15 @@ namespace mRemoteNG.Resources.Language { } } + /// + /// Looks up a localized string similar to *Some settings are determined by your company. For further information, please contact your administrator. + /// + internal static string OptionsAdminInfo { + get { + return ResourceManager.GetString("OptionsAdminInfo", resourceCulture); + } + } + /// /// Looks up a localized string similar to mRemoteNG Options. /// diff --git a/mRemoteNG/Language/Language.de.resx b/mRemoteNG/Language/Language.de.resx index 0a6f70594..db19159e4 100644 --- a/mRemoteNG/Language/Language.de.resx +++ b/mRemoteNG/Language/Language.de.resx @@ -2047,4 +2047,7 @@ Nightly umfasst Alphas, Betas und Release Candidates. Maximale Anmeldeversuche erreicht. Verbindung erneut initiieren. C# to Powershell transfer issue with encoding possible + + *Einige Einstellungen werden von Ihrem Unternehmen festgelegt. Für weitere Informationen wenden Sie sich an Ihren Systemadministrator. + \ No newline at end of file diff --git a/mRemoteNG/Language/Language.resx b/mRemoteNG/Language/Language.resx index 5b7aa5945..eba84d393 100644 --- a/mRemoteNG/Language/Language.resx +++ b/mRemoteNG/Language/Language.resx @@ -2362,4 +2362,7 @@ Nightly Channel includes Alphas, Betas & Release Candidates. SecureCRT (*.xml) + + *Some settings are determined by your company. For further information, please contact your administrator + \ No newline at end of file diff --git a/mRemoteNG/UI/Forms/OptionsPages/OptionsPage.cs b/mRemoteNG/UI/Forms/OptionsPages/OptionsPage.cs index 80ec17810..b5e03a5e6 100644 --- a/mRemoteNG/UI/Forms/OptionsPages/OptionsPage.cs +++ b/mRemoteNG/UI/Forms/OptionsPages/OptionsPage.cs @@ -42,6 +42,16 @@ namespace mRemoteNG.UI.Forms.OptionsPages public virtual void RevertSettings() { } + public virtual void LoadRegistrySettings() + { + } + public virtual bool ShowAdministratorInfo() + { + return false; + } + public virtual void DisablePage() + { + } #endregion @@ -65,6 +75,27 @@ namespace mRemoteNG.UI.Forms.OptionsPages Name = "OptionsPage"; ResumeLayout(false); } + + /// + /// Disables the specified control by setting its Enabled property to false. + /// For TextBox controls, additionally sets the ReadOnly property based on the Enabled state. + /// Does nothing if the control is null. + /// + /// The control to be disabled. + protected static void DisableControl(Control control) + { + if (control == null) return; + + control.Enabled = false; + + if (control is TextBox) + { + // If it's a TextBox, set the ReadOnly property + ((TextBox)control).ReadOnly = control.Enabled; + } + } + + } internal class DropdownList { diff --git a/mRemoteNG/UI/Forms/OptionsPages/UpdatesPage.Designer.cs b/mRemoteNG/UI/Forms/OptionsPages/UpdatesPage.Designer.cs index 34859d8c2..9aa1020d4 100644 --- a/mRemoteNG/UI/Forms/OptionsPages/UpdatesPage.Designer.cs +++ b/mRemoteNG/UI/Forms/OptionsPages/UpdatesPage.Designer.cs @@ -35,9 +35,9 @@ namespace mRemoteNG.UI.Forms.OptionsPages { lblUpdatesExplanation = new MrngLabel(); pnlUpdateCheck = new System.Windows.Forms.Panel(); + cboUpdateCheckFrequency = new MrngComboBox(); btnUpdateCheckNow = new MrngButton(); chkCheckForUpdatesOnStartup = new MrngCheckBox(); - cboUpdateCheckFrequency = new MrngComboBox(); lblReleaseChannelExplanation = new MrngTextBox(); cboReleaseChannel = new MrngComboBox(); pnlProxy = new System.Windows.Forms.Panel(); @@ -55,36 +55,53 @@ namespace mRemoteNG.UI.Forms.OptionsPages chkUseProxyAuthentication = new MrngCheckBox(); btnTestProxy = new MrngButton(); groupBoxReleaseChannel = new MrngGroupBox(); + pnlDefaultUpdate = new System.Windows.Forms.Panel(); + lblUpdateAdminInfo = new System.Windows.Forms.Label(); pnlUpdateCheck.SuspendLayout(); pnlProxy.SuspendLayout(); tblProxyBasic.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)numProxyPort).BeginInit(); tblProxyAuthentication.SuspendLayout(); groupBoxReleaseChannel.SuspendLayout(); + pnlDefaultUpdate.SuspendLayout(); SuspendLayout(); // // lblUpdatesExplanation // - lblUpdatesExplanation.Location = new System.Drawing.Point(3, 3); + lblUpdatesExplanation.Dock = System.Windows.Forms.DockStyle.Top; + lblUpdatesExplanation.Location = new System.Drawing.Point(0, 0); lblUpdatesExplanation.Name = "lblUpdatesExplanation"; - lblUpdatesExplanation.Size = new System.Drawing.Size(595, 32); + lblUpdatesExplanation.Padding = new System.Windows.Forms.Padding(3, 0, 0, 0); + lblUpdatesExplanation.Size = new System.Drawing.Size(610, 38); lblUpdatesExplanation.TabIndex = 0; lblUpdatesExplanation.Text = "mRemoteNG can periodically connect to the mRemoteNG website to check for updates."; // // pnlUpdateCheck // + pnlUpdateCheck.Controls.Add(cboUpdateCheckFrequency); pnlUpdateCheck.Controls.Add(btnUpdateCheckNow); pnlUpdateCheck.Controls.Add(chkCheckForUpdatesOnStartup); - pnlUpdateCheck.Controls.Add(cboUpdateCheckFrequency); - pnlUpdateCheck.Location = new System.Drawing.Point(3, 25); + pnlUpdateCheck.Controls.Add(lblUpdatesExplanation); + pnlUpdateCheck.Dock = System.Windows.Forms.DockStyle.Top; + pnlUpdateCheck.Location = new System.Drawing.Point(0, 30); pnlUpdateCheck.Name = "pnlUpdateCheck"; - pnlUpdateCheck.Size = new System.Drawing.Size(604, 99); - pnlUpdateCheck.TabIndex = 1; + pnlUpdateCheck.Size = new System.Drawing.Size(610, 114); + pnlUpdateCheck.TabIndex = 0; + // + // cboUpdateCheckFrequency + // + cboUpdateCheckFrequency._mice = MrngComboBox.MouseState.HOVER; + cboUpdateCheckFrequency.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + cboUpdateCheckFrequency.FormattingEnabled = true; + cboUpdateCheckFrequency.Location = new System.Drawing.Point(27, 44); + cboUpdateCheckFrequency.Name = "cboUpdateCheckFrequency"; + cboUpdateCheckFrequency.Size = new System.Drawing.Size(120, 21); + cboUpdateCheckFrequency.TabIndex = 1; // // btnUpdateCheckNow // btnUpdateCheckNow._mice = MrngButton.MouseState.OUT; - btnUpdateCheckNow.Location = new System.Drawing.Point(5, 63); + btnUpdateCheckNow.Location = new System.Drawing.Point(5, 79); btnUpdateCheckNow.Name = "btnUpdateCheckNow"; btnUpdateCheckNow.Size = new System.Drawing.Size(122, 25); btnUpdateCheckNow.TabIndex = 2; @@ -97,7 +114,7 @@ namespace mRemoteNG.UI.Forms.OptionsPages chkCheckForUpdatesOnStartup._mice = MrngCheckBox.MouseState.OUT; chkCheckForUpdatesOnStartup.AutoSize = true; chkCheckForUpdatesOnStartup.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - chkCheckForUpdatesOnStartup.Location = new System.Drawing.Point(6, 11); + chkCheckForUpdatesOnStartup.Location = new System.Drawing.Point(9, 21); chkCheckForUpdatesOnStartup.Name = "chkCheckForUpdatesOnStartup"; chkCheckForUpdatesOnStartup.Size = new System.Drawing.Size(120, 17); chkCheckForUpdatesOnStartup.TabIndex = 0; @@ -105,16 +122,6 @@ namespace mRemoteNG.UI.Forms.OptionsPages chkCheckForUpdatesOnStartup.UseVisualStyleBackColor = true; chkCheckForUpdatesOnStartup.CheckedChanged += chkCheckForUpdatesOnStartup_CheckedChanged; // - // cboUpdateCheckFrequency - // - cboUpdateCheckFrequency._mice = MrngComboBox.MouseState.HOVER; - cboUpdateCheckFrequency.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - cboUpdateCheckFrequency.FormattingEnabled = true; - cboUpdateCheckFrequency.Location = new System.Drawing.Point(6, 34); - cboUpdateCheckFrequency.Name = "cboUpdateCheckFrequency"; - cboUpdateCheckFrequency.Size = new System.Drawing.Size(120, 21); - cboUpdateCheckFrequency.TabIndex = 1; - // // lblReleaseChannelExplanation // lblReleaseChannelExplanation.BackColor = System.Drawing.SystemColors.Control; @@ -145,9 +152,10 @@ namespace mRemoteNG.UI.Forms.OptionsPages pnlProxy.Controls.Add(chkUseProxyForAutomaticUpdates); pnlProxy.Controls.Add(chkUseProxyAuthentication); pnlProxy.Controls.Add(btnTestProxy); - pnlProxy.Location = new System.Drawing.Point(3, 240); + pnlProxy.Dock = System.Windows.Forms.DockStyle.Top; + pnlProxy.Location = new System.Drawing.Point(0, 248); pnlProxy.Name = "pnlProxy"; - pnlProxy.Size = new System.Drawing.Size(604, 223); + pnlProxy.Size = new System.Drawing.Size(610, 232); pnlProxy.TabIndex = 3; // // tblProxyBasic @@ -311,24 +319,47 @@ namespace mRemoteNG.UI.Forms.OptionsPages // groupBoxReleaseChannel.Controls.Add(lblReleaseChannelExplanation); groupBoxReleaseChannel.Controls.Add(cboReleaseChannel); - groupBoxReleaseChannel.Location = new System.Drawing.Point(3, 130); + groupBoxReleaseChannel.Dock = System.Windows.Forms.DockStyle.Top; + groupBoxReleaseChannel.Location = new System.Drawing.Point(0, 144); groupBoxReleaseChannel.Name = "groupBoxReleaseChannel"; - groupBoxReleaseChannel.Size = new System.Drawing.Size(604, 104); + groupBoxReleaseChannel.Size = new System.Drawing.Size(610, 104); groupBoxReleaseChannel.TabIndex = 3; groupBoxReleaseChannel.TabStop = false; groupBoxReleaseChannel.Text = "Release Channel"; // + // pnlDefaultUpdate + // + pnlDefaultUpdate.Controls.Add(pnlProxy); + pnlDefaultUpdate.Controls.Add(groupBoxReleaseChannel); + pnlDefaultUpdate.Controls.Add(pnlUpdateCheck); + pnlDefaultUpdate.Controls.Add(lblUpdateAdminInfo); + pnlDefaultUpdate.Dock = System.Windows.Forms.DockStyle.Top; + pnlDefaultUpdate.Location = new System.Drawing.Point(0, 0); + pnlDefaultUpdate.Name = "pnlDefaultUpdate"; + pnlDefaultUpdate.Size = new System.Drawing.Size(610, 483); + pnlDefaultUpdate.TabIndex = 4; + // + // lblUpdateAdminInfo + // + lblUpdateAdminInfo.BackColor = System.Drawing.SystemColors.ControlLight; + lblUpdateAdminInfo.Dock = System.Windows.Forms.DockStyle.Top; + lblUpdateAdminInfo.ForeColor = System.Drawing.SystemColors.ControlText; + lblUpdateAdminInfo.Location = new System.Drawing.Point(0, 0); + lblUpdateAdminInfo.Name = "lblUpdateAdminInfo"; + lblUpdateAdminInfo.Padding = new System.Windows.Forms.Padding(0, 2, 0, 0); + lblUpdateAdminInfo.Size = new System.Drawing.Size(610, 30); + lblUpdateAdminInfo.TabIndex = 0; + lblUpdateAdminInfo.Text = "Some settings are configured by your Administrator. Please contact your administrator for more information."; + lblUpdateAdminInfo.Visible = false; + // // UpdatesPage // AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; - Controls.Add(groupBoxReleaseChannel); - Controls.Add(lblUpdatesExplanation); - Controls.Add(pnlUpdateCheck); - Controls.Add(pnlProxy); + Controls.Add(pnlDefaultUpdate); Margin = new System.Windows.Forms.Padding(4); Name = "UpdatesPage"; - Size = new System.Drawing.Size(610, 490); + Size = new System.Drawing.Size(610, 496); pnlUpdateCheck.ResumeLayout(false); pnlUpdateCheck.PerformLayout(); pnlProxy.ResumeLayout(false); @@ -340,6 +371,7 @@ namespace mRemoteNG.UI.Forms.OptionsPages tblProxyAuthentication.PerformLayout(); groupBoxReleaseChannel.ResumeLayout(false); groupBoxReleaseChannel.PerformLayout(); + pnlDefaultUpdate.ResumeLayout(false); ResumeLayout(false); } @@ -347,7 +379,6 @@ namespace mRemoteNG.UI.Forms.OptionsPages internal System.Windows.Forms.Panel pnlUpdateCheck; internal MrngButton btnUpdateCheckNow; internal MrngCheckBox chkCheckForUpdatesOnStartup; - internal MrngComboBox cboUpdateCheckFrequency; internal System.Windows.Forms.Panel pnlProxy; internal Controls.MrngLabel lblProxyAddress; internal Controls.MrngTextBox txtProxyAddress; @@ -365,5 +396,8 @@ namespace mRemoteNG.UI.Forms.OptionsPages private MrngGroupBox groupBoxReleaseChannel; private System.Windows.Forms.TableLayoutPanel tblProxyBasic; private System.Windows.Forms.TableLayoutPanel tblProxyAuthentication; + private System.Windows.Forms.Panel pnlDefaultUpdate; + internal System.Windows.Forms.Label lblUpdateAdminInfo; + internal MrngComboBox cboUpdateCheckFrequency; } } \ No newline at end of file diff --git a/mRemoteNG/UI/Forms/OptionsPages/UpdatesPage.cs b/mRemoteNG/UI/Forms/OptionsPages/UpdatesPage.cs index 93c87d2a4..5cd9a0d43 100644 --- a/mRemoteNG/UI/Forms/OptionsPages/UpdatesPage.cs +++ b/mRemoteNG/UI/Forms/OptionsPages/UpdatesPage.cs @@ -10,6 +10,7 @@ using mRemoteNG.Tools; using mRemoteNG.UI.TaskDialog; using mRemoteNG.Resources.Language; using System.Runtime.Versioning; +using mRemoteNG.Config.Settings.Registry; namespace mRemoteNG.UI.Forms.OptionsPages { @@ -19,6 +20,8 @@ namespace mRemoteNG.UI.Forms.OptionsPages #region Private Fields private AppUpdater _appUpdate; + private readonly OptRegistryUpdatesPage _RegistrySettings = new(); + private bool _pageEnabled = true; #endregion @@ -58,39 +61,51 @@ namespace mRemoteNG.UI.Forms.OptionsPages lblProxyPassword.Text = Language.Password; btnTestProxy.Text = Language.TestProxy; + + lblUpdateAdminInfo.Text = Language.OptionsAdminInfo; } public override void LoadSettings() { + if (UpdatesForbidden()) + return; + chkCheckForUpdatesOnStartup.Checked = Properties.OptionsUpdatesPage.Default.CheckForUpdatesOnStartup; - cboUpdateCheckFrequency.Enabled = chkCheckForUpdatesOnStartup.Checked; - cboUpdateCheckFrequency.Items.Clear(); - var nDaily = cboUpdateCheckFrequency.Items.Add(Language.Daily); - var nWeekly = cboUpdateCheckFrequency.Items.Add(Language.Weekly); - var nMonthly = cboUpdateCheckFrequency.Items.Add(Language.Monthly); - if (Properties.OptionsUpdatesPage.Default.CheckForUpdatesFrequencyDays < 1) + if (!_RegistrySettings.CheckForUpdatesFrequencyDays.IsKeyPresent) + cboUpdateCheckFrequency.Enabled = chkCheckForUpdatesOnStartup.Checked; + + if (CommonRegistrySettings.AllowCheckForUpdatesAutomatical) { - chkCheckForUpdatesOnStartup.Checked = false; - cboUpdateCheckFrequency.SelectedIndex = nDaily; - } // Daily - else - switch (Properties.OptionsUpdatesPage.Default.CheckForUpdatesFrequencyDays) + cboUpdateCheckFrequency.Items.Clear(); + var nDaily = cboUpdateCheckFrequency.Items.Add(Language.Daily); + var nWeekly = cboUpdateCheckFrequency.Items.Add(Language.Weekly); + var nMonthly = cboUpdateCheckFrequency.Items.Add(Language.Monthly); + if (Properties.OptionsUpdatesPage.Default.CheckForUpdatesFrequencyDays < 1) { - case 1: - cboUpdateCheckFrequency.SelectedIndex = nDaily; - break; - case 7: - cboUpdateCheckFrequency.SelectedIndex = nWeekly; - break; - case 31: - cboUpdateCheckFrequency.SelectedIndex = nMonthly; - break; - default: - var nCustom = - cboUpdateCheckFrequency.Items.Add(string.Format(Language.UpdateFrequencyCustom, Properties.OptionsUpdatesPage.Default.CheckForUpdatesFrequencyDays)); - cboUpdateCheckFrequency.SelectedIndex = nCustom; - break; + chkCheckForUpdatesOnStartup.Checked = false; + cboUpdateCheckFrequency.SelectedIndex = nDaily; + } // Daily + else + { + switch (Properties.OptionsUpdatesPage.Default.CheckForUpdatesFrequencyDays) + { + case 1: + cboUpdateCheckFrequency.SelectedIndex = nDaily; + break; + case 7: + cboUpdateCheckFrequency.SelectedIndex = nWeekly; + break; + case 31: + cboUpdateCheckFrequency.SelectedIndex = nMonthly; + break; + default: + var nCustom = + cboUpdateCheckFrequency.Items.Add(string.Format(Language.UpdateFrequencyCustom, Properties.OptionsUpdatesPage.Default.CheckForUpdatesFrequencyDays)); + cboUpdateCheckFrequency.SelectedIndex = nCustom; + break; + } } + } var stable = cboReleaseChannel.Items.Add(UpdateChannelInfo.STABLE); var beta = cboReleaseChannel.Items.Add(UpdateChannelInfo.PREVIEW); @@ -130,6 +145,9 @@ namespace mRemoteNG.UI.Forms.OptionsPages { base.SaveSettings(); + if (UpdatesForbidden()) + return; + Properties.OptionsUpdatesPage.Default.CheckForUpdatesOnStartup = chkCheckForUpdatesOnStartup.Checked; if (cboUpdateCheckFrequency.SelectedItem.ToString() == Language.Daily) { @@ -156,13 +174,109 @@ namespace mRemoteNG.UI.Forms.OptionsPages Properties.OptionsUpdatesPage.Default.UpdateProxyAuthPass = cryptographyProvider.Encrypt(txtProxyPassword.Text, Runtime.EncryptionKey); } + public override void LoadRegistrySettings() + { + if (UpdatesForbidden()) + return; + + if (!CommonRegistrySettings.AllowCheckForUpdatesAutomatical) + { + Properties.OptionsUpdatesPage.Default.CheckForUpdatesOnStartup = false; + DisableControl(chkCheckForUpdatesOnStartup); + DisableControl(cboUpdateCheckFrequency); + } + + if (_RegistrySettings.CheckForUpdatesFrequencyDays.IsKeyPresent && _RegistrySettings.CheckForUpdatesFrequencyDays.Value >= 1) + { + Properties.OptionsUpdatesPage.Default.CheckForUpdatesFrequencyDays = _RegistrySettings.CheckForUpdatesFrequencyDays.Value; + DisableControl(cboUpdateCheckFrequency); + } + + btnUpdateCheckNow.Enabled = CommonRegistrySettings.AllowCheckForUpdatesManual; + + if (_RegistrySettings.UpdateChannel.IsKeyPresent) + { + Properties.OptionsUpdatesPage.Default.UpdateChannel = _RegistrySettings.UpdateChannel.Value; + DisableControl(cboReleaseChannel); + } + + if (_RegistrySettings.UseProxyForUpdates.IsKeyPresent) + { + Properties.OptionsUpdatesPage.Default.UpdateUseProxy = _RegistrySettings.UseProxyForUpdates.Value; + DisableControl(chkUseProxyForAutomaticUpdates); + + if (_RegistrySettings.UseProxyForUpdates.Value == false) + { + Properties.OptionsUpdatesPage.Default.UpdateProxyAddress = ""; + Properties.OptionsUpdatesPage.Default.UpdateProxyPort = 80; + } + + if (_RegistrySettings.ProxyAddress.IsKeyPresent && _RegistrySettings.UseProxyForUpdates.Value == true) + { + Properties.OptionsUpdatesPage.Default.UpdateProxyAddress = _RegistrySettings.ProxyAddress.Value; + DisableControl(txtProxyAddress); + } + + if (_RegistrySettings.ProxyPort.IsKeyPresent && _RegistrySettings.UseProxyForUpdates.Value == true) + { + // only set value if not is 0 to prevent errors.. + if (_RegistrySettings.ProxyPort.Value >= 1) + Properties.OptionsUpdatesPage.Default.UpdateProxyPort = _RegistrySettings.ProxyPort.Value; + + DisableControl(numProxyPort); + } + } + + if (_RegistrySettings.UseProxyAuthentication.IsKeyPresent) + { + Properties.OptionsUpdatesPage.Default.UpdateProxyUseAuthentication = _RegistrySettings.UseProxyAuthentication.Value; + DisableControl(chkUseProxyAuthentication); + + if (_RegistrySettings.UseProxyAuthentication.Value == false) + { + Properties.OptionsUpdatesPage.Default.UpdateProxyAuthUser = ""; + //Properties.OptionsUpdatesPage.Default.UpdateProxyAuthPass = ""; + } + + if (_RegistrySettings.ProxyAuthUser.IsKeyPresent && _RegistrySettings.UseProxyAuthentication.Value == true) + { + Properties.OptionsUpdatesPage.Default.UpdateProxyAuthUser = _RegistrySettings.ProxyAuthUser.Value; + DisableControl(txtProxyUsername); + } + + /*if (_RegistrySettings.ProxyAuthPass.IsProvided && _RegistrySettings.UseProxyAuthentication.Value == true) + { + Properties.OptionsUpdatesPage.Default.UpdateProxyAuthPass = _RegistrySettings.ProxyAuthPass; + DisableControl(txtProxyPassword); + }*/ + } + + + + lblUpdateAdminInfo.Visible = ShowAdministratorInfo(); + } + + public override bool ShowAdministratorInfo() + { + return !CommonRegistrySettings.AllowCheckForUpdatesAutomatical + || !CommonRegistrySettings.AllowCheckForUpdatesManual + || _RegistrySettings.CheckForUpdatesFrequencyDays.IsKeyPresent + || _RegistrySettings.UpdateChannel.IsKeyPresent + || _RegistrySettings.UseProxyForUpdates.IsKeyPresent + || _RegistrySettings.ProxyAddress.IsKeyPresent + || _RegistrySettings.ProxyPort.IsKeyPresent + || _RegistrySettings.UseProxyAuthentication.IsKeyPresent + || _RegistrySettings.ProxyAuthUser.IsKeyPresent; + } + #endregion #region Event Handlers private void chkCheckForUpdatesOnStartup_CheckedChanged(object sender, EventArgs e) { - cboUpdateCheckFrequency.Enabled = chkCheckForUpdatesOnStartup.Checked; + if (!_RegistrySettings.CheckForUpdatesFrequencyDays.IsKeyPresent) + cboUpdateCheckFrequency.Enabled = chkCheckForUpdatesOnStartup.Checked; } private void btnUpdateCheckNow_Click(object sender, EventArgs e) @@ -177,9 +291,10 @@ namespace mRemoteNG.UI.Forms.OptionsPages if (chkUseProxyForAutomaticUpdates.Checked) { - chkUseProxyAuthentication.Enabled = true; + if (!_RegistrySettings.UseProxyForUpdates.IsKeyPresent) + chkUseProxyAuthentication.Enabled = true; - if (chkUseProxyAuthentication.Checked) + if (chkUseProxyAuthentication.Checked && !_RegistrySettings.UseProxyAuthentication.IsKeyPresent) { tblProxyAuthentication.Enabled = true; } @@ -238,6 +353,49 @@ namespace mRemoteNG.UI.Forms.OptionsPages } } + private bool UpdatesForbidden() + { + bool forbidden = !CommonRegistrySettings.AllowCheckForUpdates + || (!CommonRegistrySettings.AllowCheckForUpdatesAutomatical + && !CommonRegistrySettings.AllowCheckForUpdatesManual); + + if (forbidden && _pageEnabled) + DisablePage(); + + return forbidden; + } + + public override void DisablePage() + { + chkCheckForUpdatesOnStartup.Checked = false; + chkCheckForUpdatesOnStartup.Enabled = false; + cboUpdateCheckFrequency.Enabled = false; + btnUpdateCheckNow.Enabled = false; + cboReleaseChannel.Enabled = false; + + chkUseProxyForAutomaticUpdates.Checked = false; + chkUseProxyForAutomaticUpdates.Enabled = false; + + tblProxyBasic.Enabled = false; + txtProxyAddress.Enabled = false; + txtProxyAddress.ReadOnly = true; + numProxyPort.Enabled = false; + + chkUseProxyAuthentication.Checked = false; + chkUseProxyAuthentication.Enabled = false; + + tblProxyAuthentication.Enabled = false; + txtProxyUsername.Enabled = false; + txtProxyUsername.ReadOnly = true; + txtProxyPassword.Enabled = false; + txtProxyPassword.ReadOnly = true; + btnTestProxy.Enabled = false; + + lblUpdateAdminInfo.Visible = true; + + _pageEnabled = false; + } + #endregion } } \ No newline at end of file diff --git a/mRemoteNG/UI/Forms/OptionsPages/UpdatesPage.resx b/mRemoteNG/UI/Forms/OptionsPages/UpdatesPage.resx index f298a7be8..5b46216f2 100644 --- a/mRemoteNG/UI/Forms/OptionsPages/UpdatesPage.resx +++ b/mRemoteNG/UI/Forms/OptionsPages/UpdatesPage.resx @@ -1,4 +1,64 @@ - + + + @@ -57,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True + \ No newline at end of file diff --git a/mRemoteNG/UI/Forms/frmMain.cs b/mRemoteNG/UI/Forms/frmMain.cs index 244bfcc5f..eee7f9f7a 100644 --- a/mRemoteNG/UI/Forms/frmMain.cs +++ b/mRemoteNG/UI/Forms/frmMain.cs @@ -33,6 +33,7 @@ using WeifenLuo.WinFormsUI.Docking; using mRemoteNG.UI.Controls; using mRemoteNG.Resources.Language; using System.Runtime.Versioning; +using mRemoteNG.Config.Settings.Registry; #endregion // ReSharper disable MemberCanBePrivate.Global @@ -345,6 +346,10 @@ namespace mRemoteNG.UI.Forms private void PromptForUpdatesPreference() { + if (!CommonRegistrySettings.AllowCheckForUpdates) return; + if (!CommonRegistrySettings.AllowCheckForUpdatesAutomatical) return; + if (CommonRegistrySettings.CheckForUpdatesAsked) return; + if (Properties.OptionsUpdatesPage.Default.CheckForUpdatesAsked) return; string[] commandButtons = { @@ -368,6 +373,9 @@ namespace mRemoteNG.UI.Forms private async Task CheckForUpdates() { + if (!CommonRegistrySettings.AllowCheckForUpdates) return; + if (!CommonRegistrySettings.AllowCheckForUpdatesAutomatical) return; + if (!Properties.OptionsUpdatesPage.Default.CheckForUpdatesOnStartup) return; var nextUpdateCheck = diff --git a/mRemoteNG/UI/Forms/frmOptions.cs b/mRemoteNG/UI/Forms/frmOptions.cs index 09257643a..fc4e97897 100644 --- a/mRemoteNG/UI/Forms/frmOptions.cs +++ b/mRemoteNG/UI/Forms/frmOptions.cs @@ -206,6 +206,7 @@ namespace mRemoteNG.UI.Forms if (page == null) return; page.ApplyLanguage(); + page.LoadRegistrySettings(); page.LoadSettings(); _optionPages.Add(page); lstOptionPages.AddObject(page); diff --git a/mRemoteNG/UI/Menu/msMain/HelpMenu.cs b/mRemoteNG/UI/Menu/msMain/HelpMenu.cs index c4675bd1a..5bb3bd830 100644 --- a/mRemoteNG/UI/Menu/msMain/HelpMenu.cs +++ b/mRemoteNG/UI/Menu/msMain/HelpMenu.cs @@ -6,6 +6,7 @@ using mRemoteNG.App.Info; using mRemoteNG.UI.Forms; using mRemoteNG.Resources.Language; using System.Runtime.Versioning; +using mRemoteNG.Config.Settings.Registry; namespace mRemoteNG.UI.Menu { @@ -78,6 +79,8 @@ namespace mRemoteNG.UI.Menu _mMenToolsUpdate.Size = new System.Drawing.Size(190, 22); _mMenToolsUpdate.Text = Language.CheckForUpdates; _mMenToolsUpdate.Click += mMenToolsUpdate_Click; + _mMenToolsUpdate.Enabled = CommonRegistrySettings.AllowCheckForUpdates + && CommonRegistrySettings.AllowCheckForUpdatesManual; // // mMenInfoSep1 //