|
@@ -271,9 +271,8 @@ void CardReader::selectByName(SdFile dir, const char * const match) {
|
271
|
271
|
* good addition.
|
272
|
272
|
*/
|
273
|
273
|
void CardReader::printListing(
|
274
|
|
- SdFile parent
|
|
274
|
+ SdFile parent, const char * const prepend
|
275
|
275
|
OPTARG(LONG_FILENAME_HOST_SUPPORT, const bool includeLongNames/*=false*/)
|
276
|
|
- , const char * const prepend/*=nullptr*/
|
277
|
276
|
OPTARG(LONG_FILENAME_HOST_SUPPORT, const char * const prependLong/*=nullptr*/)
|
278
|
277
|
) {
|
279
|
278
|
dir_t p;
|
|
@@ -283,61 +282,47 @@ void CardReader::printListing(
|
283
|
282
|
size_t lenPrepend = prepend ? strlen(prepend) + 1 : 0;
|
284
|
283
|
// Allocate enough stack space for the full path including / separator
|
285
|
284
|
char path[lenPrepend + FILENAME_LENGTH];
|
286
|
|
- if (prepend) {
|
287
|
|
- strcpy(path, prepend);
|
288
|
|
- path[lenPrepend - 1] = '/';
|
289
|
|
- }
|
|
285
|
+ if (prepend) { strcpy(path, prepend); path[lenPrepend - 1] = '/'; }
|
290
|
286
|
char* dosFilename = path + lenPrepend;
|
291
|
287
|
createFilename(dosFilename, p);
|
292
|
288
|
|
293
|
289
|
// Get a new directory object using the full path
|
294
|
290
|
// and dive recursively into it.
|
295
|
291
|
SdFile child; // child.close() in destructor
|
296
|
|
- if (child.open(&parent, dosFilename, O_READ))
|
|
292
|
+ if (child.open(&parent, dosFilename, O_READ)) {
|
297
|
293
|
#if ENABLED(LONG_FILENAME_HOST_SUPPORT)
|
298
|
294
|
if (includeLongNames) {
|
299
|
295
|
size_t lenPrependLong = prependLong ? strlen(prependLong) + 1 : 0;
|
300
|
296
|
// Allocate enough stack space for the full long path including / separator
|
301
|
297
|
char pathLong[lenPrependLong + strlen(longFilename) + 1];
|
302
|
|
- if (prependLong) {
|
303
|
|
- strcpy(pathLong, prependLong);
|
304
|
|
- pathLong[lenPrependLong - 1] = '/';
|
305
|
|
- }
|
|
298
|
+ if (prependLong) { strcpy(pathLong, prependLong); pathLong[lenPrependLong - 1] = '/'; }
|
306
|
299
|
strcpy(pathLong + lenPrependLong, longFilename);
|
307
|
|
- printListing(child, true, path, pathLong);
|
|
300
|
+ printListing(child, path, true, pathLong);
|
308
|
301
|
}
|
309
|
302
|
else
|
310
|
|
- printListing(child, false, path);
|
|
303
|
+ printListing(child, path);
|
311
|
304
|
#else
|
312
|
305
|
printListing(child, path);
|
313
|
306
|
#endif
|
|
307
|
+ }
|
314
|
308
|
else {
|
315
|
309
|
SERIAL_ECHO_MSG(STR_SD_CANT_OPEN_SUBDIR, dosFilename);
|
316
|
310
|
return;
|
317
|
311
|
}
|
318
|
312
|
}
|
319
|
313
|
else if (is_dir_or_gcode(p)) {
|
320
|
|
- if (prepend) {
|
321
|
|
- SERIAL_ECHO(prepend);
|
322
|
|
- SERIAL_CHAR('/');
|
323
|
|
- }
|
|
314
|
+ if (prepend) { SERIAL_ECHO(prepend); SERIAL_CHAR('/'); }
|
324
|
315
|
SERIAL_ECHO(createFilename(filename, p));
|
325
|
316
|
SERIAL_CHAR(' ');
|
|
317
|
+ SERIAL_ECHO(p.fileSize);
|
326
|
318
|
#if ENABLED(LONG_FILENAME_HOST_SUPPORT)
|
327
|
|
- if (!includeLongNames)
|
328
|
|
- #endif
|
329
|
|
- SERIAL_ECHOLN(p.fileSize);
|
330
|
|
- #if ENABLED(LONG_FILENAME_HOST_SUPPORT)
|
331
|
|
- else {
|
332
|
|
- SERIAL_ECHO(p.fileSize);
|
|
319
|
+ if (includeLongNames) {
|
333
|
320
|
SERIAL_CHAR(' ');
|
334
|
|
- if (prependLong) {
|
335
|
|
- SERIAL_ECHO(prependLong);
|
336
|
|
- SERIAL_CHAR('/');
|
337
|
|
- }
|
338
|
|
- SERIAL_ECHOLN(longFilename[0] ? longFilename : "???");
|
|
321
|
+ if (prependLong) { SERIAL_ECHO(prependLong); SERIAL_CHAR('/'); }
|
|
322
|
+ SERIAL_ECHO(longFilename[0] ? longFilename : "???");
|
339
|
323
|
}
|
340
|
324
|
#endif
|
|
325
|
+ SERIAL_EOL();
|
341
|
326
|
}
|
342
|
327
|
}
|
343
|
328
|
}
|
|
@@ -348,7 +333,7 @@ void CardReader::printListing(
|
348
|
333
|
void CardReader::ls(TERN_(LONG_FILENAME_HOST_SUPPORT, bool includeLongNames/*=false*/)) {
|
349
|
334
|
if (flag.mounted) {
|
350
|
335
|
root.rewind();
|
351
|
|
- printListing(root OPTARG(LONG_FILENAME_HOST_SUPPORT, includeLongNames));
|
|
336
|
+ printListing(root, nullptr OPTARG(LONG_FILENAME_HOST_SUPPORT, includeLongNames));
|
352
|
337
|
}
|
353
|
338
|
}
|
354
|
339
|
|