diff options
| author | jacqueline <me@jacqueline.id.au> | 2024-05-10 14:28:03 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2024-05-10 14:28:03 +1000 |
| commit | 41426151a1cb9e7bf27fae4d1ee2dbba7553e3fa (patch) | |
| tree | da28cf369c04a0d39977de6b23fb100d43b6ba92 /src/tangara/lua/file_iterator.hpp | |
| parent | 1d0ad4cbf9bd7e9a9c3deabed31342a4b10cac4b (diff) | |
| parent | 35c6125b25f3f0c1852c74f9d165a46282494a7c (diff) | |
| download | tangara-fw-41426151a1cb9e7bf27fae4d1ee2dbba7553e3fa.tar.gz | |
Merge branch 'main' of codeberg.org:cool-tech-zone/tangara-fw
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..b803062c --- /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 lua { + +// 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 lua
\ No newline at end of file |
