상속: AddinHeader
예제 #1
0
        public static AddinInfo ReadFromAddinFile(StreamReader r)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(r);
            r.Close();

            AddinInfo info = new AddinInfo();

            info.id       = doc.DocumentElement.GetAttribute("id");
            info.namspace = doc.DocumentElement.GetAttribute("namespace");
            info.name     = doc.DocumentElement.GetAttribute("name");
            if (info.id == "")
            {
                info.id = info.name;
            }
            info.version     = doc.DocumentElement.GetAttribute("version");
            info.author      = doc.DocumentElement.GetAttribute("author");
            info.copyright   = doc.DocumentElement.GetAttribute("copyright");
            info.url         = doc.DocumentElement.GetAttribute("url");
            info.description = doc.DocumentElement.GetAttribute("description");
            info.category    = doc.DocumentElement.GetAttribute("category");
            info.baseVersion = doc.DocumentElement.GetAttribute("compatVersion");
            AddinPropertyCollectionImpl props = new AddinPropertyCollectionImpl();

            info.properties = props;
            ReadHeader(info, props, doc.DocumentElement);
            ReadDependencies(info.Dependencies, info.OptionalDependencies, doc.DocumentElement);
            return(info);
        }
예제 #2
0
        void ExtractSupportFiles(string targetDir, string file, AddinInfo ainfo)
        {
            Random  r     = new Random();
            ZipFile zfile = new ZipFile(file);

            foreach (var prop in ainfo.Properties)
            {
                ZipEntry ze = zfile.GetEntry(prop.Value);
                if (ze != null)
                {
                    string fname;
                    do
                    {
                        fname = Path.Combine(targetDir, r.Next().ToString("x") + Path.GetExtension(prop.Value));
                    } while (File.Exists(fname));

                    if (!Directory.Exists(targetDir))
                    {
                        Directory.CreateDirectory(targetDir);
                    }

                    using (var f = File.OpenWrite(fname)) {
                        using (Stream s = zfile.GetInputStream(ze)) {
                            byte[] buffer = new byte [8092];
                            int    nr     = 0;
                            while ((nr = s.Read(buffer, 0, buffer.Length)) > 0)
                            {
                                f.Write(buffer, 0, nr);
                            }
                        }
                    }
                    prop.Value = Path.Combine(addinFilesDir, Path.GetFileName(fname));
                }
            }
        }
예제 #3
0
        public static AddinPackage FromInstalledAddin(Addin sinfo)
        {
            AddinPackage pack = new AddinPackage();

            pack.info = AddinInfo.ReadFromDescription(sinfo.Description);
            return(pack);
        }
예제 #4
0
        internal static AddinInfo ReadFromDescription(AddinDescription description)
        {
            AddinInfo info = new AddinInfo();

            info.id          = description.LocalId;
            info.namspace    = description.Namespace;
            info.name        = description.Name;
            info.version     = description.Version;
            info.author      = description.Author;
            info.copyright   = description.Copyright;
            info.url         = description.Url;
            info.description = description.Description;
            info.category    = description.Category;
            info.baseVersion = description.CompatVersion;
            info.properties  = new AddinPropertyCollectionImpl(description.Properties);

            foreach (Dependency dep in description.MainModule.Dependencies)
            {
                info.Dependencies.Add(dep);
            }

            foreach (ModuleDescription mod in description.OptionalModules)
            {
                foreach (Dependency dep in mod.Dependencies)
                {
                    info.OptionalDependencies.Add(dep);
                }
            }
            return(info);
        }
예제 #5
0
        internal void RegisterAddin(IProgressMonitor monitor, AddinInfo info, string sourceDir)
        {
            monitor.Log.WriteLine("Installing " + info.Name + " v" + info.Version);
            string addinDir = GetAddinDirectory(info);

            if (!Directory.Exists(addinDir))
            {
                Directory.CreateDirectory(addinDir);
            }
            CopyDirectory(sourceDir, addinDir);

            ResetCachedData();
        }
예제 #6
0
        static AddinInfo ReadAddinInfo(string file)
        {
            ZipFile zfile = new ZipFile(file);

            foreach (ZipEntry ze in zfile)
            {
                if (ze.Name == "addin.info")
                {
                    using (Stream s = zfile.GetInputStream(ze)) {
                        return(AddinInfo.ReadFromAddinFile(new StreamReader(s)));
                    }
                }
            }
            throw new InstallException("Addin configuration file not found in package.");
        }
        static void ReadHeader(AddinInfo info, AddinPropertyCollectionImpl properties, XmlElement elem)
        {
            elem = elem.SelectSingleNode("Header") as XmlElement;
            if (elem == null)
            {
                return;
            }
            foreach (XmlNode xprop in elem.ChildNodes)
            {
                XmlElement prop = xprop as XmlElement;
                if (prop != null)
                {
                    switch (prop.LocalName)
                    {
                    case "Id":
                        info.id = prop.InnerText;
                        break;

                    case "Namespace":
                        info.namspace = prop.InnerText;
                        break;

                    case "Version":
                        info.version = prop.InnerText;
                        break;

                    case "CompatVersion":
                        info.baseVersion = prop.InnerText;
                        break;

                    default:
                    {
                        AddinProperty aprop = new AddinProperty();
                        aprop.Name = prop.LocalName;
                        if (prop.HasAttribute("locale"))
                        {
                            aprop.Locale = prop.GetAttribute("locale");
                        }
                        aprop.Value = prop.InnerText;
                        properties.Add(aprop);
                        break;
                    }
                    }
                }
            }
        }
