diff --git a/Source/GrasscutterTools/App.config b/Source/GrasscutterTools/App.config index 45ea3ed..15823b0 100644 --- a/Source/GrasscutterTools/App.config +++ b/Source/GrasscutterTools/App.config @@ -10,27 +10,30 @@ - - False - - - 10001 - - - zh-CN - - - - - - TextMapCHS - - - 10001 - - - https://127.0.0.1 - - + + False + + + 10001 + + + zh-CN + + + + + + TextMapCHS + + + 10001 + + + https://127.0.0.1 + + + + + \ No newline at end of file diff --git a/Source/GrasscutterTools/FormMain.cs b/Source/GrasscutterTools/FormMain.cs index 2677504..a6faebe 100644 --- a/Source/GrasscutterTools/FormMain.cs +++ b/Source/GrasscutterTools/FormMain.cs @@ -40,17 +40,18 @@ namespace GrasscutterTools { InitializeComponent(); Icon = Resources.IconGrasscutter; + LoadVersion(); LoadSettings(); + LoadUpdate(); } private void FormMain_Load(object sender, EventArgs e) { MultiLanguage.LoadLanguage(this, typeof(FormMain)); - Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; #if DEBUG - Text += " - by jie65535 - v" + version.ToString(3) + "-debug"; + Text += " - by jie65535 - v" + AppVersion.ToString(3) + "-debug"; #else - Text += " - by jie65535 - v" + version.ToString(3); + Text += " - by jie65535 - v" + AppVersion.ToString(3); #endif GameData.LoadResources(); @@ -75,6 +76,13 @@ namespace GrasscutterTools private readonly string[] LanguageNames = new string[] { "简体中文", "English" }; private readonly string[] Languages = new string[] { "zh-CN", "en-US" }; + + private Version AppVersion; + private void LoadVersion() + { + AppVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; + } + private void LoadSettings() { try @@ -116,6 +124,42 @@ namespace GrasscutterTools } } + private void LoadUpdate() + { + Task.Run(() => + { + try + { + var info = Github.ReleaseAPI.GetReleasesLastest("jie65535", "GrasscutterCommandGenerator").Result; + if (Version.TryParse(info.TagName.Substring(1), out Version lastestVersion) && AppVersion < lastestVersion) + { + if (!string.IsNullOrEmpty(Settings.Default.CheckedLastVersion) + && Version.TryParse(Settings.Default.CheckedLastVersion, out Version checkedVersion) + && checkedVersion >= lastestVersion) + return; + BeginInvoke(new Action(() => + { + var r = MessageBox.Show( + string.Format(Resources.NewVersionInfo, info.Name, info.CraeteTime, info.Body), + Resources.CheckToNewVersion, + MessageBoxButtons.YesNo, + MessageBoxIcon.Information); + if (r == DialogResult.Yes) + System.Diagnostics.Process.Start(info.Url); + else if (r == DialogResult.No) + Settings.Default.CheckedLastVersion = lastestVersion.ToString(); + })); + } + } + catch (Exception) + { +#if DEBUG + throw; +#endif + } + }); + } + #endregion - 初始化 - #region - 主页 - diff --git a/Source/GrasscutterTools/Github/ReleaseAPI.cs b/Source/GrasscutterTools/Github/ReleaseAPI.cs new file mode 100644 index 0000000..c421158 --- /dev/null +++ b/Source/GrasscutterTools/Github/ReleaseAPI.cs @@ -0,0 +1,46 @@ +using System; +using System.Net.Http.Headers; +using System.Threading.Tasks; + +using GrasscutterTools.Utils; + +namespace GrasscutterTools.Github +{ + public static class ReleaseAPI + { + public static async Task GetReleasesLastest(string username, string repo) + { + var headerValue = new ProductInfoHeaderValue("GrasscutterTools", "1"); + try + { + HttpHelper.HttpClient.DefaultRequestHeaders.UserAgent.Add(headerValue); + var r = await HttpHelper.GetAsync($"https://api.github.com/repos/{username}/{repo}/releases/latest"); + return new ReleaseInfo + { + TagName = r.tag_name, + Url = r.html_url, + CraeteTime = r.created_at, + Name = r.name, + Body = r.body + }; + } + finally + { + HttpHelper.HttpClient.DefaultRequestHeaders.UserAgent.Remove(headerValue); + } + } + + public class ReleaseInfo + { + public string TagName { get; set; } + + public string Url { get; set; } + + public DateTime CraeteTime { get; set; } + + public string Name { get; set; } + + public string Body { get; set; } + } + } +} diff --git a/Source/GrasscutterTools/GrasscutterTools.csproj b/Source/GrasscutterTools/GrasscutterTools.csproj index 2fd6ca0..89d6b79 100644 --- a/Source/GrasscutterTools/GrasscutterTools.csproj +++ b/Source/GrasscutterTools/GrasscutterTools.csproj @@ -222,6 +222,7 @@ + diff --git a/Source/GrasscutterTools/Properties/AssemblyInfo.cs b/Source/GrasscutterTools/Properties/AssemblyInfo.cs index a0b8661..038d4a9 100644 --- a/Source/GrasscutterTools/Properties/AssemblyInfo.cs +++ b/Source/GrasscutterTools/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ using System.Runtime.InteropServices; //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 //通过使用 "*",如下所示: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.2.0")] +[assembly: AssemblyVersion("1.1.0")] [assembly: AssemblyFileVersion("1.0.0")] \ No newline at end of file diff --git a/Source/GrasscutterTools/Properties/Resources.Designer.cs b/Source/GrasscutterTools/Properties/Resources.Designer.cs index 1e041e8..fbd6c96 100644 --- a/Source/GrasscutterTools/Properties/Resources.Designer.cs +++ b/Source/GrasscutterTools/Properties/Resources.Designer.cs @@ -403,6 +403,15 @@ namespace GrasscutterTools.Properties { } } + /// + /// 查找类似 检查到新版本 的本地化字符串。 + /// + internal static string CheckToNewVersion { + get { + return ResourceManager.GetString("CheckToNewVersion", resourceCulture); + } + } + /// /// 查找类似 无,晴天,多云,雨天,雷暴,雪天,雾天 的本地化字符串。 /// @@ -715,6 +724,15 @@ namespace GrasscutterTools.Properties { } } + /// + /// 查找类似 版本名:{0}\n更新时间:{1}\n更新内容:\n{2}\n\n是否查看更新?选择否将不再提醒该版本。 的本地化字符串。 + /// + internal static string NewVersionInfo { + get { + return ResourceManager.GetString("NewVersionInfo", resourceCulture); + } + } + /// /// 查找类似 1: (test)蒙德城主$UNRELEASED ///2: (test)哥哥$UNRELEASED diff --git a/Source/GrasscutterTools/Properties/Resources.en-us.resx b/Source/GrasscutterTools/Properties/Resources.en-us.resx index 77aea0a..5869ed1 100644 --- a/Source/GrasscutterTools/Properties/Resources.en-us.resx +++ b/Source/GrasscutterTools/Properties/Resources.en-us.resx @@ -148,6 +148,9 @@ The browser failed to open. You can manually access the following address: + + Check to new version + None,Sunny,Partly cloudy,Rain,Thunderstorm,Snow,Fog @@ -196,6 +199,9 @@ ..\Resources\en-us\Monster.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + + Name : {0}\nUpdate time : {1}\nUpdate info : \n{2}\n\nDo you want to check for updates? Selecting No will no longer remind you of this version. + ..\Resources\en-us\NPC.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 diff --git a/Source/GrasscutterTools/Properties/Resources.resx b/Source/GrasscutterTools/Properties/Resources.resx index 0f29f75..3395fd6 100644 --- a/Source/GrasscutterTools/Properties/Resources.resx +++ b/Source/GrasscutterTools/Properties/Resources.resx @@ -148,6 +148,9 @@ 浏览器打开失败,你可以通过以下链接手动访问: + + 检查到新版本 + 无,晴天,多云,雨天,雷暴,雪天,雾天 @@ -199,6 +202,9 @@ ..\Resources\zh-cn\Monster.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + + 版本名:{0}\n更新时间:{1}\n更新内容:\n{2}\n\n是否查看更新?选择否将不再提醒该版本。 + ..\Resources\zh-cn\NPC.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 diff --git a/Source/GrasscutterTools/Properties/Settings.Designer.cs b/Source/GrasscutterTools/Properties/Settings.Designer.cs index 7975ccd..0addf4c 100644 --- a/Source/GrasscutterTools/Properties/Settings.Designer.cs +++ b/Source/GrasscutterTools/Properties/Settings.Designer.cs @@ -106,5 +106,17 @@ namespace GrasscutterTools.Properties { this["Host"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string CheckedLastVersion { + get { + return ((string)(this["CheckedLastVersion"])); + } + set { + this["CheckedLastVersion"] = value; + } + } } } diff --git a/Source/GrasscutterTools/Properties/Settings.settings b/Source/GrasscutterTools/Properties/Settings.settings index 8e20a25..363cfd2 100644 --- a/Source/GrasscutterTools/Properties/Settings.settings +++ b/Source/GrasscutterTools/Properties/Settings.settings @@ -23,5 +23,8 @@ https://127.0.0.1 + + + \ No newline at end of file diff --git a/Source/GrasscutterTools/Utils/HttpHelper.cs b/Source/GrasscutterTools/Utils/HttpHelper.cs index c897dbe..97d4c24 100644 --- a/Source/GrasscutterTools/Utils/HttpHelper.cs +++ b/Source/GrasscutterTools/Utils/HttpHelper.cs @@ -28,7 +28,10 @@ namespace GrasscutterTools.Utils { public static class HttpHelper { - private static readonly HttpClient httpClient = new HttpClient(); + public static readonly HttpClient HttpClient = new HttpClient + { + Timeout = TimeSpan.FromSeconds(30), + }; static HttpHelper() { @@ -39,7 +42,7 @@ namespace GrasscutterTools.Utils { try { - var responseMessage = await httpClient.GetAsync(url); + var responseMessage = await HttpClient.GetAsync(url); if (responseMessage.IsSuccessStatusCode) { var responseString = await responseMessage.Content.ReadAsStringAsync(); @@ -63,7 +66,7 @@ namespace GrasscutterTools.Utils try { var content = new StringContent(JsonConvert.SerializeObject(obj), Encoding.UTF8, "application/json"); - var responseMessage = await httpClient.PostAsync(url, content); + var responseMessage = await HttpClient.PostAsync(url, content); if (responseMessage.IsSuccessStatusCode) { var responseString = await responseMessage.Content.ReadAsStringAsync();