mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-12-21 04:11:48 +03:00
53435579b3
* fbt, faploader: minimal app module implementation * faploader, libs: moved API hashtable core to flipper_application * example: compound api * lib: flipper_application: naming fixes, doxygen comments * fbt: changed `requires` manifest field behavior for app extensions * examples: refactored plugin apps; faploader: changed new API naming; fbt: changed PLUGIN app type meaning * loader: dropped support for debug apps & plugin menus * moved applications/plugins -> applications/external * Restored x bit on chiplist_convert.py * git: fixed free-dap submodule path * pvs: updated submodule paths * examples: example_advanced_plugins.c: removed potential memory leak on errors * examples: example_plugins: refined requires * fbt: not deploying app modules for debug/sample apps; extra validation for .PLUGIN-type apps * apps: removed cdefines for external apps * fbt: moved ext app path definition * fbt: reworked fap_dist handling; f18: synced api_symbols.csv * fbt: removed resources_paths for extapps * scripts: reworked storage * scripts: reworked runfap.py & selfupdate.py to use new api * wip: fal runner * fbt: moved file packaging into separate module * scripts: storage: fixes * scripts: storage: minor fixes for new api * fbt: changed internal artifact storage details for external apps * scripts: storage: additional fixes and better error reporting; examples: using APP_DATA_PATH() * fbt, scripts: reworked launch_app to deploy plugins; moved old runfap.py to distfap.py * fbt: extra check for plugins descriptors * fbt: additional checks in emitter * fbt: better info message on SDK rebuild * scripts: removed requirements.txt * loader: removed remnants of plugins & debug menus * post-review fixes
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;
|
|
}
|