Inheritance: Mono.Addins.Setup.Package
		public static AddinPackage PackageFromFile (string file)
		{
			AddinPackage pack = new AddinPackage ();
			pack.info = ReadAddinInfo (file);
			pack.packFile = file;
			return pack;
		}
Example #2
0
        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 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);
            }
            else
            {
                Console.WriteLine("No updates found.");
            }
        }
Example #4
0
        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 static AddinPackage PackageFromRepository (AddinRepositoryEntry repAddin)
		{
			AddinPackage pack = new AddinPackage ();
			pack.info = (AddinInfo) repAddin.Addin;
			pack.url = new Uri (new Uri (repAddin.RepositoryUrl), repAddin.Url).ToString ();
			return pack;
		}
Example #6
0
        public static AddinPackage FromInstalledAddin(Addin sinfo)
        {
            AddinPackage pack = new AddinPackage();

            pack.info = AddinInfo.ReadFromDescription(sinfo.Description);
            return(pack);
        }
Example #7
0
        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);
        }
Example #8
0
        public static AddinPackage PackageFromFile(string file)
        {
            AddinPackage pack = new AddinPackage();

            pack.info     = ReadAddinInfo(file);
            pack.packFile = file;
            return(pack);
        }
Example #9
0
        public static AddinPackage PackageFromRepository(AddinRepositoryEntry repAddin)
        {
            AddinPackage pack = new AddinPackage();

            pack.info = (AddinInfo)repAddin.Addin;
            pack.url  = new Uri(new Uri(repAddin.RepositoryUrl), repAddin.Url).ToString();
            return(pack);
        }
Example #10
0
 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));
 }
Example #11
0
        public override bool Equals(object ob)
        {
            AddinPackage ap = ob as AddinPackage;

            if (ap == null)
            {
                return(false);
            }
            return(ap.info.Id == info.Id && ap.info.Version == info.Version);
        }
Example #12
0
        internal override bool IsUpgradeOf(Package p)
        {
            AddinPackage ap = p as AddinPackage;

            if (ap == null)
            {
                return(false);
            }
            return(info.SupportsVersion(ap.info.Version));
        }
Example #13
0
        public bool Install(IProgressStatus statusMonitor, params AddinRepositoryEntry[] addins)
        {
            Package[] packages = new Package [addins.Length];
            for (int n = 0; n < addins.Length; n++)
            {
                packages [n] = AddinPackage.FromRepository(addins [n]);
            }

            return(Install(statusMonitor, packages));
        }
Example #14
0
        public bool Install(IProgressStatus statusMonitor, params string[] files)
        {
            Package[] packages = new Package [files.Length];
            for (int n = 0; n < files.Length; n++)
            {
                packages [n] = AddinPackage.FromFile(files [n]);
            }

            return(Install(statusMonitor, packages));
        }
Example #15
0
        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);
        }
        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);
        }
        void BuildRepository(IProgressMonitor monitor, Repository rootrep, string rootPath, string relFilePath, ArrayList allAddins)
        {
            DateTime lastModified = DateTime.MinValue;

            string mainFile = Path.Combine(rootPath, relFilePath);
            string mainPath = Path.GetDirectoryName(mainFile);

            Repository mainrep = (Repository)AddinStore.ReadObject(mainFile, typeof(Repository));

            if (mainrep == null)
            {
                mainrep = new Repository();
            }

            bool modified = false;

            monitor.Log.WriteLine("Checking directory: " + mainPath);
            foreach (string file in Directory.GetFiles(mainPath, "*.mpack"))
            {
                string fname = Path.GetFileName(file);
                PackageRepositoryEntry entry = (PackageRepositoryEntry)mainrep.FindEntry(fname);
                if (entry == null)
                {
                    entry = new PackageRepositoryEntry();
                    AddinPackage p = (AddinPackage)Package.FromFile(file);
                    entry.Addin = (AddinInfo)p.Addin;
                    entry.Url   = fname;
                    mainrep.AddEntry(entry);
                    modified = true;
                    monitor.Log.WriteLine("Added addin: " + fname);
                }
                allAddins.Add(entry);

                DateTime date = File.GetLastWriteTime(file);
                if (date > lastModified)
                {
                    lastModified = date;
                }
            }

            ArrayList toRemove = new ArrayList();

            foreach (PackageRepositoryEntry entry in mainrep.Addins)
            {
                if (!File.Exists(Path.Combine(mainPath, entry.Url)))
                {
                    toRemove.Add(entry);
                }
            }

            foreach (PackageRepositoryEntry entry in toRemove)
            {
                mainrep.RemoveEntry(entry);
            }

            if (modified || toRemove.Count > 0)
            {
                AddinStore.WriteObject(mainFile, mainrep);
                monitor.Log.WriteLine("Updated " + relFilePath);
            }

            ReferenceRepositoryEntry repEntry = (ReferenceRepositoryEntry)rootrep.FindEntry(relFilePath);

            if (repEntry != null)
            {
                if (repEntry.LastModified < lastModified)
                {
                    repEntry.LastModified = lastModified;
                }
            }
            else
            {
                repEntry = new ReferenceRepositoryEntry();
                repEntry.LastModified = lastModified;
                repEntry.Url          = relFilePath;
                rootrep.AddEntry(repEntry);
            }

            foreach (string dir in Directory.GetDirectories(mainPath))
            {
                string based = dir.Substring(rootPath.Length + 1);
                BuildRepository(monitor, rootrep, rootPath, Path.Combine(based, "main.mrep"), allAddins);
            }
        }
