2021-09-10 00:57:43 +00:00
|
|
|
#include "archive_files.h"
|
2022-02-10 13:01:49 +00:00
|
|
|
#include "archive_apps.h"
|
2021-09-21 10:56:33 +00:00
|
|
|
#include "archive_browser.h"
|
2021-09-10 00:57:43 +00:00
|
|
|
|
2021-11-12 13:04:35 +00:00
|
|
|
#define TAG "Archive"
|
|
|
|
|
2022-02-10 13:01:49 +00:00
|
|
|
#define ASSETS_DIR "assets"
|
|
|
|
|
2022-06-09 07:09:52 +00:00
|
|
|
void archive_set_file_type(ArchiveFile_t* file, const char* path, bool is_folder, bool is_app) {
|
2021-09-10 00:57:43 +00:00
|
|
|
furi_assert(file);
|
|
|
|
|
2022-02-10 13:01:49 +00:00
|
|
|
file->is_app = is_app;
|
|
|
|
if(is_app) {
|
|
|
|
file->type = archive_get_app_filetype(archive_get_app_type(path));
|
|
|
|
} else {
|
2022-05-06 13:37:10 +00:00
|
|
|
for(size_t i = 0; i < COUNT_OF(known_ext); i++) {
|
2022-02-10 13:01:49 +00:00
|
|
|
if((known_ext[i][0] == '?') || (known_ext[i][0] == '*')) continue;
|
2022-10-05 15:15:23 +00:00
|
|
|
if(furi_string_search(file->path, known_ext[i], 0) != FURI_STRING_FAILURE) {
|
2022-02-10 13:01:49 +00:00
|
|
|
if(i == ArchiveFileTypeBadUsb) {
|
2022-10-05 15:15:23 +00:00
|
|
|
if(furi_string_search(
|
|
|
|
file->path, archive_get_default_path(ArchiveTabBadUsb)) == 0) {
|
2022-02-10 13:01:49 +00:00
|
|
|
file->type = i;
|
|
|
|
return; // *.txt file is a BadUSB script only if it is in BadUSB folder
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
file->type = i;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2021-09-10 00:57:43 +00:00
|
|
|
}
|
|
|
|
|
2022-06-09 07:09:52 +00:00
|
|
|
if(is_folder) {
|
2022-02-10 13:01:49 +00:00
|
|
|
file->type = ArchiveFileTypeFolder;
|
|
|
|
} else {
|
|
|
|
file->type = ArchiveFileTypeUnknown;
|
|
|
|
}
|
2021-09-10 00:57:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-09 07:09:52 +00:00
|
|
|
bool archive_get_items(void* context, const char* path) {
|
2021-09-10 00:57:43 +00:00
|
|
|
furi_assert(context);
|
|
|
|
|
2022-06-09 07:09:52 +00:00
|
|
|
bool res = false;
|
2021-09-21 10:56:33 +00:00
|
|
|
ArchiveBrowserView* browser = context;
|
2021-09-10 00:57:43 +00:00
|
|
|
|
2022-02-10 13:01:49 +00:00
|
|
|
if(archive_get_tab(browser) == ArchiveTabFavorites) {
|
2021-09-21 10:56:33 +00:00
|
|
|
res = archive_favorites_read(browser);
|
2022-02-10 13:01:49 +00:00
|
|
|
} else if(strncmp(path, "/app:", 5) == 0) {
|
|
|
|
res = archive_app_read_dir(browser, path);
|
2021-09-10 00:57:43 +00:00
|
|
|
}
|
2021-09-21 10:56:33 +00:00
|
|
|
return res;
|
2021-09-10 00:57:43 +00:00
|
|
|
}
|
|
|
|
|
2021-09-21 10:56:33 +00:00
|
|
|
void archive_file_append(const char* path, const char* format, ...) {
|
2021-09-10 00:57:43 +00:00
|
|
|
furi_assert(path);
|
2021-09-21 10:56:33 +00:00
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
FuriString* string;
|
2021-09-21 10:56:33 +00:00
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
2022-10-05 15:15:23 +00:00
|
|
|
string = furi_string_alloc_vprintf(format, args);
|
2021-09-21 10:56:33 +00:00
|
|
|
va_end(args);
|
2021-09-10 00:57:43 +00:00
|
|
|
|
2022-07-26 12:21:51 +00:00
|
|
|
Storage* fs_api = furi_record_open(RECORD_STORAGE);
|
2022-04-14 11:28:59 +00:00
|
|
|
File* file = storage_file_alloc(fs_api);
|
2021-09-10 00:57:43 +00:00
|
|
|
|
2022-04-14 11:28:59 +00:00
|
|
|
bool res = storage_file_open(file, path, FSAM_WRITE, FSOM_OPEN_APPEND);
|
2021-09-10 00:57:43 +00:00
|
|
|
|
2022-04-14 11:28:59 +00:00
|
|
|
if(res) {
|
2022-10-05 15:15:23 +00:00
|
|
|
storage_file_write(file, furi_string_get_cstr(string), furi_string_size(string));
|
2021-09-10 00:57:43 +00:00
|
|
|
}
|
|
|
|
|
2022-04-14 11:28:59 +00:00
|
|
|
storage_file_close(file);
|
|
|
|
storage_file_free(file);
|
2022-07-26 12:21:51 +00:00
|
|
|
furi_record_close(RECORD_STORAGE);
|
2021-09-10 00:57:43 +00:00
|
|
|
}
|
|
|
|
|
2021-10-12 13:09:34 +00:00
|
|
|
void archive_delete_file(void* context, const char* format, ...) {
|
2021-09-10 00:57:43 +00:00
|
|
|
furi_assert(context);
|
2021-10-12 13:09:34 +00:00
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
FuriString* filename;
|
2021-10-12 13:09:34 +00:00
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
2022-10-05 15:15:23 +00:00
|
|
|
filename = furi_string_alloc_vprintf(format, args);
|
2021-10-12 13:09:34 +00:00
|
|
|
va_end(args);
|
|
|
|
|
2021-09-21 10:56:33 +00:00
|
|
|
ArchiveBrowserView* browser = context;
|
2022-07-26 12:21:51 +00:00
|
|
|
Storage* fs_api = furi_record_open(RECORD_STORAGE);
|
2021-09-10 00:57:43 +00:00
|
|
|
|
2022-04-06 17:44:06 +00:00
|
|
|
FileInfo fileinfo;
|
2022-10-05 15:15:23 +00:00
|
|
|
storage_common_stat(fs_api, furi_string_get_cstr(filename), &fileinfo);
|
2022-04-06 17:44:06 +00:00
|
|
|
|
|
|
|
bool res = false;
|
|
|
|
|
|
|
|
if(fileinfo.flags & FSF_DIRECTORY) {
|
2022-10-05 15:15:23 +00:00
|
|
|
res = storage_simply_remove_recursive(fs_api, furi_string_get_cstr(filename));
|
2022-04-06 17:44:06 +00:00
|
|
|
} else {
|
2022-10-05 15:15:23 +00:00
|
|
|
res = (storage_common_remove(fs_api, furi_string_get_cstr(filename)) == FSE_OK);
|
2022-04-06 17:44:06 +00:00
|
|
|
}
|
|
|
|
|
2022-07-26 12:21:51 +00:00
|
|
|
furi_record_close(RECORD_STORAGE);
|
2021-09-10 00:57:43 +00:00
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
if(archive_is_favorite("%s", furi_string_get_cstr(filename))) {
|
|
|
|
archive_favorites_delete("%s", furi_string_get_cstr(filename));
|
2021-09-21 10:56:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(res) {
|
|
|
|
archive_file_array_rm_selected(browser);
|
2021-09-10 00:57:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_free(filename);
|
2022-04-06 17:44:06 +00:00
|
|
|
}
|