private PackageUpdateSchedule PrepareUpdateSchedule() { // Load existing update schedule in order to extend it string updateFilePath = this.env.UpdateFilePath; PackageUpdateSchedule updateSchedule = null; if (File.Exists(updateFilePath)) { try { updateSchedule = PackageUpdateSchedule.Load(updateFilePath); } catch (Exception exception) { updateSchedule = null; Logs.Editor.WriteError("Error parsing existing package update schedule '{0}': {1}", Path.GetFileName(updateFilePath), LogFormat.Exception(exception)); } } // If none existed yet, create a fresh update schedule if (updateSchedule == null) { updateSchedule = new PackageUpdateSchedule(); } return(updateSchedule); }
/// <summary> /// Loads an existing update schedule from the specified file path. /// </summary> /// <param name="updateFilePath"></param> /// <returns></returns> public static PackageUpdateSchedule Load(string updateFilePath) { PackageUpdateSchedule schedule = new PackageUpdateSchedule(); schedule.document = XDocument.Load(updateFilePath); return(schedule); }
private void manager_PackageInstalled(object sender, PackageOperationEventArgs e) { Logs.Editor.Write("Integrating install of package '{0} {1}'...", e.Package.Id, e.Package.Version); // Update package entries from local config PackageInfo packageInfo = this.GetPackage(new PackageName(e.Package.Id, e.Package.Version.Version)); if (packageInfo.IsDualityPackage) { this.setup.Packages.RemoveAll(p => p.Id == e.Package.Id); this.setup.Packages.Add(new LocalPackage(packageInfo)); this.setup.Save(this.env.ConfigFilePath); } // Schedule files for updating / copying PackageUpdateSchedule updateSchedule = this.PrepareUpdateSchedule(); Dictionary <string, string> fileMapping = this.CreateFileMapping(e.Package); foreach (var pair in fileMapping) { // Don't overwrite files from a newer version of this package with their old one (think of dependencies) bool isOldVersion = false; foreach (NuGet.IPackage localNugetPackage in this.manager.LocalRepository.GetPackages()) { if (localNugetPackage.Id != e.Package.Id) { continue; } Dictionary <string, string> localMapping = this.CreateFileMapping(localNugetPackage); if (localMapping.Any(p => string.Equals(p.Value, pair.Value, StringComparison.InvariantCultureIgnoreCase))) { if (localNugetPackage.Version > e.Package.Version) { isOldVersion = true; break; } } } if (isOldVersion) { continue; } // Append the scheduled operation to the updater config file. updateSchedule.AppendCopyFile(Path.Combine(e.InstallPath, pair.Value), pair.Key); if (Path.GetExtension(pair.Key) == ".csproj") { updateSchedule.AppendIntegrateProject( pair.Key, this.env.TargetSolutionPathRelative, this.env.TargetPluginPathRelative); } } this.SaveUpdateSchedule(updateSchedule); this.OnPackageInstalled(new PackageEventArgs(new PackageName(e.Package.Id, e.Package.Version.Version))); }
private void manager_PackageUninstalled(object sender, PackageOperationEventArgs e) { Logs.Editor.Write("Integrating uninstall of package '{0} {1}'...", e.Package.Id, e.Package.Version); // Determine all files that are referenced by a package, and the ones referenced by this one IEnumerable <string> localFiles = this.CreateFileMapping(e.Package).Select(p => p.Key); // Schedule files for removal PackageUpdateSchedule updateSchedule = this.PrepareUpdateSchedule(); foreach (var packageFile in localFiles) { // Don't remove any file that is still referenced by a local package bool stillInUse = false; foreach (NuGet.IPackage localNugetPackage in this.manager.LocalRepository.GetPackages()) { Dictionary <string, string> localMapping = this.CreateFileMapping(localNugetPackage); if (localMapping.Any(p => PathHelper.Equals(p.Key, packageFile))) { stillInUse = true; break; } } if (stillInUse) { continue; } // Append the scheduled operation to the updater config file. updateSchedule.AppendDeleteFile(packageFile); if (Path.GetExtension(packageFile) == ".csproj") { updateSchedule.AppendSeparateProject( packageFile, this.env.TargetSolutionPathRelative); } } this.SaveUpdateSchedule(updateSchedule); // Update local package configuration file PackageName packageName = new PackageName(e.Package.Id, e.Package.Version.Version); this.setup.Packages.RemoveAll(p => p.Name == packageName); this.setup.Save(this.env.ConfigFilePath); this.OnPackageUninstalled(new PackageEventArgs(new PackageName(e.Package.Id, e.Package.Version.Version))); }
/// <summary> /// Starts applying any pending package updates and returns true when it is required /// to shut down the current editor instance in order to complete them. /// </summary> /// <param name="restartEditor"> /// Whether the current editor instance should be restarted after the update has been applied. /// </param> /// <returns></returns> public bool ApplyUpdate(bool restartEditor = true) { if (!File.Exists(this.env.UpdateFilePath)) { return(false); } Logs.Editor.Write("Applying package update..."); Logs.Editor.PushIndent(); try { // Manually perform update operations on the updater itself try { Logs.Editor.Write("Preparing updater..."); PackageUpdateSchedule schedule = this.PrepareUpdateSchedule(); schedule.ApplyUpdaterChanges(this.env.UpdaterExecFilePath); this.SaveUpdateSchedule(schedule); } catch (Exception e) { Logs.Editor.WriteError( "Can't update '{0}', because an error occurred: {1}", this.env.UpdaterExecFilePath, LogFormat.Exception(e)); return(false); } // Run the updater application Logs.Editor.Write("Running updater..."); Process.Start(this.env.UpdaterExecFilePath, string.Format("\"{0}\" \"{1}\" \"{2}\"", this.env.UpdateFilePath, restartEditor ? typeof(DualityEditorApp).Assembly.Location : "", restartEditor ? Environment.CurrentDirectory : "")); } finally { Logs.Editor.PopIndent(); } return(true); }
private void SaveUpdateSchedule(PackageUpdateSchedule schedule) { string updateFilePath = this.env.UpdateFilePath; schedule.Save(updateFilePath); }