mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-12-21 12:21:49 +03:00
777a4d109d
* Threads: application id * Unit tests: appsdata getter test * Unit tests: moar test cases for appsdata getter * Unit tests: remove folders after test * Storage: dir_is_exist, migrate, + unit_tests * Plugins: migration * Storage: common_exists, moar unit_tests 4 "common_migrate", "common_migrate" and "common_merge" bugfixes * Storage: use FuriString for path handling * Storage API: send caller thread id with path * Storage: remove StorageType field in storage file list * Storage: simplify processing * Storage API: send caller thread id with path everywhere * Storage: /app alias, unit tests and path creation * Storage, path helper: remove unused * Examples: app data example * App plugins: use new VFS path * Storage: file_info_is_dir * Services: handle alias if the service accepts a path. * App plugins: fixes * Make PVS happy * Storage: fix storage_merge_recursive * Storage: rename process_aliases to resolve_path. Rename APPS_DATA to APP_DATA. * Apps: use predefined macro instead of raw paths. Example Apps Data: README fixes. * Storage: rename storage_common_resolve_path to storage_common_resolve_path_and_ensure_app_directory * Api: fix version * Storage: rename alias message * Storage: do not create app folders in path resolving process in certain cases. --------- Co-authored-by: Astra <93453568+Astrrra@users.noreply.github.com> Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
69 lines
2.3 KiB
C
69 lines
2.3 KiB
C
#include "spi_mem_app_i.h"
|
|
|
|
bool spi_mem_file_delete(SPIMemApp* app) {
|
|
return (storage_simply_remove(app->storage, furi_string_get_cstr(app->file_path)));
|
|
}
|
|
|
|
bool spi_mem_file_select(SPIMemApp* app) {
|
|
DialogsFileBrowserOptions browser_options;
|
|
dialog_file_browser_set_basic_options(&browser_options, SPI_MEM_FILE_EXTENSION, &I_Dip8_10px);
|
|
browser_options.base_path = STORAGE_APP_DATA_PATH_PREFIX;
|
|
bool success =
|
|
dialog_file_browser_show(app->dialogs, app->file_path, app->file_path, &browser_options);
|
|
return success;
|
|
}
|
|
|
|
bool spi_mem_file_create_open(SPIMemApp* app) {
|
|
bool success = false;
|
|
app->file = storage_file_alloc(app->storage);
|
|
do {
|
|
if(furi_string_end_with(app->file_path, SPI_MEM_FILE_EXTENSION)) {
|
|
if(!spi_mem_file_delete(app)) break;
|
|
size_t filename_start = furi_string_search_rchar(app->file_path, '/');
|
|
furi_string_left(app->file_path, filename_start);
|
|
}
|
|
furi_string_cat_printf(app->file_path, "/%s%s", app->text_buffer, SPI_MEM_FILE_EXTENSION);
|
|
if(!storage_file_open(
|
|
app->file, furi_string_get_cstr(app->file_path), FSAM_WRITE, FSOM_CREATE_NEW))
|
|
break;
|
|
success = true;
|
|
} while(0);
|
|
if(!success) { //-V547
|
|
dialog_message_show_storage_error(app->dialogs, "Cannot save\nfile");
|
|
}
|
|
return success;
|
|
}
|
|
|
|
bool spi_mem_file_open(SPIMemApp* app) {
|
|
app->file = storage_file_alloc(app->storage);
|
|
if(!storage_file_open(
|
|
app->file, furi_string_get_cstr(app->file_path), FSAM_READ_WRITE, FSOM_OPEN_EXISTING)) {
|
|
dialog_message_show_storage_error(app->dialogs, "Cannot save\nfile");
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool spi_mem_file_write_block(SPIMemApp* app, uint8_t* data, size_t size) {
|
|
if(storage_file_write(app->file, data, size) != size) return false;
|
|
return true;
|
|
}
|
|
|
|
bool spi_mem_file_read_block(SPIMemApp* app, uint8_t* data, size_t size) {
|
|
if(storage_file_read(app->file, data, size) != size) return false;
|
|
return true;
|
|
}
|
|
|
|
void spi_mem_file_close(SPIMemApp* app) {
|
|
storage_file_close(app->file);
|
|
storage_file_free(app->file);
|
|
}
|
|
|
|
size_t spi_mem_file_get_size(SPIMemApp* app) {
|
|
FileInfo file_info;
|
|
if(storage_common_stat(app->storage, furi_string_get_cstr(app->file_path), &file_info) !=
|
|
FSE_OK)
|
|
return 0;
|
|
return file_info.size;
|
|
}
|