AsynchDownload::AsynchBindStatusCallback Class Reference

#include <camnet.h>

List of all members.

Public Member Functions

 AsynchBindStatusCallback (AsynchDownload *pDownload)
 callback object constructor.
 ~AsynchBindStatusCallback ()
 callback object destructor.
HRESULT _stdcall QueryInterface (REFIID riid, void **ppv)
 standard IUnknown method
UINT32 _stdcall AddRef ()
UINT32 _stdcall Release ()
HRESULT _stdcall OnStartBinding (DWORD dwReserved, IBinding *pbinding)
 standard IBindStatusCallback method (must be implemented). Allows us to get a pointer to the binding. See also: MS Internet SDK documentation (URL Monikers)
HRESULT _stdcall GetPriority (INT32 *pnPriority)
HRESULT _stdcall OnLowResource (DWORD dwReserved)
HRESULT _stdcall OnProgress (UINT32 ulProgress, UINT32 ulProgressMax, UINT32 ulStateCode, LPCWSTR pwzStateText)
 standard IBindStatusCallback (must be implemented). Allows monitoring the progress of the bind. changes See also: MS Internet SDK documentation (URL Monikers)
HRESULT _stdcall OnStopBinding (HRESULT hrResult, LPCWSTR szError)
 standard IBindStatusCallback (must be implemented). Allows us to retrieve the result of the bind in hrState. See also: MS Internet SDK documentation (URL Monikers)
HRESULT _stdcall GetBindInfo (DWORD *pgrfBINDF, BINDINFO *pbindinfo)
 standard IBindStatusCallback method (must be implemented) See also: MS Internet SDK documentation (URL Monikers)
HRESULT _stdcall OnDataAvailable (DWORD grfBSCF, DWORD dwSize, FORMATETC *pfmtetc, STGMEDIUM *pstgmed)
 standard IBindStatusCallback method (must be implemented, so we just return S_OK) See also: MS Internet SDK documentation (URL Monikers)
HRESULT _stdcall OnObjectAvailable (REFIID riid, IUnknown *punk)
STDMETHODIMP Authenticate (HWND *phwnd, LPWSTR *pszUserName, LPWSTR *pszPassword)
BOOL AttachProgressDlg ()
 creates a modeless progress dialog box and attach it to this callback, i.e. make an entry in the callback table mapping the callback pointer to the handle of its dialog
void DetachProgressDlg ()
 called by OnStopBinding() to remove this callback's entry in the callback table - as it will be no longer valid - and destroy the progress dialog if one exists

Static Public Member Functions

static BOOL CALLBACK DialogProc (HWND hwndDlg, UINT32 message, WPARAM wParam, LPARAM lParam)
 progress dialog procedure

Public Attributes

DWORD m_dwRef
AsynchDownloadm_pDownload
IBinding * m_pBinding
HWND m_hProgressDlg
UINT32 m_nIconID

Static Public Attributes

static HWND m_hNormalPriorityProgressDlg = NULL
static UINT32 m_nNormalPriorityIconID = _R(IDI_DOWNLOADING)
static HICON m_hiconProgress = 0
static CTypedPtrMap< CMapPtrToPtr,
HWND, AsynchBindStatusCallback * > 
m_CallbackTable


Detailed Description

Definition at line 281 of file camnet.h.


Constructor & Destructor Documentation

AsynchDownload::AsynchBindStatusCallback::AsynchBindStatusCallback AsynchDownload pDownload  ) 
 

callback object constructor.

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/11/96
Parameters:
pDownload - pointer to the AsynchDownload object owning the callback [INPUTS]
Returns:
none

Definition at line 409 of file camnet.cpp.

00410 {
00411     m_dwRef = 1;
00412     m_pDownload = pDownload;
00413     m_pBinding = NULL;
00414     m_hProgressDlg = NULL;
00415     m_nIconID = _R(IDI_DOWNLOADING); 
00416 }

AsynchDownload::AsynchBindStatusCallback::~AsynchBindStatusCallback  ) 
 

callback object destructor.

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/11/96
Parameters:
none [INPUTS]
Returns:
none

Definition at line 430 of file camnet.cpp.

