示例#1
0
        private static void OnResponse(IAsyncResult ar)
        {
            var    versionRegex = new Regex(@"<meta\s+name\s*=\s*'ChapterTool'\s+content\s*=\s*'(\d+\.\d+\.\d+\.\d+)'\s*>", RegexOptions.Compiled);
            var    baseUrlRegex = new Regex(@"<meta\s+name\s*=\s*'BaseUrl'\s+content\s*=\s*'(.+)'\s*>", RegexOptions.Compiled);
            var    webRequest   = (WebRequest)ar.AsyncState;
            Stream responseStream;

            try
            {
                responseStream = webRequest.EndGetResponse(ar).GetResponseStream();
            }
            catch (Exception exception)
            {
                MessageBox.Show(
                    string.Format(
                        "检查更新失败, 错误信息:{0}{1}{0}请联系TC以了解详情",
                        Environment.NewLine, exception.Message), @"Update Check Fail");
                responseStream = null;
            }
            if (responseStream == null)
            {
                return;
            }

            var streamReader = new StreamReader(responseStream);
            var context      = streamReader.ReadToEnd();
            var result       = versionRegex.Match(context);
            var urlResult    = baseUrlRegex.Match(context);

            if (!result.Success || !result.Success)
            {
                return;
            }

            var currentVersion = Assembly.GetExecutingAssembly().GetName().Version;
            var remoteVersion  = Version.Parse(result.Groups[1].Value);

            if (currentVersion >= remoteVersion)
            {
                MessageBox.Show($"v{currentVersion} 已是最新版", @"As Expected");
                return;
            }
            var dialogResult = MessageBox.Show(
                caption: @"Wow! Such Impressive",
                text: $"新车已发车 v{remoteVersion},上车!",
                buttons: MessageBoxButtons.YesNo,
                icon: MessageBoxIcon.Asterisk);

            if (dialogResult != DialogResult.Yes)
            {
                return;
            }
            var formUpdater = new FormUpdater(Assembly.GetExecutingAssembly().Location, remoteVersion, urlResult.Groups[1].Value);

            formUpdater.ShowDialog();
        }
示例#2
0
        private void Changelog_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            FormUpdater formUpdater = new FormUpdater();

            formUpdater.Show();
        }
示例#3
0
        private void BtnTest_Click(object sender, EventArgs e)
        {
            var updaterForm = new FormUpdater();

            updaterForm.Show();
        }