From 2b94e7ce1da972c0b2315dc198f9f316c00a074c Mon Sep 17 00:00:00 2001 From: EX3 Date: Tue, 10 Dec 2024 14:10:13 +0900 Subject: [PATCH] Fixed Recentfiles are not saved properly when rebooted --- Mirivoice/Mirivoice.Core/Managers/MainManager.cs | 15 +++++++++++++++ Mirivoice/ViewModels/MainViewModel.cs | 16 ++-------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Mirivoice/Mirivoice.Core/Managers/MainManager.cs b/Mirivoice/Mirivoice.Core/Managers/MainManager.cs index cf06b4b..ed31941 100644 --- a/Mirivoice/Mirivoice.Core/Managers/MainManager.cs +++ b/Mirivoice/Mirivoice.Core/Managers/MainManager.cs @@ -50,6 +50,7 @@ public void Initialize() UpdateDefaultVoicers(); LoadVoicerManager(); LoadSetting(); + LoadRecentFiles(); InitializationTask = Task.Run(() => { Log.Information("MainManager Initialize Start"); @@ -74,6 +75,20 @@ public void LoadSetting() MainManager.Instance.Setting.Save(); } } + + public void LoadRecentFiles() + { + if (File.Exists(MainManager.Instance.PathM.RecentFilesPath)) + { + var yamlUtf8Bytes = System.Text.Encoding.UTF8.GetBytes(ReadTxtFile(MainManager.Instance.PathM.RecentFilesPath)); + MainManager.Instance.Recent = YamlSerializer.Deserialize(yamlUtf8Bytes); + } + else + { + MainManager.Instance.Recent.Save(); + } + } + private static void DeleteExtractedZip(string zipFilePath) { // deletes zip file and split files diff --git a/Mirivoice/ViewModels/MainViewModel.cs b/Mirivoice/ViewModels/MainViewModel.cs index d696e7b..4e8c150 100644 --- a/Mirivoice/ViewModels/MainViewModel.cs +++ b/Mirivoice/ViewModels/MainViewModel.cs @@ -913,21 +913,9 @@ public void EndProgress() public void LoadRecentFIles() { - if (!File.Exists(MainManager.Instance.PathM.RecentFilesPath)) - { - RecentFiles = new RecentFiles(); - RecentFiles.Save(); - RecentFiles.Validate(); - OnPropertyChanged(nameof(RecentMenuCollection)); - } - else - { - var yamlUtf8Bytes = System.Text.Encoding.UTF8.GetBytes(MainManager.Instance.ReadTxtFile(MainManager.Instance.PathM.RecentFilesPath)); - RecentFiles = YamlSerializer.Deserialize(yamlUtf8Bytes); - RecentFiles.Validate(); - OnPropertyChanged(nameof(RecentMenuCollection)); - } + RecentFiles = MainManager.Instance.Recent; + OnPropertyChanged(nameof(RecentMenuCollection)); RecentFiles.UpdateUI(this); // update UI }