00431 {
00432     if (m_pBinding) // download still in progress
00433     {
00434         // this will almost certainly result in an access violation
00435         ERROR3("AsynchDownload deleted while still in progress");
00436     }
00437 }


Member Function Documentation

UINT32 _stdcall AsynchDownload::AsynchBindStatusCallback::AddRef  )  [inline]
 

Definition at line 312 of file camnet.h.

00312 { return m_dwRef++; }

BOOL AsynchDownload::AsynchBindStatusCallback::AttachProgressDlg  ) 
 

creates a modeless progress dialog box and attach it to this callback, i.e. make an entry in the callback table mapping the callback pointer to the handle of its dialog

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/11/96
Parameters:
- [INPUTS]
Returns:
TRUE if the dialog box was created successful, FALSE otherwise

Definition at line 946 of file camnet.cpp.

00947 {
00948     static BOOL bShouldRegisterClass = TRUE;
00949     if (bShouldRegisterClass) // register the progress dlg class if needed
00950     {
00951         WNDCLASSEX wndClass;
00952         static char szClassName[] =  "DownloadProgressDlg";
00953         if (!::GetClassInfoEx(NULL, MAKEINTRESOURCE(32770), &wndClass))
00954         {
00955             ERROR3("Failed to get class info");
00956         }
00957         wndClass.lpszClassName = szClassName;
00958         wndClass.hInstance = AfxGetResourceHandle();
00959         wndClass.hIcon = NULL;
00960         wndClass.hIconSm = (HICON) ::LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(_R(IDI_DOWNLOADING)), IMAGE_ICON, 16, 16, 0);
00961         wndClass.cbSize = sizeof(wndClass);
00962         ERROR3IF(!wndClass.hIconSm, "Failed to load icon");
00963         if (!::RegisterClassEx(&wndClass))
00964         {
00965             ERROR3("Failed to register progress dlg class");
00966         }
00967         else
00968             bShouldRegisterClass = FALSE;
00969     }
00970     if (m_pDownload->m_Priority == PRIORITY_HIGH) // high priority download - gets its own progress dialog
00971     {
00972         m_hProgressDlg = ::CreateDialogParam(AfxGetResourceHandle(), MAKEINTRESOURCE(_R(IDD_PROGRESS)), 
00973             HWND_DESKTOP,   (DLGPROC) &DialogProc, NULL);
00974         if (!m_hProgressDlg)
00975         {
00976             ERROR3("Could not create progress dialog");
00977             return FALSE;
00978         }
00979         else
00980         {
00981             // Enter the handle in the callback table
00982             m_CallbackTable[m_hProgressDlg] = this;
00983             ::SetTimer(m_hProgressDlg, ICON_ANIMATION, ICON_UPDATE_INTERVAL, NULL);
00984         }
00985     }
00986     else if (!m_hNormalPriorityProgressDlg) // low priority download - create dialog only if there is none to be reused
00987     {
00988         m_hNormalPriorityProgressDlg = ::CreateDialogParam(AfxGetResourceHandle(), MAKEINTRESOURCE(_R(IDD_PROGRESS)), 
00989             HWND_DESKTOP,   (DLGPROC) &DialogProc, NULL);
00990         if (!m_hNormalPriorityProgressDlg)
00991         {
00992             ERROR3("Could not create progress dialog");
00993             return FALSE;
00994         }
00995         else
00996             ::SetTimer(m_hNormalPriorityProgressDlg, ICON_ANIMATION, ICON_UPDATE_INTERVAL, NULL);
00997     }
00998     return TRUE;
00999 }

STDMETHODIMP AsynchDownload::AsynchBindStatusCallback::Authenticate HWND *  phwnd,
LPWSTR pszUserName,
LPWSTR pszPassword
 

Definition at line 823 of file camnet.cpp.

00824 {
00825     *phwnd = AfxGetMainWnd()->m_hWnd;
00826     *pszUserName = 0;
00827     *pszPassword = 0;
00828 
00829     return S_OK;
00830 }

void AsynchDownload::AsynchBindStatusCallback::DetachProgressDlg  ) 
 

called by OnStopBinding() to remove this callback's entry in the callback table - as it will be no longer valid - and destroy the progress dialog if one exists

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/11/96
Parameters:
- [INPUTS]
Returns:
-

