diff options
author | George Hazan <george.hazan@gmail.com> | 2013-02-05 21:49:35 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-02-05 21:49:35 +0000 |
commit | 9c32e9a999c2a0d86133b1fca16f75fe10672136 (patch) | |
tree | 95f8b8c1fa8a3a07c4f81429f1d6bc557018ad52 /plugins/PluginUpdater/src/unzipfile.cpp | |
parent | e505b22562e80b830d43093758f376c858c6661d (diff) |
experimental version of PU that can handle UAC correctly
git-svn-id: http://svn.miranda-ng.org/main/trunk@3445 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/PluginUpdater/src/unzipfile.cpp')
-rw-r--r-- | plugins/PluginUpdater/src/unzipfile.cpp | 76 |
1 files changed, 43 insertions, 33 deletions
diff --git a/plugins/PluginUpdater/src/unzipfile.cpp b/plugins/PluginUpdater/src/unzipfile.cpp index b2b621d37a..2362debf44 100644 --- a/plugins/PluginUpdater/src/unzipfile.cpp +++ b/plugins/PluginUpdater/src/unzipfile.cpp @@ -37,12 +37,8 @@ static void PrepareFileName(TCHAR *dest, size_t destSize, const TCHAR *ptszPath, void BackupFile(TCHAR *ptszSrcFileName, TCHAR *ptszBackFileName)
{
- CreatePathToFileT(ptszBackFileName);
- DeleteFile(ptszBackFileName);
- if ( MoveFile(ptszSrcFileName, ptszBackFileName) == 0) { // use copy on error
- CopyFile(ptszSrcFileName, ptszBackFileName, FALSE);
- DeleteFile(ptszSrcFileName);
- }
+ SafeCreateFilePath(ptszBackFileName);
+ SafeMoveFile(ptszSrcFileName, ptszBackFileName);
}
bool extractCurrentFile(unzFile uf, TCHAR *ptszDestPath, TCHAR *ptszBackPath)
@@ -69,38 +65,52 @@ bool extractCurrentFile(unzFile uf, TCHAR *ptszDestPath, TCHAR *ptszBackPath) if (err != UNZ_OK)
return false;
- PrepareFileName(tszDestFile, SIZEOF(tszDestFile), ptszDestPath, ptszNewName);
- PrepareFileName(tszBackFile, SIZEOF(tszBackFile), ptszBackPath, ptszNewName);
- BackupFile(tszDestFile, tszBackFile);
+ if (ptszBackPath != NULL) {
+ PrepareFileName(tszDestFile, SIZEOF(tszDestFile), ptszDestPath, ptszNewName);
+ PrepareFileName(tszBackFile, SIZEOF(tszBackFile), ptszBackPath, ptszNewName);
+ BackupFile(tszDestFile, tszBackFile);
+ }
PrepareFileName(tszDestFile, SIZEOF(tszDestFile), ptszDestPath, ptszNewName);
- CreatePathToFileT(tszDestFile);
-
- HANDLE hFile = CreateFile(tszDestFile, GENERIC_WRITE, FILE_SHARE_WRITE, 0,
- CREATE_ALWAYS, file_info.external_fa, 0);
-
- if (hFile != INVALID_HANDLE_VALUE) {
- while (true) {
- err = unzReadCurrentFile(uf, buf, sizeof(buf));
- if (err <= 0)
- break;
-
- DWORD bytes;
- if (!WriteFile(hFile, buf, err, &bytes, FALSE)) {
- err = UNZ_ERRNO;
- break;
- }
+ SafeCreateFilePath(tszDestFile);
+
+ TCHAR *ptszFile2unzip;
+ if (hPipe == NULL) // direct mode
+ ptszFile2unzip = tszDestFile;
+ else {
+ TCHAR tszTempPath[MAX_PATH];
+ GetTempPath( SIZEOF(tszTempPath), tszTempPath);
+ GetTempFileName(tszTempPath, _T("PUtemp"), GetCurrentProcessId(), tszBackFile);
+ ptszFile2unzip = tszBackFile;
+ }
+
+ HANDLE hFile = CreateFile(ptszFile2unzip, GENERIC_WRITE, FILE_SHARE_WRITE, 0, CREATE_ALWAYS, file_info.external_fa, 0);
+ if (hFile == INVALID_HANDLE_VALUE)
+ return false;
+
+ while (true) {
+ err = unzReadCurrentFile(uf, buf, sizeof(buf));
+ if (err <= 0)
+ break;
+
+ DWORD bytes;
+ if (!WriteFile(hFile, buf, err, &bytes, FALSE)) {
+ err = UNZ_ERRNO;
+ break;
}
+ }
- FILETIME ftLocal, ftCreate, ftLastAcc, ftLastWrite;
- GetFileTime(hFile, &ftCreate, &ftLastAcc, &ftLastWrite);
- DosDateTimeToFileTime(HIWORD(file_info.dosDate), LOWORD(file_info.dosDate), &ftLocal);
- LocalFileTimeToFileTime(&ftLocal, &ftLastWrite);
- SetFileTime(hFile, &ftCreate, &ftLastAcc, &ftLastWrite);
+ FILETIME ftLocal, ftCreate, ftLastAcc, ftLastWrite;
+ GetFileTime(hFile, &ftCreate, &ftLastAcc, &ftLastWrite);
+ DosDateTimeToFileTime(HIWORD(file_info.dosDate), LOWORD(file_info.dosDate), &ftLocal);
+ LocalFileTimeToFileTime(&ftLocal, &ftLastWrite);
+ SetFileTime(hFile, &ftCreate, &ftLastAcc, &ftLastWrite);
- CloseHandle(hFile);
- unzCloseCurrentFile(uf); /* don't lose the error */
- }
+ CloseHandle(hFile);
+ unzCloseCurrentFile(uf); /* don't lose the error */
+
+ if (hPipe)
+ SafeMoveFile(ptszFile2unzip, tszDestFile);
}
mir_free(ptszNewName);
return true;
|