mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2025-12-13 13:09:49 +04:00
more checks and limits
This commit is contained in:
@@ -5,7 +5,7 @@ App(
|
||||
entry_point="archive_app",
|
||||
cdefines=["APP_ARCHIVE"],
|
||||
requires=["gui"],
|
||||
stack_size=4 * 1024,
|
||||
stack_size=6 * 1024,
|
||||
icon="A_FileManager_14",
|
||||
order=0,
|
||||
)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#define TAG "Archive"
|
||||
|
||||
#define SHOW_MAX_FILE_SIZE 20000
|
||||
#define SHOW_MAX_FILE_SIZE 5000
|
||||
|
||||
void archive_scene_show_widget_callback(GuiButtonType result, InputType type, void* context) {
|
||||
furi_assert(context);
|
||||
@@ -14,6 +14,22 @@ void archive_scene_show_widget_callback(GuiButtonType result, InputType type, vo
|
||||
}
|
||||
}
|
||||
|
||||
static bool text_show_read_lines(File* file, FuriString* str_result) {
|
||||
//furi_string_reset(str_result);
|
||||
uint8_t buffer[SHOW_MAX_FILE_SIZE];
|
||||
|
||||
uint16_t read_count = storage_file_read(file, buffer, SHOW_MAX_FILE_SIZE);
|
||||
if(storage_file_get_error(file) != FSE_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for(uint16_t i = 0; i < read_count; i++) {
|
||||
furi_string_push_back(str_result, buffer[i]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void archive_scene_show_on_enter(void* context) {
|
||||
furi_assert(context);
|
||||
ArchiveApp* instance = context;
|
||||
@@ -21,27 +37,34 @@ void archive_scene_show_on_enter(void* context) {
|
||||
FuriString* filename;
|
||||
filename = furi_string_alloc();
|
||||
|
||||
FuriString* buffer;
|
||||
buffer = furi_string_alloc();
|
||||
|
||||
ArchiveFile_t* current = archive_get_current_file(instance->browser);
|
||||
Storage* fs_api = furi_record_open(RECORD_STORAGE);
|
||||
File* file = storage_file_alloc(fs_api);
|
||||
uint32_t bytes_count;
|
||||
|
||||
FileInfo fileinfo;
|
||||
FS_Error error = storage_common_stat(fs_api, furi_string_get_cstr(current->path), &fileinfo);
|
||||
if(error == FSE_OK) {
|
||||
if(fileinfo.size < SHOW_MAX_FILE_SIZE) {
|
||||
if((fileinfo.size < SHOW_MAX_FILE_SIZE) && (fileinfo.size > 2)) {
|
||||
bool ok = storage_file_open(
|
||||
file, furi_string_get_cstr(current->path), FSAM_READ, FSOM_OPEN_EXISTING);
|
||||
if(ok) {
|
||||
char* content = malloc(fileinfo.size + 1);
|
||||
if(!text_show_read_lines(file, buffer)) {
|
||||
goto text_file_read_err;
|
||||
}
|
||||
if(!furi_string_size(buffer)) {
|
||||
goto text_file_read_err;
|
||||
}
|
||||
|
||||
bytes_count = storage_file_read(file, content, fileinfo.size);
|
||||
content[bytes_count + 1] = 0;
|
||||
storage_file_seek(file, 0, true);
|
||||
|
||||
widget_add_text_scroll_element(instance->widget, 0, 0, 128, 64, content);
|
||||
widget_add_text_scroll_element(
|
||||
instance->widget, 0, 0, 128, 64, furi_string_get_cstr(buffer));
|
||||
|
||||
free(content);
|
||||
} else {
|
||||
text_file_read_err:
|
||||
widget_add_text_box_element(
|
||||
instance->widget,
|
||||
0,
|
||||
@@ -54,6 +77,17 @@ void archive_scene_show_on_enter(void* context) {
|
||||
false);
|
||||
}
|
||||
storage_file_close(file);
|
||||
} else if(fileinfo.size < 2) {
|
||||
widget_add_text_box_element(
|
||||
instance->widget,
|
||||
0,
|
||||
0,
|
||||
128,
|
||||
64,
|
||||
AlignLeft,
|
||||
AlignCenter,
|
||||
"\e#Error:\nFile is too small\e#",
|
||||
false);
|
||||
} else {
|
||||
widget_add_text_box_element(
|
||||
instance->widget,
|
||||
@@ -84,6 +118,8 @@ void archive_scene_show_on_enter(void* context) {
|
||||
path_extract_filename_no_ext(furi_string_get_cstr(current->path), filename);
|
||||
strlcpy(instance->text_store, furi_string_get_cstr(filename), MAX_NAME_LEN);
|
||||
|
||||
furi_string_free(buffer);
|
||||
|
||||
storage_file_free(file);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user