Example #18
0
        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);
        }
Example #19
0
        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);
        }
Example #20
0
        public void Uninstall(IProgressStatus statusMonitor, IEnumerable <string> ids)
        {
            IProgressMonitor monitor = ProgressStatusMonitor.GetProgressMonitor(statusMonitor);

            monitor.BeginTask("Uninstalling add-ins", ids.Count());

            foreach (string id in ids)
            {
                bool      rollback          = false;
                ArrayList toUninstall       = new ArrayList();
                ArrayList uninstallPrepared = new ArrayList();

                Addin ia = service.Registry.GetAddin(id);
                if (ia == null)
                {
                    throw new InstallException("The add-in '" + id + "' is not installed.");
                }

                toUninstall.Add(AddinPackage.FromInstalledAddin(ia));

                Addin[] deps = GetDependentAddins(id, true);
                foreach (Addin dep in deps)
                {
                    toUninstall.Add(AddinPackage.FromInstalledAddin(dep));
                }

                monitor.BeginTask("Deleting files", toUninstall.Count * 2 + uninstallPrepared.Count + 1);

                // Prepare install

                foreach (Package mpack in toUninstall)
                {
                    try
                    {
                        mpack.PrepareUninstall(monitor, this);
                        monitor.Step(1);
                        uninstallPrepared.Add(mpack);
                    }
                    catch (Exception ex)
                    {
                        ReportException(monitor, ex);
                        rollback = true;
                        break;
                    }
                }

                // Commit install

                if (!rollback)
                {
                    foreach (Package mpack in toUninstall)
                    {
                        try
                        {
                            mpack.CommitUninstall(monitor, this);
                            monitor.Step(1);
                        }
                        catch (Exception ex)
                        {
                            ReportException(monitor, ex);
                            rollback = true;
                            break;
                        }
                    }
                }

                // Rollback if failed

                if (rollback)
                {
                    monitor.BeginTask("Rolling back uninstall", uninstallPrepared.Count);
                    foreach (Package mpack in uninstallPrepared)
                    {
                        try
                        {
                            mpack.RollbackUninstall(monitor, this);
                        }
                        catch (Exception ex)
                        {
                            ReportException(monitor, ex);
                        }
                    }
                    monitor.EndTask();
                }
                monitor.Step(1);

                // Cleanup

                foreach (Package mpack in uninstallPrepared)
                {
                    try
                    {
                        mpack.EndUninstall(monitor, this);
                        monitor.Step(1);
                    }
                    catch (Exception ex)
                    {
                        monitor.Log.WriteLine(ex);
                    }
                }

                monitor.EndTask();
                monitor.Step(1);
            }

            // Update the extension maps
            service.Registry.Update(statusMonitor);

            monitor.EndTask();

            service.SaveConfiguration();
            ResetCachedData();
        }
