Skip to content

Commit

Permalink
add update check;
Browse files Browse the repository at this point in the history
bump version;
  • Loading branch information
changbowen committed Nov 5, 2022
1 parent f938fb0 commit 0c13e9f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
28 changes: 25 additions & 3 deletions App.xaml.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -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<Dictionary<string, object>>(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);
Expand Down
1 change: 1 addition & 0 deletions DesktopNote.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
4 changes: 4 additions & 0 deletions Resources/StringResources.en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,8 @@ Program will exit now.</sys:String>
<sys:String x:Key="msgbox_not_saved_confirm">Current note content is not saved. Changes will be lost after exiting. Exit anyway?</sys:String>
<sys:String x:Key="label_filename">File Name</sys:String>
<sys:String x:Key="msgbox_file_already_opened">The file is already opened in another window!</sys:String>
<sys:String x:Key="msgbox_new_version_avail">A new version is available.
Current version: {0}
New version: {1}
Click OK to open the release page.</sys:String>
</ResourceDictionary>
4 changes: 4 additions & 0 deletions Resources/StringResources.zh.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,8 @@
<sys:String x:Key="msgbox_not_saved_confirm">当前笔记内容并未保存,退出会丢失更改的内容。确定要退出吗?</sys:String>
<sys:String x:Key="label_filename">文件名</sys:String>
<sys:String x:Key="msgbox_file_already_opened">该文件已在另一窗口中打开!</sys:String>
<sys:String x:Key="msgbox_new_version_avail">有新版本可用。
当前版本: {0}
新版本: {1}
点击确定以打开发布页面。</sys:String>
</ResourceDictionary>

0 comments on commit 0c13e9f

Please sign in to comment.