Beispiel #1
0
        void Check(object sender, EventArgs e)
        {
            UpdateChecker checker;
            if (ProductVersion.Checked)
            {
                checker = new UpdateChecker(User.Text, Repo.Text);
            }
            else
            {
                checker = new UpdateChecker(User.Text, Repo.Text, Version.Text);
            }

            ((Button)sender).Enabled = false;
            checker.CheckUpdate(locked: (UpdateType)Lock.SelectedIndex).ContinueWith(continuation =>
            {
                // if (continuation.Result == UpdateType.None)
                //    return;

                Invoke(new Action(() => // Go back to the UI thread
                {
                    ((Button)sender).Enabled = true;
                    if (continuation.Result != UpdateType.None)
                    {
                        var result = new UpdateNotifyDialog(checker).ShowDialog();
                        if (result == DialogResult.Yes)
                        {
                            checker.DownloadAsset(Asset.Text);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Up to date!");
                    }
                }));
            });
        }
Beispiel #2
0
        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);
                });
            }
        }