mirror of https://github.com/stella-emu/stella.git
Move ZipHandler from OSystem directly into FSNodeZip class, since it's the
only class that uses it. This is in preparation for improvements to ZIP file handling. Use emplace_back instead of push_back in several places, as it's faster. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@3121 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
4642183745
commit
1460947005
|
@ -45,7 +45,7 @@ FilesystemNodeZIP::FilesystemNodeZIP(const string& p)
|
||||||
_zipFile = p.substr(0, pos+4);
|
_zipFile = p.substr(0, pos+4);
|
||||||
|
|
||||||
// Open file at least once to initialize the virtual file count
|
// Open file at least once to initialize the virtual file count
|
||||||
ZipHandler& zip = OSystem::zip(_zipFile);
|
ZipHandler& zip = open(_zipFile);
|
||||||
_numFiles = zip.romFiles();
|
_numFiles = zip.romFiles();
|
||||||
if(_numFiles == 0)
|
if(_numFiles == 0)
|
||||||
{
|
{
|
||||||
|
@ -123,11 +123,11 @@ bool FilesystemNodeZIP::getChildren(AbstractFSList& myList, ListMode mode,
|
||||||
if(!isDirectory() || _error != ZIPERR_NONE)
|
if(!isDirectory() || _error != ZIPERR_NONE)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ZipHandler& zip = OSystem::zip(_zipFile);
|
ZipHandler& zip = open(_zipFile);
|
||||||
while(zip.hasNext())
|
while(zip.hasNext())
|
||||||
{
|
{
|
||||||
FilesystemNodeZIP entry(_path, zip.next(), _realNode);
|
FilesystemNodeZIP entry(_path, zip.next(), _realNode);
|
||||||
myList.push_back(new FilesystemNodeZIP(entry));
|
myList.emplace_back(new FilesystemNodeZIP(entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -144,7 +144,7 @@ uInt32 FilesystemNodeZIP::read(uInt8*& image) const
|
||||||
case ZIPERR_NO_ROMS: throw "ZIP file doesn't contain any ROMs";
|
case ZIPERR_NO_ROMS: throw "ZIP file doesn't contain any ROMs";
|
||||||
}
|
}
|
||||||
|
|
||||||
ZipHandler& zip = OSystem::zip(_zipFile);
|
ZipHandler& zip = open(_zipFile);
|
||||||
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
while(zip.hasNext() && !found)
|
while(zip.hasNext() && !found)
|
||||||
|
@ -158,3 +158,6 @@ AbstractFSNode* FilesystemNodeZIP::getParent() const
|
||||||
{
|
{
|
||||||
return _realNode ? _realNode->getParent() : nullptr;
|
return _realNode ? _realNode->getParent() : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
unique_ptr<ZipHandler> FilesystemNodeZIP::myZipHandler = make_ptr<ZipHandler>();
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#ifndef FS_NODE_ZIP_HXX
|
#ifndef FS_NODE_ZIP_HXX
|
||||||
#define FS_NODE_ZIP_HXX
|
#define FS_NODE_ZIP_HXX
|
||||||
|
|
||||||
|
#include "ZipHandler.hxx"
|
||||||
#include "FSNode.hxx"
|
#include "FSNode.hxx"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -74,6 +75,15 @@ class FilesystemNodeZIP : public AbstractFSNode
|
||||||
void setFlags(const string& zipfile, const string& virtualfile,
|
void setFlags(const string& zipfile, const string& virtualfile,
|
||||||
shared_ptr<AbstractFSNode> realnode);
|
shared_ptr<AbstractFSNode> realnode);
|
||||||
|
|
||||||
|
friend ostream& operator<<(ostream& os, const FilesystemNodeZIP& node)
|
||||||
|
{
|
||||||
|
os << "_zipFile: " << node._zipFile << endl
|
||||||
|
<< "_virtualFile: " << node._virtualFile << endl
|
||||||
|
<< "_path: " << node._path << endl
|
||||||
|
<< "_shortPath: " << node._shortPath << endl;
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/* Error types */
|
/* Error types */
|
||||||
enum zip_error
|
enum zip_error
|
||||||
|
@ -89,6 +99,14 @@ class FilesystemNodeZIP : public AbstractFSNode
|
||||||
string _path, _shortPath;
|
string _path, _shortPath;
|
||||||
zip_error _error;
|
zip_error _error;
|
||||||
uInt32 _numFiles;
|
uInt32 _numFiles;
|
||||||
|
|
||||||
|
// ZIP static reference variable responsible for accessing ZIP files
|
||||||
|
static unique_ptr<ZipHandler> myZipHandler;
|
||||||
|
static ZipHandler& open(const string& file)
|
||||||
|
{
|
||||||
|
myZipHandler->open(file);
|
||||||
|
return *myZipHandler;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -70,7 +70,7 @@ bool FilesystemNode::getChildren(FSList& fslist, ListMode mode, bool hidden) con
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (const auto& i: tmp)
|
for (const auto& i: tmp)
|
||||||
fslist.push_back(FilesystemNode(i));
|
fslist.emplace_back(FilesystemNode(i));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,9 +159,6 @@ bool OSystem::create()
|
||||||
// Create PNG handler
|
// Create PNG handler
|
||||||
myPNGLib = make_ptr<PNGLibrary>(*myFrameBuffer);
|
myPNGLib = make_ptr<PNGLibrary>(*myFrameBuffer);
|
||||||
|
|
||||||
// Create ZIP handler
|
|
||||||
myZipHandler = make_ptr<ZipHandler>();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -690,6 +687,3 @@ void OSystem::mainLoop()
|
||||||
myCheatManager->saveCheatDatabase();
|
myCheatManager->saveCheatDatabase();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
||||||
unique_ptr<ZipHandler> OSystem::myZipHandler = unique_ptr<ZipHandler>();
|
|
||||||
|
|
|
@ -39,7 +39,6 @@ class VideoDialog;
|
||||||
#include "FSNode.hxx"
|
#include "FSNode.hxx"
|
||||||
#include "FrameBuffer.hxx"
|
#include "FrameBuffer.hxx"
|
||||||
#include "PNGLibrary.hxx"
|
#include "PNGLibrary.hxx"
|
||||||
#include "ZipHandler.hxx"
|
|
||||||
#include "bspf.hxx"
|
#include "bspf.hxx"
|
||||||
|
|
||||||
struct TimingInfo {
|
struct TimingInfo {
|
||||||
|
@ -173,17 +172,6 @@ class OSystem
|
||||||
*/
|
*/
|
||||||
PNGLibrary& png() const { return *myPNGLib; }
|
PNGLibrary& png() const { return *myPNGLib; }
|
||||||
|
|
||||||
/**
|
|
||||||
Get the ZIP handler of the system.
|
|
||||||
|
|
||||||
@return The ZIP object, using the given file
|
|
||||||
*/
|
|
||||||
static ZipHandler& zip(const string& file)
|
|
||||||
{
|
|
||||||
myZipHandler->open(file);
|
|
||||||
return *myZipHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This method should be called to load the current settings from an rc file.
|
This method should be called to load the current settings from an rc file.
|
||||||
It first loads the settings from the config file, then informs subsystems
|
It first loads the settings from the config file, then informs subsystems
|
||||||
|
@ -506,9 +494,6 @@ class OSystem
|
||||||
// Indicates whether to stop the main loop
|
// Indicates whether to stop the main loop
|
||||||
bool myQuitLoop;
|
bool myQuitLoop;
|
||||||
|
|
||||||
// ZIP static reference variable responsible for accessing ZIP files
|
|
||||||
static unique_ptr<ZipHandler> myZipHandler;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
string myBaseDir;
|
string myBaseDir;
|
||||||
string myStateDir;
|
string myStateDir;
|
||||||
|
|
|
@ -195,7 +195,7 @@ bool FilesystemNodePOSIX::getChildren(AbstractFSList& myList, ListMode mode,
|
||||||
(mode == FilesystemNode::kListDirectoriesOnly && !entry._isDirectory))
|
(mode == FilesystemNode::kListDirectoriesOnly && !entry._isDirectory))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
myList.push_back(new FilesystemNodePOSIX(entry));
|
myList.emplace_back(new FilesystemNodePOSIX(entry));
|
||||||
}
|
}
|
||||||
closedir(dirp);
|
closedir(dirp);
|
||||||
|
|
||||||
|
@ -256,8 +256,8 @@ AbstractFSNode* FilesystemNodePOSIX::getParent() const
|
||||||
if (_path == "/")
|
if (_path == "/")
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
const char *start = _path.c_str();
|
const char* start = _path.c_str();
|
||||||
const char *end = lastPathComponent(_path);
|
const char* end = lastPathComponent(_path);
|
||||||
|
|
||||||
return new FilesystemNodePOSIX(string(start, end - start));
|
return new FilesystemNodePOSIX(string(start, end - start));
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,7 +149,7 @@ void FilesystemNodeWINDOWS::addFile(AbstractFSList& list, ListMode mode,
|
||||||
entry._isValid = true;
|
entry._isValid = true;
|
||||||
entry._isPseudoRoot = false;
|
entry._isPseudoRoot = false;
|
||||||
|
|
||||||
list.push_back(new FilesystemNodeWINDOWS(entry));
|
list.emplace_back(new FilesystemNodeWINDOWS(entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
@ -244,7 +244,7 @@ bool FilesystemNodeWINDOWS::
|
||||||
entry._isValid = true;
|
entry._isValid = true;
|
||||||
entry._isPseudoRoot = false;
|
entry._isPseudoRoot = false;
|
||||||
entry._path = toAscii(current_drive);
|
entry._path = toAscii(current_drive);
|
||||||
myList.push_back(new FilesystemNodeWINDOWS(entry));
|
myList.emplace_back(new FilesystemNodeWINDOWS(entry));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue