void CMMServer::ProcessDetailRequest(CMMData* data, CMMSocket* sender){ uint8 byFileIndex = data->ReadByte(); if (byFileIndex >= m_SentFileList.GetSize() || !theApp.downloadqueue->IsPartFile(m_SentFileList[byFileIndex])) { CMMPacket* packet = new CMMPacket(MMP_GENERALERROR); sender->SendPacket(packet); ASSERT ( false ); return; } CPartFile* selFile = m_SentFileList[byFileIndex]; CMMPacket* packet = new CMMPacket(MMP_FILEDETAILANS); WriteFileInfo(selFile, packet); sender->SendPacket(packet); }
void CMMServer::ProcessFileListRequest(CMMSocket* sender, CMMPacket* packet){ if (packet == NULL) packet = new CMMPacket(MMP_FILELISTANS); else packet->WriteByte(MMP_FILELISTANS); int nCount = thePrefs.GetCatCount(); packet->WriteByte((uint8)nCount); for (int i = 0; i != nCount; i++){ packet->WriteString(thePrefs.GetCategory(i)->strTitle); } nCount = (theApp.downloadqueue->GetFileCount() > m_nMaxDownloads)? m_nMaxDownloads : theApp.downloadqueue->GetFileCount(); m_SentFileList.SetSize(nCount); packet->WriteByte((uint8)nCount); for (int i = 0; i != nCount; i++){ // while this is not the fastest method the trace this list, it's not timecritical here CPartFile* cur_file = theApp.downloadqueue->GetFileByIndex(i); if (cur_file == NULL){ delete packet; packet = new CMMPacket(MMP_GENERALERROR); sender->SendPacket(packet); ASSERT ( false ); return; } m_SentFileList[i] = cur_file; if (cur_file->GetStatus(false) == PS_PAUSED) packet->WriteByte(MMT_PAUSED); else{ if (cur_file->GetTransferringSrcCount() > 0) packet->WriteByte(MMT_DOWNLOADING); else packet->WriteByte(MMT_WAITING); } packet->WriteString(cur_file->GetFileName()); packet->WriteByte((uint8)cur_file->GetCategory()); if (i < m_nMaxBufDownloads){ packet->WriteByte(1); WriteFileInfo(cur_file,packet); } else{ packet->WriteByte(0); } } sender->SendPacket(packet); }
//=============================================================================================== // FUNCTION: Write // PURPOSE: Writes the complete protocol to the data file. // BOOL CProtocolWriterABF2::Write( const ABF_FileInfo *pOldFileInfo, ABFFileHeader *pFH ) { MEMBERASSERT(); RPTRASSERT( pFH ); m_pFH = pFH; BOOL bOK = TRUE; // Clear the existing file contents if no data has been written. if( m_pFI->GetAcquiredSamples() == 0 ) bOK &= m_pFI->SetEndOfFile(); if( pOldFileInfo ) m_FileInfo.StringsSection = pOldFileInfo->StringsSection; // Clear the strings since we are about to re-write them. m_Strings.Clear(); // Write out the various bits. bOK &= WriteFileInfo(); bOK &= WriteProtocolInfo(); bOK &= WriteADCInfo(); bOK &= WriteDACInfo(); bOK &= WriteEpochs(); bOK &= WriteStats(); bOK &= WriteUserList(); bOK &= WriteMathInfo(); // Write out the protocol strings. bOK &= WriteStrings(); // Now re-write the FileInfo to update the the section info. bOK &= m_pFI->Seek( 0L, FILE_BEGIN); bOK &= m_pFI->Write( &m_FileInfo, sizeof( m_FileInfo ) ); bOK &= m_pFI->Seek( 0L, FILE_END); m_pFI->FillToNextBlock( &m_lNextBlock ); if( m_pFI->GetAcquiredSamples() == 0 ) { m_FileInfo.DataSection.uBlockIndex = m_lNextBlock; m_pFH->lDataSectionPtr = m_lNextBlock; } return bOK; }
bool ZPatcher::CreatePatchFile(FILE* patchFile, std::string& newVersionPath, PatchFileList_t* patchFileList, ProgressCallback progressFunction, ICompressProgress LZMAProgressCallback) { // Initialize our custom LZMA2 Encoder CLzma2EncHandle hLzma2Enc = InitLzma2Encoder(); fprintf(stdout, "Writing patch data...\n"); Log(LOG, "Writing patch data"); // Write the file header, including our custom LZMA2 props Byte props = Lzma2Enc_WriteProperties(hLzma2Enc); WritePatchFileHeader(patchFile, props); size_t totalFiles = patchFileList->RemovedFileList.size() + patchFileList->AddedFileList.size() + patchFileList->ModifiedFileList.size(); unsigned int i = 0; // Process the removed file list in reverse order - Directories should be the last thing being deleted. for (std::vector<std::string>::reverse_iterator ritr = patchFileList->RemovedFileList.rbegin(); ritr != patchFileList->RemovedFileList.rend(); ++ritr) { // Update our progress bar float progress = ((float)++i / (float)totalFiles) * 100.0f; progressFunction(progress, i, totalFiles); Log(LOG, "[del] %s", ritr->c_str()); WriteFileInfo(patchFile, Patch_File_Delete, ritr->c_str()); } for (std::vector<std::string>::iterator itr = patchFileList->AddedFileList.begin(); itr < patchFileList->AddedFileList.end(); ++itr) { // Update our progress bar float progress = ((float)++i / (float)totalFiles) * 100.0f; progressFunction(progress, i, totalFiles); Log(LOG, "[add] %s", itr->c_str()); size_t fileNameLength = itr->length(); if (fileNameLength > 0 && (*itr)[fileNameLength - 1] != '/') { WriteFileInfo(patchFile, Patch_File_Add, itr->c_str()); std::string localPath = newVersionPath + "/" + *itr; if (!WriteCompressedFile(hLzma2Enc, localPath, patchFile, LZMAProgressCallback)) { return false; } } else { WriteFileInfo(patchFile, Patch_Dir_Add, itr->c_str()); } } // Right now, we replace both the modified files and the added files for (std::vector<std::string>::iterator itr = patchFileList->ModifiedFileList.begin(); itr < patchFileList->ModifiedFileList.end(); ++itr) { // Update our progress bar float progress = ((float)++i / (float)totalFiles) * 100.0f; progressFunction(progress, i, totalFiles); Log(LOG, "[mod] %s", itr->c_str()); WriteFileInfo(patchFile, Patch_File_Replace, itr->c_str()); std::string localPath = newVersionPath + "/" + *itr; if (!WriteCompressedFile(hLzma2Enc, localPath, patchFile, LZMAProgressCallback)) { return false; } } // Update our progress bar float progress = ((float)i / (float)totalFiles) * 100.0f; progressFunction(progress, i, totalFiles); // Hacky hack if we are using our own provided function ;) if (progressFunction == &PrintCreatePatchProgressBar) { fprintf(stdout, "\n"); } Log(LOG, "Patch data writing process completed"); DestroyLzma2EncHandle(hLzma2Enc); return true; }