Skip to content

Commit

Permalink
Add file info option to file menu
Browse files Browse the repository at this point in the history
  • Loading branch information
rennancockles committed Sep 1, 2024
1 parent 4fe95f4 commit bf7130f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/core/sd_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ String loopSD(FS &fs, bool filePicker, String allowed_ext) {
clearFileList(fileList);
options = {
{"View File", [=]() { viewFile(fs, filepath); }},
{"File Info", [=]() { fileInfo(fs, filepath); }},
{"Rename", [=]() { renameFile(fs, filepath, filename); }},
{"Copy", [=]() { copyFile(fs, filepath); }},
{"Delete", [=]() { deleteFromSd(fs, filepath); }},
Expand Down Expand Up @@ -903,3 +904,52 @@ bool getFsStorage(FS *&fs) {

return true;
}

/*********************************************************************
** Function: fileInfo
** Display file info
**********************************************************************/
void fileInfo(FS fs, String filepath) {
tft.fillScreen(BGCOLOR);
tft.setCursor(0,0);
tft.setTextColor(FGCOLOR, BGCOLOR);
tft.setTextSize(FP);

File file = fs.open(filepath, FILE_READ);
if (!file) return;

int bytesize = file.size();
float filesize = bytesize;
String unit = "B";

time_t modifiedTime = file.getLastWrite();

if (filesize >= 1000000) {
filesize /= 1000000.0;
unit = "MB";
} else if (filesize >= 1000) {
filesize /= 1000.0;
unit = "kB";
}

padprintln("");
tft.drawCentreString("-"+String(file.name()), WIDTH/2, tft.getCursorY(), 1);
padprintln("\n");
padprintln("Path: " + filepath);
padprintln("");
padprintf("Bytes: %d\n", bytesize);
padprintln("");
padprintf("Size: %.02f %s\n", filesize, unit.c_str());
padprintln("");
padprintf("Modified: %s\n", ctime(&modifiedTime));

file.close();
delay(100);

while(1) {
if(checkEscPress() || checkSelPress()) break;
delay(100);
}

return;
}
2 changes: 2 additions & 0 deletions src/core/sd_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ bool checkLittleFsSize();
bool checkLittleFsSizeNM(); //Don't display msg

bool getFsStorage(FS *&fs);

void fileInfo(FS fs, String filepath);

0 comments on commit bf7130f

Please sign in to comment.