mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2026-08-15 15:07:48 +04:00
54 lines
1.7 KiB
C#
54 lines
1.7 KiB
C#
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);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|