config: abstract fs utils to fix esp32 builds

This commit is contained in:
Torrie Fischer
2023-12-20 09:19:37 +01:00
parent 6797889b4c
commit ce65e7e7f0
3 changed files with 91 additions and 48 deletions

33
src/FsUtils.h Normal file
View File

@@ -0,0 +1,33 @@
#pragma once
#include <iterator>
#include <LittleFS.h>
struct filename_iterator: public std::iterator<std::input_iterator_tag, const char*> {
public:
filename_iterator();
filename_iterator(const char* path, const char* suffix);
void next();
filename_iterator& operator++();
filename_iterator& operator++(int) {filename_iterator ret = *this; ++(*this); return ret;}
bool operator==(const filename_iterator &other) const { return valid == other.valid;}
bool operator!=(const filename_iterator &other) const { return !(*this == other); }
const char* operator*() const {
if (!valid) {
return NULL;
}
return ret.c_str();
}
private:
String ret;
bool valid;
const char* suffix;
#ifdef BOARD_ESP8266
Dir dir;
#endif
#ifdef BOARD_ESP32
File dir;
#endif
};