本文整理汇总了C++中common::DumpFile::close方法的典型用法代码示例。如果您正苦于以下问题:C++ DumpFile::close方法的具体用法?C++ DumpFile::close怎么用?C++ DumpFile::close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common::DumpFile
的用法示例。
在下文中一共展示了DumpFile::close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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();
}
示例3: 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;
}
示例4: 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();
}
示例5: 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();
}
示例6: 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;
}
示例7: 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;
}
示例8: 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();
}
示例9: 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;
}
示例10: 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;
}
示例11: dumpFaceMask
bool Node::dumpFaceMask(uint16 index, int face, DirectorySubEntry::ResourceType type) {
static const int32 kMaskSize = 640 * 640;
byte *mask = new byte[kMaskSize];
memset(mask, 0, kMaskSize);
uint32 headerOffset = 0;
uint32 dataOffset = 0;
const DirectorySubEntry *maskDesc = _vm->getFileDescription(0, index, face, type);
if (!maskDesc) {
delete[] mask;
return false;
}
Common::MemoryReadStream *maskStream = maskDesc->getData();
while (headerOffset < 400) {
int blockX = (headerOffset / sizeof(dataOffset)) % 10;
int blockY = (headerOffset / sizeof(dataOffset)) / 10;
maskStream->seek(headerOffset, SEEK_SET);
dataOffset = maskStream->readUint32LE();
headerOffset = maskStream->pos();
if (dataOffset != 0) {
maskStream->seek(dataOffset, SEEK_SET);
for(int i = 63; i >= 0; i--) {
int x = 0;
byte numValues = maskStream->readByte();
for (int j = 0; j < numValues; j++) {
byte repeat = maskStream->readByte();
byte value = maskStream->readByte();
for (int k = 0; k < repeat; k++) {
mask[((blockY * 64) + i) * 640 + blockX * 64 + x] = value;
x++;
}
}
}
}
}
delete maskStream;
Common::DumpFile outFile;
outFile.open(Common::String::format("dump/%d-%d.masku_%d", index, face, type));
outFile.write(mask, kMaskSize);
outFile.close();
delete[] mask;
return true;
}
示例12: dumpStream
void dumpStream(Common::SeekableReadStream &stream, const Common::UString &fileName) {
Common::DumpFile file;
if (!file.open(fileName))
throw Common::Exception(Common::kOpenError);
file.writeStream(stream);
file.flush();
if (file.err())
throw Common::Exception(Common::kWriteError);
file.close();
}
示例13: dumpFile
void dumpFile(Common::SeekableReadStream *s, const char *outName) {
byte *buffer = new byte[s->size()];
s->read(buffer, s->size());
Common::DumpFile dumpFile;
dumpFile.open(outName);
dumpFile.write(buffer, s->size());
dumpFile.flush();
dumpFile.close();
delete[] buffer;
}
示例14: Cmd_DumpFile
bool Debugger::Cmd_DumpFile(int argc, const char **argv) {
if (argc < 2) {
debugPrintf("Usage: %s <resource> <unpack>\n", argv[0]);
debugPrintf(" resource: the resource name\n");
debugPrintf(" unpack: optional, when specified, the FAB/MADSPACK compressed resource is unpacked\n");
} else {
Common::DumpFile outFile;
Common::File inFile;
if (!inFile.open(argv[1])) {
debugPrintf("Specified resource does not exist\n");
} else {
outFile.open(argv[1]);
bool unpack = ((argc >= 3) && !scumm_stricmp(argv[2], "unpack"));
byte *data;
int totalSize = 0;
if (!unpack) {
totalSize = inFile.size();
data = new byte[totalSize];
inFile.read(data, totalSize);
} else {
MadsPack dataPack(&inFile);
int count = dataPack.getCount();
for (int i = 0; i < count; i++) {
totalSize += dataPack.getItem(i)._size;
}
data = new byte[totalSize];
byte *ptr = data;
for (int i = 0; i < count; i++) {
Common::SeekableReadStream *readStream = dataPack.getItemStream(i);
readStream->read(ptr, readStream->size());
ptr += readStream->size();
}
}
outFile.write(data, totalSize);
outFile.flush();
delete[] data;
inFile.close();
outFile.close();
debugPrintf("File written successfully.\n");
}
}
return true;
}
示例15: dumpASCII
bool TwoDAFile::dumpASCII(const Common::UString &fileName) const {
Common::DumpFile file;
if (!file.open(fileName))
return false;
// Write header
file.writeString("2DA V2.0\n");
file.writeString(_defaultString); file.writeByte('\n');
// Calculate column lengths
std::vector<uint32> colLength;
colLength.resize(_headers.size() + 1);
const Common::UString maxRow = Common::UString::sprintf("%d", (int)_rows.size() - 1);
colLength[0] = maxRow.size();
for (uint32 i = 0; i < _headers.size(); i++)
colLength[i + 1] = _headers[i].size();
for (uint32 i = 0; i < _rows.size(); i++)
for (uint32 j = 0; j < _rows[i]->_data.size(); j++)
colLength[j + 1] = MAX<uint32>(colLength[j + 1], _rows[i]->_data[j].size());
// Write column headers
file.writeString(Common::UString::sprintf("%-*s", colLength[0], ""));
for (uint32 i = 0; i < _headers.size(); i++)
file.writeString(Common::UString::sprintf(" %-*s", colLength[i + 1], _headers[i].c_str()));
file.writeByte('\n');
// Write array
for (uint32 i = 0; i < _rows.size(); i++) {
file.writeString(Common::UString::sprintf("%*d", colLength[0], i));
for (uint32 j = 0; j < _rows[i]->_data.size(); j++)
file.writeString(Common::UString::sprintf(" %-*s", colLength[j + 1], _rows[i]->_data[j].c_str()));
file.writeByte('\n');
}
file.flush();
file.close();
return true;
}