summaryrefslogtreecommitdiff
path: root/src/dtf/WixToolset.Dtf.Resources/ResourceCollection.cs
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2022-03-31 11:56:14 -0700
committerRob Mensching <rob@firegiant.com>2022-03-31 18:01:06 -0700
commit47582b162368e8edf7a3b11c13b8e9dabc5f0a26 (patch)
tree2c4063eff325684bed39de0edacd7866a257ae02 /src/dtf/WixToolset.Dtf.Resources/ResourceCollection.cs
parent167296c42497c4e95f0d5d71168542d747655981 (diff)
downloadwix-47582b162368e8edf7a3b11c13b8e9dabc5f0a26.tar.gz
wix-47582b162368e8edf7a3b11c13b8e9dabc5f0a26.tar.bz2
wix-47582b162368e8edf7a3b11c13b8e9dabc5f0a26.zip
Provide managed CA and Embedded UI DTF libraries via NuGet
Lots of refactoring to bring the SFX tooling back into the 'dtf' layer since they are (in the end) tightly coupled to some DTF assemblies. Also refactored the DTF tests into their own folder and added a couple integration tests to build using the new CA/UI NuGet package. Closes wixtoolset/issues#6080
Diffstat (limited to 'src/dtf/WixToolset.Dtf.Resources/ResourceCollection.cs')
-rw-r--r--src/dtf/WixToolset.Dtf.Resources/ResourceCollection.cs36
1 files changed, 18 insertions, 18 deletions
diff --git a/src/dtf/WixToolset.Dtf.Resources/ResourceCollection.cs b/src/dtf/WixToolset.Dtf.Resources/ResourceCollection.cs
index b37d5311..8d46b54b 100644
--- a/src/dtf/WixToolset.Dtf.Resources/ResourceCollection.cs
+++ b/src/dtf/WixToolset.Dtf.Resources/ResourceCollection.cs
@@ -18,7 +18,7 @@ namespace WixToolset.Dtf.Resources
18 /// <remarks> 18 /// <remarks>
19 /// To use this class:<list type="number"> 19 /// To use this class:<list type="number">
20 /// <item>Create a new ResourceCollection</item> 20 /// <item>Create a new ResourceCollection</item>
21 /// <item>Locate resources for the collection by calling one of the <see cref="ResourceCollection.Find(string)"/> methods</item> 21 /// <item>Locate resources for the collection by calling one of the <see cref="ResourceCollection.Find(String)"/> methods</item>
22 /// <item>Load data of one or more <see cref="Resource"/>s from a file by calling the <see cref="Load"/> method of the 22 /// <item>Load data of one or more <see cref="Resource"/>s from a file by calling the <see cref="Load"/> method of the
23 /// Resource class, or load them all at once (more efficient) with the <see cref="Load"/> method of the ResourceCollection.</item> 23 /// Resource class, or load them all at once (more efficient) with the <see cref="Load"/> method of the ResourceCollection.</item>
24 /// <item>Read and/or edit data of the individual Resource objects using the methods on that class.</item> 24 /// <item>Read and/or edit data of the individual Resource objects using the methods on that class.</item>
@@ -28,7 +28,7 @@ namespace WixToolset.Dtf.Resources
28 /// </remarks> 28 /// </remarks>
29 public class ResourceCollection : ICollection<Resource> 29 public class ResourceCollection : ICollection<Resource>
30 { 30 {
31 private List<Resource> resources; 31 private readonly List<Resource> resources;
32 32
33 /// <summary> 33 /// <summary>
34 /// Creates a new, empty ResourceCollection. 34 /// Creates a new, empty ResourceCollection.
@@ -48,17 +48,17 @@ namespace WixToolset.Dtf.Resources
48 { 48 {
49 this.Clear(); 49 this.Clear();
50 50
51 IntPtr module = NativeMethods.LoadLibraryEx(resFile, IntPtr.Zero, NativeMethods.LOAD_LIBRARY_AS_DATAFILE); 51 var module = NativeMethods.LoadLibraryEx(resFile, IntPtr.Zero, NativeMethods.LOAD_LIBRARY_AS_DATAFILE);
52 if (module == IntPtr.Zero) 52 if (module == IntPtr.Zero)
53 { 53 {
54 int err = Marshal.GetLastWin32Error(); 54 var err = Marshal.GetLastWin32Error();
55 throw new IOException(String.Format(CultureInfo.InvariantCulture, "Failed to load resource file. Error code: {0}", err)); 55 throw new IOException(String.Format(CultureInfo.InvariantCulture, "Failed to load resource file. Error code: {0}", err));
56 } 56 }
57 try 57 try
58 { 58 {
59 if (!NativeMethods.EnumResourceTypes(module, new NativeMethods.EnumResTypesProc(this.EnumResTypes), IntPtr.Zero)) 59 if (!NativeMethods.EnumResourceTypes(module, new NativeMethods.EnumResTypesProc(this.EnumResTypes), IntPtr.Zero))
60 { 60 {
61 int err = Marshal.GetLastWin32Error(); 61 var err = Marshal.GetLastWin32Error();
62 throw new IOException(String.Format(CultureInfo.InvariantCulture, "Failed to enumerate resources. Error code: {0}", err)); 62 throw new IOException(String.Format(CultureInfo.InvariantCulture, "Failed to enumerate resources. Error code: {0}", err));
63 } 63 }
64 } 64 }
@@ -79,12 +79,12 @@ namespace WixToolset.Dtf.Resources
79 { 79 {
80 this.Clear(); 80 this.Clear();
81 81
82 IntPtr module = NativeMethods.LoadLibraryEx(resFile, IntPtr.Zero, NativeMethods.LOAD_LIBRARY_AS_DATAFILE); 82 var module = NativeMethods.LoadLibraryEx(resFile, IntPtr.Zero, NativeMethods.LOAD_LIBRARY_AS_DATAFILE);
83 try 83 try
84 { 84 {
85 if (!NativeMethods.EnumResourceNames(module, (string) type, new NativeMethods.EnumResNamesProc(this.EnumResNames), IntPtr.Zero)) 85 if (!NativeMethods.EnumResourceNames(module, (string) type, new NativeMethods.EnumResNamesProc(this.EnumResNames), IntPtr.Zero))
86 { 86 {
87 int err = Marshal.GetLastWin32Error(); 87 var err = Marshal.GetLastWin32Error();
88 throw new IOException(String.Format(CultureInfo.InvariantCulture, "EnumResourceNames error. Error code: {0}", err)); 88 throw new IOException(String.Format(CultureInfo.InvariantCulture, "EnumResourceNames error. Error code: {0}", err));
89 } 89 }
90 } 90 }
@@ -106,12 +106,12 @@ namespace WixToolset.Dtf.Resources
106 { 106 {
107 this.Clear(); 107 this.Clear();
108 108
109 IntPtr module = NativeMethods.LoadLibraryEx(resFile, IntPtr.Zero, NativeMethods.LOAD_LIBRARY_AS_DATAFILE); 109 var module = NativeMethods.LoadLibraryEx(resFile, IntPtr.Zero, NativeMethods.LOAD_LIBRARY_AS_DATAFILE);
110 try 110 try
111 { 111 {
112 if (!NativeMethods.EnumResourceLanguages(module, (string) type, name, new NativeMethods.EnumResLangsProc(this.EnumResLangs), IntPtr.Zero)) 112 if (!NativeMethods.EnumResourceLanguages(module, (string) type, name, new NativeMethods.EnumResLangsProc(this.EnumResLangs), IntPtr.Zero))
113 { 113 {
114 int err = Marshal.GetLastWin32Error(); 114 var err = Marshal.GetLastWin32Error();
115 throw new IOException(String.Format(CultureInfo.InvariantCulture, "EnumResourceLanguages error. Error code: {0}", err)); 115 throw new IOException(String.Format(CultureInfo.InvariantCulture, "EnumResourceLanguages error. Error code: {0}", err));
116 } 116 }
117 } 117 }
@@ -123,9 +123,9 @@ namespace WixToolset.Dtf.Resources
123 123
124 private bool EnumResTypes(IntPtr module, IntPtr type, IntPtr param) 124 private bool EnumResTypes(IntPtr module, IntPtr type, IntPtr param)
125 { 125 {
126 if (!NativeMethods.EnumResourceNames(module, type, new NativeMethods.EnumResNamesProc(EnumResNames), IntPtr.Zero)) 126 if (!NativeMethods.EnumResourceNames(module, type, new NativeMethods.EnumResNamesProc(this.EnumResNames), IntPtr.Zero))
127 { 127 {
128 int err = Marshal.GetLastWin32Error(); 128 var err = Marshal.GetLastWin32Error();
129 throw new IOException(String.Format(CultureInfo.InvariantCulture, "EnumResourceNames error! Error code: {0}", err)); 129 throw new IOException(String.Format(CultureInfo.InvariantCulture, "EnumResourceNames error! Error code: {0}", err));
130 } 130 }
131 return true; 131 return true;
@@ -133,9 +133,9 @@ namespace WixToolset.Dtf.Resources
133 133
134 private bool EnumResNames(IntPtr module, IntPtr type, IntPtr name, IntPtr param) 134 private bool EnumResNames(IntPtr module, IntPtr type, IntPtr name, IntPtr param)
135 { 135 {
136 if (!NativeMethods.EnumResourceLanguages(module, type, name, new NativeMethods.EnumResLangsProc(EnumResLangs), IntPtr.Zero)) 136 if (!NativeMethods.EnumResourceLanguages(module, type, name, new NativeMethods.EnumResLangsProc(this.EnumResLangs), IntPtr.Zero))
137 { 137 {
138 int err = Marshal.GetLastWin32Error(); 138 var err = Marshal.GetLastWin32Error();
139 throw new IOException(String.Format(CultureInfo.InvariantCulture, "EnumResourceLanguages error. Error code: {0}", err)); 139 throw new IOException(String.Format(CultureInfo.InvariantCulture, "EnumResourceLanguages error. Error code: {0}", err));
140 } 140 }
141 return true; 141 return true;
@@ -179,10 +179,10 @@ namespace WixToolset.Dtf.Resources
179 /// <param name="file">The file from which resources are loaded.</param> 179 /// <param name="file">The file from which resources are loaded.</param>
180 public void Load(string file) 180 public void Load(string file)
181 { 181 {
182 IntPtr module = NativeMethods.LoadLibraryEx(file, IntPtr.Zero, NativeMethods.LOAD_LIBRARY_AS_DATAFILE); 182 var module = NativeMethods.LoadLibraryEx(file, IntPtr.Zero, NativeMethods.LOAD_LIBRARY_AS_DATAFILE);
183 try 183 try
184 { 184 {
185 foreach (Resource res in this) 185 foreach (var res in this)
186 { 186 {
187 res.Load(module); 187 res.Load(module);
188 } 188 }
@@ -199,17 +199,17 @@ namespace WixToolset.Dtf.Resources
199 /// <param name="file">The file to which resources are saved.</param> 199 /// <param name="file">The file to which resources are saved.</param>
200 public void Save(string file) 200 public void Save(string file)
201 { 201 {
202 IntPtr updateHandle = IntPtr.Zero; 202 var updateHandle = IntPtr.Zero;
203 try 203 try
204 { 204 {
205 updateHandle = NativeMethods.BeginUpdateResource(file, false); 205 updateHandle = NativeMethods.BeginUpdateResource(file, false);
206 foreach (Resource res in this) 206 foreach (var res in this)
207 { 207 {
208 res.Save(updateHandle); 208 res.Save(updateHandle);
209 } 209 }
210 if (!NativeMethods.EndUpdateResource(updateHandle, false)) 210 if (!NativeMethods.EndUpdateResource(updateHandle, false))
211 { 211 {
212 int err = Marshal.GetLastWin32Error(); 212 var err = Marshal.GetLastWin32Error();
213 throw new IOException(String.Format(CultureInfo.InvariantCulture, "Failed to save resource. Error {0}", err)); 213 throw new IOException(String.Format(CultureInfo.InvariantCulture, "Failed to save resource. Error {0}", err));
214 } 214 }
215 updateHandle = IntPtr.Zero; 215 updateHandle = IntPtr.Zero;