[Colorlcd] Support model notes with spaces and prevent radio crash due to filename (#645)
* support both versions of model notes file name. Fix for #641 * Adding support for names with spaces * Fix compilation
This commit is contained in:
+1
-1
@@ -303,7 +303,7 @@ char * getModelAudioPath(char * path)
|
|||||||
{
|
{
|
||||||
strcpy(path, SOUNDS_PATH "/");
|
strcpy(path, SOUNDS_PATH "/");
|
||||||
strncpy(path+SOUNDS_PATH_LNG_OFS, currentLanguagePack->id, 2);
|
strncpy(path+SOUNDS_PATH_LNG_OFS, currentLanguagePack->id, 2);
|
||||||
char * result = strcat_currentmodelname(path+sizeof(SOUNDS_PATH));
|
char * result = strcat_currentmodelname(path+sizeof(SOUNDS_PATH), 0);
|
||||||
*result++ = '/';
|
*result++ = '/';
|
||||||
*result = '\0';
|
*result = '\0';
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -428,15 +428,57 @@ void ViewTextWindow::drawVerticalScrollbar(BitmapBuffer *dc)
|
|||||||
|
|
||||||
#include "datastructs.h"
|
#include "datastructs.h"
|
||||||
|
|
||||||
|
static void replaceSpaceWithUnderscore(std::string& name)
|
||||||
|
{
|
||||||
|
size_t index;
|
||||||
|
do {
|
||||||
|
index = name.find(' ');
|
||||||
|
if(index != std::string::npos)
|
||||||
|
name[index] = '_';
|
||||||
|
} while (index != std::string::npos);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool openNotes(const char buf[], std::string modelNotesName)
|
||||||
|
{
|
||||||
|
if(isFileAvailable(modelNotesName.c_str())) {
|
||||||
|
new ViewTextWindow(std::string(buf), modelNotesName, ICON_MODEL);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
void readModelNotes()
|
void readModelNotes()
|
||||||
{
|
{
|
||||||
|
bool notesFound = false;
|
||||||
LED_ERROR_BEGIN();
|
LED_ERROR_BEGIN();
|
||||||
|
|
||||||
std::string modelNotesName(g_model.header.name);
|
std::string modelNotesName(g_model.header.name);
|
||||||
modelNotesName.append(TEXT_EXT);
|
modelNotesName.append(TEXT_EXT);
|
||||||
const char buf[] = {MODELS_PATH};
|
const char buf[] = {MODELS_PATH};
|
||||||
f_chdir((TCHAR*)buf);
|
f_chdir((TCHAR*)buf);
|
||||||
new ViewTextWindow(std::string(buf), modelNotesName, ICON_MODEL);
|
|
||||||
|
notesFound = openNotes(buf, modelNotesName);
|
||||||
|
if(!notesFound) {
|
||||||
|
replaceSpaceWithUnderscore(modelNotesName);
|
||||||
|
notesFound = openNotes(buf, modelNotesName);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !defined(EEPROM)
|
||||||
|
if(!notesFound) {
|
||||||
|
modelNotesName.assign(g_eeGeneral.currModelFilename);
|
||||||
|
size_t index = modelNotesName.find(".bin");
|
||||||
|
if(index != std::string::npos)
|
||||||
|
{
|
||||||
|
modelNotesName.erase(index);
|
||||||
|
modelNotesName.append(TEXT_EXT);
|
||||||
|
notesFound = openNotes(buf, modelNotesName);
|
||||||
|
}
|
||||||
|
if(!notesFound) {
|
||||||
|
replaceSpaceWithUnderscore(modelNotesName);
|
||||||
|
notesFound = openNotes(buf, modelNotesName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
LED_ERROR_END();
|
LED_ERROR_END();
|
||||||
}
|
}
|
||||||
@@ -830,7 +830,13 @@ bool isTrainerModeAvailable(int mode)
|
|||||||
bool modelHasNotes()
|
bool modelHasNotes()
|
||||||
{
|
{
|
||||||
char filename[sizeof(MODELS_PATH)+1+sizeof(g_model.header.name)+sizeof(TEXT_EXT)] = MODELS_PATH "/";
|
char filename[sizeof(MODELS_PATH)+1+sizeof(g_model.header.name)+sizeof(TEXT_EXT)] = MODELS_PATH "/";
|
||||||
char *buf = strcat_currentmodelname(&filename[sizeof(MODELS_PATH)]);
|
char *buf = strcat_currentmodelname(&filename[sizeof(MODELS_PATH)], 0);
|
||||||
|
strcpy(buf, TEXT_EXT);
|
||||||
|
if (isFileAvailable(filename)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf = strcat_currentmodelname(&filename[sizeof(MODELS_PATH)], ' ');
|
||||||
strcpy(buf, TEXT_EXT);
|
strcpy(buf, TEXT_EXT);
|
||||||
if (isFileAvailable(filename)) {
|
if (isFileAvailable(filename)) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
+5
-5
@@ -1182,13 +1182,13 @@ extern ReusableBuffer reusableBuffer;
|
|||||||
uint8_t zlen(const char *str, uint8_t size);
|
uint8_t zlen(const char *str, uint8_t size);
|
||||||
bool zexist(const char *str, uint8_t size);
|
bool zexist(const char *str, uint8_t size);
|
||||||
unsigned int effectiveLen(const char * str, unsigned int size);
|
unsigned int effectiveLen(const char * str, unsigned int size);
|
||||||
char * strcat_zchar(char *dest, const char *name, uint8_t size, const char *defaultName=nullptr, uint8_t defaultNameSize=0, uint8_t defaultIdx=0);
|
char * strcat_zchar(char *dest, const char *name, uint8_t size, const char spaceSym = 0, const char *defaultName=nullptr, uint8_t defaultNameSize=0, uint8_t defaultIdx=0);
|
||||||
#define strcatFlightmodeName(dest, idx) strcat_zchar(dest, g_model.flightModeData[idx].name, LEN_FLIGHT_MODE_NAME, STR_FM, PSIZE(TR_FM), idx+1)
|
#define strcatFlightmodeName(dest, idx) strcat_zchar(dest, g_model.flightModeData[idx].name, LEN_FLIGHT_MODE_NAME, 0, STR_FM, PSIZE(TR_FM), idx+1)
|
||||||
#if defined(EEPROM)
|
#if defined(EEPROM)
|
||||||
#define strcat_modelname(dest, idx) strcat_zchar(dest, modelHeaders[idx].name, LEN_MODEL_NAME, STR_MODEL, PSIZE(TR_MODEL), idx+1)
|
#define strcat_modelname(dest, idx) strcat_zchar(dest, modelHeaders[idx].name, LEN_MODEL_NAME, 0, STR_MODEL, PSIZE(TR_MODEL), idx+1)
|
||||||
#define strcat_currentmodelname(dest) strcat_modelname(dest, g_eeGeneral.currModel)
|
#define strcat_currentmodelname(dest, foo) strcat_modelname(dest, g_eeGeneral.currModel)
|
||||||
#else
|
#else
|
||||||
#define strcat_currentmodelname(dest) strcat_zchar(dest, g_model.header.name, LEN_MODEL_NAME)
|
#define strcat_currentmodelname(dest, spaceSym) strcat_zchar(dest, g_model.header.name, LEN_MODEL_NAME, spaceSym)
|
||||||
#endif
|
#endif
|
||||||
#define ZLEN(s) zlen(s, sizeof(s))
|
#define ZLEN(s) zlen(s, sizeof(s))
|
||||||
#define ZEXIST(s) zexist(s, sizeof(s))
|
#define ZEXIST(s) zexist(s, sizeof(s))
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ uint8_t zlen(const char * str, uint8_t size)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
char * strcat_zchar(char * dest, const char * name, uint8_t size, const char * defaultName, uint8_t defaultNameSize, uint8_t defaultIdx)
|
char * strcat_zchar(char * dest, const char * name, uint8_t size, const char spaceSym, const char * defaultName, uint8_t defaultNameSize, uint8_t defaultIdx)
|
||||||
{
|
{
|
||||||
int8_t len = 0;
|
int8_t len = 0;
|
||||||
|
|
||||||
@@ -142,7 +142,7 @@ char * strcat_zchar(char * dest, const char * name, uint8_t size, const char * d
|
|||||||
if (!len && dest[i])
|
if (!len && dest[i])
|
||||||
len = i+1;
|
len = i+1;
|
||||||
if (len) {
|
if (len) {
|
||||||
if (!dest[i])
|
if (dest[i] == spaceSym)
|
||||||
dest[i] = '_';
|
dest[i] = '_';
|
||||||
}
|
}
|
||||||
i--;
|
i--;
|
||||||
|
|||||||
Reference in New Issue
Block a user