diff options
Diffstat (limited to 'src/irrlicht/RezFileList.cpp')
| -rw-r--r-- | src/irrlicht/RezFileList.cpp | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/src/irrlicht/RezFileList.cpp b/src/irrlicht/RezFileList.cpp new file mode 100644 index 0000000..1932b85 --- /dev/null +++ b/src/irrlicht/RezFileList.cpp @@ -0,0 +1,143 @@ +#include <RezFileList.h> +#include <rez/dir.h> +#include <rez.h> +#include <iostream> + +static const irr::io::path s; + +irr::u32 RezFileList::getFileCount(const rez::dir &dir) const +{ + irr::u32 ret = 0; + + for (const auto &d : dir.entries()) + { + const auto &entry = d.second; + + if (std::holds_alternative<rez::dir>(entry)) + ret += getFileCount(std::get<rez::dir>(entry)); + else if (std::holds_alternative<rez::resource>(entry)) + ret++; + } + + return ret; +} + +irr::u32 RezFileList::getFileCount() const +{ + return getFileCount(rez.root()); +} + +const irr::io::path &RezFileList::getFileName(irr::u32 index) const +{ + return s; +} + +const irr::io::path &RezFileList::getFullFileName(irr::u32 index) const +{ + return s; +} + +irr::u32 RezFileList::getFileSize(irr::u32 index) const +{ + return 0; +} + +irr::u32 RezFileList::getFileOffset(irr::u32 index) const +{ + return 0; +} + +irr::u32 RezFileList::getID(irr::u32 index) const +{ + return 0; +} + +bool RezFileList::isDirectory(irr::u32 index) const +{ + if (index >= entries.size()) + return false; + + return std::holds_alternative<rez::dir>(*entries.at(index)); +} + +int RezFileList::findFile(const irr::io::path &filename, bool isFolder, + const rez::dir::direntry *entry) const +{ + if (std::holds_alternative<rez::resource>(*entry)) + { + const auto &resource = std::get<rez::resource>(*entry); + + if (resource.name() == filename.c_str()) + { + if (isFolder) + { + std::cerr << filename.c_str() << " expected to be a " + "directory, but is a file\n"; + return -1; + } + else + return 1; + } + } + else if (std::holds_alternative<rez::dir>(*entry) && isFolder) + { + const auto &dir = std::get<rez::dir>(*entry); + + if (dir.name() == filename.c_str()) + { + if (!isFolder) + { + std::cerr << filename.c_str() << " expected to be a " + "file, but is a directory\n"; + return -1; + } + else + return 1; + } + } + + return 0; +} + +irr::s32 RezFileList::findFile(const irr::io::path &filename, bool isFolder) + const +{ + for (irr::u32 i = 0; i < entries.size(); i++) + { + auto entry = entries.at(i); + int n = findFile(filename, isFolder, entry); + + if (n < 0) + return -1; + else if (n) + return i; + } + + const rez::dir::direntry *entry = rez.access(filename.c_str()); + + if (!entry || findFile(filename, isFolder, entry) <= 0) + return -1; + + entries.push_back(entry); + return entries.size() - 1; +} + +const irr::io::path &RezFileList::getPath() const +{ + return s; +} + +irr::u32 RezFileList::addItem(const irr::io::path &fullPath, irr::u32 offset, + irr::u32 size, bool isDirectory, irr::u32 id) +{ + return 0; +} + +void RezFileList::sort() +{ +} + +RezFileList::RezFileList(const rez::ball &rez) : + rez(rez) +{ +} |
