mirror of
https://github.com/EpinelPS/EpinelPS.git
synced 2025-12-12 23:14:34 +01:00
significant improvements to server selector
This commit is contained in:
51
ServerSelector/GameSettings.cs
Normal file
51
ServerSelector/GameSettings.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace ServerSelector
|
||||
{
|
||||
public class GameSettings
|
||||
{
|
||||
private static GameSettings? _settings;
|
||||
public string GameRoot { get; set; } = "C:\\Nikke";
|
||||
public string LastIp { get; set; } = "127.0.0.1";
|
||||
public int LastOffset { get; set; }
|
||||
|
||||
public static GameSettings Settings
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_settings != null)
|
||||
return _settings;
|
||||
|
||||
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "serverselectorsettings.json");
|
||||
|
||||
try
|
||||
{
|
||||
if (File.Exists(path))
|
||||
{
|
||||
string json = File.ReadAllText(path);
|
||||
_settings = JsonSerializer.Deserialize<GameSettings>(json);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if (_settings == null)
|
||||
{
|
||||
_settings = new();
|
||||
}
|
||||
|
||||
return _settings;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Save()
|
||||
{
|
||||
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "serverselectorsettings.json");
|
||||
File.WriteAllText(path, JsonSerializer.Serialize(_settings));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user