From 038f65ccc6ddfcca6b203eb3abd9a97c578cbc0b Mon Sep 17 00:00:00 2001 From: Shuming Liu Date: Sun, 29 Mar 2026 11:46:01 +0800 Subject: [PATCH] fixed a bug --- client/Reader/MainForm.cs | 13 ++++++++----- client/Reader/Reader.csproj | 5 +++++ client/Writer/MainForm.cs | 13 ++++++++----- client/Writer/Writer.csproj | 5 +++++ 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/client/Reader/MainForm.cs b/client/Reader/MainForm.cs index 08acd02..77dc99e 100644 --- a/client/Reader/MainForm.cs +++ b/client/Reader/MainForm.cs @@ -13,11 +13,14 @@ namespace Reader public partial class MainForm : Form { private static readonly HttpClient http = new HttpClient(); - private static readonly string ServerUrl = System.IO.File.ReadAllText("appsettings.json") - .Replace("\"", "") - .Split(':')[1] - .Replace("/", "") - .Trim(); + private static readonly string ServerUrl; + + static MainForm() + { + var configPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "appsettings.json"); + var jsonContent = System.IO.File.ReadAllText(configPath); + ServerUrl = jsonContent.Replace("\"", "").Split(':')[1].Replace("/", "").Trim(); + } public MainForm() { diff --git a/client/Reader/Reader.csproj b/client/Reader/Reader.csproj index ea96263..c48b8d3 100644 --- a/client/Reader/Reader.csproj +++ b/client/Reader/Reader.csproj @@ -6,4 +6,9 @@ enable enable + + + PreserveNewest + + diff --git a/client/Writer/MainForm.cs b/client/Writer/MainForm.cs index d96adb8..09e703c 100644 --- a/client/Writer/MainForm.cs +++ b/client/Writer/MainForm.cs @@ -12,11 +12,14 @@ namespace Writer public partial class MainForm : Form { private static readonly HttpClient http = new HttpClient(); - private static readonly string ServerUrl = System.IO.File.ReadAllText("appsettings.json") - .Replace("\"", "") - .Split(':')[1] - .Replace("/", "") - .Trim(); + private static readonly string ServerUrl; + + static MainForm() + { + var configPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "appsettings.json"); + var jsonContent = System.IO.File.ReadAllText(configPath); + ServerUrl = jsonContent.Replace("\"", "").Split(':')[1].Replace("/", "").Trim(); + } public MainForm() { diff --git a/client/Writer/Writer.csproj b/client/Writer/Writer.csproj index ea96263..c48b8d3 100644 --- a/client/Writer/Writer.csproj +++ b/client/Writer/Writer.csproj @@ -6,4 +6,9 @@ enable enable + + + PreserveNewest + +