diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2022-06-09 15:30:48 -0500 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2022-06-13 09:28:49 -0500 |
| commit | 6f6e4ced9f398ff37a44b91fdba62479cde29d06 (patch) | |
| tree | 8cef5b123df7ff11cdc9be79d2e981d9d567d65d /src/test/burn/WixTestTools | |
| parent | 68ec803fc7f48bb0e0463dc45f6ce40e1f07dbf5 (diff) | |
| download | wix-6f6e4ced9f398ff37a44b91fdba62479cde29d06.tar.gz wix-6f6e4ced9f398ff37a44b91fdba62479cde29d06.tar.bz2 wix-6f6e4ced9f398ff37a44b91fdba62479cde29d06.zip | |
Implement ArpEntry flavored ExePackage.
6772
Diffstat (limited to 'src/test/burn/WixTestTools')
| -rw-r--r-- | src/test/burn/WixTestTools/ArpEntryInstaller.cs | 43 | ||||
| -rw-r--r-- | src/test/burn/WixTestTools/ArpEntryVerifier.cs | 24 | ||||
| -rw-r--r-- | src/test/burn/WixTestTools/BundleRegistration.cs | 121 | ||||
| -rw-r--r-- | src/test/burn/WixTestTools/BundleVerifier.cs | 23 | ||||
| -rw-r--r-- | src/test/burn/WixTestTools/GenericArpRegistration.cs | 143 |
5 files changed, 250 insertions, 104 deletions
diff --git a/src/test/burn/WixTestTools/ArpEntryInstaller.cs b/src/test/burn/WixTestTools/ArpEntryInstaller.cs new file mode 100644 index 00000000..96d9fab9 --- /dev/null +++ b/src/test/burn/WixTestTools/ArpEntryInstaller.cs | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
| 2 | |||
| 3 | namespace WixTestTools | ||
| 4 | { | ||
| 5 | using System; | ||
| 6 | using Xunit; | ||
| 7 | |||
| 8 | public partial class ArpEntryInstaller : IDisposable | ||
| 9 | { | ||
| 10 | public ArpEntryInstaller(WixTestContext testContext, string id, bool perMachine = true, bool x64 = false) | ||
| 11 | { | ||
| 12 | this.ArpId = id; | ||
| 13 | this.PerMachine = perMachine; | ||
| 14 | this.X64 = x64; | ||
| 15 | this.TestContext = testContext; | ||
| 16 | } | ||
| 17 | |||
| 18 | public string ArpId { get; } | ||
| 19 | |||
| 20 | public bool PerMachine { get; } | ||
| 21 | |||
| 22 | public bool X64 { get; } | ||
| 23 | |||
| 24 | private WixTestContext TestContext { get; } | ||
| 25 | |||
| 26 | public void Unregister(bool assertIfMissing = true) | ||
| 27 | { | ||
| 28 | if (this.TryGetRegistration(out var registration)) | ||
| 29 | { | ||
| 30 | registration.Delete(); | ||
| 31 | } | ||
| 32 | else | ||
| 33 | { | ||
| 34 | Assert.True(false, "Tried to unregister when not registered."); | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | public void Dispose() | ||
| 39 | { | ||
| 40 | this.Unregister(false); | ||
| 41 | } | ||
| 42 | } | ||
| 43 | } | ||
diff --git a/src/test/burn/WixTestTools/ArpEntryVerifier.cs b/src/test/burn/WixTestTools/ArpEntryVerifier.cs new file mode 100644 index 00000000..b3c70337 --- /dev/null +++ b/src/test/burn/WixTestTools/ArpEntryVerifier.cs | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
| 2 | |||
| 3 | namespace WixTestTools | ||
| 4 | { | ||
| 5 | using Xunit; | ||
| 6 | |||
| 7 | public partial class ArpEntryInstaller | ||
| 8 | { | ||
| 9 | public bool TryGetRegistration(out GenericArpRegistration registration) | ||
| 10 | { | ||
| 11 | bool success = !this.PerMachine ? GenericArpRegistration.TryGetPerUserRegistrationById(this.ArpId, out registration) | ||
| 12 | : GenericArpRegistration.TryGetPerMachineRegistrationById(this.ArpId, this.X64, out registration); | ||
| 13 | |||
| 14 | return success; | ||
| 15 | } | ||
| 16 | |||
| 17 | public void VerifyRegistered(bool registered) | ||
| 18 | { | ||
| 19 | bool success = this.TryGetRegistration(out _); | ||
| 20 | |||
| 21 | Assert.Equal(registered, success); | ||
| 22 | } | ||
| 23 | } | ||
| 24 | } | ||
diff --git a/src/test/burn/WixTestTools/BundleRegistration.cs b/src/test/burn/WixTestTools/BundleRegistration.cs index 3541e7ea..524d4616 100644 --- a/src/test/burn/WixTestTools/BundleRegistration.cs +++ b/src/test/burn/WixTestTools/BundleRegistration.cs | |||
| @@ -5,108 +5,51 @@ namespace WixTestTools | |||
| 5 | using System; | 5 | using System; |
| 6 | using Microsoft.Win32; | 6 | using Microsoft.Win32; |
| 7 | 7 | ||
| 8 | public class BundleRegistration | 8 | public class BundleRegistration : GenericArpRegistration |
| 9 | { | 9 | { |
| 10 | public const string BURN_REGISTRATION_REGISTRY_UNINSTALL_KEY = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"; | ||
| 11 | public const string BURN_REGISTRATION_REGISTRY_UNINSTALL_KEY_WOW6432NODE = "SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall"; | ||
| 12 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_CACHE_PATH = "BundleCachePath"; | ||
| 13 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_ADDON_CODE = "BundleAddonCode"; | 10 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_ADDON_CODE = "BundleAddonCode"; |
| 11 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_CACHE_PATH = "BundleCachePath"; | ||
| 14 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_DETECT_CODE = "BundleDetectCode"; | 12 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_DETECT_CODE = "BundleDetectCode"; |
| 15 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_PATCH_CODE = "BundlePatchCode"; | 13 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_PATCH_CODE = "BundlePatchCode"; |
| 14 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_PROVIDER_KEY = "BundleProviderKey"; | ||
| 15 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_RESUME_COMMAND_LINE = "BundleResumeCommandLine"; | ||
| 16 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_TAG = "BundleTag"; | ||
| 16 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_UPGRADE_CODE = "BundleUpgradeCode"; | 17 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_UPGRADE_CODE = "BundleUpgradeCode"; |
| 17 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_DISPLAY_NAME = "DisplayName"; | ||
| 18 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_VERSION = "BundleVersion"; | 18 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_VERSION = "BundleVersion"; |
| 19 | public const string BURN_REGISTRATION_REGISTRY_ENGINE_VERSION = "EngineVersion"; | 19 | public const string BURN_REGISTRATION_REGISTRY_ENGINE_VERSION = "EngineVersion"; |
| 20 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_PROVIDER_KEY = "BundleProviderKey"; | ||
| 21 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_TAG = "BundleTag"; | ||
| 22 | public const string REGISTRY_REBOOT_PENDING_FORMAT = "{0}.RebootRequired"; | ||
| 23 | public const string REGISTRY_BUNDLE_INSTALLED = "Installed"; | ||
| 24 | public const string REGISTRY_BUNDLE_DISPLAY_ICON = "DisplayIcon"; | ||
| 25 | public const string REGISTRY_BUNDLE_DISPLAY_VERSION = "DisplayVersion"; | ||
| 26 | public const string REGISTRY_BUNDLE_ESTIMATED_SIZE = "EstimatedSize"; | ||
| 27 | public const string REGISTRY_BUNDLE_PUBLISHER = "Publisher"; | ||
| 28 | public const string REGISTRY_BUNDLE_HELP_LINK = "HelpLink"; | ||
| 29 | public const string REGISTRY_BUNDLE_HELP_TELEPHONE = "HelpTelephone"; | ||
| 30 | public const string REGISTRY_BUNDLE_URL_INFO_ABOUT = "URLInfoAbout"; | ||
| 31 | public const string REGISTRY_BUNDLE_URL_UPDATE_INFO = "URLUpdateInfo"; | ||
| 32 | public const string REGISTRY_BUNDLE_PARENT_DISPLAY_NAME = "ParentDisplayName"; | ||
| 33 | public const string REGISTRY_BUNDLE_PARENT_KEY_NAME = "ParentKeyName"; | ||
| 34 | public const string REGISTRY_BUNDLE_COMMENTS = "Comments"; | ||
| 35 | public const string REGISTRY_BUNDLE_CONTACT = "Contact"; | ||
| 36 | public const string REGISTRY_BUNDLE_NO_MODIFY = "NoModify"; | ||
| 37 | public const string REGISTRY_BUNDLE_MODIFY_PATH = "ModifyPath"; | ||
| 38 | public const string REGISTRY_BUNDLE_NO_ELEVATE_ON_MODIFY = "NoElevateOnModify"; | ||
| 39 | public const string REGISTRY_BUNDLE_NO_REMOVE = "NoRemove"; | ||
| 40 | public const string REGISTRY_BUNDLE_SYSTEM_COMPONENT = "SystemComponent"; | ||
| 41 | public const string REGISTRY_BUNDLE_QUIET_UNINSTALL_STRING = "QuietUninstallString"; | ||
| 42 | public const string REGISTRY_BUNDLE_UNINSTALL_STRING = "UninstallString"; | ||
| 43 | public const string REGISTRY_BUNDLE_RESUME_COMMAND_LINE = "BundleResumeCommandLine"; | ||
| 44 | public const string REGISTRY_BUNDLE_VERSION_MAJOR = "VersionMajor"; | ||
| 45 | public const string REGISTRY_BUNDLE_VERSION_MINOR = "VersionMinor"; | ||
| 46 | 20 | ||
| 47 | public string[] AddonCodes { get; set; } | 21 | public string[] AddonCodes { get; set; } |
| 48 | 22 | ||
| 49 | public string CachePath { get; set; } | 23 | public string BundleVersion { get; set; } |
| 50 | 24 | ||
| 51 | public string DisplayName { get; set; } | 25 | public string CachePath { get; set; } |
| 52 | 26 | ||
| 53 | public string[] DetectCodes { get; set; } | 27 | public string[] DetectCodes { get; set; } |
| 54 | 28 | ||
| 55 | public string EngineVersion { get; set; } | 29 | public string EngineVersion { get; set; } |
| 56 | 30 | ||
| 57 | public int? EstimatedSize { get; set; } | ||
| 58 | |||
| 59 | public int? Installed { get; set; } | ||
| 60 | |||
| 61 | public string ModifyPath { get; set; } | ||
| 62 | |||
| 63 | public string[] PatchCodes { get; set; } | 31 | public string[] PatchCodes { get; set; } |
| 64 | 32 | ||
| 65 | public string ProviderKey { get; set; } | 33 | public string ProviderKey { get; set; } |
| 66 | 34 | ||
| 67 | public string Publisher { get; set; } | ||
| 68 | |||
| 69 | public int? SystemComponent { get; set; } | ||
| 70 | |||
| 71 | public string QuietUninstallString { get; set; } | ||
| 72 | |||
| 73 | public string QuietUninstallCommand { get; set; } | ||
| 74 | |||
| 75 | public string QuietUninstallCommandArguments { get; set; } | ||
| 76 | |||
| 77 | public string Tag { get; set; } | 35 | public string Tag { get; set; } |
| 78 | 36 | ||
| 79 | public string UninstallCommand { get; set; } | ||
| 80 | |||
| 81 | public string UninstallCommandArguments { get; set; } | ||
| 82 | |||
| 83 | public string UninstallString { get; set; } | ||
| 84 | |||
| 85 | public string[] UpgradeCodes { get; set; } | 37 | public string[] UpgradeCodes { get; set; } |
| 86 | 38 | ||
| 87 | public string UrlInfoAbout { get; set; } | 39 | public static bool TryGetPerMachineBundleRegistrationById(string id, bool x64, out BundleRegistration registration) |
| 88 | 40 | { | |
| 89 | public string UrlUpdateInfo { get; set; } | 41 | return TryGetRegistrationById(id, x64, false, out registration); |
| 90 | 42 | } | |
| 91 | public string Version { get; set; } | ||
| 92 | 43 | ||
| 93 | public static bool TryGetPerMachineBundleRegistrationById(string bundleId, bool x64, out BundleRegistration registration) | 44 | public static bool TryGetPerUserBundleRegistrationById(string id, out BundleRegistration registration) |
| 94 | { | 45 | { |
| 95 | var baseKeyPath = x64 ? BURN_REGISTRATION_REGISTRY_UNINSTALL_KEY : BURN_REGISTRATION_REGISTRY_UNINSTALL_KEY_WOW6432NODE; | 46 | return TryGetRegistrationById(id, true, true, out registration); |
| 96 | var registrationKeyPath = $"{baseKeyPath}\\{bundleId}"; | ||
| 97 | using var registrationKey = Registry.LocalMachine.OpenSubKey(registrationKeyPath); | ||
| 98 | var success = registrationKey != null; | ||
| 99 | registration = success ? GetBundleRegistration(registrationKey) : null; | ||
| 100 | return success; | ||
| 101 | } | 47 | } |
| 102 | 48 | ||
| 103 | public static bool TryGetPerUserBundleRegistrationById(string bundleId, out BundleRegistration registration) | 49 | private static bool TryGetRegistrationById(string id, bool x64, bool perUser, out BundleRegistration registration) |
| 104 | { | 50 | { |
| 105 | var registrationKeyPath = $"{BURN_REGISTRATION_REGISTRY_UNINSTALL_KEY}\\{bundleId}"; | 51 | registration = GetGenericArpRegistration(id, x64, perUser, key => GetBundleRegistration(key)); |
| 106 | using var registrationKey = Registry.CurrentUser.OpenSubKey(registrationKeyPath); | 52 | return registration != null; |
| 107 | var success = registrationKey != null; | ||
| 108 | registration = success ? GetBundleRegistration(registrationKey) : null; | ||
| 109 | return success; | ||
| 110 | } | 53 | } |
| 111 | 54 | ||
| 112 | private static BundleRegistration GetBundleRegistration(RegistryKey idKey) | 55 | private static BundleRegistration GetBundleRegistration(RegistryKey idKey) |
| @@ -120,38 +63,8 @@ namespace WixTestTools | |||
| 120 | registration.ProviderKey = idKey.GetValue(BURN_REGISTRATION_REGISTRY_BUNDLE_PROVIDER_KEY) as string; | 63 | registration.ProviderKey = idKey.GetValue(BURN_REGISTRATION_REGISTRY_BUNDLE_PROVIDER_KEY) as string; |
| 121 | registration.Tag = idKey.GetValue(BURN_REGISTRATION_REGISTRY_BUNDLE_TAG) as string; | 64 | registration.Tag = idKey.GetValue(BURN_REGISTRATION_REGISTRY_BUNDLE_TAG) as string; |
| 122 | registration.UpgradeCodes = idKey.GetValue(BURN_REGISTRATION_REGISTRY_BUNDLE_UPGRADE_CODE) as string[]; | 65 | registration.UpgradeCodes = idKey.GetValue(BURN_REGISTRATION_REGISTRY_BUNDLE_UPGRADE_CODE) as string[]; |
| 123 | registration.Version = idKey.GetValue(BURN_REGISTRATION_REGISTRY_BUNDLE_VERSION) as string; | 66 | registration.BundleVersion = idKey.GetValue(BURN_REGISTRATION_REGISTRY_BUNDLE_VERSION) as string; |
| 124 | registration.DisplayName = idKey.GetValue(BURN_REGISTRATION_REGISTRY_BUNDLE_DISPLAY_NAME) as string; | ||
| 125 | registration.EngineVersion = idKey.GetValue(BURN_REGISTRATION_REGISTRY_ENGINE_VERSION) as string; | 67 | registration.EngineVersion = idKey.GetValue(BURN_REGISTRATION_REGISTRY_ENGINE_VERSION) as string; |
| 126 | registration.EstimatedSize = idKey.GetValue(REGISTRY_BUNDLE_ESTIMATED_SIZE) as int?; | ||
| 127 | registration.Installed = idKey.GetValue(REGISTRY_BUNDLE_INSTALLED) as int?; | ||
| 128 | registration.ModifyPath = idKey.GetValue(REGISTRY_BUNDLE_MODIFY_PATH) as string; | ||
| 129 | registration.Publisher = idKey.GetValue(REGISTRY_BUNDLE_PUBLISHER) as string; | ||
| 130 | registration.SystemComponent = idKey.GetValue(REGISTRY_BUNDLE_SYSTEM_COMPONENT) as int?; | ||
| 131 | registration.UrlInfoAbout = idKey.GetValue(REGISTRY_BUNDLE_URL_INFO_ABOUT) as string; | ||
| 132 | registration.UrlUpdateInfo = idKey.GetValue(REGISTRY_BUNDLE_URL_UPDATE_INFO) as string; | ||
| 133 | |||
| 134 | registration.QuietUninstallString = idKey.GetValue(REGISTRY_BUNDLE_QUIET_UNINSTALL_STRING) as string; | ||
| 135 | if (!String.IsNullOrEmpty(registration.QuietUninstallString)) | ||
| 136 | { | ||
| 137 | var closeQuote = registration.QuietUninstallString.IndexOf("\"", 1); | ||
| 138 | if (closeQuote > 0) | ||
| 139 | { | ||
| 140 | registration.QuietUninstallCommand = registration.QuietUninstallString.Substring(1, closeQuote - 1).Trim(); | ||
| 141 | registration.QuietUninstallCommandArguments = registration.QuietUninstallString.Substring(closeQuote + 1).Trim(); | ||
| 142 | } | ||
| 143 | } | ||
| 144 | |||
| 145 | registration.UninstallString = idKey.GetValue(REGISTRY_BUNDLE_UNINSTALL_STRING) as string; | ||
| 146 | if (!String.IsNullOrEmpty(registration.UninstallString)) | ||
| 147 | { | ||
| 148 | var closeQuote = registration.UninstallString.IndexOf("\"", 1); | ||
| 149 | if (closeQuote > 0) | ||
| 150 | { | ||
| 151 | registration.UninstallCommand = registration.UninstallString.Substring(1, closeQuote - 1).Trim(); | ||
| 152 | registration.UninstallCommandArguments = registration.UninstallString.Substring(closeQuote + 1).Trim(); | ||
| 153 | } | ||
| 154 | } | ||
| 155 | 68 | ||
| 156 | return registration; | 69 | return registration; |
| 157 | } | 70 | } |
diff --git a/src/test/burn/WixTestTools/BundleVerifier.cs b/src/test/burn/WixTestTools/BundleVerifier.cs index 103171cd..ff45a291 100644 --- a/src/test/burn/WixTestTools/BundleVerifier.cs +++ b/src/test/burn/WixTestTools/BundleVerifier.cs | |||
| @@ -80,6 +80,29 @@ namespace WixTestTools | |||
| 80 | File.Delete(expectedCachePath); | 80 | File.Delete(expectedCachePath); |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | public bool TryGetArpEntryExePackageConfiguration(string packageId, out string arpId, out string arpVersion, out bool arpWin64, out bool perMachine) | ||
| 84 | { | ||
| 85 | using var wixOutput = WixOutput.Read(this.BundlePdb); | ||
| 86 | var intermediate = Intermediate.Load(wixOutput); | ||
| 87 | var section = intermediate.Sections.Single(); | ||
| 88 | var packageSymbol = section.Symbols.OfType<WixBundlePackageSymbol>().SingleOrDefault(p => p.Id.Id == packageId); | ||
| 89 | var exePackageSymbol = section.Symbols.OfType<WixBundleExePackageSymbol>().SingleOrDefault(p => p.Id.Id == packageId); | ||
| 90 | if (packageSymbol == null || exePackageSymbol == null || exePackageSymbol.DetectionType != WixBundleExePackageDetectionType.Arp) | ||
| 91 | { | ||
| 92 | arpId = null; | ||
| 93 | arpVersion = null; | ||
| 94 | arpWin64 = false; | ||
| 95 | perMachine = false; | ||
| 96 | return false; | ||
| 97 | } | ||
| 98 | |||
| 99 | arpId = exePackageSymbol.ArpId; | ||
| 100 | arpVersion = exePackageSymbol.ArpDisplayVersion; | ||
| 101 | arpWin64 = exePackageSymbol.ArpWin64; | ||
| 102 | perMachine = packageSymbol.PerMachine == true; | ||
| 103 | return true; | ||
| 104 | } | ||
| 105 | |||
| 83 | public bool TryGetRegistration(out BundleRegistration registration) | 106 | public bool TryGetRegistration(out BundleRegistration registration) |
| 84 | { | 107 | { |
| 85 | var bundleSymbol = this.GetBundleSymbol(); | 108 | var bundleSymbol = this.GetBundleSymbol(); |
diff --git a/src/test/burn/WixTestTools/GenericArpRegistration.cs b/src/test/burn/WixTestTools/GenericArpRegistration.cs new file mode 100644 index 00000000..d87c4feb --- /dev/null +++ b/src/test/burn/WixTestTools/GenericArpRegistration.cs | |||
| @@ -0,0 +1,143 @@ | |||
| 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
| 2 | |||
| 3 | namespace WixTestTools | ||
| 4 | { | ||
| 5 | using System; | ||
| 6 | using Microsoft.Win32; | ||
| 7 | |||
| 8 | public class GenericArpRegistration | ||
| 9 | { | ||
| 10 | public const string UNINSTALL_KEY = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"; | ||
| 11 | public const string UNINSTALL_KEY_WOW6432NODE = "SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall"; | ||
| 12 | |||
| 13 | public const string REGISTRY_ARP_INSTALLED = "Installed"; | ||
| 14 | public const string REGISTRY_ARP_DISPLAY_ICON = "DisplayIcon"; | ||
| 15 | public const string REGISTRY_ARP_DISPLAY_NAME = "DisplayName"; | ||
| 16 | public const string REGISTRY_ARP_DISPLAY_VERSION = "DisplayVersion"; | ||
| 17 | public const string REGISTRY_ARP_ESTIMATED_SIZE = "EstimatedSize"; | ||
| 18 | public const string REGISTRY_ARP_PUBLISHER = "Publisher"; | ||
| 19 | public const string REGISTRY_ARP_HELP_LINK = "HelpLink"; | ||
| 20 | public const string REGISTRY_ARP_HELP_TELEPHONE = "HelpTelephone"; | ||
| 21 | public const string REGISTRY_ARP_URL_INFO_ABOUT = "URLInfoAbout"; | ||
| 22 | public const string REGISTRY_ARP_URL_UPDATE_INFO = "URLUpdateInfo"; | ||
| 23 | public const string REGISTRY_ARP_COMMENTS = "Comments"; | ||
| 24 | public const string REGISTRY_ARP_CONTACT = "Contact"; | ||
| 25 | public const string REGISTRY_ARP_NO_MODIFY = "NoModify"; | ||
| 26 | public const string REGISTRY_ARP_MODIFY_PATH = "ModifyPath"; | ||
| 27 | public const string REGISTRY_ARP_NO_ELEVATE_ON_MODIFY = "NoElevateOnModify"; | ||
| 28 | public const string REGISTRY_ARP_NO_REMOVE = "NoRemove"; | ||
| 29 | public const string REGISTRY_ARP_SYSTEM_COMPONENT = "SystemComponent"; | ||
| 30 | public const string REGISTRY_ARP_QUIET_UNINSTALL_STRING = "QuietUninstallString"; | ||
| 31 | public const string REGISTRY_ARP_UNINSTALL_STRING = "UninstallString"; | ||
| 32 | public const string REGISTRY_ARP_VERSION_MAJOR = "VersionMajor"; | ||
| 33 | public const string REGISTRY_ARP_VERSION_MINOR = "VersionMinor"; | ||
| 34 | |||
| 35 | public RegistryKey BaseKey { get; set; } | ||
| 36 | |||
| 37 | public string KeyPath { get; set; } | ||
| 38 | |||
| 39 | public string DisplayName { get; set; } | ||
| 40 | |||
| 41 | public string DisplayVersion { get; set; } | ||
| 42 | |||
| 43 | public int? EstimatedSize { get; set; } | ||
| 44 | |||
| 45 | public int? Installed { get; set; } | ||
| 46 | |||
| 47 | public string ModifyPath { get; set; } | ||
| 48 | |||
| 49 | public string Publisher { get; set; } | ||
| 50 | |||
| 51 | public int? SystemComponent { get; set; } | ||
| 52 | |||
| 53 | public string QuietUninstallString { get; set; } | ||
| 54 | |||
| 55 | public string QuietUninstallCommand { get; set; } | ||
| 56 | |||
| 57 | public string QuietUninstallCommandArguments { get; set; } | ||
| 58 | |||
| 59 | public string UninstallCommand { get; set; } | ||
| 60 | |||
| 61 | public string UninstallCommandArguments { get; set; } | ||
| 62 | |||
| 63 | public string UninstallString { get; set; } | ||
| 64 | |||
| 65 | public string UrlInfoAbout { get; set; } | ||
| 66 | |||
| 67 | public string UrlUpdateInfo { get; set; } | ||
| 68 | |||
| 69 | public static bool TryGetPerMachineRegistrationById(string id, bool x64, out GenericArpRegistration registration) | ||
| 70 | { | ||
| 71 | return TryGetRegistrationById(id, x64, false, out registration); | ||
| 72 | } | ||
| 73 | |||
| 74 | public static bool TryGetPerUserRegistrationById(string id, out GenericArpRegistration registration) | ||
| 75 | { | ||
| 76 | return TryGetRegistrationById(id, true, true, out registration); | ||
| 77 | } | ||
| 78 | |||
| 79 | private static bool TryGetRegistrationById(string id, bool x64, bool perUser, out GenericArpRegistration registration) | ||
| 80 | { | ||
| 81 | registration = GetGenericArpRegistration(id, x64, perUser, key => new GenericArpRegistration()); | ||
| 82 | return registration != null; | ||
| 83 | } | ||
| 84 | |||
| 85 | protected static T GetGenericArpRegistration<T>(string id, bool x64, bool perUser, Func<RegistryKey, T> fnCreate) | ||
| 86 | where T : GenericArpRegistration | ||
| 87 | { | ||
| 88 | var baseKey = perUser ? Registry.CurrentUser : Registry.LocalMachine; | ||
| 89 | var baseKeyPath = x64 ? UNINSTALL_KEY : UNINSTALL_KEY_WOW6432NODE; | ||
| 90 | var registrationKeyPath = $"{baseKeyPath}\\{id}"; | ||
| 91 | using var idKey = baseKey.OpenSubKey(registrationKeyPath); | ||
| 92 | |||
| 93 | if (idKey == null) | ||
| 94 | { | ||
| 95 | return null; | ||
| 96 | } | ||
| 97 | |||
| 98 | var registration = fnCreate(idKey); | ||
| 99 | |||
| 100 | registration.BaseKey = baseKey; | ||
| 101 | registration.KeyPath = registrationKeyPath; | ||
| 102 | |||
| 103 | registration.DisplayName = idKey.GetValue(REGISTRY_ARP_DISPLAY_NAME) as string; | ||
| 104 | registration.DisplayVersion = idKey.GetValue(REGISTRY_ARP_DISPLAY_VERSION) as string; | ||
| 105 | registration.EstimatedSize = idKey.GetValue(REGISTRY_ARP_ESTIMATED_SIZE) as int?; | ||
| 106 | registration.Installed = idKey.GetValue(REGISTRY_ARP_INSTALLED) as int?; | ||
| 107 | registration.ModifyPath = idKey.GetValue(REGISTRY_ARP_MODIFY_PATH) as string; | ||
| 108 | registration.Publisher = idKey.GetValue(REGISTRY_ARP_PUBLISHER) as string; | ||
| 109 | registration.SystemComponent = idKey.GetValue(REGISTRY_ARP_SYSTEM_COMPONENT) as int?; | ||
| 110 | registration.UrlInfoAbout = idKey.GetValue(REGISTRY_ARP_URL_INFO_ABOUT) as string; | ||
| 111 | registration.UrlUpdateInfo = idKey.GetValue(REGISTRY_ARP_URL_UPDATE_INFO) as string; | ||
| 112 | |||
| 113 | registration.QuietUninstallString = idKey.GetValue(REGISTRY_ARP_QUIET_UNINSTALL_STRING) as string; | ||
| 114 | if (!String.IsNullOrEmpty(registration.QuietUninstallString)) | ||
| 115 | { | ||
| 116 | var closeQuote = registration.QuietUninstallString.IndexOf("\"", 1); | ||
| 117 | if (closeQuote > 0) | ||
| 118 | { | ||
| 119 | registration.QuietUninstallCommand = registration.QuietUninstallString.Substring(1, closeQuote - 1).Trim(); | ||
| 120 | registration.QuietUninstallCommandArguments = registration.QuietUninstallString.Substring(closeQuote + 1).Trim(); | ||
| 121 | } | ||
| 122 | } | ||
| 123 | |||
| 124 | registration.UninstallString = idKey.GetValue(REGISTRY_ARP_UNINSTALL_STRING) as string; | ||
| 125 | if (!String.IsNullOrEmpty(registration.UninstallString)) | ||
| 126 | { | ||
| 127 | var closeQuote = registration.UninstallString.IndexOf("\"", 1); | ||
| 128 | if (closeQuote > 0) | ||
| 129 | { | ||
| 130 | registration.UninstallCommand = registration.UninstallString.Substring(1, closeQuote - 1).Trim(); | ||
| 131 | registration.UninstallCommandArguments = registration.UninstallString.Substring(closeQuote + 1).Trim(); | ||
| 132 | } | ||
| 133 | } | ||
| 134 | |||
| 135 | return registration; | ||
| 136 | } | ||
| 137 | |||
| 138 | public void Delete() | ||
| 139 | { | ||
| 140 | this.BaseKey.DeleteSubKeyTree(this.KeyPath); | ||
| 141 | } | ||
| 142 | } | ||
| 143 | } | ||
