Skip to content

Commit

Permalink
add I18N
Browse files Browse the repository at this point in the history
  • Loading branch information
MikiraSora committed Oct 22, 2024
1 parent 8ae4585 commit ae590bb
Show file tree
Hide file tree
Showing 11 changed files with 355 additions and 123 deletions.
2 changes: 1 addition & 1 deletion OngekiFumenEditor/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
<setting name="WindowSizePositionLastTime" serializeAs="String">
<value />
</setting>
<setting name="UpdaterCheckMasterBrunchOnly" serializeAs="String">
<setting name="UpdaterCheckMasterBranchOnly" serializeAs="String">
<value>True</value>
</setting>
<setting name="EnableUpdateCheck" serializeAs="String">
Expand Down
45 changes: 29 additions & 16 deletions OngekiFumenEditor/Kernel/ProgramUpdater/DefaultProgramUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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";

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -108,6 +117,12 @@ IEnumerable<T> GetAllMenuItems2<T>(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),
Expand All @@ -123,12 +138,7 @@ IEnumerable<T> GetAllMenuItems2<T>(DependencyObject parent)
Height = 20,
Source = icon
},
new TextBlock()
{
FontWeight = FontWeights.Bold,
VerticalAlignment = VerticalAlignment.Center,
Text = "有新版本!"
}
textblock
}
},
HorizontalAlignment = HorizontalAlignment.Right,
Expand All @@ -151,11 +161,6 @@ IEnumerable<T> GetAllMenuItems2<T>(DependencyObject parent)
public DefaultProgramUpdater()
{
http = new HttpClient();

if ((App.Current as App)?.IsGUIMode ?? false)
{
ModifyFrameworkMenuView();
}
}

public async Task CheckUpdatable()
Expand All @@ -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<VersionInfo>(url);
}
catch (Exception e)
Expand Down Expand Up @@ -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.");
Expand Down Expand Up @@ -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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -32,7 +33,10 @@
<RowDefinition />
</Grid.RowDefinitions>

<Label VerticalAlignment="Center" FontSize="15">Current Version</Label>
<Label
VerticalAlignment="Center"
Content="{markup:Translate [CurrentVersion]}"
FontSize="15" />
<Label
Grid.Row="0"
Grid.Column="1"
Expand All @@ -46,8 +50,8 @@
<Label
Grid.Row="1"
VerticalAlignment="Center"
Content="{markup:Translate [NewVersion]}"
FontSize="15">
New Version
</Label>
<Label
Grid.Row="1"
Expand All @@ -62,8 +66,8 @@
<Label
Grid.Row="2"
VerticalAlignment="Center"
Content="{markup:Translate [Branch]}"
FontSize="15">
Branch
</Label>
<Label
Grid.Row="2"
Expand All @@ -78,8 +82,8 @@
<Label
Grid.Row="3"
VerticalAlignment="Center"
Content="{markup:Translate [FileSize]}"
FontSize="15">
File Size
</Label>
<Label
Grid.Row="3"
Expand All @@ -94,8 +98,8 @@
<Label
Grid.Row="4"
VerticalAlignment="Center"
Content="{markup:Translate [ReleaseTime]}"
FontSize="15">
Release Time
</Label>
<Label
Grid.Row="4"
Expand All @@ -110,13 +114,13 @@
<CheckBox
Margin="10,0"
HorizontalAlignment="Right"
Content="我已保存好项目和数据, 准备好了"
Content="{markup:Translate [UpdateProgramReady]}"
IsChecked="{Binding IsReady}" />
<Button
Margin="5,10,5,5"
Padding="10"
cal:Message.Attach="StartUpdate()"
Content="开始更新"
Content="{markup:Translate [UpdateStart]}"
IsEnabled="{Binding IsReady}" />
</StackPanel>
</mah:MetroWindow>
2 changes: 0 additions & 2 deletions OngekiFumenEditor/Kernel/ProgramUpdater/IProgramUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,5 @@ public interface IProgramUpdater
Task StartUpdate();

(int exitCode, string message) CommandExecuteUpdate(UpdaterOption option);

Task NotifyUpdateResult(bool isSuccess, string message);
}
}
Loading

0 comments on commit ae590bb

Please sign in to comment.