Embed assets in elf file (#2466)

* FBT: file_assets generator
* Elf file: process manifest section externally
* FBT, file_assets generator: add assets signature
* Storage: assets path alias
* Flipper application: assets unpacker
* Apps, Storage: use '/data' alias for apps data
* Storage: copy file to file
* Assets: log flag, fixes
* Update f18 api
* Assets: asserts
* Assets: fix signature_data check
* App assets: example
* Example assets: fix folder structure in readme
* Assets: fix error handling
* Assets builder: use ansii instead of utf-8, use .fapassets section instead of .fapfiles, add assets path to signature
* Elf file: comment strange places
* Storage: totaly optimized storage_file_copy_to_file
This commit is contained in:
Sergey Gavrilov
2023-03-09 18:01:53 +03:00
committed by GitHub
parent 50ef5deefc
commit 4fd043398a
22 changed files with 937 additions and 113 deletions

View File

@@ -10,12 +10,14 @@ extern "C" {
#define STORAGE_INT_PATH_PREFIX "/int"
#define STORAGE_EXT_PATH_PREFIX "/ext"
#define STORAGE_ANY_PATH_PREFIX "/any"
#define STORAGE_APP_DATA_PATH_PREFIX "/app"
#define STORAGE_APP_DATA_PATH_PREFIX "/data"
#define STORAGE_APP_ASSETS_PATH_PREFIX "/assets"
#define INT_PATH(path) STORAGE_INT_PATH_PREFIX "/" path
#define EXT_PATH(path) STORAGE_EXT_PATH_PREFIX "/" path
#define ANY_PATH(path) STORAGE_ANY_PATH_PREFIX "/" path
#define APP_DATA_PATH(path) STORAGE_APP_DATA_PATH_PREFIX "/" path
#define APP_ASSETS_PATH(path) STORAGE_APP_ASSETS_PATH_PREFIX "/" path
#define RECORD_STORAGE "storage"
@@ -146,6 +148,17 @@ bool storage_file_eof(File* file);
*/
bool storage_file_exists(Storage* storage, const char* path);
/**
* @brief Copy data from one opened file to another opened file
* Size bytes will be copied from current position of source file to current position of destination file
*
* @param source source file
* @param destination destination file
* @param size size of data to copy
* @return bool success flag
*/
bool storage_file_copy_to_file(File* source, File* destination, uint32_t size);
/******************* Dir Functions *******************/
/** Opens a directory to get objects from it

View File

@@ -9,6 +9,7 @@
#define MAX_NAME_LENGTH 256
#define MAX_EXT_LEN 16
#define FILE_BUFFER_SIZE 512
#define TAG "StorageAPI"
@@ -251,6 +252,26 @@ bool storage_file_exists(Storage* storage, const char* path) {
return exist;
}
bool storage_file_copy_to_file(File* source, File* destination, uint32_t size) {
uint8_t* buffer = malloc(FILE_BUFFER_SIZE);
while(size) {
uint32_t read_size = size > FILE_BUFFER_SIZE ? FILE_BUFFER_SIZE : size;
if(storage_file_read(source, buffer, read_size) != read_size) {
break;
}
if(storage_file_write(destination, buffer, read_size) != read_size) {
break;
}
size -= read_size;
}
free(buffer);
return size == 0;
}
/****************** DIR ******************/
static bool storage_dir_open_internal(File* file, const char* path) {

View File

@@ -13,6 +13,7 @@ extern "C" {
#define STORAGE_COUNT (ST_INT + 1)
#define APPS_DATA_PATH EXT_PATH("apps_data")
#define APPS_ASSETS_PATH EXT_PATH("apps_assets")
typedef struct {
ViewPort* view_port;

View File

@@ -454,7 +454,7 @@ void storage_process_alias(
FuriString* apps_data_path_with_appsid = furi_string_alloc_set(APPS_DATA_PATH "/");
furi_string_cat(apps_data_path_with_appsid, furi_thread_get_appid(thread_id));
// "/app" -> "/ext/apps_data/appsid"
// "/data" -> "/ext/apps_data/appsid"
furi_string_replace_at(
path,
0,
@@ -472,6 +472,18 @@ void storage_process_alias(
}
furi_string_free(apps_data_path_with_appsid);
} else if(furi_string_start_with(path, STORAGE_APP_ASSETS_PATH_PREFIX)) {
FuriString* apps_assets_path_with_appsid = furi_string_alloc_set(APPS_ASSETS_PATH "/");
furi_string_cat(apps_assets_path_with_appsid, furi_thread_get_appid(thread_id));
// "/assets" -> "/ext/apps_assets/appsid"
furi_string_replace_at(
path,
0,
strlen(STORAGE_APP_ASSETS_PATH_PREFIX),
furi_string_get_cstr(apps_assets_path_with_appsid));
furi_string_free(apps_assets_path_with_appsid);
}
}