From 64f5531411bbf911f18878eae9511a902c19b77b Mon Sep 17 00:00:00 2001 From: Justin Swanson Date: Thu, 9 Apr 2020 12:17:24 -0500 Subject: [PATCH] Wabbajack.Lib: Some nullability enabled --- Wabbajack.Lib/ACompiler.cs | 8 +++--- Wabbajack.Lib/AInstaller.cs | 16 ++++++++---- Wabbajack.Lib/ClientAPI.cs | 5 ++-- Wabbajack.Lib/MO2Installer.cs | 26 ++++++++++--------- Wabbajack.Lib/Manifest.cs | 1 + Wabbajack.Lib/SystemParameters.cs | 7 ++--- Wabbajack.Lib/ViewModel.cs | 3 ++- Wabbajack.Lib/VortexCompiler.cs | 1 + Wabbajack.Lib/VortexInstaller.cs | 1 + Wabbajack.Lib/zEditIntegration.cs | 1 + Wabbajack/Util/SystemParametersConstructor.cs | 1 - 11 files changed, 42 insertions(+), 28 deletions(-) diff --git a/Wabbajack.Lib/ACompiler.cs b/Wabbajack.Lib/ACompiler.cs index ba162ca2..aa036ddd 100644 --- a/Wabbajack.Lib/ACompiler.cs +++ b/Wabbajack.Lib/ACompiler.cs @@ -14,15 +14,16 @@ using Wabbajack.VirtualFileSystem; using Directory = Alphaleonis.Win32.Filesystem.Directory; using File = Alphaleonis.Win32.Filesystem.File; using Path = Alphaleonis.Win32.Filesystem.Path; +#nullable enable namespace Wabbajack.Lib { public abstract class ACompiler : ABatchProcessor { - public string ModListName, ModListAuthor, ModListDescription, ModListWebsite; + public string? ModListName, ModListAuthor, ModListDescription, ModListWebsite; public AbsolutePath ModListImage, ModListReadme; public bool ReadmeIsWebsite; - protected Version WabbajackVersion; + protected Version? WabbajackVersion; public abstract AbsolutePath VFSCacheName { get; } //protected string VFSCacheName => Path.Combine(Consts.LocalAppDataPath, $"vfs_compile_cache.bin"); @@ -231,8 +232,7 @@ namespace Wabbajack.Lib return await ResolveArchive(found); } - Error($"No match found for Archive sha: {hash.ToBase64()} this shouldn't happen"); - return null; + throw new ArgumentException($"No match found for Archive sha: {hash.ToBase64()} this shouldn't happen"); } public async Task ResolveArchive(IndexedArchive archive) diff --git a/Wabbajack.Lib/AInstaller.cs b/Wabbajack.Lib/AInstaller.cs index 43719b81..ac103756 100644 --- a/Wabbajack.Lib/AInstaller.cs +++ b/Wabbajack.Lib/AInstaller.cs @@ -13,6 +13,7 @@ using Directory = Alphaleonis.Win32.Filesystem.Directory; using File = Alphaleonis.Win32.Filesystem.File; using FileInfo = Alphaleonis.Win32.Filesystem.FileInfo; using Path = Alphaleonis.Win32.Filesystem.Path; +#nullable enable namespace Wabbajack.Lib { @@ -27,7 +28,7 @@ namespace Wabbajack.Lib public AbsolutePath ModListArchive { get; private set; } public ModList ModList { get; private set; } - public Dictionary HashedArchives { get; set; } + public Dictionary HashedArchives { get; } = new Dictionary(); public SystemParameters SystemParameters { get; set; } @@ -279,11 +280,11 @@ namespace Wabbajack.Lib var hashResults = await DownloadFolder.EnumerateFiles() .Where(e => e.Extension != Consts.HashFileExtension) .PMap(Queue, async e => (await e.FileHashCachedAsync(), e)); - HashedArchives = hashResults + HashedArchives.Add(hashResults .OrderByDescending(e => e.Item2.LastModified) .GroupBy(e => e.Item1) .Select(e => e.First()) - .ToDictionary(e => e.Item1, e => e.Item2); + .Select(e => new KeyValuePair(e.Item1, e.Item2))); } /// @@ -392,8 +393,13 @@ namespace Wabbajack.Lib return await path.FileHashAsync() == d.Hash ? d : null; })) - .Where(d => d != null) - .Do(d => indexed.Remove(d.To)); + .Do(d => + { + if (d != null) + { + indexed.Remove(d.To); + } + }); UpdateTracker.NextStep("Updating ModList"); Utils.Log($"Optimized {ModList.Directives.Count} directives to {indexed.Count} required"); diff --git a/Wabbajack.Lib/ClientAPI.cs b/Wabbajack.Lib/ClientAPI.cs index c750782b..80fc2043 100644 --- a/Wabbajack.Lib/ClientAPI.cs +++ b/Wabbajack.Lib/ClientAPI.cs @@ -1,6 +1,7 @@ using System.Threading.Tasks; using Wabbajack.Common; using Wabbajack.Lib.Exceptions; +#nullable enable namespace Wabbajack.Lib { @@ -14,7 +15,7 @@ namespace Wabbajack.Lib return client; } - public static async Task GetModUpgrade(Hash hash) + public static async Task GetModUpgrade(Hash hash) { using var response = await GetClient() .GetAsync($"{Consts.WabbajackBuildServerUri}alternative/{hash.ToHex()}"); @@ -33,7 +34,7 @@ namespace Wabbajack.Lib /// /// /// - public static async Task GetModIni(Hash hash) + public static async Task GetModIni(Hash hash) { var client = new Common.Http.Client(); try diff --git a/Wabbajack.Lib/MO2Installer.cs b/Wabbajack.Lib/MO2Installer.cs index 050ab03a..ab4af57a 100644 --- a/Wabbajack.Lib/MO2Installer.cs +++ b/Wabbajack.Lib/MO2Installer.cs @@ -21,6 +21,7 @@ using Directory = Alphaleonis.Win32.Filesystem.Directory; using File = Alphaleonis.Win32.Filesystem.File; using Path = Alphaleonis.Win32.Filesystem.Path; using SectionData = Wabbajack.Common.SectionData; +#nullable enable namespace Wabbajack.Lib { @@ -32,6 +33,8 @@ namespace Wabbajack.Lib public AbsolutePath? GameFolder { get; set; } + public GameMetaData Game { get; } + public MO2Installer(AbsolutePath archive, ModList modList, AbsolutePath outputFolder, AbsolutePath downloadFolder, SystemParameters parameters) : base( archive: archive, @@ -41,6 +44,7 @@ namespace Wabbajack.Lib parameters: parameters, steps: 20) { + Game = ModList.GameType.MetaData(); } protected override async Task _Begin(CancellationToken cancel) @@ -50,27 +54,26 @@ namespace Wabbajack.Lib Utils.Log("Configuring Processor"); Queue.SetActiveThreadsObservable(ConstructDynamicNumThreads(await RecommendQueueSize())); - var game = ModList.GameType.MetaData(); if (GameFolder == null) - GameFolder = game.GameLocation(); + GameFolder = Game.GameLocation(); if (GameFolder == null) { - var otherGame = game.CommonlyConfusedWith.Where(g => g.MetaData().IsInstalled).Select(g => g.MetaData()).FirstOrDefault(); + var otherGame = Game.CommonlyConfusedWith.Where(g => g.MetaData().IsInstalled).Select(g => g.MetaData()).FirstOrDefault(); if (otherGame != null) { await Utils.Log(new CriticalFailureIntervention( - $"In order to do a proper install Wabbajack needs to know where your {game.HumanFriendlyGameName} folder resides. However this game doesn't seem to be installed, we did however find a installed " + + $"In order to do a proper install Wabbajack needs to know where your {Game.HumanFriendlyGameName} folder resides. However this game doesn't seem to be installed, we did however find a installed " + $"copy of {otherGame.HumanFriendlyGameName}, did you install the wrong game?", - $"Could not locate {game.HumanFriendlyGameName}")) + $"Could not locate {Game.HumanFriendlyGameName}")) .Task; } else { await Utils.Log(new CriticalFailureIntervention( - $"In order to do a proper install Wabbajack needs to know where your {game.HumanFriendlyGameName} folder resides. However this game doesn't seem to be installed", - $"Could not locate {game.HumanFriendlyGameName}")) + $"In order to do a proper install Wabbajack needs to know where your {Game.HumanFriendlyGameName} folder resides. However this game doesn't seem to be installed", + $"Could not locate {Game.HumanFriendlyGameName}")) .Task; } @@ -170,7 +173,6 @@ namespace Wabbajack.Lib private void CreateOutputMods() { - OutputFolder.Combine("profiles") .EnumerateFiles(true) .Where(f => f.FileName == Consts.SettingsIni) @@ -236,7 +238,7 @@ namespace Wabbajack.Lib foreach (var esm in ModList.Directives.OfType().ToList()) { var filename = esm.To.FileName; - var gameFile = GameFolder.Value.Combine((RelativePath)"Data", filename); + var gameFile = GameFolder!.Value.Combine((RelativePath)"Data", filename); Utils.Log($"Validating {filename}"); var hash = gameFile.FileHash(); if (hash != esm.SourceESMHash) @@ -311,7 +313,7 @@ namespace Wabbajack.Lib private async Task GenerateCleanedESM(CleanedESM directive) { var filename = directive.To.FileName; - var gameFile = GameFolder.Value.Combine((RelativePath)"Data", filename); + var gameFile = GameFolder!.Value.Combine((RelativePath)"Data", filename); Info($"Generating cleaned ESM for {filename}"); if (!gameFile.Exists) throw new InvalidDataException($"Missing {filename} at {gameFile}"); Status($"Hashing game version of {filename}"); @@ -376,8 +378,8 @@ namespace Wabbajack.Lib { var data = Encoding.UTF8.GetString(await LoadBytesFromPath(directive.SourceDataID)); - data = data.Replace(Consts.GAME_PATH_MAGIC_BACK, (string)GameFolder); - data = data.Replace(Consts.GAME_PATH_MAGIC_DOUBLE_BACK, ((string)GameFolder).Replace("\\", "\\\\")); + data = data.Replace(Consts.GAME_PATH_MAGIC_BACK, (string)GameFolder!); + data = data.Replace(Consts.GAME_PATH_MAGIC_DOUBLE_BACK, ((string)GameFolder!).Replace("\\", "\\\\")); data = data.Replace(Consts.GAME_PATH_MAGIC_FORWARD, ((string)GameFolder).Replace("\\", "/")); data = data.Replace(Consts.MO2_PATH_MAGIC_BACK, (string)OutputFolder); diff --git a/Wabbajack.Lib/Manifest.cs b/Wabbajack.Lib/Manifest.cs index 4058e922..00ce5d6a 100644 --- a/Wabbajack.Lib/Manifest.cs +++ b/Wabbajack.Lib/Manifest.cs @@ -2,6 +2,7 @@ using System.Linq; using Wabbajack.Common; using Wabbajack.Common.Serialization.Json; +#nullable enable namespace Wabbajack.Lib { diff --git a/Wabbajack.Lib/SystemParameters.cs b/Wabbajack.Lib/SystemParameters.cs index 1964b8c1..2dc7c9d5 100644 --- a/Wabbajack.Lib/SystemParameters.cs +++ b/Wabbajack.Lib/SystemParameters.cs @@ -1,4 +1,5 @@ using System; +#nullable enable namespace Wabbajack.Lib { @@ -14,9 +15,9 @@ namespace Wabbajack.Lib public int ScreenWidth { get; set; } public long VideoMemorySize { get; set; } public long SystemMemorySize { get; set; } - - public Version WindowsVersion { get; set; } - + + public Version WindowsVersion { get; set; } = Environment.OSVersion.Version; + /// /// Value used in LE ENBs for VideoMemorySizeMb /// diff --git a/Wabbajack.Lib/ViewModel.cs b/Wabbajack.Lib/ViewModel.cs index 6b2b06fc..ce5da622 100644 --- a/Wabbajack.Lib/ViewModel.cs +++ b/Wabbajack.Lib/ViewModel.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Reactive.Disposables; using System.Runtime.CompilerServices; +#nullable enable namespace Wabbajack.Lib { @@ -24,7 +25,7 @@ namespace Wabbajack.Lib protected void RaiseAndSetIfChanged( ref T item, T newItem, - [CallerMemberName] string propertyName = null) + [CallerMemberName] string? propertyName = null) { if (EqualityComparer.Default.Equals(item, newItem)) return; item = newItem; diff --git a/Wabbajack.Lib/VortexCompiler.cs b/Wabbajack.Lib/VortexCompiler.cs index 4ad94116..8f0e3022 100644 --- a/Wabbajack.Lib/VortexCompiler.cs +++ b/Wabbajack.Lib/VortexCompiler.cs @@ -15,6 +15,7 @@ using Wabbajack.Lib.NexusApi; using Wabbajack.Lib.Validation; using File = Alphaleonis.Win32.Filesystem.File; using Game = Wabbajack.Common.Game; +#nullable enable namespace Wabbajack.Lib { diff --git a/Wabbajack.Lib/VortexInstaller.cs b/Wabbajack.Lib/VortexInstaller.cs index 78ba8d1e..dd0ad998 100644 --- a/Wabbajack.Lib/VortexInstaller.cs +++ b/Wabbajack.Lib/VortexInstaller.cs @@ -11,6 +11,7 @@ using Directory = Alphaleonis.Win32.Filesystem.Directory; using DirectoryInfo = Alphaleonis.Win32.Filesystem.DirectoryInfo; using File = Alphaleonis.Win32.Filesystem.File; using Path = Alphaleonis.Win32.Filesystem.Path; +#nullable disable namespace Wabbajack.Lib { diff --git a/Wabbajack.Lib/zEditIntegration.cs b/Wabbajack.Lib/zEditIntegration.cs index a4e67b0e..3b4dbb72 100644 --- a/Wabbajack.Lib/zEditIntegration.cs +++ b/Wabbajack.Lib/zEditIntegration.cs @@ -9,6 +9,7 @@ using Directory = Alphaleonis.Win32.Filesystem.Directory; using File = Alphaleonis.Win32.Filesystem.File; using Path = Alphaleonis.Win32.Filesystem.Path; using System.Threading.Tasks; +#nullable disable namespace Wabbajack.Lib { diff --git a/Wabbajack/Util/SystemParametersConstructor.cs b/Wabbajack/Util/SystemParametersConstructor.cs index 28abeafb..cad457b9 100644 --- a/Wabbajack/Util/SystemParametersConstructor.cs +++ b/Wabbajack/Util/SystemParametersConstructor.cs @@ -56,7 +56,6 @@ namespace Wabbajack.Util ScreenHeight = height, VideoMemorySize = video_memory, SystemMemorySize = (long)memory.ullTotalPhys, - WindowsVersion = Environment.OSVersion.Version }; } }