diff options
-rw-r--r-- | plugins/PluginUpdater/src/DlgListNew.cpp | 2 | ||||
-rw-r--r-- | plugins/PluginUpdater/src/DlgUpdate.cpp | 4 | ||||
-rw-r--r-- | plugins/PluginUpdater/src/Utils.cpp | 87 | ||||
-rw-r--r-- | plugins/PluginUpdater/src/stdafx.h | 2 | ||||
-rw-r--r-- | plugins/PluginUpdater/src/version.h | 2 |
5 files changed, 52 insertions, 45 deletions
diff --git a/plugins/PluginUpdater/src/DlgListNew.cpp b/plugins/PluginUpdater/src/DlgListNew.cpp index 204a84e06f..d93b3fc043 100644 --- a/plugins/PluginUpdater/src/DlgListNew.cpp +++ b/plugins/PluginUpdater/src/DlgListNew.cpp @@ -311,7 +311,7 @@ public: // download update
m_list.SetItemText(i, 1, TranslateT("Downloading..."));
- if (DownloadFile(&p->File, nlc)) {
+ if (DownloadFile(&p->File, nlc) == ERROR_SUCCESS) {
m_list.SetItemText(i, 1, TranslateT("Succeeded."));
if (!unzip(p->File.wszDiskPath, wszMirandaPath, wszBackupFolder, false))
PU::SafeDeleteFile(p->File.wszDiskPath); // remove .zip after successful update
diff --git a/plugins/PluginUpdater/src/DlgUpdate.cpp b/plugins/PluginUpdater/src/DlgUpdate.cpp index 3629ced550..e177fe13ec 100644 --- a/plugins/PluginUpdater/src/DlgUpdate.cpp +++ b/plugins/PluginUpdater/src/DlgUpdate.cpp @@ -67,7 +67,7 @@ class CUpdateDLg : public CDlgBase pDlg->m_list.SetItemText(i, 1, TranslateT("Downloading..."));
FILEURL *pFileUrl = &todo[i].File;
- if (!DownloadFile(pFileUrl, nlc)) {
+ if (DownloadFile(pFileUrl, nlc) != ERROR_SUCCESS) {
pDlg->m_list.SetItemText(i, 1, TranslateT("Failed!"));
// interrupt update as we require all components to be updated
@@ -413,7 +413,7 @@ static void DlgUpdateSilent(void *param) count++;
else if (it->bEnabled) {
// download update
- if (!DownloadFile(&it->File, nlc)) {
+ if (DownloadFile(&it->File, nlc) != ERROR_SUCCESS) {
// interrupt update as we require all components to be updated
Netlib_CloseHandle(nlc);
Skin_PlaySound("updatefailed");
diff --git a/plugins/PluginUpdater/src/Utils.cpp b/plugins/PluginUpdater/src/Utils.cpp index f76e47237e..9d05d695b1 100644 --- a/plugins/PluginUpdater/src/Utils.cpp +++ b/plugins/PluginUpdater/src/Utils.cpp @@ -49,12 +49,15 @@ bool ParseHashes(const wchar_t *pwszUrl, ptrW &baseUrl, SERVLIST &arHashes) pFileUrl.CRCsum = 0;
HNETLIBCONN nlc = nullptr;
- bool ret = DownloadFile(&pFileUrl, nlc);
+ int ret = DownloadFile(&pFileUrl, nlc);
Netlib_CloseHandle(nlc);
- if (!ret) {
- Netlib_LogfW(g_hNetlibUser, L"Downloading list of available updates from %s failed", baseUrl.get());
- ShowPopup(TranslateT("Plugin Updater"), TranslateT("An error occurred while checking for new updates."), POPUP_TYPE_ERROR);
+ if (ret != ERROR_SUCCESS) {
+ Netlib_LogfW(g_hNetlibUser, L"Downloading list of available updates from %s failed with error %d", baseUrl.get(), ret);
+ if (ret == 404)
+ ShowPopup(TranslateT("Plugin Updater"), TranslateT("Updates are temporarily disabled, try again later."), POPUP_TYPE_INFO);
+ else
+ ShowPopup(TranslateT("Plugin Updater"), TranslateT("An error occurred while checking for new updates."), POPUP_TYPE_ERROR);
Skin_PlaySound("updatefailed");
return false;
}
@@ -122,7 +125,7 @@ bool ParseHashes(const wchar_t *pwszUrl, ptrW &baseUrl, SERVLIST &arHashes) /////////////////////////////////////////////////////////////////////////////////////////
// Single file HTTP transaction
-bool DownloadFile(FILEURL *pFileURL, HNETLIBCONN &nlc)
+int DownloadFile(FILEURL *pFileURL, HNETLIBCONN &nlc)
{
char szMirVer[100];
Miranda_GetVersionText(szMirVer, _countof(szMirVer));
@@ -162,49 +165,53 @@ bool DownloadFile(FILEURL *pFileURL, HNETLIBCONN &nlc) for (int i = 0; i < MAX_RETRIES; i++) {
Netlib_LogfW(g_hNetlibUser, L"Downloading file %s to %s (attempt %d)", pFileURL->wszDownloadURL, pFileURL->wszDiskPath, i + 1);
NLHR_PTR pReply(Netlib_HttpTransaction(g_hNetlibUser, &nlhr));
- if (pReply) {
- nlc = pReply->nlc;
- if ((200 == pReply->resultCode) && (pReply->dataLength > 0)) {
- // Check CRC sum
- if (pFileURL->CRCsum) {
- int crc = crc32(0, (unsigned char *)pReply->pData, pReply->dataLength);
- if (crc != pFileURL->CRCsum) {
- // crc check failed, try again
- Netlib_LogfW(g_hNetlibUser, L"crc check failed for file %s", pFileURL->wszDiskPath);
- continue;
- }
- }
+ if (pReply == nullptr) {
+ Netlib_LogfW(g_hNetlibUser, L"Downloading file %s failed, host is propably temporary down.", pFileURL->wszDownloadURL);
+ nlc = nullptr;
+ continue;
+ }
- DWORD dwBytes;
- HANDLE hFile = CreateFile(pFileURL->wszDiskPath, GENERIC_READ | GENERIC_WRITE, NULL, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
- if (hFile != INVALID_HANDLE_VALUE) {
- // write the downloaded file directly
- WriteFile(hFile, pReply->pData, (DWORD)pReply->dataLength, &dwBytes, nullptr);
- CloseHandle(hFile);
- }
- else {
- // try to write it via PU stub
- TFileName wszTempFile;
- mir_snwprintf(wszTempFile, L"%s\\pulocal.tmp", g_wszTempPath);
- hFile = CreateFile(wszTempFile, GENERIC_READ | GENERIC_WRITE, NULL, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
- if (hFile != INVALID_HANDLE_VALUE) {
- WriteFile(hFile, pReply->pData, (DWORD)pReply->dataLength, &dwBytes, nullptr);
- CloseHandle(hFile);
- PU::SafeMoveFile(wszTempFile, pFileURL->wszDiskPath);
- }
- }
- return true;
- }
+ nlc = pReply->nlc;
+ if (pReply->resultCode != 200 || pReply->dataLength <= 0) {
Netlib_LogfW(g_hNetlibUser, L"Downloading file %s failed with error %d", pFileURL->wszDownloadURL, pReply->resultCode);
+ return pReply->resultCode;
+ }
+
+ // Check CRC sum
+ if (pFileURL->CRCsum) {
+ int crc = crc32(0, (unsigned char *)pReply->pData, pReply->dataLength);
+ if (crc != pFileURL->CRCsum) {
+ // crc check failed, try again
+ Netlib_LogfW(g_hNetlibUser, L"crc check failed for file %s", pFileURL->wszDiskPath);
+ continue;
+ }
+ }
+
+ // everything is ok, write file down
+ DWORD dwBytes;
+ HANDLE hFile = CreateFile(pFileURL->wszDiskPath, GENERIC_READ | GENERIC_WRITE, NULL, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
+ if (hFile != INVALID_HANDLE_VALUE) {
+ // write the downloaded file directly
+ WriteFile(hFile, pReply->pData, (DWORD)pReply->dataLength, &dwBytes, nullptr);
+ CloseHandle(hFile);
}
else {
- Netlib_LogfW(g_hNetlibUser, L"Downloading file %s failed, host is propably temporary down.", pFileURL->wszDownloadURL);
- nlc = nullptr;
+ // try to write it via PU stub
+ TFileName wszTempFile;
+ mir_snwprintf(wszTempFile, L"%s\\pulocal.tmp", g_wszTempPath);
+ hFile = CreateFile(wszTempFile, GENERIC_READ | GENERIC_WRITE, NULL, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
+ if (hFile != INVALID_HANDLE_VALUE) {
+ WriteFile(hFile, pReply->pData, (DWORD)pReply->dataLength, &dwBytes, nullptr);
+ CloseHandle(hFile);
+ PU::SafeMoveFile(wszTempFile, pFileURL->wszDiskPath);
+ }
}
+ return ERROR_SUCCESS;
}
+ // no more retries, return previous error code
Netlib_LogfW(g_hNetlibUser, L"Downloading file %s failed, giving up", pFileURL->wszDownloadURL);
- return false;
+ return 500;
}
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/plugins/PluginUpdater/src/stdafx.h b/plugins/PluginUpdater/src/stdafx.h index 5d0690310e..a654e0997b 100644 --- a/plugins/PluginUpdater/src/stdafx.h +++ b/plugins/PluginUpdater/src/stdafx.h @@ -250,7 +250,7 @@ bool ParseHashes(const wchar_t *pwszUrl, ptrW &baseUrl, SERVLIST &arHashes); int CompareHashes(const ServListEntry *p1, const ServListEntry *p2);
wchar_t* GetDefaultUrl();
-bool DownloadFile(FILEURL *pFileURL, HNETLIBCONN &nlc);
+int DownloadFile(FILEURL *pFileURL, HNETLIBCONN &nlc);
void ShowPopup(LPCTSTR Title, LPCTSTR Text, int Number);
diff --git a/plugins/PluginUpdater/src/version.h b/plugins/PluginUpdater/src/version.h index 80406fc699..061c6606b9 100644 --- a/plugins/PluginUpdater/src/version.h +++ b/plugins/PluginUpdater/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 2 #define __RELEASE_NUM 0 -#define __BUILD_NUM 11 +#define __BUILD_NUM 12 #include <stdver.h> |