Merge pull request #1532 from meshtastic/patch-1

avoid BLE device names like a123_a123
This commit is contained in:
Thomas Göttgens 2022-06-22 15:44:25 +02:00 committed by GitHub
commit 9f78dff25f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 25 deletions

View File

@ -2,8 +2,8 @@
#include "FSCommon.h" #include "FSCommon.h"
void listDir(const char * dirname, uint8_t levels) void listDir(const char * dirname, uint8_t levels)
#ifdef FSCom
{ {
#ifdef FSCom
File root = FSCom.open(dirname); File root = FSCom.open(dirname);
if(!root){ if(!root){
return; return;
@ -29,29 +29,41 @@ void listDir(const char * dirname, uint8_t levels)
} }
void rmDir(const char * dirname) void rmDir(const char * dirname)
#ifdef FSCom
{ {
File root = FSCom.open(dirname); #ifdef FSCom
if(!root){ File file = FSCom.open(dirname);
if(!file){
return; return;
} }
if(!root.isDirectory()){ if(!file.isDirectory()){
file.close();
FSCom.remove(file.name());
// DEBUG_MSG("Remove FILE %s\n", file.name());
return; return;
} }
File file = root.openNextFile(); file.rewindDirectory();
while(file){ while (true) {
if(file.isDirectory() && !String(file.name()).endsWith(".")) { File entry = file.openNextFile();
file.close(); if (!entry) {
rmDir(file.name()); break;
FSCom.rmdir(file.name()); }
char dirpath[100]; // array to hold the result.
strcpy(dirpath, dirname); // copy string one into the result.
strcat(dirpath,"/"); // append string two to the result.
strcat(dirpath,entry.name()); // append string two to the result.
if(entry.isDirectory() && !String(entry.name()).endsWith(".")) {
entry.close();
// DEBUG_MSG("Descend DIR %s\n", dirpath);
rmDir(dirpath);
} else { } else {
file.close(); entry.close();
FSCom.remove(file.name()); // DEBUG_MSG("Remove FILE %s\n", entry.name());
FSCom.remove(entry.name());
} }
file.close();
file = root.openNextFile();
} }
FSCom.rmdir(dirname);
// DEBUG_MSG("Remove DIR %s\n", dirname);
file.close(); file.close();
#endif #endif
} }

View File

@ -105,7 +105,7 @@ const char *getDeviceName()
static char name[20]; static char name[20];
sprintf(name, "%02x%02x", dmac[4], dmac[5]); sprintf(name, "%02x%02x", dmac[4], dmac[5]);
// if the shortname exists and is NOT the new default of ab3c, use it for BLE name. // if the shortname exists and is NOT the new default of ab3c, use it for BLE name.
if ((owner.short_name != NULL) && (owner.short_name != name)) { if ((owner.short_name != NULL) && (strcmp(owner.short_name, name) != 0)) {
sprintf(name, "%s_%02x%02x", owner.short_name, dmac[4], dmac[5]); sprintf(name, "%s_%02x%02x", owner.short_name, dmac[4], dmac[5]);
} else { } else {
sprintf(name, "Meshtastic_%02x%02x", dmac[4], dmac[5]); sprintf(name, "Meshtastic_%02x%02x", dmac[4], dmac[5]);