~ubuntu-branches/ubuntu/trusty/keepass2/trusty-proposed

« back to all changes in this revision

Viewing changes to Ext/DeprecatedSources/UpdateCheck_111216.cs

  • Committer: Package Import Robot
  • Author(s): Julian Taylor
  • Date: 2011-12-30 15:45:59 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20111230154559-3en1b9v90hswvs1w
Tags: 2.18+dfsg-1
* New upstream release
  - refresh patches
  - drop upstream applied patches:
    explicitly-PUT-for-webdav-writes.patch
    prefer-4.0-framework-if-available.patch
* add patch to improve autotype when dealing with multiple keyboard layouts
  - Thanks to amiryal for the patch
* disable initial autoupdate popup via patch
* update years in debian/copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  KeePass Password Safe - The Open-Source Password Manager
 
3
  Copyright (C) 2003-2011 Dominik Reichl <dominik.reichl@t-online.de>
 
4
 
 
5
  This program is free software; you can redistribute it and/or modify
 
6
  it under the terms of the GNU General Public License as published by
 
7
  the Free Software Foundation; either version 2 of the License, or
 
8
  (at your option) any later version.
 
9
 
 
10
  This program is distributed in the hope that it will be useful,
 
11
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
  GNU General Public License for more details.
 
14
 
 
15
  You should have received a copy of the GNU General Public License
 
16
  along with this program; if not, write to the Free Software
 
17
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
*/
 
19
 
 
20
using System;
 
21
using System.Collections.Generic;
 
22
using System.Text;
 
23
using System.Net;
 
24
using System.Net.Cache;
 
25
using System.Windows.Forms;
 
26
using System.Xml;
 
27
using System.Diagnostics;
 
28
using System.Threading;
 
29
 
 
30
// using KeePass.Native;
 
31
using KeePass.Resources;
 
32
 
 
33
using KeePassLib;
 
34
using KeePassLib.Resources;
 
35
using KeePassLib.Serialization;
 
36
using KeePassLib.Utility;
 
37
 
 
38
namespace KeePass.Util
 
