From 9d4325a5fecf2133bd2446bb7e6f507213c60c16 Mon Sep 17 00:00:00 2001 From: erri120 Date: Sat, 7 Dec 2019 16:28:34 +0100 Subject: [PATCH 1/2] Updated GameLocation property --- Wabbajack.Common/GameMetaData.cs | 15 ++++----------- Wabbajack.Lib/MO2Installer.cs | 2 +- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/Wabbajack.Common/GameMetaData.cs b/Wabbajack.Common/GameMetaData.cs index eb135acd..11f24dcb 100644 --- a/Wabbajack.Common/GameMetaData.cs +++ b/Wabbajack.Common/GameMetaData.cs @@ -67,19 +67,12 @@ namespace Wabbajack.Common public List RequiredFiles { get; internal set; } public bool Disabled { get; internal set; } - public string GameLocation + public string GameLocation(bool steam) { - get - { - if (Consts.TestMode) - return Directory.GetCurrentDirectory(); + if (Consts.TestMode) + return Directory.GetCurrentDirectory(); - return (string) Registry.GetValue(GameLocationRegistryKey, "installed path", null) - ?? - (string) Registry.GetValue( - GameLocationRegistryKey.Replace(@"HKEY_LOCAL_MACHINE\SOFTWARE\", - @"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\"), "installed path", null); - } + return steam ? SteamHandler.Instance.Games.FirstOrDefault(g => g.Game == Game)?.InstallDir : GOGHandler.Instance.Games.FirstOrDefault(g => g.Game == Game)?.Path; } } diff --git a/Wabbajack.Lib/MO2Installer.cs b/Wabbajack.Lib/MO2Installer.cs index 7d978754..f55e4d84 100644 --- a/Wabbajack.Lib/MO2Installer.cs +++ b/Wabbajack.Lib/MO2Installer.cs @@ -41,7 +41,7 @@ namespace Wabbajack.Lib var game = GameRegistry.Games[ModList.GameType]; if (GameFolder == null) - GameFolder = game.GameLocation; + GameFolder = game.GameLocation(SteamHandler.Instance.Games.Any(g => g.Game == game.Game)); if (GameFolder == null) { From c5858c51c3ba766fe60e9c27a11d42ed3a2919f3 Mon Sep 17 00:00:00 2001 From: erri120 Date: Sat, 7 Dec 2019 17:35:57 +0100 Subject: [PATCH 2/2] Vortex: Manual game files can be copied over --- Wabbajack.Common/Consts.cs | 1 + Wabbajack.Lib/VortexCompiler.cs | 12 +++++-- Wabbajack.Lib/VortexInstaller.cs | 57 +++++++++++++++++++++++++++++++- 3 files changed, 67 insertions(+), 3 deletions(-) diff --git a/Wabbajack.Common/Consts.cs b/Wabbajack.Common/Consts.cs index 329d4b2d..7b73acf5 100644 --- a/Wabbajack.Common/Consts.cs +++ b/Wabbajack.Common/Consts.cs @@ -10,6 +10,7 @@ namespace Wabbajack.Common public static bool TestMode { get; set; } = false; public static string GameFolderFilesDir = "Game Folder Files"; + public static string ManualGameFilesDir = "Manual Game Files"; public static string LOOTFolderFilesDir = "LOOT Config Files"; public static string BSACreationDir = "TEMP_BSA_FILES"; diff --git a/Wabbajack.Lib/VortexCompiler.cs b/Wabbajack.Lib/VortexCompiler.cs index 0f0e0234..9031a699 100644 --- a/Wabbajack.Lib/VortexCompiler.cs +++ b/Wabbajack.Lib/VortexCompiler.cs @@ -180,7 +180,15 @@ namespace Wabbajack.Lib #endif var replace = f; - replace.Path = Path.Combine("Manual Game Files", element.FullPath.Substring(DownloadsFolder.Length + 1).Replace('|', '\\')); + 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); @@ -312,7 +320,7 @@ namespace Wabbajack.Lib .Where(File.Exists) .Do(f => { - if (Path.GetExtension(f) != ".meta" && !File.Exists($"{f}.meta") && ActiveArchives.Contains(Path.GetFileNameWithoutExtension(f))) + if (Path.GetExtension(f) != ".meta" && Path.GetExtension(f) != ".xxHash" && !File.Exists($"{f}.meta") && ActiveArchives.Contains(Path.GetFileNameWithoutExtension(f))) { Utils.Log($"Trying to create meta file for {Path.GetFileName(f)}"); var metaString = "[General]\n" + diff --git a/Wabbajack.Lib/VortexInstaller.cs b/Wabbajack.Lib/VortexInstaller.cs index 802b7a37..98e933f9 100644 --- a/Wabbajack.Lib/VortexInstaller.cs +++ b/Wabbajack.Lib/VortexInstaller.cs @@ -1,8 +1,11 @@ -using System.Diagnostics; +using System; +using System.Diagnostics; +using System.IO; using System.Linq; using System.Windows; using Wabbajack.Common; using Directory = Alphaleonis.Win32.Filesystem.Directory; +using DirectoryInfo = Alphaleonis.Win32.Filesystem.DirectoryInfo; using File = Alphaleonis.Win32.Filesystem.File; using Path = Alphaleonis.Win32.Filesystem.Path; @@ -60,6 +63,7 @@ namespace Wabbajack.Lib BuildFolderStructure(); InstallArchives(); InstallIncludedFiles(); + InstallManualGameFiles(); InstallSteamWorkshopItems(); //InstallIncludedDownloadMetas(); @@ -67,6 +71,57 @@ namespace Wabbajack.Lib return true; } + private void InstallManualGameFiles() + { + if (!ModList.Directives.Any(d => d.To.StartsWith(Consts.ManualGameFilesDir))) + return; + + var result = MessageBox.Show("Some mods from this ModList must be installed directly into " + + "the game folder. Do you want to do this manually or do you want Wabbajack " + + "to do this for you?", "Question", MessageBoxButton.YesNo); + + if (result != MessageBoxResult.Yes) + return; + + var manualFilesDir = Path.Combine(OutputFolder, Consts.ManualGameFilesDir); + + var gameFolder = GameInfo.GameLocation(SteamHandler.Instance.Games.Any(g => g.Game == GameInfo.Game)); + + Info($"Copying files from {manualFilesDir} " + + $"to the game folder at {gameFolder}"); + + if (!Directory.Exists(manualFilesDir)) + { + Info($"{manualFilesDir} does not exist!"); + return; + } + + Directory.EnumerateDirectories(manualFilesDir).PMap(Queue, dir => + { + var dirInfo = new DirectoryInfo(dir); + dirInfo.GetDirectories("*", SearchOption.AllDirectories).Do(d => + { + var destPath = d.FullName.Replace(dir, gameFolder); + Status($"Creating directory {destPath}"); + Directory.CreateDirectory(destPath); + }); + + dirInfo.GetFiles("*", SearchOption.AllDirectories).Do(f => + { + var destPath = f.FullName.Replace(dir, gameFolder); + Status($"Copying file {f.FullName} to {destPath}"); + try + { + File.Copy(f.FullName, destPath); + } + catch (Exception) + { + Info($"Could not copy file {f.FullName} to {destPath}. The file may already exist, skipping..."); + } + }); + }); + } + private void InstallSteamWorkshopItems() { //var currentLib = "";