mirror of
https://github.com/RaindropViewer/RaindropViewer.git
synced 2026-07-28 14:53:17 +00:00
46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
using System;
|
|
using System.IO;
|
|
|
|
namespace Disk
|
|
{
|
|
public class FileHelpers
|
|
{
|
|
const int BYTES_TO_READ = sizeof(Int64);
|
|
|
|
public static bool FilesAreEqual(FileInfo first, FileInfo second)
|
|
{
|
|
if (first.Length != second.Length)
|
|
return false;
|
|
|
|
if (string.Equals(first.FullName, second.FullName, StringComparison.OrdinalIgnoreCase))
|
|
return true;
|
|
|
|
using (FileStream fs1 = first.OpenRead())
|
|
using (FileStream fs2 = second.OpenRead())
|
|
{
|
|
if (!FileStreamsAreEqual(fs1, fs2)) return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public static bool FileStreamsAreEqual(Stream fs1, Stream fs2)
|
|
{
|
|
int iterations = (int)Math.Ceiling((double)fs1.Length / BYTES_TO_READ);
|
|
|
|
byte[] one = new byte[BYTES_TO_READ];
|
|
byte[] two = new byte[BYTES_TO_READ];
|
|
|
|
for (int i = 0; i < iterations; i++)
|
|
{
|
|
fs1.Read(one, 0, BYTES_TO_READ);
|
|
fs2.Read(two, 0, BYTES_TO_READ);
|
|
|
|
if (BitConverter.ToInt64(one, 0) != BitConverter.ToInt64(two, 0))
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
} |