本文整理汇总了C++中FileOffset::end方法的典型用法代码示例。如果您正苦于以下问题:C++ FileOffset::end方法的具体用法?C++ FileOffset::end怎么用?C++ FileOffset::end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileOffset
的用法示例。
在下文中一共展示了FileOffset::end方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OpenPacked
PyObject* plPythonPack::OpenPacked(const char* fileName)
{
if (!Open())
return nil;
std::string pythonName = fileName;
pythonName += ".py";
FileOffset::iterator it = fFileOffsets.find(pythonName);
if (it != fFileOffsets.end())
{
plPackOffsetInfo offsetInfo = (*it).second;
hsStream* fPackStream = fPackStreams[offsetInfo.fStreamIndex];
fPackStream->SetPosition(offsetInfo.fOffset);
int32_t size = fPackStream->ReadLE32();
if (size > 0)
{
char *buf = new char[size];
uint32_t readSize = fPackStream->Read(size, buf);
hsAssert(readSize <= size, xtl::format("Python PackFile %s: Incorrect amount of data, read %d instead of %d",
fileName, readSize, size).c_str());
// let the python marshal make it back into a code object
PyObject *pythonCode = PyMarshal_ReadObjectFromString(buf, size);
delete [] buf;
return pythonCode;
}
}
return nil;
}
示例2: Open
bool plPythonPack::Open()
{
if (fPackStreams.size() > 0)
return true;
// We already tried and it wasn't there
if (fPackNotFound)
return false;
fPackNotFound = true;
// Get the names of all the pak files
std::vector<plFileName> files = plStreamSource::GetInstance()->GetListOfNames("python", "pak");
std::vector<time_t> modTimes; // the modification time for each of the streams (to resolve duplicate file issues)
// grab all the .pak files in the folder
for (int curName = 0; curName < files.size(); curName++)
{
// obtain the stream
hsStream *fPackStream = plStreamSource::GetInstance()->GetFile(files[curName]);
if (fPackStream)
{
fPackStream->Rewind(); // make sure we're at the beginning of the file
fPackNotFound = false;
time_t curModTime = 0;
plFileInfo info(files[curName]);
if (info.Exists())
curModTime = info.ModifyTime();
modTimes.push_back(curModTime);
// read the index data
int numFiles = fPackStream->ReadLE32();
uint32_t streamIndex = (uint32_t)(fPackStreams.size());
for (int i = 0; i < numFiles; i++)
{
// and pack the index into our own data structure
plString pythonName = fPackStream->ReadSafeString();
uint32_t offset = fPackStream->ReadLE32();
plPackOffsetInfo offsetInfo;
offsetInfo.fOffset = offset;
offsetInfo.fStreamIndex = streamIndex;
if (fFileOffsets.find(pythonName) != fFileOffsets.end())
{
uint32_t index = fFileOffsets[pythonName].fStreamIndex;
if (modTimes[index] < curModTime) // is the existing file older then the new one?
fFileOffsets[pythonName] = offsetInfo; // yup, so replace it with the new info
}
else
fFileOffsets[pythonName] = offsetInfo; // no conflicts, add the info
}
fPackStreams.push_back(fPackStream);
}
}
return !fPackNotFound;
}
示例3: IsPackedFile
bool plPythonPack::IsPackedFile(const plString& fileName)
{
if (!Open())
return nil;
plString pythonName = fileName + ".py";
FileOffset:: iterator it = fFileOffsets.find(pythonName);
if (it != fFileOffsets.end())
return true;
return false;
}
示例4: Open
bool plPythonPack::Open()
{
if (fPackStreams.size() > 0)
return true;
// We already tried and it wasn't there
if (fPackNotFound)
return false;
fPackNotFound = true;
// Get the names of all the pak files
std::vector<std::wstring> files = plStreamSource::GetInstance()->GetListOfNames(L"python", L".pak");
std::vector<time_t> modTimes; // the modification time for each of the streams (to resolve duplicate file issues)
// grab all the .pak files in the folder
for (int curName = 0; curName < files.size(); curName++)
{
// obtain the stream
hsStream *fPackStream = plStreamSource::GetInstance()->GetFile(files[curName]);
if (fPackStream)
{
fPackStream->Rewind(); // make sure we're at the beginning of the file
fPackNotFound = false;
char* tempFilename = hsWStringToString(files[curName].c_str());
struct stat buf;
time_t curModTime = 0;
if (stat(tempFilename,&buf)==0)
curModTime = buf.st_mtime;
modTimes.push_back(curModTime);
delete [] tempFilename;
// read the index data
int numFiles = fPackStream->ReadLE32();
uint32_t streamIndex = (uint32_t)(fPackStreams.size());
for (int i = 0; i < numFiles; i++)
{
// and pack the index into our own data structure
char* buf = fPackStream->ReadSafeString();
std::string pythonName = buf; // reading a "string" from a hsStream directly into a stl string causes memory loss
delete [] buf;
uint32_t offset = fPackStream->ReadLE32();
plPackOffsetInfo offsetInfo;
offsetInfo.fOffset = offset;
offsetInfo.fStreamIndex = streamIndex;
if (fFileOffsets.find(pythonName) != fFileOffsets.end())
{
uint32_t index = fFileOffsets[pythonName].fStreamIndex;
if (modTimes[index] < curModTime) // is the existing file older then the new one?
fFileOffsets[pythonName] = offsetInfo; // yup, so replace it with the new info
}
else
fFileOffsets[pythonName] = offsetInfo; // no conflicts, add the info
}
fPackStreams.push_back(fPackStream);
}
}
return !fPackNotFound;
}