From baa6638d032e1f16e87e5daf58496bb571c54847 Mon Sep 17 00:00:00 2001
From: status102 <102887808+status102@users.noreply.github.com>
Date: Mon, 10 Feb 2025 16:20:52 +0800
Subject: [PATCH] =?UTF-8?q?rft:=20Wpf=E5=85=AC=E5=91=8A=E5=AD=98=E5=82=A8?=
=?UTF-8?q?=E6=8B=86=E5=88=86=20(#11825)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* rft: Wpf公告存储拆分
* rft: 拆分中英公告
---
.../Configuration/AnnouncementInfo.cs | 5 --
.../ViewModels/UI/AnnouncementViewModel.cs | 56 ++++++++++++++++++-
2 files changed, 54 insertions(+), 7 deletions(-)
diff --git a/src/MaaWpfGui/Configuration/AnnouncementInfo.cs b/src/MaaWpfGui/Configuration/AnnouncementInfo.cs
index 7ea81937db..2dbefd268e 100644
--- a/src/MaaWpfGui/Configuration/AnnouncementInfo.cs
+++ b/src/MaaWpfGui/Configuration/AnnouncementInfo.cs
@@ -19,11 +19,6 @@ namespace MaaWpfGui.Configuration
{
public event PropertyChangedEventHandler PropertyChanged;
- ///
- /// Gets or sets 公告内容
- ///
- public string Info { get; set; } = string.Empty;
-
///
/// Gets or sets a value indicating whether 下次不再显示公告
///
diff --git a/src/MaaWpfGui/ViewModels/UI/AnnouncementViewModel.cs b/src/MaaWpfGui/ViewModels/UI/AnnouncementViewModel.cs
index ca913c3280..83f02f051b 100644
--- a/src/MaaWpfGui/ViewModels/UI/AnnouncementViewModel.cs
+++ b/src/MaaWpfGui/ViewModels/UI/AnnouncementViewModel.cs
@@ -13,6 +13,7 @@
using System;
using System.Collections.ObjectModel;
+using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
@@ -21,6 +22,7 @@ using HandyControl.Tools.Command;
using MaaWpfGui.Configuration;
using MaaWpfGui.Constants;
using MaaWpfGui.Helper;
+using Serilog;
using Stylet;
namespace MaaWpfGui.ViewModels.UI
@@ -32,6 +34,10 @@ namespace MaaWpfGui.ViewModels.UI
// ReSharper disable once ClassNeverInstantiated.Global
public class AnnouncementViewModel : Screen
{
+ private static readonly ILogger _logger = Log.ForContext();
+
+ private static readonly object _lock = new();
+
public string ImageSource { get; set; }
public class AnnouncementSection
@@ -131,7 +137,53 @@ namespace MaaWpfGui.ViewModels.UI
set => SetAndNotify(ref _selectedAnnouncementSection, value);
}
- private string _announcementInfo = ConfigFactory.Root.AnnouncementInfo.Info;
+ private static readonly string _announcementInFile = SettingsViewModel.GuiSettings.Language switch
+ {
+ "zh-cn" or "zh-tw" => Path.Combine(Environment.CurrentDirectory, "cache", "announcement.md"),
+ _ => Path.Combine(Environment.CurrentDirectory, "cache", "announcement_en.md"),
+ };
+
+ private static string AnnouncementInFile
+ {
+ get
+ {
+ if (!File.Exists(_announcementInFile))
+ {
+ return null;
+ }
+
+ try
+ {
+ lock (_lock)
+ {
+ return File.ReadAllText(_announcementInFile);
+ }
+ }
+ catch (Exception e)
+ {
+ _logger.Error(e, "Failed to read announcement from file");
+ }
+
+ return null;
+ }
+
+ set
+ {
+ try
+ {
+ lock (_lock)
+ {
+ File.WriteAllText(_announcementInFile, value);
+ }
+ }
+ catch (Exception e)
+ {
+ _logger.Error(e, "Failed to write announcement to file");
+ }
+ }
+ }
+
+ private string _announcementInfo = AnnouncementInFile ?? string.Empty;
///
/// Gets the announcement info.
@@ -143,7 +195,7 @@ namespace MaaWpfGui.ViewModels.UI
private set
{
SetAndNotify(ref _announcementInfo, value);
- ConfigFactory.Root.AnnouncementInfo.Info = value;
+ AnnouncementInFile = value;
AnnouncementSections = new(ParseAnnouncementInfo(AnnouncementInfo));
}
}