Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new SharpUpdateInfoForm
        /// </summary>
        internal QubedotUpdateInfoForm(QubedotUpdateLocalAppInfo applicationInfo, QubedotUpdateXml updateInfo)
        {
            InitializeComponent();

            // Sets the icon if it's not null
            if (applicationInfo.ApplicationIcon != null)
            {
                this.Icon = applicationInfo.ApplicationIcon;
            }

            // Fill in the UI
            this.Text             = applicationInfo.ApplicationName + " - Update Info";
            this.lblVersions.Text = updateInfo.Tag == JobType.UPDATE ?
                                    string.Format("Current Version: {0}\nUpdate version: {1}", applicationInfo.Version.ToString(), updateInfo.Version.ToString()) :
                                    (updateInfo.Tag == JobType.ADD ? string.Format("Version: {0}", updateInfo.Version.ToString()) :
                                     "");

            this.txtDescription.Text = updateInfo.Description;
        }
        /// <summary>
        /// Creates a new SharpUpdateAcceptForm
        /// </summary>
        /// <param name="applicationInfo"></param>
        /// <param name="updateInfo"></param>
        internal QubedotUpdateAcceptForm(QubedotUpdateLocalAppInfo applicationInfo, QubedotUpdateXml updateInfo, int num_cur_update, int num_total_update)
        {
            InitializeComponent();

            this.applicationInfo = applicationInfo;
            this.updateInfo      = updateInfo;

            this.Text = string.Format("{0} - ({1}/{2}) Available Update", this.applicationInfo.ApplicationName, num_cur_update, num_total_update);
            //this.lblUpdateAvail.Text = "An update for \"" + this.applicationInfo.ApplicationID + "\" is available.\r\nWould you like to update?";

            // Assigns the icon if it isn't null
            if (this.applicationInfo.ApplicationIcon != null)
            {
                this.Icon = this.applicationInfo.ApplicationIcon;
            }

            // Adds the update version # to the form
            this.lblNewVersion.Text = updateInfo.Tag != JobType.REMOVE ?
                                      string.Format(updateInfo.Tag == JobType.UPDATE ? "Update: {0}\nNew Version: {1}" : "New: {0}\nVersion: {1}", Path.GetFileName(this.applicationInfo.ApplicationPath), this.updateInfo.Version.ToString()) :
                                      string.Format("Remove: {0}", Path.GetFileName(this.applicationInfo.ApplicationPath));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Download the update
        /// </summary>
        /// <param name="update">The update xml info</param>
        /// <param name="applicationInfo">An SharpUpdateInfo object containing application's info</param>
        private void DownloadUpdate(QubedotUpdateXml update, QubedotUpdateLocalAppInfo applicationInfo)
        {
            if (update.Tag == JobType.REMOVE)
            {
                tempFilePaths.Add("");
                currentPaths.Add("");
                newPaths.Add(Path.GetFullPath(applicationInfo.ApplicationPath));
                launchArgss.Add(update.LaunchArgs);
                jobtypes.Add(update.Tag);
                return;
            }

            QubedotUpdateDownloadForm form = new QubedotUpdateDownloadForm(update.Uri, update.MD5, applicationInfo.ApplicationIcon);
            DialogResult result            = form.ShowDialog(applicationInfo.Context);

            if (result == DialogResult.OK)
            {
                string currentPath = (update.Tag == JobType.UPDATE) ? applicationInfo.ApplicationAssembly.Location : "";
                string newPath     = (update.Tag == JobType.UPDATE) ? Path.GetFullPath(Path.GetDirectoryName(currentPath).ToString() + update.FilePath) : Path.GetFullPath(applicationInfo.ApplicationPath);
                Directory.CreateDirectory(Path.GetDirectoryName(newPath));

                tempFilePaths.Add(form.TempFilePath);
                currentPaths.Add(currentPath);
                newPaths.Add(newPath);
                launchArgss.Add(update.LaunchArgs);
                jobtypes.Add(update.Tag);
            }
            else if (result == DialogResult.Abort)
            {
                MessageBoxEx.Show(ParentForm, "The update download was cancelled.\nThis program has not been modified.", "Update Download Cancelled", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBoxEx.Show(ParentForm, "There was a problem downloading the update.\nPlease try again later.", "Update Download Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// After the background worker is done, prompt to update if there is one
        /// </summary>
        private void BgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            // If there is a file on the server
            if (!e.Cancelled)
            {
                JobsFromXML = (QubedotUpdateXml[])e.Result;

                // Check if the update is not null and is a newer version than the current application
                if (JobsFromXML != null)
                {
                    Console.WriteLine("Number of updates from XML: " + JobsFromXML.Length);

                    // create local app info according to update xml
                    Num_Jobs = JobsFromXML.Length;
                    LocalApplicationInfos = new QubedotUpdateLocalAppInfo[Num_Jobs];
                    for (int i = 0; i < Num_Jobs; ++i)
                    {
                        if (Path.GetFileName(ParentPath).CompareTo(Path.GetFileName(JobsFromXML[i].FilePath)) == 0)
                        {
                            LocalApplicationInfos[i] = new QubedotUpdateLocalAppInfo(JobsFromXML[i], ParentAssembly, ParentForm);
                        }
                        else
                        {
                            LocalApplicationInfos[i] = new QubedotUpdateLocalAppInfo(JobsFromXML[i]);
                        }
                        LocalApplicationInfos[i].Print();
                    }

                    // validate all update jobs
                    List <int> validJobs = new List <int>();
                    for (int i = 0; i < Num_Jobs; ++i)
                    {
                        if (JobsFromXML[i].Tag == JobType.UPDATE)
                        {
                            if (!JobsFromXML[i].IsNewerThan(LocalApplicationInfos[i].Version))
                            {
                                continue;
                            }
                        }
                        validJobs.Add(i);
                    }

                    // let user choose to accept update jobs
                    bool showMsgBox = true;
                    int  count      = 0;
                    foreach (int i in validJobs)
                    {
                        count++;
                        showMsgBox = false;

                        // Ask to accept the update
                        if (new QubedotUpdateAcceptForm(LocalApplicationInfos[i], JobsFromXML[i], count, validJobs.Count).ShowDialog(LocalApplicationInfos[0].Context) == DialogResult.Yes)
                        {
                            acceptJobs++;
                            DownloadUpdate(JobsFromXML[i], LocalApplicationInfos[i]); // Do the update
                        }
                    }

                    if (showMsgBox)
                    {
                        MessageBoxEx.Show(ParentForm, "You have the latest versions already!");
                    }
                    else
                    {
                        if (acceptJobs > 0)
                        {
                            InstallUpdate();
                        }
                    }
                }
                else
                {
                    MessageBoxEx.Show(ParentForm, "You have the latest versions already!");
                }
            }
            else
            {
                MessageBoxEx.Show(ParentForm, "No update information found!");
            }
        }