diff --git a/CRSim.Core/Services/DatabaseService.cs b/CRSim.Core/Services/DatabaseService.cs index 8d3ba9a..6fb142b 100644 --- a/CRSim.Core/Services/DatabaseService.cs +++ b/CRSim.Core/Services/DatabaseService.cs @@ -5,16 +5,17 @@ namespace CRSim.Core.Services { public class DatabaseService : IDatabaseService { - private readonly string _jsonFilePath; + private readonly string _jsonFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "CRSim"); private List _stations; private List _trainNumbers; private readonly JsonSerializerOptions options = new() { WriteIndented = true }; - public DatabaseService(string jsonFilePath) + public DatabaseService() { - ImportData(jsonFilePath); - _jsonFilePath = jsonFilePath; + if (!Directory.Exists(_jsonFilePath)) Directory.CreateDirectory(_jsonFilePath); + _jsonFilePath += "\\data.json"; + ImportData(_jsonFilePath); } public List GetAllStations() diff --git a/CRSim/App.xaml.cs b/CRSim/App.xaml.cs index ccb2628..1bfa9b4 100644 --- a/CRSim/App.xaml.cs +++ b/CRSim/App.xaml.cs @@ -12,7 +12,7 @@ services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); - services.AddSingleton(sp => new DatabaseService("data.json")); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton();