Simplify filtering and remove comments

Thanks Linq
This commit is contained in:
Unnoen 2021-01-09 14:57:11 +11:00
parent d28719bd74
commit 5d857386f2
No known key found for this signature in database
GPG Key ID: 8F8E42252BA20553

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
@ -279,41 +279,17 @@ namespace Wabbajack.Lib
public async Task HashArchives()
{
Utils.Log("Looking for files to hash");
// Enumerate all files.
var allFiles = DownloadFolder.EnumerateFiles()
.Concat(Game.GameLocation().EnumerateFiles())
.ToList();
// Create a Dictionary with filesize as the key.
var hashDict = new Dictionary<long, List<AbsolutePath>>();
var hashDict = allFiles.GroupBy(f => f.Size).ToDictionary(g => g.Key);
// Populate the Dictionary with all files we found, using a list for the paths to allow for duplicated filesizes.
allFiles.ForEach(o =>
{
if (hashDict.ContainsKey(o.Size))
{
hashDict[o.Size].Add(o);
}
else
{
hashDict.Add(o.Size, new List<AbsolutePath> { o });
}
});
// Create a list for the files we filter.
var toHash = new List<AbsolutePath>();
// Iterate through required archives, adding any files we have that match filesize.
ModList.Archives.ForEach(o => {
if (hashDict.ContainsKey(o.Size))
{
hashDict[o.Size].ForEach(o => toHash.Add(o));
}
});
var toHash = ModList.Archives.Where(a => hashDict.ContainsKey(a.Size)).SelectMany(a => hashDict[a.Size]).ToList();
Utils.Log($"Found {allFiles.Count} total files, {toHash.Count} matching filesize");
// Hash all the files we added.
var hashResults = await
toHash
.PMap(Queue, UpdateTracker,async e => (await e.FileHashCachedAsync(), e));