mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
fixes and improvements
This commit is contained in:
@@ -32,6 +32,11 @@ void archive_set_file_type(ArchiveFile_t* file, const char* path, bool is_folder
|
||||
if(is_folder) {
|
||||
file->type = ArchiveFileTypeFolder;
|
||||
} else {
|
||||
char tmp_extension[MAX_EXT_LEN];
|
||||
path_extract_extension(file->path, tmp_extension, MAX_EXT_LEN);
|
||||
if((strcmp(tmp_extension, ".txt") == 0) || (strcmp(tmp_extension, ".md") == 0)) {
|
||||
file->is_text_file = true;
|
||||
}
|
||||
file->type = ArchiveFileTypeUnknown;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ typedef struct {
|
||||
FuriString* custom_name;
|
||||
bool fav;
|
||||
bool is_app;
|
||||
bool is_text_file;
|
||||
} ArchiveFile_t;
|
||||
|
||||
static void ArchiveFile_t_init(ArchiveFile_t* obj) {
|
||||
@@ -38,6 +39,7 @@ static void ArchiveFile_t_init(ArchiveFile_t* obj) {
|
||||
obj->custom_name = furi_string_alloc();
|
||||
obj->fav = false;
|
||||
obj->is_app = false;
|
||||
obj->is_text_file = false;
|
||||
}
|
||||
|
||||
static void ArchiveFile_t_init_set(ArchiveFile_t* obj, const ArchiveFile_t* src) {
|
||||
@@ -52,6 +54,7 @@ static void ArchiveFile_t_init_set(ArchiveFile_t* obj, const ArchiveFile_t* src)
|
||||
obj->custom_name = furi_string_alloc_set(src->custom_name);
|
||||
obj->fav = src->fav;
|
||||
obj->is_app = src->is_app;
|
||||
obj->is_text_file = src->is_text_file;
|
||||
}
|
||||
|
||||
static void ArchiveFile_t_set(ArchiveFile_t* obj, const ArchiveFile_t* src) {
|
||||
@@ -66,6 +69,7 @@ static void ArchiveFile_t_set(ArchiveFile_t* obj, const ArchiveFile_t* src) {
|
||||
furi_string_set(obj->custom_name, src->custom_name);
|
||||
obj->fav = src->fav;
|
||||
obj->is_app = src->is_app;
|
||||
obj->is_text_file = src->is_text_file;
|
||||
}
|
||||
|
||||
static void ArchiveFile_t_clear(ArchiveFile_t* obj) {
|
||||
|
||||
@@ -19,9 +19,7 @@ void archive_scene_show_on_enter(void* context) {
|
||||
ArchiveApp* instance = context;
|
||||
|
||||
FuriString* filename;
|
||||
FuriString* str_size;
|
||||
filename = furi_string_alloc();
|
||||
str_size = furi_string_alloc();
|
||||
|
||||
ArchiveFile_t* current = archive_get_current_file(instance->browser);
|
||||
Storage* fs_api = furi_record_open(RECORD_STORAGE);
|
||||
@@ -29,26 +27,57 @@ void archive_scene_show_on_enter(void* context) {
|
||||
uint32_t bytes_count;
|
||||
|
||||
FileInfo fileinfo;
|
||||
storage_common_stat(fs_api, furi_string_get_cstr(current->path), &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) {
|
||||
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 (fileinfo.size < SHOW_MAX_FILE_SIZE) {
|
||||
storage_file_open(file, furi_string_get_cstr(current->path), FSAM_READ, FSOM_OPEN_EXISTING);
|
||||
char* content = malloc(fileinfo.size + 1);
|
||||
bytes_count = storage_file_read(file, content, fileinfo.size);
|
||||
content[bytes_count + 1] = 0;
|
||||
|
||||
bytes_count = storage_file_read(file, content, fileinfo.size);
|
||||
content[bytes_count + 1] = 0;
|
||||
widget_add_text_scroll_element(instance->widget, 0, 0, 128, 64, content);
|
||||
|
||||
widget_add_text_scroll_element(
|
||||
instance->widget, 0, 0, 128, 64, content);
|
||||
|
||||
free(content);
|
||||
storage_file_close(file);
|
||||
free(content);
|
||||
} else {
|
||||
widget_add_text_box_element(
|
||||
instance->widget,
|
||||
0,
|
||||
0,
|
||||
128,
|
||||
64,
|
||||
AlignLeft,
|
||||
AlignCenter,
|
||||
"\e#Error:\nStorage file open error\e#",
|
||||
false);
|
||||
}
|
||||
storage_file_close(file);
|
||||
} else {
|
||||
widget_add_text_box_element(
|
||||
instance->widget,
|
||||
0,
|
||||
0,
|
||||
128,
|
||||
64,
|
||||
AlignLeft,
|
||||
AlignCenter,
|
||||
"\e#Error:\nFile is too large to show\e#",
|
||||
false);
|
||||
}
|
||||
} else {
|
||||
widget_add_text_box_element(
|
||||
instance->widget, 0, 0, 128, 64, AlignLeft, AlignCenter,
|
||||
"\e#Error:\nFile is too large to show\e#", false);
|
||||
instance->widget,
|
||||
0,
|
||||
0,
|
||||
128,
|
||||
64,
|
||||
AlignLeft,
|
||||
AlignCenter,
|
||||
"\e#Error:\nFile system error\e#",
|
||||
false);
|
||||
}
|
||||
|
||||
path_extract_filename(current->path, filename, false);
|
||||
|
||||
// This one to return and cursor select this file
|
||||
@@ -59,7 +88,6 @@ void archive_scene_show_on_enter(void* context) {
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
furi_string_free(filename);
|
||||
furi_string_free(str_size);
|
||||
|
||||
view_dispatcher_switch_to_view(instance->view_dispatcher, ArchiveViewWidget);
|
||||
}
|
||||
|
||||
@@ -80,10 +80,12 @@ static void render_item_menu(Canvas* canvas, ArchiveBrowserViewModel* model) {
|
||||
menu_array_push_raw(model->context_menu),
|
||||
item_info,
|
||||
ArchiveBrowserEventFileMenuInfo);
|
||||
archive_menu_add_item(
|
||||
menu_array_push_raw(model->context_menu),
|
||||
item_show,
|
||||
ArchiveBrowserEventFileMenuShow);
|
||||
if(selected->is_text_file) {
|
||||
archive_menu_add_item(
|
||||
menu_array_push_raw(model->context_menu),
|
||||
item_show,
|
||||
ArchiveBrowserEventFileMenuShow);
|
||||
}
|
||||
archive_menu_add_item(
|
||||
menu_array_push_raw(model->context_menu),
|
||||
item_rename,
|
||||
@@ -105,10 +107,12 @@ static void render_item_menu(Canvas* canvas, ArchiveBrowserViewModel* model) {
|
||||
menu_array_push_raw(model->context_menu),
|
||||
item_pin,
|
||||
ArchiveBrowserEventFileMenuPin);
|
||||
archive_menu_add_item(
|
||||
menu_array_push_raw(model->context_menu),
|
||||
item_show,
|
||||
ArchiveBrowserEventFileMenuShow);
|
||||
if(selected->type <= ArchiveFileTypeBadUsb) {
|
||||
archive_menu_add_item(
|
||||
menu_array_push_raw(model->context_menu),
|
||||
item_show,
|
||||
ArchiveBrowserEventFileMenuShow);
|
||||
}
|
||||
archive_menu_add_item(
|
||||
menu_array_push_raw(model->context_menu),
|
||||
item_rename,
|
||||
@@ -123,10 +127,12 @@ static void render_item_menu(Canvas* canvas, ArchiveBrowserViewModel* model) {
|
||||
menu_array_push_raw(model->context_menu),
|
||||
item_info,
|
||||
ArchiveBrowserEventFileMenuInfo);
|
||||
archive_menu_add_item(
|
||||
menu_array_push_raw(model->context_menu),
|
||||
item_show,
|
||||
ArchiveBrowserEventFileMenuShow);
|
||||
if(selected->type <= ArchiveFileTypeBadUsb) {
|
||||
archive_menu_add_item(
|
||||
menu_array_push_raw(model->context_menu),
|
||||
item_show,
|
||||
ArchiveBrowserEventFileMenuShow);
|
||||
}
|
||||
archive_menu_add_item(
|
||||
menu_array_push_raw(model->context_menu),
|
||||
item_pin,
|
||||
@@ -149,10 +155,12 @@ static void render_item_menu(Canvas* canvas, ArchiveBrowserViewModel* model) {
|
||||
menu_array_push_raw(model->context_menu),
|
||||
item_info,
|
||||
ArchiveBrowserEventFileMenuInfo);
|
||||
archive_menu_add_item(
|
||||
menu_array_push_raw(model->context_menu),
|
||||
item_show,
|
||||
ArchiveBrowserEventFileMenuShow);
|
||||
if(selected->type <= ArchiveFileTypeBadUsb) {
|
||||
archive_menu_add_item(
|
||||
menu_array_push_raw(model->context_menu),
|
||||
item_show,
|
||||
ArchiveBrowserEventFileMenuShow);
|
||||
}
|
||||
archive_menu_add_item(
|
||||
menu_array_push_raw(model->context_menu),
|
||||
item_rename,
|
||||
|
||||
@@ -63,9 +63,9 @@ FuriString* subghz_history_generate_temp_filename(uint32_t index) {
|
||||
|
||||
bool subghz_history_is_tmp_dir_exists(SubGhzHistory* instance) {
|
||||
FileInfo file_info;
|
||||
storage_common_stat(instance->storage, SUBGHZ_HISTORY_TMP_DIR, &file_info);
|
||||
FS_Error error = storage_common_stat(instance->storage, SUBGHZ_HISTORY_TMP_DIR, &file_info);
|
||||
|
||||
if(storage_common_stat(instance->storage, SUBGHZ_HISTORY_TMP_DIR, &file_info) == FSE_OK) {
|
||||
if(error == FSE_OK) {
|
||||
if(file_info.flags & FSF_DIRECTORY) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user