Added scales

This commit is contained in:
2023-04-26 18:50:32 +02:00
parent 0ecba36f51
commit 0621716636
7 changed files with 366 additions and 2 deletions

View File

@ -1,4 +1,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using IniParser;
using IniParser.Model;
@ -9,9 +11,12 @@ namespace Elwig.Helpers {
private readonly string FileName;
public string DatabaseFile = App.DataPath + "database.sqlite3";
public string? DatabaseLog = null;
public IEnumerable<string[]> Scales;
private readonly LinkedList<string[]> ScaleList = new();
public Config(string filename) {
FileName = filename;
Scales = ScaleList;
Read();
}
@ -37,12 +42,27 @@ namespace Elwig.Helpers {
} else {
DatabaseLog = App.DataPath + log;
}
ScaleList.Clear();
Scales = ScaleList;
if (ini != null) {
foreach (var s in ini.Sections.Where(s => s.SectionName.StartsWith("scale."))) {
ScaleList.AddLast(new string[] {
s.SectionName[6..], s.Keys["type"], s.Keys["model"], s.Keys["connection"], s.Keys["empty"], s.Keys["filling"]
});
}
}
}
public void Write() {
using var file = new StreamWriter(FileName, false, Encoding.UTF8);
file.Write($"\r\n[database]\r\nfile = {DatabaseFile}\r\n");
if (DatabaseLog != null) file.Write($"log = {DatabaseLog}\r\n");
foreach (var s in ScaleList) {
file.Write($"\r\n[scale.{s[0]}]\r\ntype = {s[1]}\r\nmodel = {s[2]}\r\nconnection = {s[3]}\r\n");
if (s[4] != null) file.Write($"empty = {s[4]}\r\n");
if (s[5] != null) file.Write($"filling = {s[5]}\r\n");
}
}
}
}