Skip to content

Commit

Permalink
Tweak to make hash cache load
Browse files Browse the repository at this point in the history
  • Loading branch information
BlythMeister committed Sep 12, 2016
1 parent f57a5ae commit bac8ca3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/BingWallpaper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<ItemGroup>
<Compile Include="BingInteractionAndParsing.cs" />
<Compile Include="ConsoleWriter.cs" />
<Compile Include="HistogramHash.cs" />
<Compile Include="ImageHashing.cs" />
<Compile Include="ImageMetadataPropertyId.cs" />
<Compile Include="ImagePropertyHandling.cs" />
Expand Down
22 changes: 22 additions & 0 deletions src/HistogramHash.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Collections.Generic;
using System.Linq;

namespace BingWallpaper
{
public class HistogramHash
{
public readonly string FilePath;
public readonly int[] HashValue;

public HistogramHash(string filePath, int[] values)
{
FilePath = filePath;
HashValue = values;
}

public bool Equal(HistogramHash other)
{
return HashValue.SequenceEqual(other.HashValue);
}
}
}
21 changes: 2 additions & 19 deletions src/ImageHashing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal static bool ImageInHash(string tempfilename)

internal static void AddHash(string filePath)
{
if(HistogramHashTable.Any(x=>x.filePath == filePath)) return;
if(HistogramHashTable.Any(x=>x.FilePath == filePath)) return;

HistogramHashTable.Add(GetRGBHistogram(filePath));
}
Expand All @@ -44,24 +44,7 @@ internal static HistogramHash GetRGBHistogram(string file)

File.Delete(histogramfile);

return new HistogramHash(file, values);
}
}

internal class HistogramHash
{
internal readonly string filePath;
internal readonly int[] HashValue;

public HistogramHash(string filePath, List<int> values)
{
this.filePath = filePath;
HashValue = values.ToArray();
}

public bool Equal(HistogramHash other)
{
return HashValue.SequenceEqual(other.HashValue);
return new HistogramHash(file, values.ToArray());
}
}
}
5 changes: 5 additions & 0 deletions src/SetupAndTearDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ internal static void Startup()
ConsoleWriter.WriteLine("Have loaded {0} previous hashes", ImageHashing.HistogramHashTable.Count);

HashExistingImages();

if (ImageHashing.HistogramHashTable.Any())
{
Serializer.Serialize(ImageHashing.HistogramHashTable, Path.Combine(Program.AppData, "imageHistogram.bin"));
}

ClearLogFiles(logPath);
}
Expand Down

0 comments on commit bac8ca3

Please sign in to comment.