Definition at line 1014 of file camnet.cpp.

01015 {
01016     if (m_hProgressDlg && m_pDownload->m_Priority == PRIORITY_HIGH)
01017     {
01018         BOOL bDestroyed = FALSE;
01019         // Kill the icon animation timer
01020         bDestroyed = ::KillTimer(m_hProgressDlg, ICON_ANIMATION);
01021         ERROR3IF(!bDestroyed, "Warning: timer not destroyed");
01022         // Make sure the progress dialog is destroyed 
01023         if (::IsWindow(m_hProgressDlg))
01024             bDestroyed = ::DestroyWindow(m_hProgressDlg);
01025         ERROR3IF(!bDestroyed, "Warning: progress dialog not destroyed");
01026         // Just in case we couldn't destroy the window for some reason we'll set the dialog handle
01027         // entry in the callback table to NULL indicating it references a callback pointer no longer valid
01028         m_CallbackTable[m_hProgressDlg] = NULL;
01029         m_hProgressDlg = NULL;
01030     }
01031     else if (m_hNormalPriorityProgressDlg && m_pDownload->m_Priority == PRIORITY_NORMAL)
01032     {
01033         if (m_pDownload->m_nNormalPriorityInstanceCount == 1)
01034         {
01035             // Kill the icon animation timer
01036             BOOL bDestroyed = ::KillTimer(m_hNormalPriorityProgressDlg, ICON_ANIMATION);
01037             ERROR3IF(!bDestroyed, "Warning: timer not destroyed");
01038             ::DestroyWindow(m_hNormalPriorityProgressDlg);
01039             m_hNormalPriorityProgressDlg = NULL;
01040         }
01041     }
01042 }

BOOL CALLBACK AsynchDownload::AsynchBindStatusCallback::DialogProc HWND  hDlg,
UINT32  message,
WPARAM  wParam,
LPARAM  lParam
[static]
 

progress dialog procedure

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/11/96
Parameters:
hwndDlg - identifies the dialog box. [INPUTS] uMsg - specifies the message. wParam - specifies additional message-specific information. lParam - specifies additional message-specific information
Returns:
non-zero if it processes the message, 0 if not

Definition at line 847 of file camnet.cpp.

00848 {
00849     switch (message)
00850      {
00851         case WM_TIMER:
00852         {
00853             if (wParam == ICON_ANIMATION)
00854             {
00855                 UINT32* pIconID = NULL;
00856                 if (hDlg == m_hNormalPriorityProgressDlg)
00857                     pIconID = &m_nNormalPriorityIconID;
00858                 else
00859                 {
00860                     AsynchBindStatusCallback* pCallback = NULL;
00861                     if (!m_CallbackTable.Lookup(hDlg, pCallback))
00862                     {
00863                         ERROR3("Callback not found in the lookup table");
00864                     }
00865                     else if (pCallback)
00866                         pIconID = &pCallback->m_nIconID;
00867                 }
00868                 if (*pIconID == _R(IDI_DOWNLOADING6))
00869                     *pIconID = _R(IDI_DOWNLOADING);
00870                 else
00871                     (*pIconID)++;
00872 
00873                 HICON hiconPrev = m_hiconProgress;
00874                 m_hiconProgress = (HICON)::LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(*pIconID), IMAGE_ICON, 16, 16, 0);
00875                 ::SendMessage(hDlg, WM_SETICON, (WPARAM) FALSE, (LPARAM) m_hiconProgress );
00876                 ::DestroyIcon(hiconPrev);
00877                 return TRUE;
00878             }
00879         }
00880         break;
00881         case WM_COMMAND:
00882         {
00883             switch (LOWORD(wParam))
00884             {
00885                 case IDCANCEL:
00886                 {
00887 CANCEL:                 
00888                     if (m_hiconProgress)
00889                     {
00890                         ::DestroyIcon(m_hiconProgress);
00891                         m_hiconProgress = 0;
00892                     }
00893 
00894                     // Got CANCEL from the user, find the callback this dialog belongs to
00895                     if (hDlg == m_hNormalPriorityProgressDlg) // thumbnail/catalog file download progress
00896                     {
00897                         AsynchDownload* pDownload = InternetManager::GetCurrentNormalPriorityDownload();
00898                         if (pDownload)
00899                             pDownload->AbortDownload();
00900                         return TRUE;
00901                     }
00902                     AsynchBindStatusCallback* pCallback = NULL;
00903                     if (!m_CallbackTable.Lookup(hDlg, pCallback))
00904                     {
00905                         ERROR3("Callback not found in the lookup table");
00906                     }
00907                     else
00908                     {
00909                         if (pCallback && pCallback->m_pDownload)
00910                         {
00911                             // Although the callback object doesn't contain any runtime information and
00912                             // thus we cannot directly check if it's still valid or not, a non-null pointer in the callback
00913                             // table should guarantee that, as callback objects call DetachProgressDlg() when
00914                             // a download completes or is terminated by the user.
00915                             // Never use the delete operator on a download in progress (instead of calling the Release() member
00916                             // function) as it could result in pCallback being no longer valid at this point and cause an access violation
00917                             HRESULT result = pCallback->m_pDownload->AbortDownload();
00918                             ERROR3IF(result == E_FAIL, "Could not abort download");
00919                         }
00920                     }
00921                     return TRUE;
00922                 }
00923                 break;
00924             }
00925         }
00926         break;
00927         case WM_CLOSE:
00928             goto CANCEL; // we assume they actually want to cancel the download
00929     }
00930     return FALSE;
00931 }

