#pragma once #include #include #include #include namespace roro::files { enum class FileSort : uint8_t { Name, Date, Size }; // A folder's entries for the Storage App (F1, Q129, Q136): 256 at most, the names packed into // one buffer, about 10 KB when full. A bigger folder keeps the first 256 by name, whatever order // the card lists them in, and counts the rest. class FileList { public: static constexpr size_t kMax = 256; void clear(); void add(const char* name, uint32_t size, uint32_t modified, bool folder); void sort(FileSort by); // folders first, by name; then files by name, newest or biggest first size_t count() const { return entries_.size(); } size_t more() const { return more_; } // entries that didn't fit // By position after sort(). const char* name(size_t i) const { return names_.data() + entries_[order_[i]].name; } uint32_t size(size_t i) const { return entries_[order_[i]].size; } uint32_t modified(size_t i) const { return entries_[order_[i]].modified; } // Unix time, 0 if unknown bool folder(size_t i) const { return entries_[order_[i]].folder; } int find(const std::string& name) const; // position, or -1 size_t bytes() const; // memory held private: struct Entry { uint32_t name; // offset into names_ uint32_t size, modified; bool folder; }; bool before(const Entry& a, const Entry& b, FileSort by) const; void compact(); std::vector entries_; std::vector order_; std::vector names_; size_t more_ = 0, wasted_ = 0; }; // What a row shows on the right (Q129): "folder", or "1.2 KB 2026-10-05". A file dated before // 2020 was written before the clock was set: "-" (Q137). Local time. std::string rowDetail(bool folder, uint32_t size, uint32_t modified); std::string formatStamp(uint32_t modified); // A name cut to `maxChars` for a row, from the middle: the start and the extension stay readable. std::string fitName(const std::string& name, size_t maxChars); // "2026-10-05 20:00", or "-" } // namespace roro::files