2
KeePass Password Safe - The Open-Source Password Manager
3
Copyright (C) 2003-2011 Dominik Reichl <dominik.reichl@t-online.de>
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.
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.
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
21
using System.Collections.Generic;
24
using System.Net.Cache;
25
using System.Windows.Forms;
27
using System.Diagnostics;
28
using System.Threading;
30
// using KeePass.Native;
31
using KeePass.Resources;
34
using KeePassLib.Resources;
35
using KeePassLib.Serialization;
36
using KeePassLib.Utility;
38
namespace KeePass.Util
40
/* public static class UpdateCheck
42
private const string ElemRoot = "KeePass";
44
private const string ElemVersionU = "Version32";
45
private const string ElemVersionStr = "VersionDisplayString";
47
private static volatile string m_strVersionURL = string.Empty;
48
private static volatile ToolStripStatusLabel m_tsResultsViewer = null;
50
public static void StartAsync(string strVersionUrl, ToolStripStatusLabel tsResultsViewer)
52
m_strVersionURL = strVersionUrl;
53
m_tsResultsViewer = tsResultsViewer;
55
// Local, but thread will continue to run anyway
56
Thread th = new Thread(new ThreadStart(UpdateCheck.OnStartCheck));
60
private static void OnStartCheck()
62
// NativeProgressDialog dlg = null;
63
// if(m_tsResultsViewer == null)
65
// dlg = new NativeProgressDialog();
66
// dlg.StartLogging(KPRes.Wait + "...", false);
71
IOWebClient webClient = new IOWebClient();
72
IOConnection.ConfigureWebClient(webClient);
74
Uri uri = new Uri(m_strVersionURL);
76
webClient.DownloadDataCompleted +=
77
new DownloadDataCompletedEventHandler(OnDownloadCompleted);
79
webClient.DownloadDataAsync(uri);
81
// catch(NotImplementedException)
83
// ReportStatusEx(KLRes.FrameworkNotImplExcp, true);
87
// if(dlg != null) dlg.EndLogging();
90
private static void OnDownloadCompleted(object sender, DownloadDataCompletedEventArgs e)
92
string strXmlFile = NetUtil.GZipUtf8ResultToString(e);
94
if(strXmlFile == null)
98
if(m_tsResultsViewer == null)
99
MessageService.ShowWarning(KPRes.UpdateCheckingFailed, e.Error);
100
else if(e.Error.Message != null)
101
UpdateCheck.SetTsStatus(KPRes.UpdateCheckingFailed + " " +
104
else ReportStatusEx(KPRes.UpdateCheckingFailed, true);
109
XmlDocument xmlDoc = new XmlDocument();
111
try { xmlDoc.LoadXml(strXmlFile); }
118
XmlElement xmlRoot = xmlDoc.DocumentElement;
119
if(xmlRoot == null) { StructureFail(); return; }
120
if(xmlRoot.Name != ElemRoot) { StructureFail(); return; }
124
foreach(XmlNode xmlChild in xmlRoot.ChildNodes)
126
if(xmlChild.Name == ElemVersionU)
127
uint.TryParse(xmlChild.InnerText, out uVersion);
128
else if(xmlChild.Name == ElemVersionStr)
130
// strVersion = xmlChild.InnerText;
134
if(uVersion > PwDefs.Version32)
136
if(m_tsResultsViewer == null)
138
if(MessageService.AskYesNo(KPRes.ChkForUpdNewVersion +
139
MessageService.NewParagraph + KPRes.WebsiteVisitQuestion))
141
WinUtil.OpenUrl(PwDefs.HomepageUrl, null);
144
else UpdateCheck.SetTsStatus(KPRes.ChkForUpdNewVersion);
146
else if(uVersion == PwDefs.Version32)
147
ReportStatusEx(KPRes.ChkForUpdGotLatest, false);
149
ReportStatusEx(KPRes.UnknownFileVersion, true);
152
private static void ReportStatusEx(string strText, bool bIsWarning)
154
ReportStatusEx(strText, strText, bIsWarning);
157
private static void ReportStatusEx(string strLongText, string strShortText,
160
if(m_tsResultsViewer == null)
162
if(bIsWarning) MessageService.ShowWarning(strLongText);
163
else MessageService.ShowInfo(strLongText);
165
else UpdateCheck.SetTsStatus(strShortText);
168
private static void StructureFail()
172
if(m_tsResultsViewer == null)
173
MessageService.ShowWarning(KPRes.InvalidFileStructure);
175
UpdateCheck.SetTsStatus(KPRes.ChkForUpdGotLatest + " " +
176
KPRes.InvalidFileStructure);
179
private static void SetTsStatus(string strText)
181
if(strText == null) { Debug.Assert(false); return; }
182
if(m_tsResultsViewer == null) { Debug.Assert(false); return; }
186
ToolStrip pParent = m_tsResultsViewer.Owner;
187
if((pParent != null) && pParent.InvokeRequired)
189
pParent.Invoke(new Priv_CfuSsd(UpdateCheck.SetTsStatusDirect),
190
new object[] { strText });
192
else UpdateCheck.SetTsStatusDirect(strText);
194
catch(Exception) { Debug.Assert(false); }
197
public delegate void Priv_CfuSsd(string strText);
199
private static void SetTsStatusDirect(string strText)
201
try { m_tsResultsViewer.Text = strText; }
202
catch(Exception) { Debug.Assert(false); }