ReactOS  0.4.13-dev-563-g0561610
CDownloadManager Class Reference

#include <dialogs.h>

Collaboration diagram for CDownloadManager:

Static Public Member Functions

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< CAvailableApplicationInfo > &AppsList, BOOL bIsModal=FALSE)
 
static BOOL DownloadApplication (CAvailableApplicationInfo *pAppInfo, BOOL bIsModal=FALSE)
 
static VOID DownloadApplicationsDB (LPCWSTR lpUrl)
 
static VOID LaunchDownloadDialog (BOOL)
 

Static Private Member Functions

static VOID Download (const DownloadInfo &DLInfo, BOOL bIsModal=FALSE)
 
static VOID SetProgressMarquee (HWND Item, BOOL Enable)
 

Static Private Attributes

static ATL::CSimpleArray< DownloadInfoAppsToInstallList
 
static CDowloadingAppsListView DownloadsListView
 

Detailed Description

Definition at line 12 of file dialogs.h.

Member Function Documentation

◆ Download()

VOID CDownloadManager::Download ( const DownloadInfo DLInfo,
BOOL  bIsModal = FALSE 
)
staticprivate

Definition at line 391 of file loaddlg.cpp.

392 {
394  AppsToInstallList.Add(DLInfo);
395  LaunchDownloadDialog(bIsModal);
396 }
BOOL Add(const T &t)
Definition: atlsimpcoll.h:58
static VOID LaunchDownloadDialog(BOOL)
Definition: loaddlg.cpp:965
static ATL::CSimpleArray< DownloadInfo > AppsToInstallList
Definition: dialogs.h:14

Referenced by DownloadApplication(), and DownloadApplicationsDB().

◆ DownloadApplication()

BOOL CDownloadManager::DownloadApplication ( CAvailableApplicationInfo pAppInfo,
BOOL  bIsModal = FALSE 
)
static

Definition at line 947 of file loaddlg.cpp.

948 {
949  if (!pAppInfo)
950  return FALSE;
951 
952  Download(*pAppInfo, bIsModal);
953  return TRUE;
954 }
#define TRUE
Definition: types.h:120
static VOID Download(const DownloadInfo &DLInfo, BOOL bIsModal=FALSE)
Definition: loaddlg.cpp:391

Referenced by CMainWindow::OnCommand().

◆ DownloadApplicationsDB()

VOID CDownloadManager::DownloadApplicationsDB ( LPCWSTR  lpUrl)
static

Definition at line 956 of file loaddlg.cpp.

957 {
958  static DownloadInfo DatabaseDLInfo;
959  DatabaseDLInfo.szUrl = lpUrl;
960  DatabaseDLInfo.szName.LoadStringW(IDS_DL_DIALOG_DB_DISP);
961  Download(DatabaseDLInfo, TRUE);
962 }
#define TRUE
Definition: types.h:120
#define IDS_DL_DIALOG_DB_DISP
Definition: resource.h:206
static VOID Download(const DownloadInfo &DLInfo, BOOL bIsModal=FALSE)
Definition: loaddlg.cpp:391
ATL::CStringW szUrl
Definition: loaddlg.cpp:79
ATL::CStringW szName
Definition: loaddlg.cpp:80

Referenced by CAvailableApps::UpdateAppsDB().

◆ DownloadDlgProc()

