diff options
Diffstat (limited to 'src/WixToolset.Converters.Tupleizer/ConvertTuplesCommand.cs')
| -rw-r--r-- | src/WixToolset.Converters.Tupleizer/ConvertTuplesCommand.cs | 609 |
1 files changed, 609 insertions, 0 deletions
diff --git a/src/WixToolset.Converters.Tupleizer/ConvertTuplesCommand.cs b/src/WixToolset.Converters.Tupleizer/ConvertTuplesCommand.cs new file mode 100644 index 00000000..c07dd42e --- /dev/null +++ b/src/WixToolset.Converters.Tupleizer/ConvertTuplesCommand.cs | |||
| @@ -0,0 +1,609 @@ | |||
| 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 WixToolset.Converters.Tupleizer | ||
| 4 | { | ||
| 5 | using System; | ||
| 6 | using System.Linq; | ||
| 7 | using WixToolset.Data; | ||
| 8 | using WixToolset.Data.Tuples; | ||
| 9 | using WixToolset.Data.WindowsInstaller; | ||
| 10 | using Wix3 = Microsoft.Tools.WindowsInstallerXml; | ||
| 11 | |||
| 12 | public class ConvertTuplesCommand | ||
| 13 | { | ||
| 14 | public Intermediate Execute(string path) | ||
| 15 | { | ||
| 16 | var output = Wix3.Output.Load(path, suppressVersionCheck: true, suppressSchema: true); | ||
| 17 | return this.Execute(output); | ||
| 18 | } | ||
| 19 | |||
| 20 | public Intermediate Execute(Wix3.Output output) | ||
| 21 | { | ||
| 22 | var section = new IntermediateSection(String.Empty, OutputType3ToSectionType4(output.Type), output.Codepage); | ||
| 23 | |||
| 24 | foreach (Wix3.Table table in output.Tables) | ||
| 25 | { | ||
| 26 | foreach (Wix3.Row row in table.Rows) | ||
| 27 | { | ||
| 28 | var tuple = GenerateTupleFromRow(row); | ||
| 29 | if (tuple != null) | ||
| 30 | { | ||
| 31 | section.Tuples.Add(tuple); | ||
| 32 | } | ||
| 33 | } | ||
| 34 | } | ||
| 35 | |||
| 36 | return new Intermediate(String.Empty, new[] { section }, localizationsByCulture: null, embedFilePaths: null); | ||
| 37 | } | ||
| 38 | |||
| 39 | private static IntermediateTuple GenerateTupleFromRow(Wix3.Row row) | ||
| 40 | { | ||
| 41 | var name = row.Table.Name; | ||
| 42 | switch (name) | ||
| 43 | { | ||
| 44 | case "_SummaryInformation": | ||
| 45 | return DefaultTupleFromRow(typeof(_SummaryInformationTuple), row, columnZeroIsId: false); | ||
| 46 | case "ActionText": | ||
| 47 | return DefaultTupleFromRow(typeof(ActionTextTuple), row, columnZeroIsId: false); | ||
| 48 | case "AdvtExecuteSequence": | ||
| 49 | return DefaultTupleFromRow(typeof(AdvtExecuteSequenceTuple), row, columnZeroIsId: false); | ||
| 50 | case "AppId": | ||
| 51 | return DefaultTupleFromRow(typeof(AppIdTuple), row, columnZeroIsId: false); | ||
| 52 | case "AppSearch": | ||
| 53 | return DefaultTupleFromRow(typeof(AppSearchTuple), row, columnZeroIsId: false); | ||
| 54 | case "Binary": | ||
| 55 | return DefaultTupleFromRow(typeof(BinaryTuple), row, columnZeroIsId: false); | ||
| 56 | case "Class": | ||
| 57 | return DefaultTupleFromRow(typeof(ClassTuple), row, columnZeroIsId: false); | ||
| 58 | case "CompLocator": | ||
| 59 | return DefaultTupleFromRow(typeof(CompLocatorTuple), row, columnZeroIsId: true); | ||
| 60 | case "Component": | ||
| 61 | { | ||
| 62 | var attributes = FieldAsNullableInt(row, 3); | ||
| 63 | |||
| 64 | var location = ComponentLocation.LocalOnly; | ||
| 65 | if ((attributes & WindowsInstallerConstants.MsidbComponentAttributesSourceOnly) == WindowsInstallerConstants.MsidbComponentAttributesSourceOnly) | ||
| 66 | { | ||
| 67 | location = ComponentLocation.SourceOnly; | ||
| 68 | } | ||
| 69 | else if ((attributes & WindowsInstallerConstants.MsidbComponentAttributesOptional) == WindowsInstallerConstants.MsidbComponentAttributesOptional) | ||
| 70 | { | ||
| 71 | location = ComponentLocation.Either; | ||
| 72 | } | ||
| 73 | |||
| 74 | var keyPathType = ComponentKeyPathType.File; | ||
| 75 | if ((attributes & WindowsInstallerConstants.MsidbComponentAttributesRegistryKeyPath) == WindowsInstallerConstants.MsidbComponentAttributesRegistryKeyPath) | ||
| 76 | { | ||
| 77 | keyPathType = ComponentKeyPathType.Registry; | ||
| 78 | } | ||
| 79 | else if ((attributes & WindowsInstallerConstants.MsidbComponentAttributesODBCDataSource) == WindowsInstallerConstants.MsidbComponentAttributesODBCDataSource) | ||
| 80 | { | ||
| 81 | keyPathType = ComponentKeyPathType.OdbcDataSource; | ||
| 82 | } | ||
| 83 | |||
| 84 | return new ComponentTuple(SourceLineNumber4(row.SourceLineNumbers), new Identifier(AccessModifier.Public, FieldAsString(row, 0))) | ||
| 85 | { | ||
| 86 | ComponentId = FieldAsString(row, 1), | ||
| 87 | Directory_ = FieldAsString(row, 2), | ||
| 88 | Condition = FieldAsString(row, 4), | ||
| 89 | KeyPath = FieldAsString(row, 5), | ||
| 90 | Location = location, | ||
| 91 | DisableRegistryReflection = (attributes & WindowsInstallerConstants.MsidbComponentAttributesDisableRegistryReflection) == WindowsInstallerConstants.MsidbComponentAttributesDisableRegistryReflection, | ||
| 92 | NeverOverwrite = (attributes & WindowsInstallerConstants.MsidbComponentAttributesNeverOverwrite) == WindowsInstallerConstants.MsidbComponentAttributesNeverOverwrite, | ||
| 93 | Permanent = (attributes & WindowsInstallerConstants.MsidbComponentAttributesPermanent) == WindowsInstallerConstants.MsidbComponentAttributesPermanent, | ||
| 94 | SharedDllRefCount = (attributes & WindowsInstallerConstants.MsidbComponentAttributesSharedDllRefCount) == WindowsInstallerConstants.MsidbComponentAttributesSharedDllRefCount, | ||
| 95 | Shared = (attributes & WindowsInstallerConstants.MsidbComponentAttributesShared) == WindowsInstallerConstants.MsidbComponentAttributesShared, | ||
| 96 | Transitive = (attributes & WindowsInstallerConstants.MsidbComponentAttributesTransitive) == WindowsInstallerConstants.MsidbComponentAttributesTransitive, | ||
| 97 | UninstallWhenSuperseded = (attributes & WindowsInstallerConstants.MsidbComponentAttributesUninstallOnSupersedence) == WindowsInstallerConstants.MsidbComponentAttributesUninstallOnSupersedence, | ||
| 98 | Win64 = (attributes & WindowsInstallerConstants.MsidbComponentAttributes64bit) == WindowsInstallerConstants.MsidbComponentAttributes64bit, | ||
| 99 | KeyPathType = keyPathType, | ||
| 100 | }; | ||
| 101 | } | ||
| 102 | |||
| 103 | case "Condition": | ||
| 104 | return DefaultTupleFromRow(typeof(ConditionTuple), row, columnZeroIsId: false); | ||
| 105 | case "CreateFolder": | ||
| 106 | return DefaultTupleFromRow(typeof(CreateFolderTuple), row, columnZeroIsId: false); | ||
| 107 | case "CustomAction": | ||
| 108 | { | ||
| 109 | var caType = FieldAsInt(row, 1); | ||
| 110 | var executionType = DetermineCustomActionExecutionType(caType); | ||
| 111 | var sourceType = DetermineCustomActionSourceType(caType); | ||
| 112 | var targetType = DetermineCustomActionTargetType(caType); | ||
| 113 | |||
| 114 | return new CustomActionTuple(SourceLineNumber4(row.SourceLineNumbers), new Identifier(AccessModifier.Public, FieldAsString(row, 0))) | ||
| 115 | { | ||
| 116 | ExecutionType = executionType, | ||
| 117 | SourceType = sourceType, | ||
| 118 | Source = FieldAsString(row, 2), | ||
| 119 | TargetType = targetType, | ||
| 120 | Target = FieldAsString(row, 3), | ||
| 121 | Win64 = (caType & WindowsInstallerConstants.MsidbCustomActionType64BitScript) == WindowsInstallerConstants.MsidbCustomActionType64BitScript, | ||
| 122 | TSAware = (caType & WindowsInstallerConstants.MsidbCustomActionTypeTSAware) == WindowsInstallerConstants.MsidbCustomActionTypeTSAware, | ||
| 123 | Impersonate = (caType & WindowsInstallerConstants.MsidbCustomActionTypeNoImpersonate) != WindowsInstallerConstants.MsidbCustomActionTypeNoImpersonate, | ||
| 124 | IgnoreResult = (caType & WindowsInstallerConstants.MsidbCustomActionTypeContinue) == WindowsInstallerConstants.MsidbCustomActionTypeContinue, | ||
| 125 | Hidden = (caType & WindowsInstallerConstants.MsidbCustomActionTypeHideTarget) == WindowsInstallerConstants.MsidbCustomActionTypeHideTarget, | ||
| 126 | Async = (caType & WindowsInstallerConstants.MsidbCustomActionTypeAsync) == WindowsInstallerConstants.MsidbCustomActionTypeAsync, | ||
| 127 | }; | ||
| 128 | } | ||
| 129 | |||
| 130 | case "Directory": | ||
| 131 | return DefaultTupleFromRow(typeof(DirectoryTuple), row, columnZeroIsId: false); | ||
| 132 | case "DrLocator": | ||
| 133 | return DefaultTupleFromRow(typeof(DrLocatorTuple), row, columnZeroIsId: false); | ||
| 134 | case "Error": | ||
| 135 | return DefaultTupleFromRow(typeof(ErrorTuple), row, columnZeroIsId: false); | ||
| 136 | case "Extension": | ||
| 137 | return DefaultTupleFromRow(typeof(ExtensionTuple), row, columnZeroIsId: false); | ||
| 138 | case "Feature": | ||
| 139 | { | ||
| 140 | int attributes = FieldAsInt(row, 7); | ||
| 141 | var installDefault = FeatureInstallDefault.Local; | ||
| 142 | if ((attributes & WindowsInstallerConstants.MsidbFeatureAttributesFollowParent) == WindowsInstallerConstants.MsidbFeatureAttributesFollowParent) | ||
| 143 | { | ||
| 144 | installDefault = FeatureInstallDefault.FollowParent; | ||
| 145 | } | ||
| 146 | else | ||
| 147 | if ((attributes & WindowsInstallerConstants.MsidbFeatureAttributesFavorSource) == WindowsInstallerConstants.MsidbFeatureAttributesFavorSource) | ||
| 148 | { | ||
| 149 | installDefault = FeatureInstallDefault.Source; | ||
| 150 | } | ||
| 151 | |||
| 152 | return new FeatureTuple(SourceLineNumber4(row.SourceLineNumbers), new Identifier(AccessModifier.Public, FieldAsString(row, 0))) | ||
| 153 | { | ||
| 154 | Feature_Parent = FieldAsString(row, 1), | ||
| 155 | Title = FieldAsString(row, 2), | ||
| 156 | Description = FieldAsString(row, 3), | ||
| 157 | Display = FieldAsInt(row, 4), // BUGBUGBUG: FieldAsNullableInt(row, 4), | ||
| 158 | Level = FieldAsInt(row, 5), | ||
| 159 | Directory_ = FieldAsString(row, 6), | ||
| 160 | DisallowAbsent = (attributes & WindowsInstallerConstants.MsidbFeatureAttributesUIDisallowAbsent) == WindowsInstallerConstants.MsidbFeatureAttributesUIDisallowAbsent, | ||
| 161 | DisallowAdvertise = (attributes & WindowsInstallerConstants.MsidbFeatureAttributesDisallowAdvertise) == WindowsInstallerConstants.MsidbFeatureAttributesDisallowAdvertise, | ||
| 162 | InstallDefault = installDefault, | ||
| 163 | TypicalDefault = (attributes & WindowsInstallerConstants.MsidbFeatureAttributesFavorAdvertise) == WindowsInstallerConstants.MsidbFeatureAttributesFavorAdvertise ? FeatureTypicalDefault.Advertise : FeatureTypicalDefault.Install, | ||
| 164 | }; | ||
| 165 | } | ||
| 166 | |||
| 167 | case "FeatureComponents": | ||
| 168 | return DefaultTupleFromRow(typeof(FeatureComponentsTuple), row, columnZeroIsId: false); | ||
| 169 | case "File": | ||
| 170 | { | ||
| 171 | var attributes = FieldAsNullableInt(row, 6); | ||
| 172 | var readOnly = (attributes & WindowsInstallerConstants.MsidbFileAttributesReadOnly) == WindowsInstallerConstants.MsidbFileAttributesReadOnly; | ||
| 173 | var hidden = (attributes & WindowsInstallerConstants.MsidbFileAttributesHidden) == WindowsInstallerConstants.MsidbFileAttributesHidden; | ||
| 174 | var system = (attributes & WindowsInstallerConstants.MsidbFileAttributesSystem) == WindowsInstallerConstants.MsidbFileAttributesSystem; | ||
| 175 | var vital = (attributes & WindowsInstallerConstants.MsidbFileAttributesVital) == WindowsInstallerConstants.MsidbFileAttributesVital; | ||
| 176 | var checksum = (attributes & WindowsInstallerConstants.MsidbFileAttributesChecksum) == WindowsInstallerConstants.MsidbFileAttributesChecksum; | ||
| 177 | bool? compressed = null; | ||
| 178 | if ((attributes & WindowsInstallerConstants.MsidbFileAttributesNoncompressed) == WindowsInstallerConstants.MsidbFileAttributesNoncompressed) | ||
| 179 | { | ||
| 180 | compressed = false; | ||
| 181 | } | ||
| 182 | else if ((attributes & WindowsInstallerConstants.MsidbFileAttributesCompressed) == WindowsInstallerConstants.MsidbFileAttributesCompressed) | ||
| 183 | { | ||
| 184 | compressed = true; | ||
| 185 | } | ||
| 186 | |||
| 187 | return new FileTuple(SourceLineNumber4(row.SourceLineNumbers), new Identifier(AccessModifier.Public, FieldAsString(row, 0))) | ||
| 188 | { | ||
| 189 | Component_ = FieldAsString(row, 1), | ||
| 190 | LongFileName = FieldAsString(row, 2), | ||
| 191 | FileSize = FieldAsInt(row, 3), | ||
| 192 | Version = FieldAsString(row, 4), | ||
| 193 | Language = FieldAsString(row, 5), | ||
| 194 | ReadOnly = readOnly, | ||
| 195 | Hidden = hidden, | ||
| 196 | System = system, | ||
| 197 | Vital = vital, | ||
| 198 | Checksum = checksum, | ||
| 199 | Compressed = compressed, | ||
| 200 | }; | ||
| 201 | } | ||
| 202 | |||
| 203 | case "Font": | ||
| 204 | return DefaultTupleFromRow(typeof(FontTuple), row, columnZeroIsId: false); | ||
| 205 | case "Icon": | ||
| 206 | return DefaultTupleFromRow(typeof(IconTuple), row, columnZeroIsId: false); | ||
| 207 | case "InstallExecuteSequence": | ||
| 208 | return DefaultTupleFromRow(typeof(InstallExecuteSequenceTuple), row, columnZeroIsId: false); | ||
| 209 | case "LockPermissions": | ||
| 210 | return DefaultTupleFromRow(typeof(LockPermissionsTuple), row, columnZeroIsId: false); | ||
| 211 | case "Media": | ||
| 212 | return DefaultTupleFromRow(typeof(MediaTuple), row, columnZeroIsId: false); | ||
| 213 | case "MIME": | ||
| 214 | return DefaultTupleFromRow(typeof(MIMETuple), row, columnZeroIsId: false); | ||
| 215 | case "MoveFile": | ||
| 216 | return DefaultTupleFromRow(typeof(MoveFileTuple), row, columnZeroIsId: false); | ||
| 217 | case "MsiAssembly": | ||
| 218 | return DefaultTupleFromRow(typeof(MsiAssemblyTuple), row, columnZeroIsId: false); | ||
| 219 | case "MsiShortcutProperty": | ||
| 220 | return DefaultTupleFromRow(typeof(MsiShortcutPropertyTuple), row, columnZeroIsId: false); | ||
| 221 | case "ProgId": | ||
| 222 | return DefaultTupleFromRow(typeof(ProgIdTuple), row, columnZeroIsId: false); | ||
| 223 | case "Property": | ||
| 224 | return DefaultTupleFromRow(typeof(PropertyTuple), row, columnZeroIsId: false); | ||
| 225 | case "PublishComponent": | ||
| 226 | return DefaultTupleFromRow(typeof(PublishComponentTuple), row, columnZeroIsId: false); | ||
| 227 | case "Registry": | ||
| 228 | { | ||
| 229 | var value = FieldAsString(row, 4); | ||
| 230 | var valueType = RegistryValueType.String; | ||
| 231 | var valueAction = RegistryValueActionType.Write; | ||
| 232 | |||
| 233 | if (!String.IsNullOrEmpty(value)) | ||
| 234 | { | ||
| 235 | if (value.StartsWith("#x", StringComparison.Ordinal)) | ||
| 236 | { | ||
| 237 | valueType = RegistryValueType.Binary; | ||
| 238 | value = value.Substring(2); | ||
| 239 | } | ||
| 240 | else if (value.StartsWith("#%", StringComparison.Ordinal)) | ||
| 241 | { | ||
| 242 | valueType = RegistryValueType.Expandable; | ||
| 243 | value = value.Substring(2); | ||
| 244 | } | ||
| 245 | else if (value.StartsWith("#", StringComparison.Ordinal)) | ||
| 246 | { | ||
| 247 | valueType = RegistryValueType.Integer; | ||
| 248 | value = value.Substring(1); | ||
| 249 | } | ||
| 250 | else if (value.StartsWith("[~]", StringComparison.Ordinal) && value.EndsWith("[~]", StringComparison.Ordinal)) | ||
| 251 | { | ||
| 252 | value = value.Substring(3, value.Length - 6); | ||
| 253 | valueType = RegistryValueType.MultiString; | ||
| 254 | valueAction = RegistryValueActionType.Write; | ||
| 255 | } | ||
| 256 | else if (value.StartsWith("[~]", StringComparison.Ordinal)) | ||
| 257 | { | ||
| 258 | value = value.Substring(3); | ||
| 259 | valueType = RegistryValueType.MultiString; | ||
| 260 | valueAction = RegistryValueActionType.Append; | ||
| 261 | } | ||
| 262 | else if (value.EndsWith("[~]", StringComparison.Ordinal)) | ||
| 263 | { | ||
| 264 | value = value.Substring(0, value.Length - 3); | ||
| 265 | valueType = RegistryValueType.MultiString; | ||
| 266 | valueAction = RegistryValueActionType.Prepend; | ||
| 267 | } | ||
| 268 | } | ||
| 269 | |||
| 270 | return new RegistryTuple(SourceLineNumber4(row.SourceLineNumbers), new Identifier(AccessModifier.Public, FieldAsString(row, 0))) | ||
| 271 | { | ||
| 272 | Root = (RegistryRootType)FieldAsInt(row, 1), | ||
| 273 | Key = FieldAsString(row, 2), | ||
| 274 | Name = FieldAsString(row, 3), | ||
| 275 | Value = value, | ||
| 276 | Component_ = FieldAsString(row, 5), | ||
| 277 | ValueAction = valueAction, | ||
| 278 | ValueType = valueType, | ||
| 279 | }; | ||
| 280 | } | ||
| 281 | |||
| 282 | case "RegLocator": | ||
| 283 | return DefaultTupleFromRow(typeof(RegLocatorTuple), row, columnZeroIsId: false); | ||
| 284 | case "RemoveFile": | ||
| 285 | return DefaultTupleFromRow(typeof(RemoveFileTuple), row, columnZeroIsId: false); | ||
| 286 | case "RemoveRegistry": | ||
| 287 | { | ||
| 288 | return new RemoveRegistryTuple(SourceLineNumber4(row.SourceLineNumbers), new Identifier(AccessModifier.Public, FieldAsString(row, 0))) | ||
| 289 | { | ||
| 290 | Action = RemoveRegistryActionType.RemoveOnInstall, | ||
| 291 | Root = (RegistryRootType)FieldAsInt(row, 1), | ||
| 292 | Key = FieldAsString(row, 2), | ||
| 293 | Name = FieldAsString(row, 3), | ||
| 294 | Component_ = FieldAsString(row, 4), | ||
| 295 | }; | ||
| 296 | } | ||
| 297 | |||
| 298 | case "ReserveCost": | ||
| 299 | return DefaultTupleFromRow(typeof(ReserveCostTuple), row, columnZeroIsId: false); | ||
| 300 | case "ServiceControl": | ||
| 301 | { | ||
| 302 | var events = FieldAsInt(row, 2); | ||
| 303 | var wait = FieldAsNullableInt(row, 4); | ||
| 304 | return new ServiceControlTuple(SourceLineNumber4(row.SourceLineNumbers), new Identifier(AccessModifier.Public, FieldAsString(row, 0))) | ||
| 305 | { | ||
| 306 | Name = FieldAsString(row, 1), | ||
| 307 | Arguments = FieldAsString(row, 3), | ||
| 308 | Wait = !wait.HasValue || wait.Value == 1, | ||
| 309 | Component_ = FieldAsString(row, 5), | ||
| 310 | InstallRemove = (events & WindowsInstallerConstants.MsidbServiceControlEventDelete) == WindowsInstallerConstants.MsidbServiceControlEventDelete, | ||
| 311 | UninstallRemove = (events & WindowsInstallerConstants.MsidbServiceControlEventUninstallDelete) == WindowsInstallerConstants.MsidbServiceControlEventUninstallDelete, | ||
| 312 | InstallStart = (events & WindowsInstallerConstants.MsidbServiceControlEventStart) == WindowsInstallerConstants.MsidbServiceControlEventStart, | ||
| 313 | UninstallStart = (events & WindowsInstallerConstants.MsidbServiceControlEventUninstallStart) == WindowsInstallerConstants.MsidbServiceControlEventUninstallStart, | ||
| 314 | InstallStop = (events & WindowsInstallerConstants.MsidbServiceControlEventStop) == WindowsInstallerConstants.MsidbServiceControlEventStop, | ||
| 315 | UninstallStop = (events & WindowsInstallerConstants.MsidbServiceControlEventUninstallStop) == WindowsInstallerConstants.MsidbServiceControlEventUninstallStop, | ||
| 316 | }; | ||
| 317 | } | ||
| 318 | |||
| 319 | case "ServiceInstall": | ||
| 320 | return DefaultTupleFromRow(typeof(ServiceInstallTuple), row, columnZeroIsId: true); | ||
| 321 | case "Shortcut": | ||
| 322 | return DefaultTupleFromRow(typeof(ShortcutTuple), row, columnZeroIsId: true); | ||
| 323 | case "Signature": | ||
| 324 | return DefaultTupleFromRow(typeof(SignatureTuple), row, columnZeroIsId: false); | ||
| 325 | case "Upgrade": | ||
| 326 | { | ||
| 327 | var attributes = FieldAsInt(row, 4); | ||
| 328 | return new UpgradeTuple(SourceLineNumber4(row.SourceLineNumbers), new Identifier(AccessModifier.Public, FieldAsString(row, 0))) | ||
| 329 | { | ||
| 330 | UpgradeCode = FieldAsString(row, 0), | ||
| 331 | VersionMin = FieldAsString(row, 1), | ||
| 332 | VersionMax = FieldAsString(row, 2), | ||
| 333 | Language = FieldAsString(row, 3), | ||
| 334 | Remove = FieldAsString(row, 5), | ||
| 335 | ActionProperty = FieldAsString(row, 6), | ||
| 336 | MigrateFeatures = (attributes & WindowsInstallerConstants.MsidbUpgradeAttributesMigrateFeatures) == WindowsInstallerConstants.MsidbUpgradeAttributesMigrateFeatures, | ||
| 337 | OnlyDetect = (attributes & WindowsInstallerConstants.MsidbUpgradeAttributesOnlyDetect) == WindowsInstallerConstants.MsidbUpgradeAttributesOnlyDetect, | ||
| 338 | IgnoreRemoveFailures = (attributes & WindowsInstallerConstants.MsidbUpgradeAttributesIgnoreRemoveFailure) == WindowsInstallerConstants.MsidbUpgradeAttributesIgnoreRemoveFailure, | ||
| 339 | VersionMinInclusive = (attributes & WindowsInstallerConstants.MsidbUpgradeAttributesVersionMinInclusive) == WindowsInstallerConstants.MsidbUpgradeAttributesVersionMinInclusive, | ||
| 340 | VersionMaxInclusive = (attributes & WindowsInstallerConstants.MsidbUpgradeAttributesVersionMaxInclusive) == WindowsInstallerConstants.MsidbUpgradeAttributesVersionMaxInclusive, | ||
| 341 | ExcludeLanguages = (attributes & WindowsInstallerConstants.MsidbUpgradeAttributesLanguagesExclusive) == WindowsInstallerConstants.MsidbUpgradeAttributesLanguagesExclusive, | ||
| 342 | }; | ||
| 343 | } | ||
| 344 | |||
| 345 | case "Verb": | ||
| 346 | return DefaultTupleFromRow(typeof(VerbTuple), row, columnZeroIsId: false); | ||
| 347 | //case "WixAction": | ||
| 348 | // return new WixActionTuple(SourceLineNumber4(row.SourceLineNumbers)) | ||
| 349 | // { | ||
| 350 | // SequenceTable = (SequenceTable)Enum.Parse(typeof(SequenceTable), FieldAsString(row, 0)), | ||
| 351 | // Action = FieldAsString(row, 1), | ||
| 352 | // Condition = FieldAsString(row, 2), | ||
| 353 | // Sequence = FieldAsInt(row, 3), | ||
| 354 | // Before = FieldAsString(row, 4), | ||
| 355 | // After = FieldAsString(row, 5), | ||
| 356 | // Overridable = FieldAsNullableInt(row, 6) != 0, | ||
| 357 | // }; | ||
| 358 | case "WixFile": | ||
| 359 | var assemblyAttributes3 = FieldAsNullableInt(row, 1); | ||
| 360 | return new WixFileTuple(SourceLineNumber4(row.SourceLineNumbers), new Identifier(AccessModifier.Public, FieldAsString(row, 0))) | ||
| 361 | { | ||
| 362 | AssemblyType = assemblyAttributes3 == 0 ? FileAssemblyType.DotNetAssembly : assemblyAttributes3 == 1 ? FileAssemblyType.Win32Assembly : FileAssemblyType.NotAnAssembly, | ||
| 363 | File_AssemblyManifest = FieldAsString(row, 2), | ||
| 364 | File_AssemblyApplication = FieldAsString(row, 3), | ||
| 365 | Directory_ = FieldAsString(row, 4), | ||
| 366 | DiskId = FieldAsInt(row, 5), // TODO: BUGBUGBUG: AB#2626: DiskId is nullable in WiX v3. | ||
| 367 | Source = new IntermediateFieldPathValue() { Path = FieldAsString(row, 6) }, | ||
| 368 | ProcessorArchitecture = FieldAsString(row, 7), | ||
| 369 | PatchGroup = FieldAsInt(row, 8), | ||
| 370 | Attributes = FieldAsInt(row, 9), | ||
| 371 | }; | ||
| 372 | case "WixProperty": | ||
| 373 | { | ||
| 374 | var attributes = FieldAsInt(row, 1); | ||
| 375 | return new WixPropertyTuple(SourceLineNumber4(row.SourceLineNumbers)) | ||
| 376 | { | ||
| 377 | Property_ = FieldAsString(row, 0), | ||
| 378 | Admin = (attributes & 0x1) == 0x1, | ||
| 379 | Hidden = (attributes & 0x2) == 0x2, | ||
| 380 | Secure = (attributes & 0x4) == 0x4, | ||
| 381 | }; | ||
| 382 | } | ||
| 383 | |||
| 384 | default: | ||
| 385 | return GenericTupleFromCustomRow(row, columnZeroIsId: false); | ||
| 386 | } | ||
| 387 | } | ||
| 388 | |||
| 389 | private static CustomActionTargetType DetermineCustomActionTargetType(int type) | ||
| 390 | { | ||
| 391 | var targetType = default(CustomActionTargetType); | ||
| 392 | |||
| 393 | if ((type & WindowsInstallerConstants.MsidbCustomActionTypeVBScript) == WindowsInstallerConstants.MsidbCustomActionTypeVBScript) | ||
| 394 | { | ||
| 395 | targetType = CustomActionTargetType.VBScript; | ||
| 396 | } | ||
| 397 | else if ((type & WindowsInstallerConstants.MsidbCustomActionTypeJScript) == WindowsInstallerConstants.MsidbCustomActionTypeJScript) | ||
| 398 | { | ||
| 399 | targetType = CustomActionTargetType.JScript; | ||
| 400 | } | ||
| 401 | else if ((type & WindowsInstallerConstants.MsidbCustomActionTypeTextData) == WindowsInstallerConstants.MsidbCustomActionTypeTextData) | ||
| 402 | { | ||
| 403 | targetType = CustomActionTargetType.TextData; | ||
| 404 | } | ||
| 405 | else if ((type & WindowsInstallerConstants.MsidbCustomActionTypeExe) == WindowsInstallerConstants.MsidbCustomActionTypeExe) | ||
| 406 | { | ||
| 407 | targetType = CustomActionTargetType.Exe; | ||
| 408 | } | ||
| 409 | else if ((type & WindowsInstallerConstants.MsidbCustomActionTypeDll) == WindowsInstallerConstants.MsidbCustomActionTypeDll) | ||
| 410 | { | ||
| 411 | targetType = CustomActionTargetType.Dll; | ||
| 412 | } | ||
| 413 | |||
| 414 | return targetType; | ||
| 415 | } | ||
| 416 | |||
| 417 | private static CustomActionSourceType DetermineCustomActionSourceType(int type) | ||
| 418 | { | ||
| 419 | var sourceType = CustomActionSourceType.Binary; | ||
| 420 | |||
| 421 | if ((type & WindowsInstallerConstants.MsidbCustomActionTypeProperty) == WindowsInstallerConstants.MsidbCustomActionTypeProperty) | ||
| 422 | { | ||
| 423 | sourceType = CustomActionSourceType.Property; | ||
| 424 | } | ||
| 425 | else if ((type & WindowsInstallerConstants.MsidbCustomActionTypeDirectory) == WindowsInstallerConstants.MsidbCustomActionTypeDirectory) | ||
| 426 | { | ||
| 427 | sourceType = CustomActionSourceType.Directory; | ||
| 428 | } | ||
| 429 | else if ((type & WindowsInstallerConstants.MsidbCustomActionTypeSourceFile) == WindowsInstallerConstants.MsidbCustomActionTypeSourceFile) | ||
| 430 | { | ||
| 431 | sourceType = CustomActionSourceType.File; | ||
| 432 | } | ||
| 433 | |||
| 434 | return sourceType; | ||
| 435 | } | ||
| 436 | |||
| 437 | private static CustomActionExecutionType DetermineCustomActionExecutionType(int type) | ||
| 438 | { | ||
| 439 | var executionType = CustomActionExecutionType.Immediate; | ||
| 440 | |||
| 441 | if ((type & (WindowsInstallerConstants.MsidbCustomActionTypeInScript | WindowsInstallerConstants.MsidbCustomActionTypeCommit)) == (WindowsInstallerConstants.MsidbCustomActionTypeInScript | WindowsInstallerConstants.MsidbCustomActionTypeCommit)) | ||
| 442 | { | ||
| 443 | executionType = CustomActionExecutionType.Commit; | ||
| 444 | } | ||
| 445 | else if ((type & (WindowsInstallerConstants.MsidbCustomActionTypeInScript | WindowsInstallerConstants.MsidbCustomActionTypeRollback)) == (WindowsInstallerConstants.MsidbCustomActionTypeInScript | WindowsInstallerConstants.MsidbCustomActionTypeRollback)) | ||
| 446 | { | ||
| 447 | executionType = CustomActionExecutionType.Rollback; | ||
| 448 | } | ||
| 449 | else if ((type & WindowsInstallerConstants.MsidbCustomActionTypeInScript) == WindowsInstallerConstants.MsidbCustomActionTypeInScript) | ||
| 450 | { | ||
| 451 | executionType = CustomActionExecutionType.Deferred; | ||
| 452 | } | ||
| 453 | else if ((type & WindowsInstallerConstants.MsidbCustomActionTypeClientRepeat) == WindowsInstallerConstants.MsidbCustomActionTypeClientRepeat) | ||
| 454 | { | ||
| 455 | executionType = CustomActionExecutionType.ClientRepeat; | ||
| 456 | } | ||
| 457 | else if ((type & WindowsInstallerConstants.MsidbCustomActionTypeOncePerProcess) == WindowsInstallerConstants.MsidbCustomActionTypeOncePerProcess) | ||
| 458 | { | ||
| 459 | executionType = CustomActionExecutionType.OncePerProcess; | ||
| 460 | } | ||
| 461 | else if ((type & WindowsInstallerConstants.MsidbCustomActionTypeFirstSequence) == WindowsInstallerConstants.MsidbCustomActionTypeFirstSequence) | ||
| 462 | { | ||
| 463 | executionType = CustomActionExecutionType.FirstSequence; | ||
| 464 | } | ||
| 465 | |||
| 466 | return executionType; | ||
| 467 | } | ||
| 468 | |||
| 469 | private static IntermediateFieldType ColumnType3ToIntermediateFieldType4(Wix3.ColumnType columnType) | ||
| 470 | { | ||
| 471 | switch (columnType) | ||
| 472 | { | ||
| 473 | case Wix3.ColumnType.Number: | ||
| 474 | return IntermediateFieldType.Number; | ||
| 475 | case Wix3.ColumnType.Object: | ||
| 476 | return IntermediateFieldType.Path; | ||
| 477 | case Wix3.ColumnType.Unknown: | ||
| 478 | case Wix3.ColumnType.String: | ||
| 479 | case Wix3.ColumnType.Localized: | ||
| 480 | case Wix3.ColumnType.Preserved: | ||
| 481 | default: | ||
| 482 | return IntermediateFieldType.String; | ||
| 483 | } | ||
| 484 | } | ||
| 485 | |||
| 486 | private static IntermediateTuple DefaultTupleFromRow(Type tupleType, Wix3.Row row, bool columnZeroIsId) | ||
| 487 | { | ||
| 488 | var tuple = Activator.CreateInstance(tupleType) as IntermediateTuple; | ||
| 489 | |||
| 490 | SetTupleFieldsFromRow(row, tuple, columnZeroIsId); | ||
| 491 | |||
| 492 | tuple.SourceLineNumbers = SourceLineNumber4(row.SourceLineNumbers); | ||
| 493 | return tuple; | ||
| 494 | } | ||
| 495 | |||
| 496 | private static IntermediateTuple GenericTupleFromCustomRow(Wix3.Row row, bool columnZeroIsId) | ||
| 497 | { | ||
| 498 | var columnDefinitions = row.Table.Definition.Columns.Cast<Wix3.ColumnDefinition>(); | ||
| 499 | var fieldDefinitions = columnDefinitions.Select(columnDefinition => | ||
| 500 | new IntermediateFieldDefinition(columnDefinition.Name, ColumnType3ToIntermediateFieldType4(columnDefinition.Type))).ToArray(); | ||
| 501 | var tupleDefinition = new IntermediateTupleDefinition(row.Table.Name, fieldDefinitions, null); | ||
| 502 | var tuple = new IntermediateTuple(tupleDefinition, SourceLineNumber4(row.SourceLineNumbers)); | ||
| 503 | |||
| 504 | SetTupleFieldsFromRow(row, tuple, columnZeroIsId); | ||
| 505 | |||
| 506 | return tuple; | ||
| 507 | } | ||
| 508 | |||
| 509 | private static void SetTupleFieldsFromRow(Wix3.Row row, IntermediateTuple tuple, bool columnZeroIsId) | ||
| 510 | { | ||
| 511 | int offset = 0; | ||
| 512 | if (columnZeroIsId) | ||
| 513 | { | ||
| 514 | tuple.Id = GetIdentifierForRow(row); | ||
| 515 | offset = 1; | ||
| 516 | } | ||
| 517 | |||
| 518 | for (var i = offset; i < row.Fields.Length; ++i) | ||
| 519 | { | ||
| 520 | var column = row.Fields[i].Column; | ||
| 521 | switch (column.Type) | ||
| 522 | { | ||
| 523 | case Wix3.ColumnType.String: | ||
| 524 | case Wix3.ColumnType.Localized: | ||
| 525 | case Wix3.ColumnType.Object: | ||
| 526 | case Wix3.ColumnType.Preserved: | ||
| 527 | tuple.Set(i - offset, FieldAsString(row, i)); | ||
| 528 | break; | ||
| 529 | case Wix3.ColumnType.Number: | ||
| 530 | int? nullableValue = FieldAsNullableInt(row, i); | ||
| 531 | // TODO: Consider whether null values should be coerced to their default value when | ||
| 532 | // a column is not nullable. For now, just pass through the null. | ||
| 533 | //int value = FieldAsInt(row, i); | ||
| 534 | //tuple.Set(i - offset, column.IsNullable ? nullableValue : value); | ||
| 535 | tuple.Set(i - offset, nullableValue); | ||
| 536 | break; | ||
| 537 | case Wix3.ColumnType.Unknown: | ||
| 538 | break; | ||
| 539 | } | ||
| 540 | } | ||
| 541 | } | ||
| 542 | |||
| 543 | private static Identifier GetIdentifierForRow(Wix3.Row row) | ||
| 544 | { | ||
| 545 | var column = row.Fields[0].Column; | ||
| 546 | switch (column.Type) | ||
| 547 | { | ||
| 548 | case Wix3.ColumnType.String: | ||
| 549 | case Wix3.ColumnType.Localized: | ||
| 550 | case Wix3.ColumnType.Object: | ||
| 551 | case Wix3.ColumnType.Preserved: | ||
| 552 | return new Identifier(AccessModifier.Public, (string)row.Fields[0].Data); | ||
| 553 | case Wix3.ColumnType.Number: | ||
| 554 | return new Identifier(AccessModifier.Public, FieldAsInt(row, 0)); | ||
| 555 | default: | ||
| 556 | return null; | ||
| 557 | } | ||
| 558 | } | ||
| 559 | |||
| 560 | private static SectionType OutputType3ToSectionType4(Wix3.OutputType outputType) | ||
| 561 | { | ||
| 562 | switch (outputType) | ||
| 563 | { | ||
| 564 | case Wix3.OutputType.Bundle: | ||
| 565 | return SectionType.Bundle; | ||
| 566 | case Wix3.OutputType.Module: | ||
| 567 | return SectionType.Module; | ||
| 568 | case Wix3.OutputType.Patch: | ||
| 569 | return SectionType.Patch; | ||
| 570 | case Wix3.OutputType.PatchCreation: | ||
| 571 | return SectionType.PatchCreation; | ||
| 572 | case Wix3.OutputType.Product: | ||
| 573 | return SectionType.Product; | ||
| 574 | case Wix3.OutputType.Transform: | ||
| 575 | case Wix3.OutputType.Unknown: | ||
| 576 | default: | ||
| 577 | return SectionType.Unknown; | ||
| 578 | } | ||
| 579 | } | ||
| 580 | |||
| 581 | private static SourceLineNumber SourceLineNumber4(Wix3.SourceLineNumberCollection source) | ||
| 582 | { | ||
| 583 | return String.IsNullOrEmpty(source?.EncodedSourceLineNumbers) ? null : SourceLineNumber.CreateFromEncoded(source.EncodedSourceLineNumbers); | ||
| 584 | } | ||
| 585 | |||
| 586 | private static string FieldAsString(Wix3.Row row, int column) | ||
| 587 | { | ||
| 588 | return (string)row[column]; | ||
| 589 | } | ||
| 590 | |||
| 591 | private static int FieldAsInt(Wix3.Row row, int column) | ||
| 592 | { | ||
| 593 | return Convert.ToInt32(row[column]); | ||
| 594 | } | ||
| 595 | |||
| 596 | private static int? FieldAsNullableInt(Wix3.Row row, int column) | ||
| 597 | { | ||
| 598 | var field = row.Fields[column]; | ||
| 599 | if (field.Data == null) | ||
| 600 | { | ||
| 601 | return null; | ||
| 602 | } | ||
| 603 | else | ||
| 604 | { | ||
| 605 | return Convert.ToInt32(field.Data); | ||
| 606 | } | ||
| 607 | } | ||
| 608 | } | ||
| 609 | } | ||
