diff --git a/ConvertZZ/App.xaml.cs b/ConvertZZ/App.xaml.cs index cc1a811..68fe30a 100644 --- a/ConvertZZ/App.xaml.cs +++ b/ConvertZZ/App.xaml.cs @@ -1,7 +1,9 @@ -using System; +using ConvertZZ.Moudle; +using System; +using System.Diagnostics; using System.IO; +using System.Threading.Tasks; using System.Windows; - namespace ConvertZZ { /// @@ -20,6 +22,20 @@ public App() nIcon.Icon = ConvertZZ.Properties.Resources.icon; nIcon.Visible = true; + if (Settings.CheckVersion) + { + Task.Run(() => + { + var versionReport = UpdateChecker.ChecktVersion(); + if (versionReport != null && !versionReport.HaveNew) + { + if (MessageBox.Show(String.Format("發現新版本{0}(目前版本:{1})\r\n前往官網下載更新?", versionReport.Newst.ToString(), versionReport.Current.ToString()), "發現更新", MessageBoxButton.YesNo) == MessageBoxResult.Yes) + { + Process.Start("https://github.com/flier268/ConvertZZ/releases"); + } + } + }); + } } public static ChineseConverter ChineseConverter { get; set; } = new ChineseConverter(); diff --git a/ConvertZZ/ConvertZZ.csproj b/ConvertZZ/ConvertZZ.csproj index df537a2..4b2cccf 100644 --- a/ConvertZZ/ConvertZZ.csproj +++ b/ConvertZZ/ConvertZZ.csproj @@ -94,6 +94,7 @@ + Window_MessageBoxEx.xaml diff --git a/ConvertZZ/Moudle/UpdateChecker.cs b/ConvertZZ/Moudle/UpdateChecker.cs new file mode 100644 index 0000000..687cbe2 --- /dev/null +++ b/ConvertZZ/Moudle/UpdateChecker.cs @@ -0,0 +1,45 @@ +using System; +using System.Net.Http; +using System.Reflection; +using System.Text.RegularExpressions; + +namespace ConvertZZ.Moudle +{ + public class UpdateChecker + { + public static VersionReport ChecktVersion() + { + try + { + using (var client = new HttpClient()) + { + var response = client.GetAsync("https://raw.githubusercontent.com/flier268/ConvertZZ/master/ConvertZZ/Properties/AssemblyInfo.cs").Result; + + if (response.IsSuccessStatusCode) + { + var responseContent = response.Content; + string responseString = responseContent.ReadAsStringAsync().Result; + string pattern = @"^\[assembly: AssemblyVersion\(""(.*?)""\)\]"; + var m = Regex.Match(responseString, pattern,RegexOptions.Multiline); + if (m.Success) + { + Version ver = new Version(m.Groups[1].ToString().ToString()); + Version version = Assembly.GetEntryAssembly().GetName().Version; + int tm = version.CompareTo(ver); + VersionReport versionReport = new VersionReport(); + return new VersionReport() { Current = version, Newst = ver, HaveNew = tm < 0 }; + } + } + } + } + catch { } + return null; + } + public class VersionReport + { + public Version Current { get; set; } + public Version Newst { get; set; } + public bool HaveNew { get; set; } + } + } +} diff --git a/ConvertZZ/Settings.cs b/ConvertZZ/Settings.cs index e2e6997..614459d 100644 --- a/ConvertZZ/Settings.cs +++ b/ConvertZZ/Settings.cs @@ -50,6 +50,7 @@ public Settings() AssistiveTouch = true; HotKey = new HotKey(); FileConvert = new FileConvert(); + CheckVersion = true; } /// /// 試圖自動辨識編碼 @@ -91,6 +92,11 @@ public Settings() /// [JsonProperty("FileConvert")] public FileConvert FileConvert { get; set; } + /// + /// 啟動時檢查更新 + /// + [JsonProperty("CheckVersion")] + public bool CheckVersion { get; set; } } public partial class FileConvert diff --git a/ConvertZZ/Window_Setting.xaml b/ConvertZZ/Window_Setting.xaml index 55d0e4e..1a20490 100644 --- a/ConvertZZ/Window_Setting.xaml +++ b/ConvertZZ/Window_Setting.xaml @@ -42,6 +42,8 @@