~ubuntu-branches/ubuntu/jaunty/tomboy/jaunty

« back to all changes in this revision

Viewing changes to Mono.Addins/Mono.Addins/Mono.Addins.Description/AddinDescription.cs

  • Committer: Bazaar Package Importer
  • Author(s): Pedro Fragoso
  • Date: 2009-02-17 03:08:19 UTC
  • mfrom: (1.1.46 upstream)
  • Revision ID: james.westby@ubuntu.com-20090217030819-87k5mkna0w5tvvqf
Tags: 0.13.5-0ubuntu1
* New upstream release
  - Removed bundled Mono.Addins. Mono.Addins is
    now a hard dependency.
  - Update printing to use Gtk.Print (#512369, Benjamin Podszun)
    Still buggy.
  - Fix multi-page printing of exported note HTML (#548198)
  - Fix crash when clicking link and browser not set (#569639).
  - 64-bit Windows support (#558272, Jay R. Wren).
  - Search window position saved on Windows/Mac (#559663).
  - Fix lingering tray icon in Windows (#569709, Benjamin Podszun).
  - Fix bug with font settings (#559724, Benjamin Podszun).
  - Mac MonoDevelop solution now easier to build (Doug Johnston et al).
  - Other fixes: #562846 (James Westby) #570917, #570918.
  - Additional updates to note printing (#512369, #572024
    , Benjamin Podszun).
  - Windows installer now requires Novell's GTK# >= 2.12.8 (#569324).
  - Increase/Decrease Indent shortcuts now appear in menu
    (#570334, Benjamin Podszun).
  - No longer writes to disk every 40 seconds (#514434).
  - Fixes to note linking (#323845, Florian).
  - Add GConf preference for auto-accepting SSL Certs in 
    WebDAV sync (#531364).
  - After succcessfully configuring sync, offer to perform 
    first sync (#553079).
* debian/control:
  - Use libgconf2.24-cil and libgnome2.24-cil (LP: #314516)
  - Build-dep on libgnomepanel2.24-cil
  - Remove Build-dep on libgnomeprint and libgnomeprintui
  - Add Vcs headers
* .bzr-builddeb/default.conf: added
* debian/patches/02_configurable_compiler.patch:
  - Removed, merged upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
// AddinDescription.cs
3
 
//
4
 
// Author:
5
 
//   Lluis Sanchez Gual
6
 
//
7
 
// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
8
 
//
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:
16
 
// 
17
 
// The above copyright notice and this permission notice shall be
18
 
// included in all copies or substantial portions of the Software.
19
 
// 
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.
27
 
//
28
 
 
29
 
using System;
30
 
using System.Collections;
31
 
using System.IO;
32
 
using System.Xml;
33
 
using System.Xml.Serialization;
34
 
using System.Collections.Specialized;
35
 
using Mono.Addins.Serialization;
36
 
using Mono.Addins.Database;
37
 
 
38
 
namespace Mono.Addins.Description
39
 
{
40
 
        // This class represent an add-in configuration file. It has properties for getting
41
 
        // all information, and methods for loading and saving files.
42
 
        public class AddinDescription: IBinaryXmlElement
43
 
        {
44
 
                XmlDocument configDoc;
45
 
                string configFile;
46
 
                AddinDatabase ownerDatabase;
47
 
                
48
 
                string id;
49
 
                string name;
50
 
                string ns;
51
 
                string version;
52
 
                string compatVersion;
53
 
                string author;
54
 
                string url;
55
 
                string copyright;
56
 
                string description;
57
 
                string category;
58
 
                string basePath;
59
 
                string sourceAddinFile;
60
 
                bool isroot;
61
 
                bool hasUserId;
62
 
                bool canWrite = true;
63
 
                bool defaultEnabled = true;
64
 
                string domain;
65
 
                
66
 
                ModuleDescription mainModule;
67
 
                ModuleCollection optionalModules;
68
 
                ExtensionNodeSetCollection nodeSets;
69
 
                ConditionTypeDescriptionCollection conditionTypes;
70
 
                ExtensionPointCollection extensionPoints;
71
 
                ExtensionNodeDescription localizer;
72
 
                object[] fileInfo;
73
 
                
74
 
                internal static BinaryXmlTypeMap typeMap;
75
 
                
76
 
                static AddinDescription ()
77
 
                {
78
 
                        typeMap = new BinaryXmlTypeMap ();
79
 
                        typeMap.RegisterType (typeof(AddinDescription), "AddinDescription");
80
 
                        typeMap.RegisterType (typeof(Extension), "Extension");
81
 
                        typeMap.RegisterType (typeof(ExtensionNodeDescription), "Node");
82
 
                        typeMap.RegisterType (typeof(ExtensionNodeSet), "NodeSet");
83
 
                        typeMap.RegisterType (typeof(ExtensionNodeType), "NodeType");
84
 
                        typeMap.RegisterType (typeof(ExtensionPoint), "ExtensionPoint");
85
 
                        typeMap.RegisterType (typeof(ModuleDescription), "ModuleDescription");
86
 
                        typeMap.RegisterType (typeof(ConditionTypeDescription), "ConditionType");
87
 
                        typeMap.RegisterType (typeof(Condition), "Condition");
88
 
                        typeMap.RegisterType (typeof(AddinDependency), "AddinDependency");
89
 
                        typeMap.RegisterType (typeof(AssemblyDependency), "AssemblyDependency");
90
 
                        typeMap.RegisterType (typeof(NodeTypeAttribute), "NodeTypeAttribute");
91
 
                        typeMap.RegisterType (typeof(AddinFileInfo), "FileInfo");
92
 
                }
93
 
                
94
 
                internal AddinDatabase OwnerDatabase {
95
 
                        get { return ownerDatabase; }
96
 
                        set { ownerDatabase = value; }
97
 
                }
98
 
                
99
 
                public string AddinFile {
100
 
                        get { return sourceAddinFile; }
101
 
                        set { sourceAddinFile = value; }
102
 
                }
103
 
                
104
 
                public string AddinId {
105
 
                        get { return Addin.GetFullId (Namespace, LocalId, Version); }
106
 
                }
107
 
                
108
 
                public string LocalId {
109
 
                        get { return id != null ? id : string.Empty; }
110
 
                        set { id = value; hasUserId = true; }
111
 
                }
112
 
 
113
 
                public string Namespace {
114
 
                        get { return ns != null ? ns : string.Empty; }
115
 
                        set { ns = value; }
116
 
                }
117
 
 
118
 
                public string Name {
119
 
                        get {
120
 
                                if (name != null && name.Length > 0)
121
 
                                        return name;
122
 
                                if (HasUserId)
123
 
                                        return AddinId;
124
 
                                else if (sourceAddinFile != null)
125
 
                                        return Path.GetFileNameWithoutExtension (sourceAddinFile);
126
 
                                else
127
 
                                        return string.Empty;
128
 
                        }
129
 
                        set { name = value; }
130
 
                }
131
 
 
132
 
                public string Version {
133
 
                        get { return version != null ? version : string.Empty; }
134
 
                        set { version = value; }
135
 
                }
136
 
 
137
 
                public string CompatVersion {
138
 
                        get { return compatVersion != null ? compatVersion : string.Empty; }
139
 
                        set { compatVersion = value; }
140
 
                }
141
 
 
142
 
                public string Author {
143
 
                        get { return author != null ? author : string.Empty; }
144
 
                        set { author = value; }
145
 
                }
146
 
 
147
 
                public string Url {
148
 
                        get { return url != null ? url : string.Empty; }
149
 
                        set { url = value; }
150
 
                }
151
 
 
152
 
                public string Copyright {
153
 
                        get { return copyright != null ? copyright : string.Empty; }
154
 
                        set { copyright = value; }
155
 
                }
156
 
 
157
 
                public string Description {
158
 
                        get { return description != null ? description : string.Empty; }
159
 
                        set { description = value; }
160
 
                }
161
 
 
162
 
                public string Category {
163
 
                        get { return category != null ? category : string.Empty; }
164
 
                        set { category = value; }
165
 
                }
166
 
                
167
 
                internal string BasePath {
168
 
                        get { return basePath != null ? basePath : string.Empty; }
169
 
                        set { basePath = value; }
170
 
                }
171
 
                
172
 
                public bool IsRoot {
173
 
                        get { return isroot; }
174
 
                        set { isroot = value; }
175
 
                }
176
 
                
177
 
                public bool EnabledByDefault {
178
 
                        get { return defaultEnabled; }
179
 
                        set { defaultEnabled = value; }
180
 
                }
181
 
                
182
 
                internal bool HasUserId {
183
 
                        get { return hasUserId; }
184
 
                        set { hasUserId = value; }
185
 
                }
186
 
                
187
 
                internal bool SupportsVersion (string ver)
188
 
                {
189
 
                        return Addin.CompareVersions (ver, Version) >= 0 &&
190
 
                                   (CompatVersion.Length == 0 || Addin.CompareVersions (ver, CompatVersion) <= 0);
191
 
                }
192
 
                
193
 
                public StringCollection AllFiles {
194
 
                        get {
195
 
                                StringCollection col = new StringCollection ();
196
 
                                foreach (string s in MainModule.AllFiles)
197
 
                                        col.Add (s);
198
 
 
199
 
                                foreach (ModuleDescription mod in OptionalModules) {
200
 
                                        foreach (string s in mod.AllFiles)
201
 
                                                col.Add (s);
202
 
                                }
203
 
                                return col;
204
 
                        }
205
 
                }
206
 
                
207
 
                public ModuleDescription MainModule {
208
 
                        get {
209
 
                                if (mainModule == null) {
210
 
                                        if (RootElement == null)
211
 
                                                mainModule = new ModuleDescription ();
212
 
                                        else
213
 
                                                mainModule = new ModuleDescription (RootElement);
214
 
                                        mainModule.SetParent (this);
215
 
                                }
216
 
                                return mainModule;
217
 
                        }
218
 
                }
219
 
                
220
 
                public ModuleCollection OptionalModules {
221
 
                        get {
222
 
                                if (optionalModules == null) {
223
 
                                        optionalModules = new ModuleCollection (this);
224
 
                                        if (RootElement != null) {
225
 
                                                foreach (XmlElement mod in RootElement.SelectNodes ("Module"))
226
 
                                                        optionalModules.Add (new ModuleDescription (mod));
227
 
                                        }
228
 
                                }
229
 
                                return optionalModules;
230
 
                        }
231
 
                }
232
 
                
233
 
                public ModuleCollection AllModules {
234
 
                        get {
235
 
                                ModuleCollection col = new ModuleCollection (this);
236
 
                                col.Add (MainModule);
237
 
                                foreach (ModuleDescription mod in OptionalModules)
238
 
                                        col.Add (mod);
239
 
                                return col;
240
 
                        }
241
 
                }
242
 
                
243
 
                public ExtensionNodeSetCollection ExtensionNodeSets {
244
 
                        get {
245
 
                                if (nodeSets == null) {
246
 
                                        nodeSets = new ExtensionNodeSetCollection (this);
247
 
                                        if (RootElement != null) {
248
 
                                                foreach (XmlElement elem in RootElement.SelectNodes ("ExtensionNodeSet"))
249
 
                                                        nodeSets.Add (new ExtensionNodeSet (elem));
250
 
                                        }
251
 
                                }
252
 
                                return nodeSets;
253
 
                        }
254
 
                }
255
 
                
256
 
                public ExtensionPointCollection ExtensionPoints {
257
 
                        get {
258
 
                                if (extensionPoints == null) {
259
 
                                        extensionPoints = new ExtensionPointCollection (this);
260
 
                                        if (RootElement != null) {
261
 
                                                foreach (XmlElement elem in RootElement.SelectNodes ("ExtensionPoint"))
262
 
                                                        extensionPoints.Add (new ExtensionPoint (elem));
263
 
                                        }
264
 
                                }
265
 
                                return extensionPoints;
266
 
                        }
267
 
                }
268
 
                
269
 
                public ConditionTypeDescriptionCollection ConditionTypes {
270
 
                        get {
271
 
                                if (conditionTypes == null) {
272
 
                                        conditionTypes = new ConditionTypeDescriptionCollection (this);
273
 
                                        if (RootElement != null) {
274
 
                                                foreach (XmlElement elem in RootElement.SelectNodes ("ConditionType"))
275
 
                                                        conditionTypes.Add (new ConditionTypeDescription (elem));
276
 
                                        }
277
 
                                }
278
 
                                return conditionTypes;
279
 
                        }
280
 
                }
281
 
                
282
 
                public ExtensionNodeDescription Localizer {
283
 
                        get { return localizer; }
284
 
                        set { localizer = value; }
285
 
                }
286
 
                
287
 
                public ExtensionPoint AddExtensionPoint (string path)
288
 
                {
289
 
                        ExtensionPoint ep = new ExtensionPoint ();
290
 
                        ep.Path = path;
291
 
                        ExtensionPoints.Add (ep);
292
 
                        return ep;
293
 
                }
294
 
                
295
 
                internal ExtensionNodeDescription FindExtensionNode (string path, bool lookInDeps)
296
 
                {
297
 
                        // Look in the extensions of this add-in
298
 
                        
299
 
                        foreach (Extension ext in MainModule.Extensions) {
300
 
                                if (path.StartsWith (ext.Path + "/")) {
301
 
                                        string subp = path.Substring (ext.Path.Length).Trim ('/');
302
 
                                        ExtensionNodeDescriptionCollection nodes = ext.ExtensionNodes;
303
 
                                        ExtensionNodeDescription node = null;
304
 
                                        foreach (string p in subp.Split ('/')) {
305
 
                                                if (p.Length == 0) continue;
306
 
                                                node = nodes [p];
307
 
                                                if (node == null)
308
 
                                                        break;
309
 
                                                nodes = node.ChildNodes;
310
 
                                        }
311
 
                                        if (node != null)
312
 
                                                return node;
313
 
                                }
314
 
                        }
315
 
                        
316
 
                        if (!lookInDeps || OwnerDatabase == null)
317
 
                                return null;
318
 
                        
319
 
                        // Look in dependencies
320
 
                        
321
 
                        foreach (Dependency dep in MainModule.Dependencies) {
322
 
                                AddinDependency adep = dep as AddinDependency;
323
 
                                if (adep == null) continue;
324
 
                                Addin ad = OwnerDatabase.GetInstalledAddin (Domain, adep.FullAddinId);
325
 
                                if (ad != null && ad.Description != null) {
326
 
                                        ExtensionNodeDescription node = ad.Description.FindExtensionNode (path, false);
327
 
                                        if (node != null)
328
 
                                                return node;
329
 
                                }
330
 
                        }
331
 
                        return null;
332
 
                }
333
 
                
334
 
                XmlElement RootElement {
335
 
                        get {
336
 
                                if (configDoc != null)
337
 
                                        return configDoc.DocumentElement;
338
 
                                else
339
 
                                        return null;
340
 
                        }
341
 
                }
342
 
                
343
 
                public string FileName {
344
 
                        get { return configFile; }
345
 
                        set { configFile = value; }
346
 
                }
347
 
                
348
 
                internal string Domain {
349
 
                        get { return domain; }
350
 
                        set { domain = value; }
351
 
                }
352
 
                
353
 
                internal void StoreFileInfo ()
354
 
                {
355
 
                        ArrayList list = new ArrayList ();
356
 
                        foreach (string f in AllFiles) {
357
 
                                string file = Path.Combine (this.BasePath, f);
358
 
                                AddinFileInfo fi = new AddinFileInfo ();
359
 
                                fi.FileName = f;
360
 
                                fi.Timestamp = File.GetLastWriteTime (file);
361
 
                                list.Add (fi);
362
 
                        }
363
 
                        fileInfo = list.ToArray ();
364
 
                }
365
 
                
366
 
                internal bool FilesChanged ()
367
 
                {
368
 
                        // Checks if the files of the add-in have changed.
369
 
                        if (fileInfo == null)
370
 
                                return true;
371
 
                        
372
 
                        foreach (AddinFileInfo f in fileInfo) {
373
 
                                string file = Path.Combine (this.BasePath, f.FileName);
374
 
                                if (!File.Exists (file))
375
 
                                        return true;
376
 
                                if (f.Timestamp != File.GetLastWriteTime (file))
377
 
                                        return true;
378
 
                        }
379
 
                        
380
 
                        return false;
381
 
                }
382
 
                
383
 
                public void Save (string fileName)
384
 
                {
385
 
                        configFile = fileName;
386
 
                        Save ();
387
 
                }
388
 
                
389
 
                public void Save ()
390
 
                {
391
 
                        if (configFile == null)
392
 
                                throw new InvalidOperationException ("File name not specified.");
393
 
                        
394
 
                        SaveXml ();
395
 
 
396
 
                        using (StreamWriter sw = new StreamWriter (configFile)) {
397
 
                                XmlTextWriter tw = new XmlTextWriter (sw);
398
 
                                tw.Formatting = Formatting.Indented;
399
 
                                configDoc.Save (tw);
400
 
                        }
401
 
                }
402
 
                
403
 
                public XmlDocument SaveToXml ()
404
 
                {
405
 
                        SaveXml ();
406
 
                        return configDoc;
407
 
                }
408
 
                
409
 
                void SaveXml ()
410
 
                {
411
 
                        if (!canWrite)
412
 
                                throw new InvalidOperationException ("Can't write incomplete description.");
413
 
                        
414
 
                        XmlElement elem;
415
 
                        
416
 
                        if (configDoc == null) {
417
 
                                configDoc = new XmlDocument ();
418
 
                                configDoc.AppendChild (configDoc.CreateElement ("Addin"));
419
 
                        }
420
 
                        
421
 
                        elem = configDoc.DocumentElement;
422
 
                        
423
 
                        if (HasUserId)
424
 
                                elem.SetAttribute ("id", id);
425
 
                        else
426
 
                                elem.RemoveAttribute ("id");
427
 
                        
428
 
                        elem.SetAttribute ("version", version);
429
 
                        elem.SetAttribute ("namespace", ns);
430
 
                        
431
 
                        if (isroot)
432
 
                                elem.SetAttribute ("isroot", "true");
433
 
                        else
434
 
                                elem.RemoveAttribute ("isroot");
435
 
                        
436
 
                        // Name will return the file name when HasUserId=false
437
 
                        if (Name.Length > 0)
438
 
                                elem.SetAttribute ("name", Name);
439
 
                        else
440
 
                                elem.RemoveAttribute ("name");
441
 
                                
442
 
                        if (compatVersion != null && compatVersion.Length > 0)
443
 
                                elem.SetAttribute ("compatVersion", compatVersion);
444
 
                        else
445
 
                                elem.RemoveAttribute ("compatVersion");
446
 
                        
447
 
                        if (defaultEnabled)
448
 
                                elem.RemoveAttribute ("defaultEnabled");
449
 
                        else
450
 
                                elem.SetAttribute ("defaultEnabled", "false");
451
 
                                
452
 
                        if (author != null && author.Length > 0)
453
 
                                elem.SetAttribute ("author", author);
454
 
                        else
455
 
                                elem.RemoveAttribute ("author");
456
 
                                
457
 
                        if (url != null && url.Length > 0)
458
 
                                elem.SetAttribute ("url", url);
459
 
                        else
460
 
                                elem.RemoveAttribute ("url");
461
 
                                
462
 
                        if (copyright != null && copyright.Length > 0)
463
 
                                elem.SetAttribute ("copyright", copyright);
464
 
                        else
465
 
                                elem.RemoveAttribute ("copyright");
466
 
                                
467
 
                        if (description != null && description.Length > 0)
468
 
                                elem.SetAttribute ("description", description);
469
 
                        else
470
 
                                elem.RemoveAttribute ("description");
471
 
                                
472
 
                        if (category != null && category.Length > 0)
473
 
                                elem.SetAttribute ("category", category);
474
 
                        else
475
 
                                elem.RemoveAttribute ("category");
476
 
                        
477
 
                        if (localizer == null || localizer.Element == null) {
478
 
                                // Remove old element if it exists
479
 
                                XmlElement oldLoc = (XmlElement) elem.SelectSingleNode ("Localizer");
480
 
                                if (oldLoc != null)
481
 
                                        elem.RemoveChild (oldLoc);
482
 
                        }
483
 
                        if (localizer != null)
484
 
                                localizer.SaveXml (elem);
485
 
                        
486
 
                        if (mainModule != null) {
487
 
                                mainModule.Element = elem;
488
 
                                mainModule.SaveXml (elem);
489
 
                        }
490
 
                                
491
 
                        if (optionalModules != null)
492
 
                                optionalModules.SaveXml (elem);
493
 
                                
494
 
                        if (nodeSets != null)
495
 
                                nodeSets.SaveXml (elem);
496
 
                                
497
 
                        if (extensionPoints != null)
498
 
                                extensionPoints.SaveXml (elem);
499
 
                }
500
 
                
501
 
 
502
 
                public static AddinDescription Read (string configFile)
503
 
                {
504
 
                        AddinDescription config;
505
 
                        using (Stream s = File.OpenRead (configFile)) {
506
 
                                config = Read (s, Path.GetDirectoryName (configFile));
507
 
                        }
508
 
                        config.configFile = configFile;
509
 
                        return config;
510
 
                }
511
 
                
512
 
                public static AddinDescription Read (Stream stream, string basePath)
513
 
                {
514
 
                        AddinDescription config = new AddinDescription ();
515
 
                        
516
 
                        try {
517
 
                                config.configDoc = new XmlDocument ();
518
 
                                config.configDoc.Load (stream);
519
 
                        } catch (Exception ex) {
520
 
                                throw new InvalidOperationException ("The add-in configuration file is invalid: " + ex.Message, ex);
521
 
                        }
522
 
                        
523
 
                        XmlElement elem = config.configDoc.DocumentElement;
524
 
                        config.id = elem.GetAttribute ("id");
525
 
                        config.ns = elem.GetAttribute ("namespace");
526
 
                        config.name = elem.GetAttribute ("name");
527
 
                        config.version = elem.GetAttribute ("version");
528
 
                        config.compatVersion = elem.GetAttribute ("compatVersion");
529
 
                        config.author = elem.GetAttribute ("author");
530
 
                        config.url = elem.GetAttribute ("url");
531
 
                        config.copyright = elem.GetAttribute ("copyright");
532
 
                        config.description = elem.GetAttribute ("description");
533
 
                        config.category = elem.GetAttribute ("category");
534
 
                        config.basePath = elem.GetAttribute ("basePath");
535
 
                        
536
 
                        string s = elem.GetAttribute ("isRoot");
537
 
                        if (s.Length == 0) s = elem.GetAttribute ("isroot");
538
 
                        config.isroot = s == "true" || s == "yes";
539
 
                        
540
 
                        s = elem.GetAttribute ("defaultEnabled");
541
 
                        config.defaultEnabled = s.Length == 0 || s == "true" || s == "yes";
542
 
                        
543
 
                        XmlElement localizerElem = (XmlElement) elem.SelectSingleNode ("Localizer");
544
 
                        if (localizerElem != null)
545
 
                                config.localizer = new ExtensionNodeDescription (localizerElem);
546
 
                        
547
 
                        if (config.id.Length > 0)
548
 
                                config.hasUserId = true;
549
 
                        
550
 
                        return config;
551
 
                }
552
 
                
553
 
                internal static AddinDescription ReadBinary (FileDatabase fdb, string configFile)
554
 
                {
555
 
                        AddinDescription description = (AddinDescription) fdb.ReadSharedObject (configFile, typeMap);
556
 
                        if (description != null) {
557
 
                                description.FileName = configFile;
558
 
                                description.canWrite = !fdb.IgnoreDescriptionData;
559
 
                        }
560
 
                        return description;
561
 
                }
562
 
                
563
 
                internal void SaveBinary (FileDatabase fdb, string file)
564
 
                {
565
 
                        configFile = file;
566
 
                        SaveBinary (fdb);
567
 
                }
568
 
                
569
 
                internal void SaveBinary (FileDatabase fdb)
570
 
                {
571
 
                        if (!canWrite)
572
 
                                throw new InvalidOperationException ("Can't write incomplete description.");
573
 
                        fdb.WriteSharedObject (AddinFile, FileName, typeMap, this);
574
 
//                      BinaryXmlReader.DumpFile (configFile);
575
 
                }
576
 
                
577
 
                public StringCollection Verify ()
578
 
                {
579
 
                        StringCollection errors = new StringCollection ();
580
 
                        
581
 
                        if (IsRoot) {
582
 
                                if (OptionalModules.Count > 0)
583
 
                                        errors.Add ("Root add-in hosts can't have optional modules.");
584
 
                        }
585
 
                        
586
 
                        if (AddinId.Length == 0 || Version.Length == 0) {
587
 
                                if (ExtensionPoints.Count > 0)
588
 
                                        errors.Add ("Add-ins which define new extension points must have an Id and Version.");
589
 
                        }
590
 
 
591
 
                        MainModule.Verify ("", errors);
592
 
                        OptionalModules.Verify ("", errors);
593
 
                        ExtensionNodeSets.Verify ("", errors);
594
 
                        ExtensionPoints.Verify ("", errors);
595
 
                        ConditionTypes.Verify ("", errors);
596
 
                        
597
 
                        foreach (ExtensionNodeSet nset in ExtensionNodeSets) {
598
 
                                if (nset.Id.Length == 0)
599
 
                                        errors.Add ("Attribute 'id' can't be empty for global node sets.");
600
 
                        }
601
 
                        
602
 
                        string bp = null;
603
 
                        if (BasePath.Length > 0)
604
 
                                bp = BasePath;
605
 
                        else if (sourceAddinFile != null && sourceAddinFile.Length > 0)
606
 
                                bp = Path.GetDirectoryName (AddinFile);
607
 
                        else if (configFile != null && configFile.Length > 0)
608
 
                                bp = Path.GetDirectoryName (configFile);
609
 
                                
610
 
                        if (bp != null) {
611
 
                                foreach (string file in AllFiles) {
612
 
                                        string asmFile = Path.Combine (BasePath, file);
613
 
                                        if (!File.Exists (asmFile))
614
 
                                                errors.Add ("The file '" + file + "' referenced in the manifest could not be found.");
615
 
                                }
616
 
                        }
617
 
                        
618
 
                        if (localizer != null && localizer.GetAttribute ("type").Length == 0) {
619
 
                                errors.Add ("The attribute 'type' in the Location element is required.");
620
 
                        }
621
 
                        
622
 
                        return errors;
623
 
                }
624
 
                
625
 
                internal void SetExtensionsAddinId (string addinId)
626
 
                {
627
 
                        foreach (ExtensionPoint ep in ExtensionPoints)
628
 
                                ep.SetExtensionsAddinId (addinId);
629
 
                                
630
 
                        foreach (ExtensionNodeSet ns in ExtensionNodeSets)
631
 
                                ns.SetExtensionsAddinId (addinId);
632
 
                }
633
 
                
634
 
                internal void UnmergeExternalData (Hashtable addins)
635
 
                {
636
 
                        // Removes extension types and extension sets coming from other add-ins.
637
 
                        foreach (ExtensionPoint ep in ExtensionPoints)
638
 
                                ep.UnmergeExternalData (AddinId, addins);
639
 
                                
640
 
                        foreach (ExtensionNodeSet ns in ExtensionNodeSets)
641
 
                                ns.UnmergeExternalData (AddinId, addins);
642
 
                }
643
 
                
644
 
                internal void MergeExternalData (AddinDescription other)
645
 
                {
646
 
                        // Removes extension types and extension sets coming from other add-ins.
647
 
                        foreach (ExtensionPoint ep in other.ExtensionPoints) {
648
 
                                ExtensionPoint tep = ExtensionPoints [ep.Path];
649
 
                                if (tep != null)
650
 
                                        tep.MergeWith (AddinId, ep);
651
 
                        }
652
 
                                
653
 
                        foreach (ExtensionNodeSet ns in other.ExtensionNodeSets) {
654
 
                                ExtensionNodeSet tns = ExtensionNodeSets [ns.Id];
655
 
                                if (tns != null)
656
 
                                        tns.MergeWith (AddinId, ns);
657
 
                        }
658
 
                }
659
 
                
660
 
                void IBinaryXmlElement.Write (BinaryXmlWriter writer)
661
 
                {
662
 
                        writer.WriteValue ("id", id);
663
 
                        writer.WriteValue ("ns", ns);
664
 
                        writer.WriteValue ("isroot", isroot);
665
 
                        writer.WriteValue ("name", name);
666
 
                        writer.WriteValue ("version", version);
667
 
                        writer.WriteValue ("compatVersion", compatVersion);
668
 
                        writer.WriteValue ("hasUserId", hasUserId);
669
 
                        writer.WriteValue ("author", author);
670
 
                        writer.WriteValue ("url", url);
671
 
                        writer.WriteValue ("copyright", copyright);
672
 
                        writer.WriteValue ("description", description);
673
 
                        writer.WriteValue ("category", category);
674
 
                        writer.WriteValue ("basePath", basePath);
675
 
                        writer.WriteValue ("sourceAddinFile", sourceAddinFile);
676
 
                        writer.WriteValue ("defaultEnabled", defaultEnabled);
677
 
                        writer.WriteValue ("domain", domain);
678
 
                        writer.WriteValue ("MainModule", MainModule);
679
 
                        writer.WriteValue ("OptionalModules", OptionalModules);
680
 
                        writer.WriteValue ("NodeSets", ExtensionNodeSets);
681
 
                        writer.WriteValue ("ExtensionPoints", ExtensionPoints);
682
 
                        writer.WriteValue ("ConditionTypes", ConditionTypes);
683
 
                        writer.WriteValue ("FilesInfo", fileInfo);
684
 
                        writer.WriteValue ("Localizer", localizer);
685
 
                }
686
 
                
687
 
                void IBinaryXmlElement.Read (BinaryXmlReader reader)
688
 
                {
689
 
                        id = reader.ReadStringValue ("id");
690
 
                        ns = reader.ReadStringValue ("ns");
691
 
                        isroot = reader.ReadBooleanValue ("isroot");
692
 
                        name = reader.ReadStringValue ("name");
693
 
                        version = reader.ReadStringValue ("version");
694
 
                        compatVersion = reader.ReadStringValue ("compatVersion");
695
 
                        hasUserId = reader.ReadBooleanValue ("hasUserId");
696
 
                        author = reader.ReadStringValue ("author");
697
 
                        url = reader.ReadStringValue ("url");
698
 
                        copyright = reader.ReadStringValue ("copyright");
699
 
                        description = reader.ReadStringValue ("description");
700
 
                        category = reader.ReadStringValue ("category");
701
 
                        basePath = reader.ReadStringValue ("basePath");
702
 
                        sourceAddinFile = reader.ReadStringValue ("sourceAddinFile");
703
 
                        defaultEnabled = reader.ReadBooleanValue ("defaultEnabled");
704
 
                        domain = reader.ReadStringValue ("domain");
705
 
                        mainModule = (ModuleDescription) reader.ReadValue ("MainModule");
706
 
                        optionalModules = (ModuleCollection) reader.ReadValue ("OptionalModules", new ModuleCollection (this));
707
 
                        nodeSets = (ExtensionNodeSetCollection) reader.ReadValue ("NodeSets", new ExtensionNodeSetCollection (this));
708
 
                        extensionPoints = (ExtensionPointCollection) reader.ReadValue ("ExtensionPoints", new ExtensionPointCollection (this));
709
 
                        conditionTypes = (ConditionTypeDescriptionCollection) reader.ReadValue ("ConditionTypes", new ConditionTypeDescriptionCollection (this));
710
 
                        fileInfo = (object[]) reader.ReadValue ("FilesInfo", null);
711
 
                        localizer = (ExtensionNodeDescription) reader.ReadValue ("Localizer");
712
 
                        
713
 
                        if (mainModule != null)
714
 
                                mainModule.SetParent (this);
715
 
                }
716
 
        }
717
 
        
718
 
        class AddinFileInfo: IBinaryXmlElement
719
 
        {
720
 
                string fileName;
721
 
                DateTime timestamp;
722
 
                
723
 
                public string FileName {
724
 
                        get {
725
 
                                return fileName;
726
 
                        }
727
 
                        set {
728
 
                                fileName = value;
729
 
                        }
730
 
                }
731
 
 
732
 
                public System.DateTime Timestamp {
733
 
                        get {
734
 
                                return timestamp;
735
 
                        }
736
 
                        set {
737
 
                                timestamp = value;
738
 
                        }
739
 
                }
740
 
                
741
 
                public void Read (BinaryXmlReader reader)
742
 
                {
743
 
                        fileName = reader.ReadStringValue ("fileName");
744
 
                        timestamp = reader.ReadDateTimeValue ("timestamp");
745
 
                }
746
 
 
747
 
                public void Write (BinaryXmlWriter writer)
748
 
                {
749
 
                        writer.WriteValue ("fileName", fileName);
750
 
                        writer.WriteValue ("timestamp", timestamp);
751
 
                }
752
 
 
753
 
        }
754
 
}