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.
33
using System.Collections;
34
using System.Collections.Specialized;
35
using Mono.Addins.Database;
36
using Mono.Addins.Description;
40
public class AddinRegistry: IDisposable
42
AddinDatabase database;
43
StringCollection addinDirs;
46
public AddinRegistry (string registryPath): this (registryPath, null)
50
internal AddinRegistry (string registryPath, string startupDirectory)
52
basePath = Util.GetFullPath (registryPath);
53
database = new AddinDatabase (this);
54
addinDirs = new StringCollection ();
55
addinDirs.Add (Path.Combine (basePath, "addins"));
58
public static AddinRegistry GetGlobalRegistry ()
60
return GetGlobalRegistry (null);
63
internal static AddinRegistry GetGlobalRegistry (string startupDirectory)
65
AddinRegistry reg = new AddinRegistry (GlobalRegistryPath, startupDirectory);
68
baseDir = Environment.GetFolderPath (Environment.SpecialFolder.CommonProgramFiles);
72
reg.AddinDirectories.Add (Path.Combine (baseDir, "mono.addins"));
76
internal static string GlobalRegistryPath {
78
string customDir = Environment.GetEnvironmentVariable ("MONO_ADDINS_GLOBAL_REGISTRY");
79
if (customDir != null && customDir.Length > 0)
80
return Util.GetFullPath (customDir);
82
string path = Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData);
83
path = Path.Combine (path, "mono.addins");
84
return Util.GetFullPath (path);
88
public string RegistryPath {
89
get { return basePath; }
92
public void Dispose ()
97
public Addin GetAddin (string id)
99
return database.GetInstalledAddin (id);
102
public Addin GetAddin (string id, bool exactVersionMatch)
104
return database.GetInstalledAddin (id, exactVersionMatch);
107
public Addin[] GetAddins ()
109
ArrayList list = database.GetInstalledAddins ();
110
return (Addin[]) list.ToArray (typeof(Addin));
113
public Addin[] GetAddinRoots ()
115
ArrayList list = database.GetAddinRoots ();
116
return (Addin[]) list.ToArray (typeof(Addin));
119
public AddinDescription GetAddinDescription (IProgressStatus progressStatus, string file)
121
string outFile = Path.GetTempFileName ();
123
database.ParseAddin (progressStatus, file, outFile, false);
126
File.Delete (outFile);
131
AddinDescription desc = AddinDescription.Read (outFile);
133
desc.AddinFile = file;
134
desc.OwnerDatabase = database;
139
// Errors are already reported using the progress status object
143
File.Delete (outFile);
147
public AddinDescription ReadAddinManifestFile (string file)
149
AddinDescription desc = AddinDescription.Read (file);
150
desc.OwnerDatabase = database;
154
public bool IsAddinEnabled (string id)
156
return database.IsAddinEnabled (id);
159
public void EnableAddin (string id)
161
database.EnableAddin (id, true);
164
public void DisableAddin (string id)
166
database.DisableAddin (id);
169
public void DumpFile (string file)
171
Mono.Addins.Serialization.BinaryXmlReader.DumpFile (file);
174
public void ResetConfiguration ()
176
database.ResetConfiguration ();
179
public void Update (IProgressStatus monitor)
181
database.Update (monitor);
184
public void Rebuild (IProgressStatus monitor)
186
database.Repair (monitor);
189
internal Addin GetAddinForHostAssembly (string filePath)
191
return database.GetAddinForHostAssembly (filePath);
194
internal bool AddinDependsOn (string id1, string id2)
196
return database.AddinDependsOn (id1, id2);
199
internal void ScanFolders (IProgressStatus monitor, string folderToScan, StringCollection filesToIgnore)
201
database.ScanFolders (monitor, folderToScan, filesToIgnore);
204
internal void ParseAddin (IProgressStatus progressStatus, string file, string outFile)
206
database.ParseAddin (progressStatus, file, outFile, true);
209
public string DefaultAddinsFolder {
210
get { return Path.Combine (basePath, "addins"); }
213
internal StringCollection AddinDirectories {
214
get { return addinDirs; }
217
internal bool CreateHostAddinsFile (string hostFile)
219
hostFile = Util.GetFullPath (hostFile);
220
string baseName = Path.GetFileNameWithoutExtension (hostFile);
221
if (!Directory.Exists (DefaultAddinsFolder))
222
Directory.CreateDirectory (DefaultAddinsFolder);
224
foreach (string s in Directory.GetFiles (DefaultAddinsFolder, baseName + "*.host.addins")) {
226
using (StreamReader sr = new StreamReader (s)) {
227
XmlTextReader tr = new XmlTextReader (sr);
229
string host = tr.GetAttribute ("host-reference");
230
if (host == hostFile)
239
string file = Path.Combine (DefaultAddinsFolder, baseName) + ".host.addins";
241
while (File.Exists (file)) {
242
file = Path.Combine (DefaultAddinsFolder, baseName) + "_" + n + ".host.addins";
246
using (StreamWriter sw = new StreamWriter (file)) {
247
XmlTextWriter tw = new XmlTextWriter (sw);
248
tw.Formatting = Formatting.Indented;
249
tw.WriteStartElement ("Addins");
250
tw.WriteAttributeString ("host-reference", hostFile);
251
tw.WriteElementString ("Directory", Path.GetDirectoryName (hostFile));
252
tw.WriteEndElement ();