From 02631eb503d57affe1903d7851957de2f1bcb498 Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Sun, 18 Oct 2020 07:07:18 -0600 Subject: [PATCH] Archive Indexing into ACompiler --- Wabbajack.Lib/ACompiler.cs | 80 ++++++++++++++++++++++++++++++++++++ Wabbajack.Lib/MO2Compiler.cs | 80 ------------------------------------ 2 files changed, 80 insertions(+), 80 deletions(-) diff --git a/Wabbajack.Lib/ACompiler.cs b/Wabbajack.Lib/ACompiler.cs index 85b75ace..eabdd7fa 100644 --- a/Wabbajack.Lib/ACompiler.cs +++ b/Wabbajack.Lib/ACompiler.cs @@ -198,6 +198,86 @@ namespace Wabbajack.Lib .ToDictionary(gh => gh.Key, gh => gh.Select(p => p.g.Key).ToArray()); } } + + protected async Task CleanInvalidArchivesAndFillState() + { + var remove = (await IndexedArchives.PMap(Queue, async a => + { + try + { + a.State = (await ResolveArchive(a)).State; + return null; + } + catch + { + return a; + } + })).NotNull().ToHashSet(); + + if (remove.Count == 0) + { + return; + } + + Utils.Log( + $"Removing {remove.Count} archives from the compilation state, this is probably not an issue but reference this if you have compilation failures"); + remove.Do(r => Utils.Log($"Resolution failed for: ({r.File.Size} {r.File.Hash}) {r.File.FullPath}")); + IndexedArchives.RemoveAll(a => remove.Contains(a)); + } + + protected async Task InferMetas() + { + async Task HasInvalidMeta(AbsolutePath filename) + { + var metaname = filename.WithExtension(Consts.MetaFileExtension); + if (!metaname.Exists) + { + return true; + } + + try + { + return await DownloadDispatcher.ResolveArchive(metaname.LoadIniFile()) == null; + } + catch (Exception e) + { + Utils.ErrorThrow(e, $"Exception while checking meta {filename}"); + return false; + } + } + + var to_find = (await DownloadsPath.EnumerateFiles() + .Where(f => f.Extension != Consts.MetaFileExtension && f.Extension != Consts.HashFileExtension) + .PMap(Queue, async f => await HasInvalidMeta(f) ? f : default)) + .Where(f => f.Exists) + .ToList(); + + if (to_find.Count == 0) + { + return; + } + + Utils.Log($"Attempting to infer {to_find.Count} metas from the server."); + + await to_find.PMap(Queue, async f => + { + var vf = VFS.Index.ByRootPath[f]; + + var meta = await ClientAPI.InferDownloadState(vf.Hash); + + if (meta == null) + { + await vf.AbsoluteName.WithExtension(Consts.MetaFileExtension).WriteAllLinesAsync( + "[General]", + "unknownArchive=true"); + return; + } + + Utils.Log($"Inferred .meta for {vf.FullPath.FileName}, writing to disk"); + await vf.AbsoluteName.WithExtension(Consts.MetaFileExtension) + .WriteAllTextAsync(meta.GetMetaIniString()); + }); + } public async Task ExportModList() { diff --git a/Wabbajack.Lib/MO2Compiler.cs b/Wabbajack.Lib/MO2Compiler.cs index 4bf96d6b..7f7b151a 100644 --- a/Wabbajack.Lib/MO2Compiler.cs +++ b/Wabbajack.Lib/MO2Compiler.cs @@ -379,86 +379,6 @@ namespace Wabbajack.Lib return true; } - private async Task CleanInvalidArchivesAndFillState() - { - var remove = (await IndexedArchives.PMap(Queue, async a => - { - try - { - a.State = (await ResolveArchive(a)).State; - return null; - } - catch - { - return a; - } - })).NotNull().ToHashSet(); - - if (remove.Count == 0) - { - return; - } - - Utils.Log( - $"Removing {remove.Count} archives from the compilation state, this is probably not an issue but reference this if you have compilation failures"); - remove.Do(r => Utils.Log($"Resolution failed for: ({r.File.Size} {r.File.Hash}) {r.File.FullPath}")); - IndexedArchives.RemoveAll(a => remove.Contains(a)); - } - - private async Task InferMetas() - { - async Task HasInvalidMeta(AbsolutePath filename) - { - var metaname = filename.WithExtension(Consts.MetaFileExtension); - if (!metaname.Exists) - { - return true; - } - - try - { - return await DownloadDispatcher.ResolveArchive(metaname.LoadIniFile()) == null; - } - catch (Exception e) - { - Utils.ErrorThrow(e, $"Exception while checking meta {filename}"); - return false; - } - } - - var to_find = (await DownloadsPath.EnumerateFiles() - .Where(f => f.Extension != Consts.MetaFileExtension && f.Extension != Consts.HashFileExtension) - .PMap(Queue, async f => await HasInvalidMeta(f) ? f : default)) - .Where(f => f.Exists) - .ToList(); - - if (to_find.Count == 0) - { - return; - } - - Utils.Log($"Attempting to infer {to_find.Count} metas from the server."); - - await to_find.PMap(Queue, async f => - { - var vf = VFS.Index.ByRootPath[f]; - - var meta = await ClientAPI.InferDownloadState(vf.Hash); - - if (meta == null) - { - await vf.AbsoluteName.WithExtension(Consts.MetaFileExtension).WriteAllLinesAsync( - "[General]", - "unknownArchive=true"); - return; - } - - Utils.Log($"Inferred .meta for {vf.FullPath.FileName}, writing to disk"); - await vf.AbsoluteName.WithExtension(Consts.MetaFileExtension) - .WriteAllTextAsync(meta.GetMetaIniString()); - }); - } - private async Task IncludeArchiveMetadata() { Utils.Log($"Including {SelectedArchives.Count} .meta files for downloads");