-
Notifications
You must be signed in to change notification settings - Fork 0
/
UpdateDlg.cpp
115 lines (91 loc) · 2.81 KB
/
UpdateDlg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// WinDjView
// Copyright (C) 2004-2009 Andrew Zhezherun
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// http://www.gnu.org/copyleft/gpl.html
// $Id: UpdateDlg.cpp,v 1.16 2009/02/19 10:53:32 zhezherun Exp $
#include "stdafx.h"
#include "WinDjView.h"
#include "UpdateDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CUpdateDlg dialog
IMPLEMENT_DYNAMIC(CUpdateDlg, CMyDialog)
CUpdateDlg::CUpdateDlg(CWnd* pParent)
: CMyDialog(CUpdateDlg::IDD, pParent), m_hThread(NULL), m_bOk(false)
{
}
CUpdateDlg::~CUpdateDlg()
{
if (m_hThread != NULL)
::CloseHandle(m_hThread);
}
void CUpdateDlg::DoDataExchange(CDataExchange* pDX)
{
CMyDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CUpdateDlg, CMyDialog)
ON_WM_SHOWWINDOW()
ON_MESSAGE_VOID(WM_ENDDIALOG, OnEndDialog)
END_MESSAGE_MAP()
// CUpdateDlg message handlers
void CUpdateDlg::OnOK()
{
}
void CUpdateDlg::OnCancel()
{
}
void CUpdateDlg::OnShowWindow(BOOL bShow, UINT nStatus)
{
CMyDialog::OnShowWindow(bShow, nStatus);
if (bShow && m_hThread == NULL)
{
UINT nThreadId;
m_hThread = (HANDLE)_beginthreadex(NULL, 0, UpdateThreadProc, this, 0, &nThreadId);
theApp.ThreadStarted();
}
}
unsigned int __stdcall CUpdateDlg::UpdateThreadProc(void* pvData)
{
::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
CUpdateDlg* pDlg = reinterpret_cast<CUpdateDlg*>(pvData);
CString strNewVersion = CDjViewApp::DownloadLastVersionString();
pDlg->m_bOk = !strNewVersion.IsEmpty();
pDlg->m_strNewVersion = strNewVersion;
pDlg->SendMessage(WM_ENDDIALOG);
theApp.ThreadTerminated();
return 0;
}
void CUpdateDlg::OnEndDialog()
{
if (m_bOk)
{
if (CompareVersions(m_strNewVersion, CURRENT_VERSION) > 0)
{
if (AfxMessageBox(FormatString(IDS_NEW_VERSION_AVAILABLE, m_strNewVersion),
MB_ICONQUESTION | MB_YESNO) == IDYES)
{
::ShellExecute(NULL, _T("open"), LoadString(IDS_WEBSITE_URL),
NULL, NULL, SW_SHOW);
}
}
else
AfxMessageBox(IDS_NO_UPDATES_AVAILABLE, MB_ICONINFORMATION | MB_OK);
}
else
AfxMessageBox(IDS_CONNECT_ERROR, MB_ICONEXCLAMATION | MB_OK);
EndDialog(IDOK);
}