aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core.WindowsInstaller/Bind/CreateWindowsInstallerDataFromIRCommand.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Core.WindowsInstaller/Bind/CreateWindowsInstallerDataFromIRCommand.cs')
-rw-r--r--src/WixToolset.Core.WindowsInstaller/Bind/CreateWindowsInstallerDataFromIRCommand.cs1256
1 files changed, 1256 insertions, 0 deletions
diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/CreateWindowsInstallerDataFromIRCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/CreateWindowsInstallerDataFromIRCommand.cs
new file mode 100644
index 00000000..dc60a9ac
--- /dev/null
+++ b/src/WixToolset.Core.WindowsInstaller/Bind/CreateWindowsInstallerDataFromIRCommand.cs
@@ -0,0 +1,1256 @@
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
3namespace WixToolset.Core.WindowsInstaller.Bind
4{
5 using System;
6 using System.Collections.Generic;
7 using System.Globalization;
8 using System.IO;
9 using System.Linq;
10 using System.Security.Cryptography;
11 using System.Text;
12 using WixToolset.Data;
13 using WixToolset.Data.Symbols;
14 using WixToolset.Data.WindowsInstaller;
15 using WixToolset.Data.WindowsInstaller.Rows;
16 using WixToolset.Extensibility;
17 using WixToolset.Extensibility.Services;
18
19 internal class CreateWindowsInstallerDataFromIRCommand
20 {
21 public CreateWindowsInstallerDataFromIRCommand(IMessaging messaging, IntermediateSection section, TableDefinitionCollection tableDefinitions, IEnumerable<IWindowsInstallerBackendBinderExtension> backendExtensions, IWindowsInstallerBackendHelper backendHelper)
22 {
23 this.Messaging = messaging;
24 this.Section = section;
25 this.TableDefinitions = tableDefinitions;
26 this.BackendExtensions = backendExtensions;
27 this.BackendHelper = backendHelper;
28 }
29
30 private IEnumerable<IWindowsInstallerBackendBinderExtension> BackendExtensions { get; }
31
32 private IWindowsInstallerBackendHelper BackendHelper { get; }
33
34 private IMessaging Messaging { get; }
35
36 private TableDefinitionCollection TableDefinitions { get; }
37
38 private IntermediateSection Section { get; }
39
40 public WindowsInstallerData Data { get; private set; }
41
42 public WindowsInstallerData Execute()
43 {
44 this.Data = new WindowsInstallerData(this.Section.Symbols.First().SourceLineNumbers)
45 {
46 Codepage = this.Section.Codepage,
47 Type = SectionTypeToOutputType(this.Section.Type)
48 };
49
50 this.AddSectionToData();
51
52 return this.Data;
53 }
54
55 private void AddSectionToData()
56 {
57 var cellsByTableAndRowId = new Dictionary<string, List<WixCustomTableCellSymbol>>();
58
59 foreach (var symbol in this.Section.Symbols)
60 {
61 var unknownSymbol = false;
62 switch (symbol.Definition.Type)
63 {
64 case SymbolDefinitionType.AppSearch:
65 this.AddSymbolDefaultly(symbol);
66 this.Data.EnsureTable(this.TableDefinitions["Signature"]);
67 break;
68
69 case SymbolDefinitionType.Assembly:
70 this.AddAssemblySymbol((AssemblySymbol)symbol);
71 break;
72
73 case SymbolDefinitionType.BBControl:
74 this.AddBBControlSymbol((BBControlSymbol)symbol);
75 break;
76
77 case SymbolDefinitionType.Class:
78 this.AddClassSymbol((ClassSymbol)symbol);
79 break;
80
81 case SymbolDefinitionType.Control:
82 this.AddControlSymbol((ControlSymbol)symbol);
83 break;
84
85 case SymbolDefinitionType.ControlEvent:
86 this.AddControlEventSymbol((ControlEventSymbol)symbol);
87 break;
88
89 case SymbolDefinitionType.Component:
90 this.AddComponentSymbol((ComponentSymbol)symbol);
91 break;
92
93 case SymbolDefinitionType.CustomAction:
94 this.AddCustomActionSymbol((CustomActionSymbol)symbol);
95 break;
96
97 case SymbolDefinitionType.Dialog:
98 this.AddDialogSymbol((DialogSymbol)symbol);
99 break;
100
101 case SymbolDefinitionType.Directory:
102 this.AddDirectorySymbol((DirectorySymbol)symbol);
103 break;
104
105 case SymbolDefinitionType.DuplicateFile:
106 this.AddDuplicateFileSymbol((DuplicateFileSymbol)symbol);
107 break;
108
109 case SymbolDefinitionType.Environment:
110 this.AddEnvironmentSymbol((EnvironmentSymbol)symbol);
111 break;
112
113 case SymbolDefinitionType.Error:
114 this.AddErrorSymbol((ErrorSymbol)symbol);
115 break;
116
117 case SymbolDefinitionType.Feature:
118 this.AddFeatureSymbol((FeatureSymbol)symbol);
119 break;
120
121 case SymbolDefinitionType.File:
122 this.AddFileSymbol((FileSymbol)symbol);
123 break;
124
125 case SymbolDefinitionType.IniFile:
126 this.AddIniFileSymbol((IniFileSymbol)symbol);
127 break;
128
129 case SymbolDefinitionType.IniLocator:
130 this.AddIniLocatorSymbol((IniLocatorSymbol)symbol);
131 break;
132
133 case SymbolDefinitionType.Media:
134 this.AddMediaSymbol((MediaSymbol)symbol);
135 break;
136
137 case SymbolDefinitionType.ModuleConfiguration:
138 this.AddModuleConfigurationSymbol((ModuleConfigurationSymbol)symbol);
139 break;
140
141 case SymbolDefinitionType.MsiEmbeddedUI:
142 this.AddMsiEmbeddedUISymbol((MsiEmbeddedUISymbol)symbol);
143 break;
144
145 case SymbolDefinitionType.MsiServiceConfig:
146 this.AddMsiServiceConfigSymbol((MsiServiceConfigSymbol)symbol);
147 break;
148
149 case SymbolDefinitionType.MsiServiceConfigFailureActions:
150 this.AddMsiServiceConfigFailureActionsSymbol((MsiServiceConfigFailureActionsSymbol)symbol);
151 break;
152
153 case SymbolDefinitionType.MoveFile:
154 this.AddMoveFileSymbol((MoveFileSymbol)symbol);
155 break;
156
157 case SymbolDefinitionType.ProgId:
158 this.AddSymbolDefaultly(symbol);
159 this.Data.EnsureTable(this.TableDefinitions["Extension"]);
160 break;
161
162 case SymbolDefinitionType.Property:
163 this.AddPropertySymbol((PropertySymbol)symbol);
164 break;
165
166 case SymbolDefinitionType.RemoveFile:
167 this.AddRemoveFileSymbol((RemoveFileSymbol)symbol);
168 break;
169
170 case SymbolDefinitionType.Registry:
171 this.AddRegistrySymbol((RegistrySymbol)symbol);
172 break;
173
174 case SymbolDefinitionType.RegLocator:
175 this.AddRegLocatorSymbol((RegLocatorSymbol)symbol);
176 break;
177
178 case SymbolDefinitionType.RemoveRegistry:
179 this.AddRemoveRegistrySymbol((RemoveRegistrySymbol)symbol);
180 break;
181
182 case SymbolDefinitionType.ServiceControl:
183 this.AddServiceControlSymbol((ServiceControlSymbol)symbol);
184 break;
185
186 case SymbolDefinitionType.ServiceInstall:
187 this.AddServiceInstallSymbol((ServiceInstallSymbol)symbol);
188 break;
189
190 case SymbolDefinitionType.Shortcut:
191 this.AddShortcutSymbol((ShortcutSymbol)symbol);
192 break;
193
194 case SymbolDefinitionType.TextStyle:
195 this.AddTextStyleSymbol((TextStyleSymbol)symbol);
196 break;
197
198 case SymbolDefinitionType.Upgrade:
199 this.AddUpgradeSymbol((UpgradeSymbol)symbol);
200 break;
201
202 case SymbolDefinitionType.WixAction:
203 this.AddWixActionSymbol((WixActionSymbol)symbol);
204 break;
205
206 case SymbolDefinitionType.WixCustomTableCell:
207 this.IndexCustomTableCellSymbol((WixCustomTableCellSymbol)symbol, cellsByTableAndRowId);
208 break;
209
210 case SymbolDefinitionType.WixEnsureTable:
211 this.AddWixEnsureTableSymbol((WixEnsureTableSymbol)symbol);
212 break;
213
214 // Symbols used internally and are not added to the output.
215 case SymbolDefinitionType.WixBuildInfo:
216 case SymbolDefinitionType.WixBindUpdatedFiles:
217 case SymbolDefinitionType.WixComponentGroup:
218 case SymbolDefinitionType.WixComplexReference:
219 case SymbolDefinitionType.WixDeltaPatchFile:
220 case SymbolDefinitionType.WixDeltaPatchSymbolPaths:
221 case SymbolDefinitionType.WixFragment:
222 case SymbolDefinitionType.WixFeatureGroup:
223 case SymbolDefinitionType.WixInstanceComponent:
224 case SymbolDefinitionType.WixInstanceTransforms:
225 case SymbolDefinitionType.WixFeatureModules:
226 case SymbolDefinitionType.WixGroup:
227 case SymbolDefinitionType.WixMediaTemplate:
228 case SymbolDefinitionType.WixMerge:
229 case SymbolDefinitionType.WixOrdering:
230 case SymbolDefinitionType.WixPatchBaseline:
231 case SymbolDefinitionType.WixPatchFamilyGroup:
232 case SymbolDefinitionType.WixPatchId:
233 case SymbolDefinitionType.WixPatchRef:
234 case SymbolDefinitionType.WixPatchTarget:
235 case SymbolDefinitionType.WixProperty:
236 case SymbolDefinitionType.WixProductTag:
237 case SymbolDefinitionType.WixSimpleReference:
238 case SymbolDefinitionType.WixSuppressAction:
239 case SymbolDefinitionType.WixSuppressModularization:
240 case SymbolDefinitionType.WixUI:
241 case SymbolDefinitionType.WixVariable:
242 break;
243
244 // Already processed by LoadTableDefinitions.
245 case SymbolDefinitionType.WixCustomTable:
246 case SymbolDefinitionType.WixCustomTableColumn:
247 break;
248
249 case SymbolDefinitionType.MustBeFromAnExtension:
250 unknownSymbol = !this.AddSymbolFromExtension(symbol);
251 break;
252
253 default:
254 unknownSymbol = !this.AddSymbolDefaultly(symbol);
255 break;
256 }
257
258 if (unknownSymbol)
259 {
260 this.Messaging.Write(WarningMessages.SymbolNotTranslatedToOutput(symbol));
261 }
262 }
263
264 this.AddIndexedCellSymbols(cellsByTableAndRowId);
265 }
266
267 private void AddAssemblySymbol(AssemblySymbol symbol)
268 {
269 var attributes = symbol.Type == AssemblyType.Win32Assembly ? 1 : (int?)null;
270
271 var row = this.CreateRow(symbol, "MsiAssembly");
272 row[0] = symbol.ComponentRef;
273 row[1] = symbol.FeatureRef;
274 row[2] = symbol.ManifestFileRef;
275 row[3] = symbol.ApplicationFileRef;
276 row[4] = attributes;
277 }
278
279 private void AddBBControlSymbol(BBControlSymbol symbol)
280 {
281 var attributes = symbol.Attributes;
282 attributes |= symbol.Enabled ? WindowsInstallerConstants.MsidbControlAttributesEnabled : 0;
283 attributes |= symbol.Indirect ? WindowsInstallerConstants.MsidbControlAttributesIndirect : 0;
284 attributes |= symbol.Integer ? WindowsInstallerConstants.MsidbControlAttributesInteger : 0;
285 attributes |= symbol.LeftScroll ? WindowsInstallerConstants.MsidbControlAttributesLeftScroll : 0;
286 attributes |= symbol.RightAligned ? WindowsInstallerConstants.MsidbControlAttributesRightAligned : 0;
287 attributes |= symbol.RightToLeft ? WindowsInstallerConstants.MsidbControlAttributesRTLRO : 0;
288 attributes |= symbol.Sunken ? WindowsInstallerConstants.MsidbControlAttributesSunken : 0;
289 attributes |= symbol.Visible ? WindowsInstallerConstants.MsidbControlAttributesVisible : 0;
290
291 var row = this.CreateRow(symbol, "BBControl");
292 row[0] = symbol.BillboardRef;
293 row[1] = symbol.BBControl;
294 row[2] = symbol.Type;
295 row[3] = symbol.X;
296 row[4] = symbol.Y;
297 row[5] = symbol.Width;
298 row[6] = symbol.Height;
299 row[7] = attributes;
300 row[8] = symbol.Text;
301 }
302
303 private void AddClassSymbol(ClassSymbol symbol)
304 {
305 var row = this.CreateRow(symbol, "Class");
306 row[0] = symbol.CLSID;
307 row[1] = symbol.Context;
308 row[2] = symbol.ComponentRef;
309 row[3] = symbol.DefaultProgIdRef;
310 row[4] = symbol.Description;
311 row[5] = symbol.AppIdRef;
312 row[6] = symbol.FileTypeMask;
313 row[7] = symbol.IconRef;
314 row[8] = symbol.IconIndex;
315 row[9] = symbol.DefInprocHandler;
316 row[10] = symbol.Argument;
317 row[11] = symbol.FeatureRef;
318 row[12] = symbol.RelativePath ? (int?)1 : null;
319 }
320
321 private void AddControlSymbol(ControlSymbol symbol)
322 {
323 var text = symbol.Text;
324 var attributes = symbol.Attributes;
325 attributes |= symbol.Enabled ? WindowsInstallerConstants.MsidbControlAttributesEnabled : 0;
326 attributes |= symbol.Indirect ? WindowsInstallerConstants.MsidbControlAttributesIndirect : 0;
327 attributes |= symbol.Integer ? WindowsInstallerConstants.MsidbControlAttributesInteger : 0;
328 attributes |= symbol.LeftScroll ? WindowsInstallerConstants.MsidbControlAttributesLeftScroll : 0;
329 attributes |= symbol.RightAligned ? WindowsInstallerConstants.MsidbControlAttributesRightAligned : 0;
330 attributes |= symbol.RightToLeft ? WindowsInstallerConstants.MsidbControlAttributesRTLRO : 0;
331 attributes |= symbol.Sunken ? WindowsInstallerConstants.MsidbControlAttributesSunken : 0;
332 attributes |= symbol.Visible ? WindowsInstallerConstants.MsidbControlAttributesVisible : 0;
333
334 // If we're tracking disk space, and this is a non-FormatSize Text control,
335 // and the text attribute starts with '[' and ends with ']', add a space.
336 // It is not necessary for the whole string to be a property, just those
337 // two characters matter.
338 if (symbol.TrackDiskSpace &&
339 "Text" == symbol.Type &&
340 WindowsInstallerConstants.MsidbControlAttributesFormatSize != (attributes & WindowsInstallerConstants.MsidbControlAttributesFormatSize) &&
341 null != text && text.StartsWith("[", StringComparison.Ordinal) && text.EndsWith("]", StringComparison.Ordinal))
342 {
343 text = String.Concat(text, " ");
344 }
345
346 var row = this.CreateRow(symbol, "Control");
347 row[0] = symbol.DialogRef;
348 row[1] = symbol.Control;
349 row[2] = symbol.Type;
350 row[3] = symbol.X;
351 row[4] = symbol.Y;
352 row[5] = symbol.Width;
353 row[6] = symbol.Height;
354 row[7] = attributes;
355 row[8] = symbol.Property;
356 row[9] = text;
357 row[10] = symbol.NextControlRef;
358 row[11] = symbol.Help;
359 }
360
361 private void AddControlEventSymbol(ControlEventSymbol symbol)
362 {
363 var row = this.CreateRow(symbol, "ControlEvent");
364 row[0] = symbol.DialogRef;
365 row[1] = symbol.ControlRef;
366 row[2] = symbol.Event;
367 row[3] = symbol.Argument;
368 row[4] = String.IsNullOrEmpty(symbol.Condition) ? "1" : symbol.Condition;
369 row[5] = symbol.Ordering;
370 }
371
372 private void AddComponentSymbol(ComponentSymbol symbol)
373 {
374 var attributes = ComponentLocation.Either == symbol.Location ? WindowsInstallerConstants.MsidbComponentAttributesOptional : 0;
375 attributes |= ComponentLocation.SourceOnly == symbol.Location ? WindowsInstallerConstants.MsidbComponentAttributesSourceOnly : 0;
376 attributes |= ComponentKeyPathType.Registry == symbol.KeyPathType ? WindowsInstallerConstants.MsidbComponentAttributesRegistryKeyPath : 0;
377 attributes |= ComponentKeyPathType.OdbcDataSource == symbol.KeyPathType ? WindowsInstallerConstants.MsidbComponentAttributesODBCDataSource : 0;
378 attributes |= symbol.DisableRegistryReflection ? WindowsInstallerConstants.MsidbComponentAttributesDisableRegistryReflection : 0;
379 attributes |= symbol.NeverOverwrite ? WindowsInstallerConstants.MsidbComponentAttributesNeverOverwrite : 0;
380 attributes |= symbol.Permanent ? WindowsInstallerConstants.MsidbComponentAttributesPermanent : 0;
381 attributes |= symbol.SharedDllRefCount ? WindowsInstallerConstants.MsidbComponentAttributesSharedDllRefCount : 0;
382 attributes |= symbol.Shared ? WindowsInstallerConstants.MsidbComponentAttributesShared : 0;
383 attributes |= symbol.Transitive ? WindowsInstallerConstants.MsidbComponentAttributesTransitive : 0;
384 attributes |= symbol.UninstallWhenSuperseded ? WindowsInstallerConstants.MsidbComponentAttributesUninstallOnSupersedence : 0;
385 attributes |= symbol.Win64 ? WindowsInstallerConstants.MsidbComponentAttributes64bit : 0;
386
387 var row = this.CreateRow(symbol, "Component");
388 row[0] = symbol.Id.Id;
389 row[1] = symbol.ComponentId;
390 row[2] = symbol.DirectoryRef;
391 row[3] = attributes;
392 row[4] = symbol.Condition;
393 row[5] = symbol.KeyPath;
394 }
395
396 private void AddCustomActionSymbol(CustomActionSymbol symbol)
397 {
398 var type = symbol.Win64 ? WindowsInstallerConstants.MsidbCustomActionType64BitScript : 0;
399 type |= symbol.IgnoreResult ? WindowsInstallerConstants.MsidbCustomActionTypeContinue : 0;
400 type |= symbol.Hidden ? WindowsInstallerConstants.MsidbCustomActionTypeHideTarget : 0;
401 type |= symbol.Async ? WindowsInstallerConstants.MsidbCustomActionTypeAsync : 0;
402 type |= CustomActionExecutionType.FirstSequence == symbol.ExecutionType ? WindowsInstallerConstants.MsidbCustomActionTypeFirstSequence : 0;
403 type |= CustomActionExecutionType.OncePerProcess == symbol.ExecutionType ? WindowsInstallerConstants.MsidbCustomActionTypeOncePerProcess : 0;
404 type |= CustomActionExecutionType.ClientRepeat == symbol.ExecutionType ? WindowsInstallerConstants.MsidbCustomActionTypeClientRepeat : 0;
405 type |= CustomActionExecutionType.Deferred == symbol.ExecutionType ? WindowsInstallerConstants.MsidbCustomActionTypeInScript : 0;
406 type |= CustomActionExecutionType.Rollback == symbol.ExecutionType ? WindowsInstallerConstants.MsidbCustomActionTypeInScript | WindowsInstallerConstants.MsidbCustomActionTypeRollback : 0;
407 type |= CustomActionExecutionType.Commit == symbol.ExecutionType ? WindowsInstallerConstants.MsidbCustomActionTypeInScript | WindowsInstallerConstants.MsidbCustomActionTypeCommit : 0;
408 type |= CustomActionSourceType.File == symbol.SourceType ? WindowsInstallerConstants.MsidbCustomActionTypeSourceFile : 0;
409 type |= CustomActionSourceType.Directory == symbol.SourceType ? WindowsInstallerConstants.MsidbCustomActionTypeDirectory : 0;
410 type |= CustomActionSourceType.Property == symbol.SourceType ? WindowsInstallerConstants.MsidbCustomActionTypeProperty : 0;
411 type |= CustomActionTargetType.Dll == symbol.TargetType ? WindowsInstallerConstants.MsidbCustomActionTypeDll : 0;
412 type |= CustomActionTargetType.Exe == symbol.TargetType ? WindowsInstallerConstants.MsidbCustomActionTypeExe : 0;
413 type |= CustomActionTargetType.TextData == symbol.TargetType ? WindowsInstallerConstants.MsidbCustomActionTypeTextData : 0;
414 type |= CustomActionTargetType.JScript == symbol.TargetType ? WindowsInstallerConstants.MsidbCustomActionTypeJScript : 0;
415 type |= CustomActionTargetType.VBScript == symbol.TargetType ? WindowsInstallerConstants.MsidbCustomActionTypeVBScript : 0;
416
417 if (WindowsInstallerConstants.MsidbCustomActionTypeInScript == (type & WindowsInstallerConstants.MsidbCustomActionTypeInScript))
418 {
419 type |= symbol.Impersonate ? 0 : WindowsInstallerConstants.MsidbCustomActionTypeNoImpersonate;
420 type |= symbol.TSAware ? WindowsInstallerConstants.MsidbCustomActionTypeTSAware : 0;
421 }
422
423 var row = this.CreateRow(symbol, "CustomAction");
424 row[0] = symbol.Id.Id;
425 row[1] = type;
426 row[2] = symbol.Source;
427 row[3] = symbol.Target;
428 row[4] = symbol.PatchUninstall ? (int?)WindowsInstallerConstants.MsidbCustomActionTypePatchUninstall : null;
429 }
430
431 private void AddDialogSymbol(DialogSymbol symbol)
432 {
433 var attributes = symbol.Visible ? WindowsInstallerConstants.MsidbDialogAttributesVisible : 0;
434 attributes |= symbol.Modal ? WindowsInstallerConstants.MsidbDialogAttributesModal : 0;
435 attributes |= symbol.Minimize ? WindowsInstallerConstants.MsidbDialogAttributesMinimize : 0;
436 attributes |= symbol.CustomPalette ? WindowsInstallerConstants.MsidbDialogAttributesUseCustomPalette : 0;
437 attributes |= symbol.ErrorDialog ? WindowsInstallerConstants.MsidbDialogAttributesError : 0;
438 attributes |= symbol.LeftScroll ? WindowsInstallerConstants.MsidbDialogAttributesLeftScroll : 0;
439 attributes |= symbol.KeepModeless ? WindowsInstallerConstants.MsidbDialogAttributesKeepModeless : 0;
440 attributes |= symbol.RightAligned ? WindowsInstallerConstants.MsidbDialogAttributesRightAligned : 0;
441 attributes |= symbol.RightToLeft ? WindowsInstallerConstants.MsidbDialogAttributesRTLRO : 0;
442 attributes |= symbol.SystemModal ? WindowsInstallerConstants.MsidbDialogAttributesSysModal : 0;
443 attributes |= symbol.TrackDiskSpace ? WindowsInstallerConstants.MsidbDialogAttributesTrackDiskSpace : 0;
444
445 var row = this.CreateRow(symbol, "Dialog");
446 row[0] = symbol.Id.Id;
447 row[1] = symbol.HCentering;
448 row[2] = symbol.VCentering;
449 row[3] = symbol.Width;
450 row[4] = symbol.Height;
451 row[5] = attributes;
452 row[6] = symbol.Title;
453 row[7] = symbol.FirstControlRef;
454 row[8] = symbol.DefaultControlRef;
455 row[9] = symbol.CancelControlRef;
456
457 this.Data.EnsureTable(this.TableDefinitions["ListBox"]);
458 }
459
460 private void AddDirectorySymbol(DirectorySymbol symbol)
461 {
462 if (String.IsNullOrEmpty(symbol.ShortName) && symbol.Name != null && !symbol.Name.Equals(".") && !symbol.Name.Equals("SourceDir") && !Common.IsValidShortFilename(symbol.Name, false))
463 {
464 symbol.ShortName = CreateShortName(symbol.Name, false, false, "Directory", symbol.ParentDirectoryRef);
465 }
466
467 if (String.IsNullOrEmpty(symbol.SourceShortName) && !String.IsNullOrEmpty(symbol.SourceName) && !Common.IsValidShortFilename(symbol.SourceName, false))
468 {
469 symbol.SourceShortName = CreateShortName(symbol.SourceName, false, false, "Directory", symbol.ParentDirectoryRef);
470 }
471
472 var sourceName = GetMsiFilenameValue(symbol.SourceShortName, symbol.SourceName);
473 var targetName = GetMsiFilenameValue(symbol.ShortName, symbol.Name);
474
475 if (String.IsNullOrEmpty(targetName))
476 {
477 targetName = ".";
478 }
479
480 var defaultDir = String.IsNullOrEmpty(sourceName) ? targetName : targetName + ":" + sourceName;
481
482 var row = this.CreateRow(symbol, "Directory");
483 row[0] = symbol.Id.Id;
484 row[1] = symbol.ParentDirectoryRef;
485 row[2] = defaultDir;
486 }
487
488 private void AddDuplicateFileSymbol(DuplicateFileSymbol symbol)
489 {
490 var name = symbol.DestinationName;
491 if (null == symbol.DestinationShortName && null != name && !Common.IsValidShortFilename(name, false))
492 {
493 symbol.DestinationShortName = CreateShortName(name, true, false, "CopyFile", symbol.ComponentRef, symbol.FileRef);
494 }
495
496 var row = this.CreateRow(symbol, "DuplicateFile");
497 row[0] = symbol.Id.Id;
498 row[1] = symbol.ComponentRef;
499 row[2] = symbol.FileRef;
500 row[3] = GetMsiFilenameValue(symbol.DestinationShortName, symbol.DestinationName);
501 row[4] = symbol.DestinationFolder;
502 }
503
504 private void AddEnvironmentSymbol(EnvironmentSymbol symbol)
505 {
506 var action = String.Empty;
507 var system = symbol.System ? "*" : String.Empty;
508 var uninstall = symbol.Permanent ? String.Empty : "-";
509 var value = symbol.Value;
510
511 switch (symbol.Action)
512 {
513 case EnvironmentActionType.Create:
514 action = "+";
515 break;
516 case EnvironmentActionType.Set:
517 action = "=";
518 break;
519 case EnvironmentActionType.Remove:
520 action = "!";
521 break;
522 }
523
524 switch (symbol.Part)
525 {
526 case EnvironmentPartType.First:
527 value = String.Concat(value, symbol.Separator, "[~]");
528 break;
529 case EnvironmentPartType.Last:
530 value = String.Concat("[~]", symbol.Separator, value);
531 break;
532 }
533
534 var row = this.CreateRow(symbol, "Environment");
535 row[0] = symbol.Id.Id;
536 row[1] = String.Concat(action, uninstall, system, symbol.Name);
537 row[2] = value;
538 row[3] = symbol.ComponentRef;
539 }
540
541 private void AddErrorSymbol(ErrorSymbol symbol)
542 {
543 var row = this.CreateRow(symbol, "Error");
544 row[0] = Convert.ToInt32(symbol.Id.Id);
545 row[1] = symbol.Message;
546 }
547
548 private void AddFeatureSymbol(FeatureSymbol symbol)
549 {
550 var attributes = symbol.DisallowAbsent ? WindowsInstallerConstants.MsidbFeatureAttributesUIDisallowAbsent : 0;
551 attributes |= symbol.DisallowAdvertise ? WindowsInstallerConstants.MsidbFeatureAttributesDisallowAdvertise : 0;
552 attributes |= FeatureInstallDefault.FollowParent == symbol.InstallDefault ? WindowsInstallerConstants.MsidbFeatureAttributesFollowParent : 0;
553 attributes |= FeatureInstallDefault.Source == symbol.InstallDefault ? WindowsInstallerConstants.MsidbFeatureAttributesFavorSource : 0;
554 attributes |= FeatureTypicalDefault.Advertise == symbol.TypicalDefault ? WindowsInstallerConstants.MsidbFeatureAttributesFavorAdvertise : 0;
555
556 var row = this.CreateRow(symbol, "Feature");
557 row[0] = symbol.Id.Id;
558 row[1] = symbol.ParentFeatureRef;
559 row[2] = symbol.Title;
560 row[3] = symbol.Description;
561 row[4] = symbol.Display;
562 row[5] = symbol.Level;
563 row[6] = symbol.DirectoryRef;
564 row[7] = attributes;
565 }
566
567 private void AddFileSymbol(FileSymbol symbol)
568 {
569 var name = symbol.Name;
570 if (null == symbol.ShortName && null != name && !Common.IsValidShortFilename(name, false))
571 {
572 symbol.ShortName = CreateShortName(name, true, false, "File", symbol.DirectoryRef);
573 }
574
575 var row = (FileRow)this.CreateRow(symbol, "File");
576 row.File = symbol.Id.Id;
577 row.Component = symbol.ComponentRef;
578 row.FileName = GetMsiFilenameValue(symbol.ShortName, name);
579 row.FileSize = symbol.FileSize;
580 row.Version = symbol.Version;
581 row.Language = symbol.Language;
582 row.DiskId = symbol.DiskId ?? 1; // TODO: is 1 the correct thing to default here
583 row.Sequence = symbol.Sequence;
584 row.Source = symbol.Source.Path;
585
586 var attributes = (symbol.Attributes & FileSymbolAttributes.Checksum) == FileSymbolAttributes.Checksum ? WindowsInstallerConstants.MsidbFileAttributesChecksum : 0;
587 attributes |= (symbol.Attributes & FileSymbolAttributes.Compressed) == FileSymbolAttributes.Compressed ? WindowsInstallerConstants.MsidbFileAttributesCompressed : 0;
588 attributes |= (symbol.Attributes & FileSymbolAttributes.Uncompressed) == FileSymbolAttributes.Uncompressed ? WindowsInstallerConstants.MsidbFileAttributesNoncompressed : 0;
589 attributes |= (symbol.Attributes & FileSymbolAttributes.Hidden) == FileSymbolAttributes.Hidden ? WindowsInstallerConstants.MsidbFileAttributesHidden : 0;
590 attributes |= (symbol.Attributes & FileSymbolAttributes.ReadOnly) == FileSymbolAttributes.ReadOnly ? WindowsInstallerConstants.MsidbFileAttributesReadOnly : 0;
591 attributes |= (symbol.Attributes & FileSymbolAttributes.System) == FileSymbolAttributes.System ? WindowsInstallerConstants.MsidbFileAttributesSystem : 0;
592 attributes |= (symbol.Attributes & FileSymbolAttributes.Vital) == FileSymbolAttributes.Vital ? WindowsInstallerConstants.MsidbFileAttributesVital : 0;
593 row.Attributes = attributes;
594
595 if (symbol.FontTitle != null)
596 {
597 var fontRow = this.CreateRow(symbol, "Font");
598 fontRow[0] = symbol.Id.Id;
599 fontRow[1] = symbol.FontTitle;
600 }
601
602 if (symbol.SelfRegCost.HasValue)
603 {
604 var selfRegRow = this.CreateRow(symbol, "SelfReg");
605 selfRegRow[0] = symbol.Id.Id;
606 selfRegRow[1] = symbol.SelfRegCost.Value;
607 }
608 }
609
610 private void AddIniFileSymbol(IniFileSymbol symbol)
611 {
612 var tableName = (IniFileActionType.AddLine == symbol.Action || IniFileActionType.AddTag == symbol.Action || IniFileActionType.CreateLine == symbol.Action) ? "IniFile" : "RemoveIniFile";
613
614 var name = symbol.FileName;
615 if (null == symbol.ShortFileName && null != name && !Common.IsValidShortFilename(name, false))
616 {
617 symbol.ShortFileName = CreateShortName(name, true, false, "IniFile", symbol.ComponentRef);
618 }
619
620 var row = this.CreateRow(symbol, tableName);
621 row[0] = symbol.Id.Id;
622 row[1] = GetMsiFilenameValue(symbol.ShortFileName, name);
623 row[2] = symbol.DirProperty;
624 row[3] = symbol.Section;
625 row[4] = symbol.Key;
626 row[5] = symbol.Value;
627 row[6] = symbol.Action;
628 row[7] = symbol.ComponentRef;
629 }
630
631 private void AddIniLocatorSymbol(IniLocatorSymbol symbol)
632 {
633 var name = symbol.FileName;
634 if (null == symbol.ShortFileName && null != name && !Common.IsValidShortFilename(name, false))
635 {
636 symbol.ShortFileName = CreateShortName(name, true, false, "IniFileSearch");
637 }
638
639 var row = this.CreateRow(symbol, "IniLocator");
640 row[0] = symbol.Id.Id;
641 row[1] = GetMsiFilenameValue(symbol.ShortFileName, name);
642 row[2] = symbol.Section;
643 row[3] = symbol.Key;
644 row[4] = symbol.Field;
645 row[5] = symbol.Type;
646 }
647
648 private void AddMediaSymbol(MediaSymbol symbol)
649 {
650 if (this.Section.Type != SectionType.Module)
651 {
652 var row = (MediaRow)this.CreateRow(symbol, "Media");
653 row.DiskId = symbol.DiskId;
654 row.LastSequence = symbol.LastSequence ?? 0;
655 row.DiskPrompt = symbol.DiskPrompt;
656 row.Cabinet = symbol.Cabinet;
657 row.VolumeLabel = symbol.VolumeLabel;
658 row.Source = symbol.Source;
659 }
660 }
661
662 private void AddModuleConfigurationSymbol(ModuleConfigurationSymbol symbol)
663 {
664 var row = this.CreateRow(symbol, "ModuleConfiguration");
665 row[0] = symbol.Id.Id;
666 row[1] = symbol.Format;
667 row[2] = symbol.Type;
668 row[3] = symbol.ContextData;
669 row[4] = symbol.DefaultValue;
670 row[5] = (symbol.KeyNoOrphan ? WindowsInstallerConstants.MsidbMsmConfigurableOptionKeyNoOrphan : 0) |
671 (symbol.NonNullable ? WindowsInstallerConstants.MsidbMsmConfigurableOptionNonNullable : 0);
672 row[6] = symbol.DisplayName;
673 row[7] = symbol.Description;
674 row[8] = symbol.HelpLocation;
675 row[9] = symbol.HelpKeyword;
676 }
677
678 private void AddMsiEmbeddedUISymbol(MsiEmbeddedUISymbol symbol)
679 {
680 var attributes = symbol.EntryPoint ? WindowsInstallerConstants.MsidbEmbeddedUI : 0;
681 attributes |= symbol.SupportsBasicUI ? WindowsInstallerConstants.MsidbEmbeddedHandlesBasic : 0;
682
683 var row = this.CreateRow(symbol, "MsiEmbeddedUI");
684 row[0] = symbol.Id.Id;
685 row[1] = symbol.FileName;
686 row[2] = attributes;
687 row[3] = symbol.MessageFilter;
688 row[4] = symbol.Source;
689 }
690
691 private void AddMsiServiceConfigSymbol(MsiServiceConfigSymbol symbol)
692 {
693 var events = symbol.OnInstall ? WindowsInstallerConstants.MsidbServiceConfigEventInstall : 0;
694 events |= symbol.OnReinstall ? WindowsInstallerConstants.MsidbServiceConfigEventReinstall : 0;
695 events |= symbol.OnUninstall ? WindowsInstallerConstants.MsidbServiceConfigEventUninstall : 0;
696
697 var row = this.CreateRow(symbol, "MsiServiceConfigFailureActions");
698 row[0] = symbol.Id.Id;
699 row[1] = symbol.Name;
700 row[2] = events;
701 row[3] = symbol.ConfigType;
702 row[4] = symbol.Argument;
703 row[5] = symbol.ComponentRef;
704 }
705
706 private void AddMsiServiceConfigFailureActionsSymbol(MsiServiceConfigFailureActionsSymbol symbol)
707 {
708 var events = symbol.OnInstall ? WindowsInstallerConstants.MsidbServiceConfigEventInstall : 0;
709 events |= symbol.OnReinstall ? WindowsInstallerConstants.MsidbServiceConfigEventReinstall : 0;
710 events |= symbol.OnUninstall ? WindowsInstallerConstants.MsidbServiceConfigEventUninstall : 0;
711
712 var row = this.CreateRow(symbol, "MsiServiceConfig");
713 row[0] = symbol.Id.Id;
714 row[1] = symbol.Name;
715 row[2] = events;
716 row[3] = symbol.ResetPeriod.HasValue ? symbol.ResetPeriod : null;
717 row[4] = symbol.RebootMessage ?? "[~]";
718 row[5] = symbol.Command ?? "[~]";
719 row[6] = symbol.Actions;
720 row[7] = symbol.DelayActions;
721 row[8] = symbol.ComponentRef;
722 }
723
724 private void AddMoveFileSymbol(MoveFileSymbol symbol)
725 {
726 var name = symbol.DestinationName;
727 if (null == symbol.DestinationShortName && null != name && !Common.IsValidShortFilename(name, false))
728 {
729 symbol.DestinationShortName = CreateShortName(name, true, false, "MoveFile", symbol.ComponentRef);
730 }
731
732 var row = this.CreateRow(symbol, "MoveFile");
733 row[0] = symbol.Id.Id;
734 row[1] = symbol.ComponentRef;
735 row[2] = symbol.SourceName;
736 row[3] = GetMsiFilenameValue(symbol.DestinationShortName, symbol.DestinationName);
737 row[4] = symbol.SourceFolder;
738 row[5] = symbol.DestFolder;
739 row[6] = symbol.Delete ? WindowsInstallerConstants.MsidbMoveFileOptionsMove : 0;
740 }
741
742 private void AddPropertySymbol(PropertySymbol symbol)
743 {
744 if (String.IsNullOrEmpty(symbol.Value))
745 {
746 return;
747 }
748
749 var row = (PropertyRow)this.CreateRow(symbol, "Property");
750 row.Property = symbol.Id.Id;
751 row.Value = symbol.Value;
752 }
753
754 private void AddRemoveFileSymbol(RemoveFileSymbol symbol)
755 {
756 var name = symbol.FileName;
757 if (null == symbol.ShortFileName && null != name && !Common.IsValidShortFilename(name, false))
758 {
759 symbol.ShortFileName = CreateShortName(name, true, false, "RemoveFile", symbol.ComponentRef);
760 }
761
762 var installMode = symbol.OnInstall == true ? WindowsInstallerConstants.MsidbRemoveFileInstallModeOnInstall : 0;
763 installMode |= symbol.OnUninstall == true ? WindowsInstallerConstants.MsidbRemoveFileInstallModeOnRemove : 0;
764
765 var row = this.CreateRow(symbol, "RemoveFile");
766 row[0] = symbol.Id.Id;
767 row[1] = symbol.ComponentRef;
768 row[2] = GetMsiFilenameValue(symbol.ShortFileName, symbol.FileName);
769 row[3] = symbol.DirPropertyRef;
770 row[4] = installMode;
771 }
772
773 private void AddRegistrySymbol(RegistrySymbol symbol)
774 {
775 var value = symbol.Value;
776
777 switch (symbol.ValueType)
778 {
779 case RegistryValueType.Binary:
780 value = String.Concat("#x", value);
781 break;
782 case RegistryValueType.Expandable:
783 value = String.Concat("#%", value);
784 break;
785 case RegistryValueType.Integer:
786 value = String.Concat("#", value);
787 break;
788 case RegistryValueType.MultiString:
789 switch (symbol.ValueAction)
790 {
791 case RegistryValueActionType.Append:
792 value = String.Concat("[~]", value);
793 break;
794 case RegistryValueActionType.Prepend:
795 value = String.Concat(value, "[~]");
796 break;
797 case RegistryValueActionType.Write:
798 default:
799 if (null != value && -1 == value.IndexOf("[~]", StringComparison.Ordinal))
800 {
801 value = String.Format(CultureInfo.InvariantCulture, "[~]{0}[~]", value);
802 }
803 break;
804 }
805 break;
806 case RegistryValueType.String:
807 // escape the leading '#' character for string registry keys
808 if (null != value && value.StartsWith("#", StringComparison.Ordinal))
809 {
810 value = String.Concat("#", value);
811 }
812 break;
813 }
814
815 var row = this.CreateRow(symbol, "Registry");
816 row[0] = symbol.Id.Id;
817 row[1] = symbol.Root;
818 row[2] = symbol.Key;
819 row[3] = symbol.Name;
820 row[4] = value;
821 row[5] = symbol.ComponentRef;
822 }
823
824 private void AddRegLocatorSymbol(RegLocatorSymbol symbol)
825 {
826 var type = (int)symbol.Type;
827 type |= symbol.Win64 ? WindowsInstallerConstants.MsidbLocatorType64bit : 0;
828
829 var row = this.CreateRow(symbol, "RegLocator");
830 row[0] = symbol.Id.Id;
831 row[1] = symbol.Root;
832 row[2] = symbol.Key;
833 row[3] = symbol.Name;
834 row[4] = type;
835 }
836
837 private void AddRemoveRegistrySymbol(RemoveRegistrySymbol symbol)
838 {
839 if (symbol.Action == RemoveRegistryActionType.RemoveOnInstall)
840 {
841 var row = this.CreateRow(symbol, "RemoveRegistry");
842 row[0] = symbol.Id.Id;
843 row[1] = symbol.Root;
844 row[2] = symbol.Key;
845 row[3] = symbol.Name;
846 row[4] = symbol.ComponentRef;
847 }
848 else // Registry table is used to remove registry keys on uninstall.
849 {
850 var row = this.CreateRow(symbol, "Registry");
851 row[0] = symbol.Id.Id;
852 row[1] = symbol.Root;
853 row[2] = symbol.Key;
854 row[3] = symbol.Name;
855 row[5] = symbol.ComponentRef;
856 }
857 }
858
859 private void AddServiceControlSymbol(ServiceControlSymbol symbol)
860 {
861 var events = symbol.InstallRemove ? WindowsInstallerConstants.MsidbServiceControlEventDelete : 0;
862 events |= symbol.UninstallRemove ? WindowsInstallerConstants.MsidbServiceControlEventUninstallDelete : 0;
863 events |= symbol.InstallStart ? WindowsInstallerConstants.MsidbServiceControlEventStart : 0;
864 events |= symbol.UninstallStart ? WindowsInstallerConstants.MsidbServiceControlEventUninstallStart : 0;
865 events |= symbol.InstallStop ? WindowsInstallerConstants.MsidbServiceControlEventStop : 0;
866 events |= symbol.UninstallStop ? WindowsInstallerConstants.MsidbServiceControlEventUninstallStop : 0;
867
868 var row = this.CreateRow(symbol, "ServiceControl");
869 row[0] = symbol.Id.Id;
870 row[1] = symbol.Name;
871 row[2] = events;
872 row[3] = symbol.Arguments;
873 if (symbol.Wait.HasValue)
874 {
875 row[4] = symbol.Wait.Value ? 1 : 0;
876 }
877 row[5] = symbol.ComponentRef;
878 }
879
880 private void AddServiceInstallSymbol(ServiceInstallSymbol symbol)
881 {
882 var errorControl = (int)symbol.ErrorControl;
883 errorControl |= symbol.Vital ? WindowsInstallerConstants.MsidbServiceInstallErrorControlVital : 0;
884
885 var serviceType = (int)symbol.ServiceType;
886 serviceType |= symbol.Interactive ? WindowsInstallerConstants.MsidbServiceInstallInteractive : 0;
887
888 var row = this.CreateRow(symbol, "ServiceInstall");
889 row[0] = symbol.Id.Id;
890 row[1] = symbol.Name;
891 row[2] = symbol.DisplayName;
892 row[3] = serviceType;
893 row[4] = (int)symbol.StartType;
894 row[5] = errorControl;
895 row[6] = symbol.LoadOrderGroup;
896 row[7] = symbol.Dependencies;
897 row[8] = symbol.StartName;
898 row[9] = symbol.Password;
899 row[10] = symbol.Arguments;
900 row[11] = symbol.ComponentRef;
901 row[12] = symbol.Description;
902 }
903
904 private void AddShortcutSymbol(ShortcutSymbol symbol)
905 {
906 var name = symbol.Name;
907 if (null == symbol.ShortName && null != name && !Common.IsValidShortFilename(name, false))
908 {
909 symbol.ShortName = CreateShortName(name, true, false, "Shortcut", symbol.ComponentRef, symbol.DirectoryRef);
910 }
911
912 var row = this.CreateRow(symbol, "Shortcut");
913 row[0] = symbol.Id.Id;
914 row[1] = symbol.DirectoryRef;
915 row[2] = GetMsiFilenameValue(symbol.ShortName, name);
916 row[3] = symbol.ComponentRef;
917 row[4] = symbol.Target;
918 row[5] = symbol.Arguments;
919 row[6] = symbol.Description;
920 row[7] = symbol.Hotkey;
921 row[8] = symbol.IconRef;
922 row[9] = symbol.IconIndex;
923 row[10] = (int?)symbol.Show;
924 row[11] = symbol.WorkingDirectory;
925 row[12] = symbol.DisplayResourceDll;
926 row[13] = symbol.DisplayResourceId;
927 row[14] = symbol.DescriptionResourceDll;
928 row[15] = symbol.DescriptionResourceId;
929 }
930
931 private void AddTextStyleSymbol(TextStyleSymbol symbol)
932 {
933 var styleBits = symbol.Bold ? WindowsInstallerConstants.MsidbTextStyleStyleBitsBold : 0;
934 styleBits |= symbol.Italic ? WindowsInstallerConstants.MsidbTextStyleStyleBitsItalic : 0;
935 styleBits |= symbol.Strike ? WindowsInstallerConstants.MsidbTextStyleStyleBitsStrike : 0;
936 styleBits |= symbol.Underline ? WindowsInstallerConstants.MsidbTextStyleStyleBitsUnderline : 0;
937
938 long? color = null;
939
940 if (symbol.Red.HasValue || symbol.Green.HasValue || symbol.Blue.HasValue)
941 {
942 color = symbol.Red ?? 0;
943 color += (long)(symbol.Green ?? 0) * 256;
944 color += (long)(symbol.Blue ?? 0) * 65536;
945 }
946
947 var row = this.CreateRow(symbol, "TextStyle");
948 row[0] = symbol.Id.Id;
949 row[1] = symbol.FaceName;
950 row[2] = symbol.Size;
951 row[3] = color;
952 row[4] = styleBits == 0 ? null : (int?)styleBits;
953 }
954
955 private void AddUpgradeSymbol(UpgradeSymbol symbol)
956 {
957 var row = (UpgradeRow)this.CreateRow(symbol, "Upgrade");
958 row.UpgradeCode = symbol.UpgradeCode;
959 row.VersionMin = symbol.VersionMin;
960 row.VersionMax = symbol.VersionMax;
961 row.Language = symbol.Language;
962 row.Remove = symbol.Remove;
963 row.ActionProperty = symbol.ActionProperty;
964
965 var attributes = symbol.MigrateFeatures ? WindowsInstallerConstants.MsidbUpgradeAttributesMigrateFeatures : 0;
966 attributes |= symbol.OnlyDetect ? WindowsInstallerConstants.MsidbUpgradeAttributesOnlyDetect : 0;
967 attributes |= symbol.IgnoreRemoveFailures ? WindowsInstallerConstants.MsidbUpgradeAttributesIgnoreRemoveFailure : 0;
968 attributes |= symbol.VersionMinInclusive ? WindowsInstallerConstants.MsidbUpgradeAttributesVersionMinInclusive : 0;
969 attributes |= symbol.VersionMaxInclusive ? WindowsInstallerConstants.MsidbUpgradeAttributesVersionMaxInclusive : 0;
970 attributes |= symbol.ExcludeLanguages ? WindowsInstallerConstants.MsidbUpgradeAttributesLanguagesExclusive : 0;
971 row.Attributes = attributes;
972 }
973
974 private void AddWixActionSymbol(WixActionSymbol symbol)
975 {
976 // Get the table definition for the action (and ensure the proper table exists for a module).
977 string sequenceTableName = null;
978 switch (symbol.SequenceTable)
979 {
980 case SequenceTable.AdminExecuteSequence:
981 if (OutputType.Module == this.Data.Type)
982 {
983 this.Data.EnsureTable(this.TableDefinitions["AdminExecuteSequence"]);
984 sequenceTableName = "ModuleAdminExecuteSequence";
985 }
986 else
987 {
988 sequenceTableName = "AdminExecuteSequence";
989 }
990 break;
991 case SequenceTable.AdminUISequence:
992 if (OutputType.Module == this.Data.Type)
993 {
994 this.Data.EnsureTable(this.TableDefinitions["AdminUISequence"]);
995 sequenceTableName = "ModuleAdminUISequence";
996 }
997 else
998 {
999 sequenceTableName = "AdminUISequence";
1000 }
1001 break;
1002 case SequenceTable.AdvertiseExecuteSequence:
1003 if (OutputType.Module == this.Data.Type)
1004 {
1005 this.Data.EnsureTable(this.TableDefinitions["AdvtExecuteSequence"]);
1006 sequenceTableName = "ModuleAdvtExecuteSequence";
1007 }
1008 else
1009 {
1010 sequenceTableName = "AdvtExecuteSequence";
1011 }
1012 break;
1013 case SequenceTable.InstallExecuteSequence:
1014 if (OutputType.Module == this.Data.Type)
1015 {
1016 this.Data.EnsureTable(this.TableDefinitions["InstallExecuteSequence"]);
1017 sequenceTableName = "ModuleInstallExecuteSequence";
1018 }
1019 else
1020 {
1021 sequenceTableName = "InstallExecuteSequence";
1022 }
1023 break;
1024 case SequenceTable.InstallUISequence:
1025 if (OutputType.Module == this.Data.Type)
1026 {
1027 this.Data.EnsureTable(this.TableDefinitions["InstallUISequence"]);
1028 sequenceTableName = "ModuleInstallUISequence";
1029 }
1030 else
1031 {
1032 sequenceTableName = "InstallUISequence";
1033 }
1034 break;
1035 }
1036
1037 // create the action sequence row in the output
1038 var row = this.CreateRow(symbol, sequenceTableName);
1039
1040 if (SectionType.Module == this.Section.Type)
1041 {
1042 row[0] = symbol.Action;
1043 if (0 != symbol.Sequence)
1044 {
1045 row[1] = symbol.Sequence;
1046 }
1047 else
1048 {
1049 var after = (null == symbol.Before);
1050 row[2] = after ? symbol.After : symbol.Before;
1051 row[3] = after ? 1 : 0;
1052 }
1053 row[4] = symbol.Condition;
1054 }
1055 else
1056 {
1057 row[0] = symbol.Action;
1058 row[1] = symbol.Condition;
1059 row[2] = symbol.Sequence;
1060 }
1061 }
1062
1063 private void IndexCustomTableCellSymbol(WixCustomTableCellSymbol wixCustomTableCellSymbol, Dictionary<string, List<WixCustomTableCellSymbol>> cellsByTableAndRowId)
1064 {
1065 var tableAndRowId = wixCustomTableCellSymbol.TableRef + "/" + wixCustomTableCellSymbol.RowId;
1066 if (!cellsByTableAndRowId.TryGetValue(tableAndRowId, out var cells))
1067 {
1068 cells = new List<WixCustomTableCellSymbol>();
1069 cellsByTableAndRowId.Add(tableAndRowId, cells);
1070 }
1071
1072 cells.Add(wixCustomTableCellSymbol);
1073 }
1074
1075 private void AddIndexedCellSymbols(Dictionary<string, List<WixCustomTableCellSymbol>> cellsByTableAndRowId)
1076 {
1077 foreach (var rowOfCells in cellsByTableAndRowId.Values)
1078 {
1079 var firstCellSymbol = rowOfCells[0];
1080 var customTableDefinition = this.TableDefinitions[firstCellSymbol.TableRef];
1081
1082 if (customTableDefinition.Unreal)
1083 {
1084 continue;
1085 }
1086
1087 var customRow = this.CreateRow(firstCellSymbol, customTableDefinition);
1088 var customRowFieldsByColumnName = customRow.Fields.ToDictionary(f => f.Column.Name);
1089
1090#if TODO // SectionId seems like a good thing to preserve.
1091 customRow.SectionId = symbol.SectionId;
1092#endif
1093 foreach (var cell in rowOfCells)
1094 {
1095 var data = cell.Data;
1096
1097 if (customRowFieldsByColumnName.TryGetValue(cell.ColumnRef, out var rowField))
1098 {
1099 if (!String.IsNullOrEmpty(data))
1100 {
1101 if (rowField.Column.Type == ColumnType.Number)
1102 {
1103 try
1104 {
1105 rowField.Data = Convert.ToInt32(data, CultureInfo.InvariantCulture);
1106 }
1107 catch (FormatException)
1108 {
1109 this.Messaging.Write(ErrorMessages.IllegalIntegerValue(cell.SourceLineNumbers, rowField.Column.Name, customTableDefinition.Name, data));
1110 }
1111 catch (OverflowException)
1112 {
1113 this.Messaging.Write(ErrorMessages.IllegalIntegerValue(cell.SourceLineNumbers, rowField.Column.Name, customTableDefinition.Name, data));
1114 }
1115 }
1116 else if (rowField.Column.Category == ColumnCategory.Identifier)
1117 {
1118 if (Common.IsIdentifier(data) || Common.IsValidBinderVariable(data) || ColumnCategory.Formatted == rowField.Column.Category)
1119 {
1120 rowField.Data = data;
1121 }
1122 else
1123 {
1124 this.Messaging.Write(ErrorMessages.IllegalIdentifier(cell.SourceLineNumbers, "Data", data));
1125 }
1126 }
1127 else
1128 {
1129 rowField.Data = data;
1130 }
1131 }
1132 }
1133 else
1134 {
1135 this.Messaging.Write(ErrorMessages.UnexpectedCustomTableColumn(cell.SourceLineNumbers, cell.ColumnRef));
1136 }
1137 }
1138
1139 for (var i = 0; i < customTableDefinition.Columns.Length; ++i)
1140 {
1141 if (!customTableDefinition.Columns[i].Nullable && (null == customRow.Fields[i].Data || 0 == customRow.Fields[i].Data.ToString().Length))
1142 {
1143 this.Messaging.Write(ErrorMessages.NoDataForColumn(firstCellSymbol.SourceLineNumbers, customTableDefinition.Columns[i].Name, customTableDefinition.Name));
1144 }
1145 }
1146 }
1147 }
1148
1149 private void AddWixEnsureTableSymbol(WixEnsureTableSymbol symbol)
1150 {
1151 var tableDefinition = this.TableDefinitions[symbol.Table];
1152 this.Data.EnsureTable(tableDefinition);
1153 }
1154
1155 private bool AddSymbolFromExtension(IntermediateSymbol symbol)
1156 {
1157 foreach (var extension in this.BackendExtensions)
1158 {
1159 if (extension.TryProcessSymbol(this.Section, symbol, this.Data, this.TableDefinitions))
1160 {
1161 return true;
1162 }
1163 }
1164
1165 return false;
1166 }
1167
1168 private bool AddSymbolDefaultly(IntermediateSymbol symbol) =>
1169 this.BackendHelper.TryAddSymbolToMatchingTableDefinitions(this.Section, symbol, this.Data, this.TableDefinitions);
1170
1171 private static OutputType SectionTypeToOutputType(SectionType type)
1172 {
1173 switch (type)
1174 {
1175 case SectionType.Bundle:
1176 return OutputType.Bundle;
1177 case SectionType.Module:
1178 return OutputType.Module;
1179 case SectionType.Product:
1180 return OutputType.Product;
1181 case SectionType.PatchCreation:
1182 return OutputType.PatchCreation;
1183 case SectionType.Patch:
1184 return OutputType.Patch;
1185
1186 default:
1187 throw new ArgumentOutOfRangeException(nameof(type));
1188 }
1189 }
1190
1191 private Row CreateRow(IntermediateSymbol symbol, string tableDefinitionName) =>
1192 this.CreateRow(symbol, this.TableDefinitions[tableDefinitionName]);
1193
1194 private Row CreateRow(IntermediateSymbol symbol, TableDefinition tableDefinition) =>
1195 this.BackendHelper.CreateRow(this.Section, symbol, this.Data, tableDefinition);
1196
1197 private static string GetMsiFilenameValue(string shortName, string longName)
1198 {
1199 if (String.IsNullOrEmpty(shortName) || String.Equals(shortName, longName, StringComparison.OrdinalIgnoreCase))
1200 {
1201 return longName;
1202 }
1203 else
1204 {
1205 return shortName + "|" + longName;
1206 }
1207 }
1208
1209 private static string CreateShortName(string longName, bool keepExtension, bool allowWildcards, params string[] args)
1210 {
1211 longName = longName.ToLowerInvariant();
1212
1213 // collect all the data
1214 var strings = new List<string>(1 + args.Length);
1215 strings.Add(longName);
1216 strings.AddRange(args);
1217
1218 // prepare for hashing
1219 var stringData = String.Join("|", strings);
1220 var data = Encoding.UTF8.GetBytes(stringData);
1221
1222 // hash the data
1223 byte[] hash;
1224 using (var sha1 = new SHA1CryptoServiceProvider())
1225 {
1226 hash = sha1.ComputeHash(data);
1227 }
1228
1229 // generate the short file/directory name without an extension
1230 var shortName = new StringBuilder(Convert.ToBase64String(hash));
1231 shortName.Length = 8;
1232 shortName.Replace('+', '-').Replace('/', '_');
1233
1234 if (keepExtension)
1235 {
1236 var extension = Path.GetExtension(longName);
1237
1238 if (4 < extension.Length)
1239 {
1240 extension = extension.Substring(0, 4);
1241 }
1242
1243 shortName.Append(extension);
1244
1245 // check the generated short name to ensure its still legal (the extension may not be legal)
1246 if (!Common.IsValidShortFilename(shortName.ToString(), allowWildcards))
1247 {
1248 // remove the extension (by truncating the generated file name back to the generated characters)
1249 shortName.Length -= extension.Length;
1250 }
1251 }
1252
1253 return shortName.ToString().ToLowerInvariant();
1254 }
1255 }
1256}