Check in some WIP code; still working on issue 851.

This commit is contained in:
Stephen Anthony 2022-06-12 16:54:36 -02:30
parent c122798f7f
commit 0b093cb152
5 changed files with 38 additions and 29 deletions

View File

@ -47,6 +47,8 @@ FilesystemNodeZIP::FilesystemNodeZIP(const string& p)
#endif
}
// cerr << " => p: " << p << endl;
// Open file at least once to initialize the virtual file count
try
{
@ -66,26 +68,23 @@ FilesystemNodeZIP::FilesystemNodeZIP(const string& p)
// We always need a virtual file/path
// Either one is given, or we use the first one
if(pos+5 < p.length())
if(pos+5 < p.length()) // if something comes after '.zip'
{
_virtualPath = p.substr(pos+5);
_isFile = Bankswitch::isValidRomName(_virtualPath);
_isDirectory = !_isFile;
// cerr << _virtualPath << ", isfile: " << _isFile << endl;
}
else if(_numFiles == 1)
{
bool found = false;
while(myZipHandler->hasNext() && !found)
{
const auto [name, size, isFile] = myZipHandler->next();
const auto& [name, size] = myZipHandler->next();
if(Bankswitch::isValidRomName(name))
{
_virtualPath = name;
_size = size;
_isFile = isFile;
_isFile = true;
found = true;
}
@ -105,6 +104,8 @@ FilesystemNodeZIP::FilesystemNodeZIP(const string& p)
FilesystemNodeFactory::Type::SYSTEM);
setFlags(_zipFile, _virtualPath, _realNode);
// cerr << "==============================================================\n";
// cerr << _name << ", file: " << _isFile << ", dir: " << _isDirectory << endl << endl;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -115,6 +116,7 @@ FilesystemNodeZIP::FilesystemNodeZIP(
_isDirectory{isdir},
_isFile{!isdir}
{
// cerr << "=> c'tor 2: " << zipfile << ", " << virtualpath << ", " << isdir << endl;
setFlags(zipfile, virtualpath, realnode);
}
@ -155,7 +157,7 @@ bool FilesystemNodeZIP::exists() const
myZipHandler->open(_zipFile);
while(myZipHandler->hasNext())
{
const auto [name, size, isFile] = myZipHandler->next();
const auto& [name, size] = myZipHandler->next();
if(BSPF::startsWithIgnoreCase(name, _virtualPath))
return true;
}
@ -178,17 +180,20 @@ bool FilesystemNodeZIP::getChildren(AbstractFSList& myList, ListMode mode) const
std::set<string> dirs;
myZipHandler->open(_zipFile);
// cerr << "CHILDREN: --------------------------------\n";
while(myZipHandler->hasNext())
{
// Only consider entries that start with '_virtualPath'
// Ignore empty filenames and '__MACOSX' virtual directories
const auto [name, size, isFile] = myZipHandler->next();
const auto& [name, size] = myZipHandler->next();
if(BSPF::startsWithIgnoreCase(name, "__MACOSX") || name == EmptyString)
continue;
if(BSPF::startsWithIgnoreCase(name, _virtualPath))
{
// First strip off the leading directory
const string& curr = name.substr(_virtualPath == "" ? 0 : _virtualPath.size()+1);
const string& curr = name.substr(
_virtualPath == "" ? 0 : _virtualPath.size()+1);
// cerr << " curr: " << curr << endl;
// Only add sub-directory entries once
const auto pos = curr.find_first_of("/\\");
if(pos != string::npos)
@ -204,6 +209,10 @@ bool FilesystemNodeZIP::getChildren(AbstractFSList& myList, ListMode mode) const
myList.emplace_back(new FilesystemNodeZIP(_zipFile, vpath, _realNode, 0, true));
}
// cerr << "list: \n";
// for(auto& s: myList)
// cerr << s->getPath() << " : isdir: " << s->isDirectory() << endl;
// cerr << "------------------------------------------\n";
return true;
}
@ -223,7 +232,7 @@ size_t FilesystemNodeZIP::read(ByteBuffer& image, size_t) const
bool found = false;
while(myZipHandler->hasNext() && !found)
{
const auto [name, size, isFile] = myZipHandler->next();
const auto& [name, size] = myZipHandler->next();
found = name == _virtualPath;
}
@ -266,7 +275,7 @@ AbstractFSNodePtr FilesystemNodeZIP::getParent() const
const char* start = _path.c_str();
const char* end = lastPathComponent(_path);
return make_shared<FilesystemNodeZIP>(string(start, end - start - 1));
return make_unique<FilesystemNodeZIP>(string(start, end - start - 1));
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -67,7 +67,7 @@ void ZipHandler::open(const string& filename)
{
while(hasNext())
{
const auto [name, size, isFile] = next();
const auto& [name, size] = next();
if(Bankswitch::isValidRomName(name))
myZip->myRomfiles++;
}
@ -96,7 +96,7 @@ bool ZipHandler::hasNext() const
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
std::tuple<string, size_t, bool> ZipHandler::next()
std::tuple<string, size_t> ZipHandler::next()
{
if(hasNext())
{
@ -106,9 +106,9 @@ std::tuple<string, size_t, bool> ZipHandler::next()
else if(header->uncompressedLength == 0)
return next();
else
return {header->filename, header->uncompressedLength, true};
return {header->filename, header->uncompressedLength};
}
return {EmptyString, 0, false};
return {EmptyString, 0};
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -43,7 +43,7 @@ class ZipHandler
// The following form an iterator for processing the filenames in the ZIP file
void reset(); // Reset iterator to first file
bool hasNext() const; // Answer whether there are more files present
std::tuple<string, size_t, bool> next(); // Get information on next file
std::tuple<string, size_t> next(); // Get information on next file
// Decompress the currently selected file and return its length
// An exception will be thrown on any errors

View File

@ -41,10 +41,12 @@ void FilesystemNode::setPath(const string& path)
// Is this potentially a ZIP archive?
#if defined(ZIP_SUPPORT)
if (BSPF::containsIgnoreCase(path, ".zip"))
_realNode = FilesystemNodeFactory::create(path, FilesystemNodeFactory::Type::ZIP);
_realNode = FilesystemNodeFactory::create(path,
FilesystemNodeFactory::Type::ZIP);
else
#endif
_realNode = FilesystemNodeFactory::create(path, FilesystemNodeFactory::Type::SYSTEM);
_realNode = FilesystemNodeFactory::create(path,
FilesystemNodeFactory::Type::SYSTEM);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -78,14 +80,13 @@ bool FilesystemNode::getAllChildren(FSList& fslist, ListMode mode,
{
// Sort only once at the end
#if defined(ZIP_SUPPORT)
// before sorting, replace single file ZIP archive names with contained file names
// because they are displayed using their contained file names
// before sorting, replace single file ZIP archive names with contained
// file names because they are displayed using their contained file names
for(auto& i : fslist)
{
if(BSPF::endsWithIgnoreCase(i.getPath(), ".zip"))
{
FilesystemNodeZIP zipNode(i.getPath());
i.setName(zipNode.getName());
}
}
@ -108,8 +109,8 @@ bool FilesystemNode::getAllChildren(FSList& fslist, ListMode mode,
if(BSPF::endsWithIgnoreCase(i.getPath(), ".zip"))
{
// Force ZIP c'tor to be called
AbstractFSNodePtr ptr = FilesystemNodeFactory::create(i.getPath(),
FilesystemNodeFactory::Type::ZIP);
AbstractFSNodePtr ptr = FilesystemNodeFactory::create(
i.getPath(), FilesystemNodeFactory::Type::ZIP);
FilesystemNode zipNode(ptr);
i = zipNode;
}
@ -143,14 +144,13 @@ bool FilesystemNode::getChildren(FSList& fslist, ListMode mode,
return false;
#if defined(ZIP_SUPPORT)
// before sorting, replace single file ZIP archive names with contained file names
// because they are displayed using their contained file names
// before sorting, replace single file ZIP archive names with contained
// file names because they are displayed using their contained file names
for(auto& i : tmp)
{
if(BSPF::endsWithIgnoreCase(i->getPath(), ".zip"))
{
FilesystemNodeZIP node(i->getPath());
i->setName(node.getName());
}
}
@ -185,8 +185,8 @@ bool FilesystemNode::getChildren(FSList& fslist, ListMode mode,
if (BSPF::endsWithIgnoreCase(i->getPath(), ".zip"))
{
// Force ZIP c'tor to be called
AbstractFSNodePtr ptr = FilesystemNodeFactory::create(i->getPath(),
FilesystemNodeFactory::Type::ZIP);
AbstractFSNodePtr ptr = FilesystemNodeFactory::create(
i->getPath(), FilesystemNodeFactory::Type::ZIP);
FilesystemNode zipNode(ptr);
if(filter(zipNode))

View File

@ -26,7 +26,7 @@ class Settings;
#include "FileListWidget.hxx"
/**
Specialization of the general FileListWidget which procides support for
Specialization of the general FileListWidget which provides support for
user defined favorites, recently played ROMs and most popular ROMs.
@author Thomas Jentzsch