Add State file

This commit is contained in:
pizzaboxer 2023-02-04 17:44:08 +00:00
parent 93b082263b
commit c1b892787a
8 changed files with 51 additions and 34 deletions

View File

@ -26,6 +26,7 @@ namespace Bloxstrap
public const string ProjectRepository = "pizzaboxer/bloxstrap";
public static string BaseDirectory = null!;
public static bool ShouldSaveConfigs { get; set; } = false;
public static bool IsSetupComplete { get; set; } = true;
public static bool IsFirstRun { get; private set; } = false;
public static bool IsQuiet { get; private set; } = false;
@ -38,6 +39,7 @@ namespace Bloxstrap
public static string Version = Assembly.GetExecutingAssembly().GetName().Version!.ToString()[..^2];
public static readonly JsonManager<Settings> Settings = new();
public static readonly JsonManager<State> State = new();
public static readonly HttpClient HttpClient = new(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.All });
// shorthand
@ -52,6 +54,7 @@ namespace Bloxstrap
public static void Terminate(int code = Bootstrapper.ERROR_SUCCESS)
{
Settings.Save();
State.Save();
Environment.Exit(code);
}
@ -115,8 +118,9 @@ namespace Bloxstrap
// just in case the user decides to cancel the install
if (!IsFirstRun)
{
ShouldSaveConfigs = true;
Settings.Load();
Settings.ShouldSave = true;
State.Load();
}
#if !DEBUG

View File

@ -86,7 +86,7 @@ namespace Bloxstrap
public Bootstrapper(string? launchCommandLine = null)
{
LaunchCommandLine = launchCommandLine;
FreshInstall = String.IsNullOrEmpty(App.Settings.Prop.VersionGuid);
FreshInstall = String.IsNullOrEmpty(App.State.Prop.VersionGuid);
}
// this is called from BootstrapperStyleForm.SetupDialog()
@ -107,11 +107,14 @@ namespace Bloxstrap
// if bloxstrap is installing for the first time but is running, prompt to close roblox
// if roblox needs updating but is running, ignore update for now
if (!Directory.Exists(VersionFolder) && CheckIfRunning(true) || App.Settings.Prop.VersionGuid != VersionGuid && !CheckIfRunning(false))
if (!Directory.Exists(VersionFolder) && CheckIfRunning(true) || App.State.Prop.VersionGuid != VersionGuid && !CheckIfRunning(false))
await InstallLatestVersion();
if (App.IsFirstRun)
App.Settings.ShouldSave = true;
{
//App.Settings.ShouldSave = App.State.ShouldSave = true;
App.ShouldSaveConfigs = true;
}
await ApplyModifications();
@ -123,6 +126,7 @@ namespace Bloxstrap
await RbxFpsUnlocker.CheckInstall();
App.Settings.Save();
App.State.Save();
if (App.IsFirstRun && App.IsNoLaunch)
Dialog.ShowSuccess($"{App.ProjectName} has successfully installed");
@ -413,7 +417,8 @@ namespace Bloxstrap
Dialog.Message = $"Uninstalling {App.ProjectName}...";
App.Settings.ShouldSave = false;
//App.Settings.ShouldSave = false;
App.ShouldSaveConfigs = false;
// check if stock bootstrapper is still installed
RegistryKey? bootstrapperKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall\roblox-player");
@ -540,9 +545,9 @@ namespace Bloxstrap
File.Delete(filename);
}
string oldVersionFolder = Path.Combine(Directories.Versions, App.Settings.Prop.VersionGuid);
string oldVersionFolder = Path.Combine(Directories.Versions, App.State.Prop.VersionGuid);
if (VersionGuid != App.Settings.Prop.VersionGuid && Directory.Exists(oldVersionFolder))
if (VersionGuid != App.State.Prop.VersionGuid && Directory.Exists(oldVersionFolder))
{
// and also to delete our old version folder
Directory.Delete(oldVersionFolder, true);
@ -551,7 +556,7 @@ namespace Bloxstrap
Dialog.CancelEnabled = false;
App.Settings.Prop.VersionGuid = VersionGuid;
App.State.Prop.VersionGuid = VersionGuid;
}
private async Task ApplyModifications()

View File

