mirror of https://github.com/stella-emu/stella.git
Move FSNodePOSIX to FSNodeREGULAR.
Make FSNodeREGULAR the default for UNIX and Mac (still WIP for Windows).
This commit is contained in:
parent
cca62ea4fd
commit
3f2655bbac
|
@ -23,14 +23,12 @@ class AbstractFSNode;
|
|||
#if defined(ZIP_SUPPORT)
|
||||
#include "FSNodeZIP.hxx"
|
||||
#endif
|
||||
#if defined(BSPF_UNIX) || defined(BSPF_MACOS)
|
||||
#include "FSNodePOSIX.hxx"
|
||||
#elif defined(BSPF_WINDOWS)
|
||||
#if defined(BSPF_WINDOWS)
|
||||
#include "FSNodeWINDOWS.hxx"
|
||||
#elif defined(__LIB_RETRO__)
|
||||
#include "FSNodeLIBRETRO.hxx"
|
||||
#else
|
||||
#error Unsupported platform in FSNodeFactory!
|
||||
#include "FSNodeREGULAR.hxx"
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -41,20 +39,20 @@ class AbstractFSNode;
|
|||
class FSNodeFactory
|
||||
{
|
||||
public:
|
||||
enum class Type { SYSTEM, ZIP };
|
||||
enum class Type { REGULAR, ZIP };
|
||||
|
||||
public:
|
||||
static unique_ptr<AbstractFSNode> create(const string& path, Type type)
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case Type::SYSTEM:
|
||||
#if defined(BSPF_UNIX) || defined(BSPF_MACOS)
|
||||
return make_unique<FSNodePOSIX>(path);
|
||||
#elif defined(BSPF_WINDOWS)
|
||||
case Type::REGULAR:
|
||||
#if defined(BSPF_WINDOWS)
|
||||
return make_unique<FSNodeWINDOWS>(path);
|
||||
#elif defined(__LIB_RETRO__)
|
||||
return make_unique<FSNodeLIBRETRO>(path);
|
||||
#else
|
||||
return make_unique<FSNodeREGULAR>(path);
|
||||
#endif
|
||||
break;
|
||||
case Type::ZIP:
|
||||
|
|
|
@ -21,17 +21,17 @@
|
|||
#define ROOT_DIR "/"
|
||||
#endif
|
||||
|
||||
#include "FSNodePOSIX.hxx"
|
||||
#include "FSNodeREGULAR.hxx"
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
FSNodePOSIX::FSNodePOSIX()
|
||||
FSNodeREGULAR::FSNodeREGULAR()
|
||||
: _path{ROOT_DIR},
|
||||
_displayName{_path}
|
||||
{
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
FSNodePOSIX::FSNodePOSIX(const string& path, bool verify)
|
||||
FSNodeREGULAR::FSNodeREGULAR(const string& path, bool verify)
|
||||
: _path{path.length() > 0 ? path : "~"} // Default to home directory
|
||||
{
|
||||
// Expand '~' to the HOME environment variable
|
||||
|
@ -63,7 +63,7 @@ FSNodePOSIX::FSNodePOSIX(const string& path, bool verify)
|
|||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void FSNodePOSIX::setFlags()
|
||||
void FSNodeREGULAR::setFlags()
|
||||
{
|
||||
std::error_code ec;
|
||||
const auto s = fs::status(_fspath, ec);
|
||||
|
@ -89,7 +89,7 @@ void FSNodePOSIX::setFlags()
|
|||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
string FSNodePOSIX::getShortPath() const
|
||||
string FSNodeREGULAR::getShortPath() const
|
||||
{
|
||||
// If the path starts with the home directory, replace it with '~'
|
||||
#if defined(BSPF_WINDOWS)
|
||||
|
@ -112,13 +112,13 @@ string FSNodePOSIX::getShortPath() const
|
|||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
bool FSNodePOSIX::hasParent() const
|
||||
bool FSNodeREGULAR::hasParent() const
|
||||
{
|
||||
return _path != "" && _path != ROOT_DIR;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
bool FSNodePOSIX::getChildren(AbstractFSList& myList, ListMode mode) const
|
||||
bool FSNodeREGULAR::getChildren(AbstractFSList& myList, ListMode mode) const
|
||||
{
|
||||
std::error_code ec;
|
||||
for (const auto& entry: fs::directory_iterator{_fspath,
|
||||
|
@ -142,7 +142,7 @@ bool FSNodePOSIX::getChildren(AbstractFSList& myList, ListMode mode) const
|
|||
|
||||
// Only create the object and add it to the list when absolutely
|
||||
// necessary
|
||||
FSNodePOSIX node(path.string(), false);
|
||||
FSNodeREGULAR node(path.string(), false);
|
||||
node._isFile = isFile;
|
||||
node._isDirectory = isDir;
|
||||
node._size = isFile ? entry.file_size() : 0;
|
||||
|
@ -155,14 +155,14 @@ bool FSNodePOSIX::getChildren(AbstractFSList& myList, ListMode mode) const
|
|||
fs::perms::group_write |
|
||||
fs::perms::others_write)) != fs::perms::none;
|
||||
|
||||
myList.emplace_back(make_shared<FSNodePOSIX>(node));
|
||||
myList.emplace_back(make_shared<FSNodeREGULAR>(node));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
size_t FSNodePOSIX::read(ByteBuffer& buffer, size_t size) const
|
||||
size_t FSNodeREGULAR::read(ByteBuffer& buffer, size_t size) const
|
||||
{
|
||||
std::ifstream in(_fspath, std::ios::binary);
|
||||
if (in)
|
||||
|
@ -182,7 +182,7 @@ size_t FSNodePOSIX::read(ByteBuffer& buffer, size_t size) const
|
|||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
size_t FSNodePOSIX::read(stringstream& buffer) const
|
||||
size_t FSNodeREGULAR::read(stringstream& buffer) const
|
||||
{
|
||||
std::ifstream in(_fspath);
|
||||
if (in)
|
||||
|
@ -199,7 +199,7 @@ size_t FSNodePOSIX::read(stringstream& buffer) const
|
|||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
size_t FSNodePOSIX::write(const ByteBuffer& buffer, size_t size) const
|
||||
size_t FSNodeREGULAR::write(const ByteBuffer& buffer, size_t size) const
|
||||
{
|
||||
std::ofstream out(_fspath, std::ios::binary);
|
||||
if (out)
|
||||
|
@ -213,7 +213,7 @@ size_t FSNodePOSIX::write(const ByteBuffer& buffer, size_t size) const
|
|||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
size_t FSNodePOSIX::write(const stringstream& buffer) const
|
||||
size_t FSNodeREGULAR::write(const stringstream& buffer) const
|
||||
{
|
||||
std::ofstream out(_fspath);
|
||||
if (out)
|
||||
|
@ -227,7 +227,7 @@ size_t FSNodePOSIX::write(const stringstream& buffer) const
|
|||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
bool FSNodePOSIX::makeDir()
|
||||
bool FSNodeREGULAR::makeDir()
|
||||
{
|
||||
if (!(exists() && _isDirectory) && fs::create_directory(_fspath))
|
||||
{
|
||||
|
@ -247,7 +247,7 @@ bool FSNodePOSIX::makeDir()
|
|||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
bool FSNodePOSIX::rename(const string& newfile)
|
||||
bool FSNodeREGULAR::rename(const string& newfile)
|
||||
{
|
||||
fs::path newpath = newfile;
|
||||
|
||||
|
@ -272,7 +272,7 @@ bool FSNodePOSIX::rename(const string& newfile)
|
|||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
AbstractFSNodePtr FSNodePOSIX::getParent() const
|
||||
AbstractFSNodePtr FSNodeREGULAR::getParent() const
|
||||
{
|
||||
if (_path == ROOT_DIR)
|
||||
return nullptr;
|
||||
|
@ -280,5 +280,5 @@ AbstractFSNodePtr FSNodePOSIX::getParent() const
|
|||
const char* start = _path.c_str();
|
||||
const char* end = lastPathComponent(_path);
|
||||
|
||||
return make_unique<FSNodePOSIX>(string(start, size_t(end - start)));
|
||||
return make_unique<FSNodeREGULAR>(string(start, size_t(end - start)));
|
||||
}
|
|
@ -15,8 +15,8 @@
|
|||
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||
//============================================================================
|
||||
|
||||
#ifndef FS_NODE_POSIX_HXX
|
||||
#define FS_NODE_POSIX_HXX
|
||||
#ifndef FS_NODE_REGULAR_HXX
|
||||
#define FS_NODE_REGULAR_HXX
|
||||
|
||||
#include "FSNode.hxx"
|
||||
|
||||
|
@ -27,22 +27,22 @@
|
|||
* Parts of this class are documented in the base interface classes,
|
||||
* AbstractFSNode and FSNode. See those classes for more information.
|
||||
*/
|
||||
class FSNodePOSIX : public AbstractFSNode
|
||||
class FSNodeREGULAR : public AbstractFSNode
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Creates a FSNodePOSIX with the root node as path.
|
||||
* Creates a FSNodeREGULAR with the root node as path.
|
||||
*/
|
||||
FSNodePOSIX();
|
||||
FSNodeREGULAR();
|
||||
|
||||
/**
|
||||
* Creates a FSNodePOSIX for a given path.
|
||||
* Creates a FSNodeREGULAR for a given path.
|
||||
*
|
||||
* @param path String with the path the new node should point to.
|
||||
* @param verify true if the isValid and isDirectory/isFile flags should
|
||||
* be verified during the construction.
|
||||
*/
|
||||
explicit FSNodePOSIX(const string& path, bool verify = true);
|
||||
explicit FSNodeREGULAR(const string& path, bool verify = true);
|
||||
|
||||
bool exists() const override { return fs::exists(_fspath); }
|
||||
const string& getName() const override { return _displayName; }
|
|
@ -101,7 +101,7 @@ FSNodeZIP::FSNodeZIP(const string& p)
|
|||
// Behind the scenes, this node is actually a platform-specific object
|
||||
// for whatever system we are running on
|
||||
_realNode = FSNodeFactory::create(_zipFile,
|
||||
FSNodeFactory::Type::SYSTEM);
|
||||
FSNodeFactory::Type::REGULAR);
|
||||
|
||||
setFlags(_zipFile, _virtualPath, _realNode);
|
||||
// cerr << "==============================================================\n";
|
||||
|
|
|
@ -9,6 +9,7 @@ MODULE_OBJS := \
|
|||
src/common/FBBackendSDL2.o \
|
||||
src/common/FBSurfaceSDL2.o \
|
||||
src/common/FpsMeter.o \
|
||||
src/common/FSNodeREGULAR.o \
|
||||
src/common/FSNodeZIP.o \
|
||||
src/common/HighScoresManager.o \
|
||||
src/common/JoyMap.o \
|
||||
|
|
|
@ -44,7 +44,7 @@ void FSNode::setPath(const string& path)
|
|||
_realNode = FSNodeFactory::create(path, FSNodeFactory::Type::ZIP);
|
||||
else
|
||||
#endif
|
||||
_realNode = FSNodeFactory::create(path, FSNodeFactory::Type::SYSTEM);
|
||||
_realNode = FSNodeFactory::create(path, FSNodeFactory::Type::REGULAR);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
MODULE := src/unix
|
||||
|
||||
MODULE_OBJS := \
|
||||
src/unix/FSNodePOSIX.o \
|
||||
src/unix/OSystemUNIX.o \
|
||||
src/unix/SerialPortUNIX.o
|
||||
|
||||
|
|
Loading…
Reference in New Issue