Updater: Progressbar even with huge files --nobuild

This commit is contained in:
Willy-JL
2024-07-02 00:39:48 +02:00
parent c45e6b9298
commit 1014e45c22
4 changed files with 26 additions and 19 deletions
@@ -37,20 +37,10 @@ static bool update_task_pre_update(UpdateTask* update_task) {
furi_string_free(backup_file_path);
return success;
}
typedef struct {
UpdateTask* update_task;
TarArchive* archive;
} TarUnpackProgress;
static bool update_task_resource_unpack_cb(const char* name, bool is_directory, void* context) {
UNUSED(name);
UNUSED(is_directory);
TarUnpackProgress* unpack_progress = context;
int32_t progress = 0, total = 0;
tar_archive_get_read_progress(unpack_progress->archive, &progress, &total);
update_task_set_progress(
unpack_progress->update_task, UpdateTaskStageProgress, (progress * 100) / (total + 1));
return true;
static void update_task_resource_unpack_cb(size_t progress, size_t total, void* context) {
UpdateTask* update_task = context;
update_task_set_progress(update_task, UpdateTaskStageProgress, (progress * 100) / (total + 1));
}
static void update_task_cleanup_resources(UpdateTask* update_task) {
@@ -168,11 +158,6 @@ static bool update_task_post_update(UpdateTask* update_task) {
#endif
if(update_task->state.groups & UpdateTaskStageGroupResources) {
TarUnpackProgress progress = {
.update_task = update_task,
.archive = archive,
};
path_concat(
furi_string_get_cstr(update_task->update_path),
furi_string_get_cstr(update_task->manifest->resource_bundle),
@@ -184,7 +169,7 @@ static bool update_task_post_update(UpdateTask* update_task) {
update_task_cleanup_resources(update_task);
update_task_set_progress(update_task, UpdateTaskStageResourcesFileUnpack, 0);
tar_archive_set_file_callback(archive, update_task_resource_unpack_cb, &progress);
tar_archive_set_read_callback(archive, update_task_resource_unpack_cb, update_task);
CHECK_RESULT(tar_archive_unpack_to(archive, STORAGE_EXT_PATH_PREFIX, NULL));
}
+16
View File
@@ -33,6 +33,9 @@ typedef struct TarArchive {
mtar_t tar;
tar_unpack_file_cb unpack_cb;
void* unpack_cb_context;
tar_unpack_read_cb read_cb;
void* read_cb_context;
} TarArchive;
/* Plain file backend - uncompressed, supports read and write */
@@ -211,6 +214,12 @@ void tar_archive_set_file_callback(TarArchive* archive, tar_unpack_file_cb callb
archive->unpack_cb_context = context;
}
void tar_archive_set_read_callback(TarArchive* archive, tar_unpack_read_cb callback, void* context) {
furi_check(archive);
archive->read_cb = callback;
archive->read_cb_context = context;
}
static int tar_archive_entry_counter(mtar_t* tar, const mtar_header_t* header, void* param) {
UNUSED(tar);
UNUSED(header);
@@ -321,6 +330,13 @@ static bool archive_extract_current_file(TarArchive* archive, const char* dst_pa
success = false;
break;
}
if(archive->read_cb) {
archive->read_cb(
storage_file_tell(archive->stream),
storage_file_size(archive->stream),
archive->read_cb_context);
}
}
} while(false);
storage_file_free(out_file);
+5
View File
@@ -140,6 +140,11 @@ typedef bool (*tar_unpack_file_cb)(const char* name, bool is_directory, void* co
*/
void tar_archive_set_file_callback(TarArchive* archive, tar_unpack_file_cb callback, void* context);
/* Optional read progress callback on unpacking */
typedef void (*tar_unpack_read_cb)(size_t progress, size_t total, void* context);
void tar_archive_set_read_callback(TarArchive* archive, tar_unpack_read_cb callback, void* context);
/* Low-level API */
/** Add tar archive directory header
+1
View File
@@ -3626,6 +3626,7 @@ Function,+,tar_archive_get_mode_for_path,TarOpenMode,const char*
Function,+,tar_archive_get_read_progress,_Bool,"TarArchive*, int32_t*, int32_t*"
Function,+,tar_archive_open,_Bool,"TarArchive*, const char*, TarOpenMode"
Function,+,tar_archive_set_file_callback,void,"TarArchive*, tar_unpack_file_cb, void*"
Function,+,tar_archive_set_read_callback,void,"TarArchive*, tar_unpack_read_cb, void*"
Function,+,tar_archive_store_data,_Bool,"TarArchive*, const char*, const uint8_t*, const int32_t"
Function,+,tar_archive_unpack_file,_Bool,"TarArchive*, const char*, const char*"
Function,+,tar_archive_unpack_to,_Bool,"TarArchive*, const char*, Storage_name_converter"
1 entry status name type params
3626 Function + tar_archive_get_read_progress _Bool TarArchive*, int32_t*, int32_t*
3627 Function + tar_archive_open _Bool TarArchive*, const char*, TarOpenMode
3628 Function + tar_archive_set_file_callback void TarArchive*, tar_unpack_file_cb, void*
3629 Function + tar_archive_set_read_callback void TarArchive*, tar_unpack_read_cb, void*
3630 Function + tar_archive_store_data _Bool TarArchive*, const char*, const uint8_t*, const int32_t
3631 Function + tar_archive_unpack_file _Bool TarArchive*, const char*, const char*
3632 Function + tar_archive_unpack_to _Bool TarArchive*, const char*, Storage_name_converter