@ -53,15 +53,14 @@ namespace Bloxstrap.Helpers.Integrations
public static async Task CheckInstall()
{
if (App.BaseDirectory is null)
return;
string folderLocation = Path.Combine(App.BaseDirectory, "Integrations\\rbxfpsunlocker");
string fileLocation = Path.Combine(folderLocation, "rbxfpsunlocker.exe");
string settingsLocation = Path.Combine(folderLocation, "settings");
if (!App.Settings.Prop.RFUEnabled)
{
App.State.Prop.RbxFpsUnlockerVersion = "";
if (Directory.Exists(folderLocation))
{
CheckIfRunning();
@ -83,7 +82,7 @@ namespace Bloxstrap.Helpers.Integrations
if (File.Exists(fileLocation))
{
// no new release published, return
if (App.Settings.Prop.RFUVersion == releaseInfo.TagName)
if (App.State.Prop.RbxFpsUnlockerVersion == releaseInfo.TagName)
return;
CheckIfRunning();
@ -104,7 +103,7 @@ namespace Bloxstrap.Helpers.Integrations
if (!File.Exists(settingsLocation))
await File.WriteAllTextAsync(settingsLocation, Settings);
App.Settings.Prop.RFUVersion = releaseInfo.TagName;
App.State.Prop.RbxFpsUnlockerVersion = releaseInfo.TagName;
}
}
}

View File

@ -129,7 +129,7 @@ namespace Bloxstrap.Helpers.Integrations
// config synchronization will be done whenever roblox updates or whenever we launch roblox
string modFolderConfigPath = ConfigLocation;
string versionFolderConfigPath = Path.Combine(Directories.Versions, App.Settings.Prop.VersionGuid, "ReShade.ini");
string versionFolderConfigPath = Path.Combine(Directories.Versions, App.State.Prop.VersionGuid, "ReShade.ini");
// we shouldn't be here if the mod config doesn't already exist
if (!File.Exists(modFolderConfigPath))
@ -326,7 +326,7 @@ namespace Bloxstrap.Helpers.Integrations
if (!App.Settings.Prop.UseReShadeExtraviPresets)
{
UninstallExtraviPresets();
App.Settings.Prop.ExtraviPresetsVersion = "";
App.State.Prop.ExtraviReShadePresetsVersion = "";
}
if (!App.Settings.Prop.UseReShade)
@ -337,7 +337,7 @@ namespace Bloxstrap.Helpers.Integrations
File.Delete(injectorLocation);
File.Delete(ConfigLocation);
App.Settings.Prop.ReShadeConfigVersion = "";
App.State.Prop.ReShadeConfigVersion = "";
//DeleteShaders("Stock");
if (Directory.Exists(BaseDirectory))
@ -373,7 +373,7 @@ namespace Bloxstrap.Helpers.Integrations
// check if we should download a fresh copy of the config
// extravi may need to update the config ota, in which case we'll redownload it
if (!File.Exists(ConfigLocation) || versionManifest is not null && App.Settings.Prop.ReShadeConfigVersion != versionManifest.ConfigFile)
if (!File.Exists(ConfigLocation) || versionManifest is not null && App.State.Prop.ReShadeConfigVersion != versionManifest.ConfigFile)
shouldFetchConfig = true;
if (shouldFetchReShade)
@ -393,15 +393,15 @@ namespace Bloxstrap.Helpers.Integrations
await DownloadConfig();
if (versionManifest is not null)
App.Settings.Prop.ReShadeConfigVersion = versionManifest.ConfigFile;
App.State.Prop.ReShadeConfigVersion = versionManifest.ConfigFile;
}
await DownloadShaders("Stock");
if (App.Settings.Prop.UseReShadeExtraviPresets && App.Settings.Prop.ExtraviPresetsVersion != versionManifest!.Presets)
if (App.Settings.Prop.UseReShadeExtraviPresets && App.State.Prop.ExtraviReShadePresetsVersion != versionManifest!.Presets)
{
await InstallExtraviPresets();
App.Settings.Prop.ExtraviPresetsVersion = versionManifest.Presets;
App.State.Prop.ExtraviReShadePresetsVersion = versionManifest.Presets;
}
SynchronizeConfigFile();

View File

@ -16,7 +16,7 @@ namespace Bloxstrap.Helpers
public class JsonManager<T> where T : new()
{
public T Prop { get; set; } = new T();
public bool ShouldSave { get; set; } = true;
//public bool ShouldSave { get; set; } = true;
public string FileLocation => Path.Combine(Directories.Base, $"{typeof(T).Name}.json");
//public string? FileLocation { get; set; } = null;
@ -50,7 +50,8 @@ namespace Bloxstrap.Helpers
// return;
//}
if (!ShouldSave)
//if (!ShouldSave)
if (!App.ShouldSaveConfigs)
{
Debug.WriteLine($"[JsonManager<{typeof(T).Name}>] Aborted save (ShouldSave set to false)");
return;

View File

@ -5,15 +5,6 @@ namespace Bloxstrap.Models
{
public class Settings
{
// could these be moved to a separate file (something like State.json)?
// the only problem is i havent yet figured out a way to boil down the settings handler to reduce boilerplate
// as the Program class needs a Settings and a SettingsManager property
// once i figure that out, then ig i could move these
public string VersionGuid { get; set; } = "";
public string RFUVersion { get; set; } = "";
public string ReShadeConfigVersion { get; set; } = "";
public string ExtraviPresetsVersion { get; set; } = "";
// bloxstrap configuration
public BootstrapperStyle BootstrapperStyle { get; set; } = BootstrapperStyle.ProgressDialog;
public BootstrapperIcon BootstrapperIcon { get; set; } = BootstrapperIcon.IconBloxstrap;

16
Bloxstrap/Models/State.cs Normal file
View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bloxstrap.Models
{
public class State
{
public string VersionGuid { get; set; } = "";
public string RbxFpsUnlockerVersion { get; set; } = "";
public string ReShadeConfigVersion { get; set; } = "";
public string ExtraviReShadePresetsVersion { get; set; } = "";
}
}

View File

@ -64,13 +64,14 @@ namespace Bloxstrap.ViewModels
if (!App.IsFirstRun)
{
App.Settings.ShouldSave = true;
//App.Settings.ShouldSave = true;
App.ShouldSaveConfigs = true;
if (App.BaseDirectory != _originalBaseDirectory)
{
App.ShowMessageBox($"{App.ProjectName} will install to the new location you've set the next time it runs.", MessageBoxImage.Information);
App.Settings.Prop.VersionGuid = "";
App.State.Prop.VersionGuid = "";
using (RegistryKey registryKey = Registry.CurrentUser.CreateSubKey($@"Software\{App.ProjectName}"))
{