SD sorting entries instead of positions

This commit is contained in:
Alex Voinea 2022-02-04 10:47:56 +01:00
parent 1f3640ab26
commit 858984ef35
2 changed files with 16 additions and 16 deletions

View File

@ -689,11 +689,11 @@ void CardReader::getfilename(uint16_t nr, const char * const match/*=NULL*/)
} }
void CardReader::getfilename_simple(uint32_t position, const char * const match/*=NULL*/) void CardReader::getfilename_simple(uint16_t entry, const char * const match/*=NULL*/)
{ {
curDir = &workDir; curDir = &workDir;
nrFiles = 0; nrFiles = 0;
curDir->seekSet(position); curDir->seekSet((uint32_t)entry << 5);
lsDive("", *curDir, match, LS_GetFilename); lsDive("", *curDir, match, LS_GetFilename);
} }
@ -775,7 +775,7 @@ void CardReader::updir()
*/ */
void CardReader::getfilename_sorted(const uint16_t nr, uint8_t sdSort) { void CardReader::getfilename_sorted(const uint16_t nr, uint8_t sdSort) {
if (nr < sort_count) if (nr < sort_count)
getfilename_simple(sort_positions[(sdSort == SD_SORT_ALPHA) ? (sort_count - nr - 1) : nr]); getfilename_simple(sort_entries[(sdSort == SD_SORT_ALPHA) ? (sort_count - nr - 1) : nr]);
else else
getfilename(nr); getfilename(nr);
} }
@ -832,7 +832,7 @@ void CardReader::presort() {
else else
getfilename_next(position); getfilename_next(position);
sort_order[i] = i; sort_order[i] = i;
sort_positions[i] = position; sort_entries[i] = position >> 5;
#if HAS_FOLDER_SORTING #if HAS_FOLDER_SORTING
if (filenameIsDir) dirCnt++; if (filenameIsDir) dirCnt++;
#endif #endif
@ -882,7 +882,7 @@ void CardReader::presort() {
manage_heater(); manage_heater();
uint8_t orderBckp = sort_order[i]; uint8_t orderBckp = sort_order[i];
getfilename_simple(sort_positions[orderBckp]); getfilename_simple(sort_entries[orderBckp]);
strcpy(name1, LONGEST_FILENAME); // save (or getfilename below will trounce it) strcpy(name1, LONGEST_FILENAME); // save (or getfilename below will trounce it)
crmod_date_bckp = crmodDate; crmod_date_bckp = crmodDate;
crmod_time_bckp = crmodTime; crmod_time_bckp = crmodTime;
@ -891,7 +891,7 @@ void CardReader::presort() {
#endif #endif
uint16_t j = i; uint16_t j = i;
getfilename_simple(sort_positions[sort_order[j - gap]]); getfilename_simple(sort_entries[sort_order[j - gap]]);
char *name2 = LONGEST_FILENAME; // use the string in-place char *name2 = LONGEST_FILENAME; // use the string in-place
#if HAS_FOLDER_SORTING #if HAS_FOLDER_SORTING
while (j >= gap && ((sdSort == SD_SORT_TIME)?_SORT_CMP_TIME_DIR(FOLDER_SORTING):_SORT_CMP_DIR(FOLDER_SORTING))) while (j >= gap && ((sdSort == SD_SORT_TIME)?_SORT_CMP_TIME_DIR(FOLDER_SORTING):_SORT_CMP_DIR(FOLDER_SORTING)))
@ -909,7 +909,7 @@ void CardReader::presort() {
printf_P(PSTR("i%2d j%2d gap%2d orderBckp%2d\n"), i, j, gap, orderBckp); printf_P(PSTR("i%2d j%2d gap%2d orderBckp%2d\n"), i, j, gap, orderBckp);
#endif #endif
if (j < gap) break; if (j < gap) break;
getfilename_simple(sort_positions[sort_order[j - gap]]); getfilename_simple(sort_entries[sort_order[j - gap]]);
name2 = LONGEST_FILENAME; // use the string in-place name2 = LONGEST_FILENAME; // use the string in-place
} }
sort_order[j] = orderBckp; sort_order[j] = orderBckp;
@ -950,14 +950,14 @@ void CardReader::presort() {
const uint16_t o1 = sort_order[j], o2 = sort_order[j + 1]; const uint16_t o1 = sort_order[j], o2 = sort_order[j + 1];
counter++; counter++;
getfilename_simple(sort_positions[o1]); getfilename_simple(sort_entries[o1]);
strcpy(name1, LONGEST_FILENAME); // save (or getfilename below will trounce it) strcpy(name1, LONGEST_FILENAME); // save (or getfilename below will trounce it)
crmod_date_bckp = crmodDate; crmod_date_bckp = crmodDate;
crmod_time_bckp = crmodTime; crmod_time_bckp = crmodTime;
#if HAS_FOLDER_SORTING #if HAS_FOLDER_SORTING
bool dir1 = filenameIsDir; bool dir1 = filenameIsDir;
#endif #endif
getfilename_simple(sort_positions[o2]); getfilename_simple(sort_entries[o2]);
char *name2 = LONGEST_FILENAME; // use the string in-place char *name2 = LONGEST_FILENAME; // use the string in-place
// Sort the current pair according to settings. // Sort the current pair according to settings.
@ -995,26 +995,26 @@ void CardReader::presort() {
{ {
if (sort_order_reverse_index[i] != i) if (sort_order_reverse_index[i] != i)
{ {
uint32_t el = sort_positions[i]; uint32_t el = sort_entries[i];
uint8_t idx = sort_order_reverse_index[i]; uint8_t idx = sort_order_reverse_index[i];
while (idx != i) while (idx != i)
{ {
uint32_t el1 = sort_positions[idx]; uint32_t el1 = sort_entries[idx];
uint8_t idx1 = sort_order_reverse_index[idx]; uint8_t idx1 = sort_order_reverse_index[idx];
sort_order_reverse_index[idx] = idx; sort_order_reverse_index[idx] = idx;
sort_positions[idx] = el; sort_entries[idx] = el;
idx = idx1; idx = idx1;
el = el1; el = el1;
} }
sort_order_reverse_index[idx] = idx; sort_order_reverse_index[idx] = idx;
sort_positions[idx] = el; sort_entries[idx] = el;
} }
} }
menu_progressbar_finish(); menu_progressbar_finish();
} }
else { else {
getfilename(0); getfilename(0);
sort_positions[0] = position; sort_entries[0] = position >> 5;
} }
sort_count = fileCnt; sort_count = fileCnt;

View File

@ -46,7 +46,7 @@ public:
void printingHasFinished(); void printingHasFinished();
void getfilename(uint16_t nr, const char* const match=NULL); void getfilename(uint16_t nr, const char* const match=NULL);
void getfilename_simple(uint32_t position, const char * const match = NULL); void getfilename_simple(uint16_t entry, const char * const match = NULL);
void getfilename_next(uint32_t position, const char * const match = NULL); void getfilename_next(uint32_t position, const char * const match = NULL);
uint16_t getnrfilenames(); uint16_t getnrfilenames();
@ -111,7 +111,7 @@ private:
// Sort files and folders alphabetically. // Sort files and folders alphabetically.
#ifdef SDCARD_SORT_ALPHA #ifdef SDCARD_SORT_ALPHA
uint16_t sort_count; // Count of sorted items in the current directory uint16_t sort_count; // Count of sorted items in the current directory
uint32_t sort_positions[SDSORT_LIMIT]; uint16_t sort_entries[SDSORT_LIMIT];
#endif // SDCARD_SORT_ALPHA #endif // SDCARD_SORT_ALPHA