From 63cb4413a6dbd06d2bd617cba2962059dc07dce5 Mon Sep 17 00:00:00 2001 From: positionhigh Date: Sat, 10 Jul 2021 15:07:49 +0200 Subject: [PATCH] =?UTF-8?q?Dateien=20hochladen=20nach=20=E2=80=9E=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MicroDexed.ino | 52 +++++++++++++++++++++++++++++++++++++------------- UI.hpp | 28 ++++++++++++--------------- 2 files changed, 51 insertions(+), 29 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index 42ce98d..9000e73 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -2190,7 +2190,7 @@ void check_and_create_directories(void) } } - // create directories for confgiuration files + // create directories for configuration files sprintf(tmp, "/%s", VOICE_CONFIG_PATH); if (!SD.exists(tmp)) { @@ -2228,18 +2228,44 @@ void check_and_create_directories(void) SD.mkdir(tmp); } - /* - for (uint8_t i = 0; i < MAX_BANKS; i++) - { - sprintf(tmp, "/%s/%d", FAV_CONFIG_PATH, i); - #ifdef DEBUG - Serial.print(F("Creating directory ")); - Serial.println(tmp); - #endif - if (!SD.exists(tmp)) - SD.mkdir(tmp); - } - */ + //check if updated Fav-System is ready or if setup has to run once. + + sprintf(tmp, "/%s/fav-v2", FAV_CONFIG_PATH); + if (!SD.exists(tmp)) { + + // Clear now obsolte marker files from Favs. + // Only needs to run once. + for (uint8_t i = 0; i < MAX_BANKS; i++) + { + sprintf(tmp, "/%s/%d/hasfav", FAV_CONFIG_PATH, i); +#ifdef DEBUG + Serial.print(F("Delete Marker File")); + Serial.println(tmp); +#endif + if (SD.exists(tmp)) + SD.remove(tmp); + } + + // Remove empty Folders. rmdir will only remove strictly emtpy folders, which is the desired result. + // Only needs to run once. + for (uint8_t i = 0; i < MAX_BANKS; i++) + { + sprintf(tmp, "/%s/%d", FAV_CONFIG_PATH, i); +#ifdef DEBUG + Serial.print(F("Delete empty folder")); + Serial.println(tmp); +#endif + if (SD.exists(tmp)) + SD.rmdir(tmp); + } + + sprintf(tmp, "/%s/fav-v2", FAV_CONFIG_PATH); + if (!SD.exists(tmp)) + SD.mkdir(tmp); // Set Marker so that the Cleanup loops only run once. + } else + Serial.println(F("Favs-V2 ready. ")); + + } #ifdef DEBUG else diff --git a/UI.hpp b/UI.hpp index 9275eb8..a931459 100644 --- a/UI.hpp +++ b/UI.hpp @@ -6263,7 +6263,7 @@ bool quick_check_favorites_in_bank(uint8_t b, uint8_t instance_id) if (sd_card > 0) { - sprintf(tmp, "/%s/%d/hasfav", FAV_CONFIG_PATH, b); + sprintf(tmp, "/%s/%d", FAV_CONFIG_PATH, b); #ifdef DEBUG Serial.print("check if there is a Favorite in Bank: "); Serial.print(tmp); @@ -6298,12 +6298,14 @@ void save_favorite(uint8_t b, uint8_t v, uint8_t instance_id) b = constrain(b, 0, MAX_BANKS - 1); v = constrain(v, 0, MAX_VOICES - 1); char tmp[18]; + char tmpfolder[18]; File myFav; uint8_t i = 0, countfavs = 0; if (sd_card > 0) { sprintf(tmp, "/%s/%d/%d.fav", FAV_CONFIG_PATH, b, v); + sprintf(tmpfolder, "/%s/%d", FAV_CONFIG_PATH, b); #ifdef DEBUG Serial.println("Save Favorite to SD card..."); Serial.println(tmp); @@ -6311,21 +6313,14 @@ void save_favorite(uint8_t b, uint8_t v, uint8_t instance_id) if (!SD.exists(tmp)) { //create Favorite Semaphore - SD.mkdir(tmp); + if (!SD.exists(tmpfolder)) + { + SD.mkdir(tmpfolder); + } myFav = SD.open(tmp, FILE_WRITE); myFav.close(); Serial.println("Favorite saved..."); - sprintf(tmp, "/%s/%d/hasfav", FAV_CONFIG_PATH, b); //for quick search, bank contains at least 1 favorite - if (!SD.exists(tmp)) - { - myFav = SD.open(tmp, FILE_WRITE); -#ifdef DEBUG - Serial.println("write hasfav file to:"); - Serial.print(tmp); -#endif - myFav.close(); - } lcd.setCursor(13, 0); lcd.write(2); //fav symbol #ifdef DEBUG @@ -6338,17 +6333,18 @@ void save_favorite(uint8_t b, uint8_t v, uint8_t instance_id) #ifdef DEBUG Serial.println("Removed from Favorites..."); #endif - for (i = 0; i < 32; i++) { //if no other favs exist in current bank, remove quick search semaphore + for (i = 0; i < 32; i++) { //if no other favs exist in current bank, remove folder sprintf(tmp, "/%s/%d/%d.fav", FAV_CONFIG_PATH, b, i); if (SD.exists(tmp)) countfavs++; } if (countfavs == 0) { - sprintf(tmp, "/%s/%d/hasfav", FAV_CONFIG_PATH, b); - SD.remove(tmp); + sprintf(tmp, "/%s/%d", FAV_CONFIG_PATH, b); + SD.rmdir(tmp); + #ifdef DEBUG Serial.println("Fav count in bank:"); Serial.print(countfavs); - Serial.println("Removed hasfav file since no voice in bank flagged as favorite any more"); + Serial.println("Removed folder since no voice in bank flagged as favorite any more"); #endif } lcd.setCursor(13, 0);