示例#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);
        }
示例#2
0
        private void LauncherForm_Load(object sender, EventArgs e)
        {
            //TODO -- maybe I want to thread this in the future to stop the UI freeze?
            //TODO -- 2 seconds doesn't seem too bad so far
            this._versionInfo = Helpers.GetVersionInfo();

            cmbServer.Items.AddRange(this._servers.Keys.ToArray());
            cmbServer.SelectedIndex = 0;

            var settings     = Helpers.LoadSettings();
            var serverOnline = this.CheckServerStatus(false);

            if (!settings.AutoPlay || ModifierKeys == Keys.Control ||
                (this._versionInfo != null && Version != this._versionInfo.Version))
            {
                return;
            }

            if (!serverOnline)
            {
                MessageBox.Show("Did not auto play because server is offline.");
                return;
            }

            this.WindowState   = FormWindowState.Minimized;
            this.ShowInTaskbar = false;

            this.Launch();
        }
示例#3
0
        }     //end LauncherForm_KeyDown

        private void updateChecker_DoWork(object sender, DoWorkEventArgs e)
        {
            var versionInfo      = Helpers.GetVersionInfo(this._config.VersionInfoUrl, this._config.PublicKey);
            var launcherKey      = Registry.CurrentUser.OpenSubKey(@"Software\" + this._config.KeyName, true);
            var lastUpdatedCheck = launcherKey.GetValue("LastUpdated");
            var updatesLastRun   = (int?)lastUpdatedCheck ?? 0;

            if (versionInfo == null)
            {
                return;
            }

            this._hasUpdates = versionInfo.Files.Any(b => b.Value > updatesLastRun);
        } //end updateChecker
示例#4
0
        public static bool HasUpdates(string expectedUpdaterChecksum, long lastUpdated, LauncherConfig config)
        {
            var appDataPath     = Directory.GetParent(Application.UserAppDataPath).ToString();
            var updaterLocation = Path.Combine(appDataPath, "Updater.exe");
            var updaterChecksum = Helpers.GetChecksum(updaterLocation);

            if (!File.Exists(updaterLocation) || updaterChecksum != expectedUpdaterChecksum)
            {
                return(true);
            }

            var versionInfo      = Helpers.GetVersionInfo(config.VersionInfoUrl, config.PublicKey);
            var launcherKey      = Registry.CurrentUser.OpenSubKey(@"Software\" + config.KeyName, true);
            var lastUpdatedCheck = launcherKey.GetValue("LastUpdated");
            var updatesLastRun   = (int?)lastUpdatedCheck ?? 0;

            if (updatesLastRun < lastUpdated)
            {
                return(true);
            }

            return(false);
        }
示例#5
0
        }     //end LauncherForm_KeyDown

        private void updateChecker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                var force            = e.Argument != null && (bool)e.Argument;
                var versionInfo      = Helpers.GetVersionInfo(this._config.VersionInfoUrl, this._config.PublicKey);
                var launcherKey      = Registry.CurrentUser.OpenSubKey(@"Software\" + this._config.KeyName, true);
                var lastUpdatedCheck = launcherKey.GetValue("LastUpdated");
                var updatesLastRun   = (int?)lastUpdatedCheck ?? 0;

                if (versionInfo == null)
                {
                    return;
                }

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

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

                var applicationPath = Application.ExecutablePath;
                var appDataPath     = Directory.GetParent(Application.UserAppDataPath).ToString();
                var updaterLocation = Path.Combine(appDataPath, "Updater.exe");
                var updaterChecksum = Helpers.GetChecksum(updaterLocation);

                if (!File.Exists(updaterLocation) || updaterChecksum != versionInfo.FileChecksums["Updater.exe"])
                {
                    using (var client = new WebClient())
                    {
                        client.DownloadProgressChanged += client_DownloadProgressChanged;
                        client.DownloadFileAsyncSync(new Uri(this._config.UpdaterUrl.ToString()),
                                                     updaterLocation);
                    }

                    this.updateChecker.ReportProgress(1);
                } //end if

                if (versionInfo.Version != Version)
                {
                    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(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

                if (versionInfo.LastUpdated < updatesLastRun && !force)
                {
                    return;
                }

                // checks for > 1 because the Updater.exe is always present.
                if (versionInfo.FileChecksums != null && versionInfo.FileChecksums.Count > 1)
                {
                    Helpers.SetControlPropertyThreadSafe(this.prgUpdates, "Maximum", versionInfo.FileChecksums.Count);

                    for (var i = 1; i < versionInfo.FileChecksums.Count; i++)
                    {
                        var file     = versionInfo.FileChecksums.ElementAt(i).Key;
                        var checksum = versionInfo.FileChecksums.ElementAt(i).Value;
                        var filePath = Path.Combine(this._config.InstallDir, file);

                        if (!File.Exists(filePath) || Helpers.GetChecksum(filePath) != checksum)
                        {
                            var extension = Path.GetExtension(file);
                            using (var client = new WebClient())
                            {
                                client.DownloadProgressChanged += client_DownloadProgressChanged;

                                if (File.Exists(filePath) && extension != null &&
                                    extension.Equals(".pak", StringComparison.CurrentCultureIgnoreCase) &&
                                    !file.Contains("zelgo"))
                                {
                                    var idxFile  = filePath.Replace(".pak", ".idx");
                                    var pakIndex = PakTools.RebuildPak(filePath, versionInfo.PakFiles[file], true);

                                    PakTools.RebuildIndex(idxFile, pakIndex, true);
                                }
                                else
                                {
                                    client.DownloadFileAsyncSync(
                                        new Uri(this._config.UpdaterFilesRoot + file.Replace("\\", "/")),
                                        filePath);
                                }
                            }
                        }

                        this.updateChecker.ReportProgress(i);
                    } //end for

                    var currentTime = DateTime.UtcNow - new DateTime(1970, 1, 1);
                    launcherKey.SetValue("LastUpdated", (int)currentTime.TotalSeconds, RegistryValueKind.DWord);

                    string versionName;
                    var    isWin8OrHigher = Helpers.IsWin8OrHigher(out versionName);

                    if (isWin8OrHigher && versionName == "Windows 10" && settings.ClientBin.ToLower() != "s3ep1u.bin")
                    {
                        settings.ClientBin = "S3EP1U.bin";
                        Helpers.SaveSettings(this._config.KeyName, settings, this._config.InstallDir, true);

                        MessageBox.Show(
                            "You're running Windows 10, but aren't using the S3EP1U.bin file. It has now been automatically set.\n\n" +
                            @"If you want to use the normal S3EP1.bin file, you can update it under Settings -> Client Settings.",
                            @"Windows 10 Detected",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
                    } //end if
                }     //end if
            }
            finally
            {
                this.updateChecker.ReportProgress(this.prgUpdates.Maximum);
            } //end try/finally
        }     //end updateChecker
示例#6
0
        private void updateChecker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                var 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 (versionInfo == null)
                {
                    return;
                }

                var applicationPath = Application.ExecutablePath;
                var appDataPath     = Directory.GetParent(Application.UserAppDataPath).ToString();
                var updaterLocation = Path.Combine(appDataPath, "Updater.exe");

                if (!File.Exists(updaterLocation) || versionInfo.Files["Updater.exe"] > updatesLastRun)
                {
                    using (var client = new WebClient())
                    {
                        client.DownloadProgressChanged += client_DownloadProgressChanged;
                        client.DownloadFileAsyncSync(new Uri(this._config.UpdaterUrl.ToString()),
                                                     updaterLocation);
                    }

                    this.updateChecker.ReportProgress(1);
                } //end if

                var filesToUpdate = versionInfo.Files.Where(b => (b.Value > updatesLastRun || force) &&
                                                            b.Key != "Updater.exe").ToList();
                // checks for > 1 because the Updater.exe is always present.
                if (filesToUpdate.Any())
                {
                    Helpers.SetControlPropertyThreadSafe(this.prgTotal, "Maximum", filesToUpdate.Count);

                    for (var i = 0; i < filesToUpdate.Count; i++)
                    {
                        var file     = filesToUpdate.ElementAt(i).Key;
                        var filePath = Path.Combine(this._config.InstallDir, file);

                        var extension = Path.GetExtension(file);
                        using (var client = new WebClient())
                        {
                            client.DownloadProgressChanged += client_DownloadProgressChanged;
                            client.DownloadFileAsyncSync(
                                new Uri(this._config.UpdaterFilesRoot + file.Replace("\\", "/")),
                                filePath);
                        }

                        this.updateChecker.ReportProgress(i);
                    } //end for

                    var currentTime = DateTime.UtcNow - new DateTime(1970, 1, 1);
                    launcherKey.SetValue("LastUpdated", (int)currentTime.TotalSeconds, RegistryValueKind.DWord);
                } //end if
            }
            finally
            {
                this.updateChecker.ReportProgress(this.prgTotal.Maximum);
            } //end try/finally
        }