Пример #1
0
        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 (currentVersion.Replace(".", "").CompareTo(MyCommon.fileVersion.Replace(".", "")) > 0)
            {
                string dialogText = string.Format(Properties.Resources.CheckNewVersionText3, MyCommon.GetReadableVersion(currentVersion));
                using (DialogAsShieldIcon dialog = new DialogAsShieldIcon())
                {
                    DialogResult ret = dialog.ShowDialog(this, dialogText, msgBody, MyCommon.ReplaceAppName(Properties.Resources.CheckNewVersionText1), MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (ret == DialogResult.Yes)
                    {
                        this.OpenUriAsync(downloadUrl);
                    }
                }
            }
            else
            {
                if (!startup)
                {
                    MessageBox.Show(Properties.Resources.CheckNewVersionText7 + MyCommon.GetReadableVersion() + Properties.Resources.CheckNewVersionText8 + MyCommon.GetReadableVersion(currentVersion), MyCommon.ReplaceAppName(Properties.Resources.CheckNewVersionText2), MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
Пример #2
0
        private void CheckNewVersion(bool startup = false)
        {
            string retMsg = "";
            string strVer = "";
            string strDetail = "";
            bool forceUpdate = MyCommon.IsKeyDown(Keys.Shift);

            try
            {
                retMsg = tw.GetVersionInfo();
            }
            catch (Exception)
            {
                StatusLabel.Text = Properties.Resources.CheckNewVersionText9;
                if (!startup) MessageBox.Show(Properties.Resources.CheckNewVersionText10, Properties.Resources.CheckNewVersionText2, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);
                return;
            }
            if (retMsg.Length > 0)
            {
                strVer = retMsg.Substring(0, 4);
                if (retMsg.Length > 4)
                {
                    strDetail = retMsg.Substring(5).Trim();
                }
                if (MyCommon.fileVersion != "" && strVer.CompareTo(MyCommon.fileVersion.Replace(".", "")) > 0)
                {
                    string tmp = string.Format(Properties.Resources.CheckNewVersionText3, strVer);
                    using (DialogAsShieldIcon dialogAsShieldicon = new DialogAsShieldIcon())
                    {
                        if (dialogAsShieldicon.ShowDialog(tmp, strDetail, Properties.Resources.CheckNewVersionText1, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            retMsg = tw.GetTweenBinary(strVer);
                            if (retMsg.Length == 0)
                            {
                                RunTweenUp();
                                MyCommon._endingFlag = true;
                                dialogAsShieldicon.Dispose();
                                this.Close();
                                return;
                            }
                            else
                            {
                                if (!startup) MessageBox.Show(Properties.Resources.CheckNewVersionText5 + System.Environment.NewLine + retMsg, Properties.Resources.CheckNewVersionText2, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                        }
                        dialogAsShieldicon.Dispose();
                    }
                }
                else
                {
                    if (forceUpdate)
                    {
                        string tmp = string.Format(Properties.Resources.CheckNewVersionText6, strVer);
                        using (DialogAsShieldIcon dialogAsShieldicon = new DialogAsShieldIcon())
                        {
                            if (dialogAsShieldicon.ShowDialog(tmp, strDetail, Properties.Resources.CheckNewVersionText1, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                            {
                                retMsg = tw.GetTweenBinary(strVer);
                                if (retMsg.Length == 0)
                                {
                                    RunTweenUp();
                                    MyCommon._endingFlag = true;
                                    dialogAsShieldicon.Dispose();
                                    this.Close();
                                    return;
                                }
                                else
                                {
                                    if (!startup) MessageBox.Show(Properties.Resources.CheckNewVersionText5 + System.Environment.NewLine + retMsg, Properties.Resources.CheckNewVersionText2, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                }
                            }
                            dialogAsShieldicon.Dispose();
                        }
                    }
                    else if (!startup)
                    {
                        MessageBox.Show(Properties.Resources.CheckNewVersionText7 + MyCommon.fileVersion.Replace(".", "") + Properties.Resources.CheckNewVersionText8 + strVer, Properties.Resources.CheckNewVersionText2, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            else
            {
                StatusLabel.Text = Properties.Resources.CheckNewVersionText9;
                if (!startup) MessageBox.Show(Properties.Resources.CheckNewVersionText10, Properties.Resources.CheckNewVersionText2, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }