diff --git a/InstallerProjects/CustomActions/CustomActions.cs b/InstallerProjects/CustomActions/CustomActions.cs index c8e3242d7..d13453244 100644 --- a/InstallerProjects/CustomActions/CustomActions.cs +++ b/InstallerProjects/CustomActions/CustomActions.cs @@ -7,16 +7,20 @@ namespace CustomActions [CustomAction] public static ActionResult IsMinimumRdpVersionInstalled(Session session) { - var rdpVersionChecker = new InstalledKbChecker("MINIMUM_RDP_KB", "MINIMUM_RDP_VERSION_INSTALLED", session); - rdpVersionChecker.Execute(); + var acceptedRdpKbVariables = new[] { session["RDP80_KB"], session["RDP81_KB"] }; + var returnVariable = "MINIMUM_RDP_VERSION_INSTALLED"; + var kbInstalledChecker = new KbInstalledChecker(session); + kbInstalledChecker.Execute(acceptedRdpKbVariables, returnVariable); return ActionResult.Success; } [CustomAction] public static ActionResult IsRdpDtlsUpdateInstalled(Session session) { - var rdpVersionChecker = new InstalledKbChecker("RDP_DTLS_KB", "RDP_DTLS_UPDATE_INSTALLED", session); - rdpVersionChecker.Execute(); + var kb = session["RDP_DTLS_KB"]; + var returnVar = "RDP_DTLS_UPDATE_INSTALLED"; + var kbInstalledChecker = new KbInstalledChecker(session); + kbInstalledChecker.Execute(kb, returnVar); return ActionResult.Success; } diff --git a/InstallerProjects/CustomActions/CustomActions.csproj b/InstallerProjects/CustomActions/CustomActions.csproj index cf1d50439..de635dc83 100644 --- a/InstallerProjects/CustomActions/CustomActions.csproj +++ b/InstallerProjects/CustomActions/CustomActions.csproj @@ -45,9 +45,9 @@ + - - + diff --git a/InstallerProjects/CustomActions/InstalledKbChecker.cs b/InstallerProjects/CustomActions/InstalledKbChecker.cs deleted file mode 100644 index 3a9fb5a39..000000000 --- a/InstallerProjects/CustomActions/InstalledKbChecker.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System; -using Microsoft.Deployment.WindowsInstaller; - -namespace CustomActions -{ - public class InstalledKbChecker - { - private readonly Session _session; - private readonly string _kbVariable; - private readonly string _returnVar; - - public InstalledKbChecker(string kbVariable, string returnVar, Session session) - { - _kbVariable = kbVariable; - _returnVar = returnVar; - _session = session; - } - - public bool Execute() - { - try - { - _session.Log("Begin InstalledKbChecker"); - var minimumKb = _session[_kbVariable]; - var isUpdateInstalled = IsUpdateInstalled(minimumKb); - SetReturnValue(isUpdateInstalled); - _session.Log("End InstalledKbChecker"); - return true; - } - catch (Exception e) - { - _session.Log($"There was an issue executing the RdpVersionChecker. Exception: {e}"); - return false; - } - } - - private bool IsUpdateInstalled(string kb) - { - _session.Log($"Checking if '{kb}' is installed"); - var updateGatherer = new InstalledWindowsUpdateGatherer(); - var isUpdateInstalled = updateGatherer.IsUpdateInstalled(kb); - _session.Log($"KB is installed = '{isUpdateInstalled}'"); - return isUpdateInstalled; - } - - private void SetReturnValue(bool isUpdateInstalled) - { - var updateInstalledVal = isUpdateInstalled ? "1" : "0"; - _session[_returnVar] = updateInstalledVal; - _session.Log($"Set property '{_returnVar}' to '{updateInstalledVal}'"); - } - } -} \ No newline at end of file diff --git a/InstallerProjects/CustomActions/InstalledWindowsUpdateGatherer.cs b/InstallerProjects/CustomActions/InstalledWindowsUpdateChecker.cs similarity index 90% rename from InstallerProjects/CustomActions/InstalledWindowsUpdateGatherer.cs rename to InstallerProjects/CustomActions/InstalledWindowsUpdateChecker.cs index 822084ec0..5fa3d6d27 100644 --- a/InstallerProjects/CustomActions/InstalledWindowsUpdateGatherer.cs +++ b/InstallerProjects/CustomActions/InstalledWindowsUpdateChecker.cs @@ -5,11 +5,11 @@ using System.Collections.Generic; namespace CustomActions { - public class InstalledWindowsUpdateGatherer + public class InstalledWindowsUpdateChecker { private readonly ManagementScope _managementScope; - public InstalledWindowsUpdateGatherer() + public InstalledWindowsUpdateChecker() { _managementScope = Connect(); } @@ -41,10 +41,7 @@ namespace CustomActions return installedUpdates; } - public bool IsUpdateInstalled(string kb) - { - return IsUpdateInstalled(new[] {kb}); - } + public bool IsUpdateInstalled(string kb) => IsUpdateInstalled(new[] {kb}); public bool IsUpdateInstalled(IEnumerable kbList) { diff --git a/InstallerProjects/CustomActions/KbInstalledChecker.cs b/InstallerProjects/CustomActions/KbInstalledChecker.cs new file mode 100644 index 000000000..bdfe432f3 --- /dev/null +++ b/InstallerProjects/CustomActions/KbInstalledChecker.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using Microsoft.Deployment.WindowsInstaller; + +namespace CustomActions +{ + public class KbInstalledChecker + { + private readonly Session _session; + private readonly InstalledWindowsUpdateChecker _installedUpdateChecker; + + public KbInstalledChecker(Session session) + { + _installedUpdateChecker = new InstalledWindowsUpdateChecker(); + _session = session; + } + + public bool Execute(string acceptedKb, string returnVar) => Execute(new[] {acceptedKb}, returnVar); + + public bool Execute(IEnumerable acceptedKbs, string returnVar) + { + try + { + _session.Log("Begin KbInstalledChecker"); + var isUpdateInstalled = _installedUpdateChecker.IsUpdateInstalled(acceptedKbs); + SetReturnValue(isUpdateInstalled, returnVar); + _session.Log("End KbInstalledChecker"); + return true; + } + catch (Exception e) + { + _session.Log($"There was an issue executing the KbInstalledChecker. Exception: {e}"); + return false; + } + } + + private void SetReturnValue(bool isUpdateInstalled, string returnVar) + { + var updateInstalledVal = isUpdateInstalled ? "1" : "0"; + _session[returnVar] = updateInstalledVal; + _session.Log($"Set property '{returnVar}' to '{updateInstalledVal}'"); + } + } +} \ No newline at end of file diff --git a/InstallerProjects/Installer/mRemoteNGV1.wxs b/InstallerProjects/Installer/mRemoteNGV1.wxs index f59aa0b23..054fcc9fe 100644 --- a/InstallerProjects/Installer/mRemoteNGV1.wxs +++ b/InstallerProjects/Installer/mRemoteNGV1.wxs @@ -18,7 +18,8 @@ - + +