本文整理汇总了C++中common::DumpFile::open方法的典型用法代码示例。如果您正苦于以下问题:C++ DumpFile::open方法的具体用法?C++ DumpFile::open怎么用?C++ DumpFile::open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common::DumpFile
的用法示例。
在下文中一共展示了DumpFile::open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dumpResourcesList
void ResourceManager::dumpResourcesList(const Common::UString &fileName) const {
Common::DumpFile file;
if (!file.open(fileName))
throw Common::Exception(Common::kOpenError);
file.writeString(" Name | Hash | Size \n");
file.writeString("-------------------------------------|--------------------|-------------\n");
for (ResourceMap::const_iterator r = _resources.begin(); r != _resources.end(); ++r) {
if (r->second.empty())
continue;
const Resource &res = r->second.back();
const Common::UString &name = res.name;
const Common::UString ext = TypeMan.setFileType("", res.type);
const uint64 hash = r->first;
const uint32 size = getResourceSize(res);
const Common::UString line =
Common::UString::sprintf("%32s%4s | 0x%016llX | %12d\n", name.c_str(), ext.c_str(),
(unsigned long long) hash, size);
file.writeString(line);
}
file.flush();
if (file.err())
throw Common::Exception("Write error");
file.close();
}
示例2: Cmd_DumpItems
bool Debugger::Cmd_DumpItems(int argc, const char **argv) {
InventoryObjects &objects = _vm->_game->_objects;
Common::DumpFile outFile;
outFile.open("items.txt");
for (uint32 i = 0; i < objects.size(); i++) {
Common::String curId = Common::String::format("%d", i);
Common::String desc = _vm->_game->_scene.getVocab(objects[i]._descId);
desc.toUppercase();
for (uint j = 0; j < desc.size(); j++) {
if (desc[j] == ' ' || desc[j] == '-')
desc.setChar('_', j);
}
Common::String cur = "\tOBJ_" + desc + " = " + curId + ",\n";
outFile.writeString(cur.c_str());
}
outFile.flush();
outFile.close();
debugPrintf("Game items dumped\n");
return true;
}
示例3: Cmd_DumpVocab
bool Debugger::Cmd_DumpVocab(int argc, const char **argv) {
Common::DumpFile outFile;
outFile.open("vocab.txt");
for (uint32 i = 0; i < _vm->_game->_scene.getVocabStringsCount(); i++) {
Common::String curId = Common::String::format("%x", i + 1);
Common::String curVocab = _vm->_game->_scene.getVocab(i + 1);
curVocab.toUppercase();
for (uint j = 0; j < curVocab.size(); j++) {
if (curVocab[j] == ' ' || curVocab[j] == '-')
curVocab.setChar('_', j);
}
Common::String cur = "\tNOUN_" + curVocab + " = 0x" + curId + ",\n";
outFile.writeString(cur.c_str());
}
outFile.flush();
outFile.close();
debugPrintf("Game vocab dumped\n");
return true;
}
示例4: dumpBMP
void dumpBMP(const char *filename, int16 w, int16 h, const byte *bytes, const uint32 *palette) {
Common::DumpFile out;
byte my_hdr[sizeof(bmp_hdr)];
int i;
out.open(filename);
if (!out.isOpen())
return;
memcpy(my_hdr, bmp_hdr, sizeof(bmp_hdr));
*(uint32 *)(my_hdr + 2) = w * h + 1024 + sizeof(bmp_hdr);
*(uint32 *)(my_hdr + 18) = w;
*(uint32 *)(my_hdr + 22) = h;
out.write(my_hdr, sizeof(my_hdr));
for (i = 0; i != 256; i++, palette++) {
byte color[4];
color[0] = (byte)(*palette >> 16);
color[1] = (byte)(*palette >> 8);
color[2] = (byte)(*palette);
color[3] = 0;
out.write(color, 4);
}
while (--h >= 0) {
out.write(bytes + h * ((w + 3) & ~3), ((w + 3) & ~3));
}
}
示例5: cmdDumpFile
bool Debugger::cmdDumpFile(int argc, const char **argv) {
if (argc != 2) {
debugPrintf("Format: dumpfile <resource name>\n");
return true;
}
Common::SeekableReadStream *s = _vm->_res->load(argv[1]);
if (!s) {
debugPrintf("Invalid resource.\n");
return true;
}
byte *buffer = new byte[s->size()];
s->read(buffer, s->size());
Common::DumpFile dumpFile;
dumpFile.open(argv[1]);
dumpFile.write(buffer, s->size());
dumpFile.flush();
dumpFile.close();
delete[] buffer;
debugPrintf("Resource %s has been dumped to disk.\n", argv[1]);
return true;
}
示例6: dumpResourcesList
void ResourceManager::dumpResourcesList(const Common::UString &fileName) const {
Common::DumpFile file;
if (!file.open(fileName))
throw Common::Exception(Common::kOpenError);
file.writeString(" Name | Size \n");
file.writeString("-------------------------------------|-------------\n");
for (ResourceMap::const_iterator itName = _resources.begin(); itName != _resources.end(); ++itName) {
for (ResourceTypeMap::const_iterator itType = itName->second.begin(); itType != itName->second.end(); ++itType) {
if (itType->second.empty())
continue;
const Resource &resource = itType->second.back();
const Common::UString &name = itName->first;
const Common::UString ext = setFileType("", resource.type);
const uint32 size = getResourceSize(resource);
const Common::UString line =
Common::UString::sprintf("%32s%4s | %12d\n", name.c_str(), ext.c_str(), size);
file.writeString(line);
}
}
file.flush();
if (file.err())
throw Common::Exception("Write error");
file.close();
}
示例7: Cmd_DumpFile
bool Console::Cmd_DumpFile(int argc, const char **argv) {
if (argc != 3) {
debugPrintf("Usage: %s <file path> <output file name>\n", argv[0]);
return true;
}
Common::String filePath = argv[1];
Common::String outFileName = argv[2];
BaseFileManager *fileManager = BaseEngine::instance().getFileManager();
Common::SeekableReadStream *inFile = fileManager->openFile(filePath);
if (!inFile) {
debugPrintf("File '%s' not found\n", argv[1]);
return true;
}
Common::DumpFile *outFile = new Common::DumpFile();
outFile->open(outFileName);
byte *data = new byte[inFile->size()];
inFile->read(data, inFile->size());
outFile->write(data, inFile->size());
outFile->finalize();
outFile->close();
delete[] data;
delete outFile;
delete inFile;
debugPrintf("Resource file '%s' dumped to file '%s'\n", argv[1], argv[2]);
return true;
}
示例8: 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();
}
示例9: packData
void MadsM4Engine::dumpFile(const char* filename, bool uncompress) {
Common::DumpFile f;
byte buffer[DUMP_BUFFER_SIZE];
Common::SeekableReadStream *fileS = res()->get(filename);
if (!f.open(filename))
error("Could not open '%s' for writing", filename);
int bytesRead = 0;
warning("Dumping %s, size: %i\n", filename, fileS->size());
if (!uncompress) {
while (!fileS->eos()) {
bytesRead = fileS->read(buffer, DUMP_BUFFER_SIZE);
f.write(buffer, bytesRead);
}
} else {
MadsPack packData(fileS);
Common::SeekableReadStream *sourceUnc;
for (int i = 0; i < packData.getCount(); i++) {
sourceUnc = packData.getItemStream(i);
debugCN(kDebugCore, "Dumping compressed chunk %i of %i, size is %i\n", i + 1, packData.getCount(), sourceUnc->size());
while (!sourceUnc->eos()) {
bytesRead = sourceUnc->read(buffer, DUMP_BUFFER_SIZE);
f.write(buffer, bytesRead);
}
delete sourceUnc;
}
}
f.close();
res()->toss(filename);
res()->purge();
}
示例10: ExtractCdf
void GagEngine::ExtractCdf(const Common::String &a_fn)
{
CdfArchive archive(a_fn, true);
uint pos = a_fn.size();
for(uint i = 0; i < a_fn.size(); ++i)
{
if(a_fn[i] == '.')
pos = i;
}
//TODO: figure out how to create directory
Common::String dn(ConfMan.get("path") + '/' + Common::String(a_fn.c_str(), pos) + '/');
Common::ArchiveMemberList member_list;
archive.listMembers(member_list);
for(Common::ArchiveMemberList::iterator it = member_list.begin(); it != member_list.end(); ++it)
{
Common::ScopedPtr<Common::SeekableReadStream> stream((*it)->createReadStream());
if(stream)
{
uint8 *buffer = new uint8[stream->size()];
stream->read(buffer, stream->size());
Common::DumpFile file;
if(file.open(dn + (*it)->getName()))
file.write(buffer, stream->size());
delete [] buffer;
}
}
}
示例11: writeBMP
static bool writeBMP(const Common::UString &filename, const byte *data,
int width, int height) {
if ((width <= 0) || (height <= 0) || !data)
return false;
Common::DumpFile file;
if (!file.open(filename))
return false;
// The pitch of the output has to be divisible by 4, so
// we output zeroes to make the pitch that far.
int extraDataSize = width & 3;
int imageSize = height * (width + extraDataSize) * 3;
// Main bitmap header
file.writeByte('B');
file.writeByte('M');
file.writeUint32LE(14 + 40 + imageSize); // Size
file.writeUint32LE(0); // reserved
file.writeUint32LE(14 + 40); // Image offset after both headers
// v3 header
file.writeUint32LE(40);
file.writeUint32LE(width);
file.writeUint32LE(height);
file.writeUint16LE(1);
file.writeUint16LE(24);
file.writeUint32LE(0);
file.writeUint32LE(imageSize);
file.writeUint32LE(72);
file.writeUint32LE(72);
file.writeUint32LE(0);
file.writeUint32LE(0);
if (extraDataSize != 0) {
// Dump, making sure the pitch is correct
while (height--) {
file.write(data, width * 3);
// Ensure we're on a 4-byte boundary
for (int i = 0; i < extraDataSize; i++)
file.writeByte(0);
data += width * 3;
}
} else {
// Dump directly (can do all at once here because the data
// is already good for BMP output)
file.write(data, width * height * 3);
}
if (!file.flush() || file.err())
return false;
file.close();
return true;
}
示例12: cmdDumpImage
bool Console::cmdDumpImage(int argc, const char **argv) {
if (argc != 2) {
debugPrintf("Use %s <TGA/TGZ name> to dump a Z-Vision TGA/TGZ image into a regular BMP image\n", argv[0]);
return true;
}
Common::String fileName = argv[1];
if (!fileName.hasSuffix(".tga")) {
debugPrintf("%s is not an image file", argv[1]);
}
Common::File f;
if (!_engine->getSearchManager()->openFile(f, argv[1])) {
warning("File not found: %s", argv[1]);
return true;
}
Graphics::Surface surface;
_engine->getRenderManager()->readImageToSurface(argv[1], surface, false);
// Open file
Common::DumpFile out;
fileName.setChar('b', fileName.size() - 3);
fileName.setChar('m', fileName.size() - 2);
fileName.setChar('p', fileName.size() - 1);
out.open(fileName);
// Write BMP header
out.writeByte('B');
out.writeByte('M');
out.writeUint32LE(surface.h * surface.pitch + 54);
out.writeUint32LE(0);
out.writeUint32LE(54);
out.writeUint32LE(40);
out.writeUint32LE(surface.w);
out.writeUint32LE(surface.h);
out.writeUint16LE(1);
out.writeUint16LE(16);
out.writeUint32LE(0);
out.writeUint32LE(0);
out.writeUint32LE(0);
out.writeUint32LE(0);
out.writeUint32LE(0);
out.writeUint32LE(0);
// Write pixel data to BMP
out.write(surface.getPixels(), surface.pitch * surface.h);
out.flush();
out.close();
surface.free();
return true;
}
示例13: saveScreenshot
void OpenGLGraphicsManager::saveScreenshot(const Common::String &filename) const {
const uint width = _outputScreenWidth;
const uint height = _outputScreenHeight;
// A line of a BMP image must have a size divisible by 4.
// We calculate the padding bytes needed here.
// Since we use a 3 byte per pixel mode, we can use width % 4 here, since
// it is equal to 4 - (width * 3) % 4. (4 - (width * Bpp) % 4, is the
// usual way of computing the padding bytes required).
const uint linePaddingSize = width % 4;
const uint lineSize = width * 3 + linePaddingSize;
// Allocate memory for screenshot
uint8 *pixels = new uint8[lineSize * height];
// Get pixel data from OpenGL buffer
GLCALL(glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels));
// BMP stores as BGR. Since we can't assume that GL_BGR is supported we
// will swap the components from the RGB we read to BGR on our own.
for (uint y = height; y-- > 0;) {
uint8 *line = pixels + y * lineSize;
for (uint x = width; x > 0; --x, line += 3) {
SWAP(line[0], line[2]);
}
}
// Open file
Common::DumpFile out;
out.open(filename);
// Write BMP header
out.writeByte('B');
out.writeByte('M');
out.writeUint32LE(height * lineSize + 54);
out.writeUint32LE(0);
out.writeUint32LE(54);
out.writeUint32LE(40);
out.writeUint32LE(width);
out.writeUint32LE(height);
out.writeUint16LE(1);
out.writeUint16LE(24);
out.writeUint32LE(0);
out.writeUint32LE(0);
out.writeUint32LE(0);
out.writeUint32LE(0);
out.writeUint32LE(0);
out.writeUint32LE(0);
// Write pixel data to BMP
out.write(pixels, lineSize * height);
// Free allocated memory
delete[] pixels;
}
示例14: cacheFontData
bool BdfFont::cacheFontData(const BdfFont &font, const Common::String &filename) {
Common::DumpFile cacheFile;
if (!cacheFile.open(filename)) {
warning("BdfFont::cacheFontData: Couldn't open file '%s' for writing", filename.c_str());
return false;
}
const BdfFontData &data = font._data;
cacheFile.writeUint32BE(BDF_FONTCACHE_TAG);
cacheFile.writeUint32BE(BDF_FONTCACHE_VERSION);
cacheFile.writeUint16BE(data.maxAdvance);
cacheFile.writeByte(data.height);
cacheFile.writeByte(data.defaultBox.width);
cacheFile.writeByte(data.defaultBox.height);
cacheFile.writeSByte(data.defaultBox.xOffset);
cacheFile.writeSByte(data.defaultBox.yOffset);
cacheFile.writeByte(data.ascent);
cacheFile.writeUint16BE(data.firstCharacter);
cacheFile.writeSint16BE(data.defaultCharacter);
cacheFile.writeUint16BE(data.numCharacters);
for (int i = 0; i < data.numCharacters; ++i) {
const BdfBoundingBox &box = data.boxes ? data.boxes[i] : data.defaultBox;
if (data.bitmaps[i]) {
const int bytes = ((box.width + 7) / 8) * box.height;
cacheFile.writeUint32BE(bytes);
cacheFile.write(data.bitmaps[i], bytes);
} else {
cacheFile.writeUint32BE(0);
}
}
if (data.advances) {
cacheFile.writeByte(0xFF);
cacheFile.write(data.advances, data.numCharacters);
} else {
cacheFile.writeByte(0x00);
}
if (data.boxes) {
cacheFile.writeByte(0xFF);
for (int i = 0; i < data.numCharacters; ++i) {
const BdfBoundingBox &box = data.boxes[i];
cacheFile.writeByte(box.width);
cacheFile.writeByte(box.height);
cacheFile.writeSByte(box.xOffset);
cacheFile.writeSByte(box.yOffset);
}
} else {
cacheFile.writeByte(0x00);
}
return !cacheFile.err();
}
示例15: cacheFontData
bool NewFont::cacheFontData(const NewFont &font, const Common::String &filename) {
Common::DumpFile cacheFile;
if (!cacheFile.open(filename)) {
warning("Couldn't open file '%s' for writing", filename.c_str());
return false;
}
cacheFile.writeUint16BE(font.desc.maxwidth);
cacheFile.writeUint16BE(font.desc.height);
cacheFile.writeUint16BE(font.desc.fbbw);
cacheFile.writeUint16BE(font.desc.fbbh);
cacheFile.writeSint16BE(font.desc.fbbx);
cacheFile.writeSint16BE(font.desc.fbby);
cacheFile.writeUint16BE(font.desc.ascent);
cacheFile.writeUint16BE(font.desc.firstchar);
cacheFile.writeUint16BE(font.desc.size);
cacheFile.writeUint16BE(font.desc.defaultchar);
cacheFile.writeUint32BE(font.desc.bits_size);
for (long i = 0; i < font.desc.bits_size; ++i) {
cacheFile.writeUint16BE(font.desc.bits[i]);
}
if (font.desc.offset) {
cacheFile.writeByte(1);
for (int i = 0; i < font.desc.size; ++i) {
cacheFile.writeUint32BE(font.desc.offset[i]);
}
} else {
cacheFile.writeByte(0);
}
if (font.desc.width) {
cacheFile.writeByte(1);
for (int i = 0; i < font.desc.size; ++i) {
cacheFile.writeByte(font.desc.width[i]);
}
} else {
cacheFile.writeByte(0);
}
if (font.desc.bbx) {
cacheFile.writeByte(1);
for (int i = 0; i < font.desc.size; ++i) {
cacheFile.writeByte(font.desc.bbx[i].w);
cacheFile.writeByte(font.desc.bbx[i].h);
cacheFile.writeByte(font.desc.bbx[i].x);
cacheFile.writeByte(font.desc.bbx[i].y);
}
} else {
cacheFile.writeByte(0);
}
return !cacheFile.err();
}