Esempio n. 1
0
        private void configChecker_DoWork(object sender, DoWorkEventArgs e)
        {
            this._versionInfo = Helpers.GetVersionInfo(this._config.VersionInfoUrl, this._config.PublicKey);

            var force            = e.Argument != null && (bool)e.Argument;
            var launcherKey      = Registry.CurrentUser.OpenSubKey(@"Software\" + this._config.KeyName, true);
            var lastUpdatedCheck = launcherKey.GetValue("LastUpdated");
            var updatesLastRun   = (int?)lastUpdatedCheck ?? 0;

            if (this._versionInfo == null)
            {
                return;
            }

            var settings = Helpers.LoadSettings(this._config.KeyName);

            if (Helpers.UpdateConfig(this._versionInfo, settings.DisableServerUpdate))
            {
                MessageBox.Show("Configuration information was updated from the server.\n\nThe launcher will close. Please re-launch.",
                                @"Configuration Updated", MessageBoxButtons.OK, MessageBoxIcon.Information);

                this.Invoke((MethodInvoker) delegate
                {
                    this.Close();
                });
            }

            if (Helpers.StringToNumber(this._versionInfo.Version) > Helpers.StringToNumber(Version))
            {
                var applicationPath = Application.ExecutablePath;
                var appDataPath     = Directory.GetParent(Application.UserAppDataPath).ToString();
                var updaterLocation = Path.Combine(appDataPath, "Updater.exe");
                var updaterChecksum = Helpers.GetChecksum(updaterLocation);

                var result = DialogResult.Cancel;

                // push to the UI thread to actually display the dialog... ugly hack
                var dialog = this.BeginInvoke(new MethodInvoker(delegate
                {
                    result = new UpdateForm(this._versionInfo).ShowDialog();
                }));

                this.EndInvoke(dialog);

                if (result == DialogResult.OK)
                {
                    var info = new ProcessStartInfo(updaterLocation);
                    info.Arguments = "\"" + applicationPath + "\"";

                    if (Environment.OSVersion.Version.Major >= 6)
                    {
                        info.Verb = "runas";
                    }

                    Process.Start(info);
                } //end if
            }     //end if

            Helpers.SetControlPropertyThreadSafe(this.btnPlay, "Enabled", true);
        }