本文整理汇总了C++中DataFile::getBFileLen方法的典型用法代码示例。如果您正苦于以下问题:C++ DataFile::getBFileLen方法的具体用法?C++ DataFile::getBFileLen怎么用?C++ DataFile::getBFileLen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataFile
的用法示例。
在下文中一共展示了DataFile::getBFileLen方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: WriteTorrentInfoFile
//
// Writes the info dictionary into the OutputData File. The OutputData file is
// then read in to compute the info_hash
//
void TorrentCreator::WriteTorrentInfoFile(vector<DataFile *> vDatafiles)
{
m_tempOutputFile.SetLength(0);
m_tempOutputFile.SeekToBegin();
BDictionary infoDict;
string key;
BDictionaryItem *filesItem = NULL;
BList *b_files = NULL;
vector<BDictionary *> v_b_file_dict;
vector<BDictionaryItem *> v_lengthItem;
vector<BDictionaryItem *> v_pathItem;
vector<BList *> v_b_pathlist;
// IF there is only one file in the torrent
if( vDatafiles.size() == 1 )
{
DataFile *datafile = vDatafiles.front();
//Add lengthItem
BInteger *fileLen = datafile->getBFileLen();
BDictionaryItem *lengthItem = new BDictionaryItem();
string key = "length";
lengthItem->addIntegerItem( fileLen, key );
infoDict.addItem( lengthItem );
v_lengthItem.push_back( lengthItem );
}
// ELSE there are multiple files in the torrent
else
{
filesItem = new BDictionaryItem;
b_files = new BList; //b_files is a Blist of the BDictionaries b_file_dict.
// FOR each file in the torrent
for( vector<DataFile *>::iterator v_iter = vDatafiles.begin(); v_iter != vDatafiles.end(); v_iter++ )
{
DataFile* datafile = *v_iter;
BDictionary* b_file_dict = new BDictionary();
BInteger * fileLen = datafile->getBFileLen();
BDictionaryItem * lengthItem = new BDictionaryItem();
string key = "length";
lengthItem->addIntegerItem(fileLen, key);
b_file_dict->addItem(lengthItem);
v_lengthItem.push_back(lengthItem);
BDictionaryItem * pathItem = new BDictionaryItem(); // path is a Blist of BStrings of
//the directory hierarchy and the filename
key = "path";
BList * b_pathlist = new BList();
vector <DataPath *> v_datapath = datafile->get_v_datapath();
vector<DataPath *>::iterator v_iter2;
for(v_iter2 = v_datapath.begin(); v_iter2 != v_datapath.end( ) ; v_iter2++) {
BString *dir = (*v_iter2)->GetBDir();
b_pathlist->addItem(dir);
}
//add filename to end of the pathlist
BString *filename = datafile->getBFilename();
b_pathlist->addItem(filename);
pathItem->addListItem(b_pathlist, key);
v_b_pathlist.push_back(b_pathlist);
b_file_dict->addItem(pathItem);
v_pathItem.push_back(pathItem);
b_files->addItem(b_file_dict);
v_b_file_dict.push_back(b_file_dict);
}
key = "files";
filesItem->addListItem( b_files, key );
infoDict.addItem(filesItem);
}
BDictionaryItem *root_item = new BDictionaryItem();
key = "name";
BString *root = m_pIPData->GetBParentDataname();
root_item->addStringItem(root, key);
infoDict.addItem(root_item);
BDictionaryItem pieceLen;
BInteger *plen = m_pIPData->GetBPieceLength();
key = "piece length";
pieceLen.addIntegerItem(plen, key);
infoDict.addItem(&pieceLen);
// Am not adding the hashes to the infoDict for it is UCHAR data that I do not want to
// convert to a signed char or string data.
infoDict.WritePartialEncodedData( &m_tempOutputFile );
key = "pieces";
BString keyStr(key);
keyStr.WriteEncodedData( &m_tempOutputFile );
int pieces_size = (int)(m_vPieceHashes.size()) * 20;
char aBuf[ sizeof(int)*8 + 1 ];
int nLen = sprintf( aBuf, "%d%c", pieces_size, ':' );
m_tempOutputFile.Write( aBuf, nLen );
//.........这里部分代码省略.........