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:
parent
c9051fcfbd
commit
0be985ce83
30 changed files with 200 additions and 202 deletions
|
@ -58,7 +58,7 @@ void ConfigFile::clear() {
|
||||||
|
|
||||||
bool ConfigFile::loadFromFile(const String &filename) {
|
bool ConfigFile::loadFromFile(const String &filename) {
|
||||||
File file;
|
File file;
|
||||||
if (file.open(filename, File::kFileReadMode))
|
if (file.open(filename))
|
||||||
return loadFromStream(file);
|
return loadFromStream(file);
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
@ -171,8 +171,8 @@ bool ConfigFile::loadFromStream(SeekableReadStream &stream) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfigFile::saveToFile(const String &filename) {
|
bool ConfigFile::saveToFile(const String &filename) {
|
||||||
File file;
|
DumpFile file;
|
||||||
if (file.open(filename, File::kFileWriteMode))
|
if (file.open(filename))
|
||||||
return saveToStream(file);
|
return saveToStream(file);
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -289,13 +289,9 @@ void ConfigManager::loadFile(const String &filename) {
|
||||||
|
|
||||||
void ConfigManager::flushToDisk() {
|
void ConfigManager::flushToDisk() {
|
||||||
#ifndef __DC__
|
#ifndef __DC__
|
||||||
File cfg_file;
|
DumpFile cfg_file;
|
||||||
|
|
||||||
// TODO
|
if (!cfg_file.open(_filename)) {
|
||||||
// if (!willwrite)
|
|
||||||
// return;
|
|
||||||
|
|
||||||
if (!cfg_file.open(_filename, File::kFileWriteMode)) {
|
|
||||||
warning("Unable to write configuration file: %s", _filename.c_str());
|
warning("Unable to write configuration file: %s", _filename.c_str());
|
||||||
} else {
|
} else {
|
||||||
// First write the domains in _domainSaveOrder, in that order.
|
// First write the domains in _domainSaveOrder, in that order.
|
||||||
|
|
170
common/file.cpp
170
common/file.cpp
|
@ -104,7 +104,7 @@
|
||||||
//#define fgets(str, size, file) DS::std_fgets(str, size, file) // not used
|
//#define fgets(str, size, file) DS::std_fgets(str, size, file) // not used
|
||||||
//#define getc(handle) DS::std_getc(handle) // not used
|
//#define getc(handle) DS::std_getc(handle) // not used
|
||||||
//#define getcwd(dir, dunno) DS::std_getcwd(dir, dunno) // 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
|
#endif
|
||||||
|
|
||||||
|
@ -273,26 +273,14 @@ File::File()
|
||||||
: _handle(0), _ioFailed(false) {
|
: _handle(0), _ioFailed(false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//#define DEBUG_FILE_REFCOUNT
|
|
||||||
|
|
||||||
File::~File() {
|
File::~File() {
|
||||||
#ifdef DEBUG_FILE_REFCOUNT
|
|
||||||
warning("File::~File on file '%s'", _name.c_str());
|
|
||||||
#endif
|
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool File::open(const String &filename, AccessMode mode) {
|
bool File::open(const String &filename) {
|
||||||
assert(mode == kFileReadMode || mode == kFileWriteMode);
|
assert(!filename.empty());
|
||||||
|
assert(!_handle);
|
||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
_name.clear();
|
_name.clear();
|
||||||
clearIOFailed();
|
clearIOFailed();
|
||||||
|
@ -300,32 +288,29 @@ bool File::open(const String &filename, AccessMode mode) {
|
||||||
String fname(filename);
|
String fname(filename);
|
||||||
fname.toLowercase();
|
fname.toLowercase();
|
||||||
|
|
||||||
const char *modeStr = (mode == kFileReadMode) ? "rb" : "wb";
|
if (_filesMap && _filesMap->contains(fname)) {
|
||||||
if (mode == kFileWriteMode) {
|
|
||||||
_handle = fopenNoCase(filename, "", modeStr);
|
|
||||||
} else if (_filesMap && _filesMap->contains(fname)) {
|
|
||||||
fname = (*_filesMap)[fname];
|
fname = (*_filesMap)[fname];
|
||||||
debug(3, "Opening hashed: %s", fname.c_str());
|
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 + ".")) {
|
} else if (_filesMap && _filesMap->contains(fname + ".")) {
|
||||||
// WORKAROUND: Bug #1458388: "SIMON1: Game Detection fails"
|
// WORKAROUND: Bug #1458388: "SIMON1: Game Detection fails"
|
||||||
// sometimes instead of "GAMEPC" we get "GAMEPC." (note trailing dot)
|
// sometimes instead of "GAMEPC" we get "GAMEPC." (note trailing dot)
|
||||||
fname = (*_filesMap)[fname + "."];
|
fname = (*_filesMap)[fname + "."];
|
||||||
debug(3, "Opening hashed: %s", fname.c_str());
|
debug(3, "Opening hashed: %s", fname.c_str());
|
||||||
_handle = fopen(fname.c_str(), modeStr);
|
_handle = fopen(fname.c_str(), "rb");
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (_defaultDirectories) {
|
if (_defaultDirectories) {
|
||||||
// Try all default directories
|
// Try all default directories
|
||||||
StringIntMap::const_iterator x(_defaultDirectories->begin());
|
StringIntMap::const_iterator x(_defaultDirectories->begin());
|
||||||
for (; _handle == NULL && x != _defaultDirectories->end(); ++x) {
|
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
|
// Last resort: try the current directory
|
||||||
if (_handle == NULL)
|
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.
|
// Last last (really) resort: try looking inside the application bundle on Mac OS X for the lowercase file.
|
||||||
#if defined(MACOSX) || defined(IPHONE)
|
#if defined(MACOSX) || defined(IPHONE)
|
||||||
|
@ -335,7 +320,7 @@ bool File::open(const String &filename, AccessMode mode) {
|
||||||
if (fileUrl) {
|
if (fileUrl) {
|
||||||
UInt8 buf[256];
|
UInt8 buf[256];
|
||||||
if (CFURLGetFileSystemRepresentation(fileUrl, false, (UInt8 *)buf, 256)) {
|
if (CFURLGetFileSystemRepresentation(fileUrl, false, (UInt8 *)buf, 256)) {
|
||||||
_handle = fopen((char *)buf, modeStr);
|
_handle = fopen((char *)buf, "rb");
|
||||||
}
|
}
|
||||||
CFRelease(fileUrl);
|
CFRelease(fileUrl);
|
||||||
}
|
}
|
||||||
|
@ -345,26 +330,15 @@ bool File::open(const String &filename, AccessMode mode) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_handle == NULL) {
|
if (_handle == NULL)
|
||||||
if (mode == kFileReadMode)
|
debug(2, "File %s not opened", filename.c_str());
|
||||||
debug(2, "File %s not found", filename.c_str());
|
else
|
||||||
else
|
_name = filename;
|
||||||
debug(2, "File %s not opened", filename.c_str());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return _handle != NULL;
|
||||||
_name = filename;
|
|
||||||
|
|
||||||
#ifdef DEBUG_FILE_REFCOUNT
|
|
||||||
warning("File::open on file '%s'", _name.c_str());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool File::open(const FilesystemNode &node, AccessMode mode) {
|
bool File::open(const FilesystemNode &node) {
|
||||||
assert(mode == kFileReadMode || mode == kFileWriteMode);
|
|
||||||
|
|
||||||
if (!node.exists()) {
|
if (!node.exists()) {
|
||||||
warning("File::open: Trying to open a FilesystemNode which does not exist");
|
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();
|
clearIOFailed();
|
||||||
_name.clear();
|
_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)
|
||||||
|
debug(2, "File %s not found", filename.c_str());
|
||||||
|
else
|
||||||
|
_name = filename;
|
||||||
|
|
||||||
if (_handle == NULL) {
|
return _handle != NULL;
|
||||||
if (mode == kFileReadMode)
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool File::exists(const String &filename) {
|
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
|
//Try opening the file inside the local directory as a last resort
|
||||||
File tmp;
|
File tmp;
|
||||||
return tmp.open(filename, kFileReadMode);
|
return tmp.open(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
void File::close() {
|
void File::close() {
|
||||||
|
@ -462,28 +425,19 @@ void File::clearIOFailed() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool File::eof() const {
|
bool File::eof() const {
|
||||||
if (_handle == NULL) {
|
assert(_handle);
|
||||||
error("File::eof: File is not open!");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return feof((FILE *)_handle) != 0;
|
return feof((FILE *)_handle) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 File::pos() const {
|
uint32 File::pos() const {
|
||||||
if (_handle == NULL) {
|
assert(_handle);
|
||||||
error("File::pos: File is not open!");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ftell((FILE *)_handle);
|
return ftell((FILE *)_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 File::size() const {
|
uint32 File::size() const {
|
||||||
if (_handle == NULL) {
|
assert(_handle);
|
||||||
error("File::size: File is not open!");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32 oldPos = ftell((FILE *)_handle);
|
uint32 oldPos = ftell((FILE *)_handle);
|
||||||
fseek((FILE *)_handle, 0, SEEK_END);
|
fseek((FILE *)_handle, 0, SEEK_END);
|
||||||
|
@ -494,10 +448,7 @@ uint32 File::size() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void File::seek(int32 offs, int whence) {
|
void File::seek(int32 offs, int whence) {
|
||||||
if (_handle == NULL) {
|
assert(_handle);
|
||||||
error("File::seek: File is not open!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fseek((FILE *)_handle, offs, whence) != 0)
|
if (fseek((FILE *)_handle, offs, whence) != 0)
|
||||||
clearerr((FILE *)_handle);
|
clearerr((FILE *)_handle);
|
||||||
|
@ -507,10 +458,7 @@ uint32 File::read(void *ptr, uint32 len) {
|
||||||
byte *ptr2 = (byte *)ptr;
|
byte *ptr2 = (byte *)ptr;
|
||||||
uint32 real_len;
|
uint32 real_len;
|
||||||
|
|
||||||
if (_handle == NULL) {
|
assert(_handle);
|
||||||
error("File::read: File is not open!");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -523,20 +471,62 @@ uint32 File::read(void *ptr, uint32 len) {
|
||||||
return real_len;
|
return real_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 File::write(const void *ptr, uint32 len) {
|
|
||||||
if (_handle == NULL) {
|
DumpFile::DumpFile() : _handle(0) {
|
||||||
error("File::write: File is not open!");
|
}
|
||||||
return 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)
|
if (len == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if ((uint32)fwrite(ptr, 1, len, (FILE *)_handle) != len) {
|
return (uint32)fwrite(ptr, 1, len, (FILE *)_handle);
|
||||||
_ioFailed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return len;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // End of namespace Common
|
} // End of namespace Common
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#define COMMON_FILE_H
|
#define COMMON_FILE_H
|
||||||
|
|
||||||
#include "common/scummsys.h"
|
#include "common/scummsys.h"
|
||||||
|
#include "common/noncopyable.h"
|
||||||
#include "common/str.h"
|
#include "common/str.h"
|
||||||
#include "common/stream.h"
|
#include "common/stream.h"
|
||||||
|
|
||||||
|
@ -34,7 +35,10 @@ class FilesystemNode;
|
||||||
|
|
||||||
namespace Common {
|
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:
|
protected:
|
||||||
/** File handle to the actual file; 0 if no file is open. */
|
/** File handle to the actual file; 0 if no file is open. */
|
||||||
void *_handle;
|
void *_handle;
|
||||||
|
@ -45,19 +49,7 @@ protected:
|
||||||
/** The name of this file, for debugging. */
|
/** The name of this file, for debugging. */
|
||||||
String _name;
|
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:
|
public:
|
||||||
enum AccessMode {
|
|
||||||
kFileReadMode = 1,
|
|
||||||
kFileWriteMode = 2
|
|
||||||
};
|
|
||||||
|
|
||||||
static void addDefaultDirectory(const String &directory);
|
static void addDefaultDirectory(const String &directory);
|
||||||
static void addDefaultDirectoryRecursive(const String &directory, int level = 4, const String &prefix = "");
|
static void addDefaultDirectoryRecursive(const String &directory, int level = 4, const String &prefix = "");
|
||||||
|
@ -80,8 +72,8 @@ public:
|
||||||
*/
|
*/
|
||||||
static bool exists(const String &filename);
|
static bool exists(const String &filename);
|
||||||
|
|
||||||
virtual bool open(const String &filename, AccessMode mode = kFileReadMode);
|
virtual bool open(const String &filename);
|
||||||
virtual bool open(const FilesystemNode &node, AccessMode mode = kFileReadMode);
|
virtual bool open(const FilesystemNode &node);
|
||||||
|
|
||||||
virtual void close();
|
virtual void close();
|
||||||
|
|
||||||
|
@ -114,9 +106,52 @@ public:
|
||||||
virtual uint32 size() const;
|
virtual uint32 size() const;
|
||||||
void seek(int32 offs, int whence = SEEK_SET);
|
void seek(int32 offs, int whence = SEEK_SET);
|
||||||
uint32 read(void *dataPtr, uint32 dataSize);
|
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);
|
uint32 write(const void *dataPtr, uint32 dataSize);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // End of namespace Common
|
} // End of namespace Common
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -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)
|
if (_isOpen)
|
||||||
error("Attempt to open another instance of archive");
|
error("Attempt to open another instance of archive");
|
||||||
|
|
||||||
|
|
|
@ -110,7 +110,7 @@ public:
|
||||||
|
|
||||||
void registerArchive(const String &filename);
|
void registerArchive(const String &filename);
|
||||||
|
|
||||||
bool open(const Common::String &filename, AccessMode mode = kFileReadMode);
|
bool open(const Common::String &filename);
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
uint32 read(void *dataPtr, uint32 dataSize);
|
uint32 read(void *dataPtr, uint32 dataSize);
|
||||||
|
|
|
@ -393,11 +393,11 @@ static const byte bmp_hdr[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
void dumpBMP(const char *filename, int w, int h, const byte *bytes, const uint32 *palette) {
|
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)];
|
byte my_hdr[sizeof(bmp_hdr)];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
out.open(filename, Common::File::kFileWriteMode);
|
out.open(filename);
|
||||||
if (!out.isOpen())
|
if (!out.isOpen())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -978,7 +978,7 @@ bool AGOSEngine::loadGame(const char *filename, bool restartMode) {
|
||||||
if (restartMode) {
|
if (restartMode) {
|
||||||
// Load restart state
|
// Load restart state
|
||||||
Common::File *file = new Common::File();
|
Common::File *file = new Common::File();
|
||||||
file->open(filename, Common::File::kFileReadMode);
|
file->open(filename);
|
||||||
f = file;
|
f = file;
|
||||||
} else {
|
} else {
|
||||||
f = _saveFileMan->openForLoading(filename);
|
f = _saveFileMan->openForLoading(filename);
|
||||||
|
@ -1154,7 +1154,7 @@ bool AGOSEngine_Elvira2::loadGame(const char *filename, bool restartMode) {
|
||||||
if (restartMode) {
|
if (restartMode) {
|
||||||
// Load restart state
|
// Load restart state
|
||||||
Common::File *file = new Common::File();
|
Common::File *file = new Common::File();
|
||||||
file->open(filename, Common::File::kFileReadMode);
|
file->open(filename);
|
||||||
f = file;
|
f = file;
|
||||||
} else {
|
} else {
|
||||||
f = _saveFileMan->openForLoading(filename);
|
f = _saveFileMan->openForLoading(filename);
|
||||||
|
|
|
@ -289,8 +289,8 @@ void dumpBundle(const char *fileName) {
|
||||||
|
|
||||||
debug(0, "%s", partBuffer[i].partName);
|
debug(0, "%s", partBuffer[i].partName);
|
||||||
|
|
||||||
Common::File out;
|
Common::DumpFile out;
|
||||||
if (out.open(Common::String("dumps/") + partBuffer[i].partName, Common::File::kFileWriteMode)) {
|
if (out.open(Common::String("dumps/") + partBuffer[i].partName)) {
|
||||||
out.write(data, partBuffer[i].unpackedSize);
|
out.write(data, partBuffer[i].unpackedSize);
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2957,10 +2957,10 @@ void decompileScript(const byte *scriptPtr, uint16 scriptSize, uint16 scriptIdx)
|
||||||
}
|
}
|
||||||
|
|
||||||
void dumpScript(char *dumpName) {
|
void dumpScript(char *dumpName) {
|
||||||
Common::File fHandle;
|
Common::DumpFile fHandle;
|
||||||
uint16 i;
|
uint16 i;
|
||||||
|
|
||||||
fHandle.open(dumpName, Common::File::kFileWriteMode);
|
fHandle.open(dumpName);
|
||||||
|
|
||||||
for (i = 0; i < decompileBufferPosition; i++) {
|
for (i = 0; i < decompileBufferPosition; i++) {
|
||||||
fHandle.writeString(Common::String(decompileBuffer[i]));
|
fHandle.writeString(Common::String(decompileBuffer[i]));
|
||||||
|
|
|
@ -456,8 +456,8 @@ int16 readVolCnf(void) {
|
||||||
sprintf(nameBuffer, "%s", buffer[j].name);
|
sprintf(nameBuffer, "%s", buffer[j].name);
|
||||||
|
|
||||||
if (buffer[j].size == buffer[j].extSize) {
|
if (buffer[j].size == buffer[j].extSize) {
|
||||||
Common::File fout;
|
Common::DumpFile fout;
|
||||||
fout.open(nameBuffer, Common::File::kFileWriteMode);
|
fout.open(nameBuffer);
|
||||||
if(fout.isOpen())
|
if(fout.isOpen())
|
||||||
fout.write(bufferLocal, buffer[j].size);
|
fout.write(bufferLocal, buffer[j].size);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -202,7 +202,7 @@ const Common::File *DataIO::file_getHandle(int16 handle) const {
|
||||||
return &_filesHandles[handle];
|
return &_filesHandles[handle];
|
||||||
}
|
}
|
||||||
|
|
||||||
int16 DataIO::file_open(const char *path, Common::File::AccessMode mode) {
|
int16 DataIO::file_open(const char *path) {
|
||||||
int16 i;
|
int16 i;
|
||||||
|
|
||||||
for (i = 0; i < MAX_FILES; 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)
|
if (i == MAX_FILES)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
file_getHandle(i)->open(path, mode);
|
file_getHandle(i)->open(path);
|
||||||
|
|
||||||
if (file_getHandle(i)->isOpen())
|
if (file_getHandle(i)->isOpen())
|
||||||
return i;
|
return i;
|
||||||
|
@ -467,17 +467,14 @@ void DataIO::closeData(int16 handle) {
|
||||||
file_getHandle(handle)->close();
|
file_getHandle(handle)->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
int16 DataIO::openData(const char *path, Common::File::AccessMode mode) {
|
int16 DataIO::openData(const char *path) {
|
||||||
int16 handle;
|
int16 handle;
|
||||||
|
|
||||||
if (mode != Common::File::kFileReadMode)
|
|
||||||
return file_open(path, mode);
|
|
||||||
|
|
||||||
handle = getChunk(path);
|
handle = getChunk(path);
|
||||||
if (handle >= 0)
|
if (handle >= 0)
|
||||||
return handle;
|
return handle;
|
||||||
|
|
||||||
return file_open(path, mode);
|
return file_open(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
DataStream *DataIO::openAsStream(int16 handle, bool dispose) {
|
DataStream *DataIO::openAsStream(int16 handle, bool dispose) {
|
||||||
|
|
|
@ -79,8 +79,7 @@ public:
|
||||||
void closeDataFile(bool itk = 0);
|
void closeDataFile(bool itk = 0);
|
||||||
byte *getUnpackedData(const char *name);
|
byte *getUnpackedData(const char *name);
|
||||||
void closeData(int16 handle);
|
void closeData(int16 handle);
|
||||||
int16 openData(const char *path,
|
int16 openData(const char *path);
|
||||||
Common::File::AccessMode mode = Common::File::kFileReadMode);
|
|
||||||
DataStream *openAsStream(int16 handle, bool dispose = false);
|
DataStream *openAsStream(int16 handle, bool dispose = false);
|
||||||
|
|
||||||
int32 getDataSize(const char *name);
|
int32 getDataSize(const char *name);
|
||||||
|
@ -104,8 +103,7 @@ protected:
|
||||||
|
|
||||||
class GobEngine *_vm;
|
class GobEngine *_vm;
|
||||||
|
|
||||||
int16 file_open(const char *path,
|
int16 file_open(const char *path);
|
||||||
Common::File::AccessMode mode = Common::File::kFileReadMode);
|
|
||||||
Common::File *file_getHandle(int16 handle);
|
Common::File *file_getHandle(int16 handle);
|
||||||
const Common::File *file_getHandle(int16 handle) const;
|
const Common::File *file_getHandle(int16 handle) const;
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ void ScummEngine::loadCJKFont() {
|
||||||
_2byteWidth = 16;
|
_2byteWidth = 16;
|
||||||
_2byteHeight = 16;
|
_2byteHeight = 16;
|
||||||
// use FM-TOWNS font rom, since game files don't have kanji font resources
|
// 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;
|
_useCJKMode = true;
|
||||||
debug(2, "Loading FM-TOWNS Kanji rom");
|
debug(2, "Loading FM-TOWNS Kanji rom");
|
||||||
_2byteFontPtr = new byte[((_2byteWidth + 7) / 8) * _2byteHeight * numChar];
|
_2byteFontPtr = new byte[((_2byteWidth + 7) / 8) * _2byteHeight * numChar];
|
||||||
|
|
|
@ -298,7 +298,7 @@ bool ScummDebugger::Cmd_ImportRes(int argc, const char** argv) {
|
||||||
// FIXME add bounds check
|
// FIXME add bounds check
|
||||||
|
|
||||||
if (!strncmp(argv[1], "scr", 3)) {
|
if (!strncmp(argv[1], "scr", 3)) {
|
||||||
file.open(argv[2], Common::File::kFileReadMode);
|
file.open(argv[2]);
|
||||||
if (file.isOpen() == false) {
|
if (file.isOpen() == false) {
|
||||||
DebugPrintf("Could not open file %s\n", argv[2]);
|
DebugPrintf("Could not open file %s\n", argv[2]);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -58,8 +58,8 @@ void ScummFile::resetSubfile() {
|
||||||
seek(0, SEEK_SET);
|
seek(0, SEEK_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScummFile::open(const Common::String &filename, AccessMode mode) {
|
bool ScummFile::open(const Common::String &filename) {
|
||||||
if (File::open(filename, mode)) {
|
if (File::open(filename)) {
|
||||||
resetSubfile();
|
resetSubfile();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -187,11 +187,6 @@ uint32 ScummFile::read(void *dataPtr, uint32 dataSize) {
|
||||||
return realLen;
|
return realLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 ScummFile::write(const void *, uint32) {
|
|
||||||
error("ScummFile does not support writing!");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma mark -
|
#pragma mark -
|
||||||
#pragma mark --- ScummDiskImage ---
|
#pragma mark --- ScummDiskImage ---
|
||||||
#pragma mark -
|
#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) {
|
void ScummDiskImage::setEnc(byte enc) {
|
||||||
_stream->setEnc(enc);
|
_stream->setEnc(enc);
|
||||||
}
|
}
|
||||||
|
@ -300,7 +290,7 @@ bool ScummDiskImage::openDisk(char num) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScummDiskImage::open(const Common::String &filename, AccessMode mode) {
|
bool ScummDiskImage::open(const Common::String &filename) {
|
||||||
uint16 signature;
|
uint16 signature;
|
||||||
|
|
||||||
// check signature
|
// check signature
|
||||||
|
|
|
@ -36,7 +36,7 @@ class BaseScummFile : public Common::File {
|
||||||
public:
|
public:
|
||||||
virtual void setEnc(byte value) = 0;
|
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 openSubFile(const Common::String &filename) = 0;
|
||||||
|
|
||||||
virtual bool eof() = 0;
|
virtual bool eof() = 0;
|
||||||
|
@ -44,7 +44,6 @@ public:
|
||||||
virtual uint32 size() = 0;
|
virtual uint32 size() = 0;
|
||||||
virtual void seek(int32 offs, int whence = SEEK_SET) = 0;
|
virtual void seek(int32 offs, int whence = SEEK_SET) = 0;
|
||||||
virtual uint32 read(void *dataPtr, uint32 dataSize) = 0;
|
virtual uint32 read(void *dataPtr, uint32 dataSize) = 0;
|
||||||
virtual uint32 write(const void *dataPtr, uint32 dataSize) = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class ScummFile : public BaseScummFile {
|
class ScummFile : public BaseScummFile {
|
||||||
|
@ -59,7 +58,7 @@ public:
|
||||||
void setSubfileRange(uint32 start, uint32 len);
|
void setSubfileRange(uint32 start, uint32 len);
|
||||||
void resetSubfile();
|
void resetSubfile();
|
||||||
|
|
||||||
bool open(const Common::String &filename, AccessMode mode = kFileReadMode);
|
bool open(const Common::String &filename);
|
||||||
bool openSubFile(const Common::String &filename);
|
bool openSubFile(const Common::String &filename);
|
||||||
|
|
||||||
bool eof();
|
bool eof();
|
||||||
|
@ -67,7 +66,6 @@ public:
|
||||||
uint32 size();
|
uint32 size();
|
||||||
void seek(int32 offs, int whence = SEEK_SET);
|
void seek(int32 offs, int whence = SEEK_SET);
|
||||||
uint32 read(void *dataPtr, uint32 dataSize);
|
uint32 read(void *dataPtr, uint32 dataSize);
|
||||||
uint32 write(const void *dataPtr, uint32 dataSize);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class ScummDiskImage : public BaseScummFile {
|
class ScummDiskImage : public BaseScummFile {
|
||||||
|
@ -104,7 +102,7 @@ public:
|
||||||
ScummDiskImage(const char *disk1, const char *disk2, GameSettings game);
|
ScummDiskImage(const char *disk1, const char *disk2, GameSettings game);
|
||||||
void setEnc(byte value);
|
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);
|
bool openSubFile(const Common::String &filename);
|
||||||
|
|
||||||
void close();
|
void close();
|
||||||
|
@ -113,7 +111,6 @@ public:
|
||||||
uint32 size() { return _stream->size(); }
|
uint32 size() { return _stream->size(); }
|
||||||
void seek(int32 offs, int whence = SEEK_SET) { _stream->seek(offs, whence); }
|
void seek(int32 offs, int whence = SEEK_SET) { _stream->seek(offs, whence); }
|
||||||
uint32 read(void *dataPtr, uint32 dataSize) { return _stream->read(dataPtr, dataSize); }
|
uint32 read(void *dataPtr, uint32 dataSize) { return _stream->read(dataPtr, dataSize); }
|
||||||
uint32 write(const void *dataPtr, uint32 dataSize);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // End of namespace Scumm
|
} // End of namespace Scumm
|
||||||
|
|
|
@ -62,11 +62,6 @@ struct ScummNESFile::Resource {
|
||||||
ScummNESFile::ScummNESFile() : _stream(0), _buf(0), _ROMset(kROMsetNum) {
|
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) {
|
void ScummNESFile::setEnc(byte enc) {
|
||||||
_stream->setEnc(enc);
|
_stream->setEnc(enc);
|
||||||
}
|
}
|
||||||
|
@ -1234,7 +1229,7 @@ bool ScummNESFile::generateIndex() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScummNESFile::open(const Common::String &filename, AccessMode mode) {
|
bool ScummNESFile::open(const Common::String &filename) {
|
||||||
|
|
||||||
if (_ROMset == kROMsetNum) {
|
if (_ROMset == kROMsetNum) {
|
||||||
char md5str[32+1];
|
char md5str[32+1];
|
||||||
|
@ -1267,9 +1262,8 @@ bool ScummNESFile::open(const Common::String &filename, AccessMode mode) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (File::open(filename, mode)) {
|
if (File::open(filename)) {
|
||||||
if (_stream)
|
delete _stream;
|
||||||
delete _stream;
|
|
||||||
_stream = 0;
|
_stream = 0;
|
||||||
|
|
||||||
free(_buf);
|
free(_buf);
|
||||||
|
@ -1282,8 +1276,7 @@ bool ScummNESFile::open(const Common::String &filename, AccessMode mode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScummNESFile::close() {
|
void ScummNESFile::close() {
|
||||||
if (_stream)
|
delete _stream;
|
||||||
delete _stream;
|
|
||||||
_stream = 0;
|
_stream = 0;
|
||||||
|
|
||||||
free(_buf);
|
free(_buf);
|
||||||
|
|
|
@ -64,7 +64,7 @@ public:
|
||||||
ScummNESFile();
|
ScummNESFile();
|
||||||
void setEnc(byte value);
|
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);
|
bool openSubFile(const Common::String &filename);
|
||||||
|
|
||||||
void close();
|
void close();
|
||||||
|
@ -73,7 +73,6 @@ public:
|
||||||
uint32 size() { return _stream->size(); }
|
uint32 size() { return _stream->size(); }
|
||||||
void seek(int32 offs, int whence = SEEK_SET) { _stream->seek(offs, whence); }
|
void seek(int32 offs, int whence = SEEK_SET) { _stream->seek(offs, whence); }
|
||||||
uint32 read(void *dataPtr, uint32 dataSize) { return _stream->read(dataPtr, dataSize); }
|
uint32 read(void *dataPtr, uint32 dataSize) { return _stream->read(dataPtr, dataSize); }
|
||||||
uint32 write(const void *dataPtr, uint32 dataSize);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // End of namespace Scumm
|
} // End of namespace Scumm
|
||||||
|
|
|
@ -1012,7 +1012,7 @@ void ScummEngine_v60he::o60_openFile() {
|
||||||
_hInFileTable[slot] = _saveFileMan->openForLoading(filename);
|
_hInFileTable[slot] = _saveFileMan->openForLoading(filename);
|
||||||
if (_hInFileTable[slot] == 0) {
|
if (_hInFileTable[slot] == 0) {
|
||||||
Common::File *f = new Common::File();
|
Common::File *f = new Common::File();
|
||||||
f->open(filename, Common::File::kFileReadMode);
|
f->open(filename);
|
||||||
if (!f->isOpen())
|
if (!f->isOpen())
|
||||||
delete f;
|
delete f;
|
||||||
else
|
else
|
||||||
|
|
|
@ -1692,7 +1692,7 @@ void ScummEngine_v72he::o72_openFile() {
|
||||||
_hInFileTable[slot] = _saveFileMan->openForLoading(filename);
|
_hInFileTable[slot] = _saveFileMan->openForLoading(filename);
|
||||||
if (_hInFileTable[slot] == 0) {
|
if (_hInFileTable[slot] == 0) {
|
||||||
Common::File *f = new Common::File();
|
Common::File *f = new Common::File();
|
||||||
f->open(filename, Common::File::kFileReadMode);
|
f->open(filename);
|
||||||
if (!f->isOpen())
|
if (!f->isOpen())
|
||||||
delete f;
|
delete f;
|
||||||
else
|
else
|
||||||
|
|
|
@ -409,7 +409,7 @@ void ScummEngine_v80he::o80_getFileSize() {
|
||||||
Common::SeekableReadStream *f = _saveFileMan->openForLoading((const char *)filename);
|
Common::SeekableReadStream *f = _saveFileMan->openForLoading((const char *)filename);
|
||||||
if (!f) {
|
if (!f) {
|
||||||
Common::File *file = new Common::File();
|
Common::File *file = new Common::File();
|
||||||
file->open((const char *)filename, Common::File::kFileReadMode);
|
file->open((const char *)filename);
|
||||||
if (!file->isOpen())
|
if (!file->isOpen())
|
||||||
delete f;
|
delete f;
|
||||||
else
|
else
|
||||||
|
|
|
@ -1881,7 +1881,7 @@ void Wiz::processWizImage(const WizParameters *params) {
|
||||||
memcpy(filename, params->filename, 260);
|
memcpy(filename, params->filename, 260);
|
||||||
_vm->convertFilePath(filename);
|
_vm->convertFilePath(filename);
|
||||||
|
|
||||||
if (f.open((const char *)filename, Common::File::kFileReadMode)) {
|
if (f.open((const char *)filename)) {
|
||||||
uint32 id = f.readUint32BE();
|
uint32 id = f.readUint32BE();
|
||||||
if (id == MKID_BE('AWIZ') || id == MKID_BE('MULT')) {
|
if (id == MKID_BE('AWIZ') || id == MKID_BE('MULT')) {
|
||||||
uint32 size = f.readUint32BE();
|
uint32 size = f.readUint32BE();
|
||||||
|
@ -1911,7 +1911,7 @@ void Wiz::processWizImage(const WizParameters *params) {
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
if (params->processFlags & kWPFUseFile) {
|
if (params->processFlags & kWPFUseFile) {
|
||||||
Common::File f;
|
Common::DumpFile f;
|
||||||
|
|
||||||
switch (params->fileWriteMode) {
|
switch (params->fileWriteMode) {
|
||||||
case 2:
|
case 2:
|
||||||
|
@ -1924,7 +1924,7 @@ void Wiz::processWizImage(const WizParameters *params) {
|
||||||
memcpy(filename, params->filename, 260);
|
memcpy(filename, params->filename, 260);
|
||||||
_vm->convertFilePath(filename);
|
_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);
|
debug(0, "Unable to open for write '%s'", filename);
|
||||||
_vm->VAR(119) = -3;
|
_vm->VAR(119) = -3;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1299,7 +1299,7 @@ void ScummEngine::allocateArrays() {
|
||||||
|
|
||||||
void ScummEngine::dumpResource(const char *tag, int idx, const byte *ptr, int length) {
|
void ScummEngine::dumpResource(const char *tag, int idx, const byte *ptr, int length) {
|
||||||
char buf[256];
|
char buf[256];
|
||||||
Common::File out;
|
Common::DumpFile out;
|
||||||
|
|
||||||
uint32 size;
|
uint32 size;
|
||||||
if (length >= 0)
|
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);
|
sprintf(buf, "dumps/%s%d.dmp", tag, idx);
|
||||||
|
|
||||||
out.open(buf, Common::File::kFileWriteMode);
|
out.open(buf);
|
||||||
if (out.isOpen() == false)
|
if (out.isOpen() == false)
|
||||||
return;
|
return;
|
||||||
out.write(ptr, size);
|
out.write(ptr, size);
|
||||||
|
|
|
@ -326,14 +326,14 @@ void Disk::fnFlushBuffers(void) {
|
||||||
|
|
||||||
void Disk::dumpFile(uint16 fileNr) {
|
void Disk::dumpFile(uint16 fileNr) {
|
||||||
char buf[128];
|
char buf[128];
|
||||||
Common::File out;
|
Common::DumpFile out;
|
||||||
byte* filePtr;
|
byte* filePtr;
|
||||||
|
|
||||||
filePtr = loadFile(fileNr);
|
filePtr = loadFile(fileNr);
|
||||||
sprintf(buf, "dumps/file-%d.dmp", fileNr);
|
sprintf(buf, "dumps/file-%d.dmp", fileNr);
|
||||||
|
|
||||||
if (!Common::File::exists(buf)) {
|
if (!Common::File::exists(buf)) {
|
||||||
if (out.open(buf, Common::File::kFileWriteMode))
|
if (out.open(buf))
|
||||||
out.write(filePtr, _lastLoadedFileSize);
|
out.write(filePtr, _lastLoadedFileSize);
|
||||||
}
|
}
|
||||||
free(filePtr);
|
free(filePtr);
|
||||||
|
|
|
@ -212,8 +212,8 @@ void *ResMan::openFetchRes(uint32 id) {
|
||||||
void ResMan::dumpRes(uint32 id) {
|
void ResMan::dumpRes(uint32 id) {
|
||||||
char outn[30];
|
char outn[30];
|
||||||
sprintf(outn, "DUMP%08X.BIN", id);
|
sprintf(outn, "DUMP%08X.BIN", id);
|
||||||
Common::File outf;
|
Common::DumpFile outf;
|
||||||
if (outf.open(outn, Common::File::kFileWriteMode)) {
|
if (outf.open(outn)) {
|
||||||
resOpen(id);
|
resOpen(id);
|
||||||
MemHandle *memHandle = resHandle(id);
|
MemHandle *memHandle = resHandle(id);
|
||||||
outf.write(memHandle->data, memHandle->size);
|
outf.write(memHandle->data, memHandle->size);
|
||||||
|
|
|
@ -234,7 +234,6 @@ bool ResourceManager::init() {
|
||||||
/**
|
/**
|
||||||
* Returns the address of a resource. Loads if not in memory. Retains a count.
|
* Returns the address of a resource. Loads if not in memory. Retains a count.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
byte *ResourceManager::openResource(uint32 res, bool dump) {
|
byte *ResourceManager::openResource(uint32 res, bool dump) {
|
||||||
assert(res < _totalResFiles);
|
assert(res < _totalResFiles);
|
||||||
|
|
||||||
|
@ -287,7 +286,6 @@ byte *ResourceManager::openResource(uint32 res, bool dump) {
|
||||||
if (dump) {
|
if (dump) {
|
||||||
char buf[256];
|
char buf[256];
|
||||||
const char *tag;
|
const char *tag;
|
||||||
Common::File out;
|
|
||||||
|
|
||||||
switch (fetchType(_resList[res].ptr)) {
|
switch (fetchType(_resList[res].ptr)) {
|
||||||
case ANIMATION_FILE:
|
case ANIMATION_FILE:
|
||||||
|
@ -337,7 +335,8 @@ byte *ResourceManager::openResource(uint32 res, bool dump) {
|
||||||
sprintf(buf, "dumps/%s-%d.dmp", tag, res);
|
sprintf(buf, "dumps/%s-%d.dmp", tag, res);
|
||||||
|
|
||||||
if (!Common::File::exists(buf)) {
|
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);
|
out.write(_resList[res].ptr, len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -507,7 +507,7 @@ void RestoreMidiFacts(SCNHANDLE Midi, bool Loop) {
|
||||||
// Dumps all of the game's music in external XMIDI *.xmi files
|
// Dumps all of the game's music in external XMIDI *.xmi files
|
||||||
void dumpMusic() {
|
void dumpMusic() {
|
||||||
Common::File midiFile;
|
Common::File midiFile;
|
||||||
Common::File outFile;
|
Common::DumpFile outFile;
|
||||||
char outName[20];
|
char outName[20];
|
||||||
midiFile.open(MIDI_FILE);
|
midiFile.open(MIDI_FILE);
|
||||||
int outFileSize = 0;
|
int outFileSize = 0;
|
||||||
|
@ -519,7 +519,7 @@ void dumpMusic() {
|
||||||
|
|
||||||
for (int i = 0; i < total; i++) {
|
for (int i = 0; i < total; i++) {
|
||||||
sprintf(outName, "track%03d.xmi", i + 1);
|
sprintf(outName, "track%03d.xmi", i + 1);
|
||||||
outFile.open(outName, Common::File::kFileWriteMode);
|
outFile.open(outName);
|
||||||
|
|
||||||
if (_vm->getFeatures() & GF_SCNFILES) {
|
if (_vm->getFeatures() & GF_SCNFILES) {
|
||||||
if (i < total - 1)
|
if (i < total - 1)
|
||||||
|
|
|
@ -585,8 +585,8 @@ NewFont *NewFont::loadFont(Common::SeekableReadStream &stream) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NewFont::cacheFontData(const NewFont &font, const Common::String &filename) {
|
bool NewFont::cacheFontData(const NewFont &font, const Common::String &filename) {
|
||||||
Common::File cacheFile;
|
Common::DumpFile cacheFile;
|
||||||
if (!cacheFile.open(filename, Common::File::kFileWriteMode)) {
|
if (!cacheFile.open(filename)) {
|
||||||
warning("Couldn't open file '%s' for writing", filename.c_str());
|
warning("Couldn't open file '%s' for writing", filename.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,37 +80,41 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
class MT32File : public MT32Emu::File {
|
class MT32File : public MT32Emu::File {
|
||||||
Common::File file;
|
Common::File _in;
|
||||||
|
Common::DumpFile _out;
|
||||||
public:
|
public:
|
||||||
bool open(const char *filename, OpenMode mode) {
|
bool open(const char *filename, OpenMode mode) {
|
||||||
Common::File::AccessMode accessMode = mode == OpenMode_read ? Common::File::kFileReadMode : Common::File::kFileWriteMode;
|
if (mode == OpenMode_read)
|
||||||
return file.open(filename, accessMode);
|
return _in.open(filename);
|
||||||
|
else
|
||||||
|
return _out.open(filename);
|
||||||
}
|
}
|
||||||
void close() {
|
void close() {
|
||||||
return file.close();
|
_in.close();
|
||||||
|
_out.close();
|
||||||
}
|
}
|
||||||
size_t read(void *in, size_t size) {
|
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) {
|
bool readLine(char *in, size_t size) {
|
||||||
return file.readLine(in, size) != NULL;
|
return _in.readLine(in, size) != NULL;
|
||||||
}
|
}
|
||||||
bool readBit8u(MT32Emu::Bit8u *in) {
|
bool readBit8u(MT32Emu::Bit8u *in) {
|
||||||
byte b = file.readByte();
|
byte b = _in.readByte();
|
||||||
if (file.eof())
|
if (_in.eof())
|
||||||
return false;
|
return false;
|
||||||
*in = b;
|
*in = b;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
size_t write(const void *in, size_t size) {
|
size_t write(const void *in, size_t size) {
|
||||||
return file.write(in, size);
|
return _out.write(in, size);
|
||||||
}
|
}
|
||||||
bool writeBit8u(MT32Emu::Bit8u out) {
|
bool writeBit8u(MT32Emu::Bit8u out) {
|
||||||
file.writeByte(out);
|
_out.writeByte(out);
|
||||||
return !file.ioFailed();
|
return !_out.ioFailed();
|
||||||
}
|
}
|
||||||
bool isEOF() {
|
bool isEOF() {
|
||||||
return file.eof();
|
return _in.isOpen() ? _in.eof() : _out.eof();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue