From 28899ee9d61a8eac636cd11568e30d4a2df55e86 Mon Sep 17 00:00:00 2001 From: huiyadanli Date: Thu, 23 Nov 2023 01:13:20 +0800 Subject: [PATCH] add update notice --- BetterGenshinImpact/App.xaml.cs | 1 - BetterGenshinImpact/Core/Config/Global.cs | 21 +++++++++- BetterGenshinImpact/Model/Notice.cs | 6 +++ .../ViewModel/MainWindowViewModel.cs | 39 ++++++++++++++++++- .../ViewModel/Pages/HomePageViewModel.cs | 9 ----- 5 files changed, 63 insertions(+), 13 deletions(-) create mode 100644 BetterGenshinImpact/Model/Notice.cs diff --git a/BetterGenshinImpact/App.xaml.cs b/BetterGenshinImpact/App.xaml.cs index cfd85f8e..43c99349 100644 --- a/BetterGenshinImpact/App.xaml.cs +++ b/BetterGenshinImpact/App.xaml.cs @@ -59,7 +59,6 @@ public partial class App : Application Log.Logger = loggerConfiguration.CreateLogger(); services.AddLogging(c => c.AddSerilog()); - // App Host services.AddHostedService(); diff --git a/BetterGenshinImpact/Core/Config/Global.cs b/BetterGenshinImpact/Core/Config/Global.cs index eea352cc..5da32a1d 100644 --- a/BetterGenshinImpact/Core/Config/Global.cs +++ b/BetterGenshinImpact/Core/Config/Global.cs @@ -5,7 +5,7 @@ namespace BetterGenshinImpact.Core.Config; public class Global { - public static string Version = "0.14.2"; + public static string Version = "0.15.0"; public static string StartUpPath { get; private set; } = AppContext.BaseDirectory; @@ -25,4 +25,23 @@ public static string Absolute(string relativePath) } return null; } + + public static bool IsNewVersion(string version) + { + var currentVersionArr =Version.Split('.'); + var newVersionArr = version.Split('.'); + if (currentVersionArr.Length != newVersionArr.Length) + { + return false; + } + + for (int i = 0; i < currentVersionArr.Length; i++) + { + if (int.Parse(currentVersionArr[i]) < int.Parse(newVersionArr[i])) + { + return true; + } + } + return false; + } } \ No newline at end of file diff --git a/BetterGenshinImpact/Model/Notice.cs b/BetterGenshinImpact/Model/Notice.cs new file mode 100644 index 00000000..f86d6b68 --- /dev/null +++ b/BetterGenshinImpact/Model/Notice.cs @@ -0,0 +1,6 @@ +namespace BetterGenshinImpact.Model; + +public class Notice +{ + public string Version { get; set; } = string.Empty; +} \ No newline at end of file diff --git a/BetterGenshinImpact/ViewModel/MainWindowViewModel.cs b/BetterGenshinImpact/ViewModel/MainWindowViewModel.cs index cfa757ae..0f635037 100644 --- a/BetterGenshinImpact/ViewModel/MainWindowViewModel.cs +++ b/BetterGenshinImpact/ViewModel/MainWindowViewModel.cs @@ -1,15 +1,19 @@ using BetterGenshinImpact.Core.Config; +using BetterGenshinImpact.Core.Recognition.OCR; +using BetterGenshinImpact.Helpers; +using BetterGenshinImpact.Model; using BetterGenshinImpact.Service.Interface; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Messaging; using CommunityToolkit.Mvvm.Messaging.Messages; using Microsoft.Extensions.Logging; +using OpenCvSharp; using System.Diagnostics; +using System.Net.Http; +using System.Net.Http.Json; using System.Threading.Tasks; using System.Windows; -using BetterGenshinImpact.Core.Recognition.OCR; -using OpenCvSharp; using Wpf.Ui; namespace BetterGenshinImpact.ViewModel @@ -36,6 +40,37 @@ private void OnLoaded() var s = OcrFactory.Paddle.Ocr(new Mat(Global.Absolute("Assets\\Model\\PaddleOCR\\test_ocr.png"), ImreadModes.Grayscale)); Debug.WriteLine("PaddleOcr预热结果:" + s); }); + + Task.Run(GetNewestInfo); + } + + + private async void GetNewestInfo() + { + var httpClient = new HttpClient(); + var notice = await httpClient.GetFromJsonAsync(@"https://hui-config.oss-cn-hangzhou.aliyuncs.com/bgi/notice.json"); + if (notice != null && !string.IsNullOrWhiteSpace(notice.Version)) + { + if (Global.IsNewVersion(notice.Version)) + { + await UIDispatcherHelper.Invoke(async () => + { + var uiMessageBox = new Wpf.Ui.Controls.MessageBox + { + Title = "更新提示", + Content = $"存在最新版本 {notice.Version},点击确定前往下载页面下载最新版本", + PrimaryButtonText = "确定", + CloseButtonText = "取消", + }; + + var result = await uiMessageBox.ShowDialogAsync(); + if (result == Wpf.Ui.Controls.MessageBoxResult.Primary) + { + Process.Start(new ProcessStartInfo("https://bgi.huiyadan.com/download.html") { UseShellExecute = true }); + } + }); + } + } } [RelayCommand] diff --git a/BetterGenshinImpact/ViewModel/Pages/HomePageViewModel.cs b/BetterGenshinImpact/ViewModel/Pages/HomePageViewModel.cs index 04d90722..895d2f41 100644 --- a/BetterGenshinImpact/ViewModel/Pages/HomePageViewModel.cs +++ b/BetterGenshinImpact/ViewModel/Pages/HomePageViewModel.cs @@ -12,17 +12,9 @@ using Microsoft.Extensions.Logging; using System; using System.Diagnostics; -using System.Drawing; using System.Windows; using System.Windows.Interop; -using BetterGenshinImpact.Core.Recognition.OCR; -using OpenCvSharp; using Wpf.Ui.Controls; -using Compunet.YoloV8; -using System.Drawing.Imaging; -using System.IO; -using MessageBox = System.Windows.MessageBox; -using System.Text.Json; namespace BetterGenshinImpact.ViewModel.Pages; @@ -177,6 +169,5 @@ private void OnTest() //{ // MessageBox.Show(e.StackTrace); //} - } } \ No newline at end of file