diff --git a/Elwig/App.xaml.cs b/Elwig/App.xaml.cs index 73832a0..bc1e109 100644 --- a/Elwig/App.xaml.cs +++ b/Elwig/App.xaml.cs @@ -26,7 +26,7 @@ namespace Elwig { protected override void OnStartup(StartupEventArgs evt) { using (var ctx = new AppDbContext()) { if (!ctx.Database.CanConnect()) { - MessageBox.Show($"Invalid Database:\n\n{Config.DatabasePath}", "Invalid Database", MessageBoxButton.OK, MessageBoxImage.Error); + MessageBox.Show($"Invalid Database:\n\n{Config.DatabaseFile}", "Invalid Database", MessageBoxButton.OK, MessageBoxImage.Error); Shutdown(); } } diff --git a/Elwig/Helpers/AppDbContext.cs b/Elwig/Helpers/AppDbContext.cs index bf0fb46..1167bb7 100644 --- a/Elwig/Helpers/AppDbContext.cs +++ b/Elwig/Helpers/AppDbContext.cs @@ -23,7 +23,7 @@ namespace Elwig.Helpers { public DbSet WineVarieties { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseSqlite($"Data Source=\"{App.Config.DatabasePath}\"; Foreign Keys=True; Mode=ReadWrite; Cache=Default"); + optionsBuilder.UseSqlite($"Data Source=\"{App.Config.DatabaseFile}\"; Foreign Keys=True; Mode=ReadWrite; Cache=Default"); optionsBuilder.UseLazyLoadingProxies(); base.OnConfiguring(optionsBuilder); } diff --git a/Elwig/Helpers/Config.cs b/Elwig/Helpers/Config.cs index 6d67c95..8b93aed 100644 --- a/Elwig/Helpers/Config.cs +++ b/Elwig/Helpers/Config.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Text; using IniParser; using IniParser.Model; @@ -7,7 +8,7 @@ namespace Elwig.Helpers { public class Config { private readonly string FileName; - public string DatabasePath; + public string DatabaseFile; public Config(string filename) { FileName = filename; @@ -21,17 +22,18 @@ namespace Elwig.Helpers { ini = parser.ReadFile(FileName, Encoding.UTF8); } catch {} - if (ini == null || !ini.TryGetKey("database.path", out string db)) { - DatabasePath = App.DataPath + "database.sqlite3"; + if (ini == null || !ini.TryGetKey("database.file", out string db)) { + DatabaseFile = App.DataPath + "database.sqlite3"; } else if (db.Length > 1 && db[1] == ':') { - DatabasePath = db; + DatabaseFile = db; } else { - DatabasePath = App.DataPath + db; + DatabaseFile = App.DataPath + db; } } public void Write() { - throw new NotImplementedException(); + using var file = new StreamWriter(FileName, false, Encoding.UTF8); + file.Write($"\n[database]\nfile = {DatabaseFile}\n"); } } }