Browse Source

Create settings init function in App

pull/5/head^2
Ionite 1 year ago
parent
commit
fa5c374d47
No known key found for this signature in database
  1. 29
      StabilityMatrix/App.xaml.cs
  2. 4
      StabilityMatrix/Helper/SettingsManager.cs

29
StabilityMatrix/App.xaml.cs

@ -139,6 +139,33 @@ namespace StabilityMatrix
return logConfig;
}
// Find library and initialize settings
private static SettingsManager CreateSettingsManager()
{
var settings = new SettingsManager();
var found = settings.TryFindLibrary();
// Not found, we need to show dialog to choose library location
if (!found)
{
// See if this is an existing user for message variation
var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
var settingsPath = Path.Combine(appDataPath, "StabilityMatrix", "settings.json");
var isExistingUser = File.Exists(settingsPath);
// TODO: Show dialog
// 1. For portable mode, call settings.SetPortableMode()
// 2. For custom path, call settings.SetLibraryPath(path)
// TryFindLibrary should succeed now unless weird issue
if (!settings.TryFindLibrary())
{
throw new Exception("Could not set library path.");
}
}
return settings;
}
private void App_OnStartup(object sender, StartupEventArgs e)
{
var serviceCollection = new ServiceCollection();
@ -177,7 +204,7 @@ namespace StabilityMatrix
serviceCollection.Configure<DebugOptions>(Config.GetSection(nameof(DebugOptions)));
var settingsManager = new SettingsManager();
var settingsManager = CreateSettingsManager();
serviceCollection.AddSingleton<ISettingsManager>(settingsManager);
serviceCollection.AddSingleton<BasePackage, A3WebUI>();

4
StabilityMatrix/Helper/SettingsManager.cs

@ -96,9 +96,9 @@ public class SettingsManager : ISettingsManager
/// <summary>
/// Enable and create settings files for portable mode
/// This creates the ./Data directory and the `.sm-portable` marker file
/// Creates the ./Data directory and the `.sm-portable` marker file
/// </summary>
public void SetupPortableMode()
public void SetPortableMode()
{
// Get app directory
var appDir = AppContext.BaseDirectory;

Loading…
Cancel
Save