HRESULT _stdcall AsynchDownload::AsynchBindStatusCallback::GetBindInfo DWORD pgrfBINDF,
BINDINFO *  pbindInfo
 

standard IBindStatusCallback method (must be implemented) See also: MS Internet SDK documentation (URL Monikers)

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/11/96
Parameters:
pgrfBINDF - pointer to BINDF value [INPUTS] pbindinfo - pointer to BINDINFO structure
Returns:
S_OK

Definition at line 780 of file camnet.cpp.

00781 {
00782     *pgrfBINDF = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_GETNEWESTVERSION; // bind asynchronously
00783     pbindInfo->cbSize = sizeof(BINDINFO);
00784     pbindInfo->szExtraInfo = NULL;
00785     memset(&pbindInfo->stgmedData, 0, sizeof(STGMEDIUM));
00786     pbindInfo->grfBindInfoF = 0;
00787     pbindInfo->dwBindVerb = BINDVERB_GET;
00788     pbindInfo->szCustomVerb = NULL;
00789     return S_OK;
00790 } 

HRESULT _stdcall AsynchDownload::AsynchBindStatusCallback::GetPriority INT32 *  pnPriority  )  [inline]
 

Definition at line 321 of file camnet.h.

00321 {return E_NOTIMPL;}

HRESULT _stdcall AsynchDownload::AsynchBindStatusCallback::OnDataAvailable DWORD  grfBSCF,
DWORD  dwSize,
FORMATETC *  pfmtetc,
STGMEDIUM *  pstgmed
 

standard IBindStatusCallback method (must be implemented, so we just return S_OK) See also: MS Internet SDK documentation (URL Monikers)

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/11/96
Parameters:
gfBSCF - BSCF enumeration values [INPUTS] dwSize - length of data in bytes available from current bind operation pfmtetc - pointer to FORMATETC structure pstgmed - Pointer to STGMEDIUM structure
Returns:
S_OK

Definition at line 806 of file camnet.cpp.

00808 {
00809     // We're not reading any data before the download is complete, so just return S_OK 
00810     return S_OK;
00811 }  

HRESULT _stdcall AsynchDownload::AsynchBindStatusCallback::OnLowResource DWORD  dwReserved  )  [inline]
 

Definition at line 323 of file camnet.h.

00323 {return E_NOTIMPL;}

HRESULT _stdcall AsynchDownload::AsynchBindStatusCallback::OnObjectAvailable REFIID  riid,
IUnknown punk
[inline]
 

Definition at line 337 of file camnet.h.

00337 {return E_NOTIMPL;}

HRESULT _stdcall AsynchDownload::AsynchBindStatusCallback::OnProgress UINT32  ulProgress,
UINT32  ulProgressMax,
UINT32  ulStateCode,
LPCWSTR  pwzStateText
 

