add config file

This commit is contained in:
bird_egop
2026-06-07 00:41:16 +03:00
parent 4e45bd236c
commit 8bed73fb5a
10 changed files with 169 additions and 35 deletions
+53
View File
@@ -0,0 +1,53 @@
using System.Text.Json;
using NResUI.Abstractions;
using NResUI.ImGuiUI;
namespace NResUI;
public class LoadConfigOnLaunch : ILaunchReceiver
{
private readonly ILater _later;
private readonly MessageBoxModalPanel _messageBoxModalPanel;
private readonly IConfigProvider _configProvider;
public LoadConfigOnLaunch(ILater later, MessageBoxModalPanel messageBoxModalPanel, IConfigProvider configProvider)
{
_later = later;
_messageBoxModalPanel = messageBoxModalPanel;
_configProvider = configProvider;
}
public void OnLaunch()
{
if (!File.Exists("config.json"))
{
_later.Execute(() =>
{
_messageBoxModalPanel.Show(
"config.json is not present\nViewport may be broken without game files\nPlaceholder file has been created");
});
var config = new ConfigJson() { GameBasePath = "" };
File.WriteAllText("config.json", JsonSerializer.Serialize(config));
_configProvider.Set(config);
}
else
{
var content = File.ReadAllText("config.json");
var config = JsonSerializer.Deserialize<ConfigJson>(content);
if (config is null)
{
_later.Execute(() =>
{
_messageBoxModalPanel.Show("config.json was corrupted\nReplacement has been created");
});
config = new ConfigJson() { GameBasePath = "" };
File.WriteAllText("config.json", JsonSerializer.Serialize(config));
_configProvider.Set(config);
}
else
{
_configProvider.Set(config);
}
}
}
}