From a053bcb516a3deeb08c4a02a2061ac9fac2290b4 Mon Sep 17 00:00:00 2001 From: Pd233 Date: Wed, 3 Jan 2024 10:48:29 +0800 Subject: [PATCH] fix bugs --- .../BdsPropertiesEditorPage.xaml | 29 ++++- .../BdsPropertiesEditorPage.xaml.cs | 120 ++++++++++++------ .../Pages/HomePageModules/ModulesPage.xaml.cs | 1 - src/LipUI/VIews/LipInstallerView.xaml.cs | 3 +- src/LipUI/VIews/ModuleIcon.xaml.cs | 1 - 5 files changed, 106 insertions(+), 48 deletions(-) diff --git a/src/LipUI/Pages/HomePageModules/BdsPropertiesEditorPage.xaml b/src/LipUI/Pages/HomePageModules/BdsPropertiesEditorPage.xaml index 85e1fb6..f39c3ed 100644 --- a/src/LipUI/Pages/HomePageModules/BdsPropertiesEditorPage.xaml +++ b/src/LipUI/Pages/HomePageModules/BdsPropertiesEditorPage.xaml @@ -58,14 +58,29 @@ - - - - - - + + + + + + + + + + + + + + + + diff --git a/src/LipUI/Pages/HomePageModules/BdsPropertiesEditorPage.xaml.cs b/src/LipUI/Pages/HomePageModules/BdsPropertiesEditorPage.xaml.cs index cb08b2c..d44fcba 100644 --- a/src/LipUI/Pages/HomePageModules/BdsPropertiesEditorPage.xaml.cs +++ b/src/LipUI/Pages/HomePageModules/BdsPropertiesEditorPage.xaml.cs @@ -1,21 +1,16 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; -using System.IO; -using System.Linq; -using System.Text; -using System.Text.RegularExpressions; -using System.Threading.Tasks; using LipUI.Models; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Input; using Microsoft.UI.Xaml.Media; using Microsoft.UI.Xaml.Navigation; -using Windows.Devices.Radios; -using Windows.UI; -using Microsoft.UI.Xaml.Input; +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using System.Threading.Tasks; using Windows.System; +using Windows.UI; // To learn more about WinUI, the WinUI project structure, // and more about our project templates, see: http://aka.ms/winui-project-info. @@ -54,19 +49,42 @@ protected override void OnNavigatedTo(NavigationEventArgs e) base.OnNavigatedTo(e); } + private void ShowInfoBar( + string? title, + string? message, + InfoBarSeverity severity, + UIElement? barContent = null, + Action? completed = null) + { + var timer = DispatcherQueue.CreateTimer(); + timer.Interval = TimeSpan.FromSeconds(2); + timer.Tick += (sender, e) => + { + Info.IsOpen = false; + InfoBarPopOutStoryboard.Begin(); + timer.Stop(); + completed?.Invoke(); + }; + + Info.Title = title; + Info.Message = message; + Info.Severity = severity; + Info.IsClosable = false; + Info.IsOpen = true; + Info.Content = barContent; + + InfoBarPopInStoryboard.Begin(); + timer.Start(); + } + private async void Page_Loaded(object sender, RoutedEventArgs e) { if (Server is null) { - var dialog = new ContentDialog() - { - XamlRoot = XamlRoot, - Content = "i18n.nullServerPath", - CloseButtonText = "OK" - }; - await dialog.ShowAsync(); - Frame.GoBack(); - } + await Task.Delay(500); + ShowInfoBar("i18n.nullServerPath", null, InfoBarSeverity.Error, null, Frame.GoBack); + return; + }; Viewer.Content = new ProgressRing(); DispatcherQueue.TryEnqueue(LoadPropertiesAndCreateUI); @@ -74,30 +92,57 @@ private async void Page_Loaded(object sender, RoutedEventArgs e) private async ValueTask SaveAsync() { - if (BindingSettings.Count is 0) - return; + try + { + ShowInfoBar("i18n.save", null, + InfoBarSeverity.Informational, + new ProgressBar() + { + IsIndeterminate = true + }); - var path = Path.Combine(Server!.WorkingDirectory, "server.properties"); - var lines = await File.ReadAllLinesAsync(path); + if (BindingSettings.Count is not 0) + { + var path = Path.Combine(Server!.WorkingDirectory, "server.properties"); + var lines = await File.ReadAllLinesAsync(path); - for (int i = 0; i < lines.Length; i++) - { - string? line = lines[i]; - if (line.StartsWith('#') || string.IsNullOrWhiteSpace(line)) - continue; + for (int i = 0; i < lines.Length; i++) + { + string? line = lines[i]; + if (line.StartsWith('#') || string.IsNullOrWhiteSpace(line)) + continue; - var key = line[..line.IndexOf('=')]; - if (BindingSettings.TryGetValue(key, out var value)) - lines[i] = $"{key}={value}"; - } + var key = line[..line.IndexOf('=')]; + if (BindingSettings.TryGetValue(key, out var value)) + lines[i] = $"{key}={value}"; + } - await File.WriteAllLinesAsync(path, lines); + await File.WriteAllLinesAsync(path, lines); + } + + await Task.Delay(500); + ShowInfoBar("i18n.completed", null, InfoBarSeverity.Success); + } + catch (Exception ex) + { + ShowInfoBar("i18n.error", ex.Message, InfoBarSeverity.Error); + } } private async void LoadPropertiesAndCreateUI() { var path = Path.Combine(Server!.WorkingDirectory, "server.properties"); - var lines = await File.ReadAllLinesAsync(path); + string[] lines; + + try + { + lines = await File.ReadAllLinesAsync(path); + } + catch (Exception ex) + { + ShowInfoBar("i18n.failed", ex.Message, InfoBarSeverity.Error, null, Frame.GoBack); + return; + } string? currentPropertiesLine, nextPropertiesLine = null; var notes = new List(); @@ -311,8 +356,7 @@ private async void Page_KeyDown(object sender, KeyRoutedEventArgs e) return; } - if (ctrlPressed && e.Key is VirtualKey.S) - await SaveAsync(); + if (ctrlPressed && e.Key is VirtualKey.S) await SaveAsync(); } private void Page_KeyUp(object sender, KeyRoutedEventArgs e) diff --git a/src/LipUI/Pages/HomePageModules/ModulesPage.xaml.cs b/src/LipUI/Pages/HomePageModules/ModulesPage.xaml.cs index 46fcf62..5ebc3e2 100644 --- a/src/LipUI/Pages/HomePageModules/ModulesPage.xaml.cs +++ b/src/LipUI/Pages/HomePageModules/ModulesPage.xaml.cs @@ -1,7 +1,6 @@ using LipUI.Models; using LipUI.VIews; using Microsoft.UI.Xaml.Controls; -using Microsoft.UI.Xaml.Navigation; using System.Threading.Tasks; // To learn more about WinUI, the WinUI project structure, diff --git a/src/LipUI/VIews/LipInstallerView.xaml.cs b/src/LipUI/VIews/LipInstallerView.xaml.cs index 85cddb9..6f57671 100644 --- a/src/LipUI/VIews/LipInstallerView.xaml.cs +++ b/src/LipUI/VIews/LipInstallerView.xaml.cs @@ -78,6 +78,7 @@ private async ValueTask DownloadLipPortable(InstallerInfo info) using var client = new HttpClient( new HttpClientHandler() { ClientCertificateOptions = ClientCertificateOption.Automatic }) { + Timeout = TimeSpan.FromSeconds(2), DefaultRequestHeaders = { ExpectContinue = false } }; @@ -89,7 +90,7 @@ private async ValueTask DownloadLipPortable(InstallerInfo info) } catch { - response = await client.GetAsync($"https://mirror.ghproxy.com/{info.AssetUrl}"); + response = await client.GetAsync($"https://github.moeyy.xyz/{info.AssetUrl}"); } var input = await response.Content.ReadAsStreamAsync(); diff --git a/src/LipUI/VIews/ModuleIcon.xaml.cs b/src/LipUI/VIews/ModuleIcon.xaml.cs index 162a16a..31c884c 100644 --- a/src/LipUI/VIews/ModuleIcon.xaml.cs +++ b/src/LipUI/VIews/ModuleIcon.xaml.cs @@ -2,7 +2,6 @@ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using System; -using System.Net.Security; // To learn more about WinUI, the WinUI project structure, // and more about our project templates, see: http://aka.ms/winui-project-info.