[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:
@@ -428,15 +428,57 @@ void ViewTextWindow::drawVerticalScrollbar(BitmapBuffer *dc)
|
||||
|
||||
#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()
|
||||
{
|
||||
bool notesFound = false;
|
||||
LED_ERROR_BEGIN();
|
||||
|
||||
std::string modelNotesName(g_model.header.name);
|
||||
modelNotesName.append(TEXT_EXT);
|
||||
const char buf[] = {MODELS_PATH};
|
||||
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();
|
||||
}
|
||||
@@ -830,7 +830,13 @@ bool isTrainerModeAvailable(int mode)
|
||||
bool modelHasNotes()
|
||||
{
|
||||
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);
|
||||
if (isFileAvailable(filename)) {
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user