aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core.WindowsInstaller/Unbind/ExtractCabinetsCommand.cs
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2018-10-24 21:00:13 -0700
committerRob Mensching <rob@robmensching.com>2018-10-24 21:17:34 -0700
commit0ecb2ac1ba28d33b0b3d17a2d7134d2f5485814d (patch)
tree42ce582bfc472c8b1bada41696670ed94e6ddff6 /src/WixToolset.Core.WindowsInstaller/Unbind/ExtractCabinetsCommand.cs
parent0a67f66835c882763e1504895cbec3acb9284f3d (diff)
downloadwix-0ecb2ac1ba28d33b0b3d17a2d7134d2f5485814d.tar.gz
wix-0ecb2ac1ba28d33b0b3d17a2d7134d2f5485814d.tar.bz2
wix-0ecb2ac1ba28d33b0b3d17a2d7134d2f5485814d.zip
Minor code clean up to match .editorconfig
Diffstat (limited to 'src/WixToolset.Core.WindowsInstaller/Unbind/ExtractCabinetsCommand.cs')
-rw-r--r--src/WixToolset.Core.WindowsInstaller/Unbind/ExtractCabinetsCommand.cs34
1 files changed, 21 insertions, 13 deletions
diff --git a/src/WixToolset.Core.WindowsInstaller/Unbind/ExtractCabinetsCommand.cs b/src/WixToolset.Core.WindowsInstaller/Unbind/ExtractCabinetsCommand.cs
index ed3161ef..94301727 100644
--- a/src/WixToolset.Core.WindowsInstaller/Unbind/ExtractCabinetsCommand.cs
+++ b/src/WixToolset.Core.WindowsInstaller/Unbind/ExtractCabinetsCommand.cs
@@ -1,10 +1,10 @@
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. 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 2
3namespace WixToolset.Core.WindowsInstaller.Unbind 3namespace WixToolset.Core.WindowsInstaller.Unbind
4{ 4{
5 using System; 5 using System;
6 using System.Collections; 6 using System.Collections;
7 using System.Collections.Specialized; 7 using System.Collections.Generic;
8 using System.Globalization; 8 using System.Globalization;
9 using System.IO; 9 using System.IO;
10 using WixToolset.Core.Native; 10 using WixToolset.Core.Native;
@@ -24,6 +24,8 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
24 this.IntermediateFolder = intermediateFolder; 24 this.IntermediateFolder = intermediateFolder;
25 } 25 }
26 26
27 public string[] ExtractedFiles { get; private set; }
28
27 private Output Output { get; } 29 private Output Output { get; }
28 30
29 private Database Database { get; } 31 private Database Database { get; }
@@ -36,9 +38,9 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
36 38
37 public void Execute() 39 public void Execute()
38 { 40 {
39 string databaseBasePath = Path.GetDirectoryName(this.InputFilePath); 41 var databaseBasePath = Path.GetDirectoryName(this.InputFilePath);
40 StringCollection cabinetFiles = new StringCollection(); 42 var cabinetFiles = new List<string>();
41 SortedList embeddedCabinets = new SortedList(); 43 var embeddedCabinets = new SortedList();
42 44
43 // index all of the cabinet files 45 // index all of the cabinet files
44 if (OutputType.Module == this.Output.Type) 46 if (OutputType.Module == this.Output.Type)
@@ -70,31 +72,31 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
70 // extract the embedded cabinet files from the database 72 // extract the embedded cabinet files from the database
71 if (0 < embeddedCabinets.Count) 73 if (0 < embeddedCabinets.Count)
72 { 74 {
73 using (View streamsView = this.Database.OpenView("SELECT `Data` FROM `_Streams` WHERE `Name` = ?")) 75 using (var streamsView = this.Database.OpenView("SELECT `Data` FROM `_Streams` WHERE `Name` = ?"))
74 { 76 {
75 foreach (int diskId in embeddedCabinets.Keys) 77 foreach (int diskId in embeddedCabinets.Keys)
76 { 78 {
77 using (Record record = new Record(1)) 79 using (var record = new Record(1))
78 { 80 {
79 record.SetString(1, (string)embeddedCabinets[diskId]); 81 record.SetString(1, (string)embeddedCabinets[diskId]);
80 streamsView.Execute(record); 82 streamsView.Execute(record);
81 } 83 }
82 84
83 using (Record record = streamsView.Fetch()) 85 using (var record = streamsView.Fetch())
84 { 86 {
85 if (null != record) 87 if (null != record)
86 { 88 {
87 // since the cabinets are stored in case-sensitive streams inside the msi, but the file system is not case-sensitive, 89 // since the cabinets are stored in case-sensitive streams inside the msi, but the file system is not case-sensitive,
88 // embedded cabinets must be extracted to a canonical file name (like their diskid) to ensure extraction will always work 90 // embedded cabinets must be extracted to a canonical file name (like their diskid) to ensure extraction will always work
89 string cabinetFile = Path.Combine(this.IntermediateFolder, String.Concat("Media", Path.DirectorySeparatorChar, diskId.ToString(CultureInfo.InvariantCulture), ".cab")); 91 var cabinetFile = Path.Combine(this.IntermediateFolder, String.Concat("Media", Path.DirectorySeparatorChar, diskId.ToString(CultureInfo.InvariantCulture), ".cab"));
90 92
91 // ensure the parent directory exists 93 // ensure the parent directory exists
92 Directory.CreateDirectory(Path.GetDirectoryName(cabinetFile)); 94 Directory.CreateDirectory(Path.GetDirectoryName(cabinetFile));
93 95
94 using (FileStream fs = File.Create(cabinetFile)) 96 using (var fs = File.Create(cabinetFile))
95 { 97 {
96 int bytesRead; 98 int bytesRead;
97 byte[] buffer = new byte[512]; 99 var buffer = new byte[512];
98 100
99 while (0 != (bytesRead = record.GetStream(1, buffer, buffer.Length))) 101 while (0 != (bytesRead = record.GetStream(1, buffer, buffer.Length)))
100 { 102 {
@@ -116,7 +118,7 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
116 // extract the cabinet files 118 // extract the cabinet files
117 if (0 < cabinetFiles.Count) 119 if (0 < cabinetFiles.Count)
118 { 120 {
119 string fileDirectory = Path.Combine(this.ExportBasePath, "File"); 121 var fileDirectory = Path.Combine(this.ExportBasePath, "File");
120 122
121 // delete the directory and its files to prevent cab extraction due to an existing file 123 // delete the directory and its files to prevent cab extraction due to an existing file
122 if (Directory.Exists(fileDirectory)) 124 if (Directory.Exists(fileDirectory))
@@ -127,7 +129,7 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
127 // ensure the directory exists or extraction will fail 129 // ensure the directory exists or extraction will fail
128 Directory.CreateDirectory(fileDirectory); 130 Directory.CreateDirectory(fileDirectory);
129 131
130 foreach (string cabinetFile in cabinetFiles) 132 foreach (var cabinetFile in cabinetFiles)
131 { 133 {
132 try 134 try
133 { 135 {
@@ -139,6 +141,12 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
139 throw new WixException(ErrorMessages.FileNotFound(new SourceLineNumber(this.InputFilePath), cabinetFile)); 141 throw new WixException(ErrorMessages.FileNotFound(new SourceLineNumber(this.InputFilePath), cabinetFile));
140 } 142 }
141 } 143 }
144
145 this.ExtractedFiles = Directory.GetFiles(fileDirectory);
146 }
147 else
148 {
149 this.ExtractedFiles = new string[0];
142 } 150 }
143 } 151 }
144 } 152 }