[#8] Add auto update checker

This commit is contained in:
2024-03-04 21:19:08 +01:00
parent ac4026571e
commit 7e1843a1b3
11 changed files with 231 additions and 4 deletions

View File

@ -31,14 +31,19 @@ namespace Elwig.Helpers {
public class Config {
private static readonly string[] TrueValues = ["1", "true", "yes", "on"];
private readonly string FileName;
public bool Debug;
public string DatabaseFile = App.DataPath + "database.sqlite3";
public string? DatabaseLog = null;
public string? Branch = null;
public string? UpdateUrl = null;
public bool UpdateAuto = false;
public IList<ScaleConfig> Scales;
private readonly List<ScaleConfig> ScaleList = [];
private static readonly string[] trueValues = ["1", "true", "yes", "on"];
public Config(string filename) {
FileName = filename;
@ -53,7 +58,9 @@ namespace Elwig.Helpers {
var log = config["database:log"];
DatabaseLog = log != null ? Path.Combine(App.DataPath, log) : null;
Branch = config["general:branch"];
Debug = trueValues.Contains(config["general:debug"]?.ToLower());
Debug = TrueValues.Contains(config["general:debug"]?.ToLower());
UpdateUrl = config["update:url"];
UpdateAuto = TrueValues.Contains(config["update:auto"]?.ToLower());
var scales = config.AsEnumerable().Where(i => i.Key.StartsWith("scale.")).GroupBy(i => i.Key.Split(':')[0][6..]).Select(i => i.Key);
ScaleList.Clear();
@ -73,6 +80,10 @@ namespace Elwig.Helpers {
if (Debug) file.Write("debug = true\r\n");
file.Write($"\r\n[database]\r\nfile = {DatabaseFile}\r\n");
if (DatabaseLog != null) file.Write($"log = {DatabaseLog}\r\n");
file.Write($"\r\n[update]\r\n");
if (UpdateUrl != null) file.Write($"url = {UpdateUrl}\r\n");
if (UpdateAuto) file.Write($"auto = true\r\n");
foreach (var s in ScaleList) {
file.Write($"\r\n[scale.{s.Id}]\r\ntype = {s.Type}\r\nmodel = {s.Model}\r\nconnection = {s.Connection}\r\n");
if (s.Empty != null) file.Write($"empty = {s.Empty}\r\n");