diff --git a/Wabbajack.BuildServer/Models/Jobs/EnqueueAllGameFiles.cs b/Wabbajack.BuildServer/Models/Jobs/EnqueueAllGameFiles.cs index 7a393b4e..c1983081 100644 --- a/Wabbajack.BuildServer/Models/Jobs/EnqueueAllGameFiles.cs +++ b/Wabbajack.BuildServer/Models/Jobs/EnqueueAllGameFiles.cs @@ -21,12 +21,12 @@ namespace Wabbajack.BuildServer.Models.Jobs Utils.Log($"Indexing game files"); var states = GameRegistry.Games.Values .Where(game => game.GameLocation() != null && game.MainExecutable != null) - .SelectMany(game => game.GameLocation().Value.EnumerateFiles() + .SelectMany(game => game.GameLocation().EnumerateFiles() .Select(file => new GameFileSourceDownloader.State { Game = game.Game, GameVersion = game.InstalledVersion, - GameFile = file.RelativeTo(game.GameLocation().Value), + GameFile = file.RelativeTo(game.GameLocation()), })) .ToList(); @@ -40,7 +40,7 @@ namespace Wabbajack.BuildServer.Models.Jobs await states.PMap(queue, async state => { - var path = state.Game.MetaData().GameLocation().Value.Combine(state.GameFile); + var path = state.Game.MetaData().GameLocation().Combine(state.GameFile); Utils.Log($"Hashing Game file {path}"); try { diff --git a/Wabbajack.Common/GameMetaData.cs b/Wabbajack.Common/GameMetaData.cs index 80b70bb5..b8d558df 100644 --- a/Wabbajack.Common/GameMetaData.cs +++ b/Wabbajack.Common/GameMetaData.cs @@ -99,9 +99,16 @@ namespace Wabbajack.Common public string? MainExecutable { get; internal set; } - public AbsolutePath? GameLocation() + public AbsolutePath? TryGetGameLocation() { - return Consts.TestMode ? AbsolutePath.GetCurrentDirectory() : StoreHandler.Instance.GetGamePath(Game); + return Consts.TestMode ? AbsolutePath.GetCurrentDirectory() : StoreHandler.Instance.TryGetGamePath(Game); + } + + public AbsolutePath GameLocation() + { + var ret = TryGetGameLocation(); + if (ret == null) throw new ArgumentNullException(); + return ret.Value; } } diff --git a/Wabbajack.Common/StoreHandlers/StoreHandler.cs b/Wabbajack.Common/StoreHandlers/StoreHandler.cs index 52aaf5c5..0547aa28 100644 --- a/Wabbajack.Common/StoreHandlers/StoreHandler.cs +++ b/Wabbajack.Common/StoreHandlers/StoreHandler.cs @@ -52,7 +52,7 @@ namespace Wabbajack.Common.StoreHandlers } } - public AbsolutePath? GetGamePath(Game game) + public AbsolutePath? TryGetGamePath(Game game) { return StoreGames.FirstOrDefault(g => g.Game == game)?.Path; } diff --git a/Wabbajack.Lib/Downloaders/BethesdaNetDownloader.cs b/Wabbajack.Lib/Downloaders/BethesdaNetDownloader.cs index c05d4ed1..879b1025 100644 --- a/Wabbajack.Lib/Downloaders/BethesdaNetDownloader.cs +++ b/Wabbajack.Lib/Downloaders/BethesdaNetDownloader.cs @@ -68,7 +68,7 @@ namespace Wabbajack.Lib.Downloaders public static async Task Login(Game game) { var metadata = game.MetaData(); - var gamePath = metadata.GameLocation()?.Combine(metadata.MainExecutable); + var gamePath = metadata.GameLocation().Combine(metadata.MainExecutable); var info = new ProcessStartInfo { FileName = @"Downloaders\BethesdaNet\bethnetlogin.exe", diff --git a/Wabbajack.Lib/Downloaders/GameFileSourceDownloader.cs b/Wabbajack.Lib/Downloaders/GameFileSourceDownloader.cs index 45f1e80e..dd351330 100644 --- a/Wabbajack.Lib/Downloaders/GameFileSourceDownloader.cs +++ b/Wabbajack.Lib/Downloaders/GameFileSourceDownloader.cs @@ -20,10 +20,9 @@ namespace Wabbajack.Lib.Downloaders var game = GameRegistry.GetByFuzzyName(gameName); if (game == null) return null; - var path = game.GameLocation(); + var path = game.TryGetGameLocation(); var filePath = path?.Combine(gameFile); - if (!filePath?.Exists ?? false) return null; @@ -52,7 +51,7 @@ namespace Wabbajack.Lib.Downloaders public string GameVersion { get; set; } [JsonIgnore] - internal AbsolutePath SourcePath => Game.MetaData().GameLocation().Value.Combine(GameFile); + internal AbsolutePath SourcePath => Game.MetaData().GameLocation().Combine(GameFile); [JsonIgnore] public override object[] PrimaryKey { get => new object[] {Game, GameVersion, GameFile}; } diff --git a/Wabbajack.Test/DownloaderTests.cs b/Wabbajack.Test/DownloaderTests.cs index e1d52437..08614e99 100644 --- a/Wabbajack.Test/DownloaderTests.cs +++ b/Wabbajack.Test/DownloaderTests.cs @@ -415,7 +415,7 @@ namespace Wabbajack.Test await converted.Download(new Archive { Name = "Update.esm" }, filename.Path); Assert.Equal(Hash.FromBase64("/DLG/LjdGXI="), await Utils.FileHashAsync(filename.Path)); - Assert.Equal(await filename.Path.ReadAllBytesAsync(), await Game.SkyrimSpecialEdition.MetaData().GameLocation()?.Combine("Data/Update.esm").ReadAllBytesAsync()); + Assert.Equal(await filename.Path.ReadAllBytesAsync(), await Game.SkyrimSpecialEdition.MetaData().GameLocation().Combine("Data/Update.esm").ReadAllBytesAsync()); Consts.TestMode = true; }