Exemple #1
0
        bool UpdateTask(FormUpdating fu) //один сплошной говнокод
        {
            bool finished = false;

            using (var client = new WebClient())
            {
                client.DownloadProgressChanged += (s, e) =>
                {
                    fu.BeginInvoke((MethodInvoker) delegate {
                        fu.SetProgress(e.ProgressPercentage);
                    });
                };

                client.DownloadFileCompleted += (s, e) =>
                {
                    finished = true;
                };

                try
                {
                    client.DownloadFileAsync(new Uri(updateFrom + "dl"), "update.zip");

                    while (!finished)
                    {
                        Thread.Sleep(1000);
                    }
                    return(true);
                }
                catch (WebException)
                {
                    return(false);
                }
            }
        }
Exemple #2
0
        public async void Check()
        {
            mainForm.Text = mainFormCaption + " [" + MainForm.appLocalisationStrings["upd_checking"] + "...]";

            Task <string> task   = Task.Run(() => RequestStringTask("check"));
            string        actual = await task;

            FormUpdating fu = null;

            if (actual != "connection error")
            {
                if (actual != version)
                {
                    mainForm.Text = mainFormCaption + " [" + MainForm.appLocalisationStrings["upd_new"] + " " + actual + "!]";

                    DialogResult r = MessageBoxEx.Show(mainForm, MainForm.appLocalisationStrings["upd_update"] + " " + actual + "?", MainForm.appLocalisationStrings["upd_updateAvailable"],
                                                       MessageBoxButtons.OKCancel);

                    if (r == DialogResult.OK)
                    {
                        mainForm.Text = mainFormCaption + " [" + MainForm.appLocalisationStrings["upd_updTo"] + " " + actual + "...]";

                        fu = new FormUpdating();
                        fu.Show(mainForm);
                        fu.CenterAtParent(mainForm);
                        mainForm.Enabled = false;

                        task = Task.Run(() => RequestStringTask("changelog"));
                        string changelog = await task;

                        Console.WriteLine(changelog);

                        fu.SetChangelog(changelog);

                        Task <bool> dl      = Task.Run(() => UpdateTask(fu));
                        bool        success = await dl;

                        fu.SetFinished(success);
                        return;
                    }
                }
                else
                {
                    mainForm.Text = mainFormCaption;
                }
            }
            else
            {
                mainForm.Text = mainFormCaption;
            }

            mainForm.Enabled = true;
            if (fu != null)
            {
                fu.Close();
            }
        }