0
0
mirror of https://github.com/sp-tarkov/launcher.git synced 2025-02-13 08:50:43 -05:00
launcher/project/SPT.Launcher.Base/Helpers/LauncherSettingsProvider.cs

162 lines
4.9 KiB
C#
Raw Normal View History

2023-03-03 19:25:33 +00:00
/* LauncherSettingsProvider.cs
* License: NCSA Open Source License
*
2024-05-21 20:15:19 +01:00
* Copyright: SPT
2023-03-03 19:25:33 +00:00
* AUTHORS:
* waffle.lord
*/
2024-05-21 20:15:19 +01:00
using SPT.Launcher.MiniCommon;
using SPT.Launcher.Models.Launcher;
2023-03-03 19:25:33 +00:00
using Newtonsoft.Json;
using System;
using System.ComponentModel;
using System.IO;
using SPT.Launcher.Utilities;
2024-05-21 20:15:19 +01:00
using SPT.Launcher.Controllers;
2023-03-03 19:25:33 +00:00
2024-05-21 20:15:19 +01:00
namespace SPT.Launcher.Helpers
2023-03-03 19:25:33 +00:00
{
public static class LauncherSettingsProvider
{
public static string DefaultSettingsFileLocation = Path.Join(Environment.CurrentDirectory, "user", "launcher", "config.json");
public static Settings Instance { get; } = Json.Load<Settings>(DefaultSettingsFileLocation) ?? new Settings();
}
public class Settings : NotifyPropertyChangedBase
2023-03-03 19:25:33 +00:00
{
public bool FirstRun { get; set; } = true;
public bool SaveSettings()
2023-03-03 19:25:33 +00:00
{
Server.Url = Path.TrimEndingDirectorySeparator(Server.Url);
return Json.SaveWithFormatting(LauncherSettingsProvider.DefaultSettingsFileLocation, this, Formatting.Indented);
2023-03-03 19:25:33 +00:00
}
2024-06-02 14:46:53 -04:00
public void ResetDefaults()
{
string defaultUrl = "http://127.0.0.1:6969";
string defaultPath = Environment.CurrentDirectory;
// don't reset if running in dev mode
if (IsDevMode)
{
LogManager.Instance.Info("Running in dev mode, not resetting");
return;
}
if (Server != null && Server.Url != defaultUrl)
{
LogManager.Instance.Info($"Server URL was '{Server.Url}'");
LogManager.Instance.Info($"Server URL was reset to default '{defaultUrl}'");
Server.Url = defaultUrl;
}
else
{
LogManager.Instance.Info($"Server URL is already set to default '{defaultUrl}'");
}
if (GamePath != defaultPath)
{
LogManager.Instance.Info($"Game path was '{GamePath}'");
LogManager.Instance.Info($"Game path was reset to default '{defaultPath}'");
GamePath = defaultPath;
}
else
{
LogManager.Instance.Info($"Game path is already set to default '{defaultPath}'");
}
SaveSettings();
}
2023-03-03 19:25:33 +00:00
public string DefaultLocale { get; set; } = "English";
private bool _isAddingServer;
2023-03-03 19:25:33 +00:00
[JsonIgnore]
public bool IsAddingServer
{
get => _isAddingServer;
set => SetProperty(ref _isAddingServer, value);
2023-03-03 19:25:33 +00:00
}
private bool _allowSettings;
2023-03-03 19:25:33 +00:00
[JsonIgnore]
public bool AllowSettings
{
get => _allowSettings;
set => SetProperty(ref _allowSettings, value);
2023-03-03 19:25:33 +00:00
}
private bool _gameRunning;
2023-03-03 19:25:33 +00:00
[JsonIgnore]
public bool GameRunning
{
get => _gameRunning;
set => SetProperty(ref _gameRunning, value);
2023-03-03 19:25:33 +00:00
}
private LauncherAction _launcherStartGameAction;
2023-03-03 19:25:33 +00:00
public LauncherAction LauncherStartGameAction
{
get => _launcherStartGameAction;
set => SetProperty(ref _launcherStartGameAction, value);
2023-03-03 19:25:33 +00:00
}
private bool _useAutoLogin;
2023-03-03 19:25:33 +00:00
public bool UseAutoLogin
{
get => _useAutoLogin;
set => SetProperty(ref _useAutoLogin, value);
2023-03-03 19:25:33 +00:00
}
private bool _isDevMode;
2024-06-02 14:46:53 -04:00
public bool IsDevMode
{
get => _isDevMode;
set => SetProperty(ref _isDevMode, value);
2024-06-02 14:46:53 -04:00
}
private string _gamePath;
2023-03-03 19:25:33 +00:00
public string GamePath
{
get => _gamePath;
set => SetProperty(ref _gamePath, value);
2023-03-03 19:25:33 +00:00
}
private string[] _excludeFromCleanup = [];
2023-03-03 19:25:33 +00:00
public string[] ExcludeFromCleanup
{
get => _excludeFromCleanup;
set => SetProperty(ref _excludeFromCleanup, value);
2023-03-03 19:25:33 +00:00
}
public ServerSetting Server { get; set; } = new ServerSetting();
public Settings()
{
if (!File.Exists(LauncherSettingsProvider.DefaultSettingsFileLocation))
{
2024-02-05 16:06:28 -05:00
LogManager.Instance.Warning("Launcher config not found");
LogManager.Instance.Info($"Creating launcher config: {LauncherSettingsProvider.DefaultSettingsFileLocation}");
2023-03-03 19:25:33 +00:00
LauncherStartGameAction = LauncherAction.MinimizeAction;
UseAutoLogin = true;
GamePath = Environment.CurrentDirectory;
2024-06-02 14:46:53 -04:00
IsDevMode = false;
2023-03-03 19:25:33 +00:00
Server = new ServerSetting
{
Name = "SPT",
Url = "http://127.0.0.1:6969"
};
2023-03-03 19:25:33 +00:00
SaveSettings();
}
2024-02-05 16:06:28 -05:00
LogManager.Instance.Info($"Using launcher config at: {LauncherSettingsProvider.DefaultSettingsFileLocation}");
2023-03-03 19:25:33 +00:00
}
}
}