#include <wininet.h>
#include <shellutils.h>
+#include <debug.h>
+
#include <rosctrls.h>
#include <windowsx.h>
#include <process.h>
}
}
+VOID ShowLastError(
+ HWND hWndOwner,
+ DWORD dwLastError)
+{
+ LPWSTR lpMsg;
+
+ if (!FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ dwLastError,
+ LANG_USER_DEFAULT,
+ (LPWSTR)&lpMsg,
+ 0, NULL))
+ {
+ return;
+ }
+
+ MessageBoxW(hWndOwner, lpMsg, NULL, MB_OK | MB_ICONERROR);
+ LocalFree(lpMsg);
+}
+
unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param)
{
ATL::CStringW Path;
{
bCab = TRUE;
if (!GetStorageDirectory(Path))
+ {
+ ShowLastError(hMainWnd, GetLastError());
goto end;
+ }
}
else
{
// do we have a final slash separator?
if (!p)
+ {
+ MessageBox_LoadString(hMainWnd, IDS_UNABLE_PATH);
goto end;
+ }
// prepare the tentative length of the filename, maybe we've to remove part of it later on
filenameLength = wcslen(p) * sizeof(WCHAR);
if (GetFileAttributesW(Path.GetString()) == INVALID_FILE_ATTRIBUTES)
{
if (!CreateDirectoryW(Path.GetString(), NULL))
+ {
+ ShowLastError(hMainWnd, GetLastError());
goto end;
+ }
}
// append a \ to the provided file system path, and the filename portion from the URL after that
}
if (!hOpen)
+ {
+ ShowLastError(hMainWnd, GetLastError());
goto end;
+ }
dwStatusLen = sizeof(dwStatus);
urlComponents.lpszHostName = (LPWSTR) malloc(urlComponents.dwHostNameLength * sizeof(WCHAR));
if (!InternetCrackUrlW(InfoArray[iAppId].szUrl, urlLength + 1, ICU_DECODE | ICU_ESCAPE, &urlComponents))
+ {
+ ShowLastError(hMainWnd, GetLastError());
goto end;
+ }
dwContentLen = 0;
0);
if (!hFile)
{
- MessageBox_LoadString(hMainWnd, IDS_UNABLE_TO_DOWNLOAD2);
+ ShowLastError(hMainWnd, GetLastError());
goto end;
}
// query connection
if (!HttpQueryInfoW(hFile, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &dwStatus, &dwStatusLen, NULL))
+ {
+ ShowLastError(hMainWnd, GetLastError());
goto end;
+ }
if (dwStatus != HTTP_STATUS_OK)
{
0);
if (!hFile)
{
- MessageBox_LoadString(hMainWnd, IDS_UNABLE_TO_DOWNLOAD2);
+ ShowLastError(hMainWnd, GetLastError());
goto end;
}
hOut = CreateFileW(Path.GetString(), GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, 0, NULL);
if (hOut == INVALID_HANDLE_VALUE)
+ {
+ ShowLastError(hMainWnd, GetLastError());
goto end;
+ }
dwCurrentBytesRead = 0;
do
{
if (!InternetReadFile(hFile, lpBuffer, _countof(lpBuffer), &dwBytesRead))
{
- MessageBox_LoadString(hMainWnd, IDS_INTERRUPTED_DOWNLOAD);
+ ShowLastError(hMainWnd, GetLastError());
goto end;
}
if (!WriteFile(hOut, &lpBuffer[0], dwBytesRead, &dwBytesWritten, NULL))
{
- MessageBox_LoadString(hMainWnd, IDS_UNABLE_TO_WRITE);
+ ShowLastError(hMainWnd, GetLastError());
goto end;
}
hOut = INVALID_HANDLE_VALUE;
if (bCancelled)
+ {
+ DPRINT1("Operation cancelled\n");
goto end;
+ }
if (!dwContentLen)
{
// change a few strings in the download dialog to reflect the verification process
if (!szMsgText.LoadStringW(IDS_INTEG_CHECK_TITLE))
+ {
+ DPRINT1("Unable to load string\n");
goto end;
+ }
SetWindowTextW(hDlg, szMsgText.GetString());
SendMessageW(GetDlgItem(hDlg, IDC_DOWNLOAD_STATUS), WM_SETTEXT, 0, (LPARAM) Path.GetString());
if (!VerifyInteg(InfoArray[iAppId].szSHA1.GetString(), Path.GetString()))
{
if (!szMsgText.LoadStringW(IDS_INTEG_CHECK_FAIL))
+ {
+ DPRINT1("Unable to load string\n");
goto end;
+ }
MessageBoxW(hDlg, szMsgText.GetString(), NULL, MB_OK | MB_ICONERROR);
goto end;
}
else
{
- MessageBox_LoadString(hMainWnd, IDS_UNABLE_TO_INSTALL);
+ ShowLastError(hMainWnd, GetLastError());
}
}