本文整理汇总了C++中BinaryFile类的典型用法代码示例。如果您正苦于以下问题:C++ BinaryFile类的具体用法?C++ BinaryFile怎么用?C++ BinaryFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BinaryFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkFile
Loader::LoaderVersion Loader::checkFile(std::string f) {
BinaryFile file;
if (file.open(f.c_str()) != 0)
return TR_UNKNOWN;
uint32_t start = file.readU32();
switch (start) {
case 0x00000020:
return TR_1;
case 0x0000002D:
return TR_2;
case 0xFF080038:
case 0xFF180038:
return TR_3;
case 0xFFFFFFF0: // bogus
case 0x00345254: // "TR4\0"
return TR_4;
}
Log::get(LOG_ERROR) << "Unknown TR level version: \"" << start << "\"" << Log::endl;
return TR_UNKNOWN;
}
示例2: ValidateFile
bool SavedFile::ValidateFile(BinaryFile& file, unsigned int signature_length, const char* signature, unsigned short version)
{
char read_signature[32];
file.ReadRawData(read_signature, signature_length);
// Signatur überprüfen
if(memcmp(read_signature, signature, signature_length) != 0)
{
// unterscheiden sich! --> raus
LOG.lprintf("Error: File is not in a valid format! File path: %s\n", file.getFilePath().c_str());
return false;
}
// Programmversion überspringen
file.Seek(8, SEEK_CUR);
// Version überprüfen
unsigned short read_version = file.ReadUnsignedShort();
if(read_version != version)
{
// anderes Dateiformat --> raus
LOG.lprintf("Warning: File has an old version and cannot be used (version: %u; expected: %u, file path: %s)!\n", read_version, version, file.getFilePath().c_str());
return false;
}
return true;
}
示例3: MovingPlatform
void MapReader1700::read_platforms(CMap& map, BinaryFile& mapfile, bool fPreview)
{
map.clearPlatforms();
//Load moving platforms
map.iNumPlatforms = (short)mapfile.read_i32();
map.platforms = new MovingPlatform*[map.iNumPlatforms];
for (short iPlatform = 0; iPlatform < map.iNumPlatforms; iPlatform++) {
short iWidth = (short)mapfile.read_i32();
short iHeight = (short)mapfile.read_i32();
TilesetTile ** tiles = new TilesetTile*[iWidth];
MapTile ** types = new MapTile*[iWidth];
read_platform_tiles(map, mapfile, iWidth, iHeight, tiles, types);
short iDrawLayer = 2;
//printf("Layer: %d\n", iDrawLayer);
short iPathType = 0;
//printf("PathType: %d\n", iPathType);
MovingPlatformPath* path = NULL;
path = read_platform_path_details(mapfile, iPathType, fPreview);
if (!path)
continue;
MovingPlatform * platform = new MovingPlatform(tiles, types, iWidth, iHeight, iDrawLayer, path, fPreview);
map.platforms[iPlatform] = platform;
map.platformdrawlayer[iDrawLayer].push_back(platform);
}
}
示例4: index
void index(const tstring& sDir)
{
IndexWriterPtr pIndexWriter = m_pIndex->acquireWriter();
DirectoryIterator di(sDir, false);
while(di.hasNext())
{
const File& f = di.next();
if(f.isFile())
{
BinaryFile bf;
bf.open(f.getPath().c_str(), BinaryFile::READ);
if(bf.isFileOpen())
{
size_t nRead = (size_t)bf.getLength();
if (nRead > 0)
{
DocumentPtr pDoc = new Document(pIndexWriter->getDocSchema());
pDoc->addField(0, f.getPath().c_str());
char* buf = new char[nRead + 1];
bf.read(buf, nRead);
buf[nRead] = 0;
pDoc->addField(1, buf, nRead, false);
delete[] buf;
pIndexWriter->addDocument(pDoc);
}
}
}
}
docPool.commit();
pIndexWriter->close();
}
示例5: expFuncRead
ExpressionValue expFuncRead(const std::vector<ExpressionValue>& parameters)
{
ExpressionValue result;
T buffer;
if (parameters[0].isString() == false || (parameters.size() >= 2 && parameters[1].isInt() == false))
{
Logger::queueError(Logger::Error,L"Invalid parameter");
return result;
}
std::wstring fileName = getFullPathName(parameters[0].strValue);
u64 pos = parameters.size() >= 2 ? parameters[1].intValue : 0;
BinaryFile file;
if (file.open(fileName,BinaryFile::Read) == false)
{
Logger::queueError(Logger::Error,L"Could not open %s",fileName);
return result;
}
file.setPos((long)pos);
if (file.read(&buffer,sizeof(T)) == sizeof(T))
{
result.type = ExpressionValueType::Integer;
result.intValue = (u64) buffer;
}
return result;
}
示例6: switch
BaseFile* FileInterface::OpenFile(const char* szFilename, EFileType eType, EFileFlags eFlags)
{
switch(eType)
{
case BINARY_FILE:
{
BinaryFile* pFile = new BinaryFile;
if(pFile)
{
GEN_RESULT res = pFile->Open(szFilename, eFlags);
if(RESULT_OK == res)
{
return (BaseFile*)pFile;
}
}
}
break;
case TEXT_FILE:
{
//TODO:
}
break;
default:
break;
}
return NULL;
}
示例7:
void MapReader1700::read_warp_locations(CMap& map, BinaryFile& mapfile)
{
for (unsigned short j = 0; j < MAPHEIGHT; j++) {
for (unsigned short i = 0; i < MAPWIDTH; i++) {
TileType iType = (TileType)mapfile.read_i32();
if (iType >= 0 && iType < NUMTILETYPES) {
map.mapdatatop[i][j].iType = iType;
map.mapdatatop[i][j].iFlags = g_iTileTypeConversion[iType];
} else {
map.mapdatatop[i][j].iType = tile_nonsolid;
map.mapdatatop[i][j].iFlags = tile_flag_nonsolid;
}
map.warpdata[i][j].direction = (WarpEnterDirection)mapfile.read_i32();
map.warpdata[i][j].connection = (short)mapfile.read_i32();
map.warpdata[i][j].id = (short)mapfile.read_i32();
for (short sType = 0; sType < 6; sType += 5)
map.nospawn[sType][i][j] = mapfile.read_i32() == 0 ? false : true;
//Copy player no spawn areas into team no spawn areas
for (short sType = 1; sType < 5; sType++)
map.nospawn[sType][i][j] = map.nospawn[0][i][j];
}
}
}
示例8: testPentiumLoad
/*==============================================================================
* FUNCTION: LoaderTest::testPentiumLoad
* OVERVIEW: Test loading the pentium (Solaris) hello world program
*============================================================================*/
void LoaderTest::testPentiumLoad ()
{
std::ostringstream ost;
// Load Pentium hello world
BinaryFileFactory bff;
BinaryFile* pBF = bff.Load(HELLO_PENTIUM);
CPPUNIT_ASSERT(pBF != NULL);
int n;
SectionInfo* si;
n = pBF->GetNumSections();
ost << "Number of sections = " << std::dec << n << "\r\n\t";
si = pBF->GetSectionInfo(1);
ost << si->pSectionName << "\t";
si = pBF->GetSectionInfo(n-1);
ost << si->pSectionName;
pBF->UnLoad();
// Note: the string below needs to have embedded tabs. Edit with caution!
// (And slightly different string to the sparc test, e.g. rel vs rela)
std::string expected("Number of sections = 34\r\n\t"
".interp .strtab");
CPPUNIT_ASSERT_EQUAL(expected, ost.str());
bff.UnLoad();
}
示例9: expFuncRead
ExpressionValue expFuncRead(const std::wstring& funcName, const std::vector<ExpressionValue>& parameters)
{
const std::wstring* fileName;
u64 pos;
GET_PARAM(parameters,0,fileName);
GET_OPTIONAL_PARAM(parameters,1,pos,0);
std::wstring fullName = getFullPathName(*fileName);
BinaryFile file;
if (file.open(fullName,BinaryFile::Read) == false)
{
Logger::queueError(Logger::Error,L"Could not open %s",fileName);
return ExpressionValue();
}
file.setPos((long)pos);
T buffer;
if (file.read(&buffer,sizeof(T)) != sizeof(T))
return ExpressionValue();
return ExpressionValue((u64) buffer);
}
示例10: testPalmLoad
/*==============================================================================
* FUNCTION: LoaderTest::testPalmLoad
* OVERVIEW: Test loading the Palm 68328 Starter.prc program
*============================================================================*/
void LoaderTest::testPalmLoad ()
{
std::ostringstream ost;
// Load Palm Starter.prc
BinaryFileFactory bff;
BinaryFile* pBF = bff.Load(STARTER_PALM);
CPPUNIT_ASSERT(pBF != NULL);
int n;
SectionInfo* si;
n = pBF->GetNumSections();
ost << "Number of sections = " << std::dec << n << "\r\n";
for (int i=0; i < n; i++)
{
si = pBF->GetSectionInfo(i);
ost << si->pSectionName << "\t";
}
pBF->UnLoad();
// Note: the string below needs to have embedded tabs. Edit with caution!
std::string expected("Number of sections = 8\r\n"
"code1 MBAR1000 tFRM1000 Talt1001 "
"data0 code0 tAIN1000 tver1000 ");
CPPUNIT_ASSERT_EQUAL(expected, ost.str());
bff.UnLoad();
}
示例11:
void MapReader1800::read_tiles(CMap& map, BinaryFile& mapfile)
{
//2. load map data
unsigned short i, j, k;
for (j = 0; j < MAPHEIGHT; j++) {
for (i = 0; i < MAPWIDTH; i++) {
for (k = 0; k < MAPLAYERS; k++) {
TilesetTile * tile = &map.mapdata[i][j][k];
tile->iID = mapfile.read_i8();
tile->iCol = mapfile.read_i8();
tile->iRow = mapfile.read_i8();
if (tile->iID >= 0) {
if (tile->iID > iMaxTilesetID)
tile->iID = 0;
//Make sure the column and row we read in is within the bounds of the tileset
if (tile->iCol < 0 || tile->iCol >= tilesetwidths[tile->iID])
tile->iCol = 0;
if (tile->iRow < 0 || tile->iRow >= tilesetheights[tile->iID])
tile->iRow = 0;
//Convert tileset ids into the current game's tileset's ids
tile->iID = translationid[tile->iID];
}
}
map.objectdata[i][j].iType = mapfile.read_i8();
map.objectdata[i][j].fHidden = mapfile.read_bool();
}
}
}
示例12: ValidateFile
/**
*
* @author OLiver
*/
bool SavedFile::ValidateFile(BinaryFile& file, unsigned int signature_length, const char* signature, unsigned short version)
{
char read_signature[32];
file.ReadRawData(read_signature, signature_length);
// Signatur überprüfen
if(memcmp(read_signature, signature, signature_length))
{
// unterscheiden sich! --> raus
LOG.lprintf("SavedFile::Load: ERROR: Not a valid file!\n");
return false;
}
// Programmversion überspringen
file.Seek(8, SEEK_CUR);
// Version überprüfen
unsigned short read_version = file.ReadUnsignedShort();
if(read_version != version)
{
// anderes Dateiformat --> raus
LOG.lprintf("SavedFile::Load: ERROR: Old file version (version: %u; expected: %u)!\n", read_version, version);
return false;
}
return true;
}
示例13: WriteGGS
/**
* schreibt die GlobalGameSettings in die Datei.
*
* @author OLiver
*/
void SavedFile::WriteGGS(BinaryFile& file)
{
Serializer ser;
ggs.Serialize(&ser);
file.WriteUnsignedInt(ser.GetLength());
file.WriteRawData(ser.GetData(), ser.GetLength());
}
示例14: print
void XMLDocumentWrapper::printToFile(std::string& sFile)
{
ostringstream os;
print(os);
BinaryFile bf;
bf.open(sFile, BinaryFile::CREATE);
bf.write(os.str().c_str(), os.str().length());
}
示例15: ReadGGS
/**
* liest die GlobalGameSettings aus der Datei.
*
* @author OLiver
*/
void SavedFile::ReadGGS(BinaryFile& file)
{
unsigned length = file.ReadUnsignedInt();
boost::interprocess::unique_ptr<unsigned char, Deleter<unsigned char[]> > buffer(new unsigned char[length]);
file.ReadRawData(buffer.get(), length);
Serializer ser(buffer.get(), length);
ggs.Deserialize(ser);
}