Skip to content

Commit

Permalink
add update notice
Browse files Browse the repository at this point in the history
  • Loading branch information
huiyadanli committed Nov 22, 2023
1 parent 34725b5 commit 28899ee
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 13 deletions.
1 change: 0 additions & 1 deletion BetterGenshinImpact/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public partial class App : Application
Log.Logger = loggerConfiguration.CreateLogger();
services.AddLogging(c => c.AddSerilog());


// App Host
services.AddHostedService<ApplicationHostService>();

Expand Down
21 changes: 20 additions & 1 deletion BetterGenshinImpact/Core/Config/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
}
6 changes: 6 additions & 0 deletions BetterGenshinImpact/Model/Notice.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace BetterGenshinImpact.Model;

public class Notice
{
public string Version { get; set; } = string.Empty;
}
39 changes: 37 additions & 2 deletions BetterGenshinImpact/ViewModel/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<Notice>(@"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]
Expand Down
9 changes: 0 additions & 9 deletions BetterGenshinImpact/ViewModel/Pages/HomePageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -177,6 +169,5 @@ private void OnTest()
//{
// MessageBox.Show(e.StackTrace);
//}

}
}

0 comments on commit 28899ee

Please sign in to comment.