Example #21
0
        void BuildRepository(IProgressMonitor monitor, Repository rootrep, string rootPath, string relFilePath, ArrayList allAddins)
        {
            DateTime lastModified = DateTime.MinValue;

            string mainFile       = Path.Combine(rootPath, relFilePath);
            string mainPath       = Path.GetDirectoryName(mainFile);
            string supportFileDir = Path.Combine(mainPath, addinFilesDir);

            if (File.Exists(mainFile))
            {
                lastModified = File.GetLastWriteTime(mainFile);
            }

            Repository mainrep = (Repository)AddinStore.ReadObject(mainFile, typeof(Repository));

            if (mainrep == null)
            {
                mainrep = new Repository();
            }

            ReferenceRepositoryEntry repEntry = (ReferenceRepositoryEntry)rootrep.FindEntry(relFilePath);
            DateTime rootLastModified         = repEntry != null ? repEntry.LastModified : DateTime.MinValue;

            bool modified = false;

            monitor.Log.WriteLine("Checking directory: " + mainPath);
            foreach (string file in Directory.GetFiles(mainPath, "*.mpack"))
            {
                DateTime date  = File.GetLastWriteTime(file);
                string   fname = Path.GetFileName(file);
                PackageRepositoryEntry entry = (PackageRepositoryEntry)mainrep.FindEntry(fname);

                if (entry != null && date > rootLastModified)
                {
                    mainrep.RemoveEntry(entry);
                    DeleteSupportFiles(supportFileDir, entry.Addin);
                    entry = null;
                }

                if (entry == null)
                {
                    entry = new PackageRepositoryEntry();
                    AddinPackage p = (AddinPackage)Package.FromFile(file);
                    entry.Addin = (AddinInfo)p.Addin;
                    entry.Url   = fname;
                    entry.Addin.Properties.SetPropertyValue("DownloadSize", new FileInfo(file).Length.ToString());
                    ExtractSupportFiles(supportFileDir, file, entry.Addin);
                    mainrep.AddEntry(entry);
                    modified = true;
                    monitor.Log.WriteLine("Added addin: " + fname);
                }
                allAddins.Add(entry);
            }

            ArrayList toRemove = new ArrayList();

            foreach (PackageRepositoryEntry entry in mainrep.Addins)
            {
                if (!File.Exists(Path.Combine(mainPath, entry.Url)))
                {
                    toRemove.Add(entry);
                    modified = true;
                }
            }

            foreach (PackageRepositoryEntry entry in toRemove)
            {
                DeleteSupportFiles(supportFileDir, entry.Addin);
                mainrep.RemoveEntry(entry);
            }

            if (modified)
            {
                AddinStore.WriteObject(mainFile, mainrep);
                monitor.Log.WriteLine("Updated " + relFilePath);
                lastModified = File.GetLastWriteTime(mainFile);
            }

            if (repEntry != null)
            {
                if (repEntry.LastModified < lastModified)
                {
                    repEntry.LastModified = lastModified;
                }
            }
            else if (modified)
            {
                repEntry = new ReferenceRepositoryEntry();
                repEntry.LastModified = lastModified;
                repEntry.Url          = relFilePath;
                rootrep.AddEntry(repEntry);
            }

            foreach (string dir in Directory.GetDirectories(mainPath))
            {
                if (Path.GetFileName(dir) == addinFilesDir)
                {
                    continue;
                }
                string based = dir.Substring(rootPath.Length + 1);
                BuildRepository(monitor, rootrep, rootPath, Path.Combine(based, "main.mrep"), allAddins);
            }
        }
Example #22
0
 /// <summary>
 /// Creates a package object for an add-in available in an on-line repository
 /// </summary>
 /// <param name="repAddin">
 /// An add-in reference
 /// </param>
 /// <returns>
 /// The package
 /// </returns>
 public static Package FromRepository(AddinRepositoryEntry repAddin)
 {
     return(AddinPackage.PackageFromRepository(repAddin));
 }
Example #23
0
 /// <summary>
 /// Creates a package object for a local package file
 /// </summary>
 /// <param name="file">
 /// Package file path
 /// </param>
 /// <returns>
 /// The package
 /// </returns>
 public static Package FromFile(string file)
 {
     return(AddinPackage.PackageFromFile(file));
 }
		public static AddinPackage FromInstalledAddin (Addin sinfo)
		{
			AddinPackage pack = new AddinPackage ();
			pack.info = AddinInfo.ReadFromDescription (sinfo.Description);
			return pack;
		}