Skip to content

Commit

Permalink
fix list load bug
Browse files Browse the repository at this point in the history
  • Loading branch information
poma committed Sep 7, 2017
1 parent a6848ed commit 19365c3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
11 changes: 4 additions & 7 deletions Hotsapi.Uploader.Common/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,10 @@ private async Task UploadLoop()
var analyzer = new Analyzer();
var monitor = new Monitor();

var replays = _storage.Load().ToList();
var filenames = replays.ToDictionary(x => x.Filename);
replays.AddRange(monitor.ScanReplays()
.Where(x => !filenames.ContainsKey(x))
.Select(x => new ReplayFile(x))
.Where(x => x.Created != filenames[x.Filename].Created)
);
var replays = new List<ReplayFile>(_storage.Load());
var lookup = new HashSet<ReplayFile>(replays);
var comparer = new ReplayFile.ReplayFileComparer();
replays.AddRange(monitor.ScanReplays().Select(x => new ReplayFile(x)).Where(x => !lookup.Contains(x, comparer)));
replays.OrderByDescending(x => x.Created).Map(x => Files.Add(x));

monitor.ReplayAdded += async (_, e) => {
Expand Down
14 changes: 14 additions & 0 deletions Hotsapi.Uploader.Common/ReplayFile.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -46,5 +47,18 @@ public override string ToString()
}

public event PropertyChangedEventHandler PropertyChanged;

public class ReplayFileComparer : IEqualityComparer<ReplayFile>
{
public bool Equals(ReplayFile x, ReplayFile y)
{
return x.Filename == y.Filename && x.Created == y.Created;
}

public int GetHashCode(ReplayFile obj)
{
return obj.Filename.GetHashCode() ^ obj.Created.GetHashCode();
}
}
}
}
4 changes: 2 additions & 2 deletions Hotsapi.Uploader.Windows/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.4.0.0")]
[assembly: AssemblyFileVersion("1.4.0.0")]
[assembly: AssemblyVersion("1.4.1.0")]
[assembly: AssemblyFileVersion("1.4.1.0")]

0 comments on commit 19365c3

Please sign in to comment.