void enter_next_stage() { static int current_stage = STAGE_START_INSTALL; g_message("[%s], current_stage: %d\n", __func__, current_stage); switch (current_stage) { case STAGE_START_INSTALL: current_stage = STAGE_HOOKS_BEFORE_CHROOT; run_hooks_before_chroot(); break; case STAGE_HOOKS_BEFORE_CHROOT: current_stage = STAGE_HOOKS_IN_CHROOT; run_hooks_in_chroot(); break; case STAGE_HOOKS_IN_CHROOT: current_stage = STAGE_HOOKS_AFTER_CHROOT; run_hooks_after_chroot(); break; case STAGE_HOOKS_AFTER_CHROOT: current_stage = STAGE_INSTALL_FINISH; update_install_progress(100); break; default: g_assert_not_reached(); } }
static gboolean monitor_extract_progress(HookInfo* info) { static int stage = EXTRACT_PROGRESS_NONE; int v = 0; switch (stage) { case EXTRACT_PROGRESS_NONE: v = read_progress(PROGRESS_LOG_BASE); if (v != -1) { stage = EXTRACT_PROGRESS_BASE; } return TRUE; case EXTRACT_PROGRESS_BASE: v = read_progress(PROGRESS_LOG_BASE); if (v >= 100) { stage = EXTRACT_PROGRESS_BASE_END; } double ratio = v / 100.0; //extract lang pack use 10% time update_install_progress( info->progress_begin + (info->progress_end - 10 ) * ratio); return TRUE; case EXTRACT_PROGRESS_BASE_END: v = read_progress(PROGRESS_LOG_LANG); if (v != -1) { stage = EXTRACT_PROGRESS_LANG; } return TRUE; case EXTRACT_PROGRESS_LANG: v = read_progress(PROGRESS_LOG_LANG); if (v >= 100) { stage = EXTRACT_PROGRESS_LANG_END; } update_install_progress(info->progress_end - 10 + 10 * ratio); return TRUE; case EXTRACT_PROGRESS_LANG_END: printf("END Monitor_extract_progress\n"); return FALSE; } }
void update_hooks_progress(HookInfo* info) { if (info == &before_chroot_info) { // extract squashfs is in before chroot info, special treat it with monitor_extract_progress() return; } double ratio = info->current_job_num * 1.0 / (g_list_length(g_list_first(info->jobs)) - 1); g_assert(ratio > 0 && ratio <= 1); double p = info->progress_begin + (info->progress_end - info->progress_begin) * ratio; g_assert(p > 0 && p <= 100); update_install_progress((int)p); }