Public Access
F1 steps 2-6: the Storage App, its viewers, and Maintenance moved in (#3)
The Storage App browses the SD card: folders first with sizes and dates, three sorts, one item at a time with a clipboard (c, x, v), rename, delete after counting what's inside, new folder, details. A listing holds 256 entries and says when a folder has more. FileOps does the card's work for the App and the console alike, one operation at a time on the storage task in turns of about 150 ms, so Logs and Captures are still written during a long copy. A copy shows progress, can be cancelled (what it wrote is taken back) and compares sizes after. The read-only rules are checked there: the firmware's top-level folders, /gemini/cache, and files being written (a Track, a Capture, an upload, today's IRC Logs). A listing reads the folder straight from FatFs: through the Arduino File, 329 entries took over two seconds. Viewers by type: text read a screen at a time whatever the file's size (logs open at the end), a hex dump, a Capture's packets as the LoRa Scanner lists them, a Track's summary, and an Update File checked as an install would check it, without writing anything. Tab shows any file as hex or text. Settings > Storage is gone: usage, Storage Clean-up and Erase are the App's Maintenance, behind a warning. The Storage Warning points there. The Clock sets the system time whatever its source, so files are dated correctly with a GNSS Fix alone (Q137). Console: cp, mv, mkdir, du, cancel; rm takes folders and follows the rules; ls shows dates; Debug Builds get `sd fill`. 424 host tests. Checked on the device: docs/milestones/F1.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "app.h"
|
||||
#include "apps/file_viewer.h"
|
||||
#include "apps/maintenance_page.h"
|
||||
#include "dialog_model.h"
|
||||
#include "event_bus.h"
|
||||
#include "file_list.h"
|
||||
#include "line_editor.h"
|
||||
#include "list_model.h"
|
||||
#include "services/clock_service.h"
|
||||
#include "services/file_ops.h"
|
||||
#include "services/storage_service.h"
|
||||
#include "ui/theme.h"
|
||||
|
||||
namespace roro {
|
||||
|
||||
// The Storage App (docs/milestones/F1.md): the SD card's folders and files, one item at a time
|
||||
// with a clipboard (Q131). Enter opens a folder, or a file in its viewer (Q134); Back goes up;
|
||||
// c copy, x cut, v paste here, r rename, d delete, n new folder, i details, s sort. At the top of the card, the last row is Maintenance:
|
||||
// usage, Storage Clean-up and erasing the card, behind a warning (Q128).
|
||||
class StorageApp : public App {
|
||||
public:
|
||||
StorageApp(FileOps& ops, StorageService& storage, ClockService& clock, UpdateService& update, EventBus& bus)
|
||||
: ops_(ops), storage_(storage), bus_(bus), maintenance_(storage, clock, bus), viewer_(storage, update) {}
|
||||
void onEnter() override;
|
||||
void onExit() override;
|
||||
bool onKey(const KeyEvent& e) override;
|
||||
bool textEntryActive() const override { return view_ == View::Name; }
|
||||
void update(uint32_t nowMs) override;
|
||||
void draw(Canvas& c) override;
|
||||
|
||||
private:
|
||||
enum class View { Browse, Details, Name, Viewer, Maintenance, NoMemory };
|
||||
enum class Ask { None, Delete, Replace, Maintenance };
|
||||
enum class Wait { None, List, CountToDelete, CountForDetails, Work }; // what the running operation is for
|
||||
static constexpr int kRows = 8;
|
||||
static constexpr size_t kStartFloor = 55 * 1024; // Q86, Q136
|
||||
|
||||
struct Item {
|
||||
std::string path;
|
||||
bool folder = false;
|
||||
explicit operator bool() const { return !path.empty(); }
|
||||
};
|
||||
|
||||
void open(const std::string& folder, const std::string& select = "");
|
||||
void onFinished(const FileOps::Status& s);
|
||||
bool onBrowseKey(const KeyEvent& e);
|
||||
bool onNameKey(const KeyEvent& e);
|
||||
void onAnswer(int button);
|
||||
Item selected() const; // empty on the Maintenance row or in an empty folder
|
||||
bool onMaintenanceRow() const { return cwd_ == "/" && rows_.selected() == static_cast<int>(list_.count()); }
|
||||
void paste(bool replace);
|
||||
void askDelete(const Item& item, uint32_t files, uint32_t bytes);
|
||||
void showDetails(const Item& item);
|
||||
bool work(const std::string& why, const std::string& selectAfter); // an operation was asked for: did it start?
|
||||
void say(const std::string& text);
|
||||
void drawBrowse(Canvas& c);
|
||||
void drawProgress(Canvas& c);
|
||||
|
||||
FileOps& ops_;
|
||||
StorageService& storage_;
|
||||
EventBus& bus_;
|
||||
MaintenancePage maintenance_;
|
||||
FileViewer viewer_;
|
||||
|
||||
View view_ = View::Browse;
|
||||
std::string cwd_ = "/", want_ = "/"; // the folder on screen; the one being read
|
||||
files::FileList list_;
|
||||
files::FileSort sort_ = files::FileSort::Name;
|
||||
ListModel rows_{kRows};
|
||||
bool wantList_ = false, loaded_ = false, cardPresent_ = false;
|
||||
std::string selectAfter_; // after the next listing: the name to select, or else the row
|
||||
int selectIndex_ = 0;
|
||||
|
||||
Wait wait_ = Wait::None;
|
||||
uint32_t waitSinceMs_ = 0, lastDrawMs_ = 0;
|
||||
Item clip_, target_; // the clipboard; what a dialog, the editor or the details are about
|
||||
bool cut_ = false;
|
||||
Ask ask_ = Ask::None;
|
||||
std::unique_ptr<DialogModel> dialog_;
|
||||
std::string question_;
|
||||
LineEditor editor_{60};
|
||||
bool renaming_ = false; // Name view: renaming target_, or else a new folder
|
||||
bool pasting_ = false; // the operation running came from v: it may ask to replace
|
||||
std::vector<std::string> details_;
|
||||
int detailsTop_ = 0;
|
||||
std::string message_;
|
||||
uint32_t messageMs_ = 0;
|
||||
};
|
||||
|
||||
} // namespace roro
|
||||
Reference in New Issue
Block a user