mirror of
https://github.com/reactos/reactos.git
synced 2025-05-29 22:18:13 +00:00
[RAPPS]
- Added DownloadManager class (static for now) - Multiple selection launches multiple download dialogs (Checkbox selection has a priority over Selection when clicking Install) *A preperation for lauching a single dialog with a list of apps* - Show currently installing app in the dialog window svn path=/branches/GSoC_2017/rapps/; revision=75417
This commit is contained in:
parent
9b5e78353a
commit
084ec8dee3
7 changed files with 221 additions and 187 deletions
|
@ -251,7 +251,7 @@ BOOL CAvailableApps::UpdateAppsDB()
|
||||||
if (!DeleteCurrentAppsDB())
|
if (!DeleteCurrentAppsDB())
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
DownloadApplicationsDB(APPLICATION_DATABASE_URL);
|
DownloadManager::DownloadApplicationsDB(APPLICATION_DATABASE_URL);
|
||||||
|
|
||||||
if (m_szPath.IsEmpty())
|
if (m_szPath.IsEmpty())
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -280,7 +280,7 @@ BOOL CAvailableApps::EnumAvailableApplications(INT EnumType, AVAILENUMPROC lpEnu
|
||||||
if (hFind == INVALID_HANDLE_VALUE)
|
if (hFind == INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
if (GetFileAttributesW(m_szCabPath) == INVALID_FILE_ATTRIBUTES)
|
if (GetFileAttributesW(m_szCabPath) == INVALID_FILE_ATTRIBUTES)
|
||||||
DownloadApplicationsDB(APPLICATION_DATABASE_URL);
|
DownloadManager::DownloadApplicationsDB(APPLICATION_DATABASE_URL);
|
||||||
|
|
||||||
ExtractFilesFromCab(m_szCabPath, m_szAppsPath);
|
ExtractFilesFromCab(m_szCabPath, m_szAppsPath);
|
||||||
hFind = FindFirstFileW(m_szSearchPath.GetString(), &FindFileData);
|
hFind = FindFirstFileW(m_szSearchPath.GetString(), &FindFileData);
|
||||||
|
|
|
@ -458,7 +458,7 @@ public:
|
||||||
|
|
||||||
BOOL GetCheckState(INT item)
|
BOOL GetCheckState(INT item)
|
||||||
{
|
{
|
||||||
return (BOOL) GetItemState(item, LVIS_STATEIMAGEMASK);
|
return (BOOL) (GetItemState(item, LVIS_STATEIMAGEMASK) >> 12) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID SetCheckState(INT item, BOOL fCheck)
|
VOID SetCheckState(INT item, BOOL fCheck)
|
||||||
|
@ -472,14 +472,15 @@ public:
|
||||||
SetCheckState(-1, bHasAllChecked);
|
SetCheckState(-1, bHasAllChecked);
|
||||||
}
|
}
|
||||||
|
|
||||||
ATL::CAtlList<PAPPLICATION_INFO> GetCheckedItems()
|
ATL::CSimpleArray<PAPPLICATION_INFO> GetCheckedItems()
|
||||||
{
|
{
|
||||||
ATL::CAtlList<PAPPLICATION_INFO> list;
|
ATL::CSimpleArray<PAPPLICATION_INFO> list;
|
||||||
for (INT i = 0; i != -1; i = GetNextItem(i, LVNI_ALL))
|
for (INT i = 0; i >= 0; i = GetNextItem(i, LVNI_ALL))
|
||||||
{
|
{
|
||||||
if (GetCheckState(i) != FALSE)
|
if (GetCheckState(i) != FALSE)
|
||||||
{
|
{
|
||||||
list.AddTail((PAPPLICATION_INFO) GetItemData(i));
|
PAPPLICATION_INFO pAppInfo = (PAPPLICATION_INFO) GetItemData(i);
|
||||||
|
list.Add(pAppInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
|
@ -1255,11 +1256,16 @@ private:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ID_INSTALL:
|
case ID_INSTALL:
|
||||||
if (DownloadApplication(-1))
|
if (nSelectedApps)
|
||||||
/* TODO: Implement install dialog
|
{
|
||||||
* if (InstallApplication(-1))
|
DownloadManager::DownloadListOfApplications(m_ListView->GetCheckedItems());
|
||||||
*/
|
|
||||||
UpdateApplicationsList(-1);
|
UpdateApplicationsList(-1);
|
||||||
|
}
|
||||||
|
else if(DownloadManager::DownloadApplication((PAPPLICATION_INFO) m_ListView->GetSelectionMark()))
|
||||||
|
{
|
||||||
|
UpdateApplicationsList(-1);
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ID_UNINSTALL:
|
case ID_UNINSTALL:
|
||||||
|
@ -1403,11 +1409,10 @@ private:
|
||||||
{
|
{
|
||||||
if (m_StatusBar)
|
if (m_StatusBar)
|
||||||
{
|
{
|
||||||
ATL::CStringW szBuffer1, szBuffer2;
|
ATL::CStringW szBuffer;
|
||||||
|
|
||||||
szBuffer2.LoadStringW(hInst, IDS_APPS_COUNT);
|
szBuffer.Format(IDS_APPS_COUNT, m_ListView->GetItemCount(), nSelectedApps);
|
||||||
szBuffer1.Format(szBuffer2, m_ListView->GetItemCount(), nSelectedApps);
|
m_StatusBar->SetText(szBuffer);
|
||||||
m_StatusBar->SetText(szBuffer1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ END
|
||||||
|
|
||||||
IDD_DOWNLOAD_DIALOG DIALOGEX 0, 0, 220, 72
|
IDD_DOWNLOAD_DIALOG DIALOGEX 0, 0, 220, 72
|
||||||
STYLE DS_SHELLFONT | DS_CENTER | WS_POPUPWINDOW | WS_CAPTION | WS_VISIBLE
|
STYLE DS_SHELLFONT | DS_CENTER | WS_POPUPWINDOW | WS_CAPTION | WS_VISIBLE
|
||||||
CAPTION "Downloading..."
|
CAPTION "Downloading %ls..."
|
||||||
FONT 8, "MS Shell Dlg"
|
FONT 8, "MS Shell Dlg"
|
||||||
BEGIN
|
BEGIN
|
||||||
CONTROL "Progress1", IDC_DOWNLOAD_PROGRESS, "msctls_progress32", WS_BORDER | PBS_SMOOTH, 10, 10, 200, 12
|
CONTROL "Progress1", IDC_DOWNLOAD_PROGRESS, "msctls_progress32", WS_BORDER | PBS_SMOOTH, 10, 10, 200, 12
|
||||||
|
@ -110,16 +110,6 @@ BEGIN
|
||||||
ICON IDI_MAIN, IDC_STATIC, 10, 10, 7, 30
|
ICON IDI_MAIN, IDC_STATIC, 10, 10, 7, 30
|
||||||
END
|
END
|
||||||
|
|
||||||
IDD_DOWNLOAD_DIALOG_MULTI DIALOGEX 0, 0, 220, 72
|
|
||||||
STYLE DS_SHELLFONT | DS_CENTER | WS_POPUPWINDOW | WS_CAPTION | WS_VISIBLE
|
|
||||||
CAPTION "Downloading (multiple)..."
|
|
||||||
FONT 8, "MS Shell Dlg"
|
|
||||||
BEGIN
|
|
||||||
CONTROL "Progress1", IDC_DOWNLOAD_PROGRESS, "msctls_progress32", WS_BORDER | PBS_SMOOTH, 10, 10, 200, 12
|
|
||||||
EDITTEXT IDC_DOWNLOAD_STATUS, 10, 28, 200, 22, ES_CENTER | ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY | WS_DISABLED | NOT WS_BORDER
|
|
||||||
PUSHBUTTON "Cancel", IDCANCEL, 85, 53, 50, 15, WS_GROUP | WS_TABSTOP
|
|
||||||
END
|
|
||||||
|
|
||||||
STRINGTABLE
|
STRINGTABLE
|
||||||
BEGIN
|
BEGIN
|
||||||
IDS_TOOLTIP_INSTALL "Install"
|
IDS_TOOLTIP_INSTALL "Install"
|
||||||
|
|
|
@ -92,7 +92,7 @@ END
|
||||||
|
|
||||||
IDD_DOWNLOAD_DIALOG DIALOGEX 0, 0, 220, 72
|
IDD_DOWNLOAD_DIALOG DIALOGEX 0, 0, 220, 72
|
||||||
STYLE DS_SHELLFONT | DS_CENTER | WS_POPUPWINDOW | WS_SYSMENU | WS_VISIBLE
|
STYLE DS_SHELLFONT | DS_CENTER | WS_POPUPWINDOW | WS_SYSMENU | WS_VISIBLE
|
||||||
CAPTION "Загрузка..."
|
CAPTION "Загрузка %ls..."
|
||||||
FONT 8, "MS Shell Dlg"
|
FONT 8, "MS Shell Dlg"
|
||||||
BEGIN
|
BEGIN
|
||||||
CONTROL "Progress1", IDC_DOWNLOAD_PROGRESS, "msctls_progress32", WS_BORDER | PBS_SMOOTH, 10, 10, 200, 12
|
CONTROL "Progress1", IDC_DOWNLOAD_PROGRESS, "msctls_progress32", WS_BORDER | PBS_SMOOTH, 10, 10, 200, 12
|
||||||
|
|
|
@ -100,7 +100,7 @@ END
|
||||||
|
|
||||||
IDD_DOWNLOAD_DIALOG DIALOGEX 0, 0, 220, 72
|
IDD_DOWNLOAD_DIALOG DIALOGEX 0, 0, 220, 72
|
||||||
STYLE DS_SHELLFONT | DS_CENTER | WS_POPUPWINDOW | WS_SYSMENU | WS_VISIBLE
|
STYLE DS_SHELLFONT | DS_CENTER | WS_POPUPWINDOW | WS_SYSMENU | WS_VISIBLE
|
||||||
CAPTION "Завантаження..."
|
CAPTION "Завантаження %ls..."
|
||||||
FONT 8, "MS Shell Dlg"
|
FONT 8, "MS Shell Dlg"
|
||||||
BEGIN
|
BEGIN
|
||||||
CONTROL "Progress1", IDC_DOWNLOAD_PROGRESS, "msctls_progress32", WS_BORDER | PBS_SMOOTH, 10, 10, 200, 12
|
CONTROL "Progress1", IDC_DOWNLOAD_PROGRESS, "msctls_progress32", WS_BORDER | PBS_SMOOTH, 10, 10, 200, 12
|
||||||
|
|
|
@ -39,8 +39,6 @@
|
||||||
#include <shellutils.h>
|
#include <shellutils.h>
|
||||||
#include <windowsx.h>
|
#include <windowsx.h>
|
||||||
|
|
||||||
static PAPPLICATION_INFO AppInfo;
|
|
||||||
|
|
||||||
class CDownloadDialog :
|
class CDownloadDialog :
|
||||||
public CComObjectRootEx<CComMultiThreadModelNoCS>,
|
public CComObjectRootEx<CComMultiThreadModelNoCS>,
|
||||||
public IBindStatusCallback
|
public IBindStatusCallback
|
||||||
|
@ -250,9 +248,151 @@ MessageBox_LoadString(HWND hMainWnd, INT StringID)
|
||||||
MessageBoxW(hMainWnd, szMsgText.GetString(), NULL, MB_OK | MB_ICONERROR);
|
MessageBoxW(hMainWnd, szMsgText.GetString(), NULL, MB_OK | MB_ICONERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
// DownloadManager
|
||||||
DWORD WINAPI
|
|
||||||
ThreadFunc(LPVOID Context)
|
PAPPLICATION_INFO DownloadManager::AppInfo = NULL;
|
||||||
|
|
||||||
|
INT_PTR CALLBACK DownloadManager::DownloadDlgProc(HWND Dlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
|
{
|
||||||
|
HANDLE Thread;
|
||||||
|
DWORD ThreadId;
|
||||||
|
HWND Item;
|
||||||
|
|
||||||
|
switch (uMsg)
|
||||||
|
{
|
||||||
|
case WM_INITDIALOG:
|
||||||
|
{
|
||||||
|
HICON hIconSm, hIconBg;
|
||||||
|
WCHAR szCaption[MAX_PATH];
|
||||||
|
ATL::CStringW szNewCaption;
|
||||||
|
|
||||||
|
hIconBg = (HICON) GetClassLongW(hMainWnd, GCLP_HICON);
|
||||||
|
hIconSm = (HICON) GetClassLongW(hMainWnd, GCLP_HICONSM);
|
||||||
|
|
||||||
|
if (hIconBg && hIconSm)
|
||||||
|
{
|
||||||
|
SendMessageW(Dlg, WM_SETICON, ICON_BIG, (LPARAM) hIconBg);
|
||||||
|
SendMessageW(Dlg, WM_SETICON, ICON_SMALL, (LPARAM) hIconSm);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Change caption to show the currently downloaded app
|
||||||
|
GetWindowTextW(Dlg, szCaption, MAX_PATH);
|
||||||
|
szNewCaption.Format(szCaption, AppInfo->szName.GetString());
|
||||||
|
SetWindowTextW(Dlg, szNewCaption.GetString());
|
||||||
|
|
||||||
|
SetWindowLongW(Dlg, GWLP_USERDATA, 0);
|
||||||
|
Item = GetDlgItem(Dlg, IDC_DOWNLOAD_PROGRESS);
|
||||||
|
if (Item)
|
||||||
|
{
|
||||||
|
// initialize the default values for our nifty progress bar
|
||||||
|
// and subclass it so that it learns to print a status text
|
||||||
|
SendMessageW(Item, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
|
||||||
|
SendMessageW(Item, PBM_SETPOS, 0, 0);
|
||||||
|
|
||||||
|
SetWindowSubclass(Item, DownloadProgressProc, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// add a neat placeholder until the download URL is retrieved
|
||||||
|
SetDlgItemTextW(Dlg, IDC_DOWNLOAD_STATUS, L"\x2022 \x2022 \x2022");
|
||||||
|
|
||||||
|
Thread = CreateThread(NULL, 0, ThreadFunc, Dlg, 0, &ThreadId);
|
||||||
|
if (!Thread)
|
||||||
|
return FALSE;
|
||||||
|
CloseHandle(Thread);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
case WM_COMMAND:
|
||||||
|
if (wParam == IDCANCEL)
|
||||||
|
{
|
||||||
|
SetWindowLongPtrW(Dlg, GWLP_USERDATA, 1);
|
||||||
|
PostMessageW(Dlg, WM_CLOSE, 0, 0);
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
case WM_CLOSE:
|
||||||
|
DestroyWindow(Dlg);
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LRESULT CALLBACK DownloadManager::DownloadProgressProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
|
||||||
|
{
|
||||||
|
static ATL::CStringW szProgressText;
|
||||||
|
|
||||||
|
switch (uMsg)
|
||||||
|
{
|
||||||
|
case WM_SETTEXT:
|
||||||
|
{
|
||||||
|
if (lParam)
|
||||||
|
{
|
||||||
|
szProgressText = (PCWSTR) lParam;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
case WM_ERASEBKGND:
|
||||||
|
case WM_PAINT:
|
||||||
|
{
|
||||||
|
PAINTSTRUCT ps;
|
||||||
|
HDC hDC = BeginPaint(hWnd, &ps), hdcMem;
|
||||||
|
HBITMAP hbmMem;
|
||||||
|
HANDLE hOld;
|
||||||
|
RECT myRect;
|
||||||
|
UINT win_width, win_height;
|
||||||
|
|
||||||
|
GetClientRect(hWnd, &myRect);
|
||||||
|
|
||||||
|
/* grab the progress bar rect size */
|
||||||
|
win_width = myRect.right - myRect.left;
|
||||||
|
win_height = myRect.bottom - myRect.top;
|
||||||
|
|
||||||
|
/* create an off-screen DC for double-buffering */
|
||||||
|
hdcMem = CreateCompatibleDC(hDC);
|
||||||
|
hbmMem = CreateCompatibleBitmap(hDC, win_width, win_height);
|
||||||
|
|
||||||
|
hOld = SelectObject(hdcMem, hbmMem);
|
||||||
|
|
||||||
|
/* call the original draw code and redirect it to our memory buffer */
|
||||||
|
DefSubclassProc(hWnd, uMsg, (WPARAM) hdcMem, lParam);
|
||||||
|
|
||||||
|
/* draw our nifty progress text over it */
|
||||||
|
SelectFont(hdcMem, GetStockFont(DEFAULT_GUI_FONT));
|
||||||
|
DrawShadowText(hdcMem, szProgressText.GetString(), szProgressText.GetLength(),
|
||||||
|
&myRect,
|
||||||
|
DT_CENTER | DT_VCENTER | DT_NOPREFIX | DT_SINGLELINE,
|
||||||
|
GetSysColor(COLOR_CAPTIONTEXT),
|
||||||
|
GetSysColor(COLOR_3DSHADOW),
|
||||||
|
1, 1);
|
||||||
|
|
||||||
|
/* transfer the off-screen DC to the screen */
|
||||||
|
BitBlt(hDC, 0, 0, win_width, win_height, hdcMem, 0, 0, SRCCOPY);
|
||||||
|
|
||||||
|
/* free the off-screen DC */
|
||||||
|
SelectObject(hdcMem, hOld);
|
||||||
|
DeleteObject(hbmMem);
|
||||||
|
DeleteDC(hdcMem);
|
||||||
|
|
||||||
|
EndPaint(hWnd, &ps);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Raymond Chen says that we should safely unsubclass all the things!
|
||||||
|
(http://blogs.msdn.com/b/oldnewthing/archive/2003/11/11/55653.aspx) */
|
||||||
|
case WM_NCDESTROY:
|
||||||
|
{
|
||||||
|
szProgressText.Empty();
|
||||||
|
RemoveWindowSubclass(hWnd, DownloadProgressProc, uIdSubclass);
|
||||||
|
}
|
||||||
|
/* Fall-through */
|
||||||
|
default:
|
||||||
|
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DWORD WINAPI DownloadManager::ThreadFunc(LPVOID Context)
|
||||||
{
|
{
|
||||||
CComPtr<IBindStatusCallback> dl;
|
CComPtr<IBindStatusCallback> dl;
|
||||||
ATL::CStringW Path;
|
ATL::CStringW Path;
|
||||||
|
@ -272,9 +412,15 @@ ThreadFunc(LPVOID Context)
|
||||||
URL_COMPONENTS urlComponents;
|
URL_COMPONENTS urlComponents;
|
||||||
size_t urlLength, filenameLength;
|
size_t urlLength, filenameLength;
|
||||||
|
|
||||||
|
if (!AppInfo)
|
||||||
|
{
|
||||||
|
MessageBox_LoadString(hMainWnd, IDS_UNABLE_TO_DOWNLOAD);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
/* build the path for the download */
|
/* build the path for the download */
|
||||||
p = wcsrchr(AppInfo->szUrlDownload, L'/');
|
p = wcsrchr(AppInfo->szUrlDownload.GetString(), L'/');
|
||||||
q = wcsrchr(AppInfo->szUrlDownload, L'?');
|
q = wcsrchr(AppInfo->szUrlDownload.GetString(), L'?');
|
||||||
|
|
||||||
/* do we have a final slash separator? */
|
/* do we have a final slash separator? */
|
||||||
if (!p)
|
if (!p)
|
||||||
|
@ -284,7 +430,7 @@ ThreadFunc(LPVOID Context)
|
||||||
filenameLength = wcslen(p) * sizeof(WCHAR);
|
filenameLength = wcslen(p) * sizeof(WCHAR);
|
||||||
|
|
||||||
/* do we have query arguments in the target URL after the filename? account for them
|
/* do we have query arguments in the target URL after the filename? account for them
|
||||||
(e.g. https://example.org/myfile.exe?no_adware_plz) */
|
(e.g. https://example.org/myfile.exe?no_adware_plz) */
|
||||||
if (q && q > p && (q - p) > 0)
|
if (q && q > p && (q - p) > 0)
|
||||||
filenameLength -= wcslen(q - 1) * sizeof(WCHAR);
|
filenameLength -= wcslen(q - 1) * sizeof(WCHAR);
|
||||||
|
|
||||||
|
@ -424,7 +570,7 @@ ThreadFunc(LPVOID Context)
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
/* if this thing isn't a RAPPS update and it has a SHA-1 checksum
|
/* if this thing isn't a RAPPS update and it has a SHA-1 checksum
|
||||||
verify its integrity by using the native advapi32.A_SHA1 functions */
|
verify its integrity by using the native advapi32.A_SHA1 functions */
|
||||||
if (!bCab && AppInfo->szSHA1[0] != 0)
|
if (!bCab && AppInfo->szSHA1[0] != 0)
|
||||||
{
|
{
|
||||||
ATL::CStringW szMsgText;
|
ATL::CStringW szMsgText;
|
||||||
|
@ -472,174 +618,49 @@ end:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: Maybe launch this (similar function) in a seperate thread, so the list could be updated
|
||||||
LRESULT CALLBACK
|
BOOL DownloadManager::DownloadListOfApplications(const ATL::CSimpleArray<PAPPLICATION_INFO>& AppsList)
|
||||||
DownloadProgressProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
|
|
||||||
{
|
{
|
||||||
static ATL::CStringW szProgressText;
|
BOOL bResult = TRUE;
|
||||||
|
|
||||||
switch (uMsg)
|
for (INT i = 0; i < AppsList.GetSize(); ++i)
|
||||||
{
|
{
|
||||||
case WM_SETTEXT:
|
bResult = DownloadApplication(AppsList[i]) && bResult;
|
||||||
{
|
|
||||||
if (lParam)
|
|
||||||
{
|
|
||||||
szProgressText = (PCWSTR) lParam;
|
|
||||||
}
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
case WM_ERASEBKGND:
|
|
||||||
case WM_PAINT:
|
|
||||||
{
|
|
||||||
PAINTSTRUCT ps;
|
|
||||||
HDC hDC = BeginPaint(hWnd, &ps), hdcMem;
|
|
||||||
HBITMAP hbmMem;
|
|
||||||
HANDLE hOld;
|
|
||||||
RECT myRect;
|
|
||||||
UINT win_width, win_height;
|
|
||||||
|
|
||||||
GetClientRect(hWnd, &myRect);
|
|
||||||
|
|
||||||
/* grab the progress bar rect size */
|
|
||||||
win_width = myRect.right - myRect.left;
|
|
||||||
win_height = myRect.bottom - myRect.top;
|
|
||||||
|
|
||||||
/* create an off-screen DC for double-buffering */
|
|
||||||
hdcMem = CreateCompatibleDC(hDC);
|
|
||||||
hbmMem = CreateCompatibleBitmap(hDC, win_width, win_height);
|
|
||||||
|
|
||||||
hOld = SelectObject(hdcMem, hbmMem);
|
|
||||||
|
|
||||||
/* call the original draw code and redirect it to our memory buffer */
|
|
||||||
DefSubclassProc(hWnd, uMsg, (WPARAM) hdcMem, lParam);
|
|
||||||
|
|
||||||
/* draw our nifty progress text over it */
|
|
||||||
SelectFont(hdcMem, GetStockFont(DEFAULT_GUI_FONT));
|
|
||||||
DrawShadowText(hdcMem, szProgressText.GetString(), szProgressText.GetLength(),
|
|
||||||
&myRect,
|
|
||||||
DT_CENTER | DT_VCENTER | DT_NOPREFIX | DT_SINGLELINE,
|
|
||||||
GetSysColor(COLOR_CAPTIONTEXT),
|
|
||||||
GetSysColor(COLOR_3DSHADOW),
|
|
||||||
1, 1);
|
|
||||||
|
|
||||||
/* transfer the off-screen DC to the screen */
|
|
||||||
BitBlt(hDC, 0, 0, win_width, win_height, hdcMem, 0, 0, SRCCOPY);
|
|
||||||
|
|
||||||
/* free the off-screen DC */
|
|
||||||
SelectObject(hdcMem, hOld);
|
|
||||||
DeleteObject(hbmMem);
|
|
||||||
DeleteDC(hdcMem);
|
|
||||||
|
|
||||||
EndPaint(hWnd, &ps);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Raymond Chen says that we should safely unsubclass all the things!
|
|
||||||
(http://blogs.msdn.com/b/oldnewthing/archive/2003/11/11/55653.aspx) */
|
|
||||||
case WM_NCDESTROY:
|
|
||||||
{
|
|
||||||
szProgressText.Empty();
|
|
||||||
RemoveWindowSubclass(hWnd, DownloadProgressProc, uIdSubclass);
|
|
||||||
}
|
|
||||||
/* Fall-through */
|
|
||||||
default:
|
|
||||||
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
|
|
||||||
}
|
}
|
||||||
|
return bResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
BOOL DownloadManager::DownloadApplication(PAPPLICATION_INFO pAppInfo)
|
||||||
INT_PTR CALLBACK
|
|
||||||
DownloadDlgProc(HWND Dlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
||||||
{
|
{
|
||||||
HANDLE Thread;
|
if (!pAppInfo)
|
||||||
DWORD ThreadId;
|
|
||||||
HWND Item;
|
|
||||||
|
|
||||||
switch (uMsg)
|
|
||||||
{
|
{
|
||||||
case WM_INITDIALOG:
|
|
||||||
{
|
|
||||||
HICON hIconSm = NULL, hIconBg = NULL;
|
|
||||||
|
|
||||||
hIconBg = (HICON) GetClassLongPtr(hMainWnd, GCLP_HICON);
|
|
||||||
hIconSm = (HICON) GetClassLongPtr(hMainWnd, GCLP_HICONSM);
|
|
||||||
|
|
||||||
if (hIconBg && hIconSm)
|
|
||||||
{
|
|
||||||
SendMessageW(Dlg, WM_SETICON, ICON_BIG, (LPARAM) hIconBg);
|
|
||||||
SendMessageW(Dlg, WM_SETICON, ICON_SMALL, (LPARAM) hIconSm);
|
|
||||||
}
|
|
||||||
|
|
||||||
SetWindowLongPtrW(Dlg, GWLP_USERDATA, 0);
|
|
||||||
Item = GetDlgItem(Dlg, IDC_DOWNLOAD_PROGRESS);
|
|
||||||
if (Item)
|
|
||||||
{
|
|
||||||
/* initialize the default values for our nifty progress bar
|
|
||||||
and subclass it so that it learns to print a status text */
|
|
||||||
SendMessageW(Item, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
|
|
||||||
SendMessageW(Item, PBM_SETPOS, 0, 0);
|
|
||||||
|
|
||||||
SetWindowSubclass(Item, DownloadProgressProc, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* add a neat placeholder until the download URL is retrieved */
|
|
||||||
Item = GetDlgItem(Dlg, IDC_DOWNLOAD_STATUS);
|
|
||||||
SendMessageW(Item, WM_SETTEXT, 0, (LPARAM) L"\x2022 \x2022 \x2022");
|
|
||||||
|
|
||||||
Thread = CreateThread(NULL, 0, ThreadFunc, Dlg, 0, &ThreadId);
|
|
||||||
if (!Thread)
|
|
||||||
return FALSE;
|
|
||||||
CloseHandle(Thread);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
case WM_COMMAND:
|
|
||||||
if (wParam == IDCANCEL)
|
|
||||||
{
|
|
||||||
SetWindowLongPtrW(Dlg, GWLP_USERDATA, 1);
|
|
||||||
PostMessageW(Dlg, WM_CLOSE, 0, 0);
|
|
||||||
}
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
case WM_CLOSE:
|
|
||||||
DestroyWindow(Dlg);
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
BOOL
|
// Create a dialog and issue a download process
|
||||||
DownloadApplication(INT Index)
|
AppInfo = pAppInfo;
|
||||||
{
|
LaunchDownloadDialog();
|
||||||
if (!IS_AVAILABLE_ENUM(SelectedEnumType))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
AppInfo = (PAPPLICATION_INFO) ListViewGetlParam(Index);
|
|
||||||
if (!AppInfo)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
WriteLogMessage(EVENTLOG_SUCCESS, MSG_SUCCESS_INSTALL, AppInfo->szName.GetString());
|
WriteLogMessage(EVENTLOG_SUCCESS, MSG_SUCCESS_INSTALL, AppInfo->szName.GetString());
|
||||||
|
|
||||||
CreateDialogW(hInst,
|
|
||||||
MAKEINTRESOURCEW(IDD_DOWNLOAD_DIALOG),
|
|
||||||
hMainWnd,
|
|
||||||
DownloadDlgProc);
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID
|
VOID DownloadManager::DownloadApplicationsDB(LPCWSTR lpUrl)
|
||||||
DownloadApplicationsDB(LPCWSTR lpUrl)
|
|
||||||
{
|
{
|
||||||
APPLICATION_INFO IntInfo;
|
APPLICATION_INFO IntInfo;
|
||||||
IntInfo.szUrlDownload = lpUrl;
|
IntInfo.szUrlDownload = lpUrl;
|
||||||
|
|
||||||
AppInfo = &IntInfo;
|
AppInfo = &IntInfo;
|
||||||
|
|
||||||
CreateDialogW(hInst,
|
LaunchDownloadDialog();
|
||||||
MAKEINTRESOURCEW(IDD_DOWNLOAD_DIALOG),
|
|
||||||
hMainWnd,
|
|
||||||
DownloadDlgProc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: Reuse the dialog
|
||||||
|
VOID DownloadManager::LaunchDownloadDialog()
|
||||||
|
{
|
||||||
|
CreateDialogW(hInst,
|
||||||
|
MAKEINTRESOURCEW(IDD_DOWNLOAD_DIALOG),
|
||||||
|
hMainWnd,
|
||||||
|
DownloadDlgProc);
|
||||||
|
}
|
|
@ -226,7 +226,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/* installdlg.cpp */
|
/* installdlg.cpp */
|
||||||
BOOL InstallApplication(INT Index);
|
//BOOL InstallApplication(INT Index);
|
||||||
|
|
||||||
/* installed.cpp */
|
/* installed.cpp */
|
||||||
typedef BOOL (CALLBACK *APPENUMPROC)(INT ItemIndex, ATL::CStringW &lpName, PINSTALLED_INFO Info);
|
typedef BOOL (CALLBACK *APPENUMPROC)(INT ItemIndex, ATL::CStringW &lpName, PINSTALLED_INFO Info);
|
||||||
|
@ -249,8 +249,26 @@ VOID SaveSettings(HWND hwnd);
|
||||||
VOID FillDefaultSettings(PSETTINGS_INFO pSettingsInfo);
|
VOID FillDefaultSettings(PSETTINGS_INFO pSettingsInfo);
|
||||||
|
|
||||||
/* loaddlg.cpp */
|
/* loaddlg.cpp */
|
||||||
BOOL DownloadApplication(INT Index);
|
|
||||||
VOID DownloadApplicationsDB(LPCWSTR lpUrl);
|
class DownloadManager
|
||||||
|
{
|
||||||
|
static PAPPLICATION_INFO AppInfo;
|
||||||
|
public:
|
||||||
|
|
||||||
|
static INT_PTR CALLBACK DownloadDlgProc(HWND Dlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||||
|
static LRESULT CALLBACK DownloadProgressProc(HWND hWnd,
|
||||||
|
UINT uMsg,
|
||||||
|
WPARAM wParam,
|
||||||
|
LPARAM lParam,
|
||||||
|
UINT_PTR uIdSubclass,
|
||||||
|
DWORD_PTR dwRefData);
|
||||||
|
|
||||||
|
static DWORD WINAPI ThreadFunc(LPVOID Context);
|
||||||
|
static BOOL DownloadListOfApplications(const ATL::CSimpleArray<PAPPLICATION_INFO>& AppsList);
|
||||||
|
static BOOL DownloadApplication(PAPPLICATION_INFO pAppInfo);
|
||||||
|
static VOID DownloadApplicationsDB(LPCWSTR lpUrl);
|
||||||
|
static VOID LaunchDownloadDialog();
|
||||||
|
};
|
||||||
|
|
||||||
/* misc.cpp */
|
/* misc.cpp */
|
||||||
INT GetSystemColorDepth(VOID);
|
INT GetSystemColorDepth(VOID);
|
||||||
|
|
Loading…
Reference in a new issue