Further confined v220 data structures

This commit is contained in:
Raphael Coeffic
2021-11-10 11:07:01 +01:00
parent 7b6749ebee
commit f932e9e12c
15 changed files with 175 additions and 125 deletions
+10 -2
View File
@@ -18,7 +18,12 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "theme_manager.h"
#include "theme.h"
#include <cstdlib>
#include <cstring>
ThemePersistance themePersistance;
@@ -93,7 +98,7 @@ void ThemeFile::scanFile()
char *plvalue;
char *prvalue;
strncpy(lvalue, line, min((int)(ptr - line), 63));
strncpy(lvalue, line, std::min((int)(ptr - line), 63));
lvalue[ptr - line] = '\0';
strncpy(rvalue, ptr + 1, 63);
plvalue = trim(lvalue);
@@ -226,6 +231,9 @@ void ThemeFile::applyTheme()
OpenTxTheme::instance()->update(false);
}
// not sure why this is needed...
constexpr unsigned MAX_SD_FILE_LENGTH = 64;
void ThemePersistance::scanForThemes()
{
TRACE("in scanForThemes");
@@ -251,7 +259,7 @@ void ThemePersistance::scanForThemes()
if (res != FR_OK || fno.fname[0] == 0)
break; // Break on error or end of dir
if (strlen((const char *)fno.fname) > SD_SCREEN_FILE_LENGTH) continue;
if (strlen((const char *)fno.fname) > MAX_SD_FILE_LENGTH) continue;
if (fno.fattrib & AM_DIR) continue;
TRACE("scanForThemes: found file %s", fno.fname);
+8 -1
View File
@@ -18,15 +18,22 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#pragma once
#include <stdlib.h>
#include <list>
#include <string>
#include <vector>
#include <locale>
#include "debug.h"
#include "sdcard.h"
#include "colors.h"
#include "str_functions.h"
// sdReadir: used to be in "sdcard.h" (another GPL violation...)
#include "libopenui_file.h"
class ThemePersistance;
extern ThemePersistance themePersistance;
+68
View File
@@ -29,6 +29,74 @@
#define EVT_KEY_PREVIOUS_LINE EVT_KEY_FIRST(KEY_UP)
#endif
constexpr uint32_t TEXT_FILE_MAXSIZE = 2048;
static void sdReadTextFile(const char * filename, char lines[TEXT_VIEWER_LINES][LCD_COLS + 1], int & lines_count)
{
FIL file;
int result;
char c;
unsigned int sz;
int line_length = 0;
uint8_t escape = 0;
char escape_chars[4] = {0};
int current_line = 0;
memclear(lines, TEXT_VIEWER_LINES * (LCD_COLS + 1));
result = f_open(&file, filename, FA_OPEN_EXISTING | FA_READ);
if (result == FR_OK) {
for (uint32_t i = 0; i < TEXT_FILE_MAXSIZE && f_read(&file, &c, 1, &sz) == FR_OK && sz == 1 && (lines_count == 0 || current_line - menuVerticalOffset < int(TEXT_VIEWER_LINES)); i++) {
if (c == '\n') {
++current_line;
line_length = 0;
escape = 0;
}
else if (c != '\r' && current_line >= menuVerticalOffset && current_line - menuVerticalOffset < int(TEXT_VIEWER_LINES) && line_length < LCD_COLS) {
if (c == '\\' && escape == 0) {
escape = 1;
continue;
}
else if (c != '\\' && escape > 0 && escape < sizeof(escape_chars)) {
escape_chars[escape - 1] = c;
if (escape == 2 && !strncmp(escape_chars, "up", 2)) {
c = CHAR_UP;
}
else if (escape == 2 && !strncmp(escape_chars, "dn", 2)) {
c = CHAR_DOWN;
}
else if (escape == 3) {
int val = atoi(escape_chars);
if (val >= 200 && val < 225) {
c = '\200' + val - 200;
}
}
else {
escape++;
continue;
}
}
else if (c=='~') {
c = 'z'+1;
}
else if (c=='\t') {
c = 0x1D; //tab
}
escape = 0;
lines[current_line-menuVerticalOffset][line_length++] = c;
}
}
if (c != '\n') {
current_line += 1;
}
f_close(&file);
}
if (lines_count == 0) {
lines_count = current_line;
}
}
void readModelNotes()
{
LED_ERROR_BEGIN();