aboutsummaryrefslogtreecommitdiff
path: root/src/samples/Dtf/DDiff/VersionedFileDiffEngine.cs
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2022-07-14 15:19:53 -0700
committerRob Mensching <rob@firegiant.com>2022-07-14 16:02:24 -0700
commit229242cf7c328b89b5aa65ed7a04e33c8b93b393 (patch)
treede0a9547e73e46490b0946d6850228d5b30258b8 /src/samples/Dtf/DDiff/VersionedFileDiffEngine.cs
parentf46ca6a9dce91607ffc9855270dd6998216e1a8b (diff)
downloadwix-229242cf7c328b89b5aa65ed7a04e33c8b93b393.tar.gz
wix-229242cf7c328b89b5aa65ed7a04e33c8b93b393.tar.bz2
wix-229242cf7c328b89b5aa65ed7a04e33c8b93b393.zip
Rename "samples" segment to "tools"
This segment is a bit of a "miscellaneous section" in the WiX repo. As such it has been difficult to name. I originally eschewed the name "tools" because what is in the "wix" segment was once called "tools". However, now that wix.exe is firmly established as the entry point for WiX operations, I've become comfortable with its segment being named "wix". That meant "tools" was again available and "tools" better describes the content of this section.
Diffstat (limited to 'src/samples/Dtf/DDiff/VersionedFileDiffEngine.cs')
-rw-r--r--src/samples/Dtf/DDiff/VersionedFileDiffEngine.cs90
1 files changed, 0 insertions, 90 deletions
diff --git a/src/samples/Dtf/DDiff/VersionedFileDiffEngine.cs b/src/samples/Dtf/DDiff/VersionedFileDiffEngine.cs
deleted file mode 100644
index ad4014f3..00000000
--- a/src/samples/Dtf/DDiff/VersionedFileDiffEngine.cs
+++ /dev/null
@@ -1,90 +0,0 @@
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
3using System;
4using System.IO;
5using WixToolset.Dtf.WindowsInstaller;
6
7namespace WixToolset.Dtf.Samples.DDiff
8{
9 public class VersionedFileDiffEngine : IDiffEngine
10 {
11 public VersionedFileDiffEngine()
12 {
13 }
14
15 private bool IsVersionedFile(string file)
16 {
17 return Installer.GetFileVersion(file) != "";
18 }
19
20 public float GetDiffQuality(string diffInput1, string diffInput2, string[] options, IDiffEngineFactory diffFactory)
21 {
22 if(diffInput1 != null && File.Exists(diffInput1) &&
23 diffInput2 != null && File.Exists(diffInput2) &&
24 (IsVersionedFile(diffInput1) || IsVersionedFile(diffInput2)))
25 {
26 return .20f;
27 }
28 else
29 {
30 return 0;
31 }
32 }
33
34 public bool GetDiff(string diffInput1, string diffInput2, string[] options, TextWriter diffOutput, string linePrefix, IDiffEngineFactory diffFactory)
35 {
36 bool difference = false;
37
38 string ver1 = Installer.GetFileVersion(diffInput1);
39 string ver2 = Installer.GetFileVersion(diffInput2);
40
41 if(ver1 != ver2)
42 {
43 diffOutput.WriteLine("{0}File version: {1} -> {2}", linePrefix, ver1, ver2);
44 difference = true;
45 }
46 else
47 {
48 FileStream stream1 = new FileStream(diffInput1, FileMode.Open, FileAccess.Read, FileShare.Read);
49 FileStream stream2 = new FileStream(diffInput2, FileMode.Open, FileAccess.Read, FileShare.Read);
50
51 byte[] buf1 = new byte[512];
52 byte[] buf2 = new byte[512];
53
54 while(!difference)
55 {
56 int count1 = stream1.Read(buf1, 0, buf1.Length);
57 int count2 = stream2.Read(buf2, 0, buf2.Length);
58
59 for(int i = 0; i < count1; i++)
60 {
61 if(i == count2 || buf1[i] != buf2[i])
62 {
63 difference = true;
64 break;
65 }
66 }
67 if(count1 < buf1.Length) // EOF
68 {
69 break;
70 }
71 }
72
73 stream1.Close();
74 stream2.Close();
75
76 if(difference)
77 {
78 diffOutput.WriteLine("{0}File versions match but bits differ.", linePrefix);
79 }
80 }
81
82 return difference;
83 }
84
85 public IDiffEngine Clone()
86 {
87 return new VersionedFileDiffEngine();
88 }
89 }
90}