Implement Write() in Config and rename DatabasePath to DatabaseFile
This commit is contained in:
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ namespace Elwig.Helpers {
|
||||
public DbSet<WineVar> 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);
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user