本文整理汇总了C++中BString::read_file方法的典型用法代码示例。如果您正苦于以下问题:C++ BString::read_file方法的具体用法?C++ BString::read_file怎么用?C++ BString::read_file使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BString
的用法示例。
在下文中一共展示了BString::read_file方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadMetaInfoFile
//! Added by Amir Krifa.
//! Used to load a Meta Info File, not in a network manner.
void MetainfoSocket::LoadMetaInfoFile(bool bSeeding,string MetaInfoFilePath)
{
this->SetMetaInfoFileToLoad(MetaInfoFilePath);
try
{
FILE *fil = fopen(m_filename.c_str(), "rb");
m_fil=fil;
if (fil)
{
PeerHandler& ref = static_cast<PeerHandler&>(Handler());
BString meta;
meta.read_file(fil,m_filename);
fclose(fil);
std::string info_hash = meta.GetHashAsString("info");
// copy metainfo file
std::string copy_to = ref.GetTorrentDirectory() + "\\" + info_hash + "\\.metainfo";
ref.mkpath(copy_to);
fil = fopen(m_filename.c_str(), "rb");
if (fil)
{
FILE *fil2 = fopen(copy_to.c_str(), "wb");
char buf[1000];
size_t n = fread(buf, 1, 1000, fil);
while (n > 0)
{
fwrite(buf, 1, n, fil2);
n = fread(buf, 1, 1000, fil);
}
fclose(fil2);
fclose(fil);
}
if (ref.SessionExists(info_hash))
{
}
else
{
Session *sess = new Session(dynamic_cast<SocketHandler&>(Handler()), info_hash, bSeeding,string(ref.GetTorrentDirectory() + "\\" + info_hash + "\\" ));
ref.RegSession( sess );
sess -> SetHash(meta.GetHash("info"));
BTString *p;
if ((p = meta.GetString("announce")) != NULL)
{
sess -> SetAnnounce(p -> GetValue());
}
std::string name;
if ((p = meta.GetString("info.name")) != NULL)
{
sess -> SetName(name = p -> GetValue());
}
BTInteger *piecelength = meta.GetInteger("info.piece length");
if (piecelength)
{
sess -> SetPieceLength(piecelength -> GetVal());
}
BTInteger *length = meta.GetInteger("info.length");
if (length)
{
sess -> AddFile(length -> GetVal());
}
else // info.files
{
BTObject *p = meta.GetBTObject("info.files");
BTList *files = dynamic_cast<BTList *>(p);
if (files)
{
btobject_v& ref = files -> GetList();
for (btobject_v::iterator it = ref.begin(); it != ref.end(); it++)
{
BTDictionary *p = dynamic_cast<BTDictionary *>(*it);
if (p)
{
BTInteger *length = dynamic_cast<BTInteger *>(p -> Find("length"));
BTList *path = dynamic_cast<BTList *>(p -> Find("path"));
if (path && length)
{
btobject_v& ref = path -> GetList();
std::string pathname = name;
for (btobject_v::iterator it = ref.begin(); it != ref.end(); it++)
{
BTString *p = dynamic_cast<BTString *>(*it);
if (p)
pathname += "\\" + p -> GetValue();
}
sess -> AddFile(pathname, length -> GetVal());
}
path=NULL;
length=NULL;
}
p=NULL;
}
}
files=NULL;
}
//! pieces checksum
BTString *pieces = meta.GetString("info.pieces");
if (pieces)
//.........这里部分代码省略.........