diff options
author | George Hazan <ghazan@miranda.im> | 2020-08-27 20:35:52 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2020-08-27 20:35:52 +0300 |
commit | 6d990112ad5ba4a670b71d40de7dfd9cedfd32cc (patch) | |
tree | f599470d9af322a60e13dd1e8b9666463a097539 /plugins/PluginUpdater/src/unzipfile.cpp | |
parent | 77fa06bdc1a3efb7689c3ec39c8a943f7a289920 (diff) |
fixes #2555 (PluginUpdater: некорректное обновление при работе нескольких миранд одновременно)
Diffstat (limited to 'plugins/PluginUpdater/src/unzipfile.cpp')
-rw-r--r-- | plugins/PluginUpdater/src/unzipfile.cpp | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/plugins/PluginUpdater/src/unzipfile.cpp b/plugins/PluginUpdater/src/unzipfile.cpp index 18a95fd726..9e3c21da09 100644 --- a/plugins/PluginUpdater/src/unzipfile.cpp +++ b/plugins/PluginUpdater/src/unzipfile.cpp @@ -30,7 +30,7 @@ static void PrepareFileName(wchar_t *dest, size_t destSize, const wchar_t *ptszP *p = '\\';
}
-bool extractCurrentFile(unzFile uf, wchar_t *ptszDestPath, wchar_t *ptszBackPath, bool ch)
+int extractCurrentFile(unzFile uf, wchar_t *ptszDestPath, wchar_t *ptszBackPath, bool ch)
{
unz_file_info64 file_info;
char filename[MAX_PATH];
@@ -38,7 +38,7 @@ bool extractCurrentFile(unzFile uf, wchar_t *ptszDestPath, wchar_t *ptszBackPath int err = unzGetCurrentFileInfo64(uf, &file_info, filename, sizeof(filename), buf, DATA_BUF_SIZE, nullptr, 0);
if (err != UNZ_OK)
- return false;
+ return err;
for (char *p = strchr(filename, '/'); p; p = strchr(p+1, '/'))
*p = '\\';
@@ -49,21 +49,20 @@ bool extractCurrentFile(unzFile uf, wchar_t *ptszDestPath, wchar_t *ptszBackPath return true;
wchar_t tszDestFile[MAX_PATH], tszBackFile[MAX_PATH];
- wchar_t *ptszNewName = mir_utf8decodeW(filename);
+ ptrW ptszNewName(mir_utf8decodeW(filename));
if (ptszNewName == nullptr)
ptszNewName = mir_a2u(filename);
if (!(file_info.external_fa & FILE_ATTRIBUTE_DIRECTORY)) {
err = unzOpenCurrentFile(uf);
- if (err != UNZ_OK) {
- mir_free(ptszNewName);
- return false;
- }
+ if (err != UNZ_OK)
+ return err;
if (ptszBackPath != nullptr) {
PrepareFileName(tszDestFile, _countof(tszDestFile), ptszDestPath, ptszNewName);
PrepareFileName(tszBackFile, _countof(tszBackFile), ptszBackPath, ptszNewName);
- BackupFile(tszDestFile, tszBackFile);
+ if (err = BackupFile(tszDestFile, tszBackFile))
+ return err;
}
PrepareFileName(tszDestFile, _countof(tszDestFile), ptszDestPath, ptszNewName);
@@ -74,16 +73,15 @@ bool extractCurrentFile(unzFile uf, wchar_t *ptszDestPath, wchar_t *ptszBackPath ptszFile2unzip = tszDestFile;
else {
wchar_t tszTempPath[MAX_PATH];
- GetTempPath( _countof(tszTempPath), tszTempPath);
- GetTempFileName(tszTempPath, L"PUtemp", GetCurrentProcessId(), tszBackFile);
+ GetTempPathW(_countof(tszTempPath), tszTempPath);
+ GetTempFileNameW(tszTempPath, L"PUtemp", GetCurrentProcessId(), tszBackFile);
ptszFile2unzip = tszBackFile;
}
HANDLE hFile = CreateFile(ptszFile2unzip, GENERIC_WRITE, FILE_SHARE_WRITE, nullptr, CREATE_ALWAYS, file_info.external_fa, nullptr);
- if (hFile == INVALID_HANDLE_VALUE) {
- mir_free(ptszNewName);
- return false;
- }
+ if (hFile == INVALID_HANDLE_VALUE)
+ return GetLastError();
+
while (true) {
err = unzReadCurrentFile(uf, buf, DATA_BUF_SIZE);
if (err <= 0)
@@ -91,7 +89,7 @@ bool extractCurrentFile(unzFile uf, wchar_t *ptszDestPath, wchar_t *ptszBackPath DWORD bytes;
if (!WriteFile(hFile, buf, err, &bytes, FALSE)) {
- err = UNZ_ERRNO;
+ err = GetLastError();
break;
}
}
@@ -108,13 +106,12 @@ bool extractCurrentFile(unzFile uf, wchar_t *ptszDestPath, wchar_t *ptszBackPath if (hPipe)
SafeMoveFile(ptszFile2unzip, tszDestFile);
}
- mir_free(ptszNewName);
- return true;
+ return err;
}
-bool unzip(const wchar_t *ptszZipFile, wchar_t *ptszDestPath, wchar_t *ptszBackPath,bool ch)
+int unzip(const wchar_t *ptszZipFile, wchar_t *ptszDestPath, wchar_t *ptszBackPath,bool ch)
{
- bool bResult = true;
+ int iErrorCode = 0;
zlib_filefunc64_def ffunc;
fill_fopen64_filefunc(&ffunc);
@@ -122,12 +119,12 @@ bool unzip(const wchar_t *ptszZipFile, wchar_t *ptszDestPath, wchar_t *ptszBackP unzFile uf = unzOpen2_64(ptszZipFile, &ffunc);
if (uf) {
do {
- if (!extractCurrentFile(uf, ptszDestPath, ptszBackPath,ch))
- bResult = false;
+ if (int err = extractCurrentFile(uf, ptszDestPath, ptszBackPath,ch))
+ iErrorCode = err;
}
while (unzGoToNextFile(uf) == UNZ_OK);
unzClose(uf);
}
- return bResult;
+ return iErrorCode;
}
|