本文整理汇总了C++中common::File::size方法的典型用法代码示例。如果您正苦于以下问题:C++ File::size方法的具体用法?C++ File::size怎么用?C++ File::size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common::File
的用法示例。
在下文中一共展示了File::size方法的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: Cmd_DumpFile
bool Debugger::Cmd_DumpFile(int argc, const char **argv) {
if (argc != 2) {
debugPrintf("Usage: %s <resource>\n", argv[0]);
} else {
Common::DumpFile outFile;
Common::File inFile;
if (!inFile.open(argv[1])) {
debugPrintf("Specified resource does not exist\n");
} else {
outFile.open(argv[1]);
byte *data = new byte[inFile.size()];
inFile.read(data, inFile.size());
outFile.write(data, inFile.size());
outFile.flush();
delete[] data;
inFile.close();
outFile.close();
debugPrintf("File written successfully.\n");
}
}
return true;
}
示例3: main
int main(int argc, char *argv[]) {
if (argc != 3) {
printf("Format: %s ST.exe titanic.dat\n", argv[0]);
exit(0);
}
if (!inputFile.open(argv[1])) {
error("Could not open input file");
}
res.loadFromEXE(argv[1]);
if (inputFile.size() == ENGLISH_10042C_FILESIZE)
_version = ENGLISH_10042C;
else if (inputFile.size() == ENGLISH_10042B_FILESIZE)
_version = ENGLISH_10042B;
else if (inputFile.size() == ENGLISH_10042_FILESIZE)
_version = ENGLISH_10042;
else {
printf("Unknown version of ST.exe specified");
exit(0);
}
if (!outputFile.open(argv[2], Common::kFileWriteMode)) {
error("Could not open output file");
}
writeHeader();
writeData();
writeFinalEntryHeader();
inputFile.close();
outputFile.close();
return 0;
}
示例4: loadFile
/**
* Opens a file and loads a sound effect.
*
* @param fileName Sfx filename
*
* @returns True is everything is OK, False otherwise
*/
bool FPSfx::loadFile(const char *fileName) {
if (!_soundSupported)
return true;
SoundCodecs codec = FPCODEC_UNKNOWN;
Common::File file;
if (file.open(fileName))
codec = FPCODEC_ADPCM;
else if (file.open(setExtension(fileName, ".MP3")))
codec = FPCODEC_MP3;
else if (file.open(setExtension(fileName, ".OGG")))
codec = FPCODEC_OGG;
else if (file.open(setExtension(fileName, ".FLA")))
codec = FPCODEC_FLAC;
else {
warning("FPSfx::LoadFile(): Cannot open sfx file!");
return false;
}
Common::SeekableReadStream *buffer;
switch (codec) {
case FPCODEC_ADPCM: {
if (file.readUint32BE() != MKTAG('A', 'D', 'P', 0x10)) {
warning("FPSfx::LoadFile(): Invalid ADP header!");
return false;
}
uint32 rate = file.readUint32LE();
uint32 channels = file.readUint32LE();
buffer = file.readStream(file.size() - file.pos());
_rewindableStream = Audio::makeADPCMStream(buffer, DisposeAfterUse::YES, 0, Audio::kADPCMDVI, rate, channels);
}
break;
case FPCODEC_MP3:
#ifdef USE_MAD
buffer = file.readStream(file.size());
_rewindableStream = Audio::makeMP3Stream(buffer, DisposeAfterUse::YES);
#endif
break;
case FPCODEC_OGG:
#ifdef USE_VORBIS
buffer = file.readStream(file.size());
_rewindableStream = Audio::makeVorbisStream(buffer, DisposeAfterUse::YES);
#endif
break;
case FPCODEC_FLAC:
buffer = file.readStream(file.size());
#ifdef USE_FLAC
_rewindableStream = Audio::makeFLACStream(buffer, DisposeAfterUse::YES);
#endif
break;
default:
return false;
}
_fileLoaded = true;
return true;
}
示例5: play
uint SoundChannel::play(uint soundNum, uint repeats, uint notify) {
stop();
if (repeats == 0)
return 1;
// Find a sound of the given name
Audio::AudioStream *stream;
Common::File f;
Common::String nameSnd = Common::String::format("sound%u.snd", soundNum);
Common::String nameWav = Common::String::format("sound%u.wav", soundNum);
Common::String nameAiff = Common::String::format("sound%u.aiff", soundNum);
#ifdef USE_MAD
Common::String nameMp3 = Common::String::format("sound%u.mp3", soundNum);
#endif
if (f.exists(nameSnd) && f.open(nameSnd)) {
if (f.readUint16BE() != (f.size() - 2))
error("Invalid sound filesize");
repeats = f.readByte();
f.skip(1);
uint freq = f.readUint16BE();
f.skip(2);
uint size = f.readUint16BE();
Common::SeekableReadStream *s = f.readStream(size);
stream = Audio::makeRawStream(s, freq, Audio::FLAG_UNSIGNED);
#ifdef USE_MAD
} else if (f.exists(nameMp3) && f.open(nameMp3)) {
Common::SeekableReadStream *s = f.readStream(f.size());
stream = Audio::makeMP3Stream(s, DisposeAfterUse::YES);
#endif
} else if (f.exists(nameWav) && f.open(nameWav)) {
Common::SeekableReadStream *s = f.readStream(f.size());
stream = Audio::makeWAVStream(s, DisposeAfterUse::YES);
} else if (f.exists(nameAiff) && f.open(nameAiff)) {
Common::SeekableReadStream *s = f.readStream(f.size());
stream = Audio::makeAIFFStream(s, DisposeAfterUse::YES);
} else {
warning("Could not find sound %u", soundNum);
return 1;
}
_soundNum = soundNum;
_notify = notify;
// Set up a repeat if multiple repeats are specified
if (repeats > 1) {
Audio::RewindableAudioStream *rwStream = dynamic_cast<Audio::RewindableAudioStream *>(stream);
assert(rwStream);
stream = new Audio::LoopingAudioStream(rwStream, repeats, DisposeAfterUse::YES);
}
// Start playing the audio
g_vm->_mixer->playStream(Audio::Mixer::kPlainSoundType, &_handle, stream);
return 0;
}
示例6: 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);
}
}
示例7: loadLanguageStrings
bool CruiseEngine::loadLanguageStrings() {
Common::File f;
// Give preference to a language file
if (f.open("DELPHINE.LNG")) {
char *data = (char *)MemAlloc(f.size());
f.read(data, f.size());
char *ptr = data;
for (int i = 0; i < MAX_LANGUAGE_STRINGS; ++i) {
// Get the start of the next string
while (*ptr != '"') ++ptr;
const char *v = ++ptr;
// Find the end of the string, and replace the end '"' with a NULL
while (*ptr != '"') ++ptr;
*ptr++ = '\0';
// Add the string to the list
_langStrings.push_back(v);
}
f.close();
MemFree(data);
} else {
// Try and use one of the pre-defined language lists
const char **p = NULL;
switch (getLanguage()) {
case Common::EN_ANY:
p = englishLanguageStrings;
break;
case Common::FR_FRA:
p = frenchLanguageStrings;
break;
case Common::DE_DEU:
p = germanLanguageStrings;
break;
case Common::IT_ITA:
p = italianLanguageStrings;
break;
default:
return false;
}
// Load in the located language set
for (int i = 0; i < 13; ++i, ++p)
_langStrings.push_back(*p);
}
return true;
}
示例8: detectGames
bool GlulxeMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &gameList) {
const char *const EXTENSIONS[3] = { ".ulx", ".blb", ".gblorb" };
// Loop through the files of the folder
for (Common::FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
// Check for a recognised filename
if (file->isDirectory())
continue;
Common::String filename = file->getName();
bool hasExt = false;
for (int idx = 0; idx < 3 && !hasExt; ++idx)
hasExt = filename.hasSuffixIgnoreCase(EXTENSIONS[idx]);
if (!hasExt)
continue;
// Open up the file and calculate the md5
Common::File gameFile;
if (!gameFile.open(*file))
continue;
Common::String md5 = Common::computeStreamMD5AsString(gameFile, 5000);
size_t filesize = gameFile.size();
gameFile.close();
// Check for known games
const GlulxeGameDescription *p = GLULXE_GAMES;
while (p->_gameId && (md5 != p->_md5 || filesize != p->_filesize))
++p;
DetectedGame gd;
if (!p->_gameId) {
if (filename.hasSuffixIgnoreCase(".blb"))
continue;
if (gDebugLevel > 0) {
// Print an entry suitable for putting into the detection_tables.h, using the
// name of the parent folder the game is in as the presumed game Id
Common::String folderName = file->getParent().getName();
if (folderName.hasSuffix("\\"))
folderName.deleteLastChar();
Common::String fname = filename;
const char *dot = strchr(fname.c_str(), '.');
if (dot)
fname = Common::String(fname.c_str(), dot);
debug("ENTRY0(\"%s\", \"%s\", %u),", fname.c_str(), md5.c_str(), (uint)filesize);
}
const PlainGameDescriptor &desc = GLULXE_GAME_LIST[0];
gd = DetectedGame(desc.gameId, desc.description, Common::UNK_LANG, Common::kPlatformUnknown);
} else {
PlainGameDescriptor gameDesc = findGame(p->_gameId);
gd = DetectedGame(p->_gameId, gameDesc.description, p->_language, Common::kPlatformUnknown, p->_extra);
gd.setGUIOptions(GUIO4(GUIO_NOSPEECH, GUIO_NOSFX, GUIO_NOMUSIC, GUIO_NOSUBTITLES));
}
gd.addExtraEntry("filename", filename);
gameList.push_back(gd);
}
return !gameList.empty();
}
示例9: dumpMusic
// Dumps all of the game's music in external XMIDI *.xmi files
void dumpMusic() {
Common::File midiFile;
Common::DumpFile outFile;
char outName[20];
midiFile.open(MIDI_FILE);
int outFileSize = 0;
char buffer[20000];
const int total = 155; // maximum (SCN version)
for (int i = 0; i < total; i++) {
if (midiOffsets[i] == 0)
break;
sprintf(outName, "track%03d.xmi", i + 1);
outFile.open(outName);
if (i < total - 1)
outFileSize = midiOffsets[i + 1] - midiOffsets[i] - 4;
else
outFileSize = midiFile.size() - midiOffsets[i] - 4;
midiFile.seek(midiOffsets[i] + 4, SEEK_SET);
assert(outFileSize < 20000);
midiFile.read(buffer, outFileSize);
outFile.write(buffer, outFileSize);
outFile.close();
}
midiFile.close();
}
示例10: writeParrotLobbyLinkUpdaterEntries
void writeParrotLobbyLinkUpdaterEntries() {
static const int OFFSETS[3] = { 0x5A5B38, 0x5A5320, 0x5A4360 };
static const int COUNTS[5] = { 7, 5, 6, 9, 1 };
static const int SKIP[5] = { 36, 36, 40, 36, 0 };
uint recordOffset = OFFSETS[_version], linkOffset;
byte vals[8];
outputFile.seek(dataOffset);
for (int groupNum = 0; groupNum < 4; ++groupNum) {
for (int entryNum = 0; entryNum < COUNTS[groupNum];
++entryNum, recordOffset += 36) {
inputFile.seek(recordOffset - FILE_DIFF[_version]);
linkOffset = inputFile.readUint32LE();
for (int idx = 0; idx < 8; ++idx)
vals[idx] = inputFile.readUint32LE();
// Write out the entry
inputFile.seek(linkOffset - FILE_DIFF[_version]);
outputFile.writeString(inputFile);
outputFile.write(vals, 8);
}
// Skip space between groups
recordOffset += SKIP[groupNum];
}
uint size = outputFile.size() - dataOffset;
writeEntryHeader("DATA/PARROT_LOBBY_LINK_UPDATOR", dataOffset, size);
dataOffset += size;
}
示例11: 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;
}
示例12: getFileProperties
bool AdvancedMetaEngine::getFileProperties(const Common::FSNode &parent, const FileMap &allFiles, const ADGameDescription &game, const Common::String fname, ADFileProperties &fileProps) const {
// FIXME/TODO: We don't handle the case that a file is listed as a regular
// file and as one with resource fork.
if (game.flags & ADGF_MACRESFORK) {
Common::MacResManager macResMan;
if (!macResMan.open(parent, fname))
return false;
fileProps.md5 = macResMan.computeResForkMD5AsString(_md5Bytes);
fileProps.size = macResMan.getResForkDataSize();
if (fileProps.size != 0)
return true;
}
if (!allFiles.contains(fname))
return false;
Common::File testFile;
if (!testFile.open(allFiles[fname]))
return false;
fileProps.size = (int32)testFile.size();
fileProps.md5 = Common::computeStreamMD5AsString(testFile, _md5Bytes);
return true;
}
示例13: load
Common::SeekableReadStream *Resources::load(const Common::String &filename) {
// First check if the file is directly in the cache
if (_cache.isCached(filename))
return _cache.get(filename);
// Secondly, iterate through any loaded library file looking for a resource
// that has the same name
for (LibraryIndexes::iterator i = _indexes.begin(); i != _indexes.end(); ++i) {
if (i->_value.contains(filename)) {
// Get a stream reference to the given library file
Common::SeekableReadStream *stream = load(i->_key);
LibraryEntry &entry = i->_value[filename];
_resourceIndex = entry._index;
stream->seek(entry._offset);
Common::SeekableReadStream *resStream = stream->readStream(entry._size);
decompressIfNecessary(resStream);
delete stream;
return resStream;
}
}
// At this point, fall back on a physical file with the given name
Common::File f;
if (!f.open(filename))
error("Could not load file - %s", filename.c_str());
Common::SeekableReadStream *stream = f.readStream(f.size());
f.close();
decompressIfNecessary(stream);
return stream;
}
示例14: writeResponseTree
void writeResponseTree() {
outputFile.seek(dataOffset);
const uint OFFSETS[3] = { 0x619520, 0x618340, 0x617380 };
for (int idx = 0; idx < 1022; ++idx) {
inputFile.seek(OFFSETS[_version] - FILE_DIFF[_version] + idx * 8);
uint id = inputFile.readLong();
uint offset = inputFile.readLong();
outputFile.writeLong(id);
if (!id) {
// An end of list id
} else if (offset >= OFFSETS[_version] && offset <= (OFFSETS[_version] + 0x1FF0)) {
// Offset to another table
outputFile.writeByte(0);
outputFile.writeLong((offset - OFFSETS[_version]) / 8);
} else {
// Offset to ASCIIZ string
outputFile.writeByte(1);
writeString(offset);
}
}
uint size = outputFile.size() - dataOffset;
writeEntryHeader("TEXT/TREE", dataOffset, size);
dataOffset += size;
}
示例15: tokenizer
Audio::RewindableAudioStream *makeRawZorkStream(const Common::String &filePath, ZVision *engine) {
Common::File *file = new Common::File();
Common::String actualName = filePath;
bool found = engine->getSearchManager()->openFile(*file, actualName);
bool isRaw = actualName.hasSuffix(".raw");
if ((!found && isRaw) || (found && isRaw && file->size() < 10)) {
if (found)
file->close();
// Check for an audio patch (.src)
actualName.setChar('s', actualName.size() - 3);
actualName.setChar('r', actualName.size() - 2);
actualName.setChar('c', actualName.size() - 1);
if (!engine->getSearchManager()->openFile(*file, actualName))
return NULL;
} else if (!found && !isRaw) {
return NULL;
}
// Get the file name
Common::StringTokenizer tokenizer(actualName, "/\\");
Common::String fileName;
while (!tokenizer.empty()) {
fileName = tokenizer.nextToken();
}
fileName.toLowercase();
const SoundParams *soundParams = NULL;
if (engine->getGameId() == GID_NEMESIS) {
for (int i = 0; i < 32; ++i) {
if (RawZorkStream::_zNemSoundParamLookupTable[i].identifier == (fileName[6]))
soundParams = &RawZorkStream::_zNemSoundParamLookupTable[i];
}
} else if (engine->getGameId() == GID_GRANDINQUISITOR) {
for (int i = 0; i < 24; ++i) {
if (RawZorkStream::_zgiSoundParamLookupTable[i].identifier == (fileName[7]))
soundParams = &RawZorkStream::_zgiSoundParamLookupTable[i];
}
}
if (soundParams == NULL)
return NULL;
if (soundParams->packed) {
return makeRawZorkStream(wrapBufferedSeekableReadStream(file, 2048, DisposeAfterUse::YES), soundParams->rate, soundParams->stereo, DisposeAfterUse::YES);
} else {
byte flags = 0;
if (soundParams->bits16)
flags |= Audio::FLAG_16BITS | Audio::FLAG_LITTLE_ENDIAN;
if (soundParams->stereo)
flags |= Audio::FLAG_STEREO;
return Audio::makePCMStream(file, soundParams->rate, flags, DisposeAfterUse::YES);
}
}