aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/PluginManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/PluginManager.cs')
-rw-r--r--OpenSim/Framework/PluginManager.cs561
1 files changed, 561 insertions, 0 deletions
diff --git a/OpenSim/Framework/PluginManager.cs b/OpenSim/Framework/PluginManager.cs
new file mode 100644
index 0000000..188d90a
--- /dev/null
+++ b/OpenSim/Framework/PluginManager.cs
@@ -0,0 +1,561 @@
1
2/*
3 * Copyright (c) Contributors, http://opensimulator.org/
4 * See CONTRIBUTORS.TXT for a full list of copyright holders.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the OpenSimulator Project nor the
14 * names of its contributors may be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29
30using System;
31using System.Text;
32using System.Linq;
33using System.Collections;
34using System.Collections.Generic;
35using System.Collections.ObjectModel;
36using Mono.Addins;
37using Mono.Addins.Setup;
38using Mono.Addins.Description;
39using OpenSim.Framework;
40
41
42namespace OpenSim.Framework
43{
44 /// <summary>
45 /// Manager for registries and plugins
46 /// </summary>
47 public class PluginManager : SetupService
48 {
49 public AddinRegistry PluginRegistry;
50
51 public PluginManager(AddinRegistry registry): base (registry)
52 {
53 PluginRegistry = registry;
54
55 }
56
57 /// <summary>
58 /// Installs the plugin.
59 /// </summary>
60 /// <returns>
61 /// The plugin.
62 /// </returns>
63 /// <param name='args'>
64 /// Arguments.
65 /// </param>
66 public bool InstallPlugin(int ndx, out Dictionary<string, object> result)
67 {
68 Dictionary<string, object> res = new Dictionary<string, object>();
69
70 PackageCollection pack = new PackageCollection();
71 PackageCollection toUninstall;
72 DependencyCollection unresolved;
73
74 IProgressStatus ps = new ConsoleProgressStatus(false);
75
76 AddinRepositoryEntry[] available = GetSortedAvailbleAddins();
77
78 if (ndx > (available.Length - 1))
79 {
80 MainConsole.Instance.Output("Selection out of range");
81 result = res;
82 return false;
83 }
84
85 AddinRepositoryEntry aentry = available[ndx];
86
87 Package p = Package.FromRepository(aentry);
88 pack.Add(p);
89
90 ResolveDependencies(ps, pack, out toUninstall, out unresolved);
91
92 // Attempt to install the plugin disabled
93 if (Install(ps, pack) == true)
94 {
95 PluginRegistry.Update(ps);
96 Addin addin = PluginRegistry.GetAddin(aentry.Addin.Id);
97 PluginRegistry.DisableAddin(addin.Id);
98 addin.Enabled = false;
99
100 MainConsole.Instance.Output("Installation Success");
101 ListInstalledAddins(out res);
102 result = res;
103 return true;
104 }
105 else
106 {
107 MainConsole.Instance.Output("Installation Failed");
108 result = res;
109 return false;
110 }
111 }
112
113 // Remove plugin
114 /// <summary>
115 /// Uns the install.
116 /// </summary>
117 /// <param name='args'>
118 /// Arguments.
119 /// </param>
120 public void UnInstall(int ndx)
121 {
122 Addin[] addins = GetSortedAddinList("RobustPlugin");
123
124 if (ndx > (addins.Length -1))
125 {
126 MainConsole.Instance.Output("Selection out of range");
127 return;
128 }
129
130 Addin addin = addins[ndx];
131 MainConsole.Instance.OutputFormat("Uninstalling plugin {0}", addin.Id);
132 AddinManager.Registry.DisableAddin(addin.Id);
133 addin.Enabled = false;
134 IProgressStatus ps = new ConsoleProgressStatus(false);
135 Uninstall(ps, addin.Id);
136 MainConsole.Instance.Output("Uninstall Success - restart to complete operation");
137 return;
138 }
139
140 /// <summary>
141 /// Checks the installed.
142 /// </summary>
143 /// <returns>
144 /// The installed.
145 /// </returns>
146 public string CheckInstalled()
147 {
148 return "CheckInstall";
149 }
150
151 /// <summary>
152 /// Lists the installed addins.
153 /// </summary>
154 /// <param name='result'>
155 /// Result.
156 /// </param>
157 public void ListInstalledAddins(out Dictionary<string, object> result)
158 {
159 Dictionary<string, object> res = new Dictionary<string, object>();
160
161 Addin[] addins = GetSortedAddinList("RobustPlugin");
162 if(addins.Count() < 1)
163 {
164 MainConsole.Instance.Output("Error!");
165 }
166 int count = 0;
167 foreach (Addin addin in addins)
168 {
169 Dictionary<string, object> r = new Dictionary<string, object>();
170 r["enabled"] = addin.Enabled == true ? true : false;
171 r["name"] = addin.LocalId;
172 r["version"] = addin.Version;
173
174 res.Add(count.ToString(), r);
175
176 count++;
177 }
178 result = res;
179 return;
180 }
181
182 // List compatible plugins in registered repositories
183 /// <summary>
184 /// Lists the available.
185 /// </summary>
186 /// <param name='result'>
187 /// Result.
188 /// </param>
189 public void ListAvailable(out Dictionary<string, object> result)
190 {
191 Dictionary<string, object> res = new Dictionary<string, object>();
192
193 AddinRepositoryEntry[] addins = GetSortedAvailbleAddins();
194
195 int count = 0;
196 foreach (AddinRepositoryEntry addin in addins)
197 {
198 Dictionary<string, object> r = new Dictionary<string, object>();
199 r["name"] = addin.Addin.Name;
200 r["version"] = addin.Addin.Version;
201 r["repository"] = addin.RepositoryName;
202
203 res.Add(count.ToString(), r);
204 count++;
205 }
206 result = res;
207 return;
208 }
209
210 // List available updates ** 1
211 /// <summary>
212 /// Lists the updates.
213 /// </summary>
214 public void ListUpdates()
215 {
216 IProgressStatus ps = new ConsoleProgressStatus(true);
217 Console.WriteLine ("Looking for updates...");
218 Repositories.UpdateAllRepositories (ps);
219 Console.WriteLine ("Available add-in updates:");
220 bool found = false;
221 AddinRepositoryEntry[] entries = Repositories.GetAvailableUpdates();
222
223 foreach (AddinRepositoryEntry entry in entries)
224 {
225 Console.WriteLine(String.Format("{0}",entry.Addin.Id));
226 }
227 }
228
229 // Sync to repositories
230 /// <summary>
231 /// Update this instance.
232 /// </summary>
233 public string Update()
234 {
235 IProgressStatus ps = new ConsoleProgressStatus(true);
236 Repositories.UpdateAllRepositories(ps);
237 return "Update";
238 }
239
240 // Register a repository
241 /// <summary>
242 /// Register a repository with our server.
243 /// </summary>
244 /// <returns>
245 /// result of the action
246 /// </returns>
247 /// <param name='repo'>
248 /// The URL of the repository we want to add
249 /// </param>
250 public bool AddRepository(string repo)
251 {
252 Repositories.RegisterRepository(null, repo, true);
253 PluginRegistry.Rebuild(null);
254
255 return true;
256 }
257
258 /// <summary>
259 /// Gets the repository.
260 /// </summary>
261 public void GetRepository()
262 {
263 Repositories.UpdateAllRepositories(new ConsoleProgressStatus(false));
264 }
265
266 // Remove a repository from the list
267 /// <summary>
268 /// Removes the repository.
269 /// </summary>
270 /// <param name='args'>
271 /// Arguments.
272 /// </param>
273 public void RemoveRepository(string[] args)
274 {
275 AddinRepository[] reps = Repositories.GetRepositories();
276 Array.Sort(reps, (r1,r2) => r1.Title.CompareTo(r2.Title));
277 if (reps.Length == 0)
278 {
279 MainConsole.Instance.Output("No repositories have been registered.");
280 return;
281 }
282
283 int n = Convert.ToInt16(args[2]);
284 if (n > (reps.Length -1))
285 {
286 MainConsole.Instance.Output("Selection out of range");
287 return;
288 }
289
290 AddinRepository rep = reps[n];
291 Repositories.RemoveRepository(rep.Url);
292 return;
293 }
294
295 // Enable repository
296 /// <summary>
297 /// Enables the repository.
298 /// </summary>
299 /// <param name='args'>
300 /// Arguments.
301 /// </param>
302 public void EnableRepository(string[] args)
303 {
304 AddinRepository[] reps = Repositories.GetRepositories();
305 Array.Sort(reps, (r1,r2) => r1.Title.CompareTo(r2.Title));
306 if (reps.Length == 0)
307 {
308 MainConsole.Instance.Output("No repositories have been registered.");
309 return;
310 }
311
312 int n = Convert.ToInt16(args[2]);
313 if (n > (reps.Length -1))
314 {
315 MainConsole.Instance.Output("Selection out of range");
316 return;
317 }
318
319 AddinRepository rep = reps[n];
320 Repositories.SetRepositoryEnabled(rep.Url, true);
321 return;
322 }
323
324 // Disable a repository
325 /// <summary>
326 /// Disables the repository.
327 /// </summary>
328 /// <param name='args'>
329 /// Arguments.
330 /// </param>
331 public void DisableRepository(string[] args)
332 {
333 AddinRepository[] reps = Repositories.GetRepositories();
334 Array.Sort(reps, (r1,r2) => r1.Title.CompareTo(r2.Title));
335 if (reps.Length == 0)
336 {
337 MainConsole.Instance.Output("No repositories have been registered.");
338 return;
339 }
340
341 int n = Convert.ToInt16(args[2]);
342 if (n > (reps.Length -1))
343 {
344 MainConsole.Instance.Output("Selection out of range");
345 return;
346 }
347
348 AddinRepository rep = reps[n];
349 Repositories.SetRepositoryEnabled(rep.Url, false);
350 return;
351 }
352
353 // List registered repositories
354 /// <summary>
355 /// Lists the repositories.
356 /// </summary>
357 /// <param name='result'>
358 /// Result.
359 /// </param>
360 public void ListRepositories(out Dictionary<string, object> result)
361 {
362 Dictionary<string, object> res = new Dictionary<string, object>();
363 result = res;
364
365 AddinRepository[] reps = GetSortedAddinRepo();
366 if (reps.Length == 0)
367 {
368 MainConsole.Instance.Output("No repositories have been registered.");
369 return;
370 }
371
372 int count = 0;
373 foreach (AddinRepository rep in reps)
374 {
375 Dictionary<string, object> r = new Dictionary<string, object>();
376 r["enabled"] = rep.Enabled == true ? true : false;
377 r["name"] = rep.Name;
378 r["url"] = rep.Url;
379
380 res.Add(count.ToString(), r);
381 count++;
382 }
383 return;
384 }
385
386 /// <summary>
387 /// Updates the registry.
388 /// </summary>
389 public void UpdateRegistry()
390 {
391 PluginRegistry.Update();
392 }
393
394 // Show plugin info
395 /// <summary>
396 /// Addins the info.
397 /// </summary>
398 /// <returns>
399 /// The info.
400 /// </returns>
401 /// <param name='args'>
402 /// Arguments.
403 /// </param>
404 public bool AddinInfo(int ndx, out Dictionary<string, object> result)
405 {
406 Dictionary<string, object> res = new Dictionary<string, object>();
407 result = res;
408
409 Addin[] addins = GetSortedAddinList("RobustPlugin");
410
411 if (ndx > (addins.Length - 1))
412 {
413 MainConsole.Instance.Output("Selection out of range");
414 return false;
415 }
416 // author category description
417 Addin addin = addins[ndx];
418
419 res["author"] = addin.Description.Author;
420 res["category"] = addin.Description.Category;
421 res["description"] = addin.Description.Description;
422 res["name"] = addin.Name;
423 res["url"] = addin.Description.Url;
424 res["file_name"] = addin.Description.FileName;
425
426 result = res;
427 return true;
428 }
429
430 // Disable a plugin
431 /// <summary>
432 /// Disables the plugin.
433 /// </summary>
434 /// <param name='args'>
435 /// Arguments.
436 /// </param>
437 public void DisablePlugin(string[] args)
438 {
439 Addin[] addins = GetSortedAddinList("RobustPlugin");
440
441 int n = Convert.ToInt16(args[2]);
442 if (n > (addins.Length -1))
443 {
444 MainConsole.Instance.Output("Selection out of range");
445 return;
446 }
447
448 Addin addin = addins[n];
449 AddinManager.Registry.DisableAddin(addin.Id);
450 addin.Enabled = false;
451 return;
452 }
453
454 // Enable plugin
455 /// <summary>
456 /// Enables the plugin.
457 /// </summary>
458 /// <param name='args'>
459 /// Arguments.
460 /// </param>
461 public void EnablePlugin(string[] args)
462 {
463 Addin[] addins = GetSortedAddinList("RobustPlugin");
464
465 int n = Convert.ToInt16(args[2]);
466 if (n > (addins.Length -1))
467 {
468 MainConsole.Instance.Output("Selection out of range");
469 return;
470 }
471
472 Addin addin = addins[n];
473
474 addin.Enabled = true;
475 AddinManager.Registry.EnableAddin(addin.Id);
476 // AddinManager.Registry.Update();
477 if(PluginRegistry.IsAddinEnabled(addin.Id))
478 {
479 ConsoleProgressStatus ps = new ConsoleProgressStatus(false);
480 if (!AddinManager.AddinEngine.IsAddinLoaded(addin.Id))
481 {
482 AddinManager.Registry.Rebuild(ps);
483 AddinManager.AddinEngine.LoadAddin(ps, addin.Id);
484 }
485 }
486 else
487 {
488 MainConsole.Instance.OutputFormat("Not Enabled in this domain {0}", addin.Name);
489 }
490 return;
491 }
492
493
494
495 #region Util
496 private void Testing()
497 {
498 Addin[] list = Registry.GetAddins();
499
500 var addins = list.Where( a => a.Description.Category == "RobustPlugin");
501
502 foreach (Addin addin in addins)
503 {
504 MainConsole.Instance.OutputFormat("Addin {0}", addin.Name);
505 }
506 }
507
508 // These will let us deal with numbered lists instead
509 // of needing to type in the full ids
510 private AddinRepositoryEntry[] GetSortedAvailbleAddins()
511 {
512 ArrayList list = new ArrayList();
513 list.AddRange(Repositories.GetAvailableAddins());
514
515 AddinRepositoryEntry[] addins = list.ToArray(typeof(AddinRepositoryEntry)) as AddinRepositoryEntry[];
516
517 Array.Sort(addins,(r1,r2) => r1.Addin.Id.CompareTo(r2.Addin.Id));
518
519 return addins;
520 }
521
522 private AddinRepository[] GetSortedAddinRepo()
523 {
524 ArrayList list = new ArrayList();
525 list.AddRange(Repositories.GetRepositories());
526
527 AddinRepository[] repos = list.ToArray(typeof(AddinRepository)) as AddinRepository[];
528 Array.Sort (repos,(r1,r2) => r1.Name.CompareTo(r2.Name));
529
530 return repos;
531 }
532
533 private Addin[] GetSortedAddinList(string category)
534 {
535
536 ArrayList xlist = new ArrayList();
537 ArrayList list = new ArrayList();
538 try
539 {
540 list.AddRange(PluginRegistry.GetAddins());
541 }
542 catch(Exception e)
543 {
544 Addin[] x = xlist.ToArray(typeof(Addin)) as Addin[];
545 return x;
546 }
547
548 foreach (Addin addin in list)
549 {
550 if (addin.Description.Category == category)
551 xlist.Add(addin);
552 }
553
554 Addin[] addins = xlist.ToArray(typeof(Addin)) as Addin[];
555 Array.Sort(addins,(r1,r2) => r1.Id.CompareTo(r2.Id));
556
557 return addins;
558 }
559 #endregion Util
560 }
561}