2025-02-09 16:38:49 +03:00
|
|
|
using Tommy;
|
|
|
|
|
|
|
|
namespace RestySqlite
|
|
|
|
{
|
|
|
|
public class Utils
|
|
|
|
{
|
2025-02-09 16:47:08 +03:00
|
|
|
public static dynamic? ReadConfig(string key, string? category = null)
|
2025-02-09 16:38:49 +03:00
|
|
|
{
|
2025-02-09 16:47:08 +03:00
|
|
|
if (!File.Exists("conf.toml"))
|
|
|
|
{
|
|
|
|
TomlTable toml = new TomlTable
|
|
|
|
{
|
|
|
|
["title"] = "Configuration file for API",
|
|
|
|
|
|
|
|
["api"] =
|
|
|
|
{
|
|
|
|
["port"] = 5417,
|
|
|
|
["handle"] = "api",
|
|
|
|
},
|
|
|
|
["sql"] =
|
|
|
|
{
|
|
|
|
["database"] = ""
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
using(StreamWriter writer = File.CreateText("conf.toml"))
|
|
|
|
{
|
|
|
|
toml.WriteTo(writer);
|
|
|
|
// Remember to flush the data if needed!
|
|
|
|
writer.Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
Console.WriteLine("Config created please check it.");
|
|
|
|
return null;
|
|
|
|
}
|
2025-02-09 16:38:49 +03:00
|
|
|
using(StreamReader reader = File.OpenText("conf.toml"))
|
|
|
|
{
|
|
|
|
TomlTable table = TOML.Parse(reader);
|
|
|
|
|
|
|
|
if (category != null)
|
|
|
|
{
|
|
|
|
return table[category][key];
|
|
|
|
}
|
|
|
|
return table[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|