private void CheckNewVersion(bool startup = false) { if (string.IsNullOrEmpty(MyCommon.fileVersion)) { return; } string retMsg; try { retMsg = tw.GetVersionInfo(); } catch { retMsg = ""; } if (string.IsNullOrEmpty(retMsg)) { StatusLabel.Text = Properties.Resources.CheckNewVersionText9; if (!startup) MessageBox.Show(Properties.Resources.CheckNewVersionText10, MyCommon.ReplaceAppName(Properties.Resources.CheckNewVersionText2), MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2); return; } // 改行2つで前後パートを分割(前半がバージョン番号など、後半が詳細テキスト) string[] msgPart = retMsg.Split(new string[] {"\n\n", "\r\n\r\n"}, 2, StringSplitOptions.None); string[] msgHeader = msgPart[0].Split(new string[] {"\n", "\r\n"}, StringSplitOptions.None); string msgBody = msgPart.Length == 2 ? msgPart[1] : ""; msgBody = Regex.Replace(msgBody, "(?<!\r)\n", "\r\n"); // LF -> CRLF string currentVersion = msgHeader[0]; string downloadUrl = msgHeader[1]; if (string.Compare(currentVersion, MyCommon.fileVersion) > 0) { using (var dialog = new UpdateDialog()) { dialog.SummaryText = string.Format(Properties.Resources.CheckNewVersionText3, currentVersion); dialog.DetailsText = msgBody; if (dialog.ShowDialog(this) == DialogResult.Yes) { this.OpenUriAsync(downloadUrl); } } } else { if (!startup) { var msgtext = MyCommon.ReplaceAppName(string.Format(Properties.Resources.CheckNewVersionText7, MyCommon.fileVersion, currentVersion)); MessageBox.Show(msgtext, MyCommon.ReplaceAppName(Properties.Resources.CheckNewVersionText2), MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
private async Task CheckNewVersion(bool startup = false) { if (ApplicationSettings.VersionInfoUrl == null) return; // 更新チェック無効化 try { var versionInfo = await this.GetVersionInfoAsync(); if (versionInfo.Version <= Version.Parse(MyCommon.FileVersion)) { // 更新不要 if (!startup) { var msgtext = string.Format(Properties.Resources.CheckNewVersionText7, MyCommon.GetReadableVersion(), MyCommon.GetReadableVersion(versionInfo.Version)); msgtext = MyCommon.ReplaceAppName(msgtext); MessageBox.Show(msgtext, MyCommon.ReplaceAppName(Properties.Resources.CheckNewVersionText2), MessageBoxButtons.OK, MessageBoxIcon.Information); } return; } using (var dialog = new UpdateDialog()) { dialog.SummaryText = string.Format(Properties.Resources.CheckNewVersionText3, MyCommon.GetReadableVersion(versionInfo.Version)); dialog.DetailsText = versionInfo.ReleaseNote; if (dialog.ShowDialog(this) == DialogResult.Yes) { await this.OpenUriAsync(versionInfo.DownloadUri.OriginalString); } } } catch (Exception) { this.StatusLabel.Text = Properties.Resources.CheckNewVersionText9; if (!startup) { MessageBox.Show(Properties.Resources.CheckNewVersionText10, MyCommon.ReplaceAppName(Properties.Resources.CheckNewVersionText2), MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2); } } }