39
{
 
40
        /* public static class UpdateCheck
 
41
        {
 
42
                private const string ElemRoot = "KeePass";
 
43
 
 
44
                private const string ElemVersionU = "Version32";
 
45
                private const string ElemVersionStr = "VersionDisplayString";
 
46
 
 
47
                private static volatile string m_strVersionURL = string.Empty;
 
48
                private static volatile ToolStripStatusLabel m_tsResultsViewer = null;
 
49
 
 
50
                public static void StartAsync(string strVersionUrl, ToolStripStatusLabel tsResultsViewer)
 
51
                {
 
52
                        m_strVersionURL = strVersionUrl;
 
53
                        m_tsResultsViewer = tsResultsViewer;
 
54
 
 
55
                        // Local, but thread will continue to run anyway
 
56
                        Thread th = new Thread(new ThreadStart(UpdateCheck.OnStartCheck));
 
57
                        th.Start();
 
58
                }
 
59
 
 
60
                private static void OnStartCheck()
 
61
                {
 
62
                        // NativeProgressDialog dlg = null;
 
63
                        // if(m_tsResultsViewer == null)
 
64
                        // {
 
65
                        //      dlg = new NativeProgressDialog();
 
66
                        //      dlg.StartLogging(KPRes.Wait + "...", false);
 
67
                        // }
 
68
 
 
69
                        try
 
70
                        {
 
71
                                IOWebClient webClient = new IOWebClient();
 
72
                                IOConnection.ConfigureWebClient(webClient);
 
73
 
 
74
                                Uri uri = new Uri(m_strVersionURL);
 
75
 
 
76
                                webClient.DownloadDataCompleted +=
 
77
                                        new DownloadDataCompletedEventHandler(OnDownloadCompleted);
 
78
 
 
79
                                webClient.DownloadDataAsync(uri);
 
80
                        }
 
81
                        // catch(NotImplementedException)
 
82
                        // {
 
83
                        //      ReportStatusEx(KLRes.FrameworkNotImplExcp, true);
 
84
                        // }
 
85
                        catch(Exception) { }
 
86
 
 
87
                        // if(dlg != null) dlg.EndLogging();
 
88
                }
 
89
 
 
90
                private static void OnDownloadCompleted(object sender, DownloadDataCompletedEventArgs e)
 
91
                {
 
92
                        string strXmlFile = NetUtil.GZipUtf8ResultToString(e);
 
93
 
 
94
                        if(strXmlFile == null)
 
95
                        {
 
96
                                if(e.Error != null)
 
97
                                {
 
98
                                        if(m_tsResultsViewer == null)
 
99
                                                MessageService.ShowWarning(KPRes.UpdateCheckingFailed, e.Error);
 
100
                                        else if(e.Error.Message != null)
 
101
                                                UpdateCheck.SetTsStatus(KPRes.UpdateCheckingFailed + " " +
 
102
                                                        e.Error.Message);
 
103
                                }
 
104
                                else ReportStatusEx(KPRes.UpdateCheckingFailed, true);
 
105
 
 
106
                                return;
 
107
                        }
 
108
 
 
109
                        XmlDocument xmlDoc = new XmlDocument();
 
110
 
 
111
                        try { xmlDoc.LoadXml(strXmlFile); }
 
112
                        catch(Exception)
 
113
                        {
 
114
                                StructureFail();
 
115
                                return;
 
116
                        }
 
117
 
 
118
                        XmlElement xmlRoot = xmlDoc.DocumentElement;
 
119
                        if(xmlRoot == null) { StructureFail(); return; }
 
120
                        if(xmlRoot.Name != ElemRoot) { StructureFail(); return; }
 
121
 
 
122
                        uint uVersion = 0;
 
123
 
 
124
                        foreach(XmlNode xmlChild in xmlRoot.ChildNodes)
 
125
                        {
 
126
                                if(xmlChild.Name == ElemVersionU)
 
127
                                        uint.TryParse(xmlChild.InnerText, out uVersion);
 
128
                                else if(xmlChild.Name == ElemVersionStr)
 
129
                                {
 
130
                                        // strVersion = xmlChild.InnerText;
 
131
                                }
 
132
                        }
 
133
 
 
134
                        if(uVersion > PwDefs.Version32)
 
135
                        {
 
136
                                if(m_tsResultsViewer == null)
 
137
                                {
 
138
                                        if(MessageService.AskYesNo(KPRes.ChkForUpdNewVersion +
 
139
                                                MessageService.NewParagraph + KPRes.WebsiteVisitQuestion))
 
140
                                        {
 
141
                                                WinUtil.OpenUrl(PwDefs.HomepageUrl, null);
 
142
                                        }
 
143
                                }
 
144
                                else UpdateCheck.SetTsStatus(KPRes.ChkForUpdNewVersion);
 
145
                        }
 
146
                        else if(uVersion == PwDefs.Version32)
 
147
                                ReportStatusEx(KPRes.ChkForUpdGotLatest, false);
 
148
                        else
 
149
                                ReportStatusEx(KPRes.UnknownFileVersion, true);
 
150
                }
 
151
 
 
152
                private static void ReportStatusEx(string strText, bool bIsWarning)
 
153
                {
 
154
                        ReportStatusEx(strText, strText, bIsWarning);
 
155
                }
 
156
 
 
157
                private static void ReportStatusEx(string strLongText, string strShortText,
 
158
                        bool bIsWarning)
 
159
                {
 
160
                        if(m_tsResultsViewer == null)
 
161
                        {
 
162
                                if(bIsWarning) MessageService.ShowWarning(strLongText);
 
163
                                else MessageService.ShowInfo(strLongText);
 
164
                        }
 
165
                        else UpdateCheck.SetTsStatus(strShortText);
 
166
                }
 
167
 
 
168
                private static void StructureFail()
 
169
                {
 
170
                        Debug.Assert(false);
 
171
 
 
172
                        if(m_tsResultsViewer == null)
 
173
                                MessageService.ShowWarning(KPRes.InvalidFileStructure);
 
174
                        else
 
175
                                UpdateCheck.SetTsStatus(KPRes.ChkForUpdGotLatest + " " +
 
176
                                        KPRes.InvalidFileStructure);
 
177
                }
 
178
 
 
179
                private static void SetTsStatus(string strText)
 
180
                {
 
181
                        if(strText == null) { Debug.Assert(false); return; }
 
182
                        if(m_tsResultsViewer == null) { Debug.Assert(false); return; }
 
183
 
 
184
                        try
 
185
                        {
 
186
                                ToolStrip pParent = m_tsResultsViewer.Owner;
 
187
                                if((pParent != null) && pParent.InvokeRequired)
 
188
                                {
 
189
                                        pParent.Invoke(new Priv_CfuSsd(UpdateCheck.SetTsStatusDirect),
 
190
                                                new object[] { strText });
 
191
                                }
 
192
                                else UpdateCheck.SetTsStatusDirect(strText);
 
193
                        }
 
194
                        catch(Exception) { Debug.Assert(false); }
 
195
                }
 
196
 
 
197
                public delegate void Priv_CfuSsd(string strText);
 
198
 
 
199
                private static void SetTsStatusDirect(string strText)
 
200
                {
 
201
                        try { m_tsResultsViewer.Text = strText; }
 
202
                        catch(Exception) { Debug.Assert(false); }
 
203
                }
 
204
        } */
 
205
}