ServerConfig class

This commit is contained in:
2024-01-06 21:37:21 +06:00
parent f52b49effd
commit bc868356e7
6 changed files with 81 additions and 31 deletions

View File

@@ -40,9 +40,8 @@ internal static partial class Launcher
#endif
if (args.Contains("offline")) offline = true;
if (args.Contains("updated")) updated = true;
Config = !File.Exists(LauncherConfig.ConfigFilePath)
? LauncherConfig.CreateDefault()
: LauncherConfig.LoadFromFile();
Config = LauncherConfig.LoadOrCreateDefault();
Logger.DebugLogEnabled = debug;
Logger.LogInfo("Main", "launcher is starting");

View File

@@ -28,7 +28,8 @@ public class LauncherConfig
Username = dtsod["username"];
}
public static LauncherConfig LoadFromFile() => new(new DtsodV23(File.ReadAllText(ConfigFilePath)));
private static LauncherConfig LoadFromFile() =>
new(new DtsodV23(File.ReadAllText(ConfigFilePath)));
public DtsodV23 ToDtsod() =>
new()
@@ -42,15 +43,18 @@ public class LauncherConfig
{ "username", Username },
};
public void Save()
{
public void Save() =>
File.WriteAllText(ConfigFilePath, ToDtsod().ToString());
}
public static LauncherConfig CreateDefault()
private static LauncherConfig CreateDefault()
{
var c = new LauncherConfig();
c.Save();
return c;
}
public static LauncherConfig LoadOrCreateDefault() =>
File.Exists(ConfigFilePath)
? LoadFromFile()
: CreateDefault();
}