Changed class File (and derived classes) to only support read-only access; added a new class DumpFile for writing

svn-id: r33412
This commit is contained in:
Max Horn 2008-07-29 16:09:10 +00:00
parent c9051fcfbd
commit 0be985ce83
30 changed files with 200 additions and 202 deletions

View file

@ -58,7 +58,7 @@ void ConfigFile::clear() {
bool ConfigFile::loadFromFile(const String &filename) {
File file;
if (file.open(filename, File::kFileReadMode))
if (file.open(filename))
return loadFromStream(file);
else
return false;
@ -171,8 +171,8 @@ bool ConfigFile::loadFromStream(SeekableReadStream &stream) {
}
bool ConfigFile::saveToFile(const String &filename) {
File file;
if (file.open(filename, File::kFileWriteMode))
DumpFile file;
if (file.open(filename))
return saveToStream(file);
else
return false;

View file

@ -289,13 +289,9 @@ void ConfigManager::loadFile(const String &filename) {
void ConfigManager::flushToDisk() {
#ifndef __DC__
File cfg_file;
DumpFile cfg_file;
// TODO
// if (!willwrite)
// return;
if (!cfg_file.open(_filename, File::kFileWriteMode)) {
if (!cfg_file.open(_filename)) {
warning("Unable to write configuration file: %s", _filename.c_str());
} else {
// First write the domains in _domainSaveOrder, in that order.

View file

@ -104,7 +104,7 @@
//#define fgets(str, size, file) DS::std_fgets(str, size, file) // not used
//#define getc(handle) DS::std_getc(handle) // not used
//#define getcwd(dir, dunno) DS::std_getcwd(dir, dunno) // not used
//#define ferror(handle) DS::std_ferror(handle) // not used
#define ferror(handle) DS::std_ferror(handle)
#endif
@ -273,26 +273,14 @@ File::File()
: _handle(0), _ioFailed(false) {
}
//#define DEBUG_FILE_REFCOUNT
File::~File() {
#ifdef DEBUG_FILE_REFCOUNT
warning("File::~File on file '%s'", _name.c_str());
#endif
close();
}
bool File::open(const String &filename, AccessMode mode) {
assert(mode == kFileReadMode || mode == kFileWriteMode);
if (filename.empty()) {
error("File::open: No filename was specified");
}
if (_handle) {
error("File::open: This file object already is opened (%s), won't open '%s'", _name.c_str(), filename.c_str());
}
bool File::open(const String &filename) {
assert(!filename.empty());
assert(!_handle);
_name.clear();
clearIOFailed();
@ -300,32 +288,29 @@ bool File::open(const String &filename, AccessMode mode) {
String fname(filename);
fname.toLowercase();
const char *modeStr = (mode == kFileReadMode) ? "rb" : "wb";
if (mode == kFileWriteMode) {
_handle = fopenNoCase(filename, "", modeStr);
} else if (_filesMap && _filesMap->contains(fname)) {
if (_filesMap && _filesMap->contains(fname)) {
fname = (*_filesMap)[fname];
debug(3, "Opening hashed: %s", fname.c_str());
_handle = fopen(fname.c_str(), modeStr);
_handle = fopen(fname.c_str(), "rb");
} else if (_filesMap && _filesMap->contains(fname + ".")) {
// WORKAROUND: Bug #1458388: "SIMON1: Game Detection fails"
// sometimes instead of "GAMEPC" we get "GAMEPC." (note trailing dot)
fname = (*_filesMap)[fname + "."];
debug(3, "Opening hashed: %s", fname.c_str());
_handle = fopen(fname.c_str(), modeStr);
_handle = fopen(fname.c_str(), "rb");
} else {
if (_defaultDirectories) {
// Try all default directories
StringIntMap::const_iterator x(_defaultDirectories->begin());
for (; _handle == NULL && x != _defaultDirectories->end(); ++x) {
_handle = fopenNoCase(filename, x->_key, modeStr);
_handle = fopenNoCase(filename, x->_key, "rb");
}
}
// Last resort: try the current directory
if (_handle == NULL)
_handle = fopenNoCase(filename, "", modeStr);
_handle = fopenNoCase(filename, "", "rb");
// Last last (really) resort: try looking inside the application bundle on Mac OS X for the lowercase file.
#if defined(MACOSX) || defined(IPHONE)
@ -335,7 +320,7 @@ bool File::open(const String &filename, AccessMode mode) {
if (fileUrl) {
UInt8 buf[256];
if (CFURLGetFileSystemRepresentation(fileUrl, false, (UInt8 *)buf, 256)) {
_handle = fopen((char *)buf, modeStr);
_handle = fopen((char *)buf, "rb");
}
CFRelease(fileUrl);
}
@ -345,26 +330,15 @@ bool File::open(const String &filename, AccessMode mode) {
}
if (_handle == NULL) {
if (mode == kFileReadMode)
debug(2, "File %s not found", filename.c_str());
else
if (_handle == NULL)
debug(2, "File %s not opened", filename.c_str());
return false;
}
else
_name = filename;
#ifdef DEBUG_FILE_REFCOUNT
warning("File::open on file '%s'", _name.c_str());
#endif
return true;
return _handle != NULL;
}
bool File::open(const FilesystemNode &node, AccessMode mode) {
assert(mode == kFileReadMode || mode == kFileWriteMode);
bool File::open(const FilesystemNode &node) {
if (!node.exists()) {
warning("File::open: Trying to open a FilesystemNode which does not exist");
@ -389,25 +363,14 @@ bool File::open(const FilesystemNode &node, AccessMode mode) {
clearIOFailed();
_name.clear();
const char *modeStr = (mode == kFileReadMode) ? "rb" : "wb";
_handle = fopen(node.getPath().c_str(), "rb");
_handle = fopen(node.getPath().c_str(), modeStr);
if (_handle == NULL) {
if (mode == kFileReadMode)
if (_handle == NULL)
debug(2, "File %s not found", filename.c_str());
else
debug(2, "File %s not opened", filename.c_str());
return false;
}
_name = filename;
#ifdef DEBUG_FILE_REFCOUNT
warning("File::open on file '%s'", _name.c_str());
#endif
return true;
return _handle != NULL;
}
bool File::exists(const String &filename) {
@ -438,7 +401,7 @@ bool File::exists(const String &filename) {
//Try opening the file inside the local directory as a last resort
File tmp;
return tmp.open(filename, kFileReadMode);
return tmp.open(filename);
}
void File::close() {
@ -462,28 +425,19 @@ void File::clearIOFailed() {
}
bool File::eof() const {
if (_handle == NULL) {
error("File::eof: File is not open!");
return false;
}
assert(_handle);
return feof((FILE *)_handle) != 0;
}
uint32 File::pos() const {
if (_handle == NULL) {
error("File::pos: File is not open!");
return 0;
}
assert(_handle);
return ftell((FILE *)_handle);
}
uint32 File::size() const {
if (_handle == NULL) {
error("File::size: File is not open!");
return 0;
}
assert(_handle);
uint32 oldPos = ftell((FILE *)_handle);
fseek((FILE *)_handle, 0, SEEK_END);
@ -494,10 +448,7 @@ uint32 File::size() const {
}
void File::seek(int32 offs, int whence) {
if (_handle == NULL) {
error("File::seek: File is not open!");
return;
}
assert(_handle);
if (fseek((FILE *)_handle, offs, whence) != 0)
clearerr((FILE *)_handle);
@ -507,10 +458,7 @@ uint32 File::read(void *ptr, uint32 len) {
byte *ptr2 = (byte *)ptr;
uint32 real_len;
if (_handle == NULL) {
error("File::read: File is not open!");
return 0;
}
assert(_handle);
if (len == 0)
return 0;
@ -523,20 +471,62 @@ uint32 File::read(void *ptr, uint32 len) {
return real_len;
}
uint32 File::write(const void *ptr, uint32 len) {
if (_handle == NULL) {
error("File::write: File is not open!");
return 0;
DumpFile::DumpFile() : _handle(0) {
}
DumpFile::~DumpFile() {
close();
}
bool DumpFile::open(const String &filename) {
assert(!filename.empty());
assert(!_handle);
String fname(filename);
fname.toLowercase();
_handle = fopenNoCase(filename, "", "wb");
if (_handle == NULL)
debug(2, "Failed to open '%s' for writing", filename.c_str());
return _handle != NULL;
}
void DumpFile::close() {
if (_handle)
fclose((FILE *)_handle);
_handle = NULL;
}
bool DumpFile::isOpen() const {
return _handle != NULL;
}
bool DumpFile::ioFailed() const {
assert(_handle);
return ferror((FILE *)_handle) != 0;
}
void DumpFile::clearIOFailed() {
assert(_handle);
clearerr((FILE *)_handle);
}
bool DumpFile::eof() const {
assert(_handle);
return feof((FILE *)_handle) != 0;
}
uint32 DumpFile::write(const void *ptr, uint32 len) {
assert(_handle);
if (len == 0)
return 0;
if ((uint32)fwrite(ptr, 1, len, (FILE *)_handle) != len) {
_ioFailed = true;
return (uint32)fwrite(ptr, 1, len, (FILE *)_handle);
}
return len;
}
} // End of namespace Common

View file

@ -27,6 +27,7 @@
#define COMMON_FILE_H
#include "common/scummsys.h"
#include "common/noncopyable.h"
#include "common/str.h"
#include "common/stream.h"
@ -34,7 +35,10 @@ class FilesystemNode;
namespace Common {
class File : public SeekableReadStream, public WriteStream {
/**
* TODO: vital to document this core class properly!!! For both users and implementors
*/
class File : public SeekableReadStream, public NonCopyable {
protected:
/** File handle to the actual file; 0 if no file is open. */
void *_handle;
@ -45,19 +49,7 @@ protected:
/** The name of this file, for debugging. */
String _name;
private:
// Disallow copying File objects. There is not strict reason for this,
// except that so far we never had real need for such a feature, and
// code that accidentally copied File objects tended to break in strange
// ways.
File(const File &f);
File &operator =(const File &f);
public:
enum AccessMode {
kFileReadMode = 1,
kFileWriteMode = 2
};
static void addDefaultDirectory(const String &directory);
static void addDefaultDirectoryRecursive(const String &directory, int level = 4, const String &prefix = "");
@ -80,8 +72,8 @@ public:
*/
static bool exists(const String &filename);
virtual bool open(const String &filename, AccessMode mode = kFileReadMode);
virtual bool open(const FilesystemNode &node, AccessMode mode = kFileReadMode);
virtual bool open(const String &filename);
virtual bool open(const FilesystemNode &node);
virtual void close();
@ -114,9 +106,52 @@ public:
virtual uint32 size() const;
void seek(int32 offs, int whence = SEEK_SET);
uint32 read(void *dataPtr, uint32 dataSize);
};
/**
* TODO: document this class
*
* Some design ideas:
* - automatically drop all files into dumps/ dir? Might not be desired in all cases
*/
class DumpFile : public WriteStream, public NonCopyable {
protected:
/** File handle to the actual file; 0 if no file is open. */
void *_handle;
public:
DumpFile();
virtual ~DumpFile();
virtual bool open(const String &filename);
//virtual bool open(const FilesystemNode &node);
virtual void close();
/**
* Checks if the object opened a file successfully.
*
* @return: true if any file is opened, false otherwise.
*/
bool isOpen() const;
bool ioFailed() const;
void clearIOFailed();
bool eos() const { return eof(); }
/**
* Checks for end of file.
*
* @return: true if the end of file is reached, false otherwise.
*/
virtual bool eof() const;
uint32 write(const void *dataPtr, uint32 dataSize);
};
} // End of namespace Common
#endif

View file

@ -231,7 +231,7 @@ ArjHeader *ArjFile::readHeader() {
}
bool ArjFile::open(const Common::String &filename, AccessMode mode) {
bool ArjFile::open(const Common::String &filename) {
if (_isOpen)
error("Attempt to open another instance of archive");

View file

@ -110,7 +110,7 @@ public:
void registerArchive(const String &filename);
bool open(const Common::String &filename, AccessMode mode = kFileReadMode);
bool open(const Common::String &filename);
void close();
uint32 read(void *dataPtr, uint32 dataSize);

View file

@ -393,11 +393,11 @@ static const byte bmp_hdr[] = {
};
void dumpBMP(const char *filename, int w, int h, const byte *bytes, const uint32 *palette) {
Common::File out;
Common::DumpFile out;
byte my_hdr[sizeof(bmp_hdr)];
int i;
out.open(filename, Common::File::kFileWriteMode);
out.open(filename);
if (!out.isOpen())
return;

View file

@ -978,7 +978,7 @@ bool AGOSEngine::loadGame(const char *filename, bool restartMode) {
if (restartMode) {
// Load restart state
Common::File *file = new Common::File();
file->open(filename, Common::File::kFileReadMode);
file->open(filename);
f = file;
} else {
f = _saveFileMan->openForLoading(filename);
@ -1154,7 +1154,7 @@ bool AGOSEngine_Elvira2::loadGame(const char *filename, bool restartMode) {
if (restartMode) {
// Load restart state
Common::File *file = new Common::File();
file->open(filename, Common::File::kFileReadMode);
file->open(filename);
f = file;
} else {
f = _saveFileMan->openForLoading(filename);

View file

@ -289,8 +289,8 @@ void dumpBundle(const char *fileName) {
debug(0, "%s", partBuffer[i].partName);
Common::File out;
if (out.open(Common::String("dumps/") + partBuffer[i].partName, Common::File::kFileWriteMode)) {
Common::DumpFile out;
if (out.open(Common::String("dumps/") + partBuffer[i].partName)) {
out.write(data, partBuffer[i].unpackedSize);
out.close();
}

View file

@ -2957,10 +2957,10 @@ void decompileScript(const byte *scriptPtr, uint16 scriptSize, uint16 scriptIdx)
}
void dumpScript(char *dumpName) {
Common::File fHandle;
Common::DumpFile fHandle;
uint16 i;
fHandle.open(dumpName, Common::File::kFileWriteMode);
fHandle.open(dumpName);
for (i = 0; i < decompileBufferPosition; i++) {
fHandle.writeString(Common::String(decompileBuffer[i]));

View file

@ -456,8 +456,8 @@ int16 readVolCnf(void) {
sprintf(nameBuffer, "%s", buffer[j].name);
if (buffer[j].size == buffer[j].extSize) {
Common::File fout;
fout.open(nameBuffer, Common::File::kFileWriteMode);
Common::DumpFile fout;
fout.open(nameBuffer);
if(fout.isOpen())
fout.write(bufferLocal, buffer[j].size);
} else {

View file

@ -202,7 +202,7 @@ const Common::File *DataIO::file_getHandle(int16 handle) const {
return &_filesHandles[handle];
}
int16 DataIO::file_open(const char *path, Common::File::AccessMode mode) {
int16 DataIO::file_open(const char *path) {
int16 i;
for (i = 0; i < MAX_FILES; i++) {
@ -212,7 +212,7 @@ int16 DataIO::file_open(const char *path, Common::File::AccessMode mode) {
if (i == MAX_FILES)
return -1;
file_getHandle(i)->open(path, mode);
file_getHandle(i)->open(path);
if (file_getHandle(i)->isOpen())
return i;
@ -467,17 +467,14 @@ void DataIO::closeData(int16 handle) {
file_getHandle(handle)->close();
}
int16 DataIO::openData(const char *path, Common::File::AccessMode mode) {
int16 DataIO::openData(const char *path) {
int16 handle;
if (mode != Common::File::kFileReadMode)
return file_open(path, mode);
handle = getChunk(path);
if (handle >= 0)
return handle;
return file_open(path, mode);
return file_open(path);
}
DataStream *DataIO::openAsStream(int16 handle, bool dispose) {

View file

@ -79,8 +79,7 @@ public:
void closeDataFile(bool itk = 0);
byte *getUnpackedData(const char *name);
void closeData(int16 handle);
int16 openData(const char *path,
Common::File::AccessMode mode = Common::File::kFileReadMode);
int16 openData(const char *path);
DataStream *openAsStream(int16 handle, bool dispose = false);
int32 getDataSize(const char *name);
@ -104,8 +103,7 @@ protected:
class GobEngine *_vm;
int16 file_open(const char *path,
Common::File::AccessMode mode = Common::File::kFileReadMode);
int16 file_open(const char *path);
Common::File *file_getHandle(int16 handle);
const Common::File *file_getHandle(int16 handle) const;

View file

@ -56,7 +56,7 @@ void ScummEngine::loadCJKFont() {
_2byteWidth = 16;
_2byteHeight = 16;
// use FM-TOWNS font rom, since game files don't have kanji font resources
if (fp.open("fmt_fnt.rom", Common::File::kFileReadMode)) {
if (fp.open("fmt_fnt.rom")) {
_useCJKMode = true;
debug(2, "Loading FM-TOWNS Kanji rom");
_2byteFontPtr = new byte[((_2byteWidth + 7) / 8) * _2byteHeight * numChar];

View file

@ -298,7 +298,7 @@ bool ScummDebugger::Cmd_ImportRes(int argc, const char** argv) {
// FIXME add bounds check
if (!strncmp(argv[1], "scr", 3)) {
file.open(argv[2], Common::File::kFileReadMode);
file.open(argv[2]);
if (file.isOpen() == false) {
DebugPrintf("Could not open file %s\n", argv[2]);
return true;

View file

@ -58,8 +58,8 @@ void ScummFile::resetSubfile() {
seek(0, SEEK_SET);
}
bool ScummFile::open(const Common::String &filename, AccessMode mode) {
if (File::open(filename, mode)) {
bool ScummFile::open(const Common::String &filename) {
if (File::open(filename)) {
resetSubfile();
return true;
} else {
@ -187,11 +187,6 @@ uint32 ScummFile::read(void *dataPtr, uint32 dataSize) {
return realLen;
}
uint32 ScummFile::write(const void *, uint32) {
error("ScummFile does not support writing!");
return 0;
}
#pragma mark -
#pragma mark --- ScummDiskImage ---
#pragma mark -
@ -250,11 +245,6 @@ ScummDiskImage::ScummDiskImage(const char *disk1, const char *disk2, GameSetting
}
}
uint32 ScummDiskImage::write(const void *, uint32) {
error("ScummDiskImage does not support writing!");
return 0;
}
void ScummDiskImage::setEnc(byte enc) {
_stream->setEnc(enc);
}
@ -300,7 +290,7 @@ bool ScummDiskImage::openDisk(char num) {
return true;
}
bool ScummDiskImage::open(const Common::String &filename, AccessMode mode) {
bool ScummDiskImage::open(const Common::String &filename) {
uint16 signature;
// check signature

View file

@ -36,7 +36,7 @@ class BaseScummFile : public Common::File {
public:
virtual void setEnc(byte value) = 0;
virtual bool open(const Common::String &filename, AccessMode mode = kFileReadMode) = 0;
virtual bool open(const Common::String &filename) = 0;
virtual bool openSubFile(const Common::String &filename) = 0;
virtual bool eof() = 0;
@ -44,7 +44,6 @@ public:
virtual uint32 size() = 0;
virtual void seek(int32 offs, int whence = SEEK_SET) = 0;
virtual uint32 read(void *dataPtr, uint32 dataSize) = 0;
virtual uint32 write(const void *dataPtr, uint32 dataSize) = 0;
};
class ScummFile : public BaseScummFile {
@ -59,7 +58,7 @@ public:
void setSubfileRange(uint32 start, uint32 len);
void resetSubfile();
bool open(const Common::String &filename, AccessMode mode = kFileReadMode);
bool open(const Common::String &filename);
bool openSubFile(const Common::String &filename);
bool eof();
@ -67,7 +66,6 @@ public:
uint32 size();
void seek(int32 offs, int whence = SEEK_SET);
uint32 read(void *dataPtr, uint32 dataSize);
uint32 write(const void *dataPtr, uint32 dataSize);
};
class ScummDiskImage : public BaseScummFile {
@ -104,7 +102,7 @@ public:
ScummDiskImage(const char *disk1, const char *disk2, GameSettings game);
void setEnc(byte value);
bool open(const Common::String &filename, AccessMode mode = kFileReadMode);
bool open(const Common::String &filename);
bool openSubFile(const Common::String &filename);
void close();
@ -113,7 +111,6 @@ public:
uint32 size() { return _stream->size(); }
void seek(int32 offs, int whence = SEEK_SET) { _stream->seek(offs, whence); }
uint32 read(void *dataPtr, uint32 dataSize) { return _stream->read(dataPtr, dataSize); }
uint32 write(const void *dataPtr, uint32 dataSize);
};
} // End of namespace Scumm

View file

@ -62,11 +62,6 @@ struct ScummNESFile::Resource {
ScummNESFile::ScummNESFile() : _stream(0), _buf(0), _ROMset(kROMsetNum) {
}
uint32 ScummNESFile::write(const void *, uint32) {
error("ScummNESFile does not support writing!");
return 0;
}
void ScummNESFile::setEnc(byte enc) {
_stream->setEnc(enc);
}
@ -1234,7 +1229,7 @@ bool ScummNESFile::generateIndex() {
return true;
}
bool ScummNESFile::open(const Common::String &filename, AccessMode mode) {
bool ScummNESFile::open(const Common::String &filename) {
if (_ROMset == kROMsetNum) {
char md5str[32+1];
@ -1267,8 +1262,7 @@ bool ScummNESFile::open(const Common::String &filename, AccessMode mode) {
}
}
if (File::open(filename, mode)) {
if (_stream)
if (File::open(filename)) {
delete _stream;
_stream = 0;
@ -1282,7 +1276,6 @@ bool ScummNESFile::open(const Common::String &filename, AccessMode mode) {
}
void ScummNESFile::close() {
if (_stream)
delete _stream;
_stream = 0;

View file

@ -64,7 +64,7 @@ public:
ScummNESFile();
void setEnc(byte value);
bool open(const Common::String &filename, AccessMode mode = kFileReadMode);
bool open(const Common::String &filename);
bool openSubFile(const Common::String &filename);
void close();
@ -73,7 +73,6 @@ public:
uint32 size() { return _stream->size(); }
void seek(int32 offs, int whence = SEEK_SET) { _stream->seek(offs, whence); }
uint32 read(void *dataPtr, uint32 dataSize) { return _stream->read(dataPtr, dataSize); }
uint32 write(const void *dataPtr, uint32 dataSize);
};
} // End of namespace Scumm

View file

@ -1012,7 +1012,7 @@ void ScummEngine_v60he::o60_openFile() {
_hInFileTable[slot] = _saveFileMan->openForLoading(filename);
if (_hInFileTable[slot] == 0) {
Common::File *f = new Common::File();
f->open(filename, Common::File::kFileReadMode);
f->open(filename);
if (!f->isOpen())
delete f;
else

View file

@ -1692,7 +1692,7 @@ void ScummEngine_v72he::o72_openFile() {
_hInFileTable[slot] = _saveFileMan->openForLoading(filename);
if (_hInFileTable[slot] == 0) {
Common::File *f = new Common::File();
f->open(filename, Common::File::kFileReadMode);
f->open(filename);
if (!f->isOpen())
delete f;
else

View file

@ -409,7 +409,7 @@ void ScummEngine_v80he::o80_getFileSize() {
Common::SeekableReadStream *f = _saveFileMan->openForLoading((const char *)filename);
if (!f) {
Common::File *file = new Common::File();
file->open((const char *)filename, Common::File::kFileReadMode);
file->open((const char *)filename);
if (!file->isOpen())
delete f;
else

View file

@ -1881,7 +1881,7 @@ void Wiz::processWizImage(const WizParameters *params) {
memcpy(filename, params->filename, 260);
_vm->convertFilePath(filename);
if (f.open((const char *)filename, Common::File::kFileReadMode)) {
if (f.open((const char *)filename)) {
uint32 id = f.readUint32BE();
if (id == MKID_BE('AWIZ') || id == MKID_BE('MULT')) {
uint32 size = f.readUint32BE();
@ -1911,7 +1911,7 @@ void Wiz::processWizImage(const WizParameters *params) {
break;
case 4:
if (params->processFlags & kWPFUseFile) {
Common::File f;
Common::DumpFile f;
switch (params->fileWriteMode) {
case 2:
@ -1924,7 +1924,7 @@ void Wiz::processWizImage(const WizParameters *params) {
memcpy(filename, params->filename, 260);
_vm->convertFilePath(filename);
if (!f.open((const char *)filename, Common::File::kFileWriteMode)) {
if (!f.open((const char *)filename)) {
debug(0, "Unable to open for write '%s'", filename);
_vm->VAR(119) = -3;
} else {

View file

@ -1299,7 +1299,7 @@ void ScummEngine::allocateArrays() {
void ScummEngine::dumpResource(const char *tag, int idx, const byte *ptr, int length) {
char buf[256];
Common::File out;
Common::DumpFile out;
uint32 size;
if (length >= 0)
@ -1313,7 +1313,7 @@ void ScummEngine::dumpResource(const char *tag, int idx, const byte *ptr, int le
sprintf(buf, "dumps/%s%d.dmp", tag, idx);
out.open(buf, Common::File::kFileWriteMode);
out.open(buf);
if (out.isOpen() == false)
return;
out.write(ptr, size);

View file

@ -326,14 +326,14 @@ void Disk::fnFlushBuffers(void) {
void Disk::dumpFile(uint16 fileNr) {
char buf[128];
Common::File out;
Common::DumpFile out;
byte* filePtr;
filePtr = loadFile(fileNr);
sprintf(buf, "dumps/file-%d.dmp", fileNr);
if (!Common::File::exists(buf)) {
if (out.open(buf, Common::File::kFileWriteMode))
if (out.open(buf))
out.write(filePtr, _lastLoadedFileSize);
}
free(filePtr);

View file

@ -212,8 +212,8 @@ void *ResMan::openFetchRes(uint32 id) {
void ResMan::dumpRes(uint32 id) {
char outn[30];
sprintf(outn, "DUMP%08X.BIN", id);
Common::File outf;
if (outf.open(outn, Common::File::kFileWriteMode)) {
Common::DumpFile outf;
if (outf.open(outn)) {
resOpen(id);
MemHandle *memHandle = resHandle(id);
outf.write(memHandle->data, memHandle->size);

View file

@ -234,7 +234,6 @@ bool ResourceManager::init() {
/**
* Returns the address of a resource. Loads if not in memory. Retains a count.
*/
byte *ResourceManager::openResource(uint32 res, bool dump) {
assert(res < _totalResFiles);
@ -287,7 +286,6 @@ byte *ResourceManager::openResource(uint32 res, bool dump) {
if (dump) {
char buf[256];
const char *tag;
Common::File out;
switch (fetchType(_resList[res].ptr)) {
case ANIMATION_FILE:
@ -337,7 +335,8 @@ byte *ResourceManager::openResource(uint32 res, bool dump) {
sprintf(buf, "dumps/%s-%d.dmp", tag, res);
if (!Common::File::exists(buf)) {
if (out.open(buf, Common::File::kFileWriteMode))
Common::DumpFile out;
if (out.open(buf))
out.write(_resList[res].ptr, len);
}
}

View file

@ -507,7 +507,7 @@ void RestoreMidiFacts(SCNHANDLE Midi, bool Loop) {
// Dumps all of the game's music in external XMIDI *.xmi files
void dumpMusic() {
Common::File midiFile;
Common::File outFile;
Common::DumpFile outFile;
char outName[20];
midiFile.open(MIDI_FILE);
int outFileSize = 0;
@ -519,7 +519,7 @@ void dumpMusic() {
for (int i = 0; i < total; i++) {
sprintf(outName, "track%03d.xmi", i + 1);
outFile.open(outName, Common::File::kFileWriteMode);
outFile.open(outName);
if (_vm->getFeatures() & GF_SCNFILES) {
if (i < total - 1)

View file

@ -585,8 +585,8 @@ NewFont *NewFont::loadFont(Common::SeekableReadStream &stream) {
}
bool NewFont::cacheFontData(const NewFont &font, const Common::String &filename) {
Common::File cacheFile;
if (!cacheFile.open(filename, Common::File::kFileWriteMode)) {
Common::DumpFile cacheFile;
if (!cacheFile.open(filename)) {
warning("Couldn't open file '%s' for writing", filename.c_str());
return false;
}

View file

@ -80,37 +80,41 @@ public:
};
class MT32File : public MT32Emu::File {
Common::File file;
Common::File _in;
Common::DumpFile _out;
public:
bool open(const char *filename, OpenMode mode) {
Common::File::AccessMode accessMode = mode == OpenMode_read ? Common::File::kFileReadMode : Common::File::kFileWriteMode;
return file.open(filename, accessMode);
if (mode == OpenMode_read)
return _in.open(filename);
else
return _out.open(filename);
}
void close() {
return file.close();
_in.close();
_out.close();
}
size_t read(void *in, size_t size) {
return file.read(in, size);
return _in.read(in, size);
}
bool readLine(char *in, size_t size) {
return file.readLine(in, size) != NULL;
return _in.readLine(in, size) != NULL;
}
bool readBit8u(MT32Emu::Bit8u *in) {
byte b = file.readByte();
if (file.eof())
byte b = _in.readByte();
if (_in.eof())
return false;
*in = b;
return true;
}
size_t write(const void *in, size_t size) {
return file.write(in, size);
return _out.write(in, size);
}
bool writeBit8u(MT32Emu::Bit8u out) {
file.writeByte(out);
return !file.ioFailed();
_out.writeByte(out);
return !_out.ioFailed();
}
bool isEOF() {
return file.eof();
return _in.isOpen() ? _in.eof() : _out.eof();
}
};