7
// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
9
// Permission is hereby granted, free of charge, to any person obtaining
10
// a copy of this software and associated documentation files (the
11
// "Software"), to deal in the Software without restriction, including
12
// without limitation the rights to use, copy, modify, merge, publish,
13
// distribute, sublicense, and/or sell copies of the Software, and to
14
// permit persons to whom the Software is furnished to do so, subject to
15
// the following conditions:
17
// The above copyright notice and this permission notice shall be
18
// included in all copies or substantial portions of the Software.
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31
using System.Collections;
33
using System.Xml.Serialization;
34
using Mono.Addins.Description;
38
internal class AddinInfo
44
string baseVersion = "";
46
string copyright = "";
48
string description = "";
50
bool defaultEnabled = true;
52
DependencyCollection dependencies;
53
DependencyCollection optionalDependencies;
57
dependencies = new DependencyCollection ();
58
optionalDependencies = new DependencyCollection ();
62
get { return Addin.GetFullId (namspace, id, version); }
66
public string LocalId {
71
public string Namespace {
72
get { return namspace; }
73
set { namspace = value; }
77
get { return isroot; }
78
set { isroot = value; }
83
if (name != null && name.Length > 0)
86
if (sid.StartsWith ("__"))
87
sid = sid.Substring (2);
88
return Addin.GetFullId (namspace, sid, null);
93
public string Version {
94
get { return version; }
95
set { version = value; }
98
public string BaseVersion {
99
get { return baseVersion; }
100
set { baseVersion = value; }
103
public string Author {
104
get { return author; }
105
set { author = value; }
108
public string Copyright {
109
get { return copyright; }
110
set { copyright = value; }
118
public string Description {
119
get { return description; }
120
set { description = value; }
123
public string Category {
124
get { return category; }
125
set { category = value; }
128
public bool EnabledByDefault {
129
get { return defaultEnabled; }
130
set { defaultEnabled = value; }
133
[XmlArrayItem ("AddinDependency", typeof(AddinDependency))]
134
[XmlArrayItem ("AssemblyDependency", typeof(AssemblyDependency))]
135
public DependencyCollection Dependencies {
136
get { return dependencies; }
139
[XmlArrayItem ("AddinDependency", typeof(AddinDependency))]
140
[XmlArrayItem ("AssemblyDependency", typeof(AssemblyDependency))]
141
public DependencyCollection OptionalDependencies {
142
get { return optionalDependencies; }
145
public static AddinInfo ReadFromAddinFile (StreamReader r)
147
XmlDocument doc = new XmlDocument ();
151
AddinInfo info = new AddinInfo ();
152
info.id = doc.DocumentElement.GetAttribute ("id");
153
info.namspace = doc.DocumentElement.GetAttribute ("namespace");
154
info.name = doc.DocumentElement.GetAttribute ("name");
155
if (info.id == "") info.id = info.name;
156
info.version = doc.DocumentElement.GetAttribute ("version");
157
info.author = doc.DocumentElement.GetAttribute ("author");
158
info.copyright = doc.DocumentElement.GetAttribute ("copyright");
159
info.url = doc.DocumentElement.GetAttribute ("url");
160
info.description = doc.DocumentElement.GetAttribute ("description");
161
info.category = doc.DocumentElement.GetAttribute ("category");
162
info.baseVersion = doc.DocumentElement.GetAttribute ("compatVersion");
164
string s = doc.DocumentElement.GetAttribute ("defaultEnabled");
165
info.defaultEnabled = s.Length == 0 || s == "true" || s == "yes";
167
s = doc.DocumentElement.GetAttribute ("isRoot");
168
if (s.Length == 0) s = doc.DocumentElement.GetAttribute ("isroot");
169
info.isroot = s == "true" || s == "yes";
171
ReadDependencies (info.Dependencies, info.OptionalDependencies, doc.DocumentElement);
176
static void ReadDependencies (DependencyCollection deps, DependencyCollection opDeps, XmlElement elem)
178
foreach (XmlElement dep in elem.SelectNodes ("Dependencies/Addin")) {
179
AddinDependency adep = new AddinDependency ();
180
adep.AddinId = dep.GetAttribute ("id");
181
string v = dep.GetAttribute ("version");
187
foreach (XmlElement dep in elem.SelectNodes ("Dependencies/Assembly")) {
188
AssemblyDependency adep = new AssemblyDependency ();
189
adep.FullName = dep.GetAttribute ("name");
190
adep.Package = dep.GetAttribute ("package");
194
foreach (XmlElement mod in elem.SelectNodes ("Module"))
195
ReadDependencies (opDeps, opDeps, mod);
198
internal static AddinInfo ReadFromDescription (AddinDescription description)
200
AddinInfo info = new AddinInfo ();
201
info.id = description.LocalId;
202
info.namspace = description.Namespace;
203
info.name = description.Name;
204
info.version = description.Version;
205
info.author = description.Author;
206
info.copyright = description.Copyright;
207
info.url = description.Url;
208
info.description = description.Description;
209
info.category = description.Category;
210
info.baseVersion = description.CompatVersion;
211
info.isroot = description.IsRoot;
212
info.defaultEnabled = description.EnabledByDefault;
214
foreach (Dependency dep in description.MainModule.Dependencies)
215
info.Dependencies.Add (dep);
217
foreach (ModuleDescription mod in description.OptionalModules) {
218
foreach (Dependency dep in mod.Dependencies)
219
info.OptionalDependencies.Add (dep);
224
public bool SupportsVersion (string version)
226
if (Addin.CompareVersions (Version, version) > 0)
228
if (baseVersion == "")
230
return Addin.CompareVersions (BaseVersion, version) >= 0;
233
public int CompareVersionTo (AddinInfo other)
235
return Addin.CompareVersions (this.version, other.Version);