From ae590bb2598657e6bb8ad25eab28e467fd504713 Mon Sep 17 00:00:00 2001 From: MikiraSora Date: Wed, 23 Oct 2024 05:48:36 +0800 Subject: [PATCH] add I18N --- OngekiFumenEditor/App.config | 2 +- .../ProgramUpdater/DefaultProgramUpdater.cs | 45 +++-- .../Views/ShowNewVersionDialogView.xaml | 20 +- .../Kernel/ProgramUpdater/IProgramUpdater.cs | 2 - .../Kernel/Scheduler/SchedulerManager.cs | 181 +++++++++--------- .../Program/Views/ProgramSettingView.xaml | 10 +- .../Properties/ProgramSetting.Designer.cs | 6 +- .../Properties/ProgramSetting.settings | 2 +- .../Properties/Resources.Designer.cs | 126 ++++++++++++ OngekiFumenEditor/Properties/Resources.resx | 42 ++++ .../Properties/Resources.zh-Hans.resx | 42 ++++ 11 files changed, 355 insertions(+), 123 deletions(-) diff --git a/OngekiFumenEditor/App.config b/OngekiFumenEditor/App.config index fb7c5289..54c99aff 100644 --- a/OngekiFumenEditor/App.config +++ b/OngekiFumenEditor/App.config @@ -91,7 +91,7 @@ - + True diff --git a/OngekiFumenEditor/Kernel/ProgramUpdater/DefaultProgramUpdater.cs b/OngekiFumenEditor/Kernel/ProgramUpdater/DefaultProgramUpdater.cs index 40f4e413..e51cab10 100644 --- a/OngekiFumenEditor/Kernel/ProgramUpdater/DefaultProgramUpdater.cs +++ b/OngekiFumenEditor/Kernel/ProgramUpdater/DefaultProgramUpdater.cs @@ -8,7 +8,9 @@ using Gemini.Modules.MainWindow.Views; using OngekiFumenEditor.Kernel.MiscMenu.Commands.About; using OngekiFumenEditor.Kernel.ProgramUpdater.Dialogs.ViewModels; +using OngekiFumenEditor.Kernel.Scheduler; using OngekiFumenEditor.Properties; +using OngekiFumenEditor.UI.Markup; using OngekiFumenEditor.Utils; using System; using System.Collections.Generic; @@ -20,6 +22,7 @@ using System.Net.Http; using System.Net.Http.Json; using System.Text; +using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; @@ -30,7 +33,9 @@ namespace OngekiFumenEditor.Kernel.ProgramUpdater { [Export(typeof(IProgramUpdater))] - internal class DefaultProgramUpdater : PropertyChangedBase, IProgramUpdater + [Export(typeof(ISchedulable))] + [PartCreationPolicy(CreationPolicy.Shared)] + internal class DefaultProgramUpdater : PropertyChangedBase, IProgramUpdater, ISchedulable { private const string ApiEndPoint = "https://fumen.naominet.live"; @@ -64,6 +69,10 @@ public VersionInfo RemoteVersionInfo } } + public string SchedulerName => "Program Update Check Scheduler"; + + public TimeSpan ScheduleCallLoopInterval => TimeSpan.FromMinutes(5); + private HttpClient http; private bool isModified = false; @@ -108,6 +117,12 @@ IEnumerable GetAllMenuItems2(DependencyObject parent) var icon = new BitmapImage(new Uri("pack://application:,,,/OngekiFumenEditor;component/Resources/Icons/notication.png")); icon.Freeze(); + var textblock = new TextBlock() + { + FontWeight = FontWeights.Bold, + VerticalAlignment = VerticalAlignment.Center, + }; + textblock.SetBinding(TextBlock.TextProperty, new TranslateExtension("HasNewVersion")); updatableButton = new Button() { BorderThickness = new Thickness(0), @@ -123,12 +138,7 @@ IEnumerable GetAllMenuItems2(DependencyObject parent) Height = 20, Source = icon }, - new TextBlock() - { - FontWeight = FontWeights.Bold, - VerticalAlignment = VerticalAlignment.Center, - Text = "有新版本!" - } + textblock } }, HorizontalAlignment = HorizontalAlignment.Right, @@ -151,11 +161,6 @@ IEnumerable GetAllMenuItems2(DependencyObject parent) public DefaultProgramUpdater() { http = new HttpClient(); - - if ((App.Current as App)?.IsGUIMode ?? false) - { - ModifyFrameworkMenuView(); - } } public async Task CheckUpdatable() @@ -166,9 +171,12 @@ public async Task CheckUpdatable() return; } + if ((App.Current as App)?.IsGUIMode ?? false) + ModifyFrameworkMenuView(); + try { - var url = $"{ApiEndPoint}/editor/getVersionInfo?requireMasterBranch={ProgramSetting.Default.UpdaterCheckMasterBrunchOnly}"; + var url = $"{ApiEndPoint}/editor/getVersionInfo?requireMasterBranch={ProgramSetting.Default.UpdaterCheckMasterBranchOnly}"; RemoteVersionInfo = await http.GetFromJsonAsync(url); } catch (Exception e) @@ -212,7 +220,7 @@ public async Task StartUpdate() Log.LogInfo($"targetFolder: {updaterFilePath}"); Log.LogInfo($"args: {string.Join(" ", args)}"); - if (MessageBox.Show($"程序更新文件准备完成, 是否关闭程序, 开始更新?", Resources.Warning, MessageBoxButton.OKCancel) != MessageBoxResult.OK) + if (MessageBox.Show(Resources.ProgramReadyToUpdate, Resources.Warning, MessageBoxButton.OKCancel) != MessageBoxResult.OK) return; Log.LogInfo($"user comfirmed."); @@ -350,9 +358,14 @@ void DoRollback() return (0, string.Empty); } - public Task NotifyUpdateResult(bool isSuccess, string message) + public void OnSchedulerTerm() + { + + } + + public async Task OnScheduleCall(CancellationToken cancellationToken) { - throw new NotImplementedException(); + await CheckUpdatable(); } } } diff --git a/OngekiFumenEditor/Kernel/ProgramUpdater/Dialogs/Views/ShowNewVersionDialogView.xaml b/OngekiFumenEditor/Kernel/ProgramUpdater/Dialogs/Views/ShowNewVersionDialogView.xaml index 95dbc357..ef91539c 100644 --- a/OngekiFumenEditor/Kernel/ProgramUpdater/Dialogs/Views/ShowNewVersionDialogView.xaml +++ b/OngekiFumenEditor/Kernel/ProgramUpdater/Dialogs/Views/ShowNewVersionDialogView.xaml @@ -6,9 +6,10 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:OngekiFumenEditor.Kernel.ProgramUpdater.Dialogs.Views" xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls" + xmlns:markup="clr-namespace:OngekiFumenEditor.UI.Markup" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:vm="clr-namespace:OngekiFumenEditor.Kernel.ProgramUpdater.Dialogs.ViewModels" - Title="ShowNewVersionDialogView" + Title="{markup:Translate [ShowNewVersionTitle]}" d:DataContext="{d:DesignInstance Type=vm:ShowNewVersionDialogViewModel}" Background="{DynamicResource EnvironmentWindowBackground}" ResizeMode="NoResize" @@ -32,7 +33,10 @@ - +