void CDownload::FileEnd() { if (!InProgress()) return; // Is there any data to process? if (m_pData) { FileSave(); free(m_pData); m_pData = NULL; m_dwSize = 0; } // Pop the download item off the list m_List.erase(m_List.begin()); // Are there any more files in the list to download? if (Next()) return; // Yes, more files to download // No more files to download, so make the final callback if (m_fnCallback) m_fnCallback(m_pPlugin, NULL); // No more files to download or process Free(); }
bool SetProgress(OCProvisioningStatusCB provisioningStatusCallback) { if (InProgress()) return false; cbData = provisioningStatusCallback; return true; }
bool CDownload::Init(int iFileType, FNDOWNLOADCALLBACK fnCallback) { if (InProgress()) { if (::MessageBox(m_pPlugin->m_hWnd, "Download already in progress.\n\nDo you want to abort the current download?", "", MB_YESNO) == IDNO) return false; } Free(); m_iFileType = iFileType; m_fnCallback = fnCallback; return true; }
void CDownload::FileSave() { if (!InProgress()) return; // Is there any file data to process? if (!m_pData) return; // If there is a destination file defined, write the data to disk DOWNLOAD Download = m_List.front(); CString& strDstPath = Download.strDstPath; if (!strDstPath.IsEmpty()) { // Write the file to the destination path HANDLE hFile = ::CreateFile(strDstPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) { char strMsg[256]; wsprintf(strMsg, "Error creating file '%s' after download.", strDstPath); ::MessageBox(m_pPlugin->m_hWnd, strMsg, "", MB_OK); return; } DWORD dwBytesWritten = 0; bool bFailed = !::WriteFile(hFile, (LPCVOID)m_pData, m_dwSize, &dwBytesWritten, NULL); ::CloseHandle(hFile); if (bFailed) { char strMsg[256]; wsprintf(strMsg, "Error writing to '%s' after download.", strDstPath); ::MessageBox(m_pPlugin->m_hWnd, strMsg, "", MB_OK); return; } } // If there is a callback defined, make the call if (m_fnCallback) { Download.pData = m_pData; Download.dwSize = m_dwSize; m_fnCallback(m_pPlugin, (void*)&Download); } }
void CDownload::FileData(BYTE* pBytes, DWORD dwLen) { if (!InProgress()) return; if (!pBytes || !dwLen) return; if (!m_pData) m_pData = (BYTE*)malloc(dwLen); else m_pData = (BYTE*)realloc(m_pData, m_dwSize + dwLen); if (!m_pData) return; ::memcpy(m_pData + m_dwSize, pBytes, dwLen); m_dwSize += dwLen; }
bool CDownload::Init(int iFileType, FNDOWNLOADCALLBACK fnCallback, LPARAM lParam, DWORD dwFlags) { if (InProgress()) { if (!(dwFlags & DL_PROMPTUSER)) return !!(dwFlags & DL_KILLINPROGRESS); if (CMessageBox::Message("Download already in progress.\n\nDo you want to abort the current download?", MB_YESNO) == IDNO) return false; } Free(); m_iFileType = iFileType; m_fnCallback = fnCallback; m_lParam = lParam; return true; }
void CDownload::FileEnd(bool bError) { if (m_bShowProgress) { m_ProgressDialog.Destroy(); m_bShowProgress = false; } if (!InProgress()) return; #ifdef NOTUSED //j Code to examine the data for the MIME type CComObject<CAsyncDownload>* pbsc = NULL; HRESULT hr = CComObject<CAsyncDownload>::CreateInstance(&pbsc); if (SUCCEEDED(hr)) { LPWSTR pMimeOut = NULL; hr = ::FindMimeFromData(pbsc->m_spBindCtx, NULL/*pwzUrl*/, m_pData/*pBuffer*/, m_dwSize/*cbSize*/, NULL/*pwzMimeProposed*/, 0/*dwMimeFlags*/, &pMimeOut/*ppwzMimeOut*/, 0/*dwReserved*/); int i = 0; } #endif NOTUSED bool bPickingUpLeftovers = false; if (m_iFileType > 0) // Anything but a project file { // Is there any data to process? if (m_pData) { FileSave(); free(m_pData); m_pData = NULL; m_dwSize = 0; } // Pop the download item off the list m_List.erase(m_List.begin()); // Are there any more files in the list to download? if (!bError && Next()) return; // Yes, more files to download // No more files to download, so make the final callback after we do the Free() FNDOWNLOADCALLBACK fnCallback = m_fnCallback; LPARAM lParam = m_lParam; if (!m_pDataSaved) // Is there any leftover project data to pick up? Free(); if (fnCallback) fnCallback(lParam, NULL); if (!m_pDataSaved) // Is there any leftover project data to pick up? return; // No more files to download or process // Fall through to pick up any leftover project data bPickingUpLeftovers = true; m_pData = m_pDataSaved; m_pDataSaved = NULL; m_dwSize = m_dwSizeSaved; m_dwSizeSaved = 0; m_fnCallback = m_fnCallbackSaved; m_fnCallbackSaved = NULL; m_iFileType = 0; // A project file } // If this is not a project file, we are done if (m_iFileType != 0) return; // Is there any data to process? if (!m_pData) { Free(); return; } CAGDoc* pAGDoc = new CAGDoc(); if (!pAGDoc) { Free(); return; } // Set the Context License for the document. This must be called // prior to Read() below. CCtp* pCtp = (CCtp*)m_lParam; int iContextLicense = pCtp->GetContextLicense(); pAGDoc->SetContextLicense(iContextLicense); istrstream input((char*)m_pData, m_dwSize); bool bAdjusted = false; if (!pAGDoc->Read(input, bAdjusted)) { delete pAGDoc; CMessageBox::Message("Error reading the project data."); Free(); return; } // See if we need to start downloading any fonts if (!bPickingUpLeftovers) { // Pop the download item off the list m_List.erase(m_List.begin()); LOGFONTLIST lfProjectFontList; pAGDoc->GetFonts(lfProjectFontList); FONTDOWNLOADLIST List; pCtp->GetFontList().GetProjectFontList(lfProjectFontList, List, true/*bMissingOnly*/); if (!List.empty()) { delete pAGDoc; // Save the project data so we can pick it up later m_pDataSaved = m_pData; m_pData = NULL; m_dwSizeSaved = m_dwSize; m_dwSize = 0; m_fnCallbackSaved = m_fnCallback; m_fnCallback = NULL; // A whole new Init() process will begin, with the saved data being picked up when it's over Free(); // Download the fonts pCtp->FontListDownload(List); return; } } // Set the document name CComBSTR bstrSrcURL; pCtp->GetSrc(&bstrSrcURL); pAGDoc->SetFileName(CString(bstrSrcURL)); // Set the document as active CDocWindow* pDocWindow = pCtp->GetDocWindow(); if (pDocWindow) pDocWindow->SetDoc(pAGDoc); // No more files to download, so make the final callback after we do the Free() FNDOWNLOADCALLBACK fnCallback = m_fnCallback; LPARAM lParam = m_lParam; Free(); if (fnCallback) fnCallback(lParam, NULL); // If necessary, send the print command if (pCtp->AutoPrintEnabled()) pCtp->m_pDocWindow->SendMessage(WM_COMMAND, IDC_DOC_PRINT); }