本文整理汇总了C++中common::File::open方法的典型用法代码示例。如果您正苦于以下问题:C++ File::open方法的具体用法?C++ File::open怎么用?C++ File::open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common::File
的用法示例。
在下文中一共展示了File::open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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 {
error("Missing startup file '%s'", getBootFilename());
}
}
if (ofp.size() < (int32)sizeof(_vm->_boot))
error("Corrupted startup file");
_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.exit_len = 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_bootCyper[i % s_bootCyperLen];
}
ofp.close();
if (checksum)
error("Corrupted startup file");
}
示例2: getSound
/**
* Read sound (or music) file data. Call with SILENCE to free-up
* any allocated memory. Also returns size of data
*/
sound_pt FileManager::getSound(const int16 sound, uint16 *size) {
debugC(1, kDebugFile, "getSound(%d)", sound);
// No more to do if SILENCE (called for cleanup purposes)
if (sound == _vm->_soundSilence)
return 0;
// Open sounds file
Common::File fp; // Handle to SOUND_FILE
if (!fp.open(getSoundFilename())) {
warning("Hugo Error: File not found %s", getSoundFilename());
return 0;
}
if (!has_read_header) {
if (fp.read(s_hdr, sizeof(s_hdr)) != sizeof(s_hdr))
error("Wrong sound file format");
has_read_header = true;
}
*size = s_hdr[sound].size;
if (*size == 0)
error("Wrong sound file format or missing sound %d", sound);
// Allocate memory for sound or music, if possible
sound_pt soundPtr = (byte *)malloc(s_hdr[sound].size); // Ptr to sound data
assert(soundPtr);
// Seek to data and read it
fp.seek(s_hdr[sound].offset, SEEK_SET);
if (fp.read(soundPtr, s_hdr[sound].size) != s_hdr[sound].size)
error("Wrong sound file format");
fp.close();
return soundPtr;
}
示例3: createVideoHandle
VideoHandle VideoManager::createVideoHandle(const Common::String &filename, uint16 x, uint16 y, bool loop, byte volume) {
// First, check to see if that video is already playing
for (uint32 i = 0; i < _videoStreams.size(); i++)
if (_videoStreams[i].filename == filename)
return i;
// Otherwise, create a new entry
VideoEntry entry;
entry.clear();
entry.video = new Video::QuickTimeDecoder();
entry.x = x;
entry.y = y;
entry.filename = filename;
entry.loop = loop;
entry.enabled = true;
Common::File *file = new Common::File();
if (!file->open(filename)) {
delete file;
return NULL_VID_HANDLE;
}
entry->loadStream(file);
entry->setVolume(volume);
entry->start();
// Search for any deleted videos so we can take a formerly used slot
for (uint32 i = 0; i < _videoStreams.size(); i++)
if (!_videoStreams[i].video) {
_videoStreams[i] = entry;
return i;
}
// Otherwise, just add it to the list
_videoStreams.push_back(entry);
return _videoStreams.size() - 1;
}
示例4: if
Common::SeekableReadStream *SaveManager::getSlotFile(uint slot) {
Common::SeekableReadStream *saveFile = g_system->getSavefileManager()->openForLoading(_engine->generateSaveFileName(slot));
if (saveFile == NULL) {
// Try to load standard save file
Common::String filename;
if (_engine->getGameId() == GID_GRANDINQUISITOR)
filename = Common::String::format("inqsav%u.sav", slot);
else if (_engine->getGameId() == GID_NEMESIS)
filename = Common::String::format("nemsav%u.sav", slot);
saveFile = _engine->getSearchManager()->openFile(filename);
if (saveFile == NULL) {
Common::File *tmpFile = new Common::File;
if (!tmpFile->open(filename)) {
delete tmpFile;
} else {
saveFile = tmpFile;
}
}
}
return saveFile;
}
示例5: loadClut
bool GfxPalette::loadClut(uint16 clutId) {
// loadClut() will load a color lookup table from a clu file and set
// the palette found in the file. This is to be used with Phantasmagoria 2.
unloadClut();
Common::String filename = Common::String::format("%d.clu", clutId);
Common::File clut;
if (!clut.open(filename) || clut.size() != 0x10000 + 236 * 3)
return false;
// Read in the lookup table
// It maps each RGB565 color to a palette index
_clutTable = new byte[0x10000];
clut.read(_clutTable, 0x10000);
Palette pal;
memset(&pal, 0, sizeof(Palette));
// Setup 1:1 mapping
for (int i = 0; i < 256; i++)
pal.mapping[i] = i;
// Now load in the palette
for (int i = 1; i <= 236; i++) {
pal.colors[i].used = 1;
pal.colors[i].r = clut.readByte();
pal.colors[i].g = clut.readByte();
pal.colors[i].b = clut.readByte();
}
set(&pal, true);
setOnScreen();
return true;
}
示例6: setAmiga
// Will try to set amiga palette by using "spal" file. If not found, we return false
bool GfxPalette::setAmiga() {
Common::File file;
if (file.open("spal")) {
for (int curColor = 0; curColor < 32; curColor++) {
byte byte1 = file.readByte();
byte byte2 = file.readByte();
if (file.eos())
error("Amiga palette file ends prematurely");
_sysPalette.colors[curColor].used = 1;
_sysPalette.colors[curColor].r = (byte1 & 0x0F) * 0x11;
_sysPalette.colors[curColor].g = ((byte2 & 0xF0) >> 4) * 0x11;
_sysPalette.colors[curColor].b = (byte2 & 0x0F) * 0x11;
}
// Directly set the palette, because setOnScreen() wont do a thing for amiga
copySysPaletteToScreen();
return true;
}
return false;
}
示例7: version
bool MD5Check::advanceCheck(int *pos, int *total) {
if (_iterator < 0) {
return false;
}
const MD5Sum &sum = (*_files)[_iterator++];
if (pos) {
*pos = _iterator;
}
if (total) {
*total = _files->size();
}
if ((uint32)_iterator == _files->size()) {
_iterator = -1;
}
Common::File file;
if (file.open(sum.filename)) {
Common::String md5 = Common::computeStreamMD5AsString(file);
if (!checkMD5(sum, md5.c_str())) {
warning("'%s' may be corrupted. MD5: '%s'", sum.filename, md5.c_str());
GUI::displayErrorDialog(Common::String::format("The game data file %s may be corrupted.\nIf you are sure it is "
"not please provide the ResidualVM team the following code, along with the file name, the language and a "
"description of your game version (i.e. dvd-box or jewelcase):\n%s", sum.filename, md5.c_str()).c_str());
return false;
}
} else {
warning("Could not open %s for checking", sum.filename);
GUI::displayErrorDialog(Common::String::format("Could not open the file %s for checking.\nIt may be missing or "
"you may not have the rights to open it.\nGo to http://wiki.residualvm.org/index.php/Datafiles to see a list "
"of the needed files.", sum.filename).c_str());
return false;
}
return true;
}
示例8: convertRawToWav
void convertRawToWav(const Common::String &inputFile, ZVision *engine, const Common::String &outputFile) {
Common::File file;
if (!file.open(inputFile))
return;
Audio::AudioStream *audioStream = makeRawZorkStream(inputFile, engine);
Common::DumpFile output;
output.open(outputFile);
output.writeUint32BE(MKTAG('R', 'I', 'F', 'F'));
output.writeUint32LE(file.size() * 2 + 36);
output.writeUint32BE(MKTAG('W', 'A', 'V', 'E'));
output.writeUint32BE(MKTAG('f', 'm', 't', ' '));
output.writeUint32LE(16);
output.writeUint16LE(1);
uint16 numChannels;
if (audioStream->isStereo()) {
numChannels = 2;
output.writeUint16LE(2);
} else {
numChannels = 1;
output.writeUint16LE(1);
}
output.writeUint32LE(audioStream->getRate());
output.writeUint32LE(audioStream->getRate() * numChannels * 2);
output.writeUint16LE(numChannels * 2);
output.writeUint16LE(16);
output.writeUint32BE(MKTAG('d', 'a', 't', 'a'));
output.writeUint32LE(file.size() * 2);
int16 *buffer = new int16[file.size()];
audioStream->readBuffer(buffer, file.size());
output.write(buffer, file.size() * 2);
delete[] buffer;
}
示例9: draw
/**
* Draw background animation
* @remarks Originally called 'show_one'
*/
void Background::draw(int16 destX, int16 destY, byte sprId) {
assert(sprId < 40);
if (_sprites[sprId]._x > kOnDisk) {
if (destX < 0) {
destX = _sprites[sprId]._x * 8;
destY = _sprites[sprId]._y;
}
drawSprite(destX, destY, _sprites[sprId]);
} else {
Common::File f;
if (!f.open(_filename)) // Filename was set in loadBackgroundSprites().
return; // We skip because some rooms don't have sprites in the background.
f.seek(_offsets[sprId]);
SpriteType sprite;
sprite._type = (PictureType)(f.readByte());
sprite._x = f.readSint16LE();
sprite._y = f.readSint16LE();
sprite._width = f.readSint16LE();
sprite._height = f.readSint16LE();
sprite._size = f.readSint32LE();
f.skip(2); // Natural and Memorize are used in Load()
sprite._picture = _vm->_graphics->loadPictureRaw(f, sprite._width * 8, sprite._height + 1);
if (destX < 0) {
destX = sprite._x * 8;
destY = sprite._y;
}
drawSprite(destX, destY, sprite);
sprite._picture.free();
f.close();
}
}
示例10: sizeof
BaseSound::BaseSound(Audio::Mixer *mixer, const Common::String &filename, uint32 base, bool bigEndian)
: _mixer(mixer), _filename(filename), _offsets(NULL) {
uint res = 0;
uint32 size;
Common::File file;
if (!file.open(_filename))
error("BaseSound: Could not open file \"%s\"", filename.c_str());
file.seek(base + sizeof(uint32), SEEK_SET);
if (bigEndian)
size = file.readUint32BE();
else
size = file.readUint32LE();
// The Feeble Files uses set amount of voice offsets
if (size == 0)
size = 40000;
res = size / sizeof(uint32);
_offsets = (uint32 *)malloc(size + sizeof(uint32));
_freeOffsets = true;
file.seek(base, SEEK_SET);
for (uint i = 0; i < res; i++) {
if (bigEndian)
_offsets[i] = base + file.readUint32BE();
else
_offsets[i] = base + file.readUint32LE();
}
_offsets[res] = file.size();
}
示例11: load
void GameModule::load(const char *filename) {
debug(0, "GameModule::load()");
unload();
Common::File fd;
if (!fd.open(filename))
error("GameModule::load() Could not open %s", filename);
loadBgSprites(fd);
loadCameraInits(fd);
loadWalkRects(fd);
loadSceneExits(fd);
loadBgObjects(fd);
loadAnimations(fd);
loadSceneObjectDefs(fd);
loadSceneObjectInits(fd);
loadActions(fd);
loadGuiSpriteIndices(fd);
loadInventoryItemSpriteIndices(fd);
loadInventoryItemInfos(fd);
loadDialogItemSpriteIndices(fd);
loadSceneSounds(fd);
loadPreloadSounds(fd);
fd.seek(0xC);
_fieldC = fd.readUint32LE();
fd.seek(0x1A8);
_buttheadObjectIndex = fd.readUint32LE();
fd.close();
debug(0, "GameModule::load() OK");
}
示例12: MemoryReadStream
Common::SeekableReadStream *InstallShieldCabinet::createReadStreamForMember(const Common::String &name) const {
if (!_map.contains(name))
return 0;
const FileEntry &entry = _map[name];
Common::File archiveFile;
archiveFile.open(_installShieldFilename);
archiveFile.seek(entry.offset);
if (!(entry.flags & 0x04)) {
// Not compressed
return archiveFile.readStream(entry.uncompressedSize);
}
#ifdef USE_ZLIB
byte *src = (byte *)malloc(entry.compressedSize);
byte *dst = (byte *)malloc(entry.uncompressedSize);
archiveFile.read(src, entry.compressedSize);
bool result = Common::inflateZlibHeaderless(dst, entry.uncompressedSize, src, entry.compressedSize);
free(src);
if (!result) {
warning("failed to inflate CAB file '%s'", name.c_str());
free(dst);
return 0;
}
return new Common::MemoryReadStream(dst, entry.uncompressedSize, DisposeAfterUse::YES);
#else
warning("zlib required to extract compressed CAB file '%s'", name.c_str());
return 0;
#endif
}
示例13:
Common::SeekableReadStream *Resources::openFile(const Common::String &fileName) {
debugC(1, kDebugResource, "openFile(%s)", fileName.c_str());
// first try to find files outside of .pak
// some patched files have not been included in package.
if (Common::File::exists(fileName)) {
Common::File *file = new Common::File();
bool opened = file->open(fileName);
if (!opened) {
delete file;
return 0;
}
return file;
} else {
for (uint32 i = 0; i < _pakFiles.size(); i++) {
Common::SeekableReadStream *stream = 0;
stream = _pakFiles[i]->createReadStream(fileName);
if (stream)
return stream;
}
return 0;
}
}
示例14: loadFont
bool Font::loadFont(const Common::String &filename) {
// Free previously loaded font (if any)
freeFont();
Common::File f;
f.open(filename);
if (f.isOpen()) {
debugC(6, kDraciGeneralDebugLevel, "Opened font file %s",
filename.c_str());
} else {
debugC(6, kDraciGeneralDebugLevel, "Error opening font file %s",
filename.c_str());
return false;
}
_maxCharWidth = f.readByte();
_fontHeight = f.readByte();
// Read in the widths of the glyphs
_charWidths = new uint8[kCharNum];
for (uint i = 0; i < kCharNum; ++i) {
_charWidths[i] = f.readByte();
}
// Calculate size of font data
uint fontDataSize = kCharNum * _maxCharWidth * _fontHeight;
// Read in all glyphs
_charData = new byte[fontDataSize];
f.read(_charData, fontDataSize);
debugC(5, kDraciGeneralDebugLevel, "Font %s loaded", filename.c_str());
return true;
}
示例15: load
bool SndRes::load(ResourceContext *context, uint32 resourceId, SoundBuffer &buffer, bool onlyHeader) {
size_t soundResourceLength;
bool result = false;
GameSoundType resourceType = kSoundPCM;
int rate = 0, size = 0;
Common::File *file;
if (resourceId == (uint32)-1) {
return false;
}
#ifdef ENABLE_IHNM
//TODO: move to resource_res so we can use normal "getResourceData" and "getFile" methods
if (_vm->getGameId() == GID_IHNM && _vm->isMacResources()) {
char soundFileName[40];
int dirIndex = resourceId / 64;
if ((context->fileType() & GAME_VOICEFILE) != 0) {
if (_voiceSerial == 0) {
sprintf(soundFileName, "Voices/VoicesS/Voices%d/VoicesS%03x", dirIndex, resourceId);
} else {
sprintf(soundFileName, "Voices/Voices%d/Voices%d/Voices%d%03x", _voiceSerial, dirIndex, _voiceSerial, resourceId);
}
} else {
sprintf(soundFileName, "SFX/SFX%d/SFX%03x", dirIndex, resourceId);
}
file = new Common::File();
file->open(soundFileName);
soundResourceLength = file->size();
} else
#endif
{
ResourceData* resourceData = context->getResourceData(resourceId);
file = context->getFile(resourceData);
file->seek(resourceData->offset);
soundResourceLength = resourceData->size;
}
Common::SeekableReadStream &readS = *file;
bool uncompressedSound = false;
if (soundResourceLength >= 8) {
byte header[8];
readS.read(&header, 8);
readS.seek(readS.pos() - 8);
if (!memcmp(header, "Creative", 8)) {
resourceType = kSoundVOC;
} else if (!memcmp(header, "RIFF", 4) != 0) {
resourceType = kSoundWAV;
} else if (!memcmp(header, "FORM", 4) != 0) {
resourceType = kSoundAIFF;
} else if (!memcmp(header, "ajkg", 4) != 0) {
resourceType = kSoundShorten;
}
// If patch data exists for sound resource 4 (used in ITE intro), don't treat this sound as compressed
// Patch data for this resource is in file p2_a.iaf or p2_a.voc
if (_vm->getGameId() == GID_ITE && resourceId == 4 && context->getResourceData(resourceId)->patchData != NULL)
uncompressedSound = true;
// FIXME: Currently, the SFX.RES file in IHNM cannot be compressed
if (_vm->getGameId() == GID_IHNM && (context->fileType() & GAME_SOUNDFILE))
uncompressedSound = true;
if (context->isCompressed() && !uncompressedSound) {
if (header[0] == char(0)) {
resourceType = kSoundMP3;
} else if (header[0] == char(1)) {
resourceType = kSoundOGG;
} else if (header[0] == char(2)) {
resourceType = kSoundFLAC;
}
}
}
// Default sound type is 16-bit signed PCM, used in ITE
byte rawFlags = Audio::FLAG_16BITS;
if (_vm->getGameId() == GID_ITE) {
if (context->fileType() & GAME_MACBINARY) {
// ITE Mac has sound in the Mac snd format
resourceType = kSoundMacSND;
} else if (_vm->getFeatures() & GF_8BIT_UNSIGNED_PCM) { // older ITE demos
rawFlags |= Audio::FLAG_UNSIGNED;
rawFlags &= ~Audio::FLAG_16BITS;
} else if (!uncompressedSound && !scumm_stricmp(context->fileName(), "voicesd.rsc")) {
// Voice files in newer ITE demo versions are OKI ADPCM (VOX) encoded.
resourceType = kSoundVOX;
}
}
buffer.stream = 0;
// Check for LE sounds
//.........这里部分代码省略.........