aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core.WindowsInstaller/Bind/FileSystemManager.cs
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2020-05-30 14:53:05 -0700
committerRob Mensching <rob@firegiant.com>2020-05-30 15:07:21 -0700
commitd529525a1e331f3ef9ec2707791c99bd78fdd82f (patch)
tree1d9fe1f0c0ee9850371c916802eb03ec9dc37a87 /src/WixToolset.Core.WindowsInstaller/Bind/FileSystemManager.cs
parent9c54d2fce80983bbee5f0f113b5aa30f22bc8a23 (diff)
downloadwix-d529525a1e331f3ef9ec2707791c99bd78fdd82f.tar.gz
wix-d529525a1e331f3ef9ec2707791c99bd78fdd82f.tar.bz2
wix-d529525a1e331f3ef9ec2707791c99bd78fdd82f.zip
Basic patching support
Diffstat (limited to 'src/WixToolset.Core.WindowsInstaller/Bind/FileSystemManager.cs')
-rw-r--r--src/WixToolset.Core.WindowsInstaller/Bind/FileSystemManager.cs71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/FileSystemManager.cs b/src/WixToolset.Core.WindowsInstaller/Bind/FileSystemManager.cs
new file mode 100644
index 00000000..75477271
--- /dev/null
+++ b/src/WixToolset.Core.WindowsInstaller/Bind/FileSystemManager.cs
@@ -0,0 +1,71 @@
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.Collections.Generic;
6 using System.IO;
7 using WixToolset.Extensibility;
8
9 internal class FileSystemManager
10 {
11 public FileSystemManager(IEnumerable<IFileSystemExtension> fileSystemExtensions)
12 {
13 this.Extensions = fileSystemExtensions;
14 }
15
16 private IEnumerable<IFileSystemExtension> Extensions { get; }
17
18 public bool CompareFiles(string firstPath, string secondPath)
19 {
20 foreach (var extension in this.Extensions)
21 {
22 var compared = extension.CompareFiles(firstPath, secondPath);
23 if (compared.HasValue)
24 {
25 return compared.Value;
26 }
27 }
28
29 return BuiltinCompareFiles(firstPath, secondPath);
30 }
31
32 private static bool BuiltinCompareFiles(string firstPath, string secondPath)
33 {
34 using (var firstStream = File.OpenRead(firstPath))
35 using (var secondStream = File.OpenRead(secondPath))
36 {
37 if (firstStream.Length != secondStream.Length)
38 {
39 return false;
40 }
41
42 // Using a larger buffer than the default buffer of 4 * 1024 used by FileStream.ReadByte improves performance.
43 // The buffer size is based on user feedback. Based on performance results, a better buffer size may be determined.
44 var firstBuffer = new byte[16 * 1024];
45 var secondBuffer = new byte[16 * 1024];
46
47 var firstReadLength = 0;
48 do
49 {
50 firstReadLength = firstStream.Read(firstBuffer, 0, firstBuffer.Length);
51 var secondReadLength = secondStream.Read(secondBuffer, 0, secondBuffer.Length);
52
53 if (firstReadLength != secondReadLength)
54 {
55 return false;
56 }
57
58 for (var i = 0; i < firstReadLength; ++i)
59 {
60 if (firstBuffer[i] != secondBuffer[i])
61 {
62 return false;
63 }
64 }
65 } while (0 < firstReadLength);
66 }
67
68 return true;
69 }
70 }
71}