From 579c05d9e83d350d9ce220d75d8caf751b102e59 Mon Sep 17 00:00:00 2001 From: denglihong2007 <2639367181@qq.com> Date: Sat, 8 Mar 2025 01:17:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E4=BF=9D=E7=95=99?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CRSim.Core/Services/DatabaseService.cs | 9 +++++---- CRSim/App.xaml.cs | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) 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();