|
@ -29,6 +29,7 @@ |
|
|
#include "cardreader.h" |
|
|
#include "cardreader.h" |
|
|
|
|
|
|
|
|
#include "../MarlinCore.h" |
|
|
#include "../MarlinCore.h" |
|
|
|
|
|
#include "../libs/hex_print.h" |
|
|
#include "../lcd/marlinui.h" |
|
|
#include "../lcd/marlinui.h" |
|
|
|
|
|
|
|
|
#if ENABLED(DWIN_CREALITY_LCD) |
|
|
#if ENABLED(DWIN_CREALITY_LCD) |
|
@ -197,7 +198,7 @@ char *createFilename(char * const buffer, const dir_t &p) { |
|
|
//
|
|
|
//
|
|
|
// Return 'true' if the item is a folder, G-code file or Binary file
|
|
|
// Return 'true' if the item is a folder, G-code file or Binary file
|
|
|
//
|
|
|
//
|
|
|
bool CardReader::is_visible_entity(const dir_t &p OPTARG(CUSTOM_FIRMWARE_UPLOAD, bool onlyBin/*=false*/)) { |
|
|
bool CardReader::is_visible_entity(const dir_t &p OPTARG(CUSTOM_FIRMWARE_UPLOAD, const bool onlyBin/*=false*/)) { |
|
|
//uint8_t pn0 = p.name[0];
|
|
|
//uint8_t pn0 = p.name[0];
|
|
|
|
|
|
|
|
|
#if DISABLED(CUSTOM_FIRMWARE_UPLOAD) |
|
|
#if DISABLED(CUSTOM_FIRMWARE_UPLOAD) |
|
@ -279,12 +280,17 @@ void CardReader::selectByName(SdFile dir, const char * const match) { |
|
|
* this can blow up the stack, so a 'depth' parameter would be a |
|
|
* this can blow up the stack, so a 'depth' parameter would be a |
|
|
* good addition. |
|
|
* good addition. |
|
|
*/ |
|
|
*/ |
|
|
void CardReader::printListing( |
|
|
void CardReader::printListing(SdFile parent, const char * const prepend, const uint8_t lsflags |
|
|
SdFile parent, const char * const prepend |
|
|
|
|
|
OPTARG(CUSTOM_FIRMWARE_UPLOAD, bool onlyBin/*=false*/) |
|
|
|
|
|
OPTARG(LONG_FILENAME_HOST_SUPPORT, const bool includeLongNames/*=false*/) |
|
|
|
|
|
OPTARG(LONG_FILENAME_HOST_SUPPORT, const char * const prependLong/*=nullptr*/) |
|
|
OPTARG(LONG_FILENAME_HOST_SUPPORT, const char * const prependLong/*=nullptr*/) |
|
|
) { |
|
|
) { |
|
|
|
|
|
const bool includeTime = TERN0(M20_TIMESTAMP_SUPPORT, TEST(lsflags, LS_TIMESTAMP)); |
|
|
|
|
|
#if ENABLED(LONG_FILENAME_HOST_SUPPORT) |
|
|
|
|
|
const bool includeLong = TEST(lsflags, LS_LONG_FILENAME); |
|
|
|
|
|
#endif |
|
|
|
|
|
#if ENABLED(CUSTOM_FIRMWARE_UPLOAD) |
|
|
|
|
|
const bool onlyBin = TEST(lsflags, LS_ONLY_BIN); |
|
|
|
|
|
#endif |
|
|
|
|
|
UNUSED(lsflags); |
|
|
dir_t p; |
|
|
dir_t p; |
|
|
while (parent.readDir(&p, longFilename) > 0) { |
|
|
while (parent.readDir(&p, longFilename) > 0) { |
|
|
if (DIR_IS_SUBDIR(&p)) { |
|
|
if (DIR_IS_SUBDIR(&p)) { |
|
@ -301,19 +307,17 @@ void CardReader::printListing( |
|
|
SdFile child; // child.close() in destructor
|
|
|
SdFile child; // child.close() in destructor
|
|
|
if (child.open(&parent, dosFilename, O_READ)) { |
|
|
if (child.open(&parent, dosFilename, O_READ)) { |
|
|
#if ENABLED(LONG_FILENAME_HOST_SUPPORT) |
|
|
#if ENABLED(LONG_FILENAME_HOST_SUPPORT) |
|
|
if (includeLongNames) { |
|
|
if (includeLong) { |
|
|
size_t lenPrependLong = prependLong ? strlen(prependLong) + 1 : 0; |
|
|
const size_t lenPrependLong = prependLong ? strlen(prependLong) + 1 : 0; |
|
|
// Allocate enough stack space for the full long path including / separator
|
|
|
// Allocate enough stack space for the full long path including / separator
|
|
|
char pathLong[lenPrependLong + strlen(longFilename) + 1]; |
|
|
char pathLong[lenPrependLong + strlen(longFilename) + 1]; |
|
|
if (prependLong) { strcpy(pathLong, prependLong); pathLong[lenPrependLong - 1] = '/'; } |
|
|
if (prependLong) { strcpy(pathLong, prependLong); pathLong[lenPrependLong - 1] = '/'; } |
|
|
strcpy(pathLong + lenPrependLong, longFilename); |
|
|
strcpy(pathLong + lenPrependLong, longFilename); |
|
|
printListing(child, path OPTARG(CUSTOM_FIRMWARE_UPLOAD, onlyBin), true, pathLong); |
|
|
printListing(child, path, lsflags, pathLong); |
|
|
|
|
|
continue; |
|
|
} |
|
|
} |
|
|
else |
|
|
|
|
|
printListing(child, path OPTARG(CUSTOM_FIRMWARE_UPLOAD, onlyBin)); |
|
|
|
|
|
#else |
|
|
|
|
|
printListing(child, path OPTARG(CUSTOM_FIRMWARE_UPLOAD, onlyBin)); |
|
|
|
|
|
#endif |
|
|
#endif |
|
|
|
|
|
printListing(child, path, lsflags); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
SERIAL_ECHO_MSG(STR_SD_CANT_OPEN_SUBDIR, dosFilename); |
|
|
SERIAL_ECHO_MSG(STR_SD_CANT_OPEN_SUBDIR, dosFilename); |
|
@ -325,8 +329,18 @@ void CardReader::printListing( |
|
|
SERIAL_ECHO(createFilename(filename, p)); |
|
|
SERIAL_ECHO(createFilename(filename, p)); |
|
|
SERIAL_CHAR(' '); |
|
|
SERIAL_CHAR(' '); |
|
|
SERIAL_ECHO(p.fileSize); |
|
|
SERIAL_ECHO(p.fileSize); |
|
|
|
|
|
if (includeTime) { |
|
|
|
|
|
SERIAL_CHAR(' '); |
|
|
|
|
|
uint16_t crmodDate = p.lastWriteDate, crmodTime = p.lastWriteTime; |
|
|
|
|
|
if (crmodDate < p.creationDate || (crmodDate == p.creationDate && crmodTime < p.creationTime)) { |
|
|
|
|
|
crmodDate = p.creationDate; |
|
|
|
|
|
crmodTime = p.creationTime; |
|
|
|
|
|
} |
|
|
|
|
|
SERIAL_ECHOPGM("0x", hex_word(crmodDate)); |
|
|
|
|
|
print_hex_word(crmodTime); |
|
|
|
|
|
} |
|
|
#if ENABLED(LONG_FILENAME_HOST_SUPPORT) |
|
|
#if ENABLED(LONG_FILENAME_HOST_SUPPORT) |
|
|
if (includeLongNames) { |
|
|
if (includeLong) { |
|
|
SERIAL_CHAR(' '); |
|
|
SERIAL_CHAR(' '); |
|
|
if (prependLong) { SERIAL_ECHO(prependLong); SERIAL_CHAR('/'); } |
|
|
if (prependLong) { SERIAL_ECHO(prependLong); SERIAL_CHAR('/'); } |
|
|
SERIAL_ECHO(longFilename[0] ? longFilename : filename); |
|
|
SERIAL_ECHO(longFilename[0] ? longFilename : filename); |
|
@ -340,16 +354,10 @@ void CardReader::printListing( |
|
|
//
|
|
|
//
|
|
|
// List all files on the SD card
|
|
|
// List all files on the SD card
|
|
|
//
|
|
|
//
|
|
|
void CardReader::ls( |
|
|
void CardReader::ls(const uint8_t lsflags) { |
|
|
TERN_(CUSTOM_FIRMWARE_UPLOAD, const bool onlyBin/*=false*/) |
|
|
|
|
|
#if BOTH(CUSTOM_FIRMWARE_UPLOAD, LONG_FILENAME_HOST_SUPPORT) |
|
|
|
|
|
, |
|
|
|
|
|
#endif |
|
|
|
|
|
TERN_(LONG_FILENAME_HOST_SUPPORT, const bool includeLongNames/*=false*/) |
|
|
|
|
|
) { |
|
|
|
|
|
if (flag.mounted) { |
|
|
if (flag.mounted) { |
|
|
root.rewind(); |
|
|
root.rewind(); |
|
|
printListing(root, nullptr OPTARG(CUSTOM_FIRMWARE_UPLOAD, onlyBin) OPTARG(LONG_FILENAME_HOST_SUPPORT, includeLongNames)); |
|
|
printListing(root, nullptr, lsflags); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|