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;
36
namespace Mono.Addins.Setup
38
internal class AddinInfo: AddinHeader
44
string baseVersion = "";
46
string copyright = "";
48
string description = "";
50
DependencyCollection dependencies;
51
DependencyCollection optionalDependencies;
52
AddinPropertyCollectionImpl properties;
56
dependencies = new DependencyCollection ();
57
optionalDependencies = new DependencyCollection ();
58
properties = new AddinPropertyCollectionImpl ();
62
get { return Addin.GetFullId (namspace, id, version); }
66
public string LocalId {
71
public string Namespace {
72
get { return namspace; }
73
set { namspace = value; }
78
string s = Properties.GetPropertyValue ("Name");
81
if (name != null && name.Length > 0)
84
if (sid.StartsWith ("__"))
85
sid = sid.Substring (2);
86
return Addin.GetFullId (namspace, sid, null);
91
public string Version {
92
get { return version; }
93
set { version = value; }
96
public string BaseVersion {
97
get { return baseVersion; }
98
set { baseVersion = value; }
101
public string Author {
103
string s = Properties.GetPropertyValue ("Author");
108
set { author = value; }
111
public string Copyright {
113
string s = Properties.GetPropertyValue ("Copyright");
118
set { copyright = value; }
123
string s = Properties.GetPropertyValue ("Url");
131
public string Description {
133
string s = Properties.GetPropertyValue ("Description");
138
set { description = value; }
141
public string Category {
143
string s = Properties.GetPropertyValue ("Category");
148
set { category = value; }
151
[XmlArrayItem ("AddinDependency", typeof(AddinDependency))]
152
[XmlArrayItem ("NativeDependency", typeof(NativeDependency))]
153
[XmlArrayItem ("AssemblyDependency", typeof(AssemblyDependency))]
154
public DependencyCollection Dependencies {
155
get { return dependencies; }
158
[XmlArrayItem ("AddinDependency", typeof(AddinDependency))]
159
[XmlArrayItem ("NativeDependency", typeof(NativeDependency))]
160
[XmlArrayItem ("AssemblyDependency", typeof(AssemblyDependency))]
161
public DependencyCollection OptionalDependencies {
162
get { return optionalDependencies; }
165
[XmlArrayItem ("Property", typeof(AddinProperty))]
166
public AddinPropertyCollectionImpl Properties {
167
get { return properties; }
170
AddinPropertyCollection AddinHeader.Properties {
171
get { return properties; }
174
public static AddinInfo ReadFromAddinFile (StreamReader r)
176
XmlDocument doc = new XmlDocument ();
180
AddinInfo info = new AddinInfo ();
181
info.id = doc.DocumentElement.GetAttribute ("id");
182
info.namspace = doc.DocumentElement.GetAttribute ("namespace");
183
info.name = doc.DocumentElement.GetAttribute ("name");
184
if (info.id == "") info.id = info.name;
185
info.version = doc.DocumentElement.GetAttribute ("version");
186
info.author = doc.DocumentElement.GetAttribute ("author");
187
info.copyright = doc.DocumentElement.GetAttribute ("copyright");
188
info.url = doc.DocumentElement.GetAttribute ("url");
189
info.description = doc.DocumentElement.GetAttribute ("description");
190
info.category = doc.DocumentElement.GetAttribute ("category");
191
info.baseVersion = doc.DocumentElement.GetAttribute ("compatVersion");
192
AddinPropertyCollectionImpl props = new AddinPropertyCollectionImpl ();
193
info.properties = props;
194
ReadHeader (info, props, doc.DocumentElement);
195
ReadDependencies (info.Dependencies, info.OptionalDependencies, doc.DocumentElement);
199
static void ReadDependencies (DependencyCollection deps, DependencyCollection opDeps, XmlElement elem)
201
foreach (XmlElement dep in elem.SelectNodes ("Dependencies/Addin")) {
202
AddinDependency adep = new AddinDependency ();
203
adep.AddinId = dep.GetAttribute ("id");
204
string v = dep.GetAttribute ("version");
210
foreach (XmlElement dep in elem.SelectNodes ("Dependencies/Assembly")) {
211
AssemblyDependency adep = new AssemblyDependency ();
212
adep.FullName = dep.GetAttribute ("name");
213
adep.Package = dep.GetAttribute ("package");
217
foreach (XmlElement mod in elem.SelectNodes ("Module"))
218
ReadDependencies (opDeps, opDeps, mod);
221
static void ReadHeader (AddinInfo info, AddinPropertyCollectionImpl properties, XmlElement elem)
223
elem = elem.SelectSingleNode ("Header") as XmlElement;
226
foreach (XmlNode xprop in elem.ChildNodes) {
227
XmlElement prop = xprop as XmlElement;
229
switch (prop.LocalName) {
230
case "Id": info.id = prop.InnerText; break;
231
case "Namespace": info.namspace = prop.InnerText; break;
232
case "Version": info.version = prop.InnerText; break;
233
case "CompatVersion": info.baseVersion = prop.InnerText; break;
235
AddinProperty aprop = new AddinProperty ();
236
aprop.Name = prop.LocalName;
237
if (prop.HasAttribute ("locale"))
238
aprop.Locale = prop.GetAttribute ("locale");
239
aprop.Value = prop.InnerText;
240
properties.Add (aprop);
247
internal static AddinInfo ReadFromDescription (AddinDescription description)
249
AddinInfo info = new AddinInfo ();
250
info.id = description.LocalId;
251
info.namspace = description.Namespace;
252
info.name = description.Name;
253
info.version = description.Version;
254
info.author = description.Author;
255
info.copyright = description.Copyright;
256
info.url = description.Url;
257
info.description = description.Description;
258
info.category = description.Category;
259
info.baseVersion = description.CompatVersion;
260
info.properties = new AddinPropertyCollectionImpl (description.Properties);
262
foreach (Dependency dep in description.MainModule.Dependencies)
263
info.Dependencies.Add (dep);
265
foreach (ModuleDescription mod in description.OptionalModules) {
266
foreach (Dependency dep in mod.Dependencies)
267
info.OptionalDependencies.Add (dep);
272
public bool SupportsVersion (string version)
274
if (Addin.CompareVersions (Version, version) > 0)
276
if (baseVersion == "")
278
return Addin.CompareVersions (BaseVersion, version) >= 0;
281
public int CompareVersionTo (AddinHeader other)
283
return Addin.CompareVersions (this.version, other.Version);
288
/// Basic add-in information
290
public interface AddinHeader
293
/// Full identifier of the add-in
300
/// Display name of the add-in
307
/// Namespace of the add-in
314
/// Version of the add-in
321
/// Version with which this add-in is compatible
342
/// Web page URL with more information about the add-in
349
/// Description of the add-in
356
/// Category of the add-in
363
/// Dependencies of the add-in
365
DependencyCollection Dependencies {
370
/// Optional dependencies of the add-in
372
DependencyCollection OptionalDependencies {
377
/// Custom properties specified in the add-in header
379
AddinPropertyCollection Properties {
384
/// Compares the versions of two add-ins
386
/// <param name="other">
390
/// Result of comparison
392
int CompareVersionTo (AddinHeader other);