Add config file

This commit is contained in:
2023-04-15 21:11:27 +02:00
parent ca30f12f5a
commit 7c7b3ed561
8 changed files with 59 additions and 14 deletions

37
Elwig/Helpers/Config.cs Normal file
View File

@ -0,0 +1,37 @@
using System;
using System.Text;
using IniParser;
using IniParser.Model;
namespace Elwig.Helpers {
public class Config {
private readonly string FileName;
public string DatabasePath;
public Config(string filename) {
FileName = filename;
Read();
}
public void Read() {
var parser = new FileIniDataParser();
IniData? ini = null;
try {
ini = parser.ReadFile(FileName, Encoding.UTF8);
} catch {}
if (ini == null || !ini.TryGetKey("database.path", out string db)) {
DatabasePath = App.DataPath + "database.sqlite3";
} else if (db.Length > 1 && db[1] == ':') {
DatabasePath = db;
} else {
DatabasePath = App.DataPath + db;
}
}
public void Write() {
throw new NotImplementedException();
}
}
}