From ae7e9817bb10d635e031e51496f2e529595a9cfe Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Sun, 11 Apr 2021 12:23:19 -0700 Subject: Add RemoveRegistryKey --- src/wixext/Symbols/UtilSymbolDefinitions.cs | 4 + src/wixext/Symbols/WixRemoveRegistryKeyExSymbol.cs | 86 +++++++++++++++++ src/wixext/UtilCompiler.cs | 103 +++++++++++++++++++-- src/wixext/UtilTableDefinitions.cs | 16 ++++ 4 files changed, 203 insertions(+), 6 deletions(-) create mode 100644 src/wixext/Symbols/WixRemoveRegistryKeyExSymbol.cs (limited to 'src/wixext') diff --git a/src/wixext/Symbols/UtilSymbolDefinitions.cs b/src/wixext/Symbols/UtilSymbolDefinitions.cs index 5f062676..72091c3b 100644 --- a/src/wixext/Symbols/UtilSymbolDefinitions.cs +++ b/src/wixext/Symbols/UtilSymbolDefinitions.cs @@ -23,6 +23,7 @@ namespace WixToolset.Util WixFormatFiles, WixInternetShortcut, WixRemoveFolderEx, + WixRemoveRegistryKeyEx, WixRestartResource, WixTouchFile, WixWindowsFeatureSearch, @@ -93,6 +94,9 @@ namespace WixToolset.Util case UtilSymbolDefinitionType.WixRemoveFolderEx: return UtilSymbolDefinitions.WixRemoveFolderEx; + case UtilSymbolDefinitionType.WixRemoveRegistryKeyEx: + return UtilSymbolDefinitions.WixRemoveRegistryKeyEx; + case UtilSymbolDefinitionType.WixRestartResource: return UtilSymbolDefinitions.WixRestartResource; diff --git a/src/wixext/Symbols/WixRemoveRegistryKeyExSymbol.cs b/src/wixext/Symbols/WixRemoveRegistryKeyExSymbol.cs new file mode 100644 index 00000000..8e4bd212 --- /dev/null +++ b/src/wixext/Symbols/WixRemoveRegistryKeyExSymbol.cs @@ -0,0 +1,86 @@ +// 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. + +namespace WixToolset.Util +{ + using WixToolset.Data; + using WixToolset.Util.Symbols; + + public static partial class UtilSymbolDefinitions + { + public static readonly IntermediateSymbolDefinition WixRemoveRegistryKeyEx = new IntermediateSymbolDefinition( + UtilSymbolDefinitionType.WixRemoveRegistryKeyEx.ToString(), + new[] + { + new IntermediateFieldDefinition(nameof(WixRemoveRegistryKeyExSymbolFields.ComponentRef), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(WixRemoveRegistryKeyExSymbolFields.Root), IntermediateFieldType.Number), + new IntermediateFieldDefinition(nameof(WixRemoveRegistryKeyExSymbolFields.Key), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(WixRemoveRegistryKeyExSymbolFields.InstallMode), IntermediateFieldType.Number), + new IntermediateFieldDefinition(nameof(WixRemoveRegistryKeyExSymbolFields.Condition), IntermediateFieldType.String), + }, + typeof(WixRemoveRegistryKeyExSymbol)); + } +} + +namespace WixToolset.Util.Symbols +{ + using WixToolset.Data; + using WixToolset.Data.Symbols; + + public enum WixRemoveRegistryKeyExSymbolFields + { + ComponentRef, + Root, + Key, + InstallMode, + Condition, + } + + public enum WixRemoveRegistryKeyExInstallMode + { + Install = 1, + Uninstall = 2, + } + + public class WixRemoveRegistryKeyExSymbol : IntermediateSymbol + { + public WixRemoveRegistryKeyExSymbol() : base(UtilSymbolDefinitions.WixRemoveRegistryKeyEx, null, null) + { + } + + public WixRemoveRegistryKeyExSymbol(SourceLineNumber sourceLineNumber, Identifier id = null) : base(UtilSymbolDefinitions.WixRemoveRegistryKeyEx, sourceLineNumber, id) + { + } + + public IntermediateField this[WixRemoveRegistryKeyExSymbolFields index] => this.Fields[(int)index]; + + public string ComponentRef + { + get => this.Fields[(int)WixRemoveRegistryKeyExSymbolFields.ComponentRef].AsString(); + set => this.Set((int)WixRemoveRegistryKeyExSymbolFields.ComponentRef, value); + } + + public RegistryRootType Root + { + get => (RegistryRootType)this.Fields[(int)WixRemoveRegistryKeyExSymbolFields.Root].AsNumber(); + set => this.Set((int)WixRemoveRegistryKeyExSymbolFields.Root, (int)value); + } + + public string Key + { + get => (string)this.Fields[(int)WixRemoveRegistryKeyExSymbolFields.Key]; + set => this.Set((int)WixRemoveRegistryKeyExSymbolFields.Key, value); + } + + public WixRemoveRegistryKeyExInstallMode InstallMode + { + get => (WixRemoveRegistryKeyExInstallMode)this.Fields[(int)WixRemoveRegistryKeyExSymbolFields.InstallMode].AsNumber(); + set => this.Set((int)WixRemoveRegistryKeyExSymbolFields.InstallMode, (int)value); + } + + public string Condition + { + get => this.Fields[(int)WixRemoveRegistryKeyExSymbolFields.Condition].AsString(); + set => this.Set((int)WixRemoveRegistryKeyExSymbolFields.Condition, value); + } + } +} diff --git a/src/wixext/UtilCompiler.cs b/src/wixext/UtilCompiler.cs index 63f2b469..45079150 100644 --- a/src/wixext/UtilCompiler.cs +++ b/src/wixext/UtilCompiler.cs @@ -35,12 +35,6 @@ namespace WixToolset.Util internal const int UserDontCreateUser = 0x00000200; internal const int UserNonVital = 0x00000400; - internal enum WixRegistrySearchFormat - { - Raw, - Compatible, - } - private static readonly Regex FindPropertyBrackets = new Regex(@"\[(?!\\|\])|(? "http://wixtoolset.org/schemas/v4/wxs/util"; @@ -135,6 +129,9 @@ namespace WixToolset.Util case "RemoveFolderEx": this.ParseRemoveFolderExElement(intermediate, section, element, componentId); break; + case "RemoveRegistryKey": + this.ParseRemoveRegistryKeyExElement(intermediate, section, element, componentId); + break; case "RestartResource": this.ParseRestartResourceElement(intermediate, section, element, componentId); break; @@ -2887,6 +2884,100 @@ namespace WixToolset.Util } } + /// + /// Parses a RemoveRegistryKeyEx element. + /// + /// Element to parse. + /// Identifier of parent component. + private void ParseRemoveRegistryKeyExElement(Intermediate intermediate, IntermediateSection section, XElement element, string componentId) + { + var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element); + Identifier id = null; + var mode = WixRemoveRegistryKeyExInstallMode.Uninstall; + string condition = null; + RegistryRootType? root = null; + string key = null; + + foreach (var attrib in element.Attributes()) + { + if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace) + { + switch (attrib.Name.LocalName) + { + case "Condition": + condition = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); + break; + case "Id": + id = this.ParseHelper.GetAttributeIdentifier(sourceLineNumbers, attrib); + break; + case "On": + var actionValue = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); + switch (actionValue) + { + case "": + break; + case "install": + mode = WixRemoveRegistryKeyExInstallMode.Install; + break; + case "uninstall": + mode = WixRemoveRegistryKeyExInstallMode.Uninstall; + break; + default: + this.Messaging.Write(ErrorMessages.IllegalAttributeValue(sourceLineNumbers, element.Name.LocalName, "On", actionValue, "install", "uninstall")); + break; + } + break; + case "Root": + root = this.ParseHelper.GetAttributeRegistryRootValue(sourceLineNumbers, attrib, false); + break; + case "Key": + key = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); + break; + default: + this.ParseHelper.UnexpectedAttribute(element, attrib); + break; + } + } + else + { + this.ParseHelper.ParseExtensionAttribute(this.Context.Extensions, intermediate, section, element, attrib); + } + } + + if (!root.HasValue) + { + this.Messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, element.Name.LocalName, "Root")); + } + + if (key == null) + { + this.Messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, element.Name.LocalName, "Key")); + } + + if (id == null) + { + id = this.ParseHelper.CreateIdentifier("rrx", componentId, condition, root.ToString(), key, mode.ToString()); + } + + this.ParseHelper.ParseForExtensionElements(this.Context.Extensions, intermediate, section, element); + + if (!this.Messaging.EncounteredError) + { + this.ParseHelper.EnsureTable(section, sourceLineNumbers, "Registry"); + this.ParseHelper.EnsureTable(section, sourceLineNumbers, "RemoveRegistry"); + this.ParseHelper.CreateCustomActionReference(sourceLineNumbers, section, "Wix4RemoveRegistryKeysEx", this.Context.Platform, CustomActionPlatforms.X86 | CustomActionPlatforms.X64 | CustomActionPlatforms.ARM64); + + section.AddSymbol(new WixRemoveRegistryKeyExSymbol(sourceLineNumbers, id) + { + ComponentRef = componentId, + Root = root.Value, + Key = key, + InstallMode = mode, + Condition = condition + }); + } + } + /// /// Parses a RestartResource element. /// diff --git a/src/wixext/UtilTableDefinitions.cs b/src/wixext/UtilTableDefinitions.cs index fd09367a..12f423cc 100644 --- a/src/wixext/UtilTableDefinitions.cs +++ b/src/wixext/UtilTableDefinitions.cs @@ -38,6 +38,21 @@ namespace WixToolset.Util symbolIdIsPrimaryKey: true ); + public static readonly TableDefinition Wix4RemoveRegistryKeyEx = new TableDefinition( + "Wix4RemoveRegistryKeyEx", + UtilSymbolDefinitions.WixRemoveRegistryKeyEx, + new[] + { + new ColumnDefinition("Wix4RemoveRegistryKeyEx", ColumnType.String, 72, primaryKey: true, nullable: false, ColumnCategory.Identifier, description: "Identifier for the Wix4RemoveRegistryKeyEx row in the package.", modularizeType: ColumnModularizeType.Column), + new ColumnDefinition("Component_", ColumnType.String, 72, primaryKey: false, nullable: false, ColumnCategory.Identifier, keyTable: "Component", keyColumn: 1, description: "Foreign key into the Component table used to determine install state", modularizeType: ColumnModularizeType.Column), + new ColumnDefinition("Root", ColumnType.Number, 2, primaryKey: false, nullable: false, ColumnCategory.Unknown, minValue: -1, maxValue: 3, description: "The predefined root key for the registry value, one of rrkEnum."), + new ColumnDefinition("Key", ColumnType.Localized, 255, primaryKey: false, nullable: false, ColumnCategory.RegPath, description: "The key for the registry value.", modularizeType: ColumnModularizeType.Property), + new ColumnDefinition("InstallMode", ColumnType.Number, 2, primaryKey: false, nullable: false, ColumnCategory.Unknown, minValue: 1, maxValue: 3, description: "1 == Remove only when the associated component is being installed (msiInstallStateLocal or msiInstallStateSource), 2 == Remove only when the associated component is being removed (msiInstallStateAbsent), 3 = Remove in either of the above cases."), + new ColumnDefinition("Condition", ColumnType.String, 0, primaryKey: false, nullable: true, ColumnCategory.Condition, description: "Optional expression to control whether the registry key is removed.", modularizeType: ColumnModularizeType.Condition, forceLocalizable: true), + }, + symbolIdIsPrimaryKey: true + ); + public static readonly TableDefinition Wix4RestartResource = new TableDefinition( "Wix4RestartResource", UtilSymbolDefinitions.WixRestartResource, @@ -281,6 +296,7 @@ namespace WixToolset.Util { Wix4CloseApplication, Wix4RemoveFolderEx, + Wix4RemoveRegistryKeyEx, Wix4RestartResource, Wix4FileShare, Wix4FileSharePermissions, -- cgit v1.2.3-55-g6feb