本文整理汇总了C++中FileReader::Read方法的典型用法代码示例。如果您正苦于以下问题:C++ FileReader::Read方法的具体用法?C++ FileReader::Read怎么用?C++ FileReader::Read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileReader
的用法示例。
在下文中一共展示了FileReader::Read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadCompressed
void FTGATexture::ReadCompressed(FileReader &lump, BYTE * buffer, int bytesperpixel)
{
BYTE b;
BYTE data[4];
int Size = Width * Height;
while (Size > 0)
{
lump >> b;
if (b & 128)
{
b&=~128;
lump.Read(data, bytesperpixel);
for (int i=MIN<int>(Size, (b+1)); i>0; i--)
{
buffer[0] = data[0];
if (bytesperpixel>=2) buffer[1] = data[1];
if (bytesperpixel>=3) buffer[2] = data[2];
if (bytesperpixel==4) buffer[3] = data[3];
buffer+=bytesperpixel;
}
}
else
{
lump.Read(buffer, MIN<int>(Size, (b+1))*bytesperpixel);
buffer += (b+1)*bytesperpixel;
}
Size -= b+1;
}
}
示例2: if
HMISong::HMISong (FileReader &reader, EMidiDevice type)
: MIDIStreamer(type), MusHeader(0), Tracks(0)
{
#ifdef _WIN32
if (ExitEvent == NULL)
{
return;
}
#endif
int len = reader.GetLength();
if (len < 0x100)
{ // Way too small to be HMI.
return;
}
MusHeader = new BYTE[len];
SongLen = len;
NumTracks = 0;
if (reader.Read(MusHeader, len) != len)
return;
// Do some validation of the MIDI file
if (memcmp(MusHeader, HMI_SONG_MAGIC, sizeof(HMI_SONG_MAGIC)) == 0)
{
SetupForHMI(len);
}
else if (((DWORD *)MusHeader)[0] == MAKE_ID('H','M','I','M') &&
((DWORD *)MusHeader)[1] == MAKE_ID('I','D','I','P'))
{
SetupForHMP(len);
}
}
示例3: MIDIStreamer
XMISong::XMISong (FileReader &reader, EMidiDevice type, const char *args)
: MIDIStreamer(type, args), MusHeader(0), Songs(0)
{
SongLen = reader.GetLength();
MusHeader = new uint8_t[SongLen];
if (reader.Read(MusHeader, SongLen) != SongLen)
return;
// Find all the songs in this file.
NumSongs = FindXMIDforms(MusHeader, SongLen, NULL);
if (NumSongs == 0)
{
return;
}
// XMIDI files are played with a constant 120 Hz clock rate. While the
// song may contain tempo events, these are vestigial remnants from the
// original MIDI file that were not removed by the converter and should
// be ignored.
//
// We can use any combination of Division and Tempo values that work out
// to be 120 Hz.
Division = 60;
InitialTempo = 500000;
Songs = new TrackInfo[NumSongs];
memset(Songs, 0, sizeof(*Songs) * NumSongs);
FindXMIDforms(MusHeader, SongLen, Songs);
CurrSong = Songs;
DPrintf(DMSG_SPAMMY, "XMI song count: %d\n", NumSongs);
}
示例4: FillCache
int FDirectoryLump::FillCache()
{
Cache = new char[LumpSize];
FileReader *reader = NewReader();
reader->Read(Cache, LumpSize);
delete reader;
RefCount = 1;
return 1;
}
示例5: DecompressRead
bool DecompressRead(void *pOutput, size_t outputSize, FileReader &fr)
{
if ( !outputSize )
return false;
char *_pOutput = (char*)pOutput;
memset(bWorkBuff, 0, sizeof(bWorkBuff));
memset(bSegment, 0, sizeof(bSegment));
memset(¶ms, 0, sizeof(params));
_Part hdr = fr.Read<_Part>();
DWORD dwPos = 0;
for ( DWORD s = 0; s < hdr.dwSectionCount; ++s )
{
size_t chunkSize = fr.Read<size_t>();
if ( chunkSize > outputSize )
{
MessageBox(NULL, "ChunkSize > output", 0, 0);
return false;
}
char *pTmp = (char*)malloc(chunkSize);
if ( pTmp != nullptr )
{
fr.Read(pTmp, chunkSize);
if ( chunkSize != outputSize )
{
memset(¶ms, 0, sizeof(params));
params.pCompressedData = pTmp;
params.dwMaxRead = chunkSize;
params.pDecompressedData = bSegment;
params.dwMaxWrite = sizeof(bSegment);
if ( explode(&read_buf, &write_buf, bWorkBuff, ¶ms) )
return false;
if ( params.dwWritePos <= sizeof(bSegment) )
{
memcpy(&_pOutput[dwPos], bSegment, params.dwWritePos);
dwPos += params.dwWritePos;
}
}
else
{
memcpy(&_pOutput[dwPos], pTmp, chunkSize);
dwPos += chunkSize;
}
free(pTmp);
}
}
unsigned int dwSize = outputSize;
unsigned long dwOld = ~0;
return crc32pk((char*)pOutput, &dwSize, &dwOld) == hdr.dwCrc32Sum;
}
示例6: Read
virtual long Read(void *buffer, long len)
{
assert(len >= 0);
if (len <= 0) return 0;
if (FilePos + len > StartPos + Length)
{
len = Length - FilePos + StartPos;
}
len = (long)mReader->Read(buffer, len);
FilePos += len;
return len;
}
示例7: FillCache
int FDirectoryLump::FillCache()
{
FileReader fr;
Cache = new char[LumpSize];
if (!fr.OpenFile(mFullPath))
{
memset(Cache, 0, LumpSize);
return 0;
}
fr.Read(Cache, LumpSize);
RefCount = 1;
return 1;
}
示例8: OpenFile
bool FScanner::OpenFile (const char *name)
{
Close ();
FileReader fr;
if (!fr.OpenFile(name)) return false;
auto filesize = fr.GetLength();
auto filebuff = fr.Read();
if (filebuff.Size() == 0 && filesize > 0) return false;
ScriptBuffer = FString((const char *)filebuff.Data(), filesize);
ScriptName = name; // This is used for error messages so the full file name is preferable
LumpNum = -1;
PrepareScript ();
return true;
}
示例9: SetLumpAddress
void FZipLump::SetLumpAddress()
{
// This file is inside a zip and has not been opened before.
// Position points to the start of the local file header, which we must
// read and skip so that we can get to the actual file data.
FZipLocalFileHeader localHeader;
int skiplen;
FileReader *file = Owner->Reader;
file->Seek(Position, SEEK_SET);
file->Read(&localHeader, sizeof(localHeader));
skiplen = LittleShort(localHeader.NameLength) + LittleShort(localHeader.ExtraLength);
Position += sizeof(localHeader) + skiplen;
Flags &= ~LUMPFZIP_NEEDFILESTART;
}
示例10: Check
bool FPatchTexture::Check(FileReader & file)
{
if (file.GetLength() < 13) return false; // minimum length of a valid Doom patch
BYTE *data = new BYTE[file.GetLength()];
file.Seek(0, SEEK_SET);
file.Read(data, file.GetLength());
const patch_t * foo = (const patch_t *)data;
int height = LittleShort(foo->height);
int width = LittleShort(foo->width);
bool gapAtStart=true;
if (height > 0 && height < 2048 && width > 0 && width <= 2048 && width < file.GetLength()/4)
{
// The dimensions seem like they might be valid for a patch, so
// check the column directory for extra security. At least one
// column must begin exactly at the end of the column directory,
// and none of them must point past the end of the patch.
bool gapAtStart = true;
int x;
for (x = 0; x < width; ++x)
{
DWORD ofs = LittleLong(foo->columnofs[x]);
if (ofs == (DWORD)width * 4 + 8)
{
gapAtStart = false;
}
else if (ofs >= (DWORD)(file.GetLength())) // Need one byte for an empty column (but there's patches that don't know that!)
{
delete [] data;
return false;
}
}
delete [] data;
return !gapAtStart;
}
delete [] data;
return false;
}
示例11: DefaultLogSink
Kumu::Result_t
Kumu::ReadFileIntoString(const std::string& filename, std::string& outString, ui32_t max_size)
{
fsize_t fsize = 0;
ui32_t read_size = 0;
FileReader File;
ByteString ReadBuf;
Result_t result = File.OpenRead(filename);
if ( KM_SUCCESS(result) )
{
fsize = File.Size();
if ( fsize > (Kumu::fpos_t)max_size )
{
DefaultLogSink().Error("%s: exceeds available buffer size (%u)\n", filename.c_str(), max_size);
return RESULT_ALLOC;
}
if ( fsize == 0 )
{
DefaultLogSink().Error("%s: zero file size\n", filename.c_str());
return RESULT_READFAIL;
}
result = ReadBuf.Capacity((ui32_t)fsize);
}
if ( KM_SUCCESS(result) )
result = File.Read(ReadBuf.Data(), ReadBuf.Capacity(), &read_size);
if ( KM_SUCCESS(result) )
outString.assign((const char*)ReadBuf.RoData(), read_size);
return result;
}
示例12: RID
Result_t
ASDCP::TimedText::LocalFilenameResolver::ResolveRID(const byte_t* uuid, TimedText::FrameBuffer& FrameBuf) const
{
Result_t result = RESULT_NOT_FOUND;
char buf[64];
UUID RID(uuid);
PathList_t found_list;
FindInPath(PathMatchRegex(RID.EncodeHex(buf, 64)), m_Dirname, found_list);
if ( found_list.size() == 1 )
{
FileReader Reader;
DefaultLogSink().Debug("retrieving resource %s from file %s\n", buf, found_list.front().c_str());
result = Reader.OpenRead(found_list.front().c_str());
if ( KM_SUCCESS(result) )
{
ui32_t read_count, read_size = Reader.Size();
result = FrameBuf.Capacity(read_size);
if ( KM_SUCCESS(result) )
result = Reader.Read(FrameBuf.Data(), read_size, &read_count);
if ( KM_SUCCESS(result) )
FrameBuf.Size(read_count);
}
}
else if ( ! found_list.empty() )
{
DefaultLogSink().Error("More than one file in %s matches %s.\n", m_Dirname.c_str(), buf);
result = RESULT_RAW_FORMAT;
}
return result;
}
示例13: if
HMISong::HMISong (FileReader &reader)
{
int len = (int)reader.GetLength();
if (len < 0x100)
{ // Way too small to be HMI.
return;
}
MusHeader = new uint8_t[len];
SongLen = len;
NumTracks = 0;
if (reader.Read(MusHeader, len) != len)
return;
// Do some validation of the MIDI file
if (memcmp(MusHeader, HMI_SONG_MAGIC, sizeof(HMI_SONG_MAGIC)) == 0)
{
SetupForHMI(len);
}
else if (((uint32_t *)MusHeader)[0] == MAKE_ID('H','M','I','M') &&
((uint32_t *)MusHeader)[1] == MAKE_ID('I','D','I','P'))
{
SetupForHMP(len);
}
}
示例14: ReadSaveStrings
void FSavegameManager::ReadSaveStrings()
{
if (SaveGames.Size() == 0)
{
void *filefirst;
findstate_t c_file;
FString filter;
LastSaved = LastAccessed = -1;
quickSaveSlot = nullptr;
filter = G_BuildSaveName("*." SAVEGAME_EXT, -1);
filefirst = I_FindFirst(filter.GetChars(), &c_file);
if (filefirst != ((void *)(-1)))
{
do
{
// I_FindName only returns the file's name and not its full path
FString filepath = G_BuildSaveName(I_FindName(&c_file), -1);
FResourceFile *savegame = FResourceFile::OpenResourceFile(filepath, true, true);
if (savegame != nullptr)
{
bool oldVer = false;
bool missing = false;
FResourceLump *info = savegame->FindLump("info.json");
if (info == nullptr)
{
// savegame info not found. This is not a savegame so leave it alone.
delete savegame;
continue;
}
void *data = info->CacheLump();
FSerializer arc(nullptr);
if (arc.OpenReader((const char *)data, info->LumpSize))
{
int savever = 0;
arc("Save Version", savever);
FString engine = arc.GetString("Engine");
FString iwad = arc.GetString("Game WAD");
FString title = arc.GetString("Title");
if (engine.Compare(GAMESIG) != 0 || savever > SAVEVER)
{
// different engine or newer version:
// not our business. Leave it alone.
delete savegame;
continue;
}
if (savever < MINSAVEVER)
{
// old, incompatible savegame. List as not usable.
oldVer = true;
}
else if (iwad.CompareNoCase(Wads.GetWadName(Wads.GetIwadNum())) == 0)
{
missing = !G_CheckSaveGameWads(arc, false);
}
else
{
// different game. Skip this.
delete savegame;
continue;
}
FSaveGameNode *node = new FSaveGameNode;
node->Filename = filepath;
node->bOldVersion = oldVer;
node->bMissingWads = missing;
node->SaveTitle = title;
InsertSaveNode(node);
delete savegame;
}
}
else // check for old formats.
{
FileReader file;
if (file.OpenFile(filepath))
{
PNGHandle *png;
char sig[16];
char title[OLDSAVESTRINGSIZE + 1];
bool oldVer = true;
bool addIt = false;
bool missing = false;
// ZDoom 1.23 betas 21-33 have the savesig first.
// Earlier versions have the savesig second.
// Later versions have the savegame encapsulated inside a PNG.
//
// Old savegame versions are always added to the menu so
// the user can easily delete them if desired.
title[OLDSAVESTRINGSIZE] = 0;
if (nullptr != (png = M_VerifyPNG(file)))
{
char *ver = M_GetPNGText(png, "ZDoom Save Version");
//.........这里部分代码省略.........
示例15: ReadITQ
bool CSoundFile::ReadITQ(FileReader &file, ModLoadingFlags loadFlags)
//------------------------------------------------------------------
{
file.Rewind();
ITFileHeader fileHeader;
if(!file.ReadConvertEndianness(fileHeader)
|| (memcmp(fileHeader.id, "ITQM", 4))
|| fileHeader.insnum > 0xFF
|| fileHeader.smpnum >= MAX_SAMPLES
|| !file.CanRead(fileHeader.ordnum + (fileHeader.insnum + fileHeader.smpnum + fileHeader.patnum) * 4))
{
return false;
} else if(loadFlags == onlyVerifyHeader)
{
return true;
}
InitializeGlobals();
bool interpretModPlugMade = false;
// OpenMPT crap at the end of file
file.Seek(file.GetLength() - 4);
size_t mptStartPos = file.ReadUint32LE();
if(mptStartPos >= file.GetLength() || mptStartPos < 0x100)
{
mptStartPos = file.GetLength();
}
if(!memcmp(fileHeader.id, "tpm.", 4))
{
// Legacy MPTM files (old 1.17.02.xx releases)
ChangeModTypeTo(MOD_TYPE_MPT);
} else
{
if(mptStartPos <= file.GetLength() - 3 && fileHeader.cwtv > 0x888 && fileHeader.cwtv <= 0xFFF)
{
file.Seek(mptStartPos);
ChangeModTypeTo(file.ReadMagic("228") ? MOD_TYPE_MPT : MOD_TYPE_IT);
} else
{
ChangeModTypeTo(MOD_TYPE_IT);
}
if(GetType() == MOD_TYPE_IT)
{
// Which tracker was used to made this?
if((fileHeader.cwtv & 0xF000) == 0x5000)
{
// OpenMPT Version number (Major.Minor)
// This will only be interpreted as "made with ModPlug" (i.e. disable compatible playback etc) if the "reserved" field is set to "OMPT" - else, compatibility was used.
m_dwLastSavedWithVersion = (fileHeader.cwtv & 0x0FFF) << 16;
if(!memcmp(fileHeader.reserved, "OMPT", 4))
interpretModPlugMade = true;
} else if(fileHeader.cmwt == 0x888 || fileHeader.cwtv == 0x888)
{
// OpenMPT 1.17 and 1.18 (raped IT format)
// Exact version number will be determined later.
interpretModPlugMade = true;
} else if(fileHeader.cwtv == 0x0217 && fileHeader.cmwt == 0x0200 && !memcmp(fileHeader.reserved, "\0\0\0\0", 4))
{
if(memchr(fileHeader.chnpan, 0xFF, sizeof(fileHeader.chnpan)) != NULL)
{
// ModPlug Tracker 1.16 (semi-raped IT format)
m_dwLastSavedWithVersion = MAKE_VERSION_NUMERIC(1, 16, 00, 00);
madeWithTracker = "ModPlug tracker 1.09 - 1.16";
} else
{
// OpenMPT 1.17 disguised as this in compatible mode,
// but never writes 0xFF in the pan map for unused channels (which is an invalid value).
m_dwLastSavedWithVersion = MAKE_VERSION_NUMERIC(1, 17, 00, 00);
madeWithTracker = "OpenMPT 1.17 (compatibility export)";
}
interpretModPlugMade = true;
} else if(fileHeader.cwtv == 0x0214 && fileHeader.cmwt == 0x0202 && !memcmp(fileHeader.reserved, "\0\0\0\0", 4))
{
// ModPlug Tracker b3.3 - 1.09, instruments 557 bytes apart
m_dwLastSavedWithVersion = MAKE_VERSION_NUMERIC(1, 09, 00, 00);
madeWithTracker = "ModPlug tracker b3.3 - 1.09";
interpretModPlugMade = true;
}
} else // case: type == MOD_TYPE_MPT
{
if (fileHeader.cwtv >= verMptFileVerLoadLimit)
{
AddToLog(str_LoadingIncompatibleVersion);
return false;
}
else if (fileHeader.cwtv > verMptFileVer)
{
AddToLog(str_LoadingMoreRecentVersion);
}
}
}
if(GetType() == MOD_TYPE_IT) mptStartPos = file.GetLength();
// Read row highlights
if((fileHeader.special & ITFileHeader::embedPatternHighlights))
//.........这里部分代码省略.........