standard IBindStatusCallback (must be implemented). Allows monitoring the progress of the bind. changes See also: MS Internet SDK documentation (URL Monikers)

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/11/96
Parameters:
ulProgress - progress indicator for bind operation [INPUTS] ulProgressMax - expected maximum value of ulProgress parameter ulStateCode - BINDSTATUS value indicating bind progress szStateText - displayable information indicating bind progress
Returns:
NOERROR or E_ABORT if Abort() has been called

Definition at line 556 of file camnet.cpp.

00558 {
00559     if (m_pDownload->m_bAbort)
00560     {
00561         return E_ABORT;
00562     }
00563     TCHAR   sz[256];
00564     if(pwzStateText != NULL)
00565         WideCharToMultiByte(CP_ACP, 0, pwzStateText, -1, sz, sizeof(sz)/sizeof(TCHAR), 0, 0);
00566     // Update download progress
00567     // (Note that ulProgressMax is the file size returned by the server and if may be 0 if the server doesn't know it)
00568     // (Hopefully our server is better than that)
00569     m_pDownload->m_ulFileSize = (ulProgress > ulProgressMax) ? ulProgress : ulProgressMax;
00570     m_pDownload->m_ulDownloaded = ulProgress;
00571     INT32 nPercentage = (ulProgress && ulProgressMax) ? (100 * ulProgress/ulProgressMax) : 0;
00572 
00573     if (nPercentage!=m_pDownload->m_nPercentageDownloaded)
00574     {
00575         // we should inform our client that things are happening...
00576         InternetManager::SetState(m_pDownload->m_Handle, AsynchDownload::STATE_PENDING);
00577     }
00578 
00579     m_pDownload->m_nPercentageDownloaded = nPercentage;
00580     if (m_pDownload->m_bHasProgressDlg)
00581     {
00582         HWND hProgressDlg;
00583         if (m_pDownload->m_Priority == PRIORITY_NORMAL)
00584             hProgressDlg = m_hNormalPriorityProgressDlg;
00585         else
00586             hProgressDlg = m_hProgressDlg;
00587         // Make sure the progress dialog handle is still valid before attempting to update it 
00588         if (hProgressDlg && ::IsWindow(hProgressDlg))
00589         {   
00590             HWND hPercentage = GetDlgItem(hProgressDlg, _R(IDC_PERCENTAGE)); // handle of static text used to display percent downloaded
00591             HWND hProgressBar = GetDlgItem(hProgressDlg, _R(IDC_PROGRESSBAR)); // handle of progress bar
00592             if (!(hPercentage && hProgressBar))
00593             {
00594                 ERROR3("Cannot find control");
00595             }
00596             else
00597             {
00598                 String_256 strCaption, strPercentage;
00599                 switch (ulStateCode)
00600                 {
00601                     case BINDSTATUS_FINDINGRESOURCE: // these 3 states are now displayed as "Contacting host..."
00602                     case BINDSTATUS_CONNECTING:
00603                     case BINDSTATUS_SENDINGREQUEST:
00604                         break;
00605 
00606                     case BINDSTATUS_DOWNLOADINGDATA:
00607                         {
00608                             strCaption = String_256(_R(IDS_DOWNLOAD));
00609                             if (m_pDownload->m_strDescription.IsEmpty()) // no description available, just use the filename
00610                             {
00611                                 strCaption+= _T("'");
00612                                 strCaption += strrchr(m_pDownload->m_strTargetURL, _T('/')) + 1;
00613                                 strCaption+= _T("'");
00614                             }
00615                             else
00616                             {
00617                                 strCaption += m_pDownload->m_strDescription;
00618                             }
00619                             if (!ulProgressMax)
00620                             {
00621                                 strPercentage = "N/A"; // in case the server didn't return any size information
00622                                 m_pDownload->m_nPercentageDownloaded = 0;
00623                             }
00624                             else // set the progress bar to the percentage we have downloaded
00625                             {
00626                                 wsprintf(strPercentage, "%d%%", nPercentage);
00627                                 ::SendMessage(hProgressBar, PBM_SETPOS, (WPARAM) nPercentage, 0);
00628                                 // Force an immediate repaint to avoid any redraw latency
00629                                 ::UpdateWindow(hProgressBar);
00630                             }
00631                         }
00632                         break;
00633                     case BINDSTATUS_ENDDOWNLOADDATA:
00634                         strPercentage = _T("100%");
00635                         ::SendMessage(hProgressBar, PBM_SETPOS, (WPARAM) 100, 0);
00636                         // Force an immediate repaint to avoid any redraw latency
00637                         ::UpdateWindow(hProgressBar);
00638                         strCaption = String_256(_R(IDS_ENDDOWNLOAD));
00639                         break;
00640                 }
00641                 // We'll update the controls only if the new strings are different to the current ones so that we don't 
00642                 // get any flicker 
00643                 TCHAR tchBuff[96];
00644                 ::GetWindowText(hPercentage, tchBuff, sizeof(tchBuff)/sizeof(TCHAR));
00645                 if (strPercentage != String_256(tchBuff))
00646                 {
00647                     ::SetWindowText(hPercentage, (TCHAR*) strPercentage);
00648                     ::UpdateWindow(hPercentage);
00649                 }
00650                 ::GetWindowText(hProgressDlg, tchBuff, sizeof(tchBuff)/sizeof(TCHAR));
00651                 if (strCaption.Length() && strCaption != String_256(tchBuff)) // we need to update the message
00652                 {
00653                     ::SetWindowText(hProgressDlg, (TCHAR*) strCaption);
00654                     ::UpdateWindow(hProgressDlg);
00655                 }
00656             }
00657         }
00658     }   
00659     // Save filename of local image if available
00660     if (ulStateCode == BINDSTATUS_CACHEFILENAMEAVAILABLE)
00661         m_pDownload->m_strCacheFileName = sz;
00662 
00663     return (NOERROR);
00664 }

