~ubuntu-branches/ubuntu/lucid/monodevelop/lucid

« back to all changes in this revision

Viewing changes to src/addins/MacPlatform/MacUpdater.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2010-02-02 11:39:59 UTC
  • mfrom: (1.2.6 upstream) (1.3.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100202113959-s4exdz7er7igylz2
Tags: 2.2.1+dfsg-1
* New upstream release
* debian/control:
  + Standards version 3.8.4 (no changes needed)
* debian/patches/remove_support_for_non_debian_functionality.patch,
  debian/patches/remove_support_for_soft_debugger.patch,
  debian/patches/remove_support_for_moonlight.patch,
  debian/rules:
  + Split patch into two pieces, to make it easier to enable either
    SDB or Moonlight support with a rebuild
* debian/monodevelop-moonlight.install,
  debian/monodevelop-debugger-sdb.install,
  debian/control:
  + Create packaging data for the Soft Debugger addin and Moonlight addin -
    and comment them out of debian/control as we can't provide them on
    Debian for now

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// 
2
 
// MacUpdater.cs
3
 
//  
4
 
// Author:
5
 
//       Michael Hutchinson <mhutchinson@novell.com>
6
 
// 
7
 
// Copyright (c) 2009 Novell, Inc. (http://www.novell.com)
8
 
// 
9
 
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
 
// of this software and associated documentation files (the "Software"), to deal
11
 
// in the Software without restriction, including without limitation the rights
12
 
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
 
// copies of the Software, and to permit persons to whom the Software is
14
 
// furnished to do so, subject to the following conditions:
15
 
// 
16
 
// The above copyright notice and this permission notice shall be included in
17
 
// all copies or substantial portions of the Software.
18
 
// 
19
 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
 
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
 
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
 
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
 
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
 
// THE SOFTWARE.
26
 
 
27
 
using System;
28
 
using System.Linq;
29
 
using System.IO;
30
 
using System.Text;
31
 
using MonoDevelop.Core;
32
 
using System.Net;
33
 
using MonoDevelop.Core.Gui;
34
 
using System.Collections.Generic;
35
 
 
36
 
namespace MonoDevelop.Platform
37
 
{
38
 
 
39
 
        public static class AppUpdater
40
 
        {
41
 
                const int formatVersion = 1;
42
 
                const string updateAutoPropertyKey = "AppUpdater.CheckAutomatically";
43
 
                
44
 
                static UpdateInfo[] updateInfos;
45
 
                
46
 
                //FIXME: populate from an extension point
47
 
                public static UpdateInfo[] DefaultUpdateInfos {
48
 
                        get {
49
 
                                if (updateInfos == null) {
50
 
                                        var files = new string[] {
51
 
                                                "/Developer/MonoTouch/updateinfo",
52
 
                                                "/Developer/MonoTouch/Source/updateinfo",
53
 
                                                "/Library/Frameworks/Mono.framework/Versions/Current/updateinfo",
54
 
                                                "/Library/Frameworks/Mono.framework/Versions/Current/updateinfo.csdk",
55
 
                                                Path.GetDirectoryName (typeof (MacPlatform).Assembly.Location) + "/../../../updateinfo",
56
 
                                        }.Where (File.Exists);
57
 
                                        
58
 
                                        var list = new List<UpdateInfo> ();
59
 
                                        foreach (string file in files) {
60
 
                                                try {
61
 
                                                        list.Add (UpdateInfo.FromFile (file));
62
 
                                                } catch (Exception ex) {
63
 
                                                        LoggingService.LogError ("Error reading update info file '" + file + "'", ex);
64
 
                                                }
65
 
                                        }
66
 
                                        updateInfos = list.ToArray ();
67
 
                                }
68
 
                                
69
 
                                return updateInfos;
70
 
                        }
71
 
                }
72
 
                
73
 
                public static bool CheckAutomatically {
74
 
                        get {
75
 
                                return PropertyService.Get<bool> (updateAutoPropertyKey, true);
76
 
                        }
77
 
                        set {
78
 
                                PropertyService.Set (updateAutoPropertyKey, value);
79
 
                        }
80
 
                }
81
 
                
82
 
                public static void RunCheck (bool automatic)
83
 
                {
84
 
                        RunCheck (DefaultUpdateInfos, automatic);
85
 
                }
86
 
                
87
 
                public static void RunCheck (UpdateInfo[] updateInfos, bool automatic)
88
 
                {
89
 
                        if (updateInfos == null || updateInfos.Length == 0 || (automatic && !CheckAutomatically))
90
 
                                return;
91
 
                        
92
 
                        var query = new StringBuilder ("http://go-mono.com/macupdate/update?v=");
93
 
                        query.Append (formatVersion);
94
 
                        foreach (var info in updateInfos)
95
 
                                query.AppendFormat ("&{0}={1}", info.AppId, info.VersionId);
96
 
                        
97
 
                        if (!string.IsNullOrEmpty (Environment.GetEnvironmentVariable ("MONODEVELOP_UPDATER_TEST")))
98
 
                                query.Append ("&test=1");
99
 
                        
100
 
                        var request = (HttpWebRequest) WebRequest.Create (query.ToString ());
101
 
                        
102
 
                        //FIXME: use IfModifiedSince
103
 
                        //request.IfModifiedSince = somevalue;
104
 
                        
105
 
                        request.BeginGetResponse (delegate (IAsyncResult ar) {
106
 
                                ReceivedResponse (request, ar, automatic);
107
 
                        }, null);
108
 
                }
109
 
                
110
 
                static void ReceivedResponse (HttpWebRequest request, IAsyncResult ar, bool automatic)
111
 
                {
112
 
                        try {
113
 
                                using (var response = (HttpWebResponse) request.EndGetResponse (ar)) {
114
 
                                        var encoding = Encoding.GetEncoding (response.CharacterSet);
115
 
                                        using (var reader = new StreamReader (response.GetResponseStream(), encoding)) {
116
 
                                                var doc = System.Xml.Linq.XDocument.Load (reader);
117
 
                                                var updates = (from x in doc.Root.Elements ("Application")
118
 
                                                        let first = x.Elements ("Update").First ()
119
 
                                                        select new Update () {
120
 
                                                                Name = x.Attribute ("name").Value,
121
 
                                                                Url = first.Attribute ("url").Value,
122
 
                                                                Version = first.Attribute ("version").Value,
123
 
                                                                Date = DateTime.Parse (first.Attribute ("date").Value),
124
 
                                                                Releases = x.Elements ("Update").Select (y => new Release () {
125
 
                                                                        Version = y.Attribute ("version").Value,
126
 
                                                                        Date = DateTime.Parse (y.Attribute ("date").Value),
127
 
                                                                        Notes = y.Value
128
 
                                                                }).ToList ()
129
 
                                                        }).ToList ();
130
 
                                                
131
 
                                                if (!automatic || (updates != null && updates.Count > 0)) {
132
 
                                                        Gtk.Application.Invoke (delegate {
133
 
                                                                MessageService.ShowCustomDialog (new UpdateDialog (updates));
134
 
                                                        });
135
 
                                                }
136
 
                                        }
137
 
                                }
138
 
                        } catch (WebException ex) {
139
 
                                LoggingService.LogError ("Error retrieving update information", ex);
140
 
                                if (!automatic)
141
 
                                        MessageService.ShowException (ex, GettextCatalog.GetString ("Error retrieving update information"));
142
 
                        } catch (Exception ex) {
143
 
                                LoggingService.LogError ("Error retrieving update information", ex);
144
 
                                if (!automatic)
145
 
                                        MessageService.ShowException (ex, GettextCatalog.GetString ("Error retrieving update information"));
146
 
                        }
147
 
                }
148
 
                
149
 
                public class Update
150
 
                {
151
 
                        public string Name;
152
 
                        public string Url;
153
 
                        public string Version;
154
 
                        public DateTime Date;
155
 
                        public List<Release> Releases;
156
 
                }
157
 
                
158
 
                public class Release
159
 
                {
160
 
                        public string Version;
161
 
                        public DateTime Date;
162
 
                        public string Notes;
163
 
                }
164
 
                
165
 
                public class UpdateInfo
166
 
                {
167
 
                        UpdateInfo ()
168
 
                        {
169
 
                        }
170
 
                        
171
 
                        public UpdateInfo (Guid appId, long versionId)
172
 
                        {
173
 
                                this.AppId = appId;
174
 
                                this.VersionId = versionId;
175
 
                        }
176
 
                        
177
 
                        public readonly Guid AppId;
178
 
                        public readonly long VersionId;
179
 
                        
180
 
                        public static UpdateInfo FromFile (string fileName)
181
 
                        {
182
 
                                using (var f = File.OpenText (fileName)) {
183
 
                                        var s = f.ReadLine ();
184
 
                                        var parts = s.Split (' ');
185
 
                                        return new UpdateInfo (new Guid (parts[0]), long.Parse (parts[1]));
186
 
                                }
187
 
                        }
188
 
                }
189
 
        }
190
 
}