Esempio n. 1
0
        private async void updateBtn_Click(object sender, EventArgs e)
        {
            if (ProcessWatcher.IsGameRunning())
            {
                Notifications.PlayErrorSound();

                MaterialMessageBox.Show(null,
                                        "The game is active and running! Please close it if you wish to begin updating.", "CLOSE THE GAME",
                                        MessageBoxButtons.OK);

                return;
            }

            if (UpdateData.Version.Equals("1.3.0") && VRegistry.GetSubKeyValue("Version").Equals("1.2.0"))
            {
                Notifications.PlayNotificationSound2();

                var dialogResult = MaterialMessageBox.Show(null,
                                                           "Update 1.3.0 has a different file system organization and therefore previous update files must be removed.\n" +
                                                           "Would you like the client to delete a list of 1.2.0 files and begin installing 1.3.0?", "Important notice!", MessageBoxButtons.YesNo);

                if (dialogResult == DialogResult.Yes)
                {
                    Updater.RemoveOlderUpdate("1.2.0");
                }
                else
                {
                    CleanUpdateUi();
                    return;
                }
            }

            if (UpdateData.Version.Equals("1.4.0") && VRegistry.GetSubKeyValue("Version").Equals("1.3.0"))
            {
                Updater.RemoveOlderUpdate("1.3.0");
            }

            checkUpdatesBtn.Enabled = false;
            updateBtn.Enabled       = false;
            changePathBtn.Enabled   = false;

            if (File.Exists("data_" + UpdateData.Version + ".rar"))
            {
                Notifications.PlayNotificationSound2();
                var dialogResult = MaterialMessageBox.Show(null, "We've found already downloaded update package.\n\n" +
                                                           "The package might be corrupted / invalid." +
                                                           "Do you wish to install this package?",
                                                           "Package found", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2);

                if (dialogResult == DialogResult.Yes)
                {
                    versionAvailableLbl.Text = "installing the cached update ...";

                    var installCached = Task.Run(() => Updater.InstallUpdate());
                    await Task.WhenAll(installCached);

                    if (installCached.Result)
                    {
                        DisplayFinishedInstallUi();
                    }
                    else
                    {
                        CleanUpdateUi();

                        Notifications.PlayErrorSound();
                        FlashWindow(this.Handle, true);

                        return;
                    }

                    CleanupUpdate();

                    Analytics.TrackEvent("Cached update has been installed", new Dictionary <string, string>
                    {
                        { "Version", UpdateData.Version }
                    });
                }
                else
                {
                    DownloadUpdate();
                }
            }

            else
            {
                DownloadUpdate();
            }
        }