mirror of
https://github.com/CyberL1/Minecraft-Realms-Emulator.git
synced 2024-11-09 07:58:23 -05:00
feat: automatic configuration checking
This commit is contained in:
parent
62864d58e1
commit
25c98d1687
@ -33,7 +33,7 @@ namespace Minecraft_Realms_Emulator.Helpers
|
|||||||
|
|
||||||
public Configuration? GetSetting(string key)
|
public Configuration? GetSetting(string key)
|
||||||
{
|
{
|
||||||
var setting = Db.Configuration.Find(key);
|
var setting = Db.Configuration.Find(FirstCharToLowerCase(key));
|
||||||
|
|
||||||
if (setting == null) return null;
|
if (setting == null) return null;
|
||||||
|
|
||||||
@ -43,5 +43,13 @@ namespace Minecraft_Realms_Emulator.Helpers
|
|||||||
Value = JsonConvert.DeserializeObject(setting.Value)
|
Value = JsonConvert.DeserializeObject(setting.Value)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string FirstCharToLowerCase(string str)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(str) && char.IsUpper(str[0]))
|
||||||
|
return str.Length == 1 ? char.ToLower(str[0]).ToString() : char.ToLower(str[0]) + str[1..];
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
namespace Minecraft_Realms_Emulator.Helpers.Config
|
namespace Minecraft_Realms_Emulator.Helpers.Config
|
||||||
{
|
{
|
||||||
public class Settings : Dictionary<string, string>
|
public class Settings
|
||||||
{
|
{
|
||||||
public string DefaultServerAddress { get; set; } = "127.0.0.1";
|
public string DefaultServerAddress { get; set; } = "127.0.0.1";
|
||||||
public string NewsLink { get; set; } = "https://github.com/CyberL1/Minecraft-Realms-Emulator";
|
public string NewsLink { get; set; } = "https://github.com/CyberL1/Minecraft-Realms-Emulator";
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Minecraft_Realms_Emulator.Data;
|
using Minecraft_Realms_Emulator.Data;
|
||||||
using Minecraft_Realms_Emulator.Entities;
|
using Minecraft_Realms_Emulator.Entities;
|
||||||
using Minecraft_Realms_Emulator.Enums;
|
|
||||||
using Minecraft_Realms_Emulator.Helpers.Config;
|
using Minecraft_Realms_Emulator.Helpers.Config;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
@ -19,31 +18,19 @@ namespace Minecraft_Realms_Emulator.Helpers
|
|||||||
var config = new ConfigHelper(db);
|
var config = new ConfigHelper(db);
|
||||||
var settings = new Settings();
|
var settings = new Settings();
|
||||||
|
|
||||||
if (config.GetSetting(nameof(SettingsEnum.newsLink)) == null)
|
foreach (var property in settings.GetType().GetProperties())
|
||||||
{
|
{
|
||||||
db.Configuration.Add(new Configuration
|
var name = property.Name;
|
||||||
{
|
var value = property.GetValue(settings);
|
||||||
Key = nameof(SettingsEnum.newsLink),
|
|
||||||
Value = JsonConvert.SerializeObject(settings.NewsLink)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.GetSetting(nameof(SettingsEnum.defaultServerAddress)) == null)
|
|
||||||
{
|
|
||||||
db.Configuration.Add(new Configuration
|
|
||||||
{
|
|
||||||
Key = nameof(SettingsEnum.defaultServerAddress),
|
|
||||||
Value = JsonConvert.SerializeObject(settings.DefaultServerAddress)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.GetSetting(nameof(SettingsEnum.trialMode)) == null)
|
if (config.GetSetting(name) == null)
|
||||||
{
|
|
||||||
db.Configuration.Add(new Configuration
|
|
||||||
{
|
{
|
||||||
Key = nameof(SettingsEnum.trialMode),
|
db.Configuration.Add(new Configuration
|
||||||
Value = JsonConvert.SerializeObject(settings.TrialMode)
|
{
|
||||||
});
|
Key = name,
|
||||||
|
Value = JsonConvert.SerializeObject(value)
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
db.SaveChanges();
|
db.SaveChanges();
|
||||||
|
Loading…
Reference in New Issue
Block a user