Esempio n. 1
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);
            }
        }
Esempio n. 2
0
        void GenerateIndexPage(Repository rep, ArrayList addins, string basePath)
        {
            StreamWriter sw = new StreamWriter (Path.Combine (basePath, "index.html"));
            sw.WriteLine ("<html><body>");
            sw.WriteLine ("<h1>Add-in Repository</h1>");
            if (rep.Name != null && rep.Name != "")
                sw.WriteLine ("<h2>" + rep.Name + "</h2>");
            sw.WriteLine ("<p>This is a list of add-ins available in this repository.</p>");
            sw.WriteLine ("<table border=1><thead><tr><th>Add-in</th><th>Version</th><th>Description</th></tr></thead>");

            foreach (PackageRepositoryEntry entry in addins) {
                sw.WriteLine ("<tr><td>" + entry.Addin.Name + "</td><td>" + entry.Addin.Version + "</td><td>" + entry.Addin.Description + "</td></tr>");
            }

            sw.WriteLine ("</table>");
            sw.WriteLine ("</body></html>");
            sw.Close ();
        }
Esempio n. 3
0
        public void BuildRepository(IProgressStatus statusMonitor, string path)
        {
            string mainPath = Path.Combine (path, "main.mrep");
            ArrayList allAddins = new ArrayList ();

            Repository rootrep = (Repository) AddinStore.ReadObject (mainPath, typeof(Repository));
            if (rootrep == null) {
                rootrep = new Repository ();
            }

            IProgressMonitor monitor = ProgressStatusMonitor.GetProgressMonitor (statusMonitor);
            BuildRepository (monitor, rootrep, path, "root.mrep", allAddins);
            AddinStore.WriteObject (mainPath, rootrep);
            GenerateIndexPage (rootrep, allAddins, path);
            monitor.Log.WriteLine ("Updated main.mrep");
        }
Esempio n. 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);
            }
        }
Esempio n. 5
0
		internal void UpdateCachedRepository (Repository newRep)
		{
			newRep.url = Url;
			if (newRep.Name == null)
				newRep.Name = new Uri (Url).Host;
			AddinStore.WriteObject (File, newRep);
			if (name == null)
				name = newRep.Name;
			newRep.CachedFilesDir = CachedFilesDir;
		}
		internal RepositoryEntryCollection (Repository owner)
		{
			this.owner = owner;
		}
Esempio n. 7
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);
            }
        }