Skip to content

Commit

Permalink
Pushing Dir Diff System.IO into seperate library to enable support fo…
Browse files Browse the repository at this point in the history
…r unit tests and be more flexible on file system access.
  • Loading branch information
Dirkster99 committed May 22, 2019
1 parent 5d2141e commit 1d40741
Show file tree
Hide file tree
Showing 25 changed files with 474 additions and 218 deletions.
14 changes: 14 additions & 0 deletions source/Aehnlich.sln
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SettingsModel", "Aehnlich\C
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aehnlich", "Aehnlich\Aehnlich\Aehnlich.csproj", "{58BD0E02-6BFF-43F0-9B93-D3371E97794B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FsDataLib", "FsDataLib\FsDataLib.csproj", "{6C8F39A8-965B-4F96-B0DC-5C731519AC65}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -176,6 +178,18 @@ Global
{58BD0E02-6BFF-43F0-9B93-D3371E97794B}.Release|x64.Build.0 = Release|x64
{58BD0E02-6BFF-43F0-9B93-D3371E97794B}.Release|x86.ActiveCfg = Release|x86
{58BD0E02-6BFF-43F0-9B93-D3371E97794B}.Release|x86.Build.0 = Release|x86
{6C8F39A8-965B-4F96-B0DC-5C731519AC65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6C8F39A8-965B-4F96-B0DC-5C731519AC65}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6C8F39A8-965B-4F96-B0DC-5C731519AC65}.Debug|x64.ActiveCfg = Debug|Any CPU
{6C8F39A8-965B-4F96-B0DC-5C731519AC65}.Debug|x64.Build.0 = Debug|Any CPU
{6C8F39A8-965B-4F96-B0DC-5C731519AC65}.Debug|x86.ActiveCfg = Debug|Any CPU
{6C8F39A8-965B-4F96-B0DC-5C731519AC65}.Debug|x86.Build.0 = Debug|Any CPU
{6C8F39A8-965B-4F96-B0DC-5C731519AC65}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6C8F39A8-965B-4F96-B0DC-5C731519AC65}.Release|Any CPU.Build.0 = Release|Any CPU
{6C8F39A8-965B-4F96-B0DC-5C731519AC65}.Release|x64.ActiveCfg = Release|Any CPU
{6C8F39A8-965B-4F96-B0DC-5C731519AC65}.Release|x64.Build.0 = Release|Any CPU
{6C8F39A8-965B-4F96-B0DC-5C731519AC65}.Release|x86.ActiveCfg = Release|Any CPU
{6C8F39A8-965B-4F96-B0DC-5C731519AC65}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
11 changes: 4 additions & 7 deletions source/AehnlichLib/AehnlichLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,23 @@
<Compile Include="Binaries\BinaryDiff.cs" />
<Compile Include="Binaries\BinaryDiffLines.cs" />
<Compile Include="Binaries\Copy.cs" />
<Compile Include="Dir\DataSource\DirectoryInfoImpl.cs" />
<Compile Include="Dir\DataSource\DiffUtility.cs" />
<Compile Include="Dir\DiffUtility.cs" />
<Compile Include="Dir\DirectoryDiff.cs" />
<Compile Include="Dir\DirectoryDiffEntry.cs" />
<Compile Include="Dir\DirectoryDiffEntryCollection.cs" />
<Compile Include="Dir\DirectoryDiffFileFilter.cs" />
<Compile Include="Dir\DirectoryDiffRoot.cs" />
<Compile Include="Dir\DataSource\FileInfoImpl.cs" />
<Compile Include="Dir\DataSource\FileSystemInfoComparer2.cs" />
<Compile Include="Dir\DataSource\FileSystemInfoImpl.cs" />
<Compile Include="Dir\FileSystemInfoComparer.cs" />
<Compile Include="Dir\Merge\MergedEntry.cs" />
<Compile Include="Dir\Merge\MergeIndex.cs" />
<Compile Include="Dir\DataSource\PathUtil.cs" />
<Compile Include="Dir\DirDiffArgs.cs" />
<Compile Include="Enums\CompareType.cs" />
<Compile Include="Enums\DiffType.cs" />
<Compile Include="Enums\DirectorySearchOption.cs" />
<Compile Include="Enums\EditType.cs" />
<Compile Include="Enums\HashType.cs" />
<Compile Include="Enums\DiffDirFileMode.cs" />
<Compile Include="Interfaces\Dir\IDataSource.cs" />
<Compile Include="Interfaces\Dir\IDataSourceFactory.cs" />
<Compile Include="Interfaces\Dir\IDirectoryInfo.cs" />
<Compile Include="Interfaces\Dir\IFileInfo.cs" />
<Compile Include="Interfaces\Dir\IFileSystemInfo.cs" />
Expand Down
45 changes: 0 additions & 45 deletions source/AehnlichLib/Dir/DataSource/PathUtil.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ namespace AehnlichLib.Dir
{
using AehnlichLib.Interfaces;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Xml;
Expand All @@ -13,53 +12,6 @@ namespace AehnlichLib.Dir
public static class DiffUtility
{
#region Public Members

public static bool AreFilesDifferent(string fileName1, string fileName2)
{
return AreFilesDifferent(new FileInfo(fileName1), new FileInfo(fileName2));
}

/// <summary>
/// Returns false if both files are equal and true if they differ
/// (based on a byte size comparison or byte by byte comparison).
/// </summary>
/// <param name="info1"></param>
/// <param name="info2"></param>
/// <returns></returns>
public static bool AreFilesDifferent(FileInfo info1, FileInfo info2)
{
// Before we open the files, compare the sizes. If they are different,
// then the files are certainly different.
if (info1.Length != info2.Length)
{
return true;
}

using (FileStream stream1 = info1.OpenRead())
using (FileStream stream2 = info2.OpenRead())
{
// The previous length check should ensure these are equal.
Debug.Assert(stream1.Length == stream2.Length, "The streams' lengths must be the same.");

// They have the same lengths, so we have to check byte-by-byte. As soon as we find a difference, we can quit.
int byte1, byte2;
do
{
byte1 = stream1.ReadByte();
byte2 = stream2.ReadByte();

if (byte1 != byte2)
{
return true;
}
}
while (byte1 >= 0 && byte2 >= 0);

// The files were byte-by-byte equal.
return false;
}
}

public static IList<string> GetFileTextLines(string fileName, IDiffProgress progress)
{
using (StreamReader reader = new StreamReader(fileName, Encoding.Default, true))
Expand Down
Loading

0 comments on commit 1d40741

Please sign in to comment.