Browse Source

Add AppDataHome and LibraryDir overrides from args

pull/324/head
Ionite 1 year ago
parent
commit
ac8c7a0e9f
No known key found for this signature in database
  1. 2
      StabilityMatrix.Avalonia/App.axaml.cs
  2. 8
      StabilityMatrix.Avalonia/Models/AppArgs.cs
  3. 5
      StabilityMatrix.Avalonia/Program.cs
  4. 14
      StabilityMatrix.Core/Helper/Compat.cs
  5. 1
      StabilityMatrix.Core/Services/ISettingsManager.cs
  6. 17
      StabilityMatrix.Core/Services/SettingsManager.cs

2
StabilityMatrix.Avalonia/App.axaml.cs

@ -258,6 +258,8 @@ public sealed class App : Application
var settingsManager = Services.GetRequiredService<ISettingsManager>();
settingsManager.LibraryDirOverride = Program.Args.DataDirectoryOverride;
if (settingsManager.TryFindLibrary())
{
Cultures.SetSupportedCultureOrDefault(settingsManager.Settings.Language);

8
StabilityMatrix.Avalonia/Models/AppArgs.cs

@ -58,18 +58,18 @@ public class AppArgs
public bool DisableGpuRendering { get; set; }
/// <summary>
/// Override global app data directory
/// Override global app home directory
/// Defaults to (%APPDATA%|~/.config)/StabilityMatrix
/// </summary>
[Option("global-dir", HelpText = "Override global app data directory")]
public string? GlobalDirectory { get; set; }
[Option("home-dir", HelpText = "Override global app home directory")]
public string? HomeDirectoryOverride { get; set; }
/// <summary>
/// Override data directory
/// This takes precedence over relative portable directory and global directory
/// </summary>
[Option("data-dir", HelpText = "Override data directory")]
public string? DataDirectory { get; set; }
public string? DataDirectoryOverride { get; set; }
/// <summary>
/// Custom Uri protocol handler

5
StabilityMatrix.Avalonia/Program.cs

@ -65,6 +65,11 @@ public static class Program
Args = parseResult.Value;
if (Args.HomeDirectoryOverride is { } homeDir)
{
Compat.SetAppDataHome(homeDir);
}
// Launched for custom URI scheme, handle and exit
if (Args.Uri is { } uriArg)
{

14
StabilityMatrix.Core/Helper/Compat.cs

@ -51,7 +51,7 @@ public static class Compat
/// <summary>
/// Set AppDataHome to a custom path. Used for testing.
/// </summary>
internal static void SetAppDataHome(string path)
public static void SetAppDataHome(string path)
{
AppDataHome = path;
}
@ -136,17 +136,7 @@ public static class Compat
AppData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
if (
Environment.GetEnvironmentVariable("STABILITY_MATRIX_APPDATAHOME") is
{ } appDataOverride
)
{
AppDataHome = appDataOverride;
}
else
{
AppDataHome = AppData + AppName;
}
AppDataHome = AppData + AppName;
}
/// <summary>

1
StabilityMatrix.Core/Services/ISettingsManager.cs

@ -9,6 +9,7 @@ namespace StabilityMatrix.Core.Services;
public interface ISettingsManager
{
bool IsPortableMode { get; }
string? LibraryDirOverride { set; }
string LibraryDir { get; }
bool IsLibraryDirSet { get; }
string DatabasePath { get; }

17
StabilityMatrix.Core/Services/SettingsManager.cs

@ -22,10 +22,9 @@ public class SettingsManager : ISettingsManager
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private static readonly ReaderWriterLockSlim FileLock = new();
private static readonly string GlobalSettingsPath = Path.Combine(
Compat.AppDataHome,
"global.json"
);
private static string GlobalSettingsPath => Path.Combine(Compat.AppDataHome, "global.json");
public string? LibraryDirOverride { private get; set; }
private readonly string? originalEnvPath = Environment.GetEnvironmentVariable(
"PATH",
@ -274,6 +273,16 @@ public class SettingsManager : ISettingsManager
if (IsLibraryDirSet && !forceReload)
return true;
// 0. Check Override
if (!string.IsNullOrEmpty(LibraryDirOverride))
{
Logger.Info("Using library override path: {Path}", LibraryDirOverride);
LibraryDir = LibraryDirOverride;
SetStaticLibraryPaths();
LoadSettings();
return true;
}
// 1. Check portable mode
var appDir = Compat.AppCurrentDir;
IsPortableMode = File.Exists(Path.Combine(appDir, "Data", ".sm-portable"));

Loading…
Cancel
Save