INT_PTR CALLBACK CDownloadManager::DownloadDlgProc ( HWND  Dlg,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 398 of file loaddlg.cpp.

399 {
400  static WCHAR szCaption[MAX_PATH];
401 
402  switch (uMsg)
403  {
404  case WM_INITDIALOG:
405  {
406  HICON hIconSm, hIconBg;
407  ATL::CStringW szTempCaption;
408 
411 
412  if (hIconBg && hIconSm)
413  {
414  SendMessageW(Dlg, WM_SETICON, ICON_BIG, (LPARAM) hIconBg);
415  SendMessageW(Dlg, WM_SETICON, ICON_SMALL, (LPARAM) hIconSm);
416  }
417 
418  SetWindowLongW(Dlg, GWLP_USERDATA, 0);
420  if (Item)
421  {
422  // initialize the default values for our nifty progress bar
423  // and subclass it so that it learns to print a status text
424  SendMessageW(Item, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
425  SendMessageW(Item, PBM_SETPOS, 0, 0);
426 
428  }
429 
430  // Add a ListView
432  if (!hListView)
433  {
434  return FALSE;
435  }
437 
438  // Get a dlg string for later use
439  GetWindowTextW(Dlg, szCaption, _countof(szCaption));
440 
441  // Hide a placeholder from displaying
442  szTempCaption = szCaption;
443  szTempCaption.Replace(L"%ls", L"");
444  SetWindowText(Dlg, szTempCaption.GetString());
445 
446  ShowWindow(Dlg, SW_SHOW);
447 
448  // Start download process
449  DownloadParam *param = new DownloadParam(Dlg, AppsToInstallList, szCaption);
450  DWORD ThreadId;
451  HANDLE Thread = CreateThread(NULL, 0, ThreadFunc, (LPVOID) param, 0, &ThreadId);
452 
453  if (!Thread)
454  {
455  return FALSE;
456  }
457 
460  return TRUE;
461  }
462 
463  case WM_COMMAND:
464  if (wParam == IDCANCEL)
465  {
466  SetWindowLongW(Dlg, GWLP_USERDATA, 1);
467  PostMessageW(Dlg, WM_CLOSE, 0, 0);
468  }
469  return FALSE;
470 
471  case WM_CLOSE:
472  EndDialog(Dlg, 0);
473  //DestroyWindow(Dlg);
474  return TRUE;
475 
476  default:
477  return FALSE;
478  }
479 }
static LRESULT CALLBACK DownloadProgressProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
Definition: loaddlg.cpp:481
static HICON
Definition: imagelist.c:84
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
#define _countof(array)
Definition: fontsub.cpp:30
#define MAKELPARAM(l, h)
Definition: winuser.h:3915
#define PBM_SETPOS
Definition: commctrl.h:2156
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
WPARAM wParam
Definition: combotst.c:138
#define ICON_SMALL
Definition: tnclass.cpp:48
#define PBM_SETRANGE
Definition: commctrl.h:2155
LONG WINAPI SetWindowLongW(_In_ HWND, _In_ int, _In_ LONG)
#define GWLP_USERDATA
Definition: treelist.c:63
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:111
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
static CDowloadingAppsListView DownloadsListView
Definition: dialogs.h:15
#define SW_SHOW
Definition: winuser.h:769
VOID LoadList(ATL::CSimpleArray< DownloadInfo > arrInfo)
Definition: loaddlg.cpp:278
BOOL WINAPI SetWindowSubclass(HWND hWnd, SUBCLASSPROC pfnSubclass, UINT_PTR uIDSubclass, DWORD_PTR dwRef)
Definition: commctrl.c:1261
#define GCLP_HICONSM
Definition: winuser.h:670
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define WM_CLOSE
Definition: winuser.h:1603
GLfloat param
Definition: glext.h:5796
#define MAX_PATH
Definition: compat.h:26
PCXSTR GetString() const
Definition: atlsimpstr.h:361
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
#define IDC_DOWNLOAD_PROGRESS
Definition: resource.h:40
HWND hMainWnd
Definition: magnifier.c:32
static const WCHAR L[]
Definition: oid.c:1250
#define GCLP_HICON
Definition: winuser.h:669
#define WM_COMMAND
Definition: winuser.h:1716
static ATL::CSimpleArray< DownloadInfo > AppsToInstallList
Definition: dialogs.h:14
int Replace(PCXSTR pszOld, PCXSTR pszNew)
Definition: cstringt.h:696
HWND hListView
Definition: gui.cpp:29
int WINAPI GetWindowTextW(HWND hWnd, LPWSTR lpString, int nMaxCount)
Definition: window.c:1378
HWND Create(HWND hwndParent)
Definition: loaddlg.cpp:264
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
static DWORD WINAPI ThreadFunc(LPVOID Context)
Definition: loaddlg.cpp:576
#define SetWindowText
Definition: winuser.h:5723
BOOL WINAPI PostMessageW(_In_opt_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
HICON hIconSm
Definition: msconfig.c:44
#define IDCANCEL
Definition: winuser.h:825
#define WM_INITDIALOG
Definition: winuser.h:1715
#define GetClassLongPtrW
Definition: winuser.h:4433
#define ICON_BIG
Definition: tnclass.cpp:51

Referenced by LaunchDownloadDialog().

◆ DownloadListOfApplications()

BOOL CDownloadManager::DownloadListOfApplications ( const ATL::CSimpleArray< CAvailableApplicationInfo > &  AppsList,
BOOL  bIsModal = FALSE 
)
static

Definition at line 930 of file loaddlg.cpp.

931 {
932  if (AppsList.GetSize() == 0)
933  return FALSE;
934 
935  // Initialize shared variables
936  for (INT i = 0; i < AppsList.GetSize(); ++i)
937  {
938  AppsToInstallList.Add(AppsList[i]); // implicit conversion to DownloadInfo
939  }
940 
941  // Create a dialog and issue a download process
942  LaunchDownloadDialog(bIsModal);
943 
944  return TRUE;
945 }
#define TRUE
Definition: types.h:120
BOOL Add(const T &t)
Definition: atlsimpcoll.h:58
static VOID LaunchDownloadDialog(BOOL)
Definition: loaddlg.cpp:965
int GetSize() const
Definition: atlsimpcoll.h:104
int32_t INT
Definition: typedefs.h:56
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static ATL::CSimpleArray< DownloadInfo > AppsToInstallList
Definition: dialogs.h:14

Referenced by CMainWindow::OnCommand(), and UseCmdParameters().

◆ DownloadProgressProc()

LRESULT CALLBACK CDownloadManager::DownloadProgressProc ( HWND  hWnd,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam,
UINT_PTR  uIdSubclass,
DWORD_PTR  dwRefData 
)
static

Definition at line 481 of file loaddlg.cpp.

487 {
488  static ATL::CStringW szProgressText;
489 
490  switch (uMsg)
491  {
492  case WM_SETTEXT:
493  {
494  if (lParam)
495  {
496  szProgressText = (PCWSTR) lParam;
497  }
498  return TRUE;
499  }
500 
501  case WM_ERASEBKGND:
502  case WM_PAINT:
503  {
504  PAINTSTRUCT ps;
505  HDC hDC = BeginPaint(hWnd, &ps), hdcMem;
506  HBITMAP hbmMem;
507  HANDLE hOld;
508  RECT myRect;
509  UINT win_width, win_height;
510 
511  GetClientRect(hWnd, &myRect);
512 
513  /* grab the progress bar rect size */
514  win_width = myRect.right - myRect.left;
515  win_height = myRect.bottom - myRect.top;
516 
517  /* create an off-screen DC for double-buffering */
519  hbmMem = CreateCompatibleBitmap(hDC, win_width, win_height);
520 
521  hOld = SelectObject(hdcMem, hbmMem);
522 
523  /* call the original draw code and redirect it to our memory buffer */
525 
526  /* draw our nifty progress text over it */
528  DrawShadowText(hdcMem, szProgressText.GetString(), szProgressText.GetLength(),
529  &myRect,
533  1, 1);
534 
535  /* transfer the off-screen DC to the screen */
536  BitBlt(hDC, 0, 0, win_width, win_height, hdcMem, 0, 0, SRCCOPY);
537 
538  /* free the off-screen DC */
539  SelectObject(hdcMem, hOld);
540  DeleteObject(hbmMem);
541  DeleteDC(hdcMem);
542 
543  EndPaint(hWnd, &ps);
544  return 0;
545  }
546 
547  /* Raymond Chen says that we should safely unsubclass all the things!
548  (http://blogs.msdn.com/b/oldnewthing/archive/2003/11/11/55653.aspx) */
549 
550  case WM_NCDESTROY:
551  {
552  szProgressText.Empty();
554  }
555  /* Fall-through */
556  default:
557  return DefSubclassProc(hWnd, uMsg, wParam, lParam);
558  }
559 }
int GetLength() const
Definition: atlsimpstr.h:356
static LRESULT CALLBACK DownloadProgressProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
Definition: loaddlg.cpp:481
const uint16_t * PCWSTR
Definition: typedefs.h:55
#define TRUE
Definition: types.h:120
#define GetStockFont(i)
Definition: windowsx.h:283
HBITMAP WINAPI CreateCompatibleBitmap(_In_ HDC hdc, _In_ INT cx, _In_ INT cy)
static HDC
Definition: imagelist.c:92
HWND hWnd
Definition: settings.c:17
LONG top
Definition: windef.h:292
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
#define COLOR_CAPTIONTEXT
Definition: winuser.h:912
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
UINT_PTR WPARAM
Definition: windef.h:207
LONG left
Definition: windef.h:291
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
LONG right
Definition: windef.h:293
#define DT_NOPREFIX
Definition: winuser.h:537
static VOID NTAPI BitBlt(IN ULONG Left, IN ULONG Top, IN ULONG Width, IN ULONG Height, IN PUCHAR Buffer, IN ULONG BitsPerPixel, IN ULONG Delta)
Definition: vga.c:410
DWORD WINAPI GetSysColor(_In_ int)
WPARAM wParam
Definition: combotst.c:138
#define COLOR_3DSHADOW
Definition: winuser.h:921
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
int WINAPI DrawShadowText(HDC hdc, LPCWSTR pszText, UINT cch, RECT *prc, DWORD dwFlags, COLORREF crText, COLORREF crShadow, int ixOffset, int iyOffset)
Definition: commctrl.c:1845
LRESULT WINAPI DefSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: commctrl.c:1496
#define DT_VCENTER
Definition: winuser.h:543
#define WM_SETTEXT
Definition: winuser.h:1599
#define WM_NCDESTROY
Definition: winuser.h:1666
PCXSTR GetString() const
Definition: atlsimpstr.h:361
#define DEFAULT_GUI_FONT
Definition: wingdi.h:908
#define WM_PAINT
Definition: winuser.h:1602
#define SelectFont(hdc, hfont)
Definition: windowsx.h:486
static HDC hDC
Definition: 3dtext.c:33
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define DT_SINGLELINE
Definition: winuser.h:540
BOOL WINAPI RemoveWindowSubclass(HWND hWnd, SUBCLASSPROC pfnSubclass, UINT_PTR uID)
Definition: commctrl.c:1390
BOOL WINAPI DeleteDC(_In_ HDC)
unsigned int UINT
Definition: ndis.h:50
LONG bottom
Definition: windef.h:294
#define DT_CENTER
Definition: winuser.h:527
static HBITMAP
Definition: button.c:44
#define WM_ERASEBKGND
Definition: winuser.h:1607
LPARAM lParam
Definition: combotst.c:139
_In_ SUBCLASSPROC _In_ UINT_PTR uIdSubclass
Definition: commctrl.h:5027
#define SRCCOPY
Definition: wingdi.h:332
HDC hdcMem
Definition: welcome.c:104

Referenced by DownloadDlgProc().

◆ LaunchDownloadDialog()

VOID CDownloadManager::LaunchDownloadDialog ( BOOL  bIsModal)
static

Definition at line 965 of file loaddlg.cpp.

966 {
967  if (bIsModal)
968  {
971  hMainWnd,
973  }
974  else
975  {
978  hMainWnd,
980  }
981 }
#define IDD_DOWNLOAD_DIALOG
Definition: resource.h:61
#define DialogBoxW(i, t, p, f)
Definition: winuser.h:4268
static INT_PTR CALLBACK DownloadDlgProc(HWND Dlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: loaddlg.cpp:398
HWND hMainWnd
Definition: magnifier.c:32
#define CreateDialogW(h, n, w, f)
Definition: winuser.h:4150
HINSTANCE hInst
Definition: dxdiag.c:13
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582

Referenced by Download(), and DownloadListOfApplications().

◆ SetProgressMarquee()

VOID CDownloadManager::SetProgressMarquee ( HWND  Item,
BOOL  Enable 
)
staticprivate

Definition at line 561 of file loaddlg.cpp.

562 {
563  if (!Item)
564  return;
565 
567  if (!style)
568  return;
569 
571  return;
572 
574 }
#define PBS_MARQUEE
Definition: commctrl.h:2170
#define PBM_SETMARQUEE
Definition: commctrl.h:2171
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:140
#define SetWindowLongPtr
Definition: treelist.c:70
unsigned long DWORD
Definition: ntddk_ex.h:95
#define GWL_STYLE
Definition: winuser.h:846
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define GetWindowLongPtr
Definition: treelist.c:73
Arabic default style
Definition: afstyles.h:93

Referenced by ThreadFunc().

◆ ThreadFunc()

DWORD WINAPI CDownloadManager::ThreadFunc ( LPVOID  Context)
static

Definition at line 576 of file loaddlg.cpp.

577 {
580  PWSTR p, q;
581 
582  HWND hDlg = static_cast<DownloadParam*>(param)->Dialog;
583  HWND Item;
584  INT iAppId;
585 
586  ULONG dwContentLen, dwBytesWritten, dwBytesRead, dwStatus;
587  ULONG dwCurrentBytesRead = 0;
588  ULONG dwStatusLen = sizeof(dwStatus);
589 
590  BOOL bCancelled = FALSE;
591  BOOL bTempfile = FALSE;
592  BOOL bCab = FALSE;
593 
594  HINTERNET hOpen = NULL;
595  HINTERNET hFile = NULL;
597 
598  unsigned char lpBuffer[4096];
599  LPCWSTR lpszAgent = L"RApps/1.0";
600  URL_COMPONENTS urlComponents;
601  size_t urlLength, filenameLength;
602 
603  const ATL::CSimpleArray<DownloadInfo> &InfoArray = static_cast<DownloadParam*>(param)->AppInfo;
604  LPCWSTR szCaption = static_cast<DownloadParam*>(param)->szCaption;
605  ATL::CStringW szNewCaption;
606 
608 
609  if (InfoArray.GetSize() <= 0)
610  {
612  goto end;
613  }
614 
615  for (iAppId = 0; iAppId < InfoArray.GetSize(); ++iAppId)
616  {
617  // Reset progress bar
618  Item = GetDlgItem(hDlg, IDC_DOWNLOAD_PROGRESS);
619  if (Item)
620  {
621  SetProgressMarquee(Item, FALSE);
622  SendMessageW(Item, WM_SETTEXT, 0, (LPARAM) L"");
623  SendMessageW(Item, PBM_SETPOS, 0, 0);
624  }
625 
626  // is this URL an update package for RAPPS? if so store it in a different place
627  if (InfoArray[iAppId].szUrl == APPLICATION_DATABASE_URL)
628  {
629  bCab = TRUE;
631  goto end;
632  }
633  else
634  {
635  bCab = FALSE;
637  }
638 
639  // Change caption to show the currently downloaded app
640  if (!bCab)
641  {
642  szNewCaption.Format(szCaption, InfoArray[iAppId].szName.GetString());
643  }
644  else
645  {
646  szNewCaption.LoadStringW(IDS_DL_DIALOG_DB_DOWNLOAD_DISP);
647  }
648 
649  SetWindowTextW(hDlg, szNewCaption.GetString());
650 
651  // build the path for the download
652  p = wcsrchr(InfoArray[iAppId].szUrl.GetString(), L'/');
653  q = wcsrchr(InfoArray[iAppId].szUrl.GetString(), L'?');
654 
655  // do we have a final slash separator?
656  if (!p)
657  goto end;
658 
659  // prepare the tentative length of the filename, maybe we've to remove part of it later on
660  filenameLength = wcslen(p) * sizeof(WCHAR);
661 
662  /* do we have query arguments in the target URL after the filename? account for them
663  (e.g. https://example.org/myfile.exe?no_adware_plz) */
664  if (q && q > p && (q - p) > 0)
665  filenameLength -= wcslen(q - 1) * sizeof(WCHAR);
666 
667  // is the path valid? can we access it?
668  if (GetFileAttributesW(Path.GetString()) == INVALID_FILE_ATTRIBUTES)
669  {
670  if (!CreateDirectoryW(Path.GetString(), NULL))
671  goto end;
672  }
673 
674  // append a \ to the provided file system path, and the filename portion from the URL after that
675  Path += L"\\";
676  Path += (LPWSTR) (p + 1);
677 
678  if (!bCab && InfoArray[iAppId].szSHA1[0] && GetFileAttributesW(Path.GetString()) != INVALID_FILE_ATTRIBUTES)
679  {
680  // only open it in case of total correctness
681  if (VerifyInteg(InfoArray[iAppId].szSHA1.GetString(), Path))
682  goto run;
683  }
684 
685  // Add the download URL
686  SetDlgItemTextW(hDlg, IDC_DOWNLOAD_STATUS, InfoArray[iAppId].szUrl.GetString());
687 
689 
690  // download it
691  bTempfile = TRUE;
693 
694  if (dl == NULL)
695  goto end;
696 
697  /* FIXME: this should just be using the system-wide proxy settings */
698  switch (SettingsInfo.Proxy)
699  {
700  case 0: // preconfig
701  default:
702  hOpen = InternetOpenW(lpszAgent, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
703  break;
704  case 1: // direct (no proxy)
705  hOpen = InternetOpenW(lpszAgent, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
706  break;
707  case 2: // use proxy
709  break;
710  }
711 
712  if (!hOpen)
713  goto end;
714 
715  dwStatusLen = sizeof(dwStatus);
716 
717  memset(&urlComponents, 0, sizeof(urlComponents));
718  urlComponents.dwStructSize = sizeof(urlComponents);
719 
720  urlLength = InfoArray[iAppId].szUrl.GetLength();
721  urlComponents.dwSchemeLength = urlLength + 1;
722  urlComponents.lpszScheme = (LPWSTR) malloc(urlComponents.dwSchemeLength * sizeof(WCHAR));
723  urlComponents.dwHostNameLength = urlLength + 1;
724  urlComponents.lpszHostName = (LPWSTR) malloc(urlComponents.dwHostNameLength * sizeof(WCHAR));
725 
726  if (!InternetCrackUrlW(InfoArray[iAppId].szUrl, urlLength + 1, ICU_DECODE | ICU_ESCAPE, &urlComponents))
727  goto end;
728 
729  dwContentLen = 0;
730 
731  if (urlComponents.nScheme == INTERNET_SCHEME_HTTP || urlComponents.nScheme == INTERNET_SCHEME_HTTPS)
732  {
733  hFile = InternetOpenUrlW(hOpen, InfoArray[iAppId].szUrl.GetString(), NULL, 0,
734  dwUrlConnectFlags,
735  0);
736  if (!hFile)
737  {
739  goto end;
740  }
741 
742  // query connection
744  goto end;
745 
746  if (dwStatus != HTTP_STATUS_OK)
747  {
749  goto end;
750  }
751 
752  // query content length
754  }
755 
756  if (urlComponents.nScheme == INTERNET_SCHEME_FTP)
757  {
758  // force passive mode on FTP
759  hFile = InternetOpenUrlW(hOpen, InfoArray[iAppId].szUrl.GetString(), NULL, 0,
760  dwUrlConnectFlags | INTERNET_FLAG_PASSIVE,
761  0);
762  if (!hFile)
763  {
765  goto end;
766  }
767 
768  dwContentLen = FtpGetFileSize(hFile, &dwStatus);
769  }
770 
771  if (!dwContentLen)
772  {
773  // content-length is not known, enable marquee mode
774  SetProgressMarquee(Item, TRUE);
775  }
776 
777  free(urlComponents.lpszScheme);
778  free(urlComponents.lpszHostName);
779 
780 #ifdef USE_CERT_PINNING
781  // are we using HTTPS to download the RAPPS update package? check if the certificate is original
782  if ((urlComponents.nScheme == INTERNET_SCHEME_HTTPS) &&
783  (wcscmp(InfoArray[iAppId].szUrl, APPLICATION_DATABASE_URL) == 0))
784  {
785  CLocalPtr subjectName, issuerName;
786  CStringW szMsgText;
787  bool bAskQuestion = false;
788  if (!CertGetSubjectAndIssuer(hFile, subjectName, issuerName))
789  {
790  szMsgText.LoadStringW(IDS_UNABLE_TO_QUERY_CERT);
791  bAskQuestion = true;
792  }
793  else
794  {
795  if (strcmp(subjectName, CERT_SUBJECT_INFO) ||
796  strcmp(issuerName, CERT_ISSUER_INFO))
797  {
798  szMsgText.Format(IDS_MISMATCH_CERT_INFO, (char*)subjectName, (const char*)issuerName);
799  bAskQuestion = true;
800  }
801  }
802 
803  if (bAskQuestion)
804  {
805  if (MessageBoxW(hMainWnd, szMsgText.GetString(), NULL, MB_YESNO | MB_ICONERROR) != IDYES)
806  {
807  goto end;
808  }
809  }
810  }
811 #endif
812 
814 
815  if (hOut == INVALID_HANDLE_VALUE)
816  goto end;
817 
818  dwCurrentBytesRead = 0;
819  do
820  {
821  if (!InternetReadFile(hFile, lpBuffer, _countof(lpBuffer), &dwBytesRead))
822  {
824  goto end;
825  }
826 
827  if (!WriteFile(hOut, &lpBuffer[0], dwBytesRead, &dwBytesWritten, NULL))
828  {
830  goto end;
831  }
832 
833  dwCurrentBytesRead += dwBytesRead;
834  dl->OnProgress(dwCurrentBytesRead, dwContentLen, 0, InfoArray[iAppId].szUrl.GetString());
835  } while (dwBytesRead && !bCancelled);
836 
837  CloseHandle(hOut);
838  hOut = INVALID_HANDLE_VALUE;
839 
840  if (bCancelled)
841  goto end;
842 
843  if (!dwContentLen)
844  {
845  // set progress bar to 100%
846  SetProgressMarquee(Item, FALSE);
847 
848  dwContentLen = dwCurrentBytesRead;
849  dl->OnProgress(dwCurrentBytesRead, dwContentLen, 0, InfoArray[iAppId].szUrl.GetString());
850  }
851 
852  /* if this thing isn't a RAPPS update and it has a SHA-1 checksum
853  verify its integrity by using the native advapi32.A_SHA1 functions */
854  if (!bCab && InfoArray[iAppId].szSHA1[0] != 0)
855  {
856  ATL::CStringW szMsgText;
857 
858  // change a few strings in the download dialog to reflect the verification process
859  if (!szMsgText.LoadStringW(IDS_INTEG_CHECK_TITLE))
860  goto end;
861 
862  SetWindowTextW(hDlg, szMsgText.GetString());
864 
865  // this may take a while, depending on the file size
866  if (!VerifyInteg(InfoArray[iAppId].szSHA1.GetString(), Path.GetString()))
867  {
868  if (!szMsgText.LoadStringW(IDS_INTEG_CHECK_FAIL))
869  goto end;
870 
871  MessageBoxW(hDlg, szMsgText.GetString(), NULL, MB_OK | MB_ICONERROR);
872  goto end;
873  }
874  }
875 
876 run:
878 
879  // run it
880  if (!bCab)
881  {
882  SHELLEXECUTEINFOW shExInfo = {0};
883  shExInfo.cbSize = sizeof(shExInfo);
884  shExInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
885  shExInfo.lpVerb = L"open";
886  shExInfo.lpFile = Path.GetString();
887  shExInfo.lpParameters = L"";
888  shExInfo.nShow = SW_SHOW;
889 
890  if (ShellExecuteExW(&shExInfo))
891  {
892  //reflect installation progress in the titlebar
893  //TODO: make a separate string with a placeholder to include app name?
895  SetWindowTextW(hDlg, szMsgText.GetString());
896 
898 
899  //TODO: issue an install operation separately so that the apps could be downloaded in the background
901  CloseHandle(shExInfo.hProcess);
902  }
903  else
904  {
906  }
907  }
908 
909 end:
910  if (hOut != INVALID_HANDLE_VALUE)
911  CloseHandle(hOut);
912 
914  InternetCloseHandle(hOpen);
915 
916  if (bTempfile)
917  {
918  if (bCancelled || (SettingsInfo.bDelInstaller && !bCab))
919  DeleteFileW(Path.GetString());
920  }
921 
923  }
924 
925  delete static_cast<DownloadParam*>(param);
926  SendMessageW(hDlg, WM_CLOSE, 0, 0);
927  return 0;
928 }
#define HTTP_QUERY_CONTENT_LENGTH
Definition: wininet.h:1528
BOOL WINAPI CreateDirectoryW(IN LPCWSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:90
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
DWORD dwHostNameLength
Definition: winhttp.h:470
#define IDS_DL_DIALOG_DB_DOWNLOAD_DISP
Definition: resource.h:207
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
#define APPLICATION_DATABASE_URL
Definition: defines.h:32
HRESULT WINAPI CDownloadDialog_Constructor(HWND Dlg, BOOL *pbCancelled, REFIID riid, LPVOID *ppv)
Definition: loaddlg.cpp:329
BOOL VerifyInteg(LPCWSTR lpSHA1Hash, LPCWSTR lpFileName)
Definition: integrity.cpp:14
#define IDYES
Definition: winuser.h:829
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define SEE_MASK_NOCLOSEPROCESS
Definition: shellapi.h:31
static BYTE subjectName[]
Definition: cert.c:63
uint16_t * PWSTR
Definition: typedefs.h:54
#define _countof(array)
Definition: fontsub.cpp:30
#define free
Definition: debug_ros.c:5
#define IDS_MISMATCH_CERT_INFO
Definition: resource.h:115
#define INTERNET_OPEN_TYPE_PROXY
Definition: wininet.h:523
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#define IDS_UNABLE_TO_WRITE
Definition: resource.h:110
void __cdecl Format(UINT nFormatID,...)
Definition: cstringt.h:668
#define PBM_SETPOS
Definition: commctrl.h:2156
BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
Definition: internet.c:1437
BOOL WINAPI SetWindowTextW(_In_ HWND, _In_opt_ LPCWSTR)
GLuint GLuint end
Definition: gl.h:1545
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define IDS_UNABLE_TO_DOWNLOAD
Definition: resource.h:104
#define IID_PPV_ARG(Itype, ppType)
int GetSize() const
Definition: atlsimpcoll.h:104
#define INTERNET_FLAG_DONT_CACHE
Definition: wininet.h:67
int32_t INT
Definition: typedefs.h:56
#define FILE_SHARE_READ
Definition: compat.h:125
#define IDC_DOWNLOAD_STATUS
Definition: resource.h:41
WCHAR szDownloadDir[MAX_PATH]
Definition: winmain.h:10
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl, LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
Definition: internet.c:3608
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
DWORD dwSchemeLength
Definition: winhttp.h:467
VOID MessageBox_LoadString(HWND hMainWnd, INT StringID)
Definition: loaddlg.cpp:378
#define MB_YESNO
Definition: winuser.h:811
DWORD WINAPI FtpGetFileSize(HINTERNET hFile, LPDWORD lpdwFileSizeHigh)
Definition: ftp.c:1754
unsigned int BOOL
Definition: ntddk_ex.h:94
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:802
#define GENERIC_WRITE
Definition: nt_native.h:90
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
#define IDS_INTEG_CHECK_FAIL
Definition: resource.h:108
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
smooth NULL
Definition: ftsmooth.c:416
SETTINGS_INFO SettingsInfo
Definition: winmain.cpp:19
LONG_PTR LPARAM
Definition: windef.h:208
_Check_return_ _CRTIMP _CONST_RETURN wchar_t *__cdecl wcsrchr(_In_z_ const wchar_t *_Str, _In_ wchar_t _Ch)
INTERNET_SCHEME nScheme
Definition: winhttp.h:468
static CDowloadingAppsListView DownloadsListView
Definition: dialogs.h:15
BOOL WINAPI DECLSPEC_HOTPATCH ShellExecuteExW(LPSHELLEXECUTEINFOW sei)
Definition: shlexec.cpp:2225
static VOID SetProgressMarquee(HWND Item, BOOL Enable)
Definition: loaddlg.cpp:561
#define IDS_UNABLE_TO_INSTALL
Definition: resource.h:113
#define SW_SHOW
Definition: winuser.h:769
#define WM_SETTEXT
Definition: winuser.h:1599
#define IDS_INTERRUPTED_DOWNLOAD
Definition: resource.h:109
#define ICU_ESCAPE
Definition: winhttp.h:48
VOID SetDownloadStatus(INT ItemIndex, DownloadStatus Status)
Definition: loaddlg.cpp:286
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define IDS_UNABLE_TO_QUERY_CERT
Definition: resource.h:106
#define WM_CLOSE
Definition: winuser.h:1603
GLfloat param
Definition: glext.h:5796
PCXSTR GetString() const
Definition: atlsimpstr.h:361
unsigned long DWORD
Definition: ntddk_ex.h:95
#define HTTP_STATUS_OK
Definition: winhttp.h:240
BOOL GetStorageDirectory(ATL::CStringW &lpDirectory)
Definition: misc.cpp:187
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
#define IDS_UNABLE_TO_DOWNLOAD2
Definition: resource.h:105
#define IDC_DOWNLOAD_PROGRESS
Definition: resource.h:40
#define INTERNET_OPEN_TYPE_DIRECT
Definition: wininet.h:522
HWND hMainWnd
Definition: magnifier.c:32
DWORD dwStructSize
Definition: winhttp.h:465
BOOL WINAPI HttpQueryInfoW(HINTERNET hHttpRequest, DWORD dwInfoLevel, LPVOID lpBuffer, LPDWORD lpdwBufferLength, LPDWORD lpdwIndex)
Definition: http.c:3807
#define IDS_INTEG_CHECK_TITLE
Definition: resource.h:107
static const WCHAR L[]
Definition: oid.c:1250
#define MB_ICONERROR
Definition: winuser.h:781
_In_ HANDLE hFile
Definition: mswsock.h:90
LPWSTR lpszHostName
Definition: winhttp.h:469
#define HTTP_QUERY_STATUS_CODE
Definition: wininet.h:1542
#define INTERNET_FLAG_PASSIVE
Definition: wininet.h:65
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define INTERNET_FLAG_PRAGMA_NOCACHE
Definition: wininet.h:85
#define CREATE_ALWAYS
Definition: disk.h:72
WCHAR szProxyServer[MAX_PATH]
Definition: winmain.h:20
DWORD dwStatus
Definition: mediaobj.idl:95
PRTL_UNICODE_STRING_BUFFER Path
#define INTERNET_OPEN_TYPE_PRECONFIG
Definition: wininet.h:521
LPCWSTR lpParameters
Definition: shellapi.h:331
BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer, DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
Definition: internet.c:2175
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define MB_OK
Definition: winuser.h:784
#define HTTP_QUERY_FLAG_NUMBER
Definition: wininet.h:1606
BOOL bDelInstaller
Definition: winmain.h:11
#define CreateFileW
Definition: compat.h:400
BOOL WINAPI InternetCrackUrlW(const WCHAR *lpszUrl, DWORD dwUrlLength, DWORD dwFlags, URL_COMPONENTSW *lpUC)
Definition: internet.c:1645
static const WCHAR szName[]
Definition: msipriv.h:1194
ATL::CStringW LoadStatusString(DownloadStatus StatusParam)
Definition: loaddlg.cpp:64
unsigned int ULONG
Definition: retypes.h:1
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
WCHAR szNoProxyFor[MAX_PATH]
Definition: winmain.h:21
#define malloc
Definition: debug_ros.c:4
#define ICU_DECODE
Definition: winhttp.h:291
GLfloat GLfloat p
Definition: glext.h:8902
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define INFINITE
Definition: serial.h:102
HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType, LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
Definition: internet.c:1002
#define memset(x, y, z)
Definition: compat.h:39
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
LPWSTR lpszScheme
Definition: winhttp.h:466
#define INTERNET_FLAG_KEEP_CONNECTION
Definition: wininet.h:72

Referenced by DownloadDlgProc().

Member Data Documentation

◆ AppsToInstallList

ATL::CSimpleArray< DownloadInfo > CDownloadManager::AppsToInstallList
staticprivate

Definition at line 14 of file dialogs.h.

Referenced by Download(), DownloadDlgProc(), and DownloadListOfApplications().

◆ DownloadsListView

CDowloadingAppsListView CDownloadManager::DownloadsListView
staticprivate

Definition at line 15 of file dialogs.h.

Referenced by DownloadDlgProc(), and ThreadFunc().


The documentation for this class was generated from the following files: