コード例 #1
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(SharpUpdateXml update, SharpUpdateLocalAppInfo 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;
            }

            SharpUpdateDownloadForm form   = new SharpUpdateDownloadForm(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);
            }
        }
コード例 #2
0
 /// <summary>
 /// Install all the updates
 /// </summary>
 private void InstallUpdate()
 {
     MessageBoxEx.Show(ParentForm, "Application restarts in 5 seconds", "Success", 5000);
     UpdateApplications();
     Application.Exit();
 }
コード例 #3
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 = (SharpUpdateXml[])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 SharpUpdateLocalAppInfo[Num_Jobs];
                    for (int i = 0; i < Num_Jobs; ++i)
                    {
                        if (Path.GetFileName(ParentPath).CompareTo(Path.GetFileName(JobsFromXML[i].FilePath)) == 0)
                        {
                            LocalApplicationInfos[i] = new SharpUpdateLocalAppInfo(JobsFromXML[i], ParentAssembly, ParentForm);
                        }
                        else
                        {
                            LocalApplicationInfos[i] = new SharpUpdateLocalAppInfo(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 SharpUpdateAcceptForm(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!");
            }
        }