Skip to content

Commit 0c13e9f

Browse files
committed
add update check;
bump version;
1 parent f938fb0 commit 0c13e9f

5 files changed

Lines changed: 36 additions & 5 deletions

File tree

App.xaml.cs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Runtime.InteropServices;
4-
//using System.Configuration;
5-
//using System.Data;
64
using System.Linq;
7-
//using System.Threading.Tasks;
85
using System.Windows;
6+
using System.Threading.Tasks;
7+
using System.IO;
8+
using System.Web.Script.Serialization;
9+
using System.Net;
10+
using System.Diagnostics;
911

1012
namespace DesktopNote
1113
{
@@ -78,6 +80,26 @@ private void RunCheck(object sender1, StartupEventArgs e1)
7880
if (!langadded)
7981
Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri(@"Resources\StringResources.en.xaml", UriKind.Relative) });
8082

83+
// check for updates
84+
Task.Run(() => {
85+
var localVer = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
86+
var req = WebRequest.CreateHttp($@"https://api.github.com/repos/changbowen/{nameof(DesktopNote)}/releases/latest");
87+
req.ContentType = @"application/json; charset=utf-8";
88+
req.UserAgent = nameof(DesktopNote); // needed otherwise 403
89+
req.Timeout = 10000;
90+
using (var res = req.GetResponse())
91+
using (var stream = res.GetResponseStream())
92+
using (var reader = new StreamReader(stream, System.Text.Encoding.UTF8)) {
93+
var dict = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(reader.ReadToEnd());
94+
if (!dict.TryGetValue("tag_name", out var tagName)) return;
95+
var remoteVer = Version.Parse(((string)tagName).TrimStart('v'));
96+
if (localVer < remoteVer && MessageBox.Show(string.Format((string)App.Res["msgbox_new_version_avail"],
97+
localVer, remoteVer), string.Empty, MessageBoxButton.OKCancel, MessageBoxImage.Information) == MessageBoxResult.OK) {
98+
Process.Start(@"explorer", $@"https://github.com/changbowen/{nameof(DesktopNote)}/releases");
99+
}
100+
}
101+
});
102+
81103
//other run checks
82104
if (PathIsNetworkPath(AppDomain.CurrentDomain.BaseDirectory)) {
83105
Helpers.MsgBox("msgbox_run_from_network", button: MessageBoxButton.OK, image: MessageBoxImage.Exclamation);

DesktopNote.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
</Reference>
6969
<Reference Include="System" />
7070
<Reference Include="System.Drawing" />
71+
<Reference Include="System.Web.Extensions" />
7172
<Reference Include="System.Xml" />
7273
<Reference Include="Microsoft.CSharp" />
7374
<Reference Include="System.Core" />

Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@
5151
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
5252
// 方法是按如下所示使用“*”:
5353
// [assembly: AssemblyVersion("1.0.*")]
54-
[assembly: AssemblyVersion("1.6.1.0")]
55-
[assembly: AssemblyFileVersion("1.6.1.0")]
54+
[assembly: AssemblyVersion("1.6.2.0")]
55+
[assembly: AssemblyFileVersion("1.6.2.0")]

Resources/StringResources.en.xaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,8 @@ Program will exit now.</sys:String>
6767
<sys:String x:Key="msgbox_not_saved_confirm">Current note content is not saved. Changes will be lost after exiting. Exit anyway?</sys:String>
6868
<sys:String x:Key="label_filename">File Name</sys:String>
6969
<sys:String x:Key="msgbox_file_already_opened">The file is already opened in another window!</sys:String>
70+
<sys:String x:Key="msgbox_new_version_avail">A new version is available.
71+
Current version: {0}
72+
New version: {1}
73+
Click OK to open the release page.</sys:String>
7074
</ResourceDictionary>

Resources/StringResources.zh.xaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,8 @@
6767
<sys:String x:Key="msgbox_not_saved_confirm">当前笔记内容并未保存,退出会丢失更改的内容。确定要退出吗?</sys:String>
6868
<sys:String x:Key="label_filename">文件名</sys:String>
6969
<sys:String x:Key="msgbox_file_already_opened">该文件已在另一窗口中打开!</sys:String>
70+
<sys:String x:Key="msgbox_new_version_avail">有新版本可用。
71+
当前版本: {0}
72+
新版本: {1}
73+
点击确定以打开发布页面。</sys:String>
7074
</ResourceDictionary>

0 commit comments

Comments
 (0)