7
// Copyright (C) 2005 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.
30
using System.Collections;
33
using System.Xml.Serialization;
34
using System.Collections.Specialized;
35
using Mono.Addins.Description;
36
using Mono.Addins.Database;
47
AddinDatabase database;
49
internal Addin (AddinDatabase database, string file)
51
this.database = database;
55
internal Addin (AddinDatabase database, string hostId, string hostSourceFile)
57
this.database = database;
59
this.sourceFile = hostSourceFile;
63
get { return this.AddinInfo.Id; }
66
public string Namespace {
67
get { return this.AddinInfo.Namespace; }
70
public string LocalId {
71
get { return this.AddinInfo.LocalId; }
74
public string Version {
75
get { return this.AddinInfo.Version; }
79
get { return this.AddinInfo.Name; }
82
internal string PrivateDataPath {
83
get { return Path.Combine (database.AddinPrivateDataPath, Path.GetFileNameWithoutExtension (Description.FileName)); }
86
public bool SupportsVersion (string version)
88
return AddinInfo.SupportsVersion (version);
91
internal AddinInfo AddinInfo {
95
addin = AddinInfo.ReadFromDescription (Description);
96
} catch (Exception ex) {
97
throw new InvalidOperationException ("Could not read add-in file: " + configFile, ex);
104
public bool Enabled {
105
get { return AddinInfo.IsRoot ? true : database.IsAddinEnabled (AddinInfo.Id, true); }
108
database.EnableAddin (AddinInfo.Id, true);
110
database.DisableAddin (AddinInfo.Id);
114
public bool IsUserAddin {
115
get { return configFile.StartsWith (Environment.GetFolderPath (Environment.SpecialFolder.Personal)); }
118
public string AddinFile {
120
if (sourceFile == null && addin == null)
126
void LoadAddinInfo ()
130
AddinDescription m = Description;
131
sourceFile = m.AddinFile;
132
addin = AddinInfo.ReadFromDescription (m);
133
} catch (Exception ex) {
134
throw new InvalidOperationException ("Could not read add-in file: " + configFile, ex);
139
public AddinDescription Description {
142
AddinDescription d = desc.Target as AddinDescription;
150
database.GetHostDescription (null, hostId, sourceFile, out m);
152
database.ReadAddinDescription (null, configFile, out m);
155
throw new InvalidOperationException ("Could not read add-in description");
157
addin = AddinInfo.ReadFromDescription (m);
158
sourceFile = m.AddinFile;
160
desc = new WeakReference (m);
166
public static int CompareVersions (string v1, string v2)
168
string[] a1 = v1.Split ('.');
169
string[] a2 = v2.Split ('.');
171
for (int n=0; n<a1.Length; n++) {
178
int n1 = int.Parse (a1[n]);
179
int n2 = int.Parse (a2[n]);
191
public static string GetFullId (string ns, string id, string version)
194
if (id.StartsWith ("::"))
195
res = id.Substring (2);
196
else if (ns != null && ns.Length > 0)
201
if (version != null && version.Length > 0)
202
return res + "," + version;
207
public static string GetIdName (string addinId)
209
int i = addinId.IndexOf (',');
211
return addinId.Substring (0, i);
216
public static string GetIdVersion (string addinId)
218
int i = addinId.IndexOf (',');
220
return addinId.Substring (i + 1).Trim ();
225
public static void GetIdParts (string addinId, out string name, out string version)
227
int i = addinId.IndexOf (',');
229
name = addinId.Substring (0, i);
230
version = addinId.Substring (i+1).Trim ();
233
version = string.Empty;