mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-23 00:24:41 +01:00
Split Settings into model, serializer, paths and store
698 lines did all of it at once. The mutable CaptureFromUi callback becomes an ISettingsCapture the settings view implements.
This commit is contained in:
54
StarterNG/Infrastructure/Settings/SettingsPaths.cs
Normal file
54
StarterNG/Infrastructure/Settings/SettingsPaths.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System.IO;
|
||||
using StarterNG.Application.Abstractions;
|
||||
|
||||
namespace StarterNG.Infrastructure.Settings;
|
||||
|
||||
/// <summary>
|
||||
/// Where the simulator's eu07.ini lives: per user on each platform, with the
|
||||
/// installation's own copy as the template for a first run.
|
||||
/// </summary>
|
||||
public sealed class SettingsPaths
|
||||
{
|
||||
private const string ConfigFileName = "eu07.ini";
|
||||
private const string VendorFolder = "MaSzyna";
|
||||
|
||||
private readonly IEnvironment _environment;
|
||||
private readonly IGamePaths _paths;
|
||||
|
||||
public SettingsPaths(IEnvironment environment, IGamePaths paths)
|
||||
{
|
||||
_environment = environment;
|
||||
_paths = paths;
|
||||
}
|
||||
|
||||
/// <summary>The user's own settings file, which is what the starter writes.</summary>
|
||||
public string UserConfigPath()
|
||||
{
|
||||
if (_environment.IsWindows)
|
||||
{
|
||||
string? appData = _environment.GetVariable("APPDATA");
|
||||
if (!string.IsNullOrEmpty(appData))
|
||||
return Path.Combine(appData, VendorFolder, ConfigFileName);
|
||||
}
|
||||
else if (_environment.IsMacOS)
|
||||
{
|
||||
string? home = _environment.GetVariable("HOME");
|
||||
if (!string.IsNullOrEmpty(home))
|
||||
return Path.Combine(home, "Library", "Application Support", VendorFolder, ConfigFileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
string? home = _environment.GetVariable("HOME");
|
||||
if (!string.IsNullOrEmpty(home))
|
||||
return Path.Combine(home, ".config", VendorFolder, ConfigFileName);
|
||||
}
|
||||
|
||||
return Path.Combine(_environment.BaseDirectory, ConfigFileName);
|
||||
}
|
||||
|
||||
/// <summary>The ini shipped with the installation, read when the user has none.</summary>
|
||||
public string InstallationConfigPath() => _paths.FromRoot(ConfigFileName);
|
||||
|
||||
public string UserConfigDirectory() =>
|
||||
Path.GetDirectoryName(UserConfigPath()) ?? _environment.BaseDirectory;
|
||||
}
|
||||
Reference in New Issue
Block a user