diff --git a/RemoteApplicationPublisher/Program.cs b/RemoteApplicationPublisher/Program.cs index 441df5a..322cd0a 100644 --- a/RemoteApplicationPublisher/Program.cs +++ b/RemoteApplicationPublisher/Program.cs @@ -1,8 +1,10 @@ using System; +using System.Runtime.Versioning; using System.Windows.Forms; namespace RemoteApplicationPublisher { + [SupportedOSPlatform("windows")] internal static class Program { /// diff --git a/RemoteApplicationPublisher/RemoteAppEditWindow.Designer.cs b/RemoteApplicationPublisher/RemoteAppEditWindow.Designer.cs index 4e68dbc..352d5d8 100644 --- a/RemoteApplicationPublisher/RemoteAppEditWindow.Designer.cs +++ b/RemoteApplicationPublisher/RemoteAppEditWindow.Designer.cs @@ -284,6 +284,7 @@ private void InitializeComponent() // this.checkBoxDebug.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.checkBoxDebug.AutoSize = true; + this.checkBoxDebug.Enabled = false; this.checkBoxDebug.ForeColor = System.Drawing.SystemColors.ControlDarkDark; this.checkBoxDebug.Location = new System.Drawing.Point(309, 261); this.checkBoxDebug.Name = "checkBoxDebug"; diff --git a/RemoteApplicationPublisher/RemoteAppEditWindow.cs b/RemoteApplicationPublisher/RemoteAppEditWindow.cs index e511064..d32dce6 100644 --- a/RemoteApplicationPublisher/RemoteAppEditWindow.cs +++ b/RemoteApplicationPublisher/RemoteAppEditWindow.cs @@ -1,12 +1,14 @@  using System; using System.IO; +using System.Runtime.Versioning; using System.Windows.Forms; using Microsoft.Win32; namespace RemoteApplicationPublisher { + [SupportedOSPlatform("windows")] public partial class RemoteAppEditWindow : Form { @@ -29,7 +31,7 @@ public RemoteAppEditWindow(RemoteAppMainWindow mainWindow) public RemoteApp EditRemoteApp(RemoteApp selectedRemoteApp) { HelpSystem.SetupTips(this); - RemoteApp = selectedRemoteApp; + RemoteApp = selectedRemoteApp ?? new RemoteApp(); Text = "Properties of " + RemoteApp.Name; Size = MinimumSize; HelpSystem.SetupTips(this); @@ -91,8 +93,16 @@ public void LoadValues() break; } checkBoxOILauncher.Checked = RemoteApp.UseLauncher; + checkBoxDebug.Enabled = checkBoxOILauncher.Checked; - checkBoxDebug.Checked = CommandLineText.Text.Contains(enableDebug); + if (checkBoxOILauncher.Checked) + { + checkBoxDebug.Checked = CommandLineText.Text.Contains(enableDebug); + } + else + { + checkBoxDebug.Checked = false; + } Icon = RemoteAppFunction.ReturnIcon(RemoteApp.Path); } @@ -139,13 +149,14 @@ private bool DoBrowsePath() private void SaveRemoteApp(string ShortName, string FullName, string Path, string VPath, string CommandLine, int CommandLineSetting, string IconPath, int IconIndex, int ShowInTSWA) { - var SysApps = new SystemRemoteApps(); if (RemoteApp.Name is not null & !(Text == "New RemoteApp")) { - if (!((RemoteApp.Name ?? "") == (ShortName ?? ""))) + if (RemoteApp.Name != null && ShortName != null && !((RemoteApp.Name ?? "") == (ShortName ?? ""))) +#pragma warning disable 8604 SysApps.RenameApp(RemoteApp.Name, ShortName); +#pragma warning restore 8604 } RemoteApp.Name = ShortName; @@ -186,19 +197,22 @@ private void SaveButton_Click(object sender, EventArgs e) private void SaveAndEditWindow() { - if (string.IsNullOrEmpty(ShortNameText.Text)) + if (string.IsNullOrEmpty(ShortNameText?.Text)) { MessageBox.Show("Name must not be blank.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); } - else if (string.IsNullOrEmpty(FullNameText.Text)) + else if (string.IsNullOrEmpty(FullNameText?.Text)) { MessageBox.Show("Full name must not be blank.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); } - else if (string.IsNullOrEmpty(PathText.Text)) + else if (string.IsNullOrEmpty(PathText?.Text)) { MessageBox.Show("Path must not be blank.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); } +// Already checked for null or empty. +#pragma warning disable 8604 else if (!((ShortNameText.Text ?? "") == (RemoteApp.Name ?? "")) & DoesAppExist(ShortNameText.Text)) +#pragma warning restore 8604 { MessageBox.Show("A RemoteApp with the same name already exists.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); } @@ -226,12 +240,12 @@ private int GetCommandLineOption() private void SaveAndCloseOrWindow() { - if (string.IsNullOrEmpty(ShortNameText.Text)) + if (string.IsNullOrEmpty(ShortNameText?.Text)) { MessageBox.Show("Name must not be blank.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); ShowDialog(); } - else if (string.IsNullOrEmpty(FullNameText.Text)) + else if (string.IsNullOrEmpty(FullNameText?.Text)) { MessageBox.Show("Full name must not be blank.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); ShowDialog(); @@ -241,7 +255,10 @@ private void SaveAndCloseOrWindow() MessageBox.Show("Path must not be blank.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); ShowDialog(); } +// Already checked for null. +#pragma warning disable 8604 else if (!((ShortNameText.Text ?? "") == (RemoteApp.Name ?? "")) & DoesAppExist(ShortNameText.Text)) +#pragma warning restore 8604 { MessageBox.Show("A RemoteApp with the same name already exists.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); ShowDialog(); @@ -260,19 +277,22 @@ private void SaveAndCloseOrWindow() private void SaveAndClose() { - if (string.IsNullOrEmpty(ShortNameText.Text)) + if (string.IsNullOrEmpty(ShortNameText?.Text)) { MessageBox.Show("Name must not be blank.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); } - else if (string.IsNullOrEmpty(FullNameText.Text)) + else if (string.IsNullOrEmpty(FullNameText?.Text)) { MessageBox.Show("Full name must not be blank.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); } - else if (string.IsNullOrEmpty(PathText.Text)) + else if (string.IsNullOrEmpty(PathText?.Text)) { MessageBox.Show("Path must not be blank.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); } +// Already checked for null. +#pragma warning disable 8604 else if (!((ShortNameText.Text ?? "") == (RemoteApp.Name ?? "")) & DoesAppExist(ShortNameText.Text)) +#pragma warning restore 8604 { MessageBox.Show("A RemoteApp with the same name already exists.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); } @@ -294,29 +314,31 @@ private void ShortNameText_TextChanged(object sender, EventArgs e) private void checkBoxOILauncher_CheckedChanged(object sender, EventArgs e) { - if (!populatingEditDialog) - { - if (checkBoxOILauncher.Checked) - { - RemoteAppOriginalPath = PathText.Text; - PathText.Text = remoteLauncher; - radioButtonEnforced.Checked = true; - CommandLineText.Text = string.Format(commandLineTemplate, RemoteAppOriginalPath); - } - else - { - var sra = new SystemRemoteApps(); - var currentApp = sra.GetApp(ShortNameText.Text); - if (currentApp != null) - { - RemoteAppOriginalPath = currentApp.VPath; - } - PathText.Text = RemoteAppOriginalPath; - radioButtonOptional.Checked = true; - CommandLineText.Text = string.Empty; + if (!populatingEditDialog) + { + if (checkBoxOILauncher.Checked) + { + RemoteAppOriginalPath = PathText.Text; + PathText.Text = remoteLauncher; + radioButtonEnforced.Checked = true; + CommandLineText.Text = string.Format(commandLineTemplate, RemoteAppOriginalPath); + } + else + { + var sra = new SystemRemoteApps(); + var currentApp = sra.GetApp(ShortNameText.Text); + if (currentApp != null) + { + RemoteAppOriginalPath = currentApp.VPath; + } + PathText.Text = RemoteAppOriginalPath; + radioButtonOptional.Checked = true; + checkBoxDebug.Checked = false; + CommandLineText.Text = string.Empty; } } + checkBoxDebug.Enabled = checkBoxOILauncher.Checked; PathText.Enabled = !checkBoxOILauncher.Checked; BrowsePath.Enabled = !checkBoxOILauncher.Checked; panelOptions.Enabled = !checkBoxOILauncher.Checked; diff --git a/RemoteApplicationPublisher/RemoteAppEditWindow.resx b/RemoteApplicationPublisher/RemoteAppEditWindow.resx index 94e935b..5d1aeb1 100644 --- a/RemoteApplicationPublisher/RemoteAppEditWindow.resx +++ b/RemoteApplicationPublisher/RemoteAppEditWindow.resx @@ -65,7 +65,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAEZTeXN0ZW0uV2luZG93cy5Gb3JtcywgQ3VsdHVyZT1uZXV0cmFs LCBQdWJsaWNLZXlUb2tl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BKwFFAUIB+AH/AVIBUAH6Af8BYQFeAv8BRQFDAfcB/wIrAX4B/AMEAQXI AAMXAR8BXgFbAv8BgQFiAv8BgQFiAf4B/wFYAVUB/QH/Ax4BKwgAAx4BKwFGAUMB+AH/AVMBUQH7Af8B diff --git a/RemoteApplicationPublisher/RemoteAppFunction.cs b/RemoteApplicationPublisher/RemoteAppFunction.cs index a07a028..4ca5b3b 100644 --- a/RemoteApplicationPublisher/RemoteAppFunction.cs +++ b/RemoteApplicationPublisher/RemoteAppFunction.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System.Drawing; using System.IO; +using System.Runtime.Versioning; using System.Text.RegularExpressions; using System.Windows.Forms; using Microsoft.Win32; @@ -9,6 +10,7 @@ namespace RemoteApplicationPublisher { + [SupportedOSPlatform("windows")] static class RemoteAppFunction { diff --git a/RemoteApplicationPublisher/RemoteAppHostOptions.cs b/RemoteApplicationPublisher/RemoteAppHostOptions.cs index d4f7c33..5600630 100644 --- a/RemoteApplicationPublisher/RemoteAppHostOptions.cs +++ b/RemoteApplicationPublisher/RemoteAppHostOptions.cs @@ -1,9 +1,11 @@ using System; +using System.Runtime.Versioning; using System.Windows.Forms; using Microsoft.Win32; namespace RemoteApplicationPublisher { + [SupportedOSPlatform("windows")] public partial class RemoteAppHostOptions : Form { private RemoteAppMainWindow _mainWindow; @@ -139,7 +141,10 @@ public void SetValues() TimeoutIdleCheckBox.Checked = false; } +// Code has a default value. +#pragma warning disable 8605 var fResetBroken = ((Int32)PolicyKey.GetValue("fResetBroken", 0)) == 0 ? false : true; +#pragma warning restore 8605 if (fResetBroken != default) { LogoffWhenTimoutCheckBox.Checked = true; @@ -149,7 +154,11 @@ public void SetValues() LogoffWhenTimoutCheckBox.Checked = false; } +// Code has a default value. +#pragma warning disable 8605 var fAllowUnlistedRemotePrograms = ((Int32)PolicyKey.GetValue("fAllowUnlistedRemotePrograms", 0)) == 0 ? false : true; +// Code has a default value. +#pragma warning restore 8605 if (fAllowUnlistedRemotePrograms != default) { AllowUnlistedRemoteProgramsCheckBox.Checked = true; diff --git a/RemoteApplicationPublisher/RemoteAppLib.cs b/RemoteApplicationPublisher/RemoteAppLib.cs index 6823d6d..f5600de 100644 --- a/RemoteApplicationPublisher/RemoteAppLib.cs +++ b/RemoteApplicationPublisher/RemoteAppLib.cs @@ -1,5 +1,6 @@  using System; +using System.Runtime.Versioning; using Microsoft.Win32; namespace RemoteApplicationPublisher @@ -33,6 +34,7 @@ public class RemoteApp public bool UseLauncher = false; } + [SupportedOSPlatform("windows")] public class SystemRemoteApps { private string RegistryPath = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Terminal Server\TSAppAllowList\Applications"; @@ -49,9 +51,9 @@ public void Init() { string RegistryPathCV = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\"; var cvKey = Registry.LocalMachine.OpenSubKey(RegistryPathCV, true); - var tsKey = cvKey.CreateSubKey("Terminal Server"); - var tsaaKey = tsKey.CreateSubKey("TSAppAllowList"); - var appKey = tsaaKey.CreateSubKey("Applications"); + var tsKey = cvKey?.CreateSubKey("Terminal Server"); + var tsaaKey = tsKey?.CreateSubKey("TSAppAllowList"); + var appKey = tsaaKey?.CreateSubKey("Applications"); } public RemoteAppCollection GetAll() diff --git a/RemoteApplicationPublisher/RemoteAppMainWindow.cs b/RemoteApplicationPublisher/RemoteAppMainWindow.cs index 0bddb9d..3b27330 100644 --- a/RemoteApplicationPublisher/RemoteAppMainWindow.cs +++ b/RemoteApplicationPublisher/RemoteAppMainWindow.cs @@ -1,10 +1,12 @@ using System; using System.Diagnostics; using System.Drawing; +using System.Runtime.Versioning; using System.Windows.Forms; namespace RemoteApplicationPublisher { + [SupportedOSPlatform("windows")] public partial class RemoteAppMainWindow : Form { private string clipboardText = string.Empty; @@ -210,7 +212,7 @@ private void aboutToolStripMenuItem1_Click(object sender, EventArgs e) private void copyToClipboardToolStripMenuItem_Click(object sender, EventArgs e) { - if (AppList.FocusedItem != null) + if (AppList.FocusedItem != null && !string.IsNullOrEmpty(clipboardText)) { Clipboard.SetText(clipboardText); }