internal override void Resolve(IProgressMonitor monitor, AddinStore service, PackageCollection toInstall, PackageCollection toUninstall, PackageCollection installedRequired, DependencyCollection unresolved) { Addin ia = service.Registry.GetAddin(Mono.Addins.Addin.GetIdName(info.Id)); if (ia != null) { Package p = AddinPackage.FromInstalledAddin(ia); if (!toUninstall.Contains(p)) { toUninstall.Add(p); } if (!info.SupportsVersion(ia.Version)) { // This addin breaks the api of the currently installed one, // it has to be removed, together with all dependencies Addin[] ainfos = service.GetDependentAddins(info.Id, true); foreach (Addin ainfo in ainfos) { p = AddinPackage.FromInstalledAddin(ainfo); if (!toUninstall.Contains(p)) { toUninstall.Add(p); } } } } foreach (Dependency dep in info.Dependencies) { service.ResolveDependency(monitor, dep, this, toInstall, toUninstall, installedRequired, unresolved); } }
internal void ResolveDependency(IProgressMonitor monitor, Dependency dep, AddinPackage parentPackage, PackageCollection toInstall, PackageCollection toUninstall, PackageCollection installedRequired, DependencyCollection unresolved) { AddinDependency adep = dep as AddinDependency; if (adep == null) { return; } string nsid = Addin.GetFullId(parentPackage.Addin.Namespace, adep.AddinId, null); foreach (Package p in toInstall) { AddinPackage ap = p as AddinPackage; if (ap != null) { if (Addin.GetIdName(ap.Addin.Id) == nsid && ((AddinInfo)ap.Addin).SupportsVersion(adep.Version)) { return; } } } ArrayList addins = new ArrayList(); addins.AddRange(service.Registry.GetAddins()); addins.AddRange(service.Registry.GetAddinRoots()); foreach (Addin addin in addins) { if (Addin.GetIdName(addin.Id) == nsid && addin.SupportsVersion(adep.Version)) { AddinPackage p = AddinPackage.FromInstalledAddin(addin); if (!installedRequired.Contains(p)) { installedRequired.Add(p); } return; } } AddinRepositoryEntry[] avaddins = service.Repositories.GetAvailableAddins(); foreach (PackageRepositoryEntry avAddin in avaddins) { if (Addin.GetIdName(avAddin.Addin.Id) == nsid && ((AddinInfo)avAddin.Addin).SupportsVersion(adep.Version)) { toInstall.Add(AddinPackage.FromRepository(avAddin)); return; } } unresolved.Add(adep); }
internal bool ResolveDependencies(IProgressMonitor monitor, PackageCollection packages, out PackageCollection toUninstall, out DependencyCollection unresolved) { PackageCollection requested = new PackageCollection(); requested.AddRange(packages); unresolved = new DependencyCollection(); toUninstall = new PackageCollection(); PackageCollection installedRequired = new PackageCollection(); for (int n = 0; n < packages.Count; n++) { Package p = packages [n]; p.Resolve(monitor, this, packages, toUninstall, installedRequired, unresolved); } if (unresolved.Count != 0) { foreach (Dependency dep in unresolved) { monitor.ReportError(string.Format("The package '{0}' could not be found in any repository", dep.Name), null); } return(false); } // Check that we are not uninstalling packages that are required // by packages being installed. foreach (Package p in installedRequired) { if (toUninstall.Contains(p)) { // Only accept to uninstall this package if we are // going to install a newer version. bool foundUpgrade = false; foreach (Package tbi in packages) { if (tbi.Equals(p) || tbi.IsUpgradeOf(p)) { foundUpgrade = true; break; } } if (!foundUpgrade) { return(false); } } } // Check that we are not trying to uninstall from a directory from // which we don't have write permissions foreach (Package p in toUninstall) { AddinPackage ap = p as AddinPackage; if (ap != null) { Addin ia = service.Registry.GetAddin(ap.Addin.Id); if (File.Exists(ia.AddinFile) && !HasWriteAccess(ia.AddinFile) && IsUserAddin(ia.AddinFile)) { monitor.ReportError(GetUninstallErrorNoRoot(ap.Addin), null); return(false); } } } // Check that we are not installing two versions of the same addin PackageCollection resolved = new PackageCollection(); resolved.AddRange(packages); bool error = false; for (int n = 0; n < packages.Count; n++) { AddinPackage ap = packages [n] as AddinPackage; if (ap == null) { continue; } for (int k = n + 1; k < packages.Count; k++) { AddinPackage otherap = packages [k] as AddinPackage; if (otherap == null) { continue; } if (ap.Addin.Id == otherap.Addin.Id) { if (ap.IsUpgradeOf(otherap)) { if (requested.Contains(otherap)) { monitor.ReportError("Can't install two versions of the same add-in: '" + ap.Addin.Name + "'.", null); error = true; } else { packages.RemoveAt(k); } } else if (otherap.IsUpgradeOf(ap)) { if (requested.Contains(ap)) { monitor.ReportError("Can't install two versions of the same add-in: '" + ap.Addin.Name + "'.", null); error = true; } else { packages.RemoveAt(n); n--; } } else { error = true; monitor.ReportError("Can't install two versions of the same add-in: '" + ap.Addin.Name + "'.", null); } break; } } } // Don't allow installing add-ins which are scheduled for uninstall foreach (Package p in packages) { AddinPackage ap = p as AddinPackage; if (ap != null && Registry.IsRegisteredForUninstall(ap.Addin.Id)) { error = true; monitor.ReportError("The addin " + ap.Addin.Name + " v" + ap.Addin.Version + " is scheduled for uninstallation. Please restart the application before trying to re-install it.", null); } } return(!error); }
internal override void Resolve (IProgressMonitor monitor, AddinStore service, PackageCollection toInstall, PackageCollection toUninstall, PackageCollection installedRequired, DependencyCollection unresolved) { Addin ia = service.Registry.GetAddin (info.Id); if (ia != null) { Package p = AddinPackage.FromInstalledAddin (ia); if (!toUninstall.Contains (p)) toUninstall.Add (p); if (!info.SupportsVersion (ia.Version)) { // This addin breaks the api of the currently installed one, // it has to be removed, together with all dependencies Addin[] ainfos = service.GetDependentAddins (info.Id, true); foreach (Addin ainfo in ainfos) { p = AddinPackage.FromInstalledAddin (ainfo); if (!toUninstall.Contains (p)) toUninstall.Add (p); } } } foreach (Dependency dep in info.Dependencies) { service.ResolveDependency (monitor, dep, this, toInstall, toUninstall, installedRequired, unresolved); } }
internal void ResolveDependency(IProgressMonitor monitor, Dependency dep, AddinPackage parentPackage, PackageCollection toInstall, PackageCollection toUninstall, PackageCollection installedRequired, DependencyCollection unresolved) { AddinDependency adep = dep as AddinDependency; if (adep == null) return; string nsid = Addin.GetFullId (parentPackage.Addin.Namespace, adep.AddinId, null); foreach (Package p in toInstall) { AddinPackage ap = p as AddinPackage; if (ap != null) { if (Addin.GetIdName (ap.Addin.Id) == nsid && ((AddinInfo)ap.Addin).SupportsVersion (adep.Version)) return; } } ArrayList addins = new ArrayList (); addins.AddRange (service.Registry.GetAddins ()); addins.AddRange (service.Registry.GetAddinRoots ()); foreach (Addin addin in addins) { if (Addin.GetIdName (addin.Id) == nsid && addin.SupportsVersion (adep.Version)) { AddinPackage p = AddinPackage.FromInstalledAddin (addin); if (!installedRequired.Contains (p)) installedRequired.Add (p); return; } } AddinRepositoryEntry[] avaddins = service.Repositories.GetAvailableAddins (); foreach (PackageRepositoryEntry avAddin in avaddins) { if (Addin.GetIdName (avAddin.Addin.Id) == nsid && ((AddinInfo)avAddin.Addin).SupportsVersion (adep.Version)) { toInstall.Add (AddinPackage.FromRepository (avAddin)); return; } } unresolved.Add (adep); }
internal bool ResolveDependencies(IProgressMonitor monitor, PackageCollection packages, out PackageCollection toUninstall, out DependencyCollection unresolved) { PackageCollection requested = new PackageCollection(); requested.AddRange (packages); unresolved = new DependencyCollection (); toUninstall = new PackageCollection (); PackageCollection installedRequired = new PackageCollection (); for (int n=0; n<packages.Count; n++) { Package p = packages [n]; p.Resolve (monitor, this, packages, toUninstall, installedRequired, unresolved); } if (unresolved.Count != 0) { foreach (Dependency dep in unresolved) monitor.ReportError (string.Format ("The package '{0}' could not be found in any repository", dep.Name), null); return false; } // Check that we are not uninstalling packages that are required // by packages being installed. foreach (Package p in installedRequired) { if (toUninstall.Contains (p)) { // Only accept to uninstall this package if we are // going to install a newer version. bool foundUpgrade = false; foreach (Package tbi in packages) if (tbi.Equals (p) || tbi.IsUpgradeOf (p)) { foundUpgrade = true; break; } if (!foundUpgrade) return false; } } // Check that we are not trying to uninstall from a directory from // which we don't have write permissions foreach (Package p in toUninstall) { AddinPackage ap = p as AddinPackage; if (ap != null) { Addin ia = service.Registry.GetAddin (ap.Addin.Id); if (File.Exists (ia.AddinFile) && !HasWriteAccess (ia.AddinFile)) { monitor.ReportError (GetUninstallErrorNoRoot (ap.Addin), null); return false; } } } // Check that we are not installing two versions of the same addin PackageCollection resolved = new PackageCollection(); resolved.AddRange (packages); bool error = false; for (int n=0; n<packages.Count; n++) { AddinPackage ap = packages [n] as AddinPackage; if (ap == null) continue; for (int k=n+1; k<packages.Count; k++) { AddinPackage otherap = packages [k] as AddinPackage; if (otherap == null) continue; if (ap.Addin.Id == otherap.Addin.Id) { if (ap.IsUpgradeOf (otherap)) { if (requested.Contains (otherap)) { monitor.ReportError ("Can't install two versions of the same add-in: '" + ap.Addin.Name + "'.", null); error = true; } else { packages.RemoveAt (k); } } else if (otherap.IsUpgradeOf (ap)) { if (requested.Contains (ap)) { monitor.ReportError ("Can't install two versions of the same add-in: '" + ap.Addin.Name + "'.", null); error = true; } else { packages.RemoveAt (n); n--; } } else { error = true; monitor.ReportError ("Can't install two versions of the same add-in: '" + ap.Addin.Name + "'.", null); } break; } } } return !error; }