コード例 #1
0
ファイル: UpdateManager.cs プロジェクト: Flavio63/DDay.Update
        /// <summary>
        /// Saves deployment and application manifests
        /// to local directories for future reference.
        /// </summary>
        static private void SaveLocalManifests()
        {
            if (DeploymentManifest != null)
            {
                // Get the path where the application manifest should reside...
                Assembly assembly = Assembly.GetExecutingAssembly();

                // Load the application manifest
                DeploymentManifest.LoadApplicationManifest();

                // Save the local application manifest also
                DeploymentManifest.ApplicationManifest.Save(ApplicationDestinationPath);

                // Update information in the deployment manifest to reflect
                // the new location of the application manifest.
                foreach (DependentAssembly da in DeploymentManifest.DependentAssemblies)
                {
                    // The deployment manifest should have a single dependent assembly -
                    // the application manifest

                    // Set new information about the application manifest
                    FileInfo fi = new FileInfo(Path.GetFullPath(ApplicationDestinationPath));

                    // Set the codebase for the application to the new version
                    // NOTE: this fixes bug #2001838 - deployment.manifest uses absolute paths
                    da.CodeBase = ApplicationDestinationRelativePath;
                    da.Size     = fi.Length;
                }

                // Save the deployment manifest
                DeploymentManifest.Save(LocalDeploymentManifestPath);

                // Get a new local deployment manifest
                LoadLocalDeploymentManifest();
            }
        }
コード例 #2
0
ファイル: UpdateManager.cs プロジェクト: Flavio63/DDay.Update
        static public ApplicationManifest GetCurrentApplicationManifest()
        {
            ApplicationManifest appManifest = null;

            DDayUpdateConfigurationSection cfg = ConfigurationManager.GetSection("DDay.Update")
                                                 as DDayUpdateConfigurationSection;

            // Try to load a local deployment manifest
            if (LocalDeploymentManifest == null)
            {
                LoadLocalDeploymentManifest();
            }

            DeploymentManifest deploymentManifest = LocalDeploymentManifest ?? DeploymentManifest;

            // Try to retrieve the application manifest from the
            // deployment manifest.
            if (deploymentManifest != null)
            {
                // Load the deployment manifest, if we haven't done so already!
                log.Debug("Loading application manifest from deployment manifest...");
                try
                {
                    deploymentManifest.LoadApplicationManifest();
                    appManifest = deploymentManifest.ApplicationManifest;
                    log.Debug("Loaded.");
                }
                catch
                {
                }
            }

            // If we haven't found an application manifest yet, then let's try to load
            // it from a previous version!
            if (appManifest == null)
            {
                log.Debug("The application manifest could not be located; searching previous versions...");
                if (cfg != null)
                {
                    Version[] localVersions = cfg.VersionManager.LocalVersions;

                    if (localVersions.Length > 0)
                    {
                        for (int i = 0; i < localVersions.Length; i++)
                        {
                            log.Debug("Searching version '" + localVersions[i] + "'...");

                            // Try to load an application manifest
                            // from this version!
                            try
                            {
                                string directory = Path.Combine(VersionRepositoryFolder, localVersions[i].ToString());
                                Uri    uri       = new Uri(
                                    Path.Combine(
                                        directory,
                                        LocalApplicationManifestFilename
                                        )
                                    );

                                log.Debug("Attempting to load manifest from '" + uri.AbsolutePath + "'...");

                                // Get the application manifest
                                appManifest = new ApplicationManifest(uri);
                            }
                            catch { }

                            // If we found an application manifest, then check to see
                            // if the application name matches our bootstrap executable
                            // name.  If it doesn't, then we're looking at a version
                            // of a *different* application, and should ignore it!
                            if (appManifest.EntryPoint != null &&
                                appManifest.EntryPoint.AssemblyIdentity != null &&
                                appManifest.EntryPoint.AssemblyIdentity.Name != null)
                            {
                                string manifestName = appManifest.EntryPoint.AssemblyIdentity.Name;
                                string appName      = Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location);
                                if (!object.Equals(manifestName, appName))
                                {
                                    log.Debug("The application manifest for application '" + manifestName + "' was found and ignored (looking for '" + appName + "')");
                                    appManifest = null;
                                }
                            }

                            // We found an application manifest that we can use!
                            if (appManifest != null)
                            {
                                log.Debug("Application manifest found!");
                                break;
                            }
                        }
                    }
                }
            }

            return(appManifest);
        }
コード例 #3
0
        /// <summary>
        /// Downloads updated versions of each file that is outdated.
        /// </summary>
        /// <exception cref="DeploymentManifestException">
        /// if the deployment manifest has not yet been loaded
        /// </exception>
        private bool UpdateFiles()
        {
            // Ensure the deployment manifest has been loaded
            if (DeploymentManifest == null)
            {
                throw new DeploymentManifestException();
            }

            // First, load the application manifest from the deployment manifest
            DeploymentManifest.LoadApplicationManifest();

            // Start a list of file downloaders the will be obtained from
            // the application manifest.
            _FileDownloaders = new List <FileDownloader>();
            _Saved           = new List <FileDownloader>();

            // Then, iterate through each downloadable file, determine if
            // an update is required for it, and download a new version
            // if necessary.
            foreach (IDownloadableFile file in
                     DeploymentManifest.ApplicationManifest.DownloadableFiles)
            {
                FileDownloader download = file.GetDownloader();
                download.Completed += new EventHandler(download_Completed);
                download.Cancelled += new EventHandler(download_Cancelled);
                download.Error     += new EventHandler <ExceptionEventArgs>(download_Error);
                download.Saved     += new EventHandler(download_Saved);

                log.Debug("Retrieved a downloader for '" + download.DestinationName + "'...");
                _FileDownloaders.Add(download);
            }

            log.Debug("Determining total download size...");

            // Determine the file patterns that are preserved (never overwritten)
            // during the update process...
            List <string> preservedPatterns    = new List <string>();
            DDayUpdateConfigurationSection cfg = ConfigurationManager.GetSection("DDay.Update")
                                                 as DDayUpdateConfigurationSection;

            if (cfg != null)
            {
                foreach (KeyValuePairConfigurationElement kvpe in cfg.Preserve)
                {
                    if (!string.IsNullOrEmpty(kvpe.Value))
                    {
                        preservedPatterns.Add(kvpe.Value);
                    }
                }
            }

            // Determine the preserved status of each file downloader.
            // Preserved files will not be downloaded
            foreach (FileDownloader downloader in _FileDownloaders)
            {
                downloader.DeterminePreservedStatus(preservedPatterns.ToArray());
            }

            // Determine the total size in bytes of updates to be made
            long totalSize = 0;

            foreach (FileDownloader downloader in _FileDownloaders)
            {
                totalSize += downloader.DownloadSize;
            }

            log.Debug("Total download size is " + totalSize + " bytes; notifying GUI...");

            // Notify of the total update size in bytes
            if (UpdateNotifier != null)
            {
                UpdateNotifier.NotifyTotalUpdateSize(totalSize);
            }

            // Setup an event to synchronize with...
            _DownloadEvent = new AutoResetEvent(false);

            log.Debug("Downloading each file to be updated...");

            // Download each file
            foreach (FileDownloader downloader in _FileDownloaders)
            {
                if (!CancelledOrError)
                {
                    // Download the new copy of the file
                    downloader.Download(UpdateNotifier);

                    // Wait for the item to be downloaded
                    _DownloadEvent.WaitOne();
                }
                else
                {
                    break;
                }
            }

            log.Info("File downloads finished.");
            return(true);
        }