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;
46
AddinDatabase database;
48
internal Addin (AddinDatabase database, string file)
50
this.database = database;
56
if (configFile != null)
57
return Path.GetFileNameWithoutExtension (configFile);
58
return this.AddinInfo.Id;
62
public string Namespace {
63
get { return this.AddinInfo.Namespace; }
66
public string LocalId {
67
get { return this.AddinInfo.LocalId; }
70
public string Version {
71
get { return this.AddinInfo.Version; }
75
get { return this.AddinInfo.Name; }
78
internal string PrivateDataPath {
79
get { return Path.Combine (database.AddinPrivateDataPath, Path.GetFileNameWithoutExtension (Description.FileName)); }
82
public bool SupportsVersion (string version)
84
return AddinInfo.SupportsVersion (version);
87
public override string ToString ()
92
internal AddinInfo AddinInfo {
96
addin = AddinInfo.ReadFromDescription (Description);
97
} catch (Exception ex) {
98
throw new InvalidOperationException ("Could not read add-in file: " + configFile, ex);
105
public bool Enabled {
106
get { return AddinInfo.IsRoot ? true : database.IsAddinEnabled (Description.Domain, AddinInfo.Id, true); }
109
database.EnableAddin (Description.Domain, AddinInfo.Id, true);
111
database.DisableAddin (Description.Domain, AddinInfo.Id);
115
public bool IsUserAddin {
116
get { return configFile.StartsWith (Environment.GetFolderPath (Environment.SpecialFolder.Personal)); }
119
public string AddinFile {
121
if (sourceFile == null && addin == null)
127
void LoadAddinInfo ()
131
AddinDescription m = Description;
132
sourceFile = m.AddinFile;
133
addin = AddinInfo.ReadFromDescription (m);
134
} catch (Exception ex) {
135
throw new InvalidOperationException ("Could not read add-in file: " + configFile, ex);
140
public AddinDescription Description {
143
AddinDescription d = desc.Target as AddinDescription;
149
database.ReadAddinDescription (null, configFile, out m);
152
throw new InvalidOperationException ("Could not read add-in description");
154
addin = AddinInfo.ReadFromDescription (m);
155
sourceFile = m.AddinFile;
157
desc = new WeakReference (m);
162
// returns -1 if v1 > v2
163
public static int CompareVersions (string v1, string v2)
165
string[] a1 = v1.Split ('.');
166
string[] a2 = v2.Split ('.');
168
for (int n=0; n<a1.Length; n++) {
171
if (a1[n].Length == 0) {
172
if (a2[n].Length != 0)
177
int n1 = int.Parse (a1[n]);
178
int n2 = int.Parse (a2[n]);
187
if (a2.Length > a1.Length)
192
public static string GetFullId (string ns, string id, string version)
195
if (id.StartsWith ("::"))
196
res = id.Substring (2);
197
else if (ns != null && ns.Length > 0)
202
if (version != null && version.Length > 0)
203
return res + "," + version;
208
public static string GetIdName (string addinId)
210
int i = addinId.IndexOf (',');
212
return addinId.Substring (0, i);
217
public static string GetIdVersion (string addinId)
219
int i = addinId.IndexOf (',');
221
return addinId.Substring (i + 1).Trim ();
226
public static void GetIdParts (string addinId, out string name, out string version)
228
int i = addinId.IndexOf (',');
230
name = addinId.Substring (0, i);
231
version = addinId.Substring (i+1).Trim ();
234
version = string.Empty;