Compiler settings automatically save/load

This commit is contained in:
Timothy Baldridge 2022-07-14 07:24:47 -06:00
parent 766bf8e719
commit 25041ab5b3
3 changed files with 32 additions and 24 deletions

View File

@ -12,6 +12,8 @@ public static class Consts
public static Version CurrentMinimumWabbajackVersion { get; set; } = Version.Parse("2.3.0.0"); public static Version CurrentMinimumWabbajackVersion { get; set; } = Version.Parse("2.3.0.0");
public static bool UseNetworkWorkaroundMode { get; set; } = false; public static bool UseNetworkWorkaroundMode { get; set; } = false;
public static AbsolutePath CefCacheLocation { get; } = KnownFolders.WabbajackAppLocal.Combine("Cef"); public static AbsolutePath CefCacheLocation { get; } = KnownFolders.WabbajackAppLocal.Combine("Cef");
public static RelativePath ModListTxt { get; } = "modlist.txt".ToRelativePath();
public static RelativePath CompilerSettings { get; } = "compiler_settings.json".ToRelativePath();
public static byte SettingsVersion = 0; public static byte SettingsVersion = 0;

View File

@ -186,11 +186,23 @@ namespace Wabbajack
private async Task InferModListFromLocation(AbsolutePath path) private async Task InferModListFromLocation(AbsolutePath path)
{ {
using var _ = LoadingLock.WithLoading(); using var _ = LoadingLock.WithLoading();
if (path == default || path.FileName != "modlist.txt".ToRelativePath())
return;
var settings = await _inferencer.InferModListFromLocation(path); CompilerSettings settings;
if (path == default) return;
if (path.FileName.Extension == Ext.CompilerSettings)
{
await using var fs = path.Open(FileMode.Open, FileAccess.Read, FileShare.Read);
settings = (await _dtos.DeserializeAsync<CompilerSettings>(fs))!;
}
else if (path.FileName == "modlist.txt".ToRelativePath())
{
settings = await _inferencer.InferModListFromLocation(path);
if (settings == null) return; if (settings == null) return;
}
else
{
return;
}
BaseGame = settings.Game; BaseGame = settings.Game;
ModListName = settings.ModListName; ModListName = settings.ModListName;
@ -198,6 +210,8 @@ namespace Wabbajack
DownloadLocation.TargetPath = settings.Downloads; DownloadLocation.TargetPath = settings.Downloads;
OutputLocation.TargetPath = settings.OutputFile; OutputLocation.TargetPath = settings.OutputFile;
SelectedProfile = settings.Profile; SelectedProfile = settings.Profile;
PublishUpdate = settings.PublishUpdate;
MachineUrl = settings.MachineUrl;
OtherProfiles = settings.AdditionalProfiles; OtherProfiles = settings.AdditionalProfiles;
AlwaysEnabled = settings.AlwaysEnabled; AlwaysEnabled = settings.AlwaysEnabled;
NoMatchInclude = settings.NoMatchInclude; NoMatchInclude = settings.NoMatchInclude;
@ -210,24 +224,12 @@ namespace Wabbajack
{ {
try try
{ {
await SaveSettingsFile();
var token = CancellationToken.None; var token = CancellationToken.None;
State = CompilerState.Compiling; State = CompilerState.Compiling;
var mo2Settings = new CompilerSettings var mo2Settings = GetSettings();
{ mo2Settings.UseGamePaths = true;
Game = BaseGame,
ModListName = ModListName,
ModListAuthor = Author,
ModlistReadme = Readme,
Source = Source,
Downloads = DownloadLocation.TargetPath,
OutputFile = OutputLocation.TargetPath,
Profile = SelectedProfile,
AdditionalProfiles = OtherProfiles,
AlwaysEnabled = AlwaysEnabled,
NoMatchInclude = NoMatchInclude,
UseGamePaths = true
};
if (PublishUpdate && !await RunPreflightChecks(token)) if (PublishUpdate && !await RunPreflightChecks(token))
{ {
@ -284,14 +286,14 @@ namespace Wabbajack
await using var st = SettingsOutputLocation.Open(FileMode.Create, FileAccess.Write, FileShare.None); await using var st = SettingsOutputLocation.Open(FileMode.Create, FileAccess.Write, FileShare.None);
await JsonSerializer.SerializeAsync(st, GetSettings(), _dtos.Options); await JsonSerializer.SerializeAsync(st, GetSettings(), _dtos.Options);
await _settingsManager.Save(LastSavedCompilerSettings, Source); await _settingsManager.Save(LastSavedCompilerSettings, SettingsOutputLocation);
} }
private async Task LoadLastSavedSettings() private async Task LoadLastSavedSettings()
{ {
var lastPath = await _settingsManager.Load<AbsolutePath>(LastSavedCompilerSettings); var lastPath = await _settingsManager.Load<AbsolutePath>(LastSavedCompilerSettings);
if (Source == default) return; if (lastPath == default || !lastPath.FileExists() || lastPath.FileName.Extension != Ext.CompilerSettings) return;
Source = lastPath; ModlistLocation.TargetPath = lastPath;
} }
@ -302,11 +304,13 @@ namespace Wabbajack
ModListName = ModListName, ModListName = ModListName,
ModListAuthor = Author, ModListAuthor = Author,
Downloads = DownloadLocation.TargetPath, Downloads = DownloadLocation.TargetPath,
Source = ModlistLocation.TargetPath, Source = Source,
Game = BaseGame, Game = BaseGame,
PublishUpdate = PublishUpdate,
MachineUrl = MachineUrl,
Profile = SelectedProfile, Profile = SelectedProfile,
UseGamePaths = true, UseGamePaths = true,
OutputFile = OutputLocation.TargetPath.Combine(SelectedProfile).WithExtension(Ext.Wabbajack), OutputFile = OutputLocation.TargetPath,
AlwaysEnabled = AlwaysEnabled, AlwaysEnabled = AlwaysEnabled,
AdditionalProfiles = OtherProfiles, AdditionalProfiles = OtherProfiles,
NoMatchInclude = NoMatchInclude, NoMatchInclude = NoMatchInclude,

View File

@ -28,6 +28,8 @@ public class CompilerSettings
public string ModlistReadme { get; set; } = ""; public string ModlistReadme { get; set; } = "";
public Uri? ModListWebsite { get; set; } public Uri? ModListWebsite { get; set; }
public Version ModlistVersion { get; set; } = Version.Parse("0.0.1.0"); public Version ModlistVersion { get; set; } = Version.Parse("0.0.1.0");
public bool PublishUpdate { get; set; } = false;
public string MachineUrl { get; set; } = "";
/// <summary> /// <summary>
/// The main (default) profile /// The main (default) profile