aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core.WindowsInstaller/Bind/CreateWindowsInstallerDataFromIRCommand.cs
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2021-04-05 12:55:26 -0700
committerRob Mensching <rob@firegiant.com>2021-04-06 16:10:05 -0700
commit860f77f7c9d522074dc7e44cfe11281efd20687f (patch)
tree49527e82264f2dac88247885e937f935ae2ac658 /src/WixToolset.Core.WindowsInstaller/Bind/CreateWindowsInstallerDataFromIRCommand.cs
parent94db5671e85ce63487e3a415251cad0eb6abe3d1 (diff)
downloadwix-860f77f7c9d522074dc7e44cfe11281efd20687f.tar.gz
wix-860f77f7c9d522074dc7e44cfe11281efd20687f.tar.bz2
wix-860f77f7c9d522074dc7e44cfe11281efd20687f.zip
Introduce "Subdirectory" which simplifies inline directory syntax
Completes wixtoolset/issues#4727
Diffstat (limited to 'src/WixToolset.Core.WindowsInstaller/Bind/CreateWindowsInstallerDataFromIRCommand.cs')
-rw-r--r--src/WixToolset.Core.WindowsInstaller/Bind/CreateWindowsInstallerDataFromIRCommand.cs58
1 files changed, 51 insertions, 7 deletions
diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/CreateWindowsInstallerDataFromIRCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/CreateWindowsInstallerDataFromIRCommand.cs
index 1bd00900..cee87df0 100644
--- a/src/WixToolset.Core.WindowsInstaller/Bind/CreateWindowsInstallerDataFromIRCommand.cs
+++ b/src/WixToolset.Core.WindowsInstaller/Bind/CreateWindowsInstallerDataFromIRCommand.cs
@@ -18,6 +18,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind
18 18
19 internal class CreateWindowsInstallerDataFromIRCommand 19 internal class CreateWindowsInstallerDataFromIRCommand
20 { 20 {
21 private static readonly char[] PathSeparatorChars = new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar };
22
21 public CreateWindowsInstallerDataFromIRCommand(IMessaging messaging, IntermediateSection section, TableDefinitionCollection tableDefinitions, int codepage, IEnumerable<IWindowsInstallerBackendBinderExtension> backendExtensions, IWindowsInstallerBackendHelper backendHelper) 23 public CreateWindowsInstallerDataFromIRCommand(IMessaging messaging, IntermediateSection section, TableDefinitionCollection tableDefinitions, int codepage, IEnumerable<IWindowsInstallerBackendBinderExtension> backendExtensions, IWindowsInstallerBackendHelper backendHelper)
22 { 24 {
23 this.Messaging = messaging; 25 this.Messaging = messaging;
@@ -488,18 +490,23 @@ namespace WixToolset.Core.WindowsInstaller.Bind
488 490
489 private void AddDirectorySymbol(DirectorySymbol symbol) 491 private void AddDirectorySymbol(DirectorySymbol symbol)
490 { 492 {
491 if (String.IsNullOrEmpty(symbol.ShortName) && symbol.Name != null && !symbol.Name.Equals(".") && !symbol.Name.Equals("SourceDir") && !this.BackendHelper.IsValidShortFilename(symbol.Name, false)) 493 (var name, var parentDir) = this.AddDirectorySubdirectories(symbol);
494
495 var shortName = symbol.ShortName;
496 var sourceShortname = symbol.SourceShortName;
497
498 if (String.IsNullOrEmpty(shortName) && name != null && name != "." && name != "SourceDir" && !this.BackendHelper.IsValidShortFilename(name, false))
492 { 499 {
493 symbol.ShortName = this.CreateShortName(symbol.Name, false, "Directory", symbol.ParentDirectoryRef); 500 shortName = this.CreateShortName(name, false, "Directory", symbol.ParentDirectoryRef);
494 } 501 }
495 502
496 if (String.IsNullOrEmpty(symbol.SourceShortName) && !String.IsNullOrEmpty(symbol.SourceName) && !this.BackendHelper.IsValidShortFilename(symbol.SourceName, false)) 503 if (String.IsNullOrEmpty(sourceShortname) && !String.IsNullOrEmpty(symbol.SourceName) && !this.BackendHelper.IsValidShortFilename(symbol.SourceName, false))
497 { 504 {
498 symbol.SourceShortName = this.CreateShortName(symbol.SourceName, false, "Directory", symbol.ParentDirectoryRef); 505 sourceShortname = this.CreateShortName(symbol.SourceName, false, "Directory", symbol.ParentDirectoryRef);
499 } 506 }
500 507
501 var sourceName = CreateMsiFilename(symbol.SourceShortName, symbol.SourceName); 508 var sourceName = CreateMsiFilename(sourceShortname, symbol.SourceName);
502 var targetName = CreateMsiFilename(symbol.ShortName, symbol.Name); 509 var targetName = CreateMsiFilename(shortName, name);
503 510
504 if (String.IsNullOrEmpty(targetName)) 511 if (String.IsNullOrEmpty(targetName))
505 { 512 {
@@ -510,7 +517,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
510 517
511 var row = this.CreateRow(symbol, "Directory"); 518 var row = this.CreateRow(symbol, "Directory");
512 row[0] = symbol.Id.Id; 519 row[0] = symbol.Id.Id;
513 row[1] = symbol.ParentDirectoryRef; 520 row[1] = parentDir;
514 row[2] = defaultDir; 521 row[2] = defaultDir;
515 522
516 if (OutputType.Module == this.Data.Type) 523 if (OutputType.Module == this.Data.Type)
@@ -1267,6 +1274,43 @@ namespace WixToolset.Core.WindowsInstaller.Bind
1267 } 1274 }
1268 } 1275 }
1269 1276
1277 private (string, string) AddDirectorySubdirectories(DirectorySymbol symbol)
1278 {
1279 var directory = symbol.Name.Trim(PathSeparatorChars);
1280 var parentDir = symbol.ParentDirectoryRef ?? (symbol.Id.Id == "TARGETDIR" ? null : "TARGETDIR");
1281
1282 var start = 0;
1283 var end = directory.IndexOfAny(PathSeparatorChars);
1284 var path = String.Empty;
1285
1286 while (start <= end)
1287 {
1288 var subdirectoryName = directory.Substring(start, end - start);
1289
1290 if (!String.IsNullOrEmpty(subdirectoryName))
1291 {
1292 path = Path.Combine(path, subdirectoryName);
1293
1294 var id = this.BackendHelper.GenerateIdentifier("d", symbol.ParentDirectoryRef, path);
1295 var shortnameSubdirectory = this.BackendHelper.IsValidShortFilename(subdirectoryName, false) ? null : this.CreateShortName(subdirectoryName, false, "Directory", symbol.ParentDirectoryRef);
1296
1297 var subdirectoryRow = this.CreateRow(symbol, "Directory");
1298 subdirectoryRow[0] = id;
1299 subdirectoryRow[1] = parentDir;
1300 subdirectoryRow[2] = CreateMsiFilename(shortnameSubdirectory, subdirectoryName);
1301
1302 parentDir = id;
1303 }
1304
1305 start = end + 1;
1306 end = symbol.Name.IndexOfAny(PathSeparatorChars, start);
1307 }
1308
1309 var name = (start == 0) ? directory : directory.Substring(start);
1310
1311 return (name, parentDir);
1312 }
1313
1270 private void EnsureRequiredTables() 1314 private void EnsureRequiredTables()
1271 { 1315 {
1272 // check for missing table and add them or display an error as appropriate 1316 // check for missing table and add them or display an error as appropriate