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

« back to all changes in this revision

Viewing changes to Mono.Addins/Mono.Addins.Setup/Mono.Addins.Setup/AddinPackage.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
 
// AddinPackage.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.Reflection;
35
 
using System.Diagnostics;
36
 
using System.Collections.Specialized;
37
 
using System.Net;
38
 
 
39
 
using ICSharpCode.SharpZipLib.Zip;
40
 
using Mono.Addins;
41
 
using Mono.Addins.Description;
42
 
 
43
 
namespace Mono.Addins.Setup
44
 
{
45
 
        internal class AddinPackage: Package
46
 
        {
47
 
                AddinInfo info;
48
 
                string packFile;
49
 
                string url;
50
 
                string tempFolder;
51
 
                string configFile;
52
 
                bool installed;
53
 
                Addin iaddin;
54
 
                
55
 
                public AddinHeader Addin {
56
 
                        get { return info; }
57
 
                }
58
 
                
59
 
                public override string Name {
60
 
                        get { return info.Name + " v" + info.Version; }
61
 
                }
62
 
                
63
 
                public static AddinPackage PackageFromRepository (AddinRepositoryEntry repAddin)
64
 
                {
65
 
                        AddinPackage pack = new AddinPackage ();
66
 
                        pack.info = (AddinInfo) repAddin.Addin;
67
 
                        pack.url = new Uri (new Uri (repAddin.RepositoryUrl), repAddin.Url).ToString ();
68
 
                        return pack;
69
 
                }
70
 
                
71
 
                public static AddinPackage PackageFromFile (string file)
72
 
                {
73
 
                        AddinPackage pack = new AddinPackage ();
74
 
                        pack.info = ReadAddinInfo (file);
75
 
                        pack.packFile = file;
76
 
                        return pack;
77
 
                }
78
 
                
79
 
                public static AddinPackage FromInstalledAddin (Addin sinfo)
80
 
                {
81
 
                        AddinPackage pack = new AddinPackage ();
82
 
                        pack.info = AddinInfo.ReadFromDescription (sinfo.Description);
83
 
                        return pack;
84
 
                }
85
 
                
86
 
                static AddinInfo ReadAddinInfo (string file)
87
 
                {
88
 
                        ZipFile zfile = new ZipFile (file);
89
 
                        foreach (ZipEntry ze in zfile) {
90
 
                                if (ze.Name == "addin.info") {
91
 
                                        using (Stream s = zfile.GetInputStream (ze)) {
92
 
                                                return AddinInfo.ReadFromAddinFile (new StreamReader (s));
93
 
                                        }
94
 
                                }
95
 
                        }
96
 
                        throw new InstallException ("Addin configuration file not found in package.");
97
 
                }
98
 
                
99
 
                internal override bool IsUpgradeOf (Package p)
100
 
                {
101
 
                        AddinPackage ap = p as AddinPackage;
102
 
                        if (ap == null) return false;
103
 
                        return info.SupportsVersion (ap.info.Version);
104
 
                }
105
 
                
106
 
                public override bool Equals (object ob)
107
 
                {
108
 
                        AddinPackage ap = ob as AddinPackage;
109
 
                        if (ap == null) return false;
110
 
                        return ap.info.Id == info.Id && ap.info.Version == info.Version;
111
 
                }
112
 
                
113
 
                public override int GetHashCode ()
114
 
                {
115
 
                        return (info.Id + info.Version).GetHashCode ();
116
 
                }
117
 
                
118
 
                internal override void PrepareInstall (IProgressMonitor monitor, AddinStore service)
119
 
                {
120
 
                        if (service.Registry.GetAddin (Mono.Addins.Addin.GetFullId (info.Namespace, info.Id, info.Version), true) != null)
121
 
                                throw new InstallException ("The addin " + info.Name + " v" + info.Version + " is already installed.");
122
 
                                                
123
 
                        if (url != null)
124
 
                                packFile = service.DownloadFile (monitor, url);
125
 
                        
126
 
                        tempFolder = CreateTempFolder ();
127
 
 
128
 
                        // Extract the files                    
129
 
                        using (FileStream fs = new FileStream (packFile, FileMode.Open, FileAccess.Read)) {
130
 
                                ZipFile zip = new ZipFile (fs);
131
 
                                foreach (ZipEntry entry in zip) {
132
 
                                        string path = Path.Combine (tempFolder, entry.Name);
133
 
                                        string dir = Path.GetDirectoryName (path);
134
 
                                        if (!Directory.Exists (dir))
135
 
                                                Directory.CreateDirectory (dir);
136
 
                                                
137
 
                                        byte[] buffer = new byte [8192];
138
 
                                        int n=0;
139
 
                                        Stream inStream = zip.GetInputStream (entry);
140
 
                                        Stream outStream = null;
141
 
                                        try {
142
 
                                                outStream = File.Create (path);
143
 
                                                while ((n = inStream.Read (buffer, 0, buffer.Length)) > 0)
144
 
                                                        outStream.Write (buffer, 0, n);
145
 
                                        } finally {
146
 
                                                inStream.Close ();
147
 
                                                if (outStream != null)
148
 
                                                        outStream.Close ();
149
 
                                        }
150
 
                                }
151
 
                        }
152
 
                        
153
 
                        foreach (string s in Directory.GetFiles (tempFolder)) {
154
 
                                if (Path.GetFileName (s) == "addin.info") {
155
 
                                        configFile = s;
156
 
                                        break;
157
 
                                }
158
 
                        }
159
 
 
160
 
                        if (configFile == null)
161
 
                                throw new InstallException ("Add-in information file not found in package.");
162
 
                }
163
 
                
164
 
                internal override void CommitInstall (IProgressMonitor monitor, AddinStore service)
165
 
                {
166
 
                        service.RegisterAddin (monitor, info, tempFolder);
167
 
                        installed = true;
168
 
                }
169
 
                
170
 
                internal override void RollbackInstall (IProgressMonitor monitor, AddinStore service)
171
 
                {
172
 
                        if (installed) {
173
 
                                iaddin = service.Registry.GetAddin (info.Id);
174
 
                                if (iaddin != null)
175
 
                                        CommitUninstall (monitor, service);
176
 
                        }
177
 
                }
178
 
                
179
 
                internal override void EndInstall (IProgressMonitor monitor, AddinStore service)
180
 
                {
181
 
                        if (url != null && packFile != null)
182
 
                                File.Delete (packFile);
183
 
                        if (tempFolder != null)
184
 
                                Directory.Delete (tempFolder, true);
185
 
                }
186
 
                
187
 
                internal override void Resolve (IProgressMonitor monitor, AddinStore service, PackageCollection toInstall, PackageCollection toUninstall, PackageCollection installedRequired, DependencyCollection unresolved)
188
 
                {
189
 
                        Addin ia = service.Registry.GetAddin (Mono.Addins.Addin.GetIdName (info.Id));
190
 
                        
191
 
                        if (ia != null) {
192
 
                                Package p = AddinPackage.FromInstalledAddin (ia);
193
 
                                if (!toUninstall.Contains (p))
194
 
                                        toUninstall.Add (p);
195
 
                                        
196
 
                                if (!info.SupportsVersion (ia.Version)) {
197
 
                                
198
 
                                        // This addin breaks the api of the currently installed one,
199
 
                                        // it has to be removed, together with all dependencies
200
 
                                        
201
 
                                        Addin[] ainfos = service.GetDependentAddins (info.Id, true);
202
 
                                        foreach (Addin ainfo in ainfos) {
203
 
                                                p = AddinPackage.FromInstalledAddin (ainfo);
204
 
                                                if (!toUninstall.Contains (p))
205
 
                                                        toUninstall.Add (p);
206
 
                                        }
207
 
                                }
208
 
                        }
209
 
                        
210
 
                        foreach (Dependency dep in info.Dependencies) {
211
 
                                service.ResolveDependency (monitor, dep, this, toInstall, toUninstall, installedRequired, unresolved);
212
 
                        }
213
 
                }
214
 
                
215
 
                internal override void PrepareUninstall (IProgressMonitor monitor, AddinStore service)
216
 
                {
217
 
                        iaddin = service.Registry.GetAddin (info.Id, true);
218
 
                        if (iaddin == null)
219
 
                                throw new InstallException (string.Format ("The add-in '{0}' is not installed.", info.Name));
220
 
 
221
 
                        AddinDescription conf = iaddin.Description;
222
 
                        string basePath = Path.GetDirectoryName (conf.AddinFile);
223
 
                        
224
 
                        if (!File.Exists (iaddin.AddinFile)) {
225
 
                                monitor.ReportWarning (string.Format ("The add-in '{0}' is scheduled for uninstalling, but the add-in file could not be found.", info.Name));
226
 
                                return;
227
 
                        }
228
 
                        
229
 
                        if (!service.HasWriteAccess (iaddin.AddinFile))
230
 
                                throw new InstallException (AddinStore.GetUninstallErrorNoRoot (info));
231
 
 
232
 
                        foreach (string relPath in conf.AllFiles) {
233
 
                                string path = Path.Combine (basePath, relPath);
234
 
                                if (!File.Exists (path))
235
 
                                        continue;
236
 
                                if (!service.HasWriteAccess (path))
237
 
                                        throw new InstallException (AddinStore.GetUninstallErrorNoRoot (info));
238
 
                        }
239
 
                        
240
 
                        tempFolder = CreateTempFolder ();
241
 
                        CopyAddinFiles (monitor, conf, iaddin.AddinFile, tempFolder);
242
 
                }
243
 
                
244
 
                internal override void CommitUninstall (IProgressMonitor monitor, AddinStore service)
245
 
                {
246
 
                        if (tempFolder == null)
247
 
                                return;
248
 
 
249
 
                        monitor.Log.WriteLine ("Uninstalling " + info.Name + " v" + info.Version);
250
 
                        
251
 
                        AddinDescription conf = iaddin.Description;
252
 
                        string basePath = Path.GetDirectoryName (conf.AddinFile);
253
 
                        
254
 
                        foreach (string relPath in conf.AllFiles) {
255
 
                                string path = Path.Combine (basePath, relPath);
256
 
                                if (!File.Exists (path))
257
 
                                        continue;
258
 
                                File.Delete (path);
259
 
                        }
260
 
                        
261
 
                        File.Delete (iaddin.AddinFile);
262
 
                        
263
 
                        if (Directory.GetFiles (basePath).Length == 0) {
264
 
                                try {
265
 
                                        Directory.Delete (basePath);
266
 
                                } catch {
267
 
                                        monitor.ReportWarning ("Directory " + basePath + " could not be deleted.");
268
 
                                }
269
 
                        }
270
 
                        
271
 
                        monitor.Log.WriteLine ("Done");
272
 
                }
273
 
                
274
 
                internal override void RollbackUninstall (IProgressMonitor monitor, AddinStore service)
275
 
                {
276
 
                        if (tempFolder != null) {
277
 
                                AddinDescription conf = iaddin.Description;
278
 
                                string configFile = Path.Combine (tempFolder, Path.GetFileName (iaddin.AddinFile));
279
 
                                
280
 
                                string addinDir = Path.GetDirectoryName (iaddin.AddinFile);
281
 
                                CopyAddinFiles (monitor, conf, configFile, addinDir);
282
 
                        }
283
 
                }
284
 
                
285
 
                internal override void EndUninstall (IProgressMonitor monitor, AddinStore service)
286
 
                {
287
 
                        if (tempFolder != null)
288
 
                                Directory.Delete (tempFolder, true);
289
 
                        tempFolder = null;
290
 
                }
291
 
                
292
 
                void CopyAddinFiles (IProgressMonitor monitor, AddinDescription conf, string configFile, string destPath)
293
 
                {
294
 
                        if (!Directory.Exists (destPath))
295
 
                                Directory.CreateDirectory (destPath);
296
 
                        
297
 
                        string dfile = Path.Combine (destPath, Path.GetFileName (configFile));
298
 
                        if (File.Exists (dfile))
299
 
                                File.Delete (dfile);
300
 
                                
301
 
                        File.Copy (configFile, dfile);
302
 
                        
303
 
                        string basePath = Path.GetDirectoryName (configFile);
304
 
                        
305
 
                        foreach (string relPath in conf.AllFiles) {
306
 
                                string path = Path.Combine (basePath, relPath);
307
 
                                if (!File.Exists (path))
308
 
                                        continue;
309
 
                                
310
 
                                string destf = Path.Combine (destPath, Path.GetDirectoryName (relPath));
311
 
                                if (!Directory.Exists (destf))
312
 
                                        Directory.CreateDirectory (destf);
313
 
                                        
314
 
                                dfile = Path.Combine (destPath, relPath);
315
 
                                if (File.Exists (dfile))
316
 
                                        File.Delete (dfile);
317
 
 
318
 
                                File.Copy (path, dfile);
319
 
                        }
320
 
                }
321
 
                
322
 
                
323
 
        }
324
 
}