1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-15 20:35:17 +03:00
This commit is contained in:
bsongis 2014-08-16 11:17:45 +02:00
parent 18748b4d6a
commit e89c920c4e
3 changed files with 17 additions and 8 deletions

View file

@ -859,12 +859,7 @@ void onSdManagerMenu(const char *result)
#endif #endif
#if defined(PCBTARANIS) #if defined(PCBTARANIS)
else if (result == STR_ASSIGN_BITMAP) { else if (result == STR_ASSIGN_BITMAP) {
strcpy(lfn, reusableBuffer.sdmanager.lines[index]); strAppendFilename(g_model.header.bitmap, reusableBuffer.sdmanager.lines[index], sizeof(g_model.header.bitmap));
// TODO duplicated code for finding extension
uint8_t len = strlen(lfn) - 4;
memset(lfn+len, 0, sizeof(g_model.header.bitmap)-len);
// TODO duplicated code
memcpy(g_model.header.bitmap, lfn, sizeof(g_model.header.bitmap));
LOAD_MODEL_BITMAP(); LOAD_MODEL_BITMAP();
memcpy(modelHeaders[g_eeGeneral.currModel].bitmap, g_model.header.bitmap, sizeof(g_model.header.bitmap)); memcpy(modelHeaders[g_eeGeneral.currModel].bitmap, g_model.header.bitmap, sizeof(g_model.header.bitmap));
eeDirty(EE_MODEL); eeDirty(EE_MODEL);
@ -983,7 +978,8 @@ void menuGeneralSdManager(uint8_t _event)
uint8_t index = m_posVert-1-s_pgOfs; uint8_t index = m_posVert-1-s_pgOfs;
// TODO duplicated code for finding extension // TODO duplicated code for finding extension
char * ext = reusableBuffer.sdmanager.lines[index]; char * ext = reusableBuffer.sdmanager.lines[index];
ext += strlen(ext) - 4; int len = strlen(ext) - 4;
ext += len;
/* TODO if (!strcasecmp(ext, MODELS_EXT)) { /* TODO if (!strcasecmp(ext, MODELS_EXT)) {
s_menu[s_menu_count++] = STR_LOAD_FILE; s_menu[s_menu_count++] = STR_LOAD_FILE;
} }
@ -992,7 +988,7 @@ void menuGeneralSdManager(uint8_t _event)
} }
#endif #endif
#if defined(PCBTARANIS) #if defined(PCBTARANIS)
else if (!strcasecmp(ext, BITMAPS_EXT) && !READ_ONLY()) { else if (!strcasecmp(ext, BITMAPS_EXT) && !READ_ONLY() && len <= (int)sizeof(g_model.header.bitmap)) {
MENU_ADD_ITEM(STR_ASSIGN_BITMAP); MENU_ADD_ITEM(STR_ASSIGN_BITMAP);
} }
else if (!strcasecmp(ext, TEXT_EXT)) { else if (!strcasecmp(ext, TEXT_EXT)) {

View file

@ -299,5 +299,6 @@ void lcdSetContrast();
char * strAppend(char * dest, const char * source); char * strAppend(char * dest, const char * source);
char * strAppendDate(char * str, bool time=false); char * strAppendDate(char * str, bool time=false);
char * strAppendFilename(char * dest, const char * filename, const int size);
#endif #endif

View file

@ -151,6 +151,18 @@ char * strAppend(char * dest, const char * source)
return dest - 1; return dest - 1;
} }
char * strAppendFilename(char * dest, const char * filename, const int size)
{
memset(dest, 0, size);
for (int i=0; i<size; i++) {
char c = *filename++;
if (c == '\0' || c == '.')
break;
*dest++ = c;
}
return dest;
}
#if defined(RTCLOCK) #if defined(RTCLOCK)
#include "rtc.h" #include "rtc.h"