diff options
| author | Rob Mensching <rob@firegiant.com> | 2021-03-14 07:38:48 -0700 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2021-03-14 07:47:48 -0700 |
| commit | 3ccd5e439da4296d6f2b66ce47075ab20d039676 (patch) | |
| tree | b5546552613b869367d09f444492a0bbcfadcfe0 /src/WixToolset.Core.WindowsInstaller/PatchAPI | |
| parent | 574785ab1421c9b67336c13ade5c2263e665ca07 (diff) | |
| download | wix-3ccd5e439da4296d6f2b66ce47075ab20d039676.tar.gz wix-3ccd5e439da4296d6f2b66ce47075ab20d039676.tar.bz2 wix-3ccd5e439da4296d6f2b66ce47075ab20d039676.zip | |
Minimize public surface area of Core
Fixes wixtoolset/issues#6374
Diffstat (limited to 'src/WixToolset.Core.WindowsInstaller/PatchAPI')
| -rw-r--r-- | src/WixToolset.Core.WindowsInstaller/PatchAPI/PatchInterop.cs | 202 |
1 files changed, 101 insertions, 101 deletions
diff --git a/src/WixToolset.Core.WindowsInstaller/PatchAPI/PatchInterop.cs b/src/WixToolset.Core.WindowsInstaller/PatchAPI/PatchInterop.cs index fcd749d2..3874d8e7 100644 --- a/src/WixToolset.Core.WindowsInstaller/PatchAPI/PatchInterop.cs +++ b/src/WixToolset.Core.WindowsInstaller/PatchAPI/PatchInterop.cs | |||
| @@ -7,7 +7,7 @@ namespace WixToolset.PatchAPI | |||
| 7 | using System.Diagnostics.CodeAnalysis; | 7 | using System.Diagnostics.CodeAnalysis; |
| 8 | using System.Globalization; | 8 | using System.Globalization; |
| 9 | using System.Runtime.InteropServices; | 9 | using System.Runtime.InteropServices; |
| 10 | using WixToolset.Core; | 10 | using WixToolset.Data.Symbols; |
| 11 | 11 | ||
| 12 | /// <summary> | 12 | /// <summary> |
| 13 | /// Interop class for the mspatchc.dll. | 13 | /// Interop class for the mspatchc.dll. |
| @@ -25,7 +25,7 @@ namespace WixToolset.PatchAPI | |||
| 25 | static internal UInt32 ParseHexOrDecimal(string source) | 25 | static internal UInt32 ParseHexOrDecimal(string source) |
| 26 | { | 26 | { |
| 27 | string value = source.Trim(); | 27 | string value = source.Trim(); |
| 28 | if (String.Equals(value.Substring(0,2), "0x", StringComparison.OrdinalIgnoreCase)) | 28 | if (String.Equals(value.Substring(0, 2), "0x", StringComparison.OrdinalIgnoreCase)) |
| 29 | { | 29 | { |
| 30 | return UInt32.Parse(value.Substring(2), NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture.NumberFormat); | 30 | return UInt32.Parse(value.Substring(2), NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture.NumberFormat); |
| 31 | } | 31 | } |
| @@ -63,13 +63,13 @@ namespace WixToolset.PatchAPI | |||
| 63 | string[] basisIgnoreOffsets, | 63 | string[] basisIgnoreOffsets, |
| 64 | string[] basisRetainLengths, | 64 | string[] basisRetainLengths, |
| 65 | string[] basisRetainOffsets, | 65 | string[] basisRetainOffsets, |
| 66 | PatchSymbolFlagsType apiPatchingSymbolFlags, | 66 | PatchSymbolFlags apiPatchingSymbolFlags, |
| 67 | bool optimizePatchSizeForLargeFiles, | 67 | bool optimizePatchSizeForLargeFiles, |
| 68 | out bool retainRangesIgnored | 68 | out bool retainRangesIgnored |
| 69 | ) | 69 | ) |
| 70 | { | 70 | { |
| 71 | retainRangesIgnored = false; | 71 | retainRangesIgnored = false; |
| 72 | if (0 != (apiPatchingSymbolFlags & ~(PatchSymbolFlagsType.PATCH_SYMBOL_NO_IMAGEHLP | PatchSymbolFlagsType.PATCH_SYMBOL_NO_FAILURES | PatchSymbolFlagsType.PATCH_SYMBOL_UNDECORATED_TOO))) | 72 | if (0 != (apiPatchingSymbolFlags & ~(PatchSymbolFlags.PatchSymbolNoImagehlp | PatchSymbolFlags.PatchSymbolNoFailures | PatchSymbolFlags.PatchSymbolUndecoratedToo))) |
| 73 | { | 73 | { |
| 74 | throw new ArgumentOutOfRangeException("apiPatchingSymbolFlags"); | 74 | throw new ArgumentOutOfRangeException("apiPatchingSymbolFlags"); |
| 75 | } | 75 | } |
| @@ -88,13 +88,13 @@ namespace WixToolset.PatchAPI | |||
| 88 | { | 88 | { |
| 89 | return false; | 89 | return false; |
| 90 | } | 90 | } |
| 91 | uint countOldFiles = (uint) basisFiles.Length; | 91 | uint countOldFiles = (uint)basisFiles.Length; |
| 92 | 92 | ||
| 93 | if (null != basisSymbolPaths) | 93 | if (null != basisSymbolPaths) |
| 94 | { | 94 | { |
| 95 | if (0 != basisSymbolPaths.Length) | 95 | if (0 != basisSymbolPaths.Length) |
| 96 | { | 96 | { |
| 97 | if ((uint) basisSymbolPaths.Length != countOldFiles) | 97 | if ((uint)basisSymbolPaths.Length != countOldFiles) |
| 98 | { | 98 | { |
| 99 | throw new ArgumentOutOfRangeException("basisSymbolPaths"); | 99 | throw new ArgumentOutOfRangeException("basisSymbolPaths"); |
| 100 | } | 100 | } |
| @@ -106,7 +106,7 @@ namespace WixToolset.PatchAPI | |||
| 106 | { | 106 | { |
| 107 | if (0 != basisIgnoreLengths.Length) | 107 | if (0 != basisIgnoreLengths.Length) |
| 108 | { | 108 | { |
| 109 | if ((uint) basisIgnoreLengths.Length != countOldFiles) | 109 | if ((uint)basisIgnoreLengths.Length != countOldFiles) |
| 110 | { | 110 | { |
| 111 | throw new ArgumentOutOfRangeException("basisIgnoreLengths"); | 111 | throw new ArgumentOutOfRangeException("basisIgnoreLengths"); |
| 112 | } | 112 | } |
| @@ -121,7 +121,7 @@ namespace WixToolset.PatchAPI | |||
| 121 | { | 121 | { |
| 122 | if (0 != basisIgnoreOffsets.Length) | 122 | if (0 != basisIgnoreOffsets.Length) |
| 123 | { | 123 | { |
| 124 | if ((uint) basisIgnoreOffsets.Length != countOldFiles) | 124 | if ((uint)basisIgnoreOffsets.Length != countOldFiles) |
| 125 | { | 125 | { |
| 126 | throw new ArgumentOutOfRangeException("basisIgnoreOffsets"); | 126 | throw new ArgumentOutOfRangeException("basisIgnoreOffsets"); |
| 127 | } | 127 | } |
| @@ -136,7 +136,7 @@ namespace WixToolset.PatchAPI | |||
| 136 | { | 136 | { |
| 137 | if (0 != basisRetainLengths.Length) | 137 | if (0 != basisRetainLengths.Length) |
| 138 | { | 138 | { |
| 139 | if ((uint) basisRetainLengths.Length != countOldFiles) | 139 | if ((uint)basisRetainLengths.Length != countOldFiles) |
| 140 | { | 140 | { |
| 141 | throw new ArgumentOutOfRangeException("basisRetainLengths"); | 141 | throw new ArgumentOutOfRangeException("basisRetainLengths"); |
| 142 | } | 142 | } |
| @@ -151,7 +151,7 @@ namespace WixToolset.PatchAPI | |||
| 151 | { | 151 | { |
| 152 | if (0 != basisRetainOffsets.Length) | 152 | if (0 != basisRetainOffsets.Length) |
| 153 | { | 153 | { |
| 154 | if ((uint) basisRetainOffsets.Length != countOldFiles) | 154 | if ((uint)basisRetainOffsets.Length != countOldFiles) |
| 155 | { | 155 | { |
| 156 | throw new ArgumentOutOfRangeException("basisRetainOffsets"); | 156 | throw new ArgumentOutOfRangeException("basisRetainOffsets"); |
| 157 | } | 157 | } |
| @@ -253,15 +253,15 @@ namespace WixToolset.PatchAPI | |||
| 253 | 253 | ||
| 254 | // determine if this is an error or a need to use whole file. | 254 | // determine if this is an error or a need to use whole file. |
| 255 | int err = Marshal.GetLastWin32Error(); | 255 | int err = Marshal.GetLastWin32Error(); |
| 256 | switch(err) | 256 | switch (err) |
| 257 | { | 257 | { |
| 258 | case unchecked((int) ERROR_PATCH_BIGGER_THAN_COMPRESSED): | 258 | case unchecked((int)ERROR_PATCH_BIGGER_THAN_COMPRESSED): |
| 259 | break; | 259 | break; |
| 260 | 260 | ||
| 261 | // too late to exclude this file -- should have been caught before | 261 | // too late to exclude this file -- should have been caught before |
| 262 | case unchecked((int) ERROR_PATCH_SAME_FILE): | 262 | case unchecked((int)ERROR_PATCH_SAME_FILE): |
| 263 | default: | 263 | default: |
| 264 | throw new System.ComponentModel.Win32Exception(err); | 264 | throw new System.ComponentModel.Win32Exception(err); |
| 265 | } | 265 | } |
| 266 | return false; | 266 | return false; |
| 267 | } | 267 | } |
| @@ -302,44 +302,44 @@ namespace WixToolset.PatchAPI | |||
| 302 | // The following contants can be combined and used as the OptionFlags | 302 | // The following contants can be combined and used as the OptionFlags |
| 303 | // parameter in the patch creation apis. | 303 | // parameter in the patch creation apis. |
| 304 | 304 | ||
| 305 | internal const uint PATCH_OPTION_USE_BEST = 0x00000000; // auto choose best (slower) | 305 | internal const uint PATCH_OPTION_USE_BEST = 0x00000000; // auto choose best (slower) |
| 306 | 306 | ||
| 307 | internal const uint PATCH_OPTION_USE_LZX_BEST = 0x00000003; // auto choose best of LXZ A/B (but not large) | 307 | internal const uint PATCH_OPTION_USE_LZX_BEST = 0x00000003; // auto choose best of LXZ A/B (but not large) |
| 308 | internal const uint PATCH_OPTION_USE_LZX_A = 0x00000001; // normal | 308 | internal const uint PATCH_OPTION_USE_LZX_A = 0x00000001; // normal |
| 309 | internal const uint PATCH_OPTION_USE_LXZ_B = 0x00000002; // better on some x86 binaries | 309 | internal const uint PATCH_OPTION_USE_LXZ_B = 0x00000002; // better on some x86 binaries |
| 310 | internal const uint PATCH_OPTION_USE_LZX_LARGE = 0x00000004; // better support for large files (requires 5.1 or higher applyer) | 310 | internal const uint PATCH_OPTION_USE_LZX_LARGE = 0x00000004; // better support for large files (requires 5.1 or higher applyer) |
| 311 | 311 | ||
| 312 | internal const uint PATCH_OPTION_NO_BINDFIX = 0x00010000; // PE bound imports | 312 | internal const uint PATCH_OPTION_NO_BINDFIX = 0x00010000; // PE bound imports |
| 313 | internal const uint PATCH_OPTION_NO_LOCKFIX = 0x00020000; // PE smashed locks | 313 | internal const uint PATCH_OPTION_NO_LOCKFIX = 0x00020000; // PE smashed locks |
| 314 | internal const uint PATCH_OPTION_NO_REBASE = 0x00040000; // PE rebased image | 314 | internal const uint PATCH_OPTION_NO_REBASE = 0x00040000; // PE rebased image |
| 315 | internal const uint PATCH_OPTION_FAIL_IF_SAME_FILE = 0x00080000; // don't create if same | 315 | internal const uint PATCH_OPTION_FAIL_IF_SAME_FILE = 0x00080000; // don't create if same |
| 316 | internal const uint PATCH_OPTION_FAIL_IF_BIGGER = 0x00100000; // fail if patch is larger than simply compressing new file (slower) | 316 | internal const uint PATCH_OPTION_FAIL_IF_BIGGER = 0x00100000; // fail if patch is larger than simply compressing new file (slower) |
| 317 | internal const uint PATCH_OPTION_NO_CHECKSUM = 0x00200000; // PE checksum zero | 317 | internal const uint PATCH_OPTION_NO_CHECKSUM = 0x00200000; // PE checksum zero |
| 318 | internal const uint PATCH_OPTION_NO_RESTIMEFIX = 0x00400000; // PE resource timestamps | 318 | internal const uint PATCH_OPTION_NO_RESTIMEFIX = 0x00400000; // PE resource timestamps |
| 319 | internal const uint PATCH_OPTION_NO_TIMESTAMP = 0x00800000; // don't store new file timestamp in patch | 319 | internal const uint PATCH_OPTION_NO_TIMESTAMP = 0x00800000; // don't store new file timestamp in patch |
| 320 | internal const uint PATCH_OPTION_SIGNATURE_MD5 = 0x01000000; // use MD5 instead of CRC (reserved for future support) | 320 | internal const uint PATCH_OPTION_SIGNATURE_MD5 = 0x01000000; // use MD5 instead of CRC (reserved for future support) |
| 321 | internal const uint PATCH_OPTION_INTERLEAVE_FILES = 0x40000000; // better support for large files (requires 5.2 or higher applyer) | 321 | internal const uint PATCH_OPTION_INTERLEAVE_FILES = 0x40000000; // better support for large files (requires 5.2 or higher applyer) |
| 322 | internal const uint PATCH_OPTION_RESERVED1 = 0x80000000; // (used internally) | 322 | internal const uint PATCH_OPTION_RESERVED1 = 0x80000000; // (used internally) |
| 323 | 323 | ||
| 324 | internal const uint PATCH_OPTION_VALID_FLAGS = 0xC0FF0007; | 324 | internal const uint PATCH_OPTION_VALID_FLAGS = 0xC0FF0007; |
| 325 | 325 | ||
| 326 | // | 326 | // |
| 327 | // The following flags are used with PATCH_OPTION_DATA ExtendedOptionFlags: | 327 | // The following flags are used with PATCH_OPTION_DATA ExtendedOptionFlags: |
| 328 | // | 328 | // |
| 329 | 329 | ||
| 330 | internal const uint PATCH_TRANSFORM_PE_RESOURCE_2 = 0x00000100; // better handling of PE resources (requires 5.2 or higher applyer) | 330 | internal const uint PATCH_TRANSFORM_PE_RESOURCE_2 = 0x00000100; // better handling of PE resources (requires 5.2 or higher applyer) |
| 331 | internal const uint PATCH_TRANSFORM_PE_IRELOC_2 = 0x00000200; // better handling of PE stripped relocs (requires 5.2 or higher applyer) | 331 | internal const uint PATCH_TRANSFORM_PE_IRELOC_2 = 0x00000200; // better handling of PE stripped relocs (requires 5.2 or higher applyer) |
| 332 | 332 | ||
| 333 | // | 333 | // |
| 334 | // In addition to the standard Win32 error codes, the following error codes may | 334 | // In addition to the standard Win32 error codes, the following error codes may |
| 335 | // be returned via GetLastError() when one of the patch APIs fails. | 335 | // be returned via GetLastError() when one of the patch APIs fails. |
| 336 | 336 | ||
| 337 | internal const uint ERROR_PATCH_ENCODE_FAILURE = 0xC00E3101; // create | 337 | internal const uint ERROR_PATCH_ENCODE_FAILURE = 0xC00E3101; // create |
| 338 | internal const uint ERROR_PATCH_INVALID_OPTIONS = 0xC00E3102; // create | 338 | internal const uint ERROR_PATCH_INVALID_OPTIONS = 0xC00E3102; // create |
| 339 | internal const uint ERROR_PATCH_SAME_FILE = 0xC00E3103; // create | 339 | internal const uint ERROR_PATCH_SAME_FILE = 0xC00E3103; // create |
| 340 | internal const uint ERROR_PATCH_RETAIN_RANGES_DIFFER = 0xC00E3104; // create | 340 | internal const uint ERROR_PATCH_RETAIN_RANGES_DIFFER = 0xC00E3104; // create |
| 341 | internal const uint ERROR_PATCH_BIGGER_THAN_COMPRESSED = 0xC00E3105; // create | 341 | internal const uint ERROR_PATCH_BIGGER_THAN_COMPRESSED = 0xC00E3105; // create |
| 342 | internal const uint ERROR_PATCH_IMAGEHLP_FALURE = 0xC00E3106; // create | 342 | internal const uint ERROR_PATCH_IMAGEHLP_FALURE = 0xC00E3106; // create |
| 343 | 343 | ||
| 344 | /// <summary> | 344 | /// <summary> |
| 345 | /// Delegate type that the PatchAPI calls for progress notification. | 345 | /// Delegate type that the PatchAPI calls for progress notification. |
| @@ -441,14 +441,14 @@ namespace WixToolset.PatchAPI | |||
| 441 | [BestFitMapping(false, ThrowOnUnmappableChar = true)] | 441 | [BestFitMapping(false, ThrowOnUnmappableChar = true)] |
| 442 | internal class PatchOptionData | 442 | internal class PatchOptionData |
| 443 | { | 443 | { |
| 444 | public PatchSymbolFlagsType symbolOptionFlags; // PATCH_SYMBOL_xxx flags | 444 | public PatchSymbolFlags symbolOptionFlags; // PATCH_SYMBOL_xxx flags |
| 445 | [MarshalAs(UnmanagedType.LPStr)] public string newFileSymbolPath; // always ANSI, never Unicode | 445 | [MarshalAs(UnmanagedType.LPStr)] public string newFileSymbolPath; // always ANSI, never Unicode |
| 446 | [MarshalAs(UnmanagedType.LPStr)] public string[] oldFileSymbolPathArray; // array[ OldFileCount ] | 446 | [MarshalAs(UnmanagedType.LPStr)] public string[] oldFileSymbolPathArray; // array[ OldFileCount ] |
| 447 | public uint extendedOptionFlags; | 447 | public uint extendedOptionFlags; |
| 448 | public PatchSymloadCallback symLoadCallback = null; | 448 | public PatchSymloadCallback symLoadCallback = null; |
| 449 | public IntPtr symLoadContext = IntPtr.Zero; | 449 | public IntPtr symLoadContext = IntPtr.Zero; |
| 450 | public PatchInterleaveMap[] interleaveMapArray = null; // array[ OldFileCount ] (requires 5.2 or higher applyer) | 450 | public PatchInterleaveMap[] interleaveMapArray = null; // array[ OldFileCount ] (requires 5.2 or higher applyer) |
| 451 | public uint maxLzxWindowSize = 0; // limit memory requirements (requires 5.2 or higher applyer) | 451 | public uint maxLzxWindowSize = 0; // limit memory requirements (requires 5.2 or higher applyer) |
| 452 | } | 452 | } |
| 453 | 453 | ||
| 454 | // | 454 | // |
| @@ -534,7 +534,7 @@ namespace WixToolset.PatchAPI | |||
| 534 | 534 | ||
| 535 | private PatchAPIMarshaler(string cookie) | 535 | private PatchAPIMarshaler(string cookie) |
| 536 | { | 536 | { |
| 537 | this.marshalType = (PatchAPIMarshaler.MarshalType) Enum.Parse(typeof(PatchAPIMarshaler.MarshalType), cookie); | 537 | this.marshalType = (PatchAPIMarshaler.MarshalType)Enum.Parse(typeof(PatchAPIMarshaler.MarshalType), cookie); |
| 538 | } | 538 | } |
| 539 | 539 | ||
| 540 | // | 540 | // |
| @@ -575,12 +575,12 @@ namespace WixToolset.PatchAPI | |||
| 575 | 575 | ||
| 576 | switch (this.marshalType) | 576 | switch (this.marshalType) |
| 577 | { | 577 | { |
| 578 | case PatchAPIMarshaler.MarshalType.PATCH_OPTION_DATA: | 578 | case PatchAPIMarshaler.MarshalType.PATCH_OPTION_DATA: |
| 579 | this.CleanUpPOD(pNativeData); | 579 | this.CleanUpPOD(pNativeData); |
| 580 | break; | 580 | break; |
| 581 | default: | 581 | default: |
| 582 | this.CleanUpPOFI_A(pNativeData); | 582 | this.CleanUpPOFI_A(pNativeData); |
| 583 | break; | 583 | break; |
| 584 | } | 584 | } |
| 585 | } | 585 | } |
| 586 | 586 | ||
| @@ -601,14 +601,14 @@ namespace WixToolset.PatchAPI | |||
| 601 | return IntPtr.Zero; | 601 | return IntPtr.Zero; |
| 602 | } | 602 | } |
| 603 | 603 | ||
| 604 | switch(this.marshalType) | 604 | switch (this.marshalType) |
| 605 | { | 605 | { |
| 606 | case PatchAPIMarshaler.MarshalType.PATCH_OPTION_DATA: | 606 | case PatchAPIMarshaler.MarshalType.PATCH_OPTION_DATA: |
| 607 | return this.MarshalPOD(ManagedObj as PatchOptionData); | 607 | return this.MarshalPOD(ManagedObj as PatchOptionData); |
| 608 | case PatchAPIMarshaler.MarshalType.PATCH_OLD_FILE_INFO_W: | 608 | case PatchAPIMarshaler.MarshalType.PATCH_OLD_FILE_INFO_W: |
| 609 | return this.MarshalPOFIW_A(ManagedObj as PatchOldFileInfoW[]); | 609 | return this.MarshalPOFIW_A(ManagedObj as PatchOldFileInfoW[]); |
| 610 | default: | 610 | default: |
| 611 | throw new InvalidOperationException(); | 611 | throw new InvalidOperationException(); |
| 612 | } | 612 | } |
| 613 | } | 613 | } |
| 614 | 614 | ||
| @@ -631,23 +631,23 @@ namespace WixToolset.PatchAPI | |||
| 631 | // Implementation ************************************************* | 631 | // Implementation ************************************************* |
| 632 | 632 | ||
| 633 | // PATCH_OPTION_DATA offsets | 633 | // PATCH_OPTION_DATA offsets |
| 634 | private static readonly int symbolOptionFlagsOffset = Marshal.SizeOf(typeof(Int32)); | 634 | private static readonly int symbolOptionFlagsOffset = Marshal.SizeOf(typeof(Int32)); |
| 635 | private static readonly int newFileSymbolPathOffset = 2*Marshal.SizeOf(typeof(Int32)); | 635 | private static readonly int newFileSymbolPathOffset = 2 * Marshal.SizeOf(typeof(Int32)); |
| 636 | private static readonly int oldFileSymbolPathArrayOffset = 2*Marshal.SizeOf(typeof(Int32)) + Marshal.SizeOf(typeof(IntPtr)); | 636 | private static readonly int oldFileSymbolPathArrayOffset = 2 * Marshal.SizeOf(typeof(Int32)) + Marshal.SizeOf(typeof(IntPtr)); |
| 637 | private static readonly int extendedOptionFlagsOffset = 2*Marshal.SizeOf(typeof(Int32)) + 2*Marshal.SizeOf(typeof(IntPtr)); | 637 | private static readonly int extendedOptionFlagsOffset = 2 * Marshal.SizeOf(typeof(Int32)) + 2 * Marshal.SizeOf(typeof(IntPtr)); |
| 638 | private static readonly int symLoadCallbackOffset = 3*Marshal.SizeOf(typeof(Int32)) + 2*Marshal.SizeOf(typeof(IntPtr)); | 638 | private static readonly int symLoadCallbackOffset = 3 * Marshal.SizeOf(typeof(Int32)) + 2 * Marshal.SizeOf(typeof(IntPtr)); |
| 639 | private static readonly int symLoadContextOffset = 3*Marshal.SizeOf(typeof(Int32)) + 3*Marshal.SizeOf(typeof(IntPtr)); | 639 | private static readonly int symLoadContextOffset = 3 * Marshal.SizeOf(typeof(Int32)) + 3 * Marshal.SizeOf(typeof(IntPtr)); |
| 640 | private static readonly int interleaveMapArrayOffset = 3*Marshal.SizeOf(typeof(Int32)) + 4*Marshal.SizeOf(typeof(IntPtr)); | 640 | private static readonly int interleaveMapArrayOffset = 3 * Marshal.SizeOf(typeof(Int32)) + 4 * Marshal.SizeOf(typeof(IntPtr)); |
| 641 | private static readonly int maxLzxWindowSizeOffset = 3*Marshal.SizeOf(typeof(Int32)) + 5*Marshal.SizeOf(typeof(IntPtr)); | 641 | private static readonly int maxLzxWindowSizeOffset = 3 * Marshal.SizeOf(typeof(Int32)) + 5 * Marshal.SizeOf(typeof(IntPtr)); |
| 642 | private static readonly int patchOptionDataSize = 4*Marshal.SizeOf(typeof(Int32)) + 5*Marshal.SizeOf(typeof(IntPtr)); | 642 | private static readonly int patchOptionDataSize = 4 * Marshal.SizeOf(typeof(Int32)) + 5 * Marshal.SizeOf(typeof(IntPtr)); |
| 643 | 643 | ||
| 644 | // PATCH_OLD_FILE_INFO offsets | 644 | // PATCH_OLD_FILE_INFO offsets |
| 645 | private static readonly int oldFileOffset = Marshal.SizeOf(typeof(Int32)); | 645 | private static readonly int oldFileOffset = Marshal.SizeOf(typeof(Int32)); |
| 646 | private static readonly int ignoreRangeCountOffset = Marshal.SizeOf(typeof(Int32)) + Marshal.SizeOf(typeof(IntPtr)); | 646 | private static readonly int ignoreRangeCountOffset = Marshal.SizeOf(typeof(Int32)) + Marshal.SizeOf(typeof(IntPtr)); |
| 647 | private static readonly int ignoreRangeArrayOffset = 2*Marshal.SizeOf(typeof(Int32)) + Marshal.SizeOf(typeof(IntPtr)); | 647 | private static readonly int ignoreRangeArrayOffset = 2 * Marshal.SizeOf(typeof(Int32)) + Marshal.SizeOf(typeof(IntPtr)); |
| 648 | private static readonly int retainRangeCountOffset = 2*Marshal.SizeOf(typeof(Int32)) + 2*Marshal.SizeOf(typeof(IntPtr)); | 648 | private static readonly int retainRangeCountOffset = 2 * Marshal.SizeOf(typeof(Int32)) + 2 * Marshal.SizeOf(typeof(IntPtr)); |
| 649 | private static readonly int retainRangeArrayOffset = 3*Marshal.SizeOf(typeof(Int32)) + 2*Marshal.SizeOf(typeof(IntPtr)); | 649 | private static readonly int retainRangeArrayOffset = 3 * Marshal.SizeOf(typeof(Int32)) + 2 * Marshal.SizeOf(typeof(IntPtr)); |
| 650 | private static readonly int patchOldFileInfoSize = 3*Marshal.SizeOf(typeof(Int32)) + 3*Marshal.SizeOf(typeof(IntPtr)); | 650 | private static readonly int patchOldFileInfoSize = 3 * Marshal.SizeOf(typeof(Int32)) + 3 * Marshal.SizeOf(typeof(IntPtr)); |
| 651 | 651 | ||
| 652 | // Methods and data used to preserve data needed for cleanup | 652 | // Methods and data used to preserve data needed for cleanup |
| 653 | 653 | ||
| @@ -658,16 +658,16 @@ namespace WixToolset.PatchAPI | |||
| 658 | private IntPtr CreateMainStruct(int oldFileCount) | 658 | private IntPtr CreateMainStruct(int oldFileCount) |
| 659 | { | 659 | { |
| 660 | int nativeSize; | 660 | int nativeSize; |
| 661 | switch(this.marshalType) | 661 | switch (this.marshalType) |
| 662 | { | 662 | { |
| 663 | case PatchAPIMarshaler.MarshalType.PATCH_OPTION_DATA: | 663 | case PatchAPIMarshaler.MarshalType.PATCH_OPTION_DATA: |
| 664 | nativeSize = patchOptionDataSize; | 664 | nativeSize = patchOptionDataSize; |
| 665 | break; | 665 | break; |
| 666 | case PatchAPIMarshaler.MarshalType.PATCH_OLD_FILE_INFO_W: | 666 | case PatchAPIMarshaler.MarshalType.PATCH_OLD_FILE_INFO_W: |
| 667 | nativeSize = oldFileCount*patchOldFileInfoSize; | 667 | nativeSize = oldFileCount * patchOldFileInfoSize; |
| 668 | break; | 668 | break; |
| 669 | default: | 669 | default: |
| 670 | throw new InvalidOperationException(); | 670 | throw new InvalidOperationException(); |
| 671 | } | 671 | } |
| 672 | 672 | ||
| 673 | IntPtr native = Marshal.AllocCoTaskMem(nativeSize); | 673 | IntPtr native = Marshal.AllocCoTaskMem(nativeSize); |
| @@ -722,7 +722,7 @@ namespace WixToolset.PatchAPI | |||
| 722 | 722 | ||
| 723 | for (int i = 0; i < managed.Length; ++i) | 723 | for (int i = 0; i < managed.Length; ++i) |
| 724 | { | 724 | { |
| 725 | Marshal.WriteIntPtr(native, i*Marshal.SizeOf(typeof(IntPtr)), OptionalAnsiString(managed[i])); | 725 | Marshal.WriteIntPtr(native, i * Marshal.SizeOf(typeof(IntPtr)), OptionalAnsiString(managed[i])); |
| 726 | } | 726 | } |
| 727 | 727 | ||
| 728 | return native; | 728 | return native; |
| @@ -741,7 +741,7 @@ namespace WixToolset.PatchAPI | |||
| 741 | 741 | ||
| 742 | for (int i = 0; i < managed.Length; ++i) | 742 | for (int i = 0; i < managed.Length; ++i) |
| 743 | { | 743 | { |
| 744 | Marshal.WriteIntPtr(native, i*Marshal.SizeOf(typeof(IntPtr)), OptionalUnicodeString(managed[i])); | 744 | Marshal.WriteIntPtr(native, i * Marshal.SizeOf(typeof(IntPtr)), OptionalUnicodeString(managed[i])); |
| 745 | } | 745 | } |
| 746 | 746 | ||
| 747 | return native; | 747 | return native; |
| @@ -765,12 +765,12 @@ namespace WixToolset.PatchAPI | |||
| 765 | } | 765 | } |
| 766 | 766 | ||
| 767 | IntPtr native = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(UInt32)) | 767 | IntPtr native = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(UInt32)) |
| 768 | + managed.ranges.Length*(Marshal.SizeOf(typeof(PatchInterleaveMap)))); | 768 | + managed.ranges.Length * (Marshal.SizeOf(typeof(PatchInterleaveMap)))); |
| 769 | WriteUInt32(native, (uint) managed.ranges.Length); | 769 | WriteUInt32(native, (uint)managed.ranges.Length); |
| 770 | 770 | ||
| 771 | for (int i = 0; i < managed.ranges.Length; ++i) | 771 | for (int i = 0; i < managed.ranges.Length; ++i) |
| 772 | { | 772 | { |
| 773 | Marshal.StructureToPtr(managed.ranges[i], (IntPtr)((Int64)native + i*Marshal.SizeOf(typeof(PatchInterleaveMap))), false); | 773 | Marshal.StructureToPtr(managed.ranges[i], (IntPtr)((Int64)native + i * Marshal.SizeOf(typeof(PatchInterleaveMap))), false); |
| 774 | } | 774 | } |
| 775 | return native; | 775 | return native; |
| 776 | } | 776 | } |
| @@ -786,7 +786,7 @@ namespace WixToolset.PatchAPI | |||
| 786 | 786 | ||
| 787 | for (int i = 0; i < managed.Length; ++i) | 787 | for (int i = 0; i < managed.Length; ++i) |
| 788 | { | 788 | { |
| 789 | Marshal.WriteIntPtr(native, i*Marshal.SizeOf(typeof(IntPtr)), CreateInterleaveMapRange(managed[i])); | 789 | Marshal.WriteIntPtr(native, i * Marshal.SizeOf(typeof(IntPtr)), CreateInterleaveMapRange(managed[i])); |
| 790 | } | 790 | } |
| 791 | 791 | ||
| 792 | return native; | 792 | return native; |
| @@ -794,12 +794,12 @@ namespace WixToolset.PatchAPI | |||
| 794 | 794 | ||
| 795 | private static void WriteUInt32(IntPtr native, uint data) | 795 | private static void WriteUInt32(IntPtr native, uint data) |
| 796 | { | 796 | { |
| 797 | Marshal.WriteInt32(native, unchecked((int) data)); | 797 | Marshal.WriteInt32(native, unchecked((int)data)); |
| 798 | } | 798 | } |
| 799 | 799 | ||
| 800 | private static void WriteUInt32(IntPtr native, int offset, uint data) | 800 | private static void WriteUInt32(IntPtr native, int offset, uint data) |
| 801 | { | 801 | { |
| 802 | Marshal.WriteInt32(native, offset, unchecked((int) data)); | 802 | Marshal.WriteInt32(native, offset, unchecked((int)data)); |
| 803 | } | 803 | } |
| 804 | 804 | ||
| 805 | // Marshal operations | 805 | // Marshal operations |
| @@ -813,7 +813,7 @@ namespace WixToolset.PatchAPI | |||
| 813 | 813 | ||
| 814 | IntPtr native = this.CreateMainStruct(managed.oldFileSymbolPathArray.Length); | 814 | IntPtr native = this.CreateMainStruct(managed.oldFileSymbolPathArray.Length); |
| 815 | Marshal.WriteInt32(native, patchOptionDataSize); // SizeOfThisStruct | 815 | Marshal.WriteInt32(native, patchOptionDataSize); // SizeOfThisStruct |
| 816 | WriteUInt32(native, symbolOptionFlagsOffset, (uint) managed.symbolOptionFlags); | 816 | WriteUInt32(native, symbolOptionFlagsOffset, (uint)managed.symbolOptionFlags); |
| 817 | Marshal.WriteIntPtr(native, newFileSymbolPathOffset, PatchAPIMarshaler.OptionalAnsiString(managed.newFileSymbolPath)); | 817 | Marshal.WriteIntPtr(native, newFileSymbolPathOffset, PatchAPIMarshaler.OptionalAnsiString(managed.newFileSymbolPath)); |
| 818 | Marshal.WriteIntPtr(native, oldFileSymbolPathArrayOffset, PatchAPIMarshaler.CreateArrayOfStringA(managed.oldFileSymbolPathArray)); | 818 | Marshal.WriteIntPtr(native, oldFileSymbolPathArrayOffset, PatchAPIMarshaler.CreateArrayOfStringA(managed.oldFileSymbolPathArray)); |
| 819 | WriteUInt32(native, extendedOptionFlagsOffset, managed.extendedOptionFlags); | 819 | WriteUInt32(native, extendedOptionFlagsOffset, managed.extendedOptionFlags); |
| @@ -866,10 +866,10 @@ namespace WixToolset.PatchAPI | |||
| 866 | { | 866 | { |
| 867 | Marshal.WriteInt32(native, patchOldFileInfoSize); // SizeOfThisStruct | 867 | Marshal.WriteInt32(native, patchOldFileInfoSize); // SizeOfThisStruct |
| 868 | WriteUInt32(native, ignoreRangeCountOffset, | 868 | WriteUInt32(native, ignoreRangeCountOffset, |
| 869 | (null == managed.ignoreRange) ? 0 : (uint) managed.ignoreRange.Length); // IgnoreRangeCount // maximum 255 | 869 | (null == managed.ignoreRange) ? 0 : (uint)managed.ignoreRange.Length); // IgnoreRangeCount // maximum 255 |
| 870 | Marshal.WriteIntPtr(native, ignoreRangeArrayOffset, MarshalPIRArray(managed.ignoreRange)); // IgnoreRangeArray | 870 | Marshal.WriteIntPtr(native, ignoreRangeArrayOffset, MarshalPIRArray(managed.ignoreRange)); // IgnoreRangeArray |
| 871 | WriteUInt32(native, retainRangeCountOffset, | 871 | WriteUInt32(native, retainRangeCountOffset, |
| 872 | (null == managed.retainRange) ? 0 : (uint) managed.retainRange.Length); // RetainRangeCount // maximum 255 | 872 | (null == managed.retainRange) ? 0 : (uint)managed.retainRange.Length); // RetainRangeCount // maximum 255 |
| 873 | Marshal.WriteIntPtr(native, retainRangeArrayOffset, MarshalPRRArray(managed.retainRange)); // RetainRangeArray | 873 | Marshal.WriteIntPtr(native, retainRangeArrayOffset, MarshalPRRArray(managed.retainRange)); // RetainRangeArray |
| 874 | } | 874 | } |
| 875 | 875 | ||
| @@ -885,11 +885,11 @@ namespace WixToolset.PatchAPI | |||
| 885 | return IntPtr.Zero; | 885 | return IntPtr.Zero; |
| 886 | } | 886 | } |
| 887 | 887 | ||
| 888 | IntPtr native = Marshal.AllocCoTaskMem(array.Length*Marshal.SizeOf(typeof(PatchIgnoreRange))); | 888 | IntPtr native = Marshal.AllocCoTaskMem(array.Length * Marshal.SizeOf(typeof(PatchIgnoreRange))); |
| 889 | 889 | ||
| 890 | for (int i = 0; i < array.Length; ++i) | 890 | for (int i = 0; i < array.Length; ++i) |
| 891 | { | 891 | { |
| 892 | Marshal.StructureToPtr(array[i], (IntPtr)((Int64)native + (i*Marshal.SizeOf(typeof(PatchIgnoreRange)))), false); | 892 | Marshal.StructureToPtr(array[i], (IntPtr)((Int64)native + (i * Marshal.SizeOf(typeof(PatchIgnoreRange)))), false); |
| 893 | } | 893 | } |
| 894 | 894 | ||
| 895 | return native; | 895 | return native; |
| @@ -907,11 +907,11 @@ namespace WixToolset.PatchAPI | |||
| 907 | return IntPtr.Zero; | 907 | return IntPtr.Zero; |
| 908 | } | 908 | } |
| 909 | 909 | ||
| 910 | IntPtr native = Marshal.AllocCoTaskMem(array.Length*Marshal.SizeOf(typeof(PatchRetainRange))); | 910 | IntPtr native = Marshal.AllocCoTaskMem(array.Length * Marshal.SizeOf(typeof(PatchRetainRange))); |
| 911 | 911 | ||
| 912 | for (int i = 0; i < array.Length; ++i) | 912 | for (int i = 0; i < array.Length; ++i) |
| 913 | { | 913 | { |
| 914 | Marshal.StructureToPtr(array[i], (IntPtr)((Int64)native + (i*Marshal.SizeOf(typeof(PatchRetainRange)))), false); | 914 | Marshal.StructureToPtr(array[i], (IntPtr)((Int64)native + (i * Marshal.SizeOf(typeof(PatchRetainRange)))), false); |
| 915 | } | 915 | } |
| 916 | 916 | ||
| 917 | return native; | 917 | return native; |
| @@ -930,7 +930,7 @@ namespace WixToolset.PatchAPI | |||
| 930 | Marshal.FreeCoTaskMem( | 930 | Marshal.FreeCoTaskMem( |
| 931 | Marshal.ReadIntPtr( | 931 | Marshal.ReadIntPtr( |
| 932 | Marshal.ReadIntPtr(native, oldFileSymbolPathArrayOffset), | 932 | Marshal.ReadIntPtr(native, oldFileSymbolPathArrayOffset), |
| 933 | i*Marshal.SizeOf(typeof(IntPtr)))); | 933 | i * Marshal.SizeOf(typeof(IntPtr)))); |
| 934 | } | 934 | } |
| 935 | 935 | ||
| 936 | Marshal.FreeCoTaskMem(Marshal.ReadIntPtr(native, oldFileSymbolPathArrayOffset)); | 936 | Marshal.FreeCoTaskMem(Marshal.ReadIntPtr(native, oldFileSymbolPathArrayOffset)); |
| @@ -943,7 +943,7 @@ namespace WixToolset.PatchAPI | |||
| 943 | Marshal.FreeCoTaskMem( | 943 | Marshal.FreeCoTaskMem( |
| 944 | Marshal.ReadIntPtr( | 944 | Marshal.ReadIntPtr( |
| 945 | Marshal.ReadIntPtr(native, interleaveMapArrayOffset), | 945 | Marshal.ReadIntPtr(native, interleaveMapArrayOffset), |
| 946 | i*Marshal.SizeOf(typeof(IntPtr)))); | 946 | i * Marshal.SizeOf(typeof(IntPtr)))); |
| 947 | } | 947 | } |
| 948 | 948 | ||
| 949 | Marshal.FreeCoTaskMem(Marshal.ReadIntPtr(native, interleaveMapArrayOffset)); | 949 | Marshal.FreeCoTaskMem(Marshal.ReadIntPtr(native, interleaveMapArrayOffset)); |
| @@ -956,7 +956,7 @@ namespace WixToolset.PatchAPI | |||
| 956 | { | 956 | { |
| 957 | for (int i = 0; i < GetOldFileCount(native); ++i) | 957 | for (int i = 0; i < GetOldFileCount(native); ++i) |
| 958 | { | 958 | { |
| 959 | PatchAPIMarshaler.CleanUpPOFI((IntPtr)((Int64)native + i*patchOldFileInfoSize)); | 959 | PatchAPIMarshaler.CleanUpPOFI((IntPtr)((Int64)native + i * patchOldFileInfoSize)); |
| 960 | } | 960 | } |
| 961 | 961 | ||
| 962 | PatchAPIMarshaler.ReleaseMainStruct(native); | 962 | PatchAPIMarshaler.ReleaseMainStruct(native); |
