mirror of
https://github.com/libretro/scummvm.git
synced 2025-04-11 03:01:01 +00:00
Add a File::open variant that takes a FilesystemNode as parameter
svn-id: r22251
This commit is contained in:
parent
fd9e73d1f0
commit
13e4fc74e0
@ -195,6 +195,7 @@ bool File::open(const String &filename, AccessMode mode) {
|
|||||||
error("File::open: This file object already is opened (%s), won't open '%s'", _name.c_str(), filename.c_str());
|
error("File::open: This file object already is opened (%s), won't open '%s'", _name.c_str(), filename.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_name.clear();
|
||||||
clearIOFailed();
|
clearIOFailed();
|
||||||
|
|
||||||
String fname(filename);
|
String fname(filename);
|
||||||
@ -261,6 +262,40 @@ bool File::open(const String &filename, AccessMode mode) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool File::open(const FilesystemNode &node, AccessMode mode) {
|
||||||
|
assert(mode == kFileReadMode || mode == kFileWriteMode);
|
||||||
|
String filename(node.displayName());
|
||||||
|
|
||||||
|
if (_handle) {
|
||||||
|
error("File::open: This file object already is opened (%s), won't open '%s'", _name.c_str(), filename.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
clearIOFailed();
|
||||||
|
_name.clear();
|
||||||
|
|
||||||
|
const char *modeStr = (mode == kFileReadMode) ? "rb" : "wb";
|
||||||
|
|
||||||
|
|
||||||
|
_handle = fopen(node.path().c_str(), modeStr);
|
||||||
|
|
||||||
|
|
||||||
|
if (_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) {
|
||||||
// First try to find the file it via a FilesystemNode (in case an absolute
|
// First try to find the file it via a FilesystemNode (in case an absolute
|
||||||
// path was passed). But we only use this to filter out directories.
|
// path was passed). But we only use this to filter out directories.
|
||||||
@ -296,6 +331,7 @@ void File::close() {
|
|||||||
if (_handle)
|
if (_handle)
|
||||||
fclose(_handle);
|
fclose(_handle);
|
||||||
_handle = NULL;
|
_handle = NULL;
|
||||||
|
_name.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool File::isOpen() const {
|
bool File::isOpen() const {
|
||||||
|
@ -28,6 +28,8 @@
|
|||||||
#include "common/str.h"
|
#include "common/str.h"
|
||||||
#include "common/stream.h"
|
#include "common/stream.h"
|
||||||
|
|
||||||
|
class FilesystemNode;
|
||||||
|
|
||||||
namespace Common {
|
namespace Common {
|
||||||
|
|
||||||
class File : public SeekableReadStream, public WriteStream {
|
class File : public SeekableReadStream, public WriteStream {
|
||||||
@ -61,6 +63,7 @@ public:
|
|||||||
void decRef();
|
void decRef();
|
||||||
|
|
||||||
virtual bool open(const String &filename, AccessMode mode = kFileReadMode);
|
virtual bool open(const String &filename, AccessMode mode = kFileReadMode);
|
||||||
|
virtual bool open(const FilesystemNode &node, AccessMode mode = kFileReadMode);
|
||||||
static bool exists(const String &filename);
|
static bool exists(const String &filename);
|
||||||
|
|
||||||
virtual void close();
|
virtual void close();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user