diff options
| author | ailurux <ailuruxx@gmail.com> | 2024-05-10 13:06:20 +1000 |
|---|---|---|
| committer | ailurux <ailuruxx@gmail.com> | 2024-05-10 13:06:20 +1000 |
| commit | 3f177cdb8880abf199f4445f1398cd69fb813892 (patch) | |
| tree | e20de4949b1344c826e5af41ab701f3db75b21bc /src/tangara/lua/file_iterator.hpp | |
| parent | 8019c7691889cde4c3d40bbd78d485a92d713bbf (diff) | |
| parent | e4ce7c4ac23402e09be8d6a52e0f739c0dff4ff0 (diff) | |
| download | tangara-fw-3f177cdb8880abf199f4445f1398cd69fb813892.tar.gz | |
Merge branch 'main' into file-browser
Diffstat (limited to 'src/tangara/lua/file_iterator.hpp')
| -rw-r--r-- | src/tangara/lua/file_iterator.hpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/tangara/lua/file_iterator.hpp b/src/tangara/lua/file_iterator.hpp new file mode 100644 index 00000000..82d6f397 --- /dev/null +++ b/src/tangara/lua/file_iterator.hpp @@ -0,0 +1,45 @@ +/* + * Copyright 2023 ailurux <ailuruxx@gmail.com> + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#pragma once + +#include <string> +#include <optional> + +#include "ff.h" + +namespace database { + +// Note for when reading FILINFO, that we are in LFN mode: +// http://elm-chan.org/fsw/ff/doc/sfileinfo.html +struct FileEntry { + int index; + bool isHidden; + bool isDirectory; + bool isTrack; + std::string filepath; +}; + +class FileIterator { + public: + FileIterator(std::string filepath); + ~FileIterator(); + + auto value() const -> const std::optional<FileEntry>&; + auto next() -> void; + auto prev() -> void; + + private: + FF_DIR dir_; + std::string original_path_; + + std::optional<FileEntry> current_; + int offset_; + + auto iterate(bool reverse = false) -> bool; +}; + +} // namespace database
\ No newline at end of file |