예제 #8
0
 void DeleteSupportFiles(string targetDir, AddinInfo ainfo)
 {
     foreach (var prop in ainfo.Properties)
     {
         if (prop.Value.StartsWith(addinFilesDir + Path.DirectorySeparatorChar))
         {
             string file = Path.Combine(targetDir, Path.GetFileName(prop.Value));
             if (File.Exists(file))
             {
                 File.Delete(file);
             }
         }
     }
     if (Directory.Exists(targetDir) && Directory.GetFileSystemEntries(targetDir).Length == 0)
     {
         Directory.Delete(targetDir, true);
     }
 }
예제 #9
0
 internal string GetAddinDirectory(AddinInfo info)
 {
     return(Path.Combine(service.InstallDirectory, info.Id.Replace(',', '.')));
 }
예제 #10
0
 /// <summary>
 /// Gets information about an add-in
 /// </summary>
 /// <param name="addin">
 /// The add-in
 /// </param>
 /// <returns>
 /// Add-in header data
 /// </returns>
 public static AddinHeader GetAddinHeader(Addin addin)
 {
     return(AddinInfo.ReadFromDescription(addin.Description));
 }
예제 #11
0
 void DeleteSupportFiles(string targetDir, AddinInfo ainfo)
 {
     foreach (var prop in ainfo.Properties) {
         if (prop.Value.StartsWith (addinFilesDir + Path.DirectorySeparatorChar)) {
             string file = Path.Combine (targetDir, Path.GetFileName (prop.Value));
             if (File.Exists (file))
                 File.Delete (file);
         }
     }
     if (Directory.Exists (targetDir) && Directory.GetFileSystemEntries (targetDir).Length == 0)
         Directory.Delete (targetDir, true);
 }
 public void Add(AddinInfo p)
 {
     List.Add(p);
 }
예제 #13
0
		static void ReadHeader (AddinInfo info, AddinPropertyCollectionImpl properties, XmlElement elem)
		{
			elem = elem.SelectSingleNode ("Header") as XmlElement;
			if (elem == null)
				return;
			foreach (XmlNode xprop in elem.ChildNodes) {
				XmlElement prop = xprop as XmlElement;
				if (prop != null) {
					switch (prop.LocalName) {
					case "Id": info.id = prop.InnerText; break;
					case "Namespace": info.namspace = prop.InnerText; break;
					case "Version": info.version = prop.InnerText; break;
					case "CompatVersion": info.baseVersion = prop.InnerText; break;
					default: {
						AddinProperty aprop = new AddinProperty ();
						aprop.Name = prop.LocalName;
						if (prop.HasAttribute ("locale"))
							aprop.Locale = prop.GetAttribute ("locale");
						aprop.Value = prop.InnerText;
						properties.Add (aprop);
						break;
					}}
				}
			}
		}
예제 #14
0
		public void Add (AddinInfo p)
		{
			List.Add (p);
		}
예제 #15
0
        public static AddinInfo ReadFromAddinFile(StreamReader r)
        {
            XmlDocument doc = new XmlDocument ();
            doc.Load (r);
            r.Close ();

            AddinInfo info = new AddinInfo ();
            info.id = doc.DocumentElement.GetAttribute ("id");
            info.namspace = doc.DocumentElement.GetAttribute ("namespace");
            info.name = doc.DocumentElement.GetAttribute ("name");
            if (info.id == "") info.id = info.name;
            info.version = doc.DocumentElement.GetAttribute ("version");
            info.author = doc.DocumentElement.GetAttribute ("author");
            info.copyright = doc.DocumentElement.GetAttribute ("copyright");
            info.url = doc.DocumentElement.GetAttribute ("url");
            info.description = doc.DocumentElement.GetAttribute ("description");
            info.category = doc.DocumentElement.GetAttribute ("category");
            info.baseVersion = doc.DocumentElement.GetAttribute ("compatVersion");

            ReadDependencies (info.Dependencies, info.OptionalDependencies, doc.DocumentElement);

            return info;
        }
예제 #16
0
        internal static AddinInfo ReadFromDescription(AddinDescription description)
        {
            AddinInfo info = new AddinInfo ();
            info.id = description.LocalId;
            info.namspace = description.Namespace;
            info.name = description.Name;
            info.version = description.Version;
            info.author = description.Author;
            info.copyright = description.Copyright;
            info.url = description.Url;
            info.description = description.Description;
            info.category = description.Category;
            info.baseVersion = description.CompatVersion;

            foreach (Dependency dep in description.MainModule.Dependencies)
                info.Dependencies.Add (dep);

            foreach (ModuleDescription mod in description.OptionalModules) {
                foreach (Dependency dep in mod.Dependencies)
                    info.OptionalDependencies.Add (dep);
            }
            return info;
        }
예제 #17
0
        void ExtractSupportFiles(string targetDir, string file, AddinInfo ainfo)
        {
            Random r = new Random ();
            ZipFile zfile = new ZipFile (file);
            foreach (var prop in ainfo.Properties) {
                ZipEntry ze = zfile.GetEntry (prop.Value);
                if (ze != null) {
                    string fname;
                    do {
                        fname = Path.Combine (targetDir, r.Next().ToString ("x") + Path.GetExtension (prop.Value));
                    } while (File.Exists (fname));

                    if (!Directory.Exists (targetDir))
                        Directory.CreateDirectory (targetDir);

                    using (var f = File.OpenWrite (fname)) {
                        using (Stream s = zfile.GetInputStream (ze)) {
                            byte[] buffer = new byte [8092];
                            int nr = 0;
                            while ((nr = s.Read (buffer, 0, buffer.Length)) > 0)
                                f.Write (buffer, 0, nr);
                        }
                    }
                    prop.Value = Path.Combine (addinFilesDir, Path.GetFileName (fname));
                }
            }
        }