ReqData* NetCore::getReq() { ReqData* req = NULL; while(1) { sem_wait(&_semReq); _reqListLock.get(); if (_reqList.empty()) { LogDbg(" "); _reqListLock.free(); continue; } req = _reqList.front(); _reqList.pop_front(); _reqListLock.free(); break; } return req; }
bool CGattooImg::ThreadProc(const CUPDUPDATA* pCUPDUPData) { SWriteProgressData* pData = (SWriteProgressData*) pCUPDUPData->GetAppData(); LPCTSTR szFilePath = (LPCTSTR) pData->szFilePath; if (nullptr == szFilePath) { LogDbg(_T("No temp file path specified.")); return false; } CVolumeAccess vol(pData->chDrive); if (!vol.IsDeviceReady()) { LogDbg(_T("Device is not ready.")); return false; } if (!vol.checkVolumeParams()) { if (IDYES != MessageBox(nullptr, _T("Volume parameters are not valid. Reformat drive (all data will be lost)?"), _T("Warning"), MB_YESNO|MB_ICONWARNING)) return false; //formatDrive(strDrive[0]); //return true; } FILE* pFile = NULL; _tfopen_s(&pFile, szFilePath, _T("rb")); if (nullptr == pFile) { LogDbg(_T("Failed to open file.")); return false; } fseek(pFile, 0, SEEK_END); long lTotal = ftell(pFile); fseek(pFile, 0, SEEK_SET); DWORD dwStartSector = 70000; size_t readData = 0; const size_t iBufSize = vol.getSectorSize(); std::vector<BYTE> vecData(iBufSize); readData = fread(&vecData[0], sizeof(BYTE), iBufSize, pFile); const double iProgressStep = 100.0 / ceil((double)lTotal/iBufSize); double dCurProgress = iProgressStep; std::stringstream strInfo; strInfo << _T("Completed "); std::streampos const iUpdtPos = strInfo.tellp(); strInfo << "0%"; dwStartSector -= vol.getResrvdSctCount(); while(readData == iBufSize && !pCUPDUPData->ShouldTerminate()) { vol.writeBytesToDeviceSector(&vecData[0], iBufSize, dwStartSector++); readData = fread(&vecData[0], sizeof(BYTE), iBufSize, pFile); pCUPDUPData->SetProgress(strInfo.str().c_str(), (int)dCurProgress); dCurProgress += iProgressStep; strInfo.seekp(iUpdtPos); strInfo << (int)dCurProgress << _T("%"); #ifdef _DEBUG Sleep(50); #else Sleep(0); #endif } if (readData) { memset(&vecData[0] + readData, 0, iBufSize - readData); vol.writeBytesToDeviceSector(&vecData[0], iBufSize, dwStartSector); pCUPDUPData->SetProgress((int)dCurProgress); } fclose(pFile); return true; }