//--------------------------------------------------------------------------------------------- int WinMainLauncher::Run( GameApplication* a_application , HINSTANCE a_hInstance, int a_nCmdShow ) { Init( a_application , a_hInstance , a_nCmdShow ); // Initialize the App a_application->Init( m_hWnd ); // HACCEL hAccelTable = LoadAccelerators( m_hInst , MAKEINTRESOURCE(IDC_HELLOTRIANGLE) ); while( !m_quitRequested ) { // Process all the Windows messages ProcessWindowsMessages(); if( ! m_quitRequested ) { a_application->OnFrame(); } } Close(); return 0; }
//--------------------------------------------- // nsZipArchive::Test //--------------------------------------------- nsresult nsZipArchive::Test(const char *aEntryName) { nsZipItem* currItem; if (aEntryName) // only test specified item { currItem = GetItem(aEntryName); if (!currItem) return ZIP_ERR_FNF; //-- don't test (synthetic) directory items if (currItem->isDirectory) return ZIP_OK; return ExtractFile(currItem, 0, 0); } // test all items in archive for (int i = 0; i < ZIP_TABSIZE; i++) { for (currItem = mFiles[i]; currItem; currItem = currItem->next) { //-- don't test (synthetic) directory items if (currItem->isDirectory) continue; nsresult rv = ExtractFile(currItem, 0, 0); if (rv != ZIP_OK) return rv; #if defined STANDALONE && defined XP_WIN ProcessWindowsMessages(); #endif } } return ZIP_OK; }
int glWindow::MouseYD () { // Read any pending windows messages ProcessWindowsMessages (); if (!m_focused) return 0; if (!m_mouseCentred) { m_mouseX = m_width / 2; m_mouseY = m_height / 2; PositionMouse (); m_mouseCentred = true; DoHideCursor (); return 0; } // Calculate how far mouse has moved from centre int centre = m_height / 2; int result = m_mouseY - centre; // Recentre cursor y m_mouseY = centre; PositionMouse (); // Return result return result; }
void glWindow::Hide () { DoShowCursor (); if (!m_visible) return; ShowWindow(m_HWnd,SW_HIDE); // Hide the window ProcessWindowsMessages (); m_visible = false; if (m_fullScreen) // Are We In Fullscreen Mode? ChangeDisplaySettings(NULL,0); // If So Switch Back To The Desktop }
int ProcessWndMsgCB() { int iRv = nsFTPConn::OK; ProcessWindowsMessages(); if((gdwDownloadDialogStatus == CS_CANCEL) || (gdwDownloadDialogStatus == CS_PAUSE)) iRv = nsFTPConn::E_USER_CANCEL; return(iRv); }
void cbXPIProgress(const char* msg, PRInt32 val, PRInt32 max) { char szFilename[MAX_BUF]; ParsePath((char *)msg, szFilename, sizeof(szFilename), PP_FILENAME_ONLY); if(max == 0) printf("Processing: %s\n", szFilename); else printf("Installing: %d/%d %s\n", val, max, szFilename); ProcessWindowsMessages(); }
void cbXPIProgress(const char* msg, PRInt32 val, PRInt32 max) { char szBuf[MAX_BUF]; if(sgProduct.ulMode != SILENT) { TruncateString(WinWindowFromID(dlgInfo.hWndDlg, IDC_STATUS3), msg, szBuf, sizeof(szBuf)); WinSetDlgItemText(dlgInfo.hWndDlg, IDC_STATUS3, szBuf); } ProcessWindowsMessages(); }
void PauseTheDownload(int rv, int *iFileDownloadRetries) { if(rv != nsFTPConn::E_USER_CANCEL) { SendMessage(dlgInfo.hWndDlg, WM_COMMAND, IDPAUSE, 0); --*iFileDownloadRetries; } while(gdwDownloadDialogStatus == CS_PAUSE) { SleepEx(200, FALSE); ProcessWindowsMessages(); } }
char glWindow::GetScanKey () { // Flush any keypress messages ProcessWindowsMessages (); // Check for buffered keypress if (m_scanBufStart == m_scanBufEnd) return 0; // Extract and return it char result = m_scanKeyBuffer [m_scanBufStart]; IncScanStart (); return result; }
int ProgressCB(int aBytesSoFar, int aTotalFinalSize) { long lBytesDiffSoFar; double dPercentSoFar; int iRv = nsFTPConn::OK; if(sgProduct.mode != SILENT) { SetStatusUrl(); if(glTotalKb == 0) glTotalKb = aTotalFinalSize; /* Calculate the difference between the last set of bytes read against * the current set of bytes read. If the value is negative, that means * that it started a new file, so reset lBytesDiffSoFar to aBytesSoFar */ lBytesDiffSoFar = ((aBytesSoFar - glLastBytesSoFar) < 1) ? aBytesSoFar : (aBytesSoFar - glLastBytesSoFar); /* Save the current bytes read as the last set of bytes read */ glLastBytesSoFar = aBytesSoFar; glAbsoluteBytesSoFar += lBytesDiffSoFar; dPercentSoFar = GetPercentSoFar(); if(gbDlgDownloadMinimized) SetMinimizedDownloadTitle((int)dPercentSoFar); UpdateGaugeFileProgressBar(dPercentSoFar); SetStatusStatus(); if((gdwDownloadDialogStatus == CS_CANCEL) || (gdwDownloadDialogStatus == CS_PAUSE)) iRv = nsFTPConn::E_USER_CANCEL; } ProcessWindowsMessages(); return(iRv); }
int DownloadFiles(char *szInputIniFile, char *szDownloadDir, char *szProxyServer, char *szProxyPort, char *szProxyUser, char *szProxyPasswd, BOOL bShowRetryMsg, BOOL bIgnoreAllNetworkErrors, char *szFailedFile, DWORD dwFailedFileSize) { char szBuf[MAX_BUF]; char szCurrentFile[MAX_BUF]; char szSection[MAX_INI_SK]; char szKey[MAX_INI_SK]; char szSavedCwd[MAX_BUF_MEDIUM]; int iCounter; int rv; int iFileDownloadRetries; int iIgnoreFileNetworkError; int iLocalTimeOutCounter; DWORD dwTotalEstDownloadSize; char szPartiallyDownloadedFilename[MAX_BUF]; BOOL bDownloadInitiated; char szTempURL[MAX_BUF]; char szWorkingURLPathOnly[MAX_BUF]; siC *siCCurrentFileObj = NULL; ZeroMemory(szTempURL, sizeof(szTempURL)); ZeroMemory(szWorkingURLPathOnly, sizeof(szWorkingURLPathOnly)); if(szInputIniFile == NULL) return(WIZ_ERROR_UNDEFINED); if(szFailedFile) ZeroMemory(szFailedFile, dwFailedFileSize); InitTickInfo(); GetCurrentDirectory(sizeof(szSavedCwd), szSavedCwd); SetCurrentDirectory(szDownloadDir); rv = WIZ_OK; dwTotalEstDownloadSize = 0; giTotalArchivesToDownload = 0; glLastBytesSoFar = 0; glAbsoluteBytesSoFar = 0; glBytesResumedFrom = 0; gdwTickStart = 0; /* Initialize the counter used to * calculate download rate */ gbStartTickCounter = FALSE; /* used to determine when to start * the tick counter used to calculate * the download rate */ gbUrlChanged = TRUE; gbDlgDownloadMinimized = FALSE; gbDlgDownloadJustMinimized = FALSE; gdwDownloadDialogStatus = CS_NONE; gbShowDownloadRetryMsg = bShowRetryMsg; gszConfigIniFile = szInputIniFile; bDownloadInitiated = FALSE; GetTotalArchivesToDownload(&giTotalArchivesToDownload, &dwTotalEstDownloadSize); glTotalKb = dwTotalEstDownloadSize; GetSetupCurrentDownloadFile(szPartiallyDownloadedFilename, sizeof(szPartiallyDownloadedFilename)); InitDownloadDlg(); for(giIndex = 0; giIndex < giTotalArchivesToDownload; giIndex++) { /* set (or reset) the counter to 0 in order to read the * next files's 0'th url from the .idi file */ iCounter = 0; gbUrlChanged = TRUE; /* Update the download dialog with new URL */ wsprintf(szSection, "File%d", giIndex); wsprintf(szKey, "url%d", iCounter); GetPrivateProfileString(szSection, szKey, "", szTempURL, sizeof(szTempURL), gszConfigIniFile); if(*szTempURL == '\0') continue; if(!bDownloadInitiated) { ParsePath(szTempURL, szWorkingURLPathOnly, sizeof(szWorkingURLPathOnly), TRUE, //use '/' as the path delimiter PP_PATH_ONLY); } GetPrivateProfileString(szSection, "desc", "", gszCurrentDownloadFileDescription, sizeof(gszCurrentDownloadFileDescription), gszConfigIniFile); iIgnoreFileNetworkError = GetPrivateProfileInt(szSection, "Ignore File Network Error", 0, gszConfigIniFile); /* save the file name to be downloaded */ ParsePath(szTempURL, szCurrentFile, sizeof(szCurrentFile), TRUE, //use '/' as the path delimiter PP_FILENAME_ONLY); RemoveSlash(szWorkingURLPathOnly); wsprintf(gszUrl, "%s/%s", szWorkingURLPathOnly, szCurrentFile); /* retrieve the file's data structure */ siCCurrentFileObj = GetObjectFromArchiveName(szCurrentFile); if((*szPartiallyDownloadedFilename != 0) && (lstrcmpi(szPartiallyDownloadedFilename, szCurrentFile) == 0)) { struct stat statBuf; if(stat(szPartiallyDownloadedFilename, &statBuf) != -1) { glAbsoluteBytesSoFar += statBuf.st_size; glBytesResumedFrom = statBuf.st_size; } } lstrcpy(gszTo, szDownloadDir); AppendBackSlash(gszTo, sizeof(gszTo)); lstrcat(gszTo, szCurrentFile); if(gbDlgDownloadMinimized) SetMinimizedDownloadTitle((int)GetPercentSoFar()); else { SetStatusUrl(); SetRestoredDownloadTitle(); } SetSetupCurrentDownloadFile(szCurrentFile); iFileDownloadRetries = 0; iLocalTimeOutCounter = 0; do { ProcessWindowsMessages(); /* Download starts here */ if((szProxyServer != NULL) && (szProxyPort != NULL) && (*szProxyServer != '\0') && (*szProxyPort != '\0')) /* If proxy info is provided, use HTTP proxy */ rv = DownloadViaProxy(gszUrl, szProxyServer, szProxyPort, szProxyUser, szProxyPasswd); else { /* is this an HTTP URL? */ if(strncmp(gszUrl, kHTTP, lstrlen(kHTTP)) == 0) rv = DownloadViaHTTP(gszUrl); /* or is this an FTP URL? */ else if(strncmp(gszUrl, kFTP, lstrlen(kFTP)) == 0) rv = DownloadViaFTP(gszUrl); } bDownloadInitiated = TRUE; if((rv == nsFTPConn::E_USER_CANCEL) || (gdwDownloadDialogStatus == CS_PAUSE)) { if(gdwDownloadDialogStatus == CS_PAUSE) { CloseSocket(szProxyServer, szProxyPort); /* rv needs to be set to something * other than E_USER_CANCEL or E_OK */ rv = nsFTPConn::E_CMD_UNEXPECTED; PauseTheDownload(rv, &iFileDownloadRetries); bDownloadInitiated = FALSE; /* restart the download using * new socket connection */ } else { /* user canceled; break out of the do loop */ break; } } else if((rv != nsFTPConn::OK) && (rv != nsFTPConn::E_CMD_FAIL) && (rv != nsSocket::E_BIND) && (rv != nsHTTPConn::E_HTTP_RESPONSE) && (gdwDownloadDialogStatus != CS_CANCEL)) { /* We timed out. No response from the server, or * we somehow lost connection. */ char szTitle[MAX_BUF_SMALL]; char szMsgDownloadPaused[MAX_BUF]; /* Incrememt the time out counter on E_TIMEOUT */ if(rv == nsSocket::E_TIMEOUT) { ++siCCurrentFileObj->iNetTimeOuts; ++iLocalTimeOutCounter; } CloseSocket(szProxyServer, szProxyPort); /* If the number of timeouts is %3 == 0, then let's pause * the download process. Otherwise, just close the * connection and open a new one to see if the download * can be restarted automatically. */ if((rv != nsSocket::E_TIMEOUT) || (rv == nsSocket::E_TIMEOUT) && ((iLocalTimeOutCounter % kModTimeOutValue) == 0)) { /* Start the pause tick counter here because we don't know how * long before the user will dismiss the MessageBox() */ if(!gtiPaused.bTickStarted) { gtiPaused.dwTickBegin = GetTickCount(); gtiPaused.bTickStarted = TRUE; gtiPaused.bTickDownloadResumed = FALSE; } /* The connection unexepectedly dropped for some reason, so inform * the user that the download will be Paused, and then update the * Download dialog to show the Paused state. */ GetConfigIniProfileString("Messages", "MB_WARNING_STR", "", szTitle, sizeof(szTitle)); GetConfigIniProfileString("Strings", "Message Download Paused", "", szMsgDownloadPaused, sizeof(szMsgDownloadPaused)); MessageBox(dlgInfo.hWndDlg, szMsgDownloadPaused, szTitle, MB_ICONEXCLAMATION); /* Let's make sure we're in a paused state */ gdwDownloadDialogStatus = CS_PAUSE; PauseTheDownload(rv, &iFileDownloadRetries); } else /* Let's make sure we're _not_ in a paused state */ gdwDownloadDialogStatus = CS_NONE; } /* We don't count time outs as normal failures. We're * keeping track of time outs differently. */ if(rv != nsSocket::E_TIMEOUT) ++iFileDownloadRetries; if((iFileDownloadRetries > MAX_FILE_DOWNLOAD_RETRIES) && (rv != nsFTPConn::E_USER_CANCEL) && (gdwDownloadDialogStatus != CS_CANCEL)) { /* since the download retries maxed out, increment the counter * to read the next url for the current file */ ++iCounter; wsprintf(szKey, "url%d", iCounter); GetPrivateProfileString(szSection, szKey, "", szTempURL, sizeof(szTempURL), gszConfigIniFile); if(*szTempURL != '\0') { /* Found more urls to download from for the current file. * Update the dialog to show the new url and reset the * file download retries to 0 since it's a new url. */ gbUrlChanged = TRUE; iFileDownloadRetries = 0; bDownloadInitiated = FALSE; // restart the download using new socket connection CloseSocket(szProxyServer, szProxyPort); ParsePath(szTempURL, szWorkingURLPathOnly, sizeof(szWorkingURLPathOnly), TRUE, //use '/' as the path delimiter PP_PATH_ONLY); RemoveSlash(szWorkingURLPathOnly); wsprintf(gszUrl, "%s/%s", szWorkingURLPathOnly, szCurrentFile); SetStatusUrl(); } } } while((rv != nsFTPConn::E_USER_CANCEL) && (rv != nsFTPConn::OK) && (gdwDownloadDialogStatus != CS_CANCEL) && (iFileDownloadRetries <= MAX_FILE_DOWNLOAD_RETRIES)); /* Save the number of retries for each file */ siCCurrentFileObj->iNetRetries = iFileDownloadRetries < 1 ? 0:iFileDownloadRetries - 1; if((rv == nsFTPConn::E_USER_CANCEL) || (gdwDownloadDialogStatus == CS_CANCEL)) { /* make sure rv is E_USER_CANCEL when gdwDownloadDialogStatus * is CS_CANCEL */ rv = nsFTPConn::E_USER_CANCEL; if(szFailedFile && ((DWORD)lstrlen(szCurrentFile) <= dwFailedFileSize)) lstrcpy(szFailedFile, gszCurrentDownloadFileDescription); /* break out of for() loop */ break; } if((rv != nsFTPConn::OK) && (iFileDownloadRetries > MAX_FILE_DOWNLOAD_RETRIES) && !bIgnoreAllNetworkErrors && !iIgnoreFileNetworkError) { /* too many retries from failed downloads */ char szMsg[MAX_BUF]; if(szFailedFile && ((DWORD)lstrlen(szCurrentFile) <= dwFailedFileSize)) lstrcpy(szFailedFile, gszCurrentDownloadFileDescription); GetConfigIniProfileString("Strings", "Error Too Many Network Errors", "", szMsg, sizeof(szMsg)); if(*szMsg != '\0') { wsprintf(szBuf, szMsg, szCurrentFile); PrintError(szBuf, ERROR_CODE_HIDE); } iFileDownloadRetries = 0; // reset the file download retries counter since // we'll be restarting the download again. bDownloadInitiated = FALSE; // restart the download using new socket connection CloseSocket(szProxyServer, szProxyPort); --giIndex; // Decrement the file index counter because we'll be trying to // download the same file again. We don't want to go to the next // file just yet. /* Let's make sure we're in a paused state. */ /* The pause state will be unset by DownloadDlgProc(). */ gdwDownloadDialogStatus = CS_PAUSE; PauseTheDownload(rv, &iFileDownloadRetries); } else if(bIgnoreAllNetworkErrors || iIgnoreFileNetworkError) rv = nsFTPConn::OK; UnsetSetupCurrentDownloadFile(); } CloseSocket(szProxyServer, szProxyPort); DeInitDownloadDlg(); SetCurrentDirectory(szSavedCwd); return(rv); }
HRESULT SmartUpdateJars() { DWORD dwIndex0; siC *siCObject = NULL; HRESULT hrResult; char szBuf[MAX_BUF]; char szEXpiInstall[MAX_BUF]; char szArchive[MAX_BUF]; char szMsgSmartUpdateStart[MAX_BUF]; char szDlgExtractingTitle[MAX_BUF]; if(!GetPrivateProfileString("Messages", "MSG_SMARTUPDATE_START", "", szMsgSmartUpdateStart, sizeof(szMsgSmartUpdateStart), szFileIniInstall)) return(1); if(!GetPrivateProfileString("Messages", "DLG_EXTRACTING_TITLE", "", szDlgExtractingTitle, sizeof(szDlgExtractingTitle), szFileIniInstall)) return(1); if(!GetPrivateProfileString("Messages", "STR_PROCESSINGFILE", "", szStrProcessingFile, sizeof(szStrProcessingFile), szFileIniInstall)) exit(1); if(!GetPrivateProfileString("Messages", "STR_INSTALLING", "", szStrInstalling, sizeof(szStrInstalling), szFileIniInstall)) exit(1); if(!GetPrivateProfileString("Messages", "STR_COPYINGFILE", "", szStrCopyingFile, sizeof(szStrCopyingFile), szFileIniInstall)) exit(1); ShowMessage(szMsgSmartUpdateStart, TRUE); if(InitializeXPIStub() == WIZ_OK) { LogISXPInstall(W_START); strcpy(szBuf, sgProduct.szPath); if(*sgProduct.szSubPath != '\0') { AppendBackSlash(szBuf, sizeof(szBuf)); strcat(szBuf, sgProduct.szSubPath); } hrResult = pfnXpiInit(szBuf, FILE_INSTALL_LOG, cbXPIProgress); /* Unset LIBPATHSTRICT */ DosSetExtLIBPATH("F", LIBPATHSTRICT); ShowMessage(szMsgSmartUpdateStart, FALSE); InitProgressDlg(); GetTotalArchivesToInstall(); WinSetWindowText(dlgInfo.hWndDlg, szDlgExtractingTitle); dwIndex0 = 0; dwCurrentArchive = 0; siCObject = SiCNodeGetObject(dwIndex0, TRUE, AC_ALL); while(siCObject) { if(siCObject->dwAttributes & SIC_SELECTED) /* Since the archive is selected, we need to process the file ops here */ ProcessFileOps(T_PRE_ARCHIVE, siCObject->szReferenceName); /* launch smartupdate engine for earch jar to be installed */ if((siCObject->dwAttributes & SIC_SELECTED) && !(siCObject->dwAttributes & SIC_LAUNCHAPP) && !(siCObject->dwAttributes & SIC_DOWNLOAD_ONLY)) { strcpy(szArchive, sgProduct.szAlternateArchiveSearchPath); AppendBackSlash(szArchive, sizeof(szArchive)); strcat(szArchive, siCObject->szArchiveName); if((*sgProduct.szAlternateArchiveSearchPath == '\0') || (!FileExists(szArchive))) { strcpy(szArchive, szSetupDir); AppendBackSlash(szArchive, sizeof(szArchive)); strcat(szArchive, siCObject->szArchiveName); if(!FileExists(szArchive)) { strcpy(szArchive, szTempDir); AppendBackSlash(szArchive, sizeof(szArchive)); strcat(szArchive, siCObject->szArchiveName); if(!FileExists(szArchive)) { char szEFileNotFound[MAX_BUF]; if(GetPrivateProfileString("Messages", "ERROR_FILE_NOT_FOUND", "", szEFileNotFound, sizeof(szEFileNotFound), szFileIniInstall)) { sprintf(szBuf, szEFileNotFound, szArchive); PrintError(szBuf, ERROR_CODE_HIDE); } return(1); } } } if(dwCurrentArchive == 0) { ++dwCurrentArchive; UpdateGaugeArchiveProgressBar((unsigned)(((double)(dwCurrentArchive)/(double)dwTotalArchives)*(double)100)); } sprintf(szBuf, szStrInstalling, siCObject->szDescriptionShort); WinSetDlgItemText(dlgInfo.hWndDlg, IDC_STATUS0, szBuf); LogISXPInstallComponent(siCObject->szDescriptionShort); hrResult = pfnXpiInstall(szArchive, "", 0xFFFF); if(hrResult == E_REBOOT) bReboot = TRUE; else if((hrResult != WIZ_OK) && !(siCObject->dwAttributes & SIC_IGNORE_XPINSTALL_ERROR)) { LogMSXPInstallStatus(siCObject->szArchiveName, hrResult); LogISXPInstallComponentResult(hrResult); if(GetPrivateProfileString("Messages", "ERROR_XPI_INSTALL", "", szEXpiInstall, sizeof(szEXpiInstall), szFileIniInstall)) { char szErrorString[MAX_BUF]; GetErrorString(hrResult, szErrorString, sizeof(szErrorString)); sprintf(szBuf, "%s - %s: %d %s", szEXpiInstall, siCObject->szDescriptionShort, hrResult, szErrorString); PrintError(szBuf, ERROR_CODE_HIDE); } /* break out of the siCObject while loop */ break; } ++dwCurrentArchive; UpdateGaugeArchiveProgressBar((unsigned)(((double)(dwCurrentArchive)/(double)dwTotalArchives)*(double)100)); ProcessWindowsMessages(); LogISXPInstallComponentResult(hrResult); if((hrResult != WIZ_OK) && (siCObject->dwAttributes & SIC_IGNORE_XPINSTALL_ERROR)) /* reset the result to WIZ_OK if there was an error and the * component's attributes contains SIC_IGNORE_XPINSTALL_ERROR. * This should be done after LogISXPInstallComponentResult() * because we still should log the error value. */ hrResult = WIZ_OK; } if(siCObject->dwAttributes & SIC_SELECTED) /* Since the archive is selected, we need to do the file ops here */ ProcessFileOps(T_POST_ARCHIVE, siCObject->szReferenceName); ++dwIndex0; siCObject = SiCNodeGetObject(dwIndex0, TRUE, AC_ALL); } /* while(siCObject) */ LogMSXPInstallStatus(NULL, hrResult); pfnXpiExit(); if(sgProduct.ulMode != SILENT) WinDestroyWindow(dlgInfo.hWndDlg); } else { ShowMessage(szMsgSmartUpdateStart, FALSE); } DeInitializeXPIStub(); LogISXPInstall(W_END); return(hrResult); }
BOOL APIENTRY ExtractFilesProc(HANDLE hModule, LPCTSTR lpszType, LPTSTR lpszName, LONG lParam) { char szTmpFile[MAX_PATH]; char szArcLstFile[MAX_PATH]; HRSRC hResInfo; HGLOBAL hGlobal; LPBYTE lpBytes; LPBYTE lptr; LPBYTE lpBytesUnCmp; HANDLE hFile; char szStatus[128]; char szText[4096]; // Update the UI LoadString(hInst, IDS_STATUS_EXTRACTING, szText, sizeof(szText)); wsprintf(szStatus, szText, lpszName); SetStatusLine(szStatus); if(gbUncompressOnly == TRUE) lstrcpy(szTmpFile, lpszName); else { // Create a file in the temp directory GetFullTempPathName(lpszName, sizeof(szTmpFile), szTmpFile); CreateDirectoriesAll(szTmpFile); } if((*gszFileToUncompress != '\0') && (lstrcmpi(lpszName, gszFileToUncompress) != 0)) // We have a file to uncompress, but the one found is not the one we want, // so return TRUE to continue looking for the right one. return TRUE; // Extract the file hResInfo = FindResource((HINSTANCE)hModule, lpszName, lpszType); hGlobal = LoadResource((HINSTANCE)hModule, hResInfo); lpBytes = (LPBYTE)LockResource(hGlobal); // Create the file hFile = CreateFile(szTmpFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY, NULL); if (hFile != INVALID_HANDLE_VALUE) { DWORD dwSize; DWORD dwSizeUnCmp; DWORD dwTemp; GetFullTempPathName("Archive.lst", sizeof(szArcLstFile), szArcLstFile); WritePrivateProfileString("Archives", lpszName, "TRUE", szArcLstFile); lptr = (LPBYTE)malloc((*(LPDWORD)(lpBytes + sizeof(DWORD))) + 1); if(!lptr) { char szBuf[512]; LoadString(hInst, IDS_ERROR_OUT_OF_MEMORY, szBuf, sizeof(szBuf)); MessageBox(NULL, szBuf, NULL, MB_OK | MB_ICONEXCLAMATION); return FALSE; } lpBytesUnCmp = lptr; dwSizeUnCmp = *(LPDWORD)(lpBytes + sizeof(DWORD)); // Copy the file. The first DWORD specifies the size of the file dwSize = *(LPDWORD)lpBytes; lpBytes += (sizeof(DWORD) * 2); dwTemp = uncompress(lpBytesUnCmp, &dwSizeUnCmp, lpBytes, dwSize); while (dwSizeUnCmp > 0) { DWORD dwBytesToWrite, dwBytesWritten; ProcessWindowsMessages(); dwBytesToWrite = dwSizeUnCmp > 4096 ? 4096 : dwSizeUnCmp; if (!WriteFile(hFile, lpBytesUnCmp, dwBytesToWrite, &dwBytesWritten, NULL)) { char szBuf[512]; LoadString(hInst, IDS_STATUS_EXTRACTING, szText, sizeof(szText)); wsprintf(szBuf, szText, szTmpFile); MessageBox(NULL, szBuf, szTitle, MB_OK | MB_ICONEXCLAMATION); FreeResource(hResInfo); if(lptr) free(lptr); return FALSE; } dwSizeUnCmp -= dwBytesWritten; lpBytesUnCmp += dwBytesWritten; // Update the UI to reflect the total number of bytes written static DWORD nBytesWritten = 0; nBytesWritten += dwBytesWritten; UpdateProgressBar(nBytesWritten * 100 / nTotalBytes); } CloseHandle(hFile); } // Release the resource FreeResource(hResInfo); if(lptr) free(lptr); if((*gszFileToUncompress != '\0') && (lstrcmpi(lpszName, gszFileToUncompress) == 0)) // We have a file to uncompress, and we have uncompressed it, // so return FALSE to stop uncompressing any other file. return FALSE; return TRUE; // keep enumerating }
//--------------------------------------------- // nsZipArchive::InflateItem //--------------------------------------------- nsresult nsZipArchive::InflateItem(const nsZipItem* aItem, PRFileDesc* outFD) /* * This function inflates an archive item to disk, to the * file specified by outFD. If outFD is zero, the extracted data is * not written, only checked for CRC, so this is in effect same as 'Test'. */ { PR_ASSERT(aItem); //-- allocate deflation buffers Bytef inbuf[ZIP_BUFLEN]; Bytef outbuf[ZIP_BUFLEN]; //-- set up the inflate z_stream zs; nsresult status = gZlibInit(&zs); if (status != ZIP_OK) return ZIP_ERR_GENERAL; //-- inflate loop zs.next_out = outbuf; zs.avail_out = ZIP_BUFLEN; PRUint32 size = aItem->size; PRUint32 outpos = 0; PRUint32 crc = crc32(0L, Z_NULL, 0); int zerr = Z_OK; while (zerr == Z_OK) { PRBool bRead = PR_FALSE; PRBool bWrote= PR_FALSE; if (zs.avail_in == 0 && zs.total_in < size) { //-- no data to inflate yet still more in file: //-- read another chunk of compressed data PRUint32 chunk = (size-zs.total_in < ZIP_BUFLEN) ? size-zs.total_in : ZIP_BUFLEN; if (PR_Read(mFd, inbuf, chunk) != (READTYPE)chunk) { //-- unexpected end of data status = ZIP_ERR_CORRUPT; break; } zs.next_in = inbuf; zs.avail_in = chunk; bRead = PR_TRUE; } if (zs.avail_out == 0) { //-- write inflated buffer to disk and make space if (outFD && PR_Write(outFD, outbuf, ZIP_BUFLEN) < ZIP_BUFLEN) { //-- Couldn't write all the data (disk full?) status = ZIP_ERR_DISK; break; } outpos = zs.total_out; zs.next_out = outbuf; zs.avail_out = ZIP_BUFLEN; bWrote = PR_TRUE; } if(bRead || bWrote) { Bytef* old_next_out = zs.next_out; zerr = inflate(&zs, Z_PARTIAL_FLUSH); //-- incrementally update crc32 crc = crc32(crc, (const unsigned char*)old_next_out, zs.next_out - old_next_out); } else zerr = Z_STREAM_END; #if defined STANDALONE && defined XP_WIN ProcessWindowsMessages(); #endif } // while //-- verify crc32 if ((status == ZIP_OK) && (crc != aItem->crc32)) { status = ZIP_ERR_CORRUPT; goto cleanup; } //-- write last inflated bit to disk if (zerr == Z_STREAM_END && outpos < zs.total_out) { PRUint32 chunk = zs.total_out - outpos; if (outFD && PR_Write(outFD, outbuf, chunk) < (READTYPE)chunk) status = ZIP_ERR_DISK; } //-- convert zlib error to return value if (status == ZIP_OK && zerr != Z_OK && zerr != Z_STREAM_END) { status = (zerr == Z_MEM_ERROR) ? ZIP_ERR_MEMORY : ZIP_ERR_CORRUPT; } //-- if found no errors make sure we've converted the whole thing // Allow for reading less than the total size if it appears we've // reached the end of the stream without error. It appears Celtx // can produce a .celtx file where an entry appears to be padded // with unnecessary data (size is 316752 bytes, but inflation // stops at 316749 bytes). It's still an error if we read more than // intended, or if the output doesn't match the expected size. PR_ASSERT(status != ZIP_OK || zs.total_in == aItem->size || (zerr == Z_STREAM_END && zs.total_in < aItem->size)); PR_ASSERT(status != ZIP_OK || zs.total_out == aItem->realsize); cleanup: //-- free zlib internal state inflateEnd(&zs); return status; }