HRESULT _stdcall AsynchDownload::AsynchBindStatusCallback::OnStartBinding DWORD  dwReserved,
IBinding *  pbinding
 

standard IBindStatusCallback method (must be implemented). Allows us to get a pointer to the binding. See also: MS Internet SDK documentation (URL Monikers)

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/11/96
Parameters:
dwReserved - not used, must be 0 [INPUTS] pbinding - pointer to the IBinding interface for the current bind operation
Returns:
S_OK

Definition at line 481 of file camnet.cpp.

00482 {
00483     m_pDownload->m_ulFileSize = 0;
00484     m_pDownload->m_ulDownloaded = 0;
00485     // We save the pointer to the binding
00486     m_pBinding = pbinding;
00487     if (m_pBinding != NULL)
00488         m_pBinding->AddRef();
00489     // Create & display the progress dialog if the download requires one
00490     if (m_pDownload->m_bHasProgressDlg)
00491     {
00492         HWND hProgressDlg;
00493         BOOL bNeedsPositioning = (m_pDownload->m_Priority != PRIORITY_NORMAL) ||
00494                 (m_pDownload->m_Priority == PRIORITY_NORMAL && !m_hNormalPriorityProgressDlg);
00495         if (!AttachProgressDlg())
00496         {
00497             ERROR3("Could not create progress dialog");
00498             goto END; 
00499         }
00500         if (m_pDownload->m_Priority == PRIORITY_NORMAL)
00501             hProgressDlg = m_hNormalPriorityProgressDlg;
00502         else
00503             hProgressDlg = m_hProgressDlg;
00504         if (hProgressDlg)
00505         {
00506             HWND hProgressBar = GetDlgItem(hProgressDlg, _R(IDC_PROGRESSBAR)); // hadle of progress bar
00507             HWND hPercentage = GetDlgItem(hProgressDlg, _R(IDC_PERCENTAGE)); // handle of static text used to display percent downloaded
00508             ERROR3IF(!(hProgressBar && hPercentage), "Cannot find control");
00509             // Set initial position on the progress bar to 0
00510             ::SendMessage(hProgressBar, PBM_SETPOS, (WPARAM) 0, 0);
00511             // Set initial percentage
00512             String_256 strPercentage = _T("0%");
00513             // Set the dialog caption
00514             String_256 strURL = m_pDownload->m_strTargetURL;
00515             strtok(strURL, _T(":/"));
00516             String_256 strCaption;
00517             strCaption.MakeMsg(_R(IDS_CONTACTING_HOST), strtok(NULL, _T(":/")));
00518             ::SetWindowText(hProgressDlg, (TCHAR*) strCaption);
00519             ::SetWindowText(hPercentage, (TCHAR*) strPercentage);
00520             // Position the window if necessary 
00521             if (bNeedsPositioning)
00522             {
00523                 CRect rcDialog;
00524                 ::GetWindowRect(hProgressDlg, &rcDialog);
00525                 // Finally position & show the dialog box
00526                 ::SetWindowPos(hProgressDlg, HWND_TOPMOST, ::GetSystemMetrics(SM_CXSCREEN) - rcDialog.Width(), 0,
00527                         0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
00528             }
00529             else
00530                 ::SetWindowPos(hProgressDlg, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW);
00531 
00532             ::UpdateWindow(hProgressBar);
00533             ::UpdateWindow(hPercentage);
00534             ::UpdateWindow(hProgressDlg);
00535         }
00536     }
00537 END:    
00538     return S_OK;
00539 }

HRESULT _stdcall AsynchDownload::AsynchBindStatusCallback::OnStopBinding HRESULT  hrState,
LPCWSTR  szError
 

standard IBindStatusCallback (must be implemented). Allows us to retrieve the result of the bind in hrState. See also: MS Internet SDK documentation (URL Monikers)

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/11/96
Parameters:
hrState - bind operation status code [INPUTS] szError - currently not used
Returns:
S_OK

Definition at line 679 of file camnet.cpp.

00680 {
00681 #ifdef _DEBUG
00682     if (hrState) // download diagnostic in debug builds
00683     {
00684         TCHAR szErrorMsg[256];
00685         if (hrState == 0x800C0006) // file not found
00686             wsprintf(szErrorMsg, "%s %s\n", (TCHAR*) (String_256) m_pDownload->m_strTargetURL, _T("not found on the server"));
00687         else
00688             wsprintf(szErrorMsg, "%s %s\n", _T("Got network error (possibly host not found) downloading"), (TCHAR*) (String_256) m_pDownload->m_strTargetURL);
00689          if (hrState != 0x80004004) // user cancel
00690              TRACE(szErrorMsg);
00691 
00692          // Write error to log
00693          String_256 strAppDataPath;
00694          GetAppDataPath(&strAppDataPath);
00695          PathName logPath(strAppDataPath);
00696          String_256 strLogName("errlog.txt");
00697          logPath.SetFileNameAndType(strLogName);
00698          static BOOL bShouldOverwrite = TRUE; // overwrite any error log generated in a previous session
00699          INT32 iFlags = bShouldOverwrite ? ios::out | ios::trunc    :   ios::out | ios::app;
00700          bShouldOverwrite = FALSE;
00701          ofstream logFile((TCHAR*) (String_256) logPath.GetPath(), iFlags);
00702          if (!logFile.bad())
00703              logFile << szErrorMsg;
00704          logFile.close();
00705     }
00706 #endif
00707 
00708     // Clean up
00709     if (m_pBinding)
00710     {
00711         m_pBinding->Release();
00712         m_pBinding = NULL;
00713     }
00714     if (m_pDownload->m_bHasProgressDlg)
00715         DetachProgressDlg(); // release/destroy the progress dialog, if any
00716 
00717     if (!hrState && !m_pDownload->m_bAbort) // file downloaded successfully
00718     {
00719         // The file has been downloaded to the system internet cache, so we need to copy it over to the required location
00720         PathNameEx path(m_pDownload->m_strLocalFilePath);
00721         BOOL bIsCacheFile = DownloadCache::IsCachePath(m_pDownload->m_strLocalFilePath); 
00722         if (!path.CreateLocation()) // create the directory path if it doesn't exist - otherwise ofstream() may fail
00723         {
00724             InformError(_R(IDS_DIRCREATEFAIL), _R(IDS_OK));
00725             m_pDownload->m_bSuccess = FALSE;
00726             goto COMPLETE;
00727         }
00728         ifstream stmCache((TCHAR*) m_pDownload->m_strCacheFileName, ios::in | ios::nocreate | ios::binary);
00729         // We overwrite the existing file if any
00730         DownloadCache::RemoveFile(m_pDownload->m_strLocalFilePath);
00731         if (bIsCacheFile)
00732             DownloadCache::m_CacheMonitor.IgnoreEvents(1);
00733         ofstream stmFile((TCHAR*) m_pDownload->m_strLocalFilePath, ios::out | ios::binary | ios::trunc);
00734         if (stmCache.bad() || stmFile.bad())
00735         {
00736             String_256 strTemp;
00737             PathName path(m_pDownload->m_strLocalFilePath);
00738             strTemp.MakeMsg(_R(IDS_FILEIOERROR), (TCHAR*) String_256(path.GetFileName()));
00739             Error::SetError(0, strTemp, 0);
00740             InformError();
00741             stmFile.close();
00742             stmCache.close();
00743             goto COMPLETE;
00744         }
00745         stmFile << stmCache.rdbuf();
00746         if (stmFile.bad() || stmCache.bad())
00747         {
00748             String_256 strTemp;
00749             PathName path(m_pDownload->m_strLocalFilePath);
00750             strTemp.MakeMsg(_R(IDS_FILEIOERROR), (TCHAR*) String_256(path.GetFileName()));
00751             Error::SetError(0,strTemp, 0);
00752             InformError();
00753         }
00754         else
00755             m_pDownload->m_bSuccess = TRUE;
00756         stmFile.close();
00757         stmCache.close();
00758     }
00759     else if (hrState == 0x800C0007) // we got a network error (unfortunately these error codes are not documented by Microsoft)
00760     {
00761         return m_pDownload->Retry();
00762     }
00763          
00764 COMPLETE:
00765     InternetManager::OnDownloadComplete(m_pDownload);
00766     return S_OK;
00767 }  

HRESULT _stdcall AsynchDownload::AsynchBindStatusCallback::QueryInterface REFIID  riid,
void **  ppv
 

standard IUnknown method

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/11/96
Parameters:
riid - identifier of the requested interface [INPUTS] ppvObject - indirect pointer to the object
Returns:
S_OK if the interface is supported, E_NOINTERFACE otherwise.

Definition at line 450 of file camnet.cpp.

00451 {
00452     *ppv = NULL;
00453 
00454     if (riid==IID_IUnknown || riid==IID_IBindStatusCallback)
00455     {
00456         *ppv = this;
00457         AddRef();
00458         return S_OK;
00459     }
00460     else if (riid == IID_IAuthenticate)
00461     {
00462         *ppv = (IAuthenticate *)this;
00463         AddRef();
00464         return S_OK;
00465     }
00466 
00467     return E_NOINTERFACE;
00468 }  

UINT32 _stdcall AsynchDownload::AsynchBindStatusCallback::Release void   )  [inline]
 

Definition at line 314 of file camnet.h.

00314 { if (--m_dwRef == 0) { delete this; return 0; } return m_dwRef; }


Member Data Documentation

CTypedPtrMap< CMapPtrToPtr, HWND, AsynchDownload::AsynchBindStatusCallback * > AsynchDownload::AsynchBindStatusCallback::m_CallbackTable [static]
 

Definition at line 300 of file camnet.h.

DWORD AsynchDownload::AsynchBindStatusCallback::m_dwRef
 

Definition at line 286 of file camnet.h.

HICON AsynchDownload::AsynchBindStatusCallback::m_hiconProgress = 0 [static]
 

Definition at line 295 of file camnet.h.

HWND AsynchDownload::AsynchBindStatusCallback::m_hNormalPriorityProgressDlg = NULL [static]
 

Definition at line 293 of file camnet.h.

HWND AsynchDownload::AsynchBindStatusCallback::m_hProgressDlg
 

Definition at line 289 of file camnet.h.

UINT32 AsynchDownload::AsynchBindStatusCallback::m_nIconID
 

Definition at line 290 of file camnet.h.

UINT32 AsynchDownload::AsynchBindStatusCallback::m_nNormalPriorityIconID = _R(IDI_DOWNLOADING) [static]
 

Definition at line 294 of file camnet.h.

IBinding* AsynchDownload::AsynchBindStatusCallback::m_pBinding
 

Definition at line 288 of file camnet.h.

AsynchDownload* AsynchDownload::AsynchBindStatusCallback::m_pDownload
 

Definition at line 287 of file camnet.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:50:03 2007 for Camelot by  doxygen 1.4.4