mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Simplify filtering and remove comments
Thanks Linq
This commit is contained in:
parent
d28719bd74
commit
5d857386f2
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user