Commit 4235f957aec4b755fedfc9f7c50f8c07e4f43c25
1 parent
e454f69f
feat(all):提交客户端自动升级项目\
新增客户端自动升级项目,用于所有客户端的升级。
Showing
11 changed files
with
1403 additions
and
0 deletions
Too many changes to show.
To preserve performance only 11 of 28 files are displayed.
client_auto_updata/AutoUpdate.sln
0 → 100644
1 | + | |
2 | +Microsoft Visual Studio Solution File, Format Version 12.00 | |
3 | +# Visual Studio 2013 | |
4 | +VisualStudioVersion = 12.0.31101.0 | |
5 | +MinimumVisualStudioVersion = 10.0.40219.1 | |
6 | +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AutoUpdate", "AutoUpdate\AutoUpdate.vcxproj", "{30A58DE1-4C62-4882-9730-638BF4209018}" | |
7 | +EndProject | |
8 | +Global | |
9 | + GlobalSection(SolutionConfigurationPlatforms) = preSolution | |
10 | + Debug|Win32 = Debug|Win32 | |
11 | + Release|Win32 = Release|Win32 | |
12 | + EndGlobalSection | |
13 | + GlobalSection(ProjectConfigurationPlatforms) = postSolution | |
14 | + {30A58DE1-4C62-4882-9730-638BF4209018}.Debug|Win32.ActiveCfg = Debug|Win32 | |
15 | + {30A58DE1-4C62-4882-9730-638BF4209018}.Debug|Win32.Build.0 = Debug|Win32 | |
16 | + {30A58DE1-4C62-4882-9730-638BF4209018}.Release|Win32.ActiveCfg = Release|Win32 | |
17 | + {30A58DE1-4C62-4882-9730-638BF4209018}.Release|Win32.Build.0 = Release|Win32 | |
18 | + EndGlobalSection | |
19 | + GlobalSection(SolutionProperties) = preSolution | |
20 | + HideSolutionNode = FALSE | |
21 | + EndGlobalSection | |
22 | +EndGlobal | ... | ... |
client_auto_updata/AutoUpdate/AUDataManage.cpp
0 → 100644
1 | +#include "stdafx.h" | |
2 | +#include "AUDataManage.h" | |
3 | +#include "afxinet.h" | |
4 | +#include "tlhelp32.h" | |
5 | +#include "tinyxml.h" | |
6 | +#include ".\zlib\zip.h" | |
7 | +#include ".\zlib\unzip.h" | |
8 | + | |
9 | + | |
10 | +CAUDataManage* CAUDataManage::m_pInstance = NULL; | |
11 | + | |
12 | +void Log(CString sLog) | |
13 | +{ | |
14 | + CStdioFile fileLog; | |
15 | + CString sPath; | |
16 | + TCHAR szPath[MAX_PATH]; | |
17 | + GetModuleFileName(NULL, szPath, MAX_PATH); | |
18 | + CString sMudolePath = szPath; | |
19 | + CString sMudoleName = AfxGetAppName(); | |
20 | + sPath = sMudolePath.Left(sMudolePath.GetLength() - sMudoleName.GetLength() - 4); | |
21 | + | |
22 | + CFileStatus statusFile; | |
23 | + statusFile.m_size = 0; | |
24 | + CString sLogPath = sPath + "AutoUpdateLog.txt"; | |
25 | + CFile::GetStatus(sLogPath, statusFile); | |
26 | + | |
27 | + CTime tmCurTime; | |
28 | + tmCurTime = CTime::GetCurrentTime(); | |
29 | + CString sData = tmCurTime.Format(_T("%y-%m-%d-%H-%M-%S")); | |
30 | + | |
31 | + CString sText = sData + " " + sLog; | |
32 | + if (statusFile.m_size > 1024 * 1024 * 10) | |
33 | + { | |
34 | + if (fileLog.Open(sLogPath, CFile::modeCreate | CFile::modeWrite)) | |
35 | + { | |
36 | + fileLog.WriteString(sText); | |
37 | + fileLog.WriteString("\n"); | |
38 | + fileLog.Close(); | |
39 | + } | |
40 | + } | |
41 | + else | |
42 | + { | |
43 | + if (fileLog.Open(sLogPath, CFile::modeCreate | CFile::modeWrite | CFile::modeNoTruncate)) | |
44 | + { | |
45 | + fileLog.SeekToEnd(); | |
46 | + fileLog.WriteString(sText); | |
47 | + fileLog.WriteString("\n"); | |
48 | + fileLog.Close(); | |
49 | + } | |
50 | + } | |
51 | +} | |
52 | + | |
53 | + | |
54 | +CAUDataManage::CAUDataManage() | |
55 | +{ | |
56 | + m_sConfigFileName = "Version.xml"; | |
57 | + m_sConfigFilePath = GetModulePath() + m_sConfigFileName; | |
58 | + | |
59 | + m_stuConfigData = ReadConfig(m_sConfigFilePath); | |
60 | +} | |
61 | + | |
62 | + | |
63 | +CAUDataManage::~CAUDataManage() | |
64 | +{ | |
65 | +} | |
66 | + | |
67 | +BOOL CAUDataManage::CheckVersion() | |
68 | +{ | |
69 | + BOOL bIsLatest = TRUE; | |
70 | + | |
71 | + CreateTempFolder(); | |
72 | + Log("检查版本。"); | |
73 | + CInternetSession *pInternetSession = NULL; | |
74 | + CFtpConnection *pFtpConnection = NULL; | |
75 | + pInternetSession = new CInternetSession(); | |
76 | + pFtpConnection = pInternetSession->GetFtpConnection(m_stuConfigData.sServerIP, m_stuConfigData.sUserName, m_stuConfigData.sPassWord); | |
77 | + CString sFilePath; | |
78 | + pFtpConnection->GetCurrentDirectory(sFilePath); | |
79 | + //add for test by liuye 2017.7.17 | |
80 | + Log("for test 获取到的路径是: " + sFilePath); | |
81 | + // | |
82 | + sFilePath += m_stuConfigData.sUpdateDir + "/" + m_sConfigFileName; | |
83 | + CString sTempConfigPath = m_stuConfigData.sTempDir + "\\" + m_sConfigFileName; | |
84 | + if (pFtpConnection) | |
85 | + { | |
86 | + Log("连接到服务器。"); | |
87 | + if (pFtpConnection->GetFile(sFilePath, sTempConfigPath)) | |
88 | + { | |
89 | + Log("下载到配置文件。"); | |
90 | + APPConfig stuTempConfig = ReadConfig(sTempConfigPath); | |
91 | + if (stuTempConfig.sVersion.Compare(m_stuConfigData.sVersion) == 0) | |
92 | + { | |
93 | + bIsLatest = TRUE; | |
94 | + } | |
95 | + else | |
96 | + { | |
97 | + bIsLatest = FALSE; | |
98 | + } | |
99 | + } | |
100 | + | |
101 | + if (!bIsLatest) | |
102 | + { | |
103 | + CString sAP; | |
104 | + pFtpConnection->GetCurrentDirectory(sAP); | |
105 | + CString sPackageName = sAP + m_stuConfigData.sUpdateDir + "/" + m_stuConfigData.sZipName; | |
106 | + | |
107 | + CFtpFileFind finderFtp(pFtpConnection); | |
108 | + if (!finderFtp.FindFile(sPackageName)) | |
109 | + { | |
110 | + Log(sPackageName + " " + "文件不存在!"); | |
111 | + bIsLatest = TRUE; | |
112 | + } | |
113 | + } | |
114 | + | |
115 | + if (NULL != pFtpConnection) | |
116 | + { | |
117 | + pFtpConnection->Close(); | |
118 | + delete pFtpConnection; | |
119 | + pFtpConnection = NULL; | |
120 | + } | |
121 | + if (NULL != pInternetSession) | |
122 | + { | |
123 | + delete pInternetSession; | |
124 | + pInternetSession = NULL; | |
125 | + } | |
126 | + } | |
127 | + else | |
128 | + { | |
129 | + Log("未连接到服务器。"); | |
130 | + } | |
131 | + | |
132 | + | |
133 | + DeleteDirectory(m_stuConfigData.sTempDir); | |
134 | + return bIsLatest; | |
135 | +} | |
136 | + | |
137 | +void CAUDataManage::Update() | |
138 | +{ | |
139 | + HWND hMainWnd = AfxGetApp()->GetMainWnd()->m_hWnd; | |
140 | + | |
141 | + PostMessage(hMainWnd, WM_UPDATEPROCESS, 0, PROCESS_KILLCLIENT); | |
142 | + if (KillCilent(m_stuConfigData.sAppName)) | |
143 | + { | |
144 | + PostMessage(hMainWnd, WM_UPDATEPROCESS, 0, PROCESS_DOWNLOADFILE); | |
145 | + if (DownloadClientFile()) | |
146 | + { | |
147 | + PostMessage(hMainWnd, WM_UPDATEPROCESS, 0, PROCESS_DELETEOLDFILE); | |
148 | + DeleteDirectory(m_stuConfigData.sAppDir); | |
149 | + PostMessage(hMainWnd, WM_UPDATEPROCESS, 0, PROCESS_UNZIP); | |
150 | + if (Unzip(m_stuConfigData.sTempDir + "\\" + m_stuConfigData.sZipName, m_stuConfigData.sAppDir)) | |
151 | + { | |
152 | + m_stuConfigData = ReadConfig(m_sConfigFilePath); | |
153 | + } | |
154 | + } | |
155 | + } | |
156 | + PostMessage(hMainWnd, WM_UPDATEPROCESS, 0, PROCESS_COMPLETE); | |
157 | +} | |
158 | + | |
159 | +BOOL CAUDataManage::KillCilent(CString sClientName) | |
160 | +{ | |
161 | + BOOL bResult = FALSE; | |
162 | + Log("关闭进程。"); | |
163 | + PROCESSENTRY32 stuClient; | |
164 | + HANDLE hAllProcess = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); | |
165 | + if (hAllProcess != INVALID_HANDLE_VALUE) | |
166 | + { | |
167 | + stuClient.dwSize = sizeof(stuClient); | |
168 | + if (Process32First(hAllProcess, &stuClient)) | |
169 | + { | |
170 | + CString sPrcessName; | |
171 | + do | |
172 | + { | |
173 | + sPrcessName = stuClient.szExeFile; | |
174 | + if (sClientName.CompareNoCase(sPrcessName) == 0) | |
175 | + { | |
176 | + | |
177 | + HANDLE hProcessHandle; | |
178 | + hProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, true, stuClient.th32ProcessID); | |
179 | + if (hProcessHandle != NULL) | |
180 | + { | |
181 | + Log("找到进程" + sClientName); | |
182 | + if (TerminateProcess(hProcessHandle, 0)) | |
183 | + { | |
184 | + Log(sClientName + "进程关闭。"); | |
185 | + bResult = TRUE; | |
186 | + } | |
187 | + else | |
188 | + { | |
189 | + Log(sClientName + "进程关闭失败。"); | |
190 | + bResult = FALSE; | |
191 | + } | |
192 | + CloseHandle(hProcessHandle); | |
193 | + break; | |
194 | + } | |
195 | + } | |
196 | + } while (Process32Next(hAllProcess, &stuClient)); | |
197 | + } | |
198 | + CloseHandle(hAllProcess); | |
199 | + } | |
200 | + return bResult; | |
201 | +} | |
202 | + | |
203 | +void CAUDataManage::RestartClient() | |
204 | +{ | |
205 | + ShellExecute(NULL, "open", m_stuConfigData.sAppDir + CString("\\") + m_stuConfigData.sAppName, NULL, m_stuConfigData.sAppDir, SW_SHOW); | |
206 | +} | |
207 | + | |
208 | +BOOL CAUDataManage::DownloadClientFile() | |
209 | +{ | |
210 | + BOOL bResult = FALSE; | |
211 | + | |
212 | + CreateTempFolder(); | |
213 | + | |
214 | + CInternetSession *pInternetSession = NULL; | |
215 | + CFtpConnection *pFtpConnection = NULL; | |
216 | + pInternetSession = new CInternetSession(); | |
217 | + pFtpConnection = pInternetSession->GetFtpConnection(m_stuConfigData.sServerIP, m_stuConfigData.sUserName, m_stuConfigData.sPassWord); | |
218 | + CString sFileDir; | |
219 | + pFtpConnection->GetCurrentDirectory(sFileDir); | |
220 | + CString sSrcPath = sFileDir + m_stuConfigData.sUpdateDir + "/" + m_stuConfigData.sZipName; | |
221 | + CString sDstPath = m_stuConfigData.sTempDir + "\\" + m_stuConfigData.sZipName; | |
222 | + if (pFtpConnection) | |
223 | + { | |
224 | + Log("连接到服务器。"); | |
225 | + if (pFtpConnection->GetFile(sSrcPath, sDstPath)) | |
226 | + { | |
227 | + Log(sDstPath + "文件下载成功"); | |
228 | + bResult = TRUE; | |
229 | + } | |
230 | + else | |
231 | + { | |
232 | + Log(sDstPath + "文件下载失败"); | |
233 | + bResult = FALSE; | |
234 | + } | |
235 | + | |
236 | + sSrcPath = sFileDir + m_stuConfigData.sUpdateDir + "/" + m_sConfigFileName; | |
237 | + sDstPath = m_stuConfigData.sTempDir + "\\" + m_sConfigFileName; | |
238 | + if (pFtpConnection->GetFile(sSrcPath, sDstPath)) | |
239 | + { | |
240 | + Log(sDstPath + "文件下载成功"); | |
241 | + bResult = TRUE; | |
242 | + } | |
243 | + else | |
244 | + { | |
245 | + Log(sDstPath + "文件下载失败"); | |
246 | + bResult = FALSE; | |
247 | + } | |
248 | + } | |
249 | + else | |
250 | + { | |
251 | + Log("未连接到服务器。"); | |
252 | + } | |
253 | + | |
254 | + //释放资源 | |
255 | + if (NULL != pFtpConnection) | |
256 | + { | |
257 | + pFtpConnection->Close(); | |
258 | + | |
259 | + delete pFtpConnection; | |
260 | + | |
261 | + pFtpConnection = NULL; | |
262 | + } | |
263 | + | |
264 | + | |
265 | + if (NULL != pInternetSession) | |
266 | + { | |
267 | + delete pInternetSession; | |
268 | + | |
269 | + pInternetSession = NULL; | |
270 | + } | |
271 | + | |
272 | + return bResult; | |
273 | +} | |
274 | + | |
275 | +void CAUDataManage::CreateTempFolder() | |
276 | +{ | |
277 | + CString sFolder = GetModulePath() + L"temp"; | |
278 | + if (PathFileExists(sFolder)) | |
279 | + { | |
280 | + DeleteDirectory(sFolder); | |
281 | + } | |
282 | + CreateDirectory(sFolder, NULL); | |
283 | +} | |
284 | + | |
285 | +void CAUDataManage::DeleteDirectory(CString sDirectory) | |
286 | +{ | |
287 | + Log("正在删除目录" + sDirectory); | |
288 | + CFileFind cFind; | |
289 | + CString sFile = sDirectory + L"\\*.*"; | |
290 | + | |
291 | + BOOL IsFinded = cFind.FindFile(sFile); | |
292 | + while (IsFinded) | |
293 | + { | |
294 | + IsFinded = cFind.FindNextFile(); | |
295 | + CString sTest = cFind.GetFileName(); | |
296 | + if (!cFind.IsDots()) | |
297 | + { | |
298 | + CString sFilePath; | |
299 | + if (cFind.GetFileName().Compare(m_stuConfigData.sSelfName) != 0 | |
300 | + && cFind.GetFilePath().Compare(m_stuConfigData.sTempDir) != 0 | |
301 | + && cFind.GetFileName().Compare("AutoUpdateLog.txt") != 0) | |
302 | + { | |
303 | + if (cFind.IsDirectory()) | |
304 | + { | |
305 | + sFilePath = cFind.GetFilePath(); | |
306 | + DeleteDirectory(sFilePath); | |
307 | + } | |
308 | + else | |
309 | + { | |
310 | + sFilePath = cFind.GetFilePath(); | |
311 | + if (DeleteFile(sFilePath)) | |
312 | + { | |
313 | + Log(sFilePath + " " + "删除成功。"); | |
314 | + } | |
315 | + else | |
316 | + { | |
317 | + Log(sFilePath + " " + "删除失败。"); | |
318 | + } | |
319 | + } | |
320 | + } | |
321 | + } | |
322 | + } | |
323 | + cFind.Close(); | |
324 | + | |
325 | + RemoveDirectory(sDirectory); | |
326 | +} | |
327 | + | |
328 | +CString CAUDataManage::GetModulePath() | |
329 | +{ | |
330 | + CString sPath; | |
331 | + | |
332 | + TCHAR szPath[MAX_PATH]; | |
333 | + GetModuleFileName(NULL, szPath, MAX_PATH); | |
334 | + CString sMudolePath = szPath; | |
335 | + CString sMudoleName = AfxGetAppName(); | |
336 | + sPath = sMudolePath.Left(sMudolePath.GetLength() - sMudoleName.GetLength() - 4); | |
337 | + return sPath; | |
338 | +} | |
339 | + | |
340 | +APPConfig CAUDataManage::ReadConfig(CString sConfigName) | |
341 | +{ | |
342 | + Log("开始读取配置文件。"); | |
343 | + APPConfig stuConfig; | |
344 | + | |
345 | + TiXmlDocument xmlDoc(sConfigName.GetBuffer()); | |
346 | + if (xmlDoc.LoadFile()) | |
347 | + { | |
348 | + TiXmlElement *pRootEle = xmlDoc.RootElement(); | |
349 | + TiXmlElement *pPackageNameEle = pRootEle->FirstChildElement(); | |
350 | + stuConfig.sZipName = pPackageNameEle->GetText(); | |
351 | + TiXmlElement *pAppNameEle = pPackageNameEle->NextSiblingElement(); | |
352 | + stuConfig.sAppName = pAppNameEle->GetText(); | |
353 | + TiXmlElement *pVersionEle = pAppNameEle->NextSiblingElement(); | |
354 | + stuConfig.sVersion = pVersionEle->GetText(); | |
355 | + TiXmlElement *pUpdateDir = pVersionEle->NextSiblingElement(); | |
356 | + stuConfig.sUpdateDir = pUpdateDir->GetText(); | |
357 | + TiXmlElement *pServerIP = pUpdateDir->NextSiblingElement(); | |
358 | + stuConfig.sServerIP = pServerIP->GetText(); | |
359 | + TiXmlElement *pUserName = pServerIP->NextSiblingElement(); | |
360 | + stuConfig.sUserName = pUserName->GetText(); | |
361 | + TiXmlElement *pPassWord = pUserName->NextSiblingElement(); | |
362 | + stuConfig.sPassWord = pPassWord->GetText(); | |
363 | + | |
364 | + stuConfig.sAppDir = GetModulePath(); | |
365 | + stuConfig.sSelfName = AfxGetAppName() + CString(".exe"); | |
366 | + stuConfig.sTempDir = stuConfig.sAppDir + CString("temp"); | |
367 | + | |
368 | + Log("读取配置文件完成。"); | |
369 | + } | |
370 | + return stuConfig; | |
371 | +} | |
372 | + | |
373 | +void CAUDataManage::ReplaceClientFile(CString sAppDir) | |
374 | +{ | |
375 | + DeleteDirectory(m_stuConfigData.sAppDir); | |
376 | + Log("旧文件已删除。"); | |
377 | + CopyClientFile(m_stuConfigData.sTempDir, m_stuConfigData.sAppDir); | |
378 | + DeleteDirectory(m_stuConfigData.sTempDir); | |
379 | + Log("临时文件已删除。"); | |
380 | +} | |
381 | + | |
382 | +void CAUDataManage::CopyClientFile(CString sSrcFile, CString sDstFile) | |
383 | +{ | |
384 | + CreateDirectory(sDstFile, NULL); | |
385 | + CFileFind cFinder; | |
386 | + CString sPath; | |
387 | + sPath = sSrcFile + "\\*.*"; | |
388 | + BOOL bWorking = cFinder.FindFile(sPath); | |
389 | + while (bWorking) | |
390 | + { | |
391 | + Log("找到文件目录,正在复制文件。"); | |
392 | + bWorking = cFinder.FindNextFile(); | |
393 | + CString sTest = cFinder.GetFileName(); | |
394 | + if (!cFinder.IsDots()) | |
395 | + { | |
396 | + if (cFinder.IsDirectory()) | |
397 | + { | |
398 | + CopyClientFile(cFinder.GetFilePath(), sDstFile + ("\\") + cFinder.GetFileName()); | |
399 | + } | |
400 | + else | |
401 | + { | |
402 | + CString stSrcFile = cFinder.GetFilePath(); | |
403 | + BOOL bDir = (GetFileAttributes(stSrcFile) & FILE_ATTRIBUTE_DIRECTORY); | |
404 | + if (!bDir) | |
405 | + { | |
406 | + if (CopyFile(cFinder.GetFilePath(), sDstFile + ("\\") + cFinder.GetFileName(), FALSE)) | |
407 | + { | |
408 | + Log(cFinder.GetFileName() + " " + "文件复制成功。"); | |
409 | + } | |
410 | + else | |
411 | + { | |
412 | + Log(cFinder.GetFileName() + " " + "文件复制失败。"); | |
413 | + } | |
414 | + } | |
415 | + } | |
416 | + } | |
417 | + | |
418 | + } | |
419 | +} | |
420 | + | |
421 | +void CAUDataManage::DownloadFile(CString sSrcFile, CString sDstFile, CFtpConnection *pFtpConnection) | |
422 | +{ | |
423 | + if (pFtpConnection) | |
424 | + { | |
425 | + Log("连接服务器成功,开始查找文件。"); | |
426 | + /*BOOL bResult =*/ pFtpConnection->SetCurrentDirectory(sSrcFile); | |
427 | + CFtpFileFind cFTPFind(pFtpConnection); | |
428 | + | |
429 | + CreateDirectory(sDstFile, NULL); | |
430 | + | |
431 | + CString sPath; | |
432 | + sPath =/* sCurPath + */sSrcFile + "/*.*"; | |
433 | + BOOL bWorking = cFTPFind.FindFile(sSrcFile); | |
434 | + while (bWorking) | |
435 | + { | |
436 | + Log("找到文件目录,开始下载文件。"); | |
437 | + bWorking = cFTPFind.FindNextFile(); | |
438 | + if (!cFTPFind.IsDots()) | |
439 | + { | |
440 | + if (cFTPFind.IsDirectory()) | |
441 | + { | |
442 | + | |
443 | + CInternetSession *pInternetSession = NULL; | |
444 | + CFtpConnection *pFtpConnection = NULL; | |
445 | + pInternetSession = new CInternetSession(); | |
446 | + pFtpConnection = pInternetSession->GetFtpConnection(m_stuConfigData.sServerIP, m_stuConfigData.sUserName, m_stuConfigData.sPassWord); | |
447 | + DownloadFile(sSrcFile + "/" + cFTPFind.GetFileName(), sDstFile + ("\\") + cFTPFind.GetFileName(), pFtpConnection); | |
448 | + if (NULL != pFtpConnection) | |
449 | + { | |
450 | + pFtpConnection->Close(); | |
451 | + delete pFtpConnection; | |
452 | + pFtpConnection = NULL; | |
453 | + } | |
454 | + if (NULL != pInternetSession) | |
455 | + { | |
456 | + delete pInternetSession; | |
457 | + pInternetSession = NULL; | |
458 | + } | |
459 | + } | |
460 | + else | |
461 | + { | |
462 | + CString sFilePath = cFTPFind.GetFilePath(); | |
463 | + CString sNewFile = sDstFile + "\\" + cFTPFind.GetFileName(); | |
464 | + BOOL bResult = pFtpConnection->GetFile(sFilePath, sNewFile); | |
465 | + } | |
466 | + } | |
467 | + | |
468 | + } | |
469 | + } | |
470 | + | |
471 | +} | |
472 | + | |
473 | +CAUDataManage* CAUDataManage::Instantialize() | |
474 | +{ | |
475 | + if (m_pInstance == NULL) | |
476 | + { //double check | |
477 | + //Lock lock(m_csLocker); //用lock实现线程安全,用资源管理类,实现异常安全 | |
478 | + //使用资源管理类,在抛出异常的时候,资源管理类对象会被析构,析构总是发生的无论是因为异常抛出还是语句块结束。 | |
479 | + if (m_pInstance == NULL) | |
480 | + { | |
481 | + m_pInstance = new CAUDataManage(); | |
482 | + } | |
483 | + } | |
484 | + return m_pInstance; | |
485 | +} | |
486 | + | |
487 | +void CAUDataManage::DestoryInstance() | |
488 | +{ | |
489 | + if (m_pInstance) | |
490 | + { | |
491 | + delete m_pInstance; | |
492 | + m_pInstance = NULL; | |
493 | + } | |
494 | +} | |
495 | + | |
496 | +BOOL CAUDataManage::Unzip(CString sSrcDir, CString sDstDir) | |
497 | +{ | |
498 | + BOOL bResult = FALSE; | |
499 | + Log("开始解压文件" + sSrcDir); | |
500 | + HZIP hZip = OpenZip(sSrcDir.GetBuffer(), NULL); | |
501 | + if (hZip) | |
502 | + { | |
503 | + SetUnzipBaseDir(hZip, sDstDir); | |
504 | + ZIPENTRY stuZipentry; | |
505 | + GetZipItem(hZip, -1, &stuZipentry); | |
506 | + int iTotalCount = stuZipentry.index; | |
507 | + for (int index = 0; index < iTotalCount; ++index) | |
508 | + { | |
509 | + Log("正在解压文件" + CString(stuZipentry.name)); | |
510 | + GetZipItem(hZip, index, &stuZipentry); | |
511 | + UnzipItem(hZip, index, stuZipentry.name); | |
512 | + } | |
513 | + } | |
514 | + | |
515 | + if (hZip != NULL) | |
516 | + { | |
517 | + CloseZip(hZip); | |
518 | + hZip = NULL; | |
519 | + } | |
520 | + | |
521 | + Log("复制配置文件"); | |
522 | + if (CopyFile(m_stuConfigData.sTempDir + ("\\") + m_sConfigFileName, m_stuConfigData.sAppDir + ("\\") + m_sConfigFileName, FALSE)) | |
523 | + { | |
524 | + Log(m_sConfigFileName + " " + "文件复制成功。"); | |
525 | + bResult = TRUE; | |
526 | + } | |
527 | + else | |
528 | + { | |
529 | + Log(m_sConfigFileName + " " + "文件复制失败。"); | |
530 | + bResult = FALSE; | |
531 | + } | |
532 | + | |
533 | + DeleteDirectory(m_stuConfigData.sTempDir); | |
534 | + | |
535 | + return bResult; | |
536 | +} | |
0 | 537 | \ No newline at end of file | ... | ... |
client_auto_updata/AutoUpdate/AUDataManage.h
0 → 100644
1 | +#pragma once | |
2 | +#include "afxinet.h" | |
3 | + | |
4 | +#define WM_UPDATEPROCESS WM_USER + 1 | |
5 | +#define WM_CRASH_CLOSE WM_USER + 2 | |
6 | + | |
7 | +#define PROCESS_KILLCLIENT 1 | |
8 | +#define PROCESS_DOWNLOADFILE 2 | |
9 | +#define PROCESS_DELETEOLDFILE 3 | |
10 | +#define PROCESS_UNZIP 4 | |
11 | +#define PROCESS_COMPLETE 5 | |
12 | + | |
13 | +typedef struct STU_CONFIG | |
14 | +{ | |
15 | + CString sAppName; | |
16 | + CString sSelfName; | |
17 | + CString sVersion; | |
18 | + CString sAppDir; | |
19 | + CString sUpdateDir; | |
20 | + CString sTempDir; | |
21 | + CString sZipName; | |
22 | + | |
23 | + CString sServerIP; | |
24 | + CString sUserName; | |
25 | + CString sPassWord; | |
26 | + | |
27 | + STU_CONFIG operator= (STU_CONFIG& stuConfig) | |
28 | + { | |
29 | + sAppName = stuConfig.sAppName; | |
30 | + sSelfName = stuConfig.sSelfName; | |
31 | + sVersion = stuConfig.sVersion; | |
32 | + sAppDir = stuConfig.sAppDir; | |
33 | + sUpdateDir = stuConfig.sUpdateDir; | |
34 | + sTempDir = stuConfig.sTempDir; | |
35 | + sZipName = stuConfig.sZipName; | |
36 | + sServerIP = stuConfig.sServerIP; | |
37 | + sUserName = stuConfig.sUserName; | |
38 | + sPassWord = stuConfig.sPassWord; | |
39 | + return *this; | |
40 | + } | |
41 | +}APPConfig; | |
42 | + | |
43 | +extern void Log(CString sLog); | |
44 | + | |
45 | + | |
46 | +//class Lock | |
47 | +//{ | |
48 | +//private: | |
49 | +// CCriticalSection m_cs; | |
50 | +//public: | |
51 | +// Lock(CCriticalSection cs) : m_cs(cs) | |
52 | +// { | |
53 | +// m_cs.Lock(); | |
54 | +// } | |
55 | +// ~Lock() | |
56 | +// { | |
57 | +// m_cs.Unlock(); | |
58 | +// } | |
59 | +//}; | |
60 | + | |
61 | +class CAUDataManage | |
62 | +{ | |
63 | +public: | |
64 | + static CAUDataManage *Instantialize(); | |
65 | + static void DestoryInstance(); | |
66 | + ~CAUDataManage(); | |
67 | + | |
68 | +public: | |
69 | + BOOL CheckVersion(); | |
70 | + void Update(); | |
71 | + void RestartClient(); | |
72 | + | |
73 | +private: | |
74 | + CAUDataManage(); | |
75 | + CAUDataManage(const CAUDataManage &); | |
76 | + CAUDataManage& operator = (const CAUDataManage &); | |
77 | + | |
78 | + BOOL KillCilent(CString sClientName); | |
79 | + BOOL DownloadClientFile(); | |
80 | + void CreateTempFolder(); | |
81 | + void DeleteDirectory(CString sDirectory); | |
82 | + CString GetModulePath(); | |
83 | + void ReplaceClientFile(CString sAppDir); | |
84 | + APPConfig ReadConfig(CString sConfigName); | |
85 | + void CopyClientFile(CString sSrcFile, CString sDstFile); | |
86 | + void DownloadFile(CString sSrcFile, CString sDstFile, CFtpConnection *pFtpConnection); | |
87 | + | |
88 | +private: | |
89 | + static CAUDataManage *m_pInstance; | |
90 | + static CCriticalSection m_csLocker; | |
91 | + | |
92 | + APPConfig m_stuConfigData; | |
93 | + CString m_sConfigFilePath; | |
94 | + CString m_sConfigFileName; | |
95 | + BOOL Unzip(CString sSrcDir, CString sDstDir); | |
96 | +}; | |
97 | + | ... | ... |
client_auto_updata/AutoUpdate/AutoUpdate.cpp
0 → 100644
1 | + | |
2 | +// AutoUpdate.cpp : 定义应用程序的类行为。 | |
3 | +// | |
4 | + | |
5 | +#include "stdafx.h" | |
6 | +#include "AutoUpdate.h" | |
7 | +#include "AutoUpdateDlg.h" | |
8 | +#include "dbghelp.h" | |
9 | + | |
10 | +#ifdef _DEBUG | |
11 | +#define new DEBUG_NEW | |
12 | +#endif | |
13 | + | |
14 | +#pragma comment(lib, "dbghelp.lib") | |
15 | + | |
16 | +//异常处理 add by liuye 2016.9.23 | |
17 | +LONG WINAPI ExceptionHandler(PEXCEPTION_POINTERS ExceptionPointer) | |
18 | +{ | |
19 | + AfxMessageBox(_T("升级程序发生异常,请联系工作人员!")); | |
20 | + // Open the file | |
21 | + | |
22 | + CTime tmCurTime; | |
23 | + tmCurTime = CTime::GetCurrentTime(); | |
24 | + CString sData = tmCurTime.Format(_T("%y%m%d")); | |
25 | + CString sDumpName = _T("AutoUpdate_") + sData + ".dmp"; | |
26 | + | |
27 | + HANDLE hFile = CreateFile(sDumpName, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); | |
28 | + if ((hFile != NULL) && (hFile != INVALID_HANDLE_VALUE)) | |
29 | + { | |
30 | + // Create the minidump | |
31 | + MINIDUMP_EXCEPTION_INFORMATION stuDump; | |
32 | + stuDump.ThreadId = GetCurrentThreadId(); | |
33 | + stuDump.ExceptionPointers = ExceptionPointer; | |
34 | + stuDump.ClientPointers = FALSE; | |
35 | + MINIDUMP_TYPE emDumpType = MiniDumpNormal; | |
36 | + BOOL bCreateDump = MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, emDumpType, (ExceptionPointer != 0) ? &stuDump : 0, 0, 0); | |
37 | + | |
38 | + if (!bCreateDump) | |
39 | + _tprintf(_T("MiniDumpWriteDump failed. Error: %u \n"), GetLastError()); | |
40 | + else | |
41 | + _tprintf(_T("Minidump created.\n")); | |
42 | + | |
43 | + // Close the file | |
44 | + CloseHandle(hFile); | |
45 | + | |
46 | + CWinApp* pApp = AfxGetApp(); | |
47 | + SendMessage(pApp->m_pMainWnd->m_hWnd, WM_CRASH_CLOSE, NULL, NULL); | |
48 | + } | |
49 | + else | |
50 | + { | |
51 | + _tprintf(_T("CreateFile failed. Error: %u \n"), GetLastError()); | |
52 | + } | |
53 | + return EXCEPTION_EXECUTE_HANDLER; | |
54 | +} | |
55 | + | |
56 | + | |
57 | +// CAUAutoUpdateApp | |
58 | + | |
59 | +BEGIN_MESSAGE_MAP(CAUAutoUpdateApp, CWinApp) | |
60 | + ON_COMMAND(ID_HELP, &CWinApp::OnHelp) | |
61 | +END_MESSAGE_MAP() | |
62 | + | |
63 | + | |
64 | +// CAUAutoUpdateApp 构造 | |
65 | + | |
66 | +CAUAutoUpdateApp::CAUAutoUpdateApp() | |
67 | +{ | |
68 | + // TODO: 在此处添加构造代码, | |
69 | + // 将所有重要的初始化放置在 InitInstance 中 | |
70 | +} | |
71 | + | |
72 | + | |
73 | +// 唯一的一个 CAUAutoUpdateApp 对象 | |
74 | + | |
75 | +CAUAutoUpdateApp theApp; | |
76 | + | |
77 | + | |
78 | +// CAUAutoUpdateApp 初始化 | |
79 | + | |
80 | +BOOL CAUAutoUpdateApp::InitInstance() | |
81 | +{ | |
82 | + CWinApp::InitInstance(); | |
83 | + | |
84 | + SetUnhandledExceptionFilter(ExceptionHandler); | |
85 | + | |
86 | + // 创建 shell 管理器,以防对话框包含 | |
87 | + // 任何 shell 树视图控件或 shell 列表视图控件。 | |
88 | + CShellManager *pShellManager = new CShellManager; | |
89 | + | |
90 | + // 激活“Windows Native”视觉管理器,以便在 MFC 控件中启用主题 | |
91 | + CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows)); | |
92 | + | |
93 | + // 标准初始化 | |
94 | + // 如果未使用这些功能并希望减小 | |
95 | + // 最终可执行文件的大小,则应移除下列 | |
96 | + // 不需要的特定初始化例程 | |
97 | + // 更改用于存储设置的注册表项 | |
98 | + // TODO: 应适当修改该字符串, | |
99 | + // 例如修改为公司或组织名 | |
100 | + SetRegistryKey(_T("应用程序向导生成的本地应用程序")); | |
101 | + | |
102 | + CAUAutoUpdateDlg dlgUpdate; | |
103 | + m_pMainWnd = &dlgUpdate; | |
104 | + | |
105 | + INT_PTR nResponse = dlgUpdate.DoModal(); | |
106 | + if (nResponse == IDOK) | |
107 | + { | |
108 | + // TODO: 在此放置处理何时用 | |
109 | + // “确定”来关闭对话框的代码 | |
110 | + } | |
111 | + else if (nResponse == IDCANCEL) | |
112 | + { | |
113 | + // TODO: 在此放置处理何时用 | |
114 | + // “取消”来关闭对话框的代码 | |
115 | + } | |
116 | + else if (nResponse == -1) | |
117 | + { | |
118 | + TRACE(traceAppMsg, 0, "警告: 对话框创建失败,应用程序将意外终止。\n"); | |
119 | + TRACE(traceAppMsg, 0, "警告: 如果您在对话框上使用 MFC 控件,则无法 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS。\n"); | |
120 | + } | |
121 | + | |
122 | + CAUDataManage::Instantialize()->DestoryInstance(); | |
123 | + | |
124 | + // 删除上面创建的 shell 管理器。 | |
125 | + if (pShellManager != NULL) | |
126 | + { | |
127 | + delete pShellManager; | |
128 | + } | |
129 | + | |
130 | + // 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序, | |
131 | + // 而不是启动应用程序的消息泵。 | |
132 | + return FALSE; | |
133 | +} | |
134 | + | ... | ... |
client_auto_updata/AutoUpdate/AutoUpdate.h
0 → 100644
1 | + | |
2 | +// AutoUpdate.h : PROJECT_NAME 应用程序的主头文件 | |
3 | +// | |
4 | + | |
5 | +#pragma once | |
6 | + | |
7 | +#ifndef __AFXWIN_H__ | |
8 | + #error "在包含此文件之前包含“stdafx.h”以生成 PCH 文件" | |
9 | +#endif | |
10 | + | |
11 | +#include "resource.h" // 主符号 | |
12 | + | |
13 | + | |
14 | +// CAUAutoUpdateApp: | |
15 | +// 有关此类的实现,请参阅 AutoUpdate.cpp | |
16 | +// | |
17 | + | |
18 | +class CAUAutoUpdateApp : public CWinApp | |
19 | +{ | |
20 | +public: | |
21 | + CAUAutoUpdateApp(); | |
22 | + | |
23 | +// 重写 | |
24 | +public: | |
25 | + virtual BOOL InitInstance(); | |
26 | + | |
27 | +// 实现 | |
28 | + | |
29 | + DECLARE_MESSAGE_MAP() | |
30 | +}; | |
31 | + | |
32 | +extern CAUAutoUpdateApp theApp; | |
0 | 33 | \ No newline at end of file | ... | ... |
client_auto_updata/AutoUpdate/AutoUpdate.rc
0 → 100644
client_auto_updata/AutoUpdate/AutoUpdate.vcxproj
0 → 100644
1 | +<?xml version="1.0" encoding="utf-8"?> | |
2 | +<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
3 | + <ItemGroup Label="ProjectConfigurations"> | |
4 | + <ProjectConfiguration Include="Debug|Win32"> | |
5 | + <Configuration>Debug</Configuration> | |
6 | + <Platform>Win32</Platform> | |
7 | + </ProjectConfiguration> | |
8 | + <ProjectConfiguration Include="Release|Win32"> | |
9 | + <Configuration>Release</Configuration> | |
10 | + <Platform>Win32</Platform> | |
11 | + </ProjectConfiguration> | |
12 | + </ItemGroup> | |
13 | + <PropertyGroup Label="Globals"> | |
14 | + <ProjectGuid>{30A58DE1-4C62-4882-9730-638BF4209018}</ProjectGuid> | |
15 | + <RootNamespace>AutoUpdate</RootNamespace> | |
16 | + <Keyword>MFCProj</Keyword> | |
17 | + </PropertyGroup> | |
18 | + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | |
19 | + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | |
20 | + <ConfigurationType>Application</ConfigurationType> | |
21 | + <UseDebugLibraries>true</UseDebugLibraries> | |
22 | + <PlatformToolset>v120</PlatformToolset> | |
23 | + <CharacterSet>MultiByte</CharacterSet> | |
24 | + <UseOfMfc>Static</UseOfMfc> | |
25 | + </PropertyGroup> | |
26 | + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | |
27 | + <ConfigurationType>Application</ConfigurationType> | |
28 | + <UseDebugLibraries>false</UseDebugLibraries> | |
29 | + <PlatformToolset>v120</PlatformToolset> | |
30 | + <WholeProgramOptimization>true</WholeProgramOptimization> | |
31 | + <CharacterSet>MultiByte</CharacterSet> | |
32 | + <UseOfMfc>Static</UseOfMfc> | |
33 | + </PropertyGroup> | |
34 | + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | |
35 | + <ImportGroup Label="ExtensionSettings"> | |
36 | + </ImportGroup> | |
37 | + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |
38 | + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |
39 | + </ImportGroup> | |
40 | + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |
41 | + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |
42 | + </ImportGroup> | |
43 | + <PropertyGroup Label="UserMacros" /> | |
44 | + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |
45 | + <LinkIncremental>true</LinkIncremental> | |
46 | + <LibraryPath>D:\GitProject\AutoUpdate\AutoUpdate\AutoUpdate;$(LibraryPath)</LibraryPath> | |
47 | + </PropertyGroup> | |
48 | + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |
49 | + <LinkIncremental>false</LinkIncremental> | |
50 | + <LibraryPath>D:\GitProject\AutoUpdate\AutoUpdate\AutoUpdate;$(LibraryPath)</LibraryPath> | |
51 | + </PropertyGroup> | |
52 | + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |
53 | + <ClCompile> | |
54 | + <PrecompiledHeader>Use</PrecompiledHeader> | |
55 | + <WarningLevel>Level3</WarningLevel> | |
56 | + <Optimization>Disabled</Optimization> | |
57 | + <PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions);_CRT_SECURE_NO_DEPRECATE</PreprocessorDefinitions> | |
58 | + <SDLCheck>true</SDLCheck> | |
59 | + <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |
60 | + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> | |
61 | + </ClCompile> | |
62 | + <Link> | |
63 | + <SubSystem>Windows</SubSystem> | |
64 | + <GenerateDebugInformation>true</GenerateDebugInformation> | |
65 | + <AdditionalLibraryDirectories>D:\GitProject\AutoUpdate\AutoUpdate\AutoUpdate\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | |
66 | + <AdditionalDependencies>dbghelp.lib;%(AdditionalDependencies)</AdditionalDependencies> | |
67 | + </Link> | |
68 | + <Midl> | |
69 | + <MkTypLibCompatible>false</MkTypLibCompatible> | |
70 | + <ValidateAllParameters>true</ValidateAllParameters> | |
71 | + <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |
72 | + </Midl> | |
73 | + <ResourceCompile> | |
74 | + <Culture>0x0804</Culture> | |
75 | + <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |
76 | + <AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |
77 | + </ResourceCompile> | |
78 | + </ItemDefinitionGroup> | |
79 | + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |
80 | + <ClCompile> | |
81 | + <WarningLevel>Level3</WarningLevel> | |
82 | + <PrecompiledHeader>Use</PrecompiledHeader> | |
83 | + <Optimization>Disabled</Optimization> | |
84 | + <FunctionLevelLinking>true</FunctionLevelLinking> | |
85 | + <IntrinsicFunctions>true</IntrinsicFunctions> | |
86 | + <PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions);_CRT_SECURE_NO_DEPRECATE</PreprocessorDefinitions> | |
87 | + <SDLCheck>true</SDLCheck> | |
88 | + <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |
89 | + </ClCompile> | |
90 | + <Link> | |
91 | + <SubSystem>Windows</SubSystem> | |
92 | + <GenerateDebugInformation>true</GenerateDebugInformation> | |
93 | + <EnableCOMDATFolding>true</EnableCOMDATFolding> | |
94 | + <OptimizeReferences>true</OptimizeReferences> | |
95 | + <AdditionalLibraryDirectories>D:\GitProject\AutoUpdate\AutoUpdate\AutoUpdate\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | |
96 | + <AdditionalDependencies>dbghelp.lib;%(AdditionalDependencies)</AdditionalDependencies> | |
97 | + </Link> | |
98 | + <Midl> | |
99 | + <MkTypLibCompatible>false</MkTypLibCompatible> | |
100 | + <ValidateAllParameters>true</ValidateAllParameters> | |
101 | + <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |
102 | + </Midl> | |
103 | + <ResourceCompile> | |
104 | + <Culture>0x0804</Culture> | |
105 | + <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |
106 | + <AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |
107 | + </ResourceCompile> | |
108 | + </ItemDefinitionGroup> | |
109 | + <ItemGroup> | |
110 | + <Text Include="ReadMe.txt" /> | |
111 | + </ItemGroup> | |
112 | + <ItemGroup> | |
113 | + <ClInclude Include="AUDataManage.h" /> | |
114 | + <ClInclude Include="AutoUpdate.h" /> | |
115 | + <ClInclude Include="AutoUpdateDlg.h" /> | |
116 | + <ClInclude Include="Resource.h" /> | |
117 | + <ClInclude Include="stdafx.h" /> | |
118 | + <ClInclude Include="targetver.h" /> | |
119 | + <ClInclude Include="tinystr.h" /> | |
120 | + <ClInclude Include="tinyxml.h" /> | |
121 | + <ClInclude Include="zlib\unzip.h" /> | |
122 | + <ClInclude Include="zlib\zip.h" /> | |
123 | + </ItemGroup> | |
124 | + <ItemGroup> | |
125 | + <ClCompile Include="AUDataManage.cpp" /> | |
126 | + <ClCompile Include="AutoUpdate.cpp" /> | |
127 | + <ClCompile Include="AutoUpdateDlg.cpp" /> | |
128 | + <ClCompile Include="stdafx.cpp"> | |
129 | + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader> | |
130 | + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader> | |
131 | + </ClCompile> | |
132 | + <ClCompile Include="tinystr.cpp" /> | |
133 | + <ClCompile Include="tinyxml.cpp" /> | |
134 | + <ClCompile Include="tinyxmlerror.cpp" /> | |
135 | + <ClCompile Include="tinyxmlparser.cpp" /> | |
136 | + <ClCompile Include="zlib\unzip.cpp" /> | |
137 | + <ClCompile Include="zlib\zip.cpp" /> | |
138 | + </ItemGroup> | |
139 | + <ItemGroup> | |
140 | + <ResourceCompile Include="AutoUpdate.rc" /> | |
141 | + </ItemGroup> | |
142 | + <ItemGroup> | |
143 | + <None Include="res\AutoUpdate.rc2" /> | |
144 | + </ItemGroup> | |
145 | + <ItemGroup> | |
146 | + <Image Include="res\AutoUpdate.ico" /> | |
147 | + </ItemGroup> | |
148 | + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | |
149 | + <ImportGroup Label="ExtensionTargets"> | |
150 | + </ImportGroup> | |
151 | + <ProjectExtensions> | |
152 | + <VisualStudio> | |
153 | + <UserProperties RESOURCE_FILE="AutoUpdate.rc" /> | |
154 | + </VisualStudio> | |
155 | + </ProjectExtensions> | |
156 | +</Project> | |
0 | 157 | \ No newline at end of file | ... | ... |
client_auto_updata/AutoUpdate/AutoUpdate.vcxproj.filters
0 → 100644
1 | +<?xml version="1.0" encoding="utf-8"?> | |
2 | +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
3 | + <ItemGroup> | |
4 | + <Filter Include="源文件"> | |
5 | + <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> | |
6 | + <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> | |
7 | + </Filter> | |
8 | + <Filter Include="头文件"> | |
9 | + <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> | |
10 | + <Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions> | |
11 | + </Filter> | |
12 | + <Filter Include="资源文件"> | |
13 | + <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> | |
14 | + <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> | |
15 | + </Filter> | |
16 | + </ItemGroup> | |
17 | + <ItemGroup> | |
18 | + <Text Include="ReadMe.txt" /> | |
19 | + </ItemGroup> | |
20 | + <ItemGroup> | |
21 | + <ClInclude Include="AutoUpdate.h"> | |
22 | + <Filter>头文件</Filter> | |
23 | + </ClInclude> | |
24 | + <ClInclude Include="AutoUpdateDlg.h"> | |
25 | + <Filter>头文件</Filter> | |
26 | + </ClInclude> | |
27 | + <ClInclude Include="stdafx.h"> | |
28 | + <Filter>头文件</Filter> | |
29 | + </ClInclude> | |
30 | + <ClInclude Include="targetver.h"> | |
31 | + <Filter>头文件</Filter> | |
32 | + </ClInclude> | |
33 | + <ClInclude Include="Resource.h"> | |
34 | + <Filter>头文件</Filter> | |
35 | + </ClInclude> | |
36 | + <ClInclude Include="AUDataManage.h"> | |
37 | + <Filter>头文件</Filter> | |
38 | + </ClInclude> | |
39 | + <ClInclude Include="tinystr.h"> | |
40 | + <Filter>头文件</Filter> | |
41 | + </ClInclude> | |
42 | + <ClInclude Include="tinyxml.h"> | |
43 | + <Filter>头文件</Filter> | |
44 | + </ClInclude> | |
45 | + <ClInclude Include="zlib\unzip.h"> | |
46 | + <Filter>头文件</Filter> | |
47 | + </ClInclude> | |
48 | + <ClInclude Include="zlib\zip.h"> | |
49 | + <Filter>头文件</Filter> | |
50 | + </ClInclude> | |
51 | + </ItemGroup> | |
52 | + <ItemGroup> | |
53 | + <ClCompile Include="AutoUpdate.cpp"> | |
54 | + <Filter>源文件</Filter> | |
55 | + </ClCompile> | |
56 | + <ClCompile Include="AutoUpdateDlg.cpp"> | |
57 | + <Filter>源文件</Filter> | |
58 | + </ClCompile> | |
59 | + <ClCompile Include="stdafx.cpp"> | |
60 | + <Filter>源文件</Filter> | |
61 | + </ClCompile> | |
62 | + <ClCompile Include="AUDataManage.cpp"> | |
63 | + <Filter>源文件</Filter> | |
64 | + </ClCompile> | |
65 | + <ClCompile Include="tinystr.cpp"> | |
66 | + <Filter>源文件</Filter> | |
67 | + </ClCompile> | |
68 | + <ClCompile Include="tinyxml.cpp"> | |
69 | + <Filter>源文件</Filter> | |
70 | + </ClCompile> | |
71 | + <ClCompile Include="tinyxmlerror.cpp"> | |
72 | + <Filter>源文件</Filter> | |
73 | + </ClCompile> | |
74 | + <ClCompile Include="tinyxmlparser.cpp"> | |
75 | + <Filter>源文件</Filter> | |
76 | + </ClCompile> | |
77 | + <ClCompile Include="zlib\unzip.cpp"> | |
78 | + <Filter>源文件</Filter> | |
79 | + </ClCompile> | |
80 | + <ClCompile Include="zlib\zip.cpp"> | |
81 | + <Filter>源文件</Filter> | |
82 | + </ClCompile> | |
83 | + </ItemGroup> | |
84 | + <ItemGroup> | |
85 | + <ResourceCompile Include="AutoUpdate.rc"> | |
86 | + <Filter>资源文件</Filter> | |
87 | + </ResourceCompile> | |
88 | + </ItemGroup> | |
89 | + <ItemGroup> | |
90 | + <None Include="res\AutoUpdate.rc2"> | |
91 | + <Filter>资源文件</Filter> | |
92 | + </None> | |
93 | + </ItemGroup> | |
94 | + <ItemGroup> | |
95 | + <Image Include="res\AutoUpdate.ico"> | |
96 | + <Filter>资源文件</Filter> | |
97 | + </Image> | |
98 | + </ItemGroup> | |
99 | +</Project> | |
0 | 100 | \ No newline at end of file | ... | ... |
client_auto_updata/AutoUpdate/AutoUpdateDlg.cpp
0 → 100644
1 | + | |
2 | +// AutoUpdateDlg.cpp : 实现文件 | |
3 | +// | |
4 | + | |
5 | +#include "stdafx.h" | |
6 | +#include "AutoUpdate.h" | |
7 | +#include "AutoUpdateDlg.h" | |
8 | +#include "afxdialogex.h" | |
9 | + | |
10 | + | |
11 | + | |
12 | +#ifdef _DEBUG | |
13 | +#define new DEBUG_NEW | |
14 | +#endif | |
15 | + | |
16 | +const int CLIENT_WIDTH = 500; | |
17 | +const int CLIENT_HEIGHT = 200; | |
18 | +const int PROCESS_HEIGHT = 40; | |
19 | +const int BOARD_HEIGHT = 40; | |
20 | +const int BOARD_WIDTH = 7; | |
21 | +const int SPACE_SIZE = 2; | |
22 | + | |
23 | +// CAUCheckVerDlg 对话框 | |
24 | + | |
25 | +UINT Updata(LPVOID lpParam) | |
26 | +{ | |
27 | + CAUDataManage::Instantialize()->Update(); | |
28 | + return 0; | |
29 | +} | |
30 | + | |
31 | +CAUAutoUpdateDlg::CAUAutoUpdateDlg(CWnd* pParent /*=NULL*/) | |
32 | + : CDialogEx(CAUAutoUpdateDlg::IDD, pParent) | |
33 | +{ | |
34 | + m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); | |
35 | + m_pDataManage = CAUDataManage::Instantialize(); | |
36 | +} | |
37 | + | |
38 | +void CAUAutoUpdateDlg::DoDataExchange(CDataExchange* pDX) | |
39 | +{ | |
40 | + CDialogEx::DoDataExchange(pDX); | |
41 | + DDX_Control(pDX, IDC_EDIT_NOTICE, m_editNotice); | |
42 | + DDX_Control(pDX, IDC_PROGRESS_UPDATE, m_progressUpdate); | |
43 | +} | |
44 | + | |
45 | +BEGIN_MESSAGE_MAP(CAUAutoUpdateDlg, CDialogEx) | |
46 | + ON_WM_PAINT() | |
47 | + ON_WM_QUERYDRAGICON() | |
48 | + ON_MESSAGE(WM_UPDATEPROCESS, CAUAutoUpdateDlg::UpdateView) | |
49 | + ON_MESSAGE(WM_CRASH_CLOSE, CAUAutoUpdateDlg::SafeClose) | |
50 | +END_MESSAGE_MAP() | |
51 | + | |
52 | + | |
53 | +// CAUCheckVerDlg 消息处理程序 | |
54 | + | |
55 | +BOOL CAUAutoUpdateDlg::OnInitDialog() | |
56 | +{ | |
57 | + CDialogEx::OnInitDialog(); | |
58 | + | |
59 | + // 设置此对话框的图标。 当应用程序主窗口不是对话框时,框架将自动 | |
60 | + // 执行此操作 | |
61 | + SetIcon(m_hIcon, TRUE); // 设置大图标 | |
62 | + SetIcon(m_hIcon, FALSE); // 设置小图标 | |
63 | + | |
64 | + ShowWindow(SW_HIDE); | |
65 | + | |
66 | + Log("检查更新。"); | |
67 | + if (!m_pDataManage->CheckVersion()) | |
68 | + { | |
69 | + if (IDOK == MessageBox(_T("检查到有新版本,是否升级?"), _T("版本升级"), MB_OKCANCEL)) | |
70 | + { | |
71 | + Log("确认升级。"); | |
72 | + SetUpdateView(); | |
73 | + AfxBeginThread(Updata, NULL, THREAD_PRIORITY_NORMAL, 0, 0, NULL); | |
74 | + } | |
75 | + else | |
76 | + { | |
77 | + Log("暂不升级。"); | |
78 | + SendMessage(WM_CLOSE); | |
79 | + } | |
80 | + } | |
81 | + else | |
82 | + { | |
83 | + Log("已经是最新版本。"); | |
84 | + SendMessage(WM_CLOSE); | |
85 | + } | |
86 | + | |
87 | + return TRUE; // 除非将焦点设置到控件,否则返回 TRUE | |
88 | +} | |
89 | + | |
90 | +// 如果向对话框添加最小化按钮,则需要下面的代码 | |
91 | +// 来绘制该图标。 对于使用文档/视图模型的 MFC 应用程序, | |
92 | +// 这将由框架自动完成。 | |
93 | + | |
94 | +void CAUAutoUpdateDlg::OnPaint() | |
95 | +{ | |
96 | + if (IsIconic()) | |
97 | + { | |
98 | + CPaintDC dc(this); // 用于绘制的设备上下文 | |
99 | + | |
100 | + SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0); | |
101 | + | |
102 | + // 使图标在工作区矩形中居中 | |
103 | + int cxIcon = GetSystemMetrics(SM_CXICON); | |
104 | + int cyIcon = GetSystemMetrics(SM_CYICON); | |
105 | + CRect rect; | |
106 | + GetClientRect(&rect); | |
107 | + int x = (rect.Width() - cxIcon + 1) / 2; | |
108 | + int y = (rect.Height() - cyIcon + 1) / 2; | |
109 | + | |
110 | + // 绘制图标 | |
111 | + dc.DrawIcon(x, y, m_hIcon); | |
112 | + } | |
113 | + else | |
114 | + { | |
115 | + CDialogEx::OnPaint(); | |
116 | + } | |
117 | +} | |
118 | + | |
119 | +//当用户拖动最小化窗口时系统调用此函数取得光标 | |
120 | +//显示。 | |
121 | +HCURSOR CAUAutoUpdateDlg::OnQueryDragIcon() | |
122 | +{ | |
123 | + return static_cast<HCURSOR>(m_hIcon); | |
124 | +} | |
125 | + | |
126 | +void CAUAutoUpdateDlg::SetUpdateView() | |
127 | +{ | |
128 | + ShowWindow(SW_SHOW); | |
129 | + | |
130 | + CRect rtCLient; | |
131 | + GetClientRect(&rtCLient); | |
132 | + ClientToScreen(&rtCLient); | |
133 | + int iScreenWidth = GetSystemMetrics(SM_CXSCREEN); | |
134 | + int iScreenHeight = GetSystemMetrics(SM_CYSCREEN); | |
135 | + | |
136 | + rtCLient.left = iScreenWidth / 2 - CLIENT_WIDTH / 2; | |
137 | + rtCLient.top = iScreenHeight / 2 - CLIENT_HEIGHT / 2; | |
138 | + rtCLient.right = rtCLient.left + CLIENT_WIDTH; | |
139 | + rtCLient.bottom = rtCLient.top + CLIENT_HEIGHT; | |
140 | + MoveWindow(rtCLient); | |
141 | + | |
142 | + m_progressUpdate.SetRange(0, 100); | |
143 | + CRect rtProgess; | |
144 | + rtProgess.left = SPACE_SIZE; | |
145 | + rtProgess.right = CLIENT_WIDTH - BOARD_WIDTH * 2 - SPACE_SIZE * 2; | |
146 | + rtProgess.bottom = CLIENT_HEIGHT - SPACE_SIZE - BOARD_HEIGHT; | |
147 | + rtProgess.top = rtProgess.bottom - PROCESS_HEIGHT; | |
148 | + m_progressUpdate.MoveWindow(rtProgess); | |
149 | + | |
150 | + SetNoticeText("正在升级请稍后······"); | |
151 | + CRect rtEdit; | |
152 | + rtEdit.left = rtProgess.left; | |
153 | + rtEdit.right = rtProgess.right; | |
154 | + rtEdit.top = SPACE_SIZE; | |
155 | + rtEdit.bottom = rtProgess.top - SPACE_SIZE * 2; | |
156 | + m_editNotice.MoveWindow(&rtEdit); | |
157 | + | |
158 | +} | |
159 | + | |
160 | +LRESULT CAUAutoUpdateDlg::UpdateView(WPARAM wParam, LPARAM lParam) | |
161 | +{ | |
162 | + if ((int)lParam == PROCESS_KILLCLIENT) | |
163 | + { | |
164 | + Log("正在关闭应用程序。"); | |
165 | + SetNoticeText("正在关闭应用程序"); | |
166 | + m_progressUpdate.OffsetPos(1); | |
167 | + } | |
168 | + else if ((int)lParam == PROCESS_DOWNLOADFILE) | |
169 | + { | |
170 | + Log("正在下载文件。"); | |
171 | + SetNoticeText("正在下载文件"); | |
172 | + m_progressUpdate.OffsetPos(10); | |
173 | + } | |
174 | + else if ((int)lParam == PROCESS_DELETEOLDFILE) | |
175 | + { | |
176 | + Log("正在删除旧文件。"); | |
177 | + SetNoticeText("正在删除旧文件"); | |
178 | + m_progressUpdate.OffsetPos(60); | |
179 | + } | |
180 | + else if ((int)lParam == PROCESS_UNZIP) | |
181 | + { | |
182 | + Log("正在解压文件。"); | |
183 | + SetNoticeText("正在解压文件"); | |
184 | + m_progressUpdate.OffsetPos(80); | |
185 | + } | |
186 | + else if ((int)lParam == PROCESS_COMPLETE) | |
187 | + { | |
188 | + Log("客户端更新完成。"); | |
189 | + SetNoticeText("客户端更新完成"); | |
190 | + m_progressUpdate.OffsetPos(100); | |
191 | + MessageBox(_T("客户端更新完成!")); | |
192 | + m_pDataManage->RestartClient(); | |
193 | + SendMessage(WM_CLOSE); | |
194 | + } | |
195 | + | |
196 | + return NULL; | |
197 | +} | |
198 | + | |
199 | +void CAUAutoUpdateDlg::SetNoticeText(CString sNotice) | |
200 | +{ | |
201 | + CString sNewText; | |
202 | + CString sOldText; | |
203 | + m_editNotice.GetWindowText(sOldText); | |
204 | + | |
205 | + if (!sOldText.IsEmpty()) | |
206 | + { | |
207 | + sNewText = sOldText + "\r\n" + sNotice; | |
208 | + } | |
209 | + else | |
210 | + { | |
211 | + sNewText = sNotice; | |
212 | + } | |
213 | + | |
214 | + m_editNotice.SetWindowText(sNewText); | |
215 | +} | |
216 | + | |
217 | +LRESULT CAUAutoUpdateDlg::SafeClose(WPARAM wParam, LPARAM lParam) | |
218 | +{ | |
219 | + SendMessage(WM_CLOSE); | |
220 | + return NULL; | |
221 | +} | |
222 | + | |
223 | + | ... | ... |
client_auto_updata/AutoUpdate/AutoUpdateDlg.h
0 → 100644
1 | + | |
2 | +// AutoUpdateDlg.h : 头文件 | |
3 | +// | |
4 | + | |
5 | +#pragma once | |
6 | +#include "AUDataManage.h" | |
7 | +#include "afxwin.h" | |
8 | +#include "afxcmn.h" | |
9 | + | |
10 | + | |
11 | +// CAUCheckVerDlg 对话框 | |
12 | +class CAUAutoUpdateDlg : public CDialogEx | |
13 | +{ | |
14 | +// 构造 | |
15 | +public: | |
16 | + CAUAutoUpdateDlg(CWnd* pParent = NULL); // 标准构造函数 | |
17 | + | |
18 | +// 对话框数据 | |
19 | + enum { IDD = IDD_AUTOUPDATE_DIALOG }; | |
20 | + | |
21 | + protected: | |
22 | + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 | |
23 | + | |
24 | + | |
25 | +// 实现 | |
26 | +protected: | |
27 | + HICON m_hIcon; | |
28 | + | |
29 | + // 生成的消息映射函数 | |
30 | + virtual BOOL OnInitDialog(); | |
31 | + afx_msg void OnPaint(); | |
32 | + afx_msg HCURSOR OnQueryDragIcon(); | |
33 | + DECLARE_MESSAGE_MAP() | |
34 | + | |
35 | +private: | |
36 | + //CAUDataManage m_cDataManage; | |
37 | + CAUDataManage* m_pDataManage; | |
38 | + CEdit m_editNotice; | |
39 | + CProgressCtrl m_progressUpdate; | |
40 | + | |
41 | +private: | |
42 | + void SetUpdateView(); | |
43 | + afx_msg LRESULT UpdateView(WPARAM wParam, LPARAM lParam); | |
44 | + afx_msg LRESULT SafeClose(WPARAM wParam, LPARAM lParam); | |
45 | + void SetNoticeText(CString sNotice); | |
46 | +}; | ... | ... |
client_auto_updata/AutoUpdate/ReadMe.txt
0 → 100644
1 | +================================================================================ | |
2 | + MICROSOFT 基础类库 : AutoUpdate 项目概述 | |
3 | +=============================================================================== | |
4 | + | |
5 | +应用程序向导已为您创建了此 AutoUpdate 应用程序。此应用程序不仅演示 Microsoft 基础类的基本使用方法,还可作为您编写应用程序的起点。 | |
6 | + | |
7 | +本文件概要介绍组成 AutoUpdate 应用程序的每个文件的内容。 | |
8 | + | |
9 | +AutoUpdate.vcxproj | |
10 | + 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 | |
11 | + | |
12 | +AutoUpdate.vcxproj.filters | |
13 | + 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 | |
14 | + | |
15 | +AutoUpdate.h | |
16 | + 这是应用程序的主头文件。 | |
17 | + 其中包括其他项目特定的标头(包括 Resource.h),并声明 CAUAutoUpdateApp 应用程序类。 | |
18 | + | |
19 | +AutoUpdate.cpp | |
20 | + 这是包含应用程序类 CAUAutoUpdateApp 的主应用程序源文件。 | |
21 | + | |
22 | +AutoUpdate.rc | |
23 | + 这是程序使用的所有 Microsoft Windows 资源的列表。它包括 RES 子目录中存储的图标、位图和光标。此文件可以直接在 Microsoft Visual C++ 中进行编辑。项目资源包含在 2052 中。 | |
24 | + | |
25 | +res\AutoUpdate.ico | |
26 | + 这是用作应用程序图标的图标文件。此图标包括在主资源文件 AutoUpdate.rc 中。 | |
27 | + | |
28 | +res\AutoUpdate.rc2 | |
29 | + 此文件包含不在 Microsoft Visual C++ 中进行编辑的资源。您应该将不可由资源编辑器编辑的所有资源放在此文件中。 | |
30 | + | |
31 | + | |
32 | +///////////////////////////////////////////////////////////////////////////// | |
33 | + | |
34 | +应用程序向导创建一个对话框类: | |
35 | + | |
36 | +AutoUpdateDlg.h、AutoUpdateDlg.cpp - 对话框 | |
37 | + 这些文件包含 CAUCheckVerDlg 类。此类定义应用程序的主对话框的行为。对话框模板包含在 AutoUpdate.rc 中,该文件可以在 Microsoft Visual C++ 中编辑。 | |
38 | + | |
39 | +///////////////////////////////////////////////////////////////////////////// | |
40 | + | |
41 | +其他标准文件: | |
42 | + | |
43 | +StdAfx.h, StdAfx.cpp | |
44 | + 这些文件用于生成名为 AutoUpdate.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 | |
45 | + | |
46 | +Resource.h | |
47 | + 这是标准头文件,可用于定义新的资源 ID。Microsoft Visual C++ 将读取并更新此文件。 | |
48 | + | |
49 | +///////////////////////////////////////////////////////////////////////////// | |
50 | + | |
51 | +其他注释: | |
52 | + | |
53 | +应用程序向导使用“TODO:”来指示应添加或自定义的源代码部分。 | |
54 | + | |
55 | +如果应用程序使用共享 DLL 中的 MFC,您将需要重新分发 MFC DLL。如果应用程序所使用的语言与操作系统的区域设置不同,则还需要重新分发相应的本地化资源 mfc110XXX.DLL。 | |
56 | +有关上述话题的更多信息,请参见 MSDN 文档中有关重新分发 Visual C++ 应用程序的部分。 | |
57 | + | |
58 | +///////////////////////////////////////////////////////////////////////////// | ... | ... |