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) { |         protected override void OnStartup(StartupEventArgs evt) { | ||||||
|             using (var ctx = new AppDbContext()) { |             using (var ctx = new AppDbContext()) { | ||||||
|                 if (!ctx.Database.CanConnect()) { |                 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(); |                     Shutdown(); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|   | |||||||
| @@ -23,7 +23,7 @@ namespace Elwig.Helpers { | |||||||
|         public DbSet<WineVar> WineVarieties { get; set; } |         public DbSet<WineVar> WineVarieties { get; set; } | ||||||
|  |  | ||||||
|         protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { |         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(); |             optionsBuilder.UseLazyLoadingProxies(); | ||||||
|             base.OnConfiguring(optionsBuilder); |             base.OnConfiguring(optionsBuilder); | ||||||
|         } |         } | ||||||
|   | |||||||
| @@ -1,4 +1,5 @@ | |||||||
| using System; | using System; | ||||||
|  | using System.IO; | ||||||
| using System.Text; | using System.Text; | ||||||
| using IniParser; | using IniParser; | ||||||
| using IniParser.Model; | using IniParser.Model; | ||||||
| @@ -7,7 +8,7 @@ namespace Elwig.Helpers { | |||||||
|     public class Config { |     public class Config { | ||||||
|  |  | ||||||
|         private readonly string FileName; |         private readonly string FileName; | ||||||
|         public string DatabasePath; |         public string DatabaseFile; | ||||||
|  |  | ||||||
|         public Config(string filename) { |         public Config(string filename) { | ||||||
|             FileName = filename; |             FileName = filename; | ||||||
| @@ -21,17 +22,18 @@ namespace Elwig.Helpers { | |||||||
|                 ini = parser.ReadFile(FileName, Encoding.UTF8); |                 ini = parser.ReadFile(FileName, Encoding.UTF8); | ||||||
|             } catch {} |             } catch {} | ||||||
|  |  | ||||||
|             if (ini == null || !ini.TryGetKey("database.path", out string db)) { |             if (ini == null || !ini.TryGetKey("database.file", out string db)) { | ||||||
|                 DatabasePath = App.DataPath + "database.sqlite3"; |                 DatabaseFile = App.DataPath + "database.sqlite3"; | ||||||
|             } else if (db.Length > 1 && db[1] == ':') { |             } else if (db.Length > 1 && db[1] == ':') { | ||||||
|                 DatabasePath = db; |                 DatabaseFile = db; | ||||||
|             } else { |             } else { | ||||||
|                 DatabasePath = App.DataPath + db; |                 DatabaseFile = App.DataPath + db; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         public void Write() { |         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