aboutsummaryrefslogtreecommitdiff
path: root/src/samples/Dtf/DDiff/TextFileDiffEngine.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/TextFileDiffEngine.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/TextFileDiffEngine.cs')
-rw-r--r--src/samples/Dtf/DDiff/TextFileDiffEngine.cs83
1 files changed, 0 insertions, 83 deletions
diff --git a/src/samples/Dtf/DDiff/TextFileDiffEngine.cs b/src/samples/Dtf/DDiff/TextFileDiffEngine.cs
deleted file mode 100644
index 22567023..00000000
--- a/src/samples/Dtf/DDiff/TextFileDiffEngine.cs
+++ /dev/null
@@ -1,83 +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 System.Diagnostics;
6
7namespace WixToolset.Dtf.Samples.DDiff
8{
9 public class TextFileDiffEngine : IDiffEngine
10 {
11 public TextFileDiffEngine()
12 {
13 }
14
15 private bool IsTextFile(string file)
16 {
17 // Guess whether this is a text file by reading the first few bytes and checking for non-ascii chars.
18
19 bool isText = true;
20 FileStream stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read);
21 byte[] buf = new byte[256];
22 int count = stream.Read(buf, 0, buf.Length);
23 for(int i = 0; i < count; i++)
24 {
25 if((buf[i] & 0x80) != 0)
26 {
27 isText = false;
28 break;
29 }
30 }
31 stream.Close();
32 return isText;
33 }
34
35 public float GetDiffQuality(string diffInput1, string diffInput2, string[] options, IDiffEngineFactory diffFactory)
36 {
37 if(diffInput1 != null && File.Exists(diffInput1) &&
38 diffInput2 != null && File.Exists(diffInput2) &&
39 (IsTextFile(diffInput1) && IsTextFile(diffInput2)))
40 {
41 return .70f;
42 }
43 else
44 {
45 return 0;
46 }
47 }
48
49 public bool GetDiff(string diffInput1, string diffInput2, string[] options, TextWriter diffOutput, string linePrefix, IDiffEngineFactory diffFactory)
50 {
51 try
52 {
53 bool difference = false;
54 ProcessStartInfo psi = new ProcessStartInfo("diff.exe");
55 psi.Arguments = String.Format("\"{0}\" \"{1}\"", diffInput1, diffInput2);
56 psi.WorkingDirectory = null;
57 psi.UseShellExecute = false;
58 psi.WindowStyle = ProcessWindowStyle.Hidden;
59 psi.RedirectStandardOutput = true;
60 Process proc = Process.Start(psi);
61
62 string line;
63 while((line = proc.StandardOutput.ReadLine()) != null)
64 {
65 diffOutput.WriteLine("{0}{1}", linePrefix, line);
66 difference = true;
67 }
68
69 proc.WaitForExit();
70 return difference;
71 }
72 catch(System.ComponentModel.Win32Exception) // If diff.exe is not found, just compare the bytes
73 {
74 return new FileDiffEngine().GetDiff(diffInput1, diffInput2, options, diffOutput, linePrefix, diffFactory);
75 }
76 }
77
78 public IDiffEngine Clone()
79 {
80 return new TextFileDiffEngine();
81 }
82 }
83}