コード例 #1
0
        private void updateButton_Click(object sender, EventArgs e)
        {
            updateButton.Enabled = false;
            cancelButton.Enabled = false;
            UpdateProgressWindow progressWindow = new UpdateProgressWindow(updater);

            progressWindow.Show();
            progressWindow.SetProgress(0, "Applying updates");
            Thread updateThread = new Thread(() => {
                UpdateInfo targetVersion = null;
                foreach (UpdateInfo cur in updateInfos)
                {
                    if (cur.version == appInfo.LatestVersion)
                    {
                        targetVersion = cur;
                    }
                }
                if (targetVersion == null)
                {
                    MessageBox.Show("Failed to retrieve update info for most recent update.");
                    this.Invoke((Action)(() => { this.Close(); }));
                    return;
                }
                updater.ApplyUpdate(appInfo, targetVersion, hostURL);
                this.Invoke((Action)(() => { this.Close(); }));
            });

            updateThread.Name         = "Update thread";
            updateThread.IsBackground = true;
            updateThread.Start();
        }
コード例 #2
0
        private void updateButton_Click(object sender, EventArgs e)
        {
            UpdateProgressWindow progressWindow = new UpdateProgressWindow(updater);

            progressWindow.Show();
            progressWindow.SetProgress(0, "Applying update");
            Thread updateThread = new Thread(() => {
                updater.ApplyUpdate(appInfo, updateInfo, updateHost);
                this.Invoke((Action)(() => { this.Close(); }));
            });

            updateThread.Name         = "Update thread";
            updateThread.IsBackground = true;
            updateThread.Start();
        }
コード例 #3
0
ファイル: Installer.cs プロジェクト: nbright/TheOpenLauncher
        public void InstallApplication(Action finishCallback)
        {
            if (!Directory.Exists(InstallationSettings.InstallationFolder))
            {
                Directory.CreateDirectory(InstallationSettings.InstallationFolder);
            }

            string lockFile = InstallationSettings.InstallationFolder + "/Updater.lock";

            if (System.IO.File.Exists(lockFile))
            {
                string message = "The chosen installation folder contains updater files. Installing in this folder may corrupt previous installations. Force installation?";
                if (MessageBox.Show(null, message, "Folder contains updater traces", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == System.Windows.Forms.DialogResult.Yes)
                {
                    System.IO.File.Delete(lockFile);
                }
                else
                {
                    Application.Exit();
                }
            }

            FileIndex newIndex = new FileIndex(LauncherSettings.AppID);

            newIndex.Serialize(InstallationSettings.InstallationFolder + "/UpdateIndex.dat");

            Updater updater = new Updater();
            UpdateProgressWindow progressWindow = new UpdateProgressWindow(updater);

            progressWindow.SetProgress(0, "Retrieving update info");
            updater.RetrieveAppInfo((appInfo, host) => {
                if (appInfo == null)
                {
                    MessageBox.Show(progressWindow, "Cannot install: No valid download mirrors online.", "Failed to install", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Application.Exit();
                }
                updater.RetrieveUpdateInfo(appInfo, host, appInfo.LatestVersion, (updateInfo, updateHost) => {
                    Action startUpdate = (() => {
                        if (updateInfo == null)
                        {
                            MessageBox.Show("No valid update info found.");
                            //TODO: Handle this. Should either search for new appInfo host or fail.
                        }
                        progressWindow.SetProgress(20, "Applying updates");
                        updater.ApplyUpdate(appInfo, updateInfo, updateHost);
                        progressWindow.SetProgress(90, "Registering installation");
                        try {
                            CreateUninstallRegistryEntry();
                            SetInstallationFolder(InstallationSettings.InstallationFolder);
                            if (InstallationSettings.CreateDesktopShortcut)
                            {
                                CreateDesktopShortcut();
                            }
                            if (InstallationSettings.CreateStartMenuEntry)
                            {
                                CreateStartMenuEntry();
                            }
                        } catch (Exception ex) {
                            MessageBox.Show(
                                "An exception occured while registering the application. \r\n" +
                                ex.Message +
                                "\r\nTo uninstall the application run the updater with -uninstall -forceInstallDir <installfolder>", "Error"
                                );
                        }

                        progressWindow.Invoke((Action)(() => { progressWindow.Close(); }));

                        InstallationFinishedForm finishedForm = new InstallationFinishedForm();
                        finishedForm.ShowDialog();
                        finishCallback.Invoke();
                    });
                    Thread updateThread       = new Thread(new ThreadStart(startUpdate));
                    updateThread.Name         = "Update thread";
                    updateThread.IsBackground = true;
                    updateThread.Start();
                });
            });
            progressWindow.Show();
        }