mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-13 21:38:36 -07:00
Updater: Resources progress based on file size
Gzipped tar will take too long to count files, instead use position in tar archive Need to find a workaround for estimating cleanup progress
This commit is contained in:
@@ -46,24 +46,14 @@ typedef enum {
|
|||||||
|
|
||||||
#define UPDATE_TASK_RESOURCES_FILE_TO_TOTAL_PERCENT 90
|
#define UPDATE_TASK_RESOURCES_FILE_TO_TOTAL_PERCENT 90
|
||||||
|
|
||||||
typedef struct {
|
static void update_task_resource_progress_cb(size_t progress, size_t total, void* context) {
|
||||||
UpdateTask* update_task;
|
UpdateTask* update_task = context;
|
||||||
int32_t total_files, processed_files;
|
|
||||||
} 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;
|
|
||||||
unpack_progress->processed_files++;
|
|
||||||
update_task_set_progress(
|
update_task_set_progress(
|
||||||
unpack_progress->update_task,
|
update_task,
|
||||||
UpdateTaskStageProgress,
|
UpdateTaskStageProgress,
|
||||||
/* For this stage, last progress segment = extraction */
|
/* For this stage, last progress segment = extraction */
|
||||||
(UpdateTaskResourcesWeightsFileCleanup + UpdateTaskResourcesWeightsDirCleanup) +
|
(UpdateTaskResourcesWeightsFileCleanup + UpdateTaskResourcesWeightsDirCleanup) +
|
||||||
(unpack_progress->processed_files * UpdateTaskResourcesWeightsFileUnpack) /
|
(progress * UpdateTaskResourcesWeightsFileUnpack) / total);
|
||||||
(unpack_progress->total_files + 1));
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void update_task_cleanup_resources(UpdateTask* update_task, const uint32_t n_tar_entries) {
|
static void update_task_cleanup_resources(UpdateTask* update_task, const uint32_t n_tar_entries) {
|
||||||
@@ -177,11 +167,6 @@ static bool update_task_post_update(UpdateTask* update_task) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(update_task->state.groups & UpdateTaskStageGroupResources) {
|
if(update_task->state.groups & UpdateTaskStageGroupResources) {
|
||||||
TarUnpackProgress progress = {
|
|
||||||
.update_task = update_task,
|
|
||||||
.total_files = 0,
|
|
||||||
.processed_files = 0,
|
|
||||||
};
|
|
||||||
update_task_set_progress(update_task, UpdateTaskStageResourcesUpdate, 0);
|
update_task_set_progress(update_task, UpdateTaskStageResourcesUpdate, 0);
|
||||||
|
|
||||||
path_concat(
|
path_concat(
|
||||||
@@ -189,16 +174,13 @@ static bool update_task_post_update(UpdateTask* update_task) {
|
|||||||
furi_string_get_cstr(update_task->manifest->resource_bundle),
|
furi_string_get_cstr(update_task->manifest->resource_bundle),
|
||||||
file_path);
|
file_path);
|
||||||
|
|
||||||
tar_archive_set_file_callback(archive, update_task_resource_unpack_cb, &progress);
|
tar_archive_set_read_callback(archive, update_task_resource_progress_cb, update_task);
|
||||||
CHECK_RESULT(
|
CHECK_RESULT(
|
||||||
tar_archive_open(archive, furi_string_get_cstr(file_path), TAR_OPEN_MODE_READ));
|
tar_archive_open(archive, furi_string_get_cstr(file_path), TAR_OPEN_MODE_READ));
|
||||||
|
|
||||||
progress.total_files = tar_archive_get_entries_count(archive);
|
update_task_cleanup_resources(update_task, 1800); // FIXME: file count estimate
|
||||||
if(progress.total_files > 0) {
|
|
||||||
update_task_cleanup_resources(update_task, progress.total_files);
|
|
||||||
|
|
||||||
CHECK_RESULT(tar_archive_unpack_to(archive, STORAGE_EXT_PATH_PREFIX, NULL));
|
CHECK_RESULT(tar_archive_unpack_to(archive, STORAGE_EXT_PATH_PREFIX, NULL));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(update_task->state.groups & UpdateTaskStageGroupSplashscreen) {
|
if(update_task->state.groups & UpdateTaskStageGroupSplashscreen) {
|
||||||
|
|||||||
Reference in New Issue
Block a user