59 lines
1.3 KiB
C#
59 lines
1.3 KiB
C#
global using System.Text.Json;
|
|
global using System.Text.Json.Serialization;
|
|
|
|
// Prevent from ending if CTL+C is pressed.
|
|
Console.TreatControlCAsInput = true;
|
|
Console.WriteLine($"AyaNova server launcher {AyaNovaVersion.VersionString}");
|
|
|
|
AyConfig cfg = null;
|
|
|
|
var ConfigFileName = @"config.json";
|
|
var json = string.Empty;
|
|
bool FirstTime=false;
|
|
//Read configuration or create if not exist
|
|
if (File.Exists(ConfigFileName))
|
|
{
|
|
json = File.ReadAllText(ConfigFileName);
|
|
cfg = JsonSerializer.Deserialize<AyConfig>(json);
|
|
}
|
|
else
|
|
{
|
|
cfg = new AyConfig();
|
|
FirstTime=true;
|
|
}
|
|
|
|
if(FirstTime){
|
|
Console.WriteLine("Configuration file not found; using default values");
|
|
}
|
|
Console.WriteLine("Current configuration:");
|
|
|
|
//iterate / prompt for each value
|
|
|
|
|
|
//write configuration
|
|
cfg = new AyConfig();
|
|
json = JsonSerializer.Serialize(cfg);
|
|
File.WriteAllText(ConfigFileName, json);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("Press CTL-C keys to shut down AyaNova Server");
|
|
bool Quit = false;
|
|
ConsoleKeyInfo cki;
|
|
do
|
|
{
|
|
cki = Console.ReadKey(false);
|
|
|
|
if (cki.Key == ConsoleKey.C && (cki.Modifiers & ConsoleModifiers.Control) != 0)
|
|
{
|
|
Quit = true;
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("Press CTL-C keys to shut down AyaNova Server");
|
|
}
|
|
//Console.WriteLine(cki.Key.ToString());
|
|
} while (!Quit); |