コード例 #1
0
ファイル: MainForm.cs プロジェクト: rweichler/WebMConverter
        async void CheckUpdate()
        {
            if (!Properties.Settings.Default.SeenNotice)
            {
                try
                {
                    using (var noticeChecker = new WebClient())
                    {
                        const string caption = "Notice";
                        var result = await noticeChecker.DownloadStringTaskAsync(@"https://raw.githubusercontent.com/nixxquality/WebMConverter/master/NOTICE");
                        var urlAndMessage = result.Split(new[] { '\n' }, 2);
                        switch (MessageBox.Show(urlAndMessage[1], caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                        {
                            case DialogResult.Yes:
                                if (urlAndMessage[0].StartsWith("http")) // just in case someone hacks my anus, let's not give him any ways to execute arbitrary code on all my users
                                    System.Diagnostics.Process.Start(urlAndMessage[0]);

                                Application.Exit();
                                break;
                            case DialogResult.No:
                                Properties.Settings.Default.SeenNotice = true;
                                Properties.Settings.Default.Save();
                                break;
                        }
                    }
                }
                catch (Exception e)
                {
                    if (!e.Message.Contains("404"))
                    {
                        this.InvokeIfRequired(() =>
                        {
                            showToolTip("Update checking failed! " + e.Message, 2000);
                        });
                        return;
                    }
                }
            }

            try
            {
                var checker = new UpdateChecker("nixxquality", "WebMConverter");

                var update = await checker.CheckUpdate();

                if (update == UpdateType.None)
                {
                    this.InvokeIfRequired(() =>
                    {
                        showToolTip("Up to date!", 1000);
                    });
                }
                else
                {
                    this.InvokeIfRequired(() =>
                    {
                        var result = new UpdateNotifyDialog(checker).ShowDialog(this);
                        if (result == DialogResult.Yes)
                        {
                            checker.DownloadAsset("Converter.zip");
                            Application.Exit();
                        }
                    });
                }
            }
            catch (Exception e)
            {
                this.InvokeIfRequired(() =>
                {
                    showToolTip("Update checking failed! " + e.Message, 2000);
                });
            }
        }
コード例 #2
0
 private async Task<bool> CheckUpdate(bool silent)
 {
     try
     {
         UpdateChecker checker = new UpdateChecker("TKGP", "STALK-IRC");
         UpdateType update = await checker.CheckUpdate();
         if (update == UpdateType.Major || update == UpdateType.Minor)
         {
             this.Hide();
             timer1.Enabled = false;
             timer3.Enabled = false;
             AddGameMsg("Information", "A mandatory update to STALK-IRC is available! STALK-IRC is now disabled; check the client to update.");
             SystemSounds.Asterisk.Play();
             string notes = await checker.RenderReleaseNotes();
             DialogResult result = new UpdateForm(notes, silent, true).ShowDialog();
             if (result == DialogResult.Yes)
                 checker.DownloadAsset("STALK-IRC.exe");
             doClose = true;
             return true;
         }
         else if (!updateSkipped && update == UpdateType.Patch)
         {
             AddGameMsg("Information", "An optional update to STALK-IRC is available! Check the client to update.");
             SystemSounds.Asterisk.Play();
             string notes = await checker.RenderReleaseNotes();
             DialogResult result = new UpdateForm(notes, silent, false).ShowDialog();
             if (result == DialogResult.Yes)
             {
                 this.Hide();
                 timer1.Enabled = false;
                 timer3.Enabled = false;
                 checker.DownloadAsset("STALK-IRC.exe");
                 doClose = true;
             }
             else
                 updateSkipped = true;
         }
     }
     catch (Octokit.RateLimitExceededException)
     {
         // Woops
     }
     return false;
 }