-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDiff.cs
103 lines (89 loc) · 3.37 KB
/
Diff.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace Melt
{
class Diff
{
static public void FolderDiff(string path, string path2)
{
if (!Directory.Exists(path))
{
Console.WriteLine("Unable to open {0}", path);
return;
}
if (!Directory.Exists(path2))
{
Console.WriteLine("Unable to open {0}", path2);
return;
}
StreamWriter outputFile = new StreamWriter(new FileStream(".\\diff_results.txt", FileMode.Create, FileAccess.Write));
if (outputFile == null)
{
Console.WriteLine("Unable to open diff_results.txt");
return;
}
string[] fileEntries = Directory.GetFiles(path);
string[] fileEntries2 = Directory.GetFiles(path2);
int fileCounter1 = 0;
int fileCounter2 = 0;
for (int i = 0; i < fileEntries.Length; i++)
{
if (fileEntries2.Length <= i)
break;
string[] filename = fileEntries[fileCounter1].Split('\\');
string[] filename2 = fileEntries2[fileCounter2].Split('\\');
if (filename[filename.Length - 1] != filename2[filename2.Length - 1])
{
fileCounter1++;
continue;
}
else if (!AreFilesEqual(fileEntries[fileCounter1], fileEntries2[fileCounter2]))
{
string[] fileCode = filename[filename.Length - 1].Split('.');
outputFile.WriteLine("writedat client_portal.dat -f {0}=\"Winter\\{1}\"", fileCode[0], filename[filename.Length-1]);
//outputFile.WriteLine("{0} {1}", fileEntries[i], fileEntries2[i]);
outputFile.Flush();
}
fileCounter1++;
fileCounter2++;
}
Console.WriteLine("Done");
outputFile.Close();
}
static public bool AreFilesEqual(string file1, string file2, bool logOnlyDifferences = true)
{
StreamReader inputFile = new StreamReader(new FileStream(file1, FileMode.Open, FileAccess.Read));
if (inputFile == null)
{
Console.WriteLine("Unable to open {0}", file1);
return false;
}
StreamReader inputFile2 = new StreamReader(new FileStream(file2, FileMode.Open, FileAccess.Read));
if (inputFile == null)
{
Console.WriteLine("Unable to open {0}", file2);
return false;
}
Console.WriteLine("Comparing {0} and {1}...",file1, file2);
if (inputFile.BaseStream.Length != inputFile2.BaseStream.Length)
{
return false;
}
for(uint i = 0; i < inputFile.BaseStream.Length; i++)
{
byte a = (byte)inputFile.BaseStream.ReadByte();
byte b = (byte)inputFile2.BaseStream.ReadByte();
if (a != b)
{
return false;
}
}
inputFile.Close();
inputFile2.Close();
//Console.WriteLine("Done");
return true;
}
}
}