From 0c13e9f3c4997a4807ca9ab069fc30be8194d60d Mon Sep 17 00:00:00 2001 From: Carl Chang Date: Sat, 5 Nov 2022 15:10:10 +0800 Subject: [PATCH] add update check; bump version; --- App.xaml.cs | 28 +++++++++++++++++++++++++--- DesktopNote.csproj | 1 + Properties/AssemblyInfo.cs | 4 ++-- Resources/StringResources.en.xaml | 4 ++++ Resources/StringResources.zh.xaml | 4 ++++ 5 files changed, 36 insertions(+), 5 deletions(-) diff --git a/App.xaml.cs b/App.xaml.cs index 6eb3060..e8b10f6 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -1,11 +1,13 @@ using System; using System.Collections.Generic; using System.Runtime.InteropServices; -//using System.Configuration; -//using System.Data; using System.Linq; -//using System.Threading.Tasks; using System.Windows; +using System.Threading.Tasks; +using System.IO; +using System.Web.Script.Serialization; +using System.Net; +using System.Diagnostics; namespace DesktopNote { @@ -78,6 +80,26 @@ private void RunCheck(object sender1, StartupEventArgs e1) if (!langadded) Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri(@"Resources\StringResources.en.xaml", UriKind.Relative) }); + // check for updates + Task.Run(() => { + var localVer = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; + var req = WebRequest.CreateHttp($@"https://api.github.com/repos/changbowen/{nameof(DesktopNote)}/releases/latest"); + req.ContentType = @"application/json; charset=utf-8"; + req.UserAgent = nameof(DesktopNote); // needed otherwise 403 + req.Timeout = 10000; + using (var res = req.GetResponse()) + using (var stream = res.GetResponseStream()) + using (var reader = new StreamReader(stream, System.Text.Encoding.UTF8)) { + var dict = new JavaScriptSerializer().Deserialize>(reader.ReadToEnd()); + if (!dict.TryGetValue("tag_name", out var tagName)) return; + var remoteVer = Version.Parse(((string)tagName).TrimStart('v')); + if (localVer < remoteVer && MessageBox.Show(string.Format((string)App.Res["msgbox_new_version_avail"], + localVer, remoteVer), string.Empty, MessageBoxButton.OKCancel, MessageBoxImage.Information) == MessageBoxResult.OK) { + Process.Start(@"explorer", $@"https://github.com/changbowen/{nameof(DesktopNote)}/releases"); + } + } + }); + //other run checks if (PathIsNetworkPath(AppDomain.CurrentDomain.BaseDirectory)) { Helpers.MsgBox("msgbox_run_from_network", button: MessageBoxButton.OK, image: MessageBoxImage.Exclamation); diff --git a/DesktopNote.csproj b/DesktopNote.csproj index c13b7ed..6074062 100644 --- a/DesktopNote.csproj +++ b/DesktopNote.csproj @@ -68,6 +68,7 @@ + diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index fa4f88e..21b77ad 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -51,5 +51,5 @@ // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, // 方法是按如下所示使用“*”: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.6.1.0")] -[assembly: AssemblyFileVersion("1.6.1.0")] +[assembly: AssemblyVersion("1.6.2.0")] +[assembly: AssemblyFileVersion("1.6.2.0")] diff --git a/Resources/StringResources.en.xaml b/Resources/StringResources.en.xaml index 05cd3a7..70b299d 100644 --- a/Resources/StringResources.en.xaml +++ b/Resources/StringResources.en.xaml @@ -67,4 +67,8 @@ Program will exit now. Current note content is not saved. Changes will be lost after exiting. Exit anyway? File Name The file is already opened in another window! + A new version is available. +Current version: {0} +New version: {1} +Click OK to open the release page. \ No newline at end of file diff --git a/Resources/StringResources.zh.xaml b/Resources/StringResources.zh.xaml index 0be7017..f1f5569 100644 --- a/Resources/StringResources.zh.xaml +++ b/Resources/StringResources.zh.xaml @@ -67,4 +67,8 @@ 当前笔记内容并未保存,退出会丢失更改的内容。确定要退出吗? 文件名 该文件已在另一窗口中打开! + 有新版本可用。 +当前版本: {0} +新版本: {1} +点击确定以打开发布页面。 \ No newline at end of file