Wabbajack.Lib: Some nullability enabled

This commit is contained in:
Justin Swanson 2020-04-09 12:17:24 -05:00
parent 6572f14f49
commit 64f5531411
11 changed files with 42 additions and 28 deletions

View File

@ -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<Archive> ResolveArchive(IndexedArchive archive)

View File

@ -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<Hash, AbsolutePath> HashedArchives { get; set; }
public Dictionary<Hash, AbsolutePath> HashedArchives { get; } = new Dictionary<Hash, AbsolutePath>();
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<Hash, AbsolutePath>(e.Item1, e.Item2)));
}
/// <summary>
@ -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");

View File

@ -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<Archive> GetModUpgrade(Hash hash)
public static async Task<Archive?> GetModUpgrade(Hash hash)
{
using var response = await GetClient()
.GetAsync($"{Consts.WabbajackBuildServerUri}alternative/{hash.ToHex()}");
@ -33,7 +34,7 @@ namespace Wabbajack.Lib
/// </summary>
/// <param name="hash"></param>
/// <returns></returns>
public static async Task<string> GetModIni(Hash hash)
public static async Task<string?> GetModIni(Hash hash)
{
var client = new Common.Http.Client();
try

View File

@ -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<bool> _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<CleanedESM>().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);

View File

@ -2,6 +2,7 @@
using System.Linq;
using Wabbajack.Common;
using Wabbajack.Common.Serialization.Json;
#nullable enable
namespace Wabbajack.Lib
{

View File

@ -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;
/// <summary>
/// Value used in LE ENBs for VideoMemorySizeMb
/// </summary>

View File

@ -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<T>(
ref T item,
T newItem,
[CallerMemberName] string propertyName = null)
[CallerMemberName] string? propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(item, newItem)) return;
item = newItem;

View File

@ -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
{

View File

@ -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
{

View File

@ -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
{

View File

@ -56,7 +56,6 @@ namespace Wabbajack.Util
ScreenHeight = height,
VideoMemorySize = video_memory,
SystemMemorySize = (long)memory.ullTotalPhys,
WindowsVersion = Environment.OSVersion.Version
};
}
}