本文整理汇总了C++中common::File::read方法的典型用法代码示例。如果您正苦于以下问题:C++ File::read方法的具体用法?C++ File::read怎么用?C++ File::read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common::File
的用法示例。
在下文中一共展示了File::read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadGamePcFile
void AGOSEngine_PN::loadGamePcFile() {
if (getFileName(GAME_BASEFILE) != NULL) {
Common::File in;
// Read dataBase
if (!in.open(getFileName(GAME_BASEFILE))) {
error("loadGamePcFile: Can't load database file '%s'", getFileName(GAME_BASEFILE));
}
_dataBaseSize = in.size();
_dataBase = (byte *)malloc(_dataBaseSize);
if (_dataBase == NULL)
error("loadGamePcFile: Out of memory for dataBase");
in.read(_dataBase, _dataBaseSize);
if (_dataBase[31] != 0)
error("Later version of system requested");
}
if (getFileName(GAME_TEXTFILE) != NULL) {
Common::File in;
// Read textBase
if (!in.open(getFileName(GAME_TEXTFILE))) {
error("loadGamePcFile: Can't load textbase file '%s'", getFileName(GAME_TEXTFILE));
}
_textBaseSize = in.size();
_textBase = (byte *)malloc(_textBaseSize);
if (_textBase == NULL)
error("loadGamePcFile: Out of memory for textBase");
in.read(_textBase, _textBaseSize);
if (_textBase[getlong(30L)] != 128)
error("Unknown compression format");
}
}
示例2: showCDLogo
bool TeenAgentEngine::showCDLogo() {
Common::File cdlogo;
if (!cdlogo.exists("cdlogo.res") || !cdlogo.open("cdlogo.res"))
return true;
byte bg[0xfa00];
byte palette[3*256];
cdlogo.read(bg, sizeof(bg));
cdlogo.read(palette, sizeof(palette));
for (uint c = 0; c < 3*256; ++c)
palette[c] *= 4;
_system->getPaletteManager()->setPalette(palette, 0, 0x100);
_system->copyRectToScreen(bg, 320, 0, 0, 320, 200);
_system->updateScreen();
for(uint i = 0; i < 20; ++i) {
int r = skipEvents();
if (r != 0)
return r > 0? true: false;
_system->delayMillis(100);
}
cdlogo.close();
return true;
}
示例3: calloc
/**
* This function does noting but load a raw resource into memory,
* if further decoding is required, it must be done by another
* routine. NULL is returned if unsucsessfull.
*/
uint8 *AgiLoader_v2::loadVolRes(struct AgiDir *agid) {
uint8 *data = NULL;
char x[MAXPATHLEN], *path;
Common::File fp;
unsigned int sig;
sprintf(x, "vol.%i", agid->volume);
path = x;
debugC(3, kDebugLevelResources, "Vol res: path = %s", path);
if (agid->offset != _EMPTY && fp.open(path)) {
debugC(3, kDebugLevelResources, "loading resource at offset %d", agid->offset);
fp.seek(agid->offset, SEEK_SET);
fp.read(&x, 5);
if ((sig = READ_BE_UINT16((uint8 *) x)) == 0x1234) {
agid->len = READ_LE_UINT16((uint8 *) x + 3);
data = (uint8 *) calloc(1, agid->len + 32);
if (data != NULL) {
fp.read(data, agid->len);
} else {
exit(1);
}
} else {
warning("AgiLoader_v2::loadVolRes: bad signature %04x", sig);
return 0;
}
fp.close();
} else {
// we have a bad volume resource
// set that resource to NA
agid->offset = _EMPTY;
}
return data;
}
示例4: loadEmergencyFont
// FIXME/TODO: 아래는 코드 중복 모음
void loadEmergencyFont()
{
Common::File fp;
int numChar = 0;
numChar = 2350;
if (fp.open("korean.fnt")) {
fp.seek(2, SEEK_CUR);
_korFontWidth = fp.readByte();
_korFontHeight = fp.readByte();
_korFontPtr = new byte[((_korFontWidth + 7) / 8) * _korFontHeight * numChar];
fp.read(_korFontPtr, ((_korFontWidth + 7) / 8) * _korFontHeight * numChar);
fp.close();
warning("V1 한글 폰트가 로드되었습니다.\n");
} else {
warning("V1 한글 폰트를 로드할 수 없습니다!\n");
}
numChar = 256;
if (fp.open("english.fnt")) {
fp.seek(2, SEEK_CUR);
_engFontWidth = fp.readByte();
_engFontHeight = fp.readByte();
_engFontPtr = new byte[((_engFontWidth + 7) / 8) * _engFontHeight * numChar];
fp.read(_engFontPtr, ((_engFontWidth + 7) / 8) * _engFontHeight * numChar);
fp.close();
warning("V1 영문 폰트가 로드되었습니다.\n");
} else {
warning("V1 영문 폰트를 로드할 수 없습니다!\n");
}
}
示例5: decompressData
void AGOSEngine::decompressData(const char *srcName, byte *dst, uint32 offset, uint32 srcSize, uint32 dstSize) {
#ifdef USE_ZLIB
Common::File in;
in.open(srcName);
if (in.isOpen() == false)
error("decompressData: Can't load %s", srcName);
in.seek(offset, SEEK_SET);
if (srcSize != dstSize) {
byte *srcBuffer = (byte *)malloc(srcSize);
if (in.read(srcBuffer, srcSize) != srcSize)
error("decompressData: Read failed");
unsigned long decompressedSize = dstSize;
if (!Common::uncompress(dst, &decompressedSize, srcBuffer, srcSize))
error("decompressData: Zlib uncompress error");
free(srcBuffer);
} else {
if (in.read(dst, dstSize) != dstSize)
error("decompressData: Read failed");
}
in.close();
#else
error("Zlib support is required for Amiga and Macintosh versions");
#endif
}
示例6: loadMortDat
/**
* Loads the contents of the mort.dat data file
*/
Common::ErrorCode MortevielleEngine::loadMortDat() {
Common::File f;
// Open the mort.dat file
if (!f.open(MORT_DAT)) {
Common::String msg = Common::String::format(_("Unable to locate the '%s' engine data file."), MORT_DAT);
GUIErrorMessage(msg);
return Common::kReadingFailed;
}
// Validate the data file header
char fileId[4];
f.read(fileId, 4);
if (strncmp(fileId, "MORT", 4) != 0) {
Common::String msg = Common::String::format(_("The '%s' engine data file is corrupt."), MORT_DAT);
GUIErrorMessage(msg);
return Common::kReadingFailed;
}
// Check the version
int majVer = f.readByte();
int minVer = f.readByte();
if (majVer < MORT_DAT_REQUIRED_VERSION) {
Common::String msg = Common::String::format(
_("Incorrect version of the '%s' engine data file found. Expected %d.%d but got %d.%d."),
MORT_DAT, MORT_DAT_REQUIRED_VERSION, 0, majVer, minVer);
GUIErrorMessage(msg);
return Common::kReadingFailed;
}
// Loop to load resources from the data file
while (f.pos() < f.size()) {
// Get the Id and size of the next resource
char dataType[4];
int dataSize;
f.read(dataType, 4);
dataSize = f.readUint16LE();
if (!strncmp(dataType, "FONT", 4)) {
// Font resource
_screenSurface->readFontData(f, dataSize);
} else if (!strncmp(dataType, "SSTR", 4)) {
readStaticStrings(f, dataSize, kStaticStrings);
} else if ((!strncmp(dataType, "GSTR", 4)) && (!_txxFileFl)) {
readStaticStrings(f, dataSize, kGameStrings);
} else if (!strncmp(dataType, "VERB", 4)) {
_menu->readVerbNums(f, dataSize);
} else {
// Unknown section
f.skip(dataSize);
}
}
// Close the file
f.close();
assert(_engineStrings.size() > 0);
return Common::kNoError;
}
示例7: showCDLogo
bool TeenAgentEngine::showCDLogo() {
Common::File cdlogo;
if (!cdlogo.exists("cdlogo.res") || !cdlogo.open("cdlogo.res"))
return true;
byte bg[0xfa00];
byte palette[0x400];
cdlogo.read(bg, sizeof(bg));
memset(palette, 0, sizeof(palette));
for(uint c = 0; c < 0x100; ++c) {
uint idx = c * 4;
cdlogo.read(palette + idx, 3);
palette[idx] *= 4;
palette[idx + 1] *= 4;
palette[idx + 2] *= 4;
}
_system->setPalette(palette, 0, 0x100);
_system->copyRectToScreen(bg, 320, 0, 0, 320, 200);
_system->updateScreen();
for(uint i = 0; i < 20; ++i) {
int r = skipEvents();
if (r != 0)
return r > 0? true: false;
_system->delayMillis(100);
}
cdlogo.close();
return true;
}
示例8: SeekableSubReadStream
Common::SeekableReadStream *MADSResourceManager::loadResource(const char *resourceName, bool loadFlag) {
Common::File hagFile;
uint32 offset = 0, size = 0;
// If the first character is a '@' then look for an external file
if (*resourceName == '@') {
++resourceName;
hagFile.open(resourceName);
if (loadFlag)
return hagFile.readStream(hagFile.size());
else
return new Common::SeekableSubReadStream(&hagFile, 0, hagFile.size());
}
// If the first character is the wildcard (resource indicator), skip over it
if (*resourceName == '*')
++resourceName;
char resName[20];
strcpy(resName, resourceName);
str_upper(resName);
hagFile.open(getResourceFilename(resName));
// Validate hag file header
char headerBuffer[16];
if ((hagFile.read(headerBuffer, 16) != 16) || (strncmp(headerBuffer, madsConcatString, 10) != 0))
error("Invalid HAG file opened");
int numEntries = hagFile.readUint16LE();
int resIndex = -1;
while (++resIndex < numEntries) {
// Read in the details of the next resource
char resourceBuffer[14];
offset = hagFile.readUint32LE();
size = hagFile.readUint32LE();
hagFile.read(resourceBuffer, 14);
if (!strcmp(resName, resourceBuffer))
break;
}
if (resIndex == numEntries)
error("Invalid resource '%s' specified", resourceName);
// Get the resource, either loading it in it's entirely or getting a stream reference
if (loadFlag) {
hagFile.seek(offset);
return hagFile.readStream(size);
} else {
return new Common::SeekableSubReadStream(&hagFile, offset, offset + size);
}
}
示例9: loadMortDat
/**
* Loads the contents of the mort.dat data file
*/
Common::ErrorCode MortevielleEngine::loadMortDat() {
Common::File f;
// Open the mort.dat file
if (!f.open(MORT_DAT)) {
GUIErrorMessage("Could not locate 'mort.dat'.");
return Common::kReadingFailed;
}
// Validate the data file header
char fileId[4];
f.read(fileId, 4);
if (strncmp(fileId, "MORT", 4) != 0) {
GUIErrorMessage("The located mort.dat data file is invalid");
return Common::kReadingFailed;
}
// Check the version
if (f.readByte() < MORT_DAT_REQUIRED_VERSION) {
GUIErrorMessage("The located mort.dat data file is too old, please download an updated version on scummvm.org");
return Common::kReadingFailed;
}
f.readByte(); // Minor version
// Loop to load resources from the data file
while (f.pos() < f.size()) {
// Get the Id and size of the next resource
char dataType[4];
int dataSize;
f.read(dataType, 4);
dataSize = f.readUint16LE();
if (!strncmp(dataType, "FONT", 4)) {
// Font resource
_screenSurface.readFontData(f, dataSize);
} else if (!strncmp(dataType, "SSTR", 4)) {
readStaticStrings(f, dataSize, kStaticStrings);
} else if ((!strncmp(dataType, "GSTR", 4)) && (!_txxFileFl)) {
readStaticStrings(f, dataSize, kGameStrings);
} else if (!strncmp(dataType, "VERB", 4)) {
_menu.readVerbNums(f, dataSize);
} else {
// Unknown section
f.skip(dataSize);
}
}
// Close the file
f.close();
assert(_engineStrings.size() > 0);
return Common::kNoError;
}
示例10: setAGIPal
//Gets AGIPAL Data
void GfxMgr::setAGIPal(int p0) {
//If 0 from savefile, do not use
if (p0 == 0)
return;
char filename[15];
sprintf(filename, "pal.%d", p0);
Common::File agipal;
if (!agipal.open(filename)) {
warning("Couldn't open AGIPAL palette file '%s'. Not changing palette", filename);
return; // Needed at least by Naturette 3 which uses AGIPAL but provides no palette files
}
//Chunk0 holds colors 0-7
agipal.read(&_agipalPalette[0], 24);
//Chunk1 is the same as the chunk0
//Chunk2 chunk holds colors 8-15
agipal.seek(24, SEEK_CUR);
agipal.read(&_agipalPalette[24], 24);
//Chunk3 is the same as the chunk2
//Chunks4-7 are duplicates of chunks0-3
if (agipal.eos() || agipal.err()) {
warning("Couldn't read AGIPAL palette from '%s'. Not changing palette", filename);
return;
}
// Use only the lowest 6 bits of each color component (Red, Green and Blue)
// because VGA used only 6 bits per color component (i.e. VGA had 18-bit colors).
// This should now be identical to the original AGIPAL-hack's behavior.
bool validVgaPalette = true;
for (int i = 0; i < 16 * 3; i++) {
if (_agipalPalette[i] >= (1 << 6)) {
_agipalPalette[i] &= 0x3F; // Leave only the lowest 6 bits of each color component
validVgaPalette = false;
}
}
if (!validVgaPalette)
warning("Invalid AGIPAL palette (Over 6 bits per color component) in '%s'. Using only the lowest 6 bits per color component", filename);
_agipalFileNum = p0;
initPalette(_agipalPalette);
gfxSetPalette();
debug(1, "Using AGIPAL palette from '%s'", filename);
}
示例11: loadNoise
/**
* Speech function - Load Noise file
* @remarks Originally called 'charge_bruit'
*/
void SpeechManager::loadNoise() {
Common::File f;
if (!f.open("bruits")) //Translation: "noise"
error("Missing file - bruits");
f.read(&_vm->_mem[kAdrNoise * 16], 250 * 128); // 32000
for (int i = 0; i < _noise5Size; ++i)
_vm->_mem[(kAdrNoise * 16) + 32000 + i] = _noise5Buf[i];
f.read(&_vm->_mem[(kAdrNoise1 * 16) + kOffsetB1], 149 * 128); // 19072
f.close();
}
示例12: readBootFile
/**
* Reads boot file for program environment. Fatal error if not there or
* file checksum is bad. De-crypts structure while checking checksum
*/
void FileManager::readBootFile() {
debugC(1, kDebugFile, "readBootFile()");
Common::File ofp;
if (!ofp.open(getBootFilename())) {
if (_vm->_gameVariant == kGameVariantH1Dos) {
//TODO initialize properly _boot structure
warning("readBootFile - Skipping as H1 Dos may be a freeware");
memset(_vm->_boot._distrib, '\0', sizeof(_vm->_boot._distrib));
_vm->_boot._registered = kRegFreeware;
return;
} else if (_vm->getPlatform() == Common::kPlatformPC) {
warning("readBootFile - Skipping as H2 and H3 Dos may be shareware");
memset(_vm->_boot._distrib, '\0', sizeof(_vm->_boot._distrib));
_vm->_boot._registered = kRegShareware;
return;
} else {
Utils::notifyBox(Common::String::format("Missing startup file '%s'", getBootFilename()));
_vm->getGameStatus()._doQuitFl = true;
return;
}
}
if (ofp.size() < (int32)sizeof(_vm->_boot)) {
Utils::notifyBox(Common::String::format("Corrupted startup file '%s'", getBootFilename()));
_vm->getGameStatus()._doQuitFl = true;
return;
}
_vm->_boot._checksum = ofp.readByte();
_vm->_boot._registered = ofp.readByte();
ofp.read(_vm->_boot._pbswitch, sizeof(_vm->_boot._pbswitch));
ofp.read(_vm->_boot._distrib, sizeof(_vm->_boot._distrib));
_vm->_boot._exitLen = ofp.readUint16LE();
byte *p = (byte *)&_vm->_boot;
byte checksum = 0;
for (uint32 i = 0; i < sizeof(_vm->_boot); i++) {
checksum ^= p[i];
p[i] ^= s_bootCypher[i % s_bootCypherLen];
}
ofp.close();
if (checksum) {
Utils::notifyBox(Common::String::format("Corrupted startup file '%s'", getBootFilename()));
_vm->getGameStatus()._doQuitFl = true;
}
}
示例13:
byte *Sword2Engine::fetchPsxBackground(uint32 location) {
Common::File file;
PSXScreensEntry header;
uint32 screenOffset, dataOffset;
uint32 totSize; // Total size of background, counting data, offset table and additional header
byte *buffer;
if (!file.open("screens.clu")) {
GUIErrorMessage("Broken Sword 2: Cannot open screens.clu");
return NULL;
}
file.seek(location * 4, SEEK_SET);
screenOffset = file.readUint32LE();
if (screenOffset == 0) { // We don't have screen data for this location number.
file.close();
return NULL;
}
// Get to the beginning of PSXScreensEntry
file.seek(screenOffset + ResHeader::size(), SEEK_SET);
buffer = (byte *)malloc(PSXScreensEntry::size());
file.read(buffer, PSXScreensEntry::size());
// Prepare the header
header.read(buffer);
free(buffer);
file.seek(screenOffset + header.bgOffset + 4, SEEK_SET);
dataOffset = file.readUint32LE();
file.seek(screenOffset + header.bgOffset, SEEK_SET);
totSize = header.bgSize + (dataOffset - header.bgOffset) + 8;
buffer = (byte *)malloc(totSize);
// Write some informations before background data
WRITE_LE_UINT16(buffer, header.bgXres);
WRITE_LE_UINT16(buffer + 2, header.bgYres);
WRITE_LE_UINT32(buffer + 4, header.bgOffset);
file.read(buffer + 8, totSize - 8); // Do not write on the header
file.close();
return buffer;
}
示例14: loadWords
int AgiEngine::loadWords(const char *fname) {
Common::File fp;
uint32 flen;
uint8 *mem = NULL;
words = NULL;
if (!fp.open(fname)) {
warning("loadWords: can't open %s", fname);
return errOK; // err_BadFileOpen
}
debug(0, "Loading dictionary: %s", fname);
fp.seek(0, SEEK_END);
flen = fp.pos();
wordsFlen = flen;
fp.seek(0, SEEK_SET);
if ((mem = (uint8 *)calloc(1, flen + 32)) == NULL) {
fp.close();
return errNotEnoughMemory;
}
fp.read(mem, flen);
fp.close();
words = mem;
return errOK;
}
示例15: printBootText
/**
* Read the encrypted text from the boot file and print it
*/
void FileManager::printBootText() {
debugC(1, kDebugFile, "printBootText()");
Common::File ofp;
if (!ofp.open(getBootFilename())) {
if (_vm->_gameVariant == kGameVariantH1Dos) {
//TODO initialize properly _boot structure
warning("printBootText - Skipping as H1 Dos may be a freeware");
return;
} else {
error("Missing startup file '%s'", getBootFilename());
}
}
// Allocate space for the text and print it
char *buf = (char *)malloc(_vm->_boot.exit_len + 1);
if (buf) {
// Skip over the boot structure (already read) and read exit text
ofp.seek((long)sizeof(_vm->_boot), SEEK_SET);
if (ofp.read(buf, _vm->_boot.exit_len) != (size_t)_vm->_boot.exit_len)
error("Error while reading startup file");
// Decrypt the exit text, using CRYPT substring
int i;
for (i = 0; i < _vm->_boot.exit_len; i++)
buf[i] ^= s_bootCyper[i % s_bootCyperLen];
buf[i] = '\0';
Utils::notifyBox(buf);
}
free(buf);
ofp.close();
}