Inheritance: Mono.Addins.Setup.RepositoryEntry, AddinRepositoryEntry, IComparable
Example #1
0
        void FilterOldVersions(List <PackageRepositoryEntry> addins)
        {
            Dictionary <string, string> versions = new Dictionary <string, string> ();

            foreach (PackageRepositoryEntry a in addins)
            {
                string last;
                string id, version;
                Addin.GetIdParts(a.Addin.Id, out id, out version);
                if (!versions.TryGetValue(id, out last) || Addin.CompareVersions(last, version) > 0)
                {
                    versions [id] = version;
                }
            }
            for (int n = 0; n < addins.Count; n++)
            {
                PackageRepositoryEntry a = addins [n];
                string id, version;
                Addin.GetIdParts(a.Addin.Id, out id, out version);
                if (versions [id] != version)
                {
                    addins.RemoveAt(n--);
                }
            }
        }
Example #2
0
        public int CompareTo(object other)
        {
            PackageRepositoryEntry rep = (PackageRepositoryEntry)other;
            string n1 = Mono.Addins.Addin.GetIdName(Addin.Id);
            string n2 = Mono.Addins.Addin.GetIdName(rep.Addin.Id);

            if (n1 != n2)
            {
                return(n1.CompareTo(n2));
            }
            else
            {
                return(Mono.Addins.Addin.CompareVersions(rep.Addin.Version, Addin.Version));
            }
        }
Example #3
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);

            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 #4
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 #5
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);
            }
        }
        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);
            }
        }