/// <summary> /// Installs the plugin. /// </summary> /// <returns> /// The plugin. /// </returns> /// <param name='args'> /// Arguments. /// </param> public bool InstallPlugin(int ndx, out Dictionary<string, object> result) { Dictionary<string, object> res = new Dictionary<string, object>(); PackageCollection pack = new PackageCollection(); PackageCollection toUninstall; DependencyCollection unresolved; IProgressStatus ps = new ConsoleProgressStatus(false); AddinRepositoryEntry[] available = GetSortedAvailbleAddins(); if (ndx > (available.Length - 1)) { MainConsole.Instance.Output("Selection out of range"); result = res; return false; } AddinRepositoryEntry aentry = available[ndx]; Package p = Package.FromRepository(aentry); pack.Add(p); ResolveDependencies(ps, pack, out toUninstall, out unresolved); // Attempt to install the plugin disabled if (Install(ps, pack) == true) { MainConsole.Instance.Output("Ignore the following error..."); PluginRegistry.Update(ps); Addin addin = PluginRegistry.GetAddin(aentry.Addin.Id); PluginRegistry.DisableAddin(addin.Id); addin.Enabled = false; MainConsole.Instance.Output("Installation Success"); ListInstalledAddins(out res); result = res; return true; } else { MainConsole.Instance.Output("Installation Failed"); result = res; return false; } }
/// <summary> /// Resolves add-in dependencies. /// </summary> /// <param name="statusMonitor"> /// Progress monitor where to show progress status /// </param> /// <param name="addins"> /// List of add-ins to check /// </param> /// <param name="resolved"> /// Packages that need to be installed. /// </param> /// <param name="toUninstall"> /// Packages that need to be uninstalled. /// </param> /// <param name="unresolved"> /// Add-in dependencies that could not be resolved. /// </param> /// <returns> /// True if all dependencies could be resolved. /// </returns> /// <remarks> /// This method can be used to get a list of all packages that have to be installed in order to install /// an add-in or set of add-ins. The list of packages to install will include the package that provides the /// add-in, and all packages that provide the add-in dependencies. In some cases, packages may need to /// be installed (for example, when an installed add-in needs to be upgraded). /// </remarks> public bool ResolveDependencies(IProgressStatus statusMonitor, AddinRepositoryEntry[] addins, out PackageCollection resolved, out PackageCollection toUninstall, out DependencyCollection unresolved) { return(store.ResolveDependencies(statusMonitor, addins, out resolved, out toUninstall, out unresolved)); }
public bool ResolveDependencies(IProgressStatus statusMonitor, AddinRepositoryEntry[] addins, out PackageCollection resolved, out PackageCollection toUninstall, out DependencyCollection unresolved) { return store.ResolveDependencies (statusMonitor, addins, out resolved, out toUninstall, out unresolved); }
void Update(string [] args) { bool showAll = args.Length > 0 && args [0] == "-a"; Console.WriteLine ("Looking for updates..."); service.Repositories.UpdateAllRepositories (null); PackageCollection packs = new PackageCollection (); AddinRepositoryEntry[] addins = service.Repositories.GetAvailableAddins (); foreach (PackageRepositoryEntry addin in addins) { Addin sinfo = registry.GetAddin (addin.Addin.Id); if (!showAll && IsHidden (sinfo)) continue; if (sinfo != null && Addin.CompareVersions (sinfo.Version, addin.Addin.Version) == 1) packs.Add (AddinPackage.FromRepository (addin)); } if (packs.Count > 0) Install (packs, true); else Console.WriteLine ("No updates found."); }
void Install(string[] args) { if (args.Length < 1) { PrintHelp ("install"); return; } PackageCollection packs = new PackageCollection (); for (int n=0; n<args.Length; n++) { if (File.Exists (args [n])) { packs.Add (AddinPackage.FromFile (args [n])); } else { string aname = Addin.GetIdName (GetFullId (args[n])); string aversion = Addin.GetIdVersion (args[n]); if (aversion.Length == 0) aversion = null; AddinRepositoryEntry[] ads = service.Repositories.GetAvailableAddin (aname, aversion); if (ads.Length == 0) throw new InstallException ("The addin '" + args[n] + "' is not available for install."); packs.Add (AddinPackage.FromRepository (ads[ads.Length-1])); } } Install (packs, true); }
void FillSummaryPage () { PackageCollection packs = new PackageCollection (); if (filesToInstall != null) { foreach (string file in filesToInstall) { packs.Add (Package.FromFile (file)); } } else { foreach (AddinRepositoryEntry arep in addinsToInstall) { packs.Add (Package.FromRepository (arep)); } } packagesToInstall = new PackageCollection (packs); PackageCollection toUninstall; DependencyCollection unresolved; bool res; InstallMonitor m = new InstallMonitor (); res = service.ResolveDependencies (m, packs, out toUninstall, out unresolved); StringBuilder sb = new StringBuilder (); if (!res) { sb.Append ("<b><span foreground=\"red\">").Append (Catalog.GetString ("The selected add-ins can't be installed because there are dependency conflicts.")).Append ("</span></b>\n"); foreach (string s in m.Errors) { sb.Append ("<b><span foreground=\"red\">" + s + "</span></b>\n"); } sb.Append ("\n"); } if (m.Warnings.Count != 0) { foreach (string w in m.Warnings) { sb.Append ("<b><span foreground=\"red\">" + w + "</span></b>\n"); } sb.Append ("\n"); } sb.Append ("<b>").Append (Catalog.GetString ("The following packages will be installed:")).Append ("</b>\n\n"); foreach (Package p in packs) { sb.Append (p.Name); if (!p.SharedInstall) sb.Append (Catalog.GetString (" (in user directory)")); sb.Append ("\n"); } sb.Append ("\n"); if (toUninstall.Count > 0) { sb.Append ("<b>").Append (Catalog.GetString ("The following packages need to be uninstalled:")).Append ("</b>\n\n"); foreach (Package p in toUninstall) { sb.Append (p.Name + "\n"); } sb.Append ("\n"); } if (unresolved.Count > 0) { sb.Append ("<b>").Append (Catalog.GetString ("The following dependencies could not be resolved:")).Append ("</b>\n\n"); foreach (Dependency p in unresolved) { sb.Append (p.Name + "\n"); } sb.Append ("\n"); } buttonOk.Sensitive = res; ShowMessage (sb.ToString ()); }
internal abstract void Resolve (IProgressMonitor monitor, AddinStore service, PackageCollection toInstall, PackageCollection toUninstall, PackageCollection required, DependencyCollection unresolved);
public bool ResolveDependencies(IProgressStatus statusMonitor, PackageCollection packages, out PackageCollection toUninstall, out DependencyCollection unresolved) { IProgressMonitor monitor = ProgressStatusMonitor.GetProgressMonitor(statusMonitor); return(ResolveDependencies(monitor, packages, out toUninstall, out unresolved)); }
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(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); } }
public bool ResolveDependencies(IProgressStatus statusMonitor, AddinRepositoryEntry[] addins, out PackageCollection resolved, out PackageCollection toUninstall, out DependencyCollection unresolved) { resolved = new PackageCollection(); for (int n = 0; n < addins.Length; n++) { resolved.Add(AddinPackage.FromRepository(addins [n])); } return(ResolveDependencies(statusMonitor, resolved, out toUninstall, out unresolved)); }
public bool Install(IProgressStatus statusMonitor, PackageCollection packages) { return(store.Install(statusMonitor, packages)); }
public bool ResolveDependencies(IProgressStatus statusMonitor, PackageCollection packages, out PackageCollection toUninstall, out DependencyCollection unresolved) { return(store.ResolveDependencies(statusMonitor, packages, out toUninstall, out unresolved)); }
internal override void Resolve(IProgressMonitor monitor, AddinStore service, PackageCollection toInstall, PackageCollection toUninstall, PackageCollection required, DependencyCollection unresolved) { }
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; }
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 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 Install(IProgressStatus statusMonitor, PackageCollection packs) { // Make sure the registry is up to date service.Registry.Update(statusMonitor); IProgressMonitor monitor = ProgressStatusMonitor.GetProgressMonitor(statusMonitor); PackageCollection toUninstall; DependencyCollection unresolved; if (!ResolveDependencies(monitor, packs, out toUninstall, out unresolved)) { monitor.ReportError("Not all dependencies could be resolved.", null); return(false); } ArrayList prepared = new ArrayList(); ArrayList uninstallPrepared = new ArrayList(); bool rollback = false; monitor.BeginTask("Installing add-ins...", 100); // Prepare install monitor.BeginStepTask("Initializing installation", toUninstall.Count + packs.Count + 1, 75); foreach (Package mpack in toUninstall) { try { mpack.PrepareUninstall(monitor, this); uninstallPrepared.Add(mpack); if (monitor.IsCancelRequested) { throw new InstallException("Installation cancelled."); } monitor.Step(1); } catch (Exception ex) { ReportException(monitor, ex); rollback = true; break; } } monitor.Step(1); foreach (Package mpack in packs) { try { mpack.PrepareInstall(monitor, this); if (monitor.IsCancelRequested) { throw new InstallException("Installation cancelled."); } prepared.Add(mpack); monitor.Step(1); } catch (Exception ex) { ReportException(monitor, ex); rollback = true; break; } } monitor.EndTask(); monitor.BeginStepTask("Installing", toUninstall.Count + packs.Count + 1, 20); // Commit install if (!rollback) { foreach (Package mpack in toUninstall) { try { mpack.CommitUninstall(monitor, this); if (monitor.IsCancelRequested) { throw new InstallException("Installation cancelled."); } monitor.Step(1); } catch (Exception ex) { ReportException(monitor, ex); rollback = true; break; } } } monitor.Step(1); if (!rollback) { foreach (Package mpack in packs) { try { mpack.CommitInstall(monitor, this); if (monitor.IsCancelRequested) { throw new InstallException("Installation cancelled."); } monitor.Step(1); } catch (Exception ex) { ReportException(monitor, ex); rollback = true; break; } } } monitor.EndTask(); // Rollback if failed if (monitor.IsCancelRequested) { monitor = new NullProgressMonitor(); } if (rollback) { monitor.BeginStepTask("Finishing installation", (prepared.Count + uninstallPrepared.Count) * 2 + 1, 5); foreach (Package mpack in prepared) { try { mpack.RollbackInstall(monitor, this); monitor.Step(1); } catch (Exception ex) { ReportException(monitor, ex); } } foreach (Package mpack in uninstallPrepared) { try { mpack.RollbackUninstall(monitor, this); monitor.Step(1); } catch (Exception ex) { ReportException(monitor, ex); } } } else { monitor.BeginStepTask("Finishing installation", prepared.Count + uninstallPrepared.Count + 1, 5); } // Cleanup foreach (Package mpack in prepared) { try { mpack.EndInstall(monitor, this); monitor.Step(1); } catch (Exception ex) { monitor.Log.WriteLine(ex); } } monitor.Step(1); foreach (Package mpack in uninstallPrepared) { try { mpack.EndUninstall(monitor, this); monitor.Step(1); } catch (Exception ex) { monitor.Log.WriteLine(ex); } } // Update the extension maps service.Registry.Update(statusMonitor); monitor.EndTask(); monitor.EndTask(); service.SaveConfiguration(); ResetCachedData(); return(!rollback); }
void FillSummaryPage () { btnPrev.Sensitive = true; AddinHeader[] infos = tree.GetSelectedAddins (); PackageCollection packs = new PackageCollection (); foreach (AddinHeader info in infos) { AddinRepositoryEntry arep = (AddinRepositoryEntry) tree.GetAddinData (info); packs.Add (Package.FromRepository (arep)); } packagesToInstall = new PackageCollection (packs); PackageCollection toUninstall; DependencyCollection unresolved; bool res; InstallMonitor m = new InstallMonitor (); res = service.ResolveDependencies (m, packs, out toUninstall, out unresolved); StringBuilder sb = new StringBuilder (); if (!res) { sb.Append (Catalog.GetString ("<b><span foreground=\"red\">The selected add-ins can't be installed because there are dependency conflicts.</span></b>\n")); foreach (string s in m.Errors) { sb.Append (Catalog.GetString ("<b><span foreground=\"red\">" + s + "</span></b>\n")); } sb.Append ("\n"); } if (m.Warnings.Count != 0) { foreach (string w in m.Warnings) { sb.Append (Catalog.GetString ("<b><span foreground=\"red\">" + w + "</span></b>\n")); } sb.Append ("\n"); } sb.Append (Catalog.GetString ("<b>The following packages will be installed:</b>\n\n")); foreach (Package p in packs) { sb.Append (p.Name); if (!p.SharedInstall) sb.Append (Catalog.GetString (" (in user directory)")); sb.Append ("\n"); } sb.Append ("\n"); if (toUninstall.Count > 0) { sb.Append (Catalog.GetString ("<b>The following packages need to be uninstalled:</b>\n\n")); foreach (Package p in toUninstall) { sb.Append (p.Name + "\n"); } sb.Append ("\n"); } if (unresolved.Count > 0) { sb.Append (Catalog.GetString ("<b>The following dependencies could not be resolved:</b>\n\n")); foreach (Dependency p in unresolved) { sb.Append (p.Name + "\n"); } sb.Append ("\n"); } btnNext.Sensitive = res; labelSummary.Markup = sb.ToString (); }
void Install(string[] args) { bool prompt = !args.Any (a => a == "-y"); var addins = args.Where (a => a != "-y"); if (!addins.Any ()) { PrintHelp ("install"); return; } PackageCollection packs = new PackageCollection (); foreach (string arg in addins) { if (File.Exists (arg)) { packs.Add (AddinPackage.FromFile (arg)); } else { string aname = Addin.GetIdName (GetFullId (arg)); string aversion = Addin.GetIdVersion (arg); if (aversion.Length == 0) aversion = null; AddinRepositoryEntry[] ads = service.Repositories.GetAvailableAddin (aname, aversion); if (ads.Length == 0) throw new InstallException ("The addin '" + arg + "' is not available for install."); packs.Add (AddinPackage.FromRepository (ads[ads.Length-1])); } } Install (packs, prompt); }
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); } }
public bool ResolveDependencies(IProgressStatus statusMonitor, AddinRepositoryEntry[] addins, out PackageCollection resolved, out PackageCollection toUninstall, out DependencyCollection unresolved) { resolved = new PackageCollection (); for (int n=0; n<addins.Length; n++) resolved.Add (AddinPackage.FromRepository (addins [n])); return ResolveDependencies (statusMonitor, resolved, out toUninstall, out unresolved); }
void CheckInstall(string[] args) { if (args.Length < 1) { PrintHelp ("check-install"); return; } PackageCollection packs = new PackageCollection (); for (int n=0; n<args.Length; n++) { Addin addin = registry.GetAddin (GetFullId (args[n])); if (addin != null) continue; string aname = Addin.GetIdName (GetFullId (args[n])); string aversion = Addin.GetIdVersion (args[n]); if (aversion.Length == 0) aversion = null; AddinRepositoryEntry[] ads = service.Repositories.GetAvailableAddin (aname, aversion); if (ads.Length == 0) throw new InstallException ("The addin '" + args[n] + "' is not available for install."); packs.Add (AddinPackage.FromRepository (ads[ads.Length-1])); } Install (packs, false); }
public bool ResolveDependencies(IProgressStatus statusMonitor, PackageCollection packages, out PackageCollection toUninstall, out DependencyCollection unresolved) { IProgressMonitor monitor = ProgressStatusMonitor.GetProgressMonitor (statusMonitor); return ResolveDependencies (monitor, packages, out toUninstall, out unresolved); }
void Install(PackageCollection packs, bool prompt) { PackageCollection toUninstall; DependencyCollection unresolved; IProgressStatus m = new ConsoleProgressStatus (verbose); int n = packs.Count; if (!service.Store.ResolveDependencies (m, packs, out toUninstall, out unresolved)) throw new InstallException ("Not all dependencies could be resolved."); bool ask = false; if (prompt && (packs.Count != n || toUninstall.Count != 0)) { Console.WriteLine ("The following packages will be installed:"); foreach (Package p in packs) Console.WriteLine (" - " + p.Name); ask = true; } if (prompt && (toUninstall.Count != 0)) { Console.WriteLine ("The following packages need to be uninstalled:"); foreach (Package p in toUninstall) Console.WriteLine (" - " + p.Name); ask = true; } if (ask) { Console.WriteLine (); Console.Write ("Are you sure you want to continue? (y/N): "); string res = Console.ReadLine (); if (res != "y" && res != "Y") return; } if (!service.Store.Install (m, packs)) { Console.WriteLine ("Install operation failed."); } }
internal bool Install(IProgressStatus monitor, params Package[] packages) { PackageCollection packs = new PackageCollection (); packs.AddRange (packages); return Install (monitor, packs); }
public bool Install(IProgressStatus statusMonitor, PackageCollection packages) { return store.Install (statusMonitor, packages); }
internal bool Install(IProgressStatus statusMonitor, PackageCollection packs) { // Make sure the registry is up to date service.Registry.Update (statusMonitor); IProgressMonitor monitor = ProgressStatusMonitor.GetProgressMonitor (statusMonitor); PackageCollection toUninstall; DependencyCollection unresolved; if (!ResolveDependencies (monitor, packs, out toUninstall, out unresolved)) { monitor.ReportError ("Not all dependencies could be resolved.", null); return false; } ArrayList prepared = new ArrayList (); ArrayList uninstallPrepared = new ArrayList (); bool rollback = false; monitor.BeginTask ("Installing add-ins...", 100); // Prepare install monitor.BeginStepTask ("Initializing installation", toUninstall.Count + packs.Count + 1, 75); foreach (Package mpack in toUninstall) { try { mpack.PrepareUninstall (monitor, this); uninstallPrepared.Add (mpack); if (monitor.IsCancelRequested) throw new InstallException ("Installation cancelled."); monitor.Step (1); } catch (Exception ex) { monitor.ReportError (null, ex); rollback = true; break; } } monitor.Step (1); foreach (Package mpack in packs) { try { mpack.PrepareInstall (monitor, this); if (monitor.IsCancelRequested) throw new InstallException ("Installation cancelled."); prepared.Add (mpack); monitor.Step (1); } catch (Exception ex) { monitor.ReportError (null, ex); rollback = true; break; } } monitor.EndTask (); monitor.BeginStepTask ("Installing", toUninstall.Count + packs.Count + 1, 20); // Commit install if (!rollback) { foreach (Package mpack in toUninstall) { try { mpack.CommitUninstall (monitor, this); if (monitor.IsCancelRequested) throw new InstallException ("Installation cancelled."); monitor.Step (1); } catch (Exception ex) { monitor.ReportError (null, ex); rollback = true; break; } } } monitor.Step (1); if (!rollback) { foreach (Package mpack in packs) { try { mpack.CommitInstall (monitor, this); if (monitor.IsCancelRequested) throw new InstallException ("Installation cancelled."); monitor.Step (1); } catch (Exception ex) { monitor.ReportError (null, ex); rollback = true; break; } } } monitor.EndTask (); // Rollback if failed if (monitor.IsCancelRequested) monitor = new NullProgressMonitor (); if (rollback) { monitor.BeginStepTask ("Finishing installation", (prepared.Count + uninstallPrepared.Count)*2 + 1, 5); foreach (Package mpack in prepared) { try { mpack.RollbackInstall (monitor, this); monitor.Step (1); } catch (Exception ex) { monitor.ReportError (null, ex); } } foreach (Package mpack in uninstallPrepared) { try { mpack.RollbackUninstall (monitor, this); monitor.Step (1); } catch (Exception ex) { monitor.ReportError (null, ex); } } } else monitor.BeginStepTask ("Finishing installation", prepared.Count + uninstallPrepared.Count + 1, 5); // Cleanup foreach (Package mpack in prepared) { try { mpack.EndInstall (monitor, this); monitor.Step (1); } catch (Exception ex) { monitor.Log.WriteLine (ex); } } monitor.Step (1); foreach (Package mpack in uninstallPrepared) { try { mpack.EndUninstall (monitor, this); monitor.Step (1); } catch (Exception ex) { monitor.Log.WriteLine (ex); } } // Update the extension maps service.Registry.Update (statusMonitor); monitor.EndTask (); monitor.EndTask (); service.SaveConfiguration (); ResetCachedData (); return !rollback; }
public bool ResolveDependencies(IProgressStatus statusMonitor, PackageCollection packages, out PackageCollection toUninstall, out DependencyCollection unresolved) { return store.ResolveDependencies (statusMonitor, packages, out toUninstall, out unresolved); }
void Install (string[] args) { if (args.Length < 1) { PrintHelp ("install"); return; } PackageCollection packs = new PackageCollection (); for (int n=0; n<args.Length; n++) { if (File.Exists (args [n])) { packs.Add (AddinPackage.FromFile (args [n])); } else { string[] aname = args[n].Split ('/'); AddinRepositoryEntry[] ads = service.Repositories.GetAvailableAddin (aname[0], null); if (ads.Length == 0) throw new InstallException ("The addin '" + args[n] + "' is not available for install."); if (ads.Length > 1) { if (aname.Length < 2) { Console.WriteLine (args[n] + ": the addin version is required because there are several versions of the same addin available."); return; } ads = service.Repositories.GetAvailableAddin (aname[0], aname[1]); if (ads.Length == 0) throw new InstallException ("The addin " + aname[0] + " v" + aname[1] + " is not available."); } packs.Add (AddinPackage.FromRepository (ads[0])); } } Install (packs); }