using System.IO;
using StarterNG.Application.Abstractions;
namespace StarterNG.Infrastructure.Settings;
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;
}
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);
}
public string InstallationConfigPath() => _paths.FromRoot(ConfigFileName);
///
/// Where the starter keeps its own copy of the vehicle database. Per user
/// rather than under the installation: that one can be read-only, is a working
/// copy someone updates from under us, and the copy is ours, not the game's.
///
public string VehicleCacheDirectory() => Path.Combine(UserConfigDirectory(), "vehicles");
/// The sceneries starred in the list.
public string FavoritesPath() => Path.Combine(UserConfigDirectory(), "favorites.txt");
/// Which cleanup of the .sbt files each installation had.
public string SbtCleanupPath() => Path.Combine(UserConfigDirectory(), "sbt-cleanup.txt");
public string UserConfigDirectory() =>
Path.GetDirectoryName(UserConfigPath()) ?? _environment.BaseDirectory;
}