-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateDlg.cpp
More file actions
182 lines (166 loc) · 6.67 KB
/
Copy pathUpdateDlg.cpp
File metadata and controls
182 lines (166 loc) · 6.67 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// CryptSync - A folder sync tool with encryption
// Copyright (C) 2012-2013 - Stefan Kueng
// 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,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
#include "stdafx.h"
#include "resource.h"
#include "UpdateDlg.h"
#include "Registry.h"
#include "version.h"
#include <string>
#include <Commdlg.h>
#include <time.h>
#include <fstream>
CUpdateDlg::CUpdateDlg(HWND hParent)
: m_hParent(hParent)
{
}
CUpdateDlg::~CUpdateDlg(void)
{
}
LRESULT CUpdateDlg::DlgFunc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (uMsg)
{
case WM_INITDIALOG:
{
InitDialog(hwndDlg, IDI_CryptSync);
// initialize the controls
m_link.ConvertStaticToHyperlink(hwndDlg, IDC_WEBURL, _T("http://stefanstools.sourceforge.net/CryptSync.html"));
ExtendFrameIntoClientArea((UINT)-1, (UINT)-1, (UINT)-1, (UINT)-1);
m_aerocontrols.SubclassControl(GetDlgItem(*this, IDC_INFOLABEL));
m_aerocontrols.SubclassControl(GetDlgItem(*this, IDC_INFOLABEL2));
m_aerocontrols.SubclassControl(GetDlgItem(*this, IDOK));
m_aerocontrols.SubclassControl(GetDlgItem(*this, IDC_WEBURL));
}
return TRUE;
case WM_COMMAND:
return DoCommand(LOWORD(wParam));
default:
return FALSE;
}
}
LRESULT CUpdateDlg::DoCommand(int id)
{
switch (id)
{
case IDOK:
// fall through
case IDCANCEL:
EndDialog(*this, id);
break;
}
return 1;
}
std::wstring CUpdateDlg::GetTempFilePath()
{
DWORD len = ::GetTempPath(0, NULL);
std::unique_ptr<TCHAR[]> temppath(new TCHAR[len+1]);
std::unique_ptr<TCHAR[]> tempF(new TCHAR[len+50]);
::GetTempPath (len+1, temppath.get());
std::wstring tempfile;
::GetTempFileName (temppath.get(), TEXT("cm_"), 0, tempF.get());
tempfile = std::wstring(tempF.get());
//now create the tempfile, so that subsequent calls to GetTempFile() return
//different filenames.
HANDLE hFile = CreateFile(tempfile.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY, NULL);
CloseHandle(hFile);
return tempfile;
}
bool CUpdateDlg::CheckNewer()
{
bool bNewerAvailable = false;
// check for newer versions
if (CRegStdDWORD(_T("Software\\CryptSync\\CheckNewer"), TRUE) != FALSE)
{
time_t now;
struct tm ptm;
time(&now);
if ((now != 0) && (localtime_s(&ptm, &now)==0))
{
int week = 0;
// we don't calculate the real 'week of the year' here
// because just to decide if we should check for an update
// that's not needed.
week = ptm.tm_yday / 7;
CRegStdDWORD oldweek = CRegStdDWORD(_T("Software\\CryptSync\\CheckNewerWeek"), (DWORD)-1);
if (((DWORD)oldweek) == -1)
oldweek = week; // first start of CommitMonitor, no update check needed
else
{
if ((DWORD)week != oldweek)
{
oldweek = week;
//
std::wstring tempfile = GetTempFilePath();
CRegStdString checkurluser = CRegStdString(_T("Software\\CryptSync\\UpdateCheckURL"), _T(""));
CRegStdString checkurlmachine = CRegStdString(_T("Software\\CryptSync\\UpdateCheckURL"), _T(""), FALSE, HKEY_LOCAL_MACHINE);
std::wstring sCheckURL = (std::wstring)checkurluser;
if (sCheckURL.empty())
{
sCheckURL = (std::wstring)checkurlmachine;
if (sCheckURL.empty())
sCheckURL = _T("http://cryptsync.googlecode.com/svn/trunk/version.txt");
}
HRESULT res = URLDownloadToFile(NULL, sCheckURL.c_str(), tempfile.c_str(), 0, NULL);
if (res == S_OK)
{
std::ifstream File;
File.open(tempfile.c_str());
if (File.good())
{
char line[1024];
char * pLine = line;
File.getline(line, sizeof(line));
int major = 0;
int minor = 0;
int micro = 0;
int build = 0;
major = atoi(pLine);
pLine = strchr(pLine, '.');
if (pLine)
{
pLine++;
minor = atoi(pLine);
pLine = strchr(pLine, '.');
if (pLine)
{
pLine++;
micro = atoi(pLine);
pLine = strchr(pLine, '.');
if (pLine)
{
pLine++;
build = atoi(pLine);
}
}
}
if (major > CS_VERMAJOR)
bNewerAvailable = true;
else if ((minor > CS_VERMINOR)&&(major == CS_VERMAJOR))
bNewerAvailable = true;
else if ((micro > CS_VERMICRO)&&(minor == CS_VERMINOR)&&(major == CS_VERMAJOR))
bNewerAvailable = true;
else if ((build > CS_VERBUILD)&&(micro == CS_VERMICRO)&&(minor == CS_VERMINOR)&&(major == CS_VERMAJOR))
bNewerAvailable = true;
}
File.close();
}
DeleteFile(tempfile.c_str());
}
}
}
}
return bNewerAvailable;
}