From 04584720a7ca5bf8f21c84a6448b5ec5a4b9d2d8 Mon Sep 17 00:00:00 2001 From: erri120 Date: Sat, 14 Dec 2019 12:10:22 +0100 Subject: [PATCH] Re-added manual files --- Wabbajack.Common/Consts.cs | 2 +- Wabbajack.Lib/CerasConfig.cs | 2 +- .../Downloaders/GameFileSourceDownloader.cs | 82 +++++++++++++++++++ Wabbajack.Lib/VortexCompiler.cs | 74 +++++++++++++++++ Wabbajack.Lib/Wabbajack.Lib.csproj | 1 + 5 files changed, 159 insertions(+), 2 deletions(-) create mode 100644 Wabbajack.Lib/Downloaders/GameFileSourceDownloader.cs diff --git a/Wabbajack.Common/Consts.cs b/Wabbajack.Common/Consts.cs index 7b943710..c839b5f0 100644 --- a/Wabbajack.Common/Consts.cs +++ b/Wabbajack.Common/Consts.cs @@ -33,7 +33,7 @@ namespace Wabbajack.Common public static string WABBAJACK_INCLUDE = "WABBAJACK_INCLUDE"; public static string WABBAJACK_ALWAYS_ENABLE = "WABBAJACK_ALWAYS_ENABLE"; public static string WABBAJACK_NOMATCH_INCLUDE = "WABBAJACK_NOMATCH_INCLUDE"; - //public static string WABBAJACK_VORTEX_MANUAL = "WABBAJACK_VORTEX_MANUAL"; + public static string WABBAJACK_VORTEX_MANUAL = "WABBAJACK_VORTEX_MANUAL"; public static string GAME_PATH_MAGIC_BACK = "{--||GAME_PATH_MAGIC_BACK||--}"; public static string GAME_PATH_MAGIC_DOUBLE_BACK = "{--||GAME_PATH_MAGIC_DOUBLE_BACK||--}"; diff --git a/Wabbajack.Lib/CerasConfig.cs b/Wabbajack.Lib/CerasConfig.cs index 56bd2efc..290bc843 100644 --- a/Wabbajack.Lib/CerasConfig.cs +++ b/Wabbajack.Lib/CerasConfig.cs @@ -24,7 +24,7 @@ namespace Wabbajack.Lib typeof(BSAStateObject), typeof(BSAFileStateObject), typeof(BA2StateObject), typeof(BA2DX10EntryState), typeof(BA2FileEntryState), typeof(MediaFireDownloader.State), typeof(ArchiveMeta), typeof(PropertyFile), typeof(SteamMeta), typeof(SteamWorkshopDownloader), typeof(SteamWorkshopDownloader.State), - typeof(LoversLabDownloader.State), //typeof(GameFileSourceDownloader.State) + typeof(LoversLabDownloader.State), typeof(GameFileSourceDownloader.State) } }; diff --git a/Wabbajack.Lib/Downloaders/GameFileSourceDownloader.cs b/Wabbajack.Lib/Downloaders/GameFileSourceDownloader.cs new file mode 100644 index 00000000..f7b02721 --- /dev/null +++ b/Wabbajack.Lib/Downloaders/GameFileSourceDownloader.cs @@ -0,0 +1,82 @@ +using System.Threading.Tasks; +using Alphaleonis.Win32.Filesystem; +using Wabbajack.Common; +using Wabbajack.Lib.Validation; +using File = Alphaleonis.Win32.Filesystem.File; +using Game = Wabbajack.Common.Game; + +namespace Wabbajack.Lib.Downloaders +{ + public class GameFileSourceDownloader : IDownloader + { + public async Task GetDownloaderState(dynamic archiveINI) + { + var gameName = (string)archiveINI?.General?.gameName; + var gameFile = (string)archiveINI?.General?.gameFile; + + if (gameFile == null || gameFile == null) + return null; + + var game = GameRegistry.GetByMO2ArchiveName(gameName); + if (game == null) return null; + + var path = game.GameLocation(); + var filePath = Path.Combine(path, gameFile); + + if (!File.Exists(filePath)) + return null; + + var hash = filePath.FileHashCached(); + + return new State + { + Game = GameRegistry.GetByMO2ArchiveName(gameName).Game, + GameFile = gameFile, + Hash = hash, + }; + } + + public async Task Prepare() + { + } + + public class State : AbstractDownloadState + { + public Game Game { get; set; } + public string GameFile { get; set; } + public string Hash { get; set; } + + internal string SourcePath => Path.Combine(Game.MetaData().GameLocation(), GameFile); + + public override bool IsWhitelisted(ServerWhitelist whitelist) + { + return true; + } + + public override async Task Download(Archive a, string destination) + { + using(var src = File.OpenRead(SourcePath)) + using (var dest = File.OpenWrite(destination)) + { + var size = new FileInfo(SourcePath).Length; + src.CopyToWithStatus(size, dest, "Copying from Game folder"); + } + } + + public override async Task Verify() + { + return File.Exists(SourcePath) && SourcePath.FileHashCached() == Hash; + } + + public override IDownloader GetDownloader() + { + return DownloadDispatcher.GetInstance(); + } + + public override string GetReportEntry(Archive a) + { + return $"* Game File {Game} - {GameFile}"; + } + } + } +} diff --git a/Wabbajack.Lib/VortexCompiler.cs b/Wabbajack.Lib/VortexCompiler.cs index c331f271..992ef0e0 100644 --- a/Wabbajack.Lib/VortexCompiler.cs +++ b/Wabbajack.Lib/VortexCompiler.cs @@ -171,6 +171,48 @@ namespace Wabbajack.Lib Error($"Found {duplicates.Count} duplicates, exiting"); } + for (var i = 0; i < AllFiles.Count; i++) + { + var f = AllFiles[i]; + if (!f.Path.StartsWith(Consts.GameFolderFilesDir) || !IndexedFiles.ContainsKey(f.Hash)) + continue; + + if (!IndexedFiles.TryGetValue(f.Hash, out var value)) + continue; + + var element = value.ElementAt(0); + + if (!f.Path.Contains(element.Name)) + continue; + + IndexedArchive targetArchive = null; + IndexedArchives.Where(a => a.File.Children.Contains(element)).Do(a => targetArchive = a); + + if (targetArchive == null) + continue; + + if(targetArchive.IniData?.General?.tag == null || targetArchive.IniData?.General?.tag != Consts.WABBAJACK_VORTEX_MANUAL) + continue; + +#if DEBUG + Utils.Log($"Double hash for: {f.AbsolutePath}"); +#endif + + var replace = f; + var name = replace.File.Name; + var archiveName = targetArchive.Name; + var elementPath = element.FullPath.Substring(element.FullPath.IndexOf('|')+1); + var gameToFile = name.Substring(GamePath.Length + 1).Replace(elementPath, ""); + if (gameToFile.EndsWith("\\")) + gameToFile = gameToFile.Substring(0, gameToFile.Length - 1); + //replace.Path = replace.Path.Replace(Consts.GameFolderFilesDir, Consts.ManualGameFilesDir); + replace.Path = Path.Combine(Consts.ManualGameFilesDir, archiveName, gameToFile, elementPath); + //replace.Path = Path.Combine(Consts.ManualGameFilesDir, element.FullPath.Substring(DownloadsFolder.Length + 1).Replace('|', '\\')); + AllFiles.RemoveAt(i); + AllFiles.Insert(i, replace); + //AllFiles.Replace(f, replace); + } + if (cancel.IsCancellationRequested) return false; var stack = MakeStack(); UpdateTracker.NextStep("Running Compilation Stack"); @@ -344,6 +386,38 @@ namespace Wabbajack.Lib } }); + var otherFiles = Directory.EnumerateFiles(DownloadsFolder, "*", SearchOption.TopDirectoryOnly).Where(f => + Path.GetExtension(f) == ".meta" && !ActiveArchives.Contains(Path.GetFileNameWithoutExtension(f))); + + await otherFiles.PMap(Queue, async f => + { + Info($"File {f} is not in ActiveArchives"); + var lines = File.ReadAllLines(f); + if (lines.Length == 0 || !lines.Any(line => lines.Contains("directURL="))) + { + if (lines.Length == 0) + return; + + lines.Do(line => + { + var tag = ""; + if (line.Contains("tag=")) + tag = line.Substring("tag=".Length); + + if (tag != Consts.WABBAJACK_VORTEX_MANUAL) + return; + + Info($"File {f} contains the {Consts.WABBAJACK_VORTEX_MANUAL} tag, adding to ActiveArchives"); + ActiveArchives.Add(Path.GetFileNameWithoutExtension(f)); + }); + } + else + { + Info($"File {f} appears to not be from the Nexus, adding to ActiveArchives"); + ActiveArchives.Add(Path.GetFileNameWithoutExtension(f)); + } + }); + Info($"Checking for Steam Workshop Items..."); if (!_isSteamGame || _steamGame == null || !_hasSteamWorkshopItems) return; diff --git a/Wabbajack.Lib/Wabbajack.Lib.csproj b/Wabbajack.Lib/Wabbajack.Lib.csproj index 6694591b..faa70202 100644 --- a/Wabbajack.Lib/Wabbajack.Lib.csproj +++ b/Wabbajack.Lib/Wabbajack.Lib.csproj @@ -116,6 +116,7 @@ +