//callback function , success return 0, non-zero fail int file_install(char *file_name, int file_len, void *data) { return_val_if_fail(file_name != NULL, RET_FAIL); return_val_if_fail(strlen(file_name) <= file_len, RET_INVALID_ARG); return_val_if_fail(data != NULL, RET_FAIL); #ifdef DUALSYSTEM_PARTITIONS int choose_system_num; if (is_tdb_enabled()) { if (RET_YES == miui_confirm(5, "<~choose.system.title>", "<~choose.system.text>", "@alert", "<~choice.system0.name>", "<~choice.system1.name>")) { miuiIntent_send(INTENT_SETSYSTEM,1,"1"); } else { miuiIntent_send(INTENT_SETSYSTEM,1,"2"); } } #endif struct _menuUnit *p = (pmenuUnit)data; if (RET_YES == miui_confirm(3, p->name, p->desc, p->icon)) { miuiIntent_send(INTENT_INSTALL, 3, file_name, "0", "1"); #ifdef DUALSYSTEM_PARTITIONS miuiIntent_send(INTENT_SETSYSTEM,1,"0"); #endif return 0; } else { #ifdef DUALSYSTEM_PARTITIONS miuiIntent_send(INTENT_SETSYSTEM,1,"0"); #endif return -1; } }
static STATUS sd_update_show(menuUnit *p) { char new_path[SD_MAX_PATH] = "/sdcard/update.zip"; int wipe_cache = 0; if (RET_YES == miui_confirm(3, p->name, p->desc, p->icon)) { miuiIntent_send(INTENT_INSTALL, 3, new_path, "0", "1"); } return MENU_BACK; }
//callback function , success return 0, non-zero fail int file_install(char *file_name, int file_len, void *data) { return_val_if_fail(file_name != NULL, RET_FAIL); return_val_if_fail(strlen(file_name) <= file_len, RET_INVALID_ARG); return_val_if_fail(data != NULL, RET_FAIL); struct _menuUnit *p = (pmenuUnit)data; if (RET_YES == miui_confirm(3, p->name, p->desc, p->icon)) { miuiIntent_send(INTENT_INSTALL, 3, file_name, "0", "1"); return 0; } else return -1; }
static STATUS sd_update_show(menuUnit *p) { char new_path[SD_MAX_PATH] = "/sdcard/update.zip"; int wipe_cache = 0; #ifdef DUALSYSTEM_PARTITIONS int choose_system_num; if (is_tdb_enabled()) { if (RET_YES == miui_confirm(5, "<~choose.system.title>", "<~choose.system.text>", "@alert", "<~choice.system0.name>", "<~choice.system1.name>")) { miuiIntent_send(INTENT_SETSYSTEM,1,"1"); } else { miuiIntent_send(INTENT_SETSYSTEM,1,"2"); } } #endif if (RET_YES == miui_confirm(3, p->name, p->desc, p->icon)) { miuiIntent_send(INTENT_INSTALL, 3, new_path, "0", "1"); } miuiIntent_send(INTENT_SETSYSTEM,1,"0"); return MENU_BACK; }
static STATUS backup_child_show(menuUnit* p) { p_current = p; miuiIntent_send(INTENT_MOUNT, 1, "/sdcard"); char path_name[PATH_MAX]; static time_t timep; static struct tm *time_tm; time(&timep); time_tm = gmtime(&timep); return_val_if_fail(miuiIntent_result_get_int() == 0, MENU_BACK); if (RET_YES == miui_confirm(3, p->name, p->desc, p->icon)) { miui_busy_process(); switch(p->result) { case BACKUP_ALL: snprintf(path_name,PATH_MAX, "%s/backup/backup/%02d%02d%02d-%02d%02d", RECOVERY_PATH, time_tm->tm_year, time_tm->tm_mon + 1, time_tm->tm_mday, time_tm->tm_hour, time_tm->tm_min); miuiIntent_send(INTENT_BACKUP, 1, path_name); break; case BACKUP_CACHE: snprintf(path_name,PATH_MAX, "%s/backup/cache/%02d%02d%02d-%02d%02d", RECOVERY_PATH, time_tm->tm_year, time_tm->tm_mon + 1, time_tm->tm_mday, time_tm->tm_hour, time_tm->tm_min); miuiIntent_send(INTENT_ADVANCED_BACKUP, 2 , path_name, "/cache"); break; case BACKUP_DATA: snprintf(path_name,PATH_MAX, "%s/backup/data/%02d%02d%02d-%02d%02d", RECOVERY_PATH, time_tm->tm_year, time_tm->tm_mon + 1, time_tm->tm_mday, time_tm->tm_hour, time_tm->tm_min); miuiIntent_send(INTENT_ADVANCED_BACKUP, 2 , path_name, "/data"); break; case BACKUP_SYSTEM: snprintf(path_name,PATH_MAX, "%s/backup/system/%02d%02d%02d-%02d%02d", RECOVERY_PATH, time_tm->tm_year, time_tm->tm_mon + 1, time_tm->tm_mday, time_tm->tm_hour, time_tm->tm_min); miuiIntent_send(INTENT_ADVANCED_BACKUP, 2 , path_name, "/system"); break; case BACKUP_BOOT: snprintf(path_name,PATH_MAX, "%s/backup/boot/%02d%02d%02d-%02d%02d", RECOVERY_PATH, time_tm->tm_year, time_tm->tm_mon + 1, time_tm->tm_mday, time_tm->tm_hour, time_tm->tm_min); miuiIntent_send(INTENT_ADVANCED_BACKUP, 2 , path_name, "/boot"); break; default: miui_error("p->resulte %d should not be the value\n", p->result); break; } } return MENU_BACK; }
STATUS wipe_item_show(menuUnit *p) { if (RET_YES == miui_confirm(3, p->name, p->desc, p->icon)) { miui_busy_process(); switch(p->result) { case WIPE_FACTORY: miuiIntent_send(INTENT_WIPE, 1, "/cache"); miuiIntent_send(INTENT_WIPE, 1, "/data"); break; case WIPE_DATA: miuiIntent_send(INTENT_WIPE, 1, "/data"); break; case WIPE_CACHE: miuiIntent_send(INTENT_WIPE, 1, "/cache"); break; case WIPE_DALVIK: miuiIntent_send(INTENT_WIPE, 1, "dalvik-cache"); break; case FORMAT_SYSTEM: miuiIntent_send(INTENT_FORMAT, 1, "/system"); break; case FORMAT_DATA: miuiIntent_send(INTENT_FORMAT, 1, "/data"); break; case FORMAT_CACHE: miuiIntent_send(INTENT_FORMAT, 1, "/cache"); break; case FORMAT_BOOT: miuiIntent_send(INTENT_FORMAT, 1, "/boot"); break; case FORMAT_SDCARD: miuiIntent_send(INTENT_FORMAT, 1, "/sdcard"); break; case FORMAT_ALL: miuiIntent_send(INTENT_FORMAT, 1, "/system"); miuiIntent_send(INTENT_FORMAT, 1, "/data"); miuiIntent_send(INTENT_FORMAT, 1, "/cache"); break; default: assert_if_fail(0); break; } } return MENU_BACK; }
static STATUS _backup_dir_show(char *path) { DIR* d; struct dirent* de; d = opendir(path); return_val_if_fail(d != NULL, RET_FAIL); int d_size = 0; int d_alloc = 10; return_val_if_fail(backup_menu != NULL, RET_FAIL); char** dirs = malloc(d_alloc * sizeof(char*)); char** dirs_desc = malloc(d_alloc * sizeof(char*)); return_val_if_fail(dirs != NULL, RET_FAIL); return_val_if_fail(dirs_desc != NULL, RET_FAIL); int z_size = 1; int z_alloc = 10; char** zips = malloc(z_alloc * sizeof(char*)); char** zips_desc=malloc(z_alloc * sizeof(char*)); return_val_if_fail(zips != NULL, RET_FAIL); return_val_if_fail(zips_desc != NULL, RET_FAIL); zips[0] = strdup("../"); zips_desc[0]=strdup("../"); while ((de = readdir(d)) != NULL) { int name_len = strlen(de->d_name); char de_path[PATH_MAX]; snprintf(de_path, PATH_MAX, "%s/%s", path, de->d_name); struct stat st ; assert_if_fail(stat(de_path, &st) == 0); if (de->d_type == DT_DIR) { //skip "." and ".." entries if (name_len == 1 && de->d_name[0] == '.') continue; if (name_len == 2 && de->d_name[0] == '.' && de->d_name[1] == '.') continue; if (d_size >= d_alloc) { d_alloc *= 2; dirs = realloc(dirs, d_alloc * sizeof(char*)); dirs_desc = realloc(dirs_desc, d_alloc * sizeof(char*)); } dirs[d_size] = malloc(name_len + 2); dirs_desc[d_size] = malloc(64); strcpy(dirs[d_size], de->d_name); dirs[d_size][name_len ] = '\0'; snprintf(dirs_desc[d_size], 64, "%s" ,ctime(&st.st_mtime)); ++d_size; } else if (de->d_type == DT_REG && name_len >= 4 && strncasecmp(de->d_name + (name_len - 4), ".zip", 4) == 0) { if (z_size >= z_alloc) { z_alloc *= 2; zips = realloc(zips, z_alloc * sizeof(char*)); zips_desc = realloc(zips_desc, z_alloc * sizeof(char*)); } zips[z_size] = strdup(de->d_name); zips_desc[z_size] = malloc(64); snprintf(zips_desc[z_size], 64, "%s %lldbytes" ,ctime(&st.st_mtime), st.st_size); z_size++; } } closedir(d); // append dirs to the zips list if (d_size + z_size + 1 > z_alloc) { z_alloc = d_size + z_size + 1; zips = realloc(zips, z_alloc * sizeof(char*)); zips_desc = realloc(zips_desc, z_alloc * sizeof(char*)); } memcpy(zips + z_size, dirs, d_size * sizeof(char *)); memcpy(zips_desc + z_size, dirs_desc, d_size * sizeof(char*)); free(dirs); z_size += d_size; zips[z_size] = NULL; zips_desc[z_size] = NULL; int result; int chosen_item = 0; do { chosen_item = miui_sdmenu(backup_menu->name, zips, zips_desc, z_size); return_val_if_fail(chosen_item >= 0, RET_FAIL); char * item = zips[chosen_item]; int item_len = strlen(item); if ( chosen_item == 0) { //go up but continue browsing result = -1; break; } else { // select a zipfile // the status to the caller char new_path[PATH_MAX]; strlcpy(new_path, path, PATH_MAX); strlcat(new_path, "/", PATH_MAX); strlcat(new_path, item, PATH_MAX); /* *nandroid_restore(backup_path, restore_boot, system, data, chache , sdext, wimax) */ if (p_current != NULL && RET_YES == miui_confirm(3, p_current->name, p_current->desc, p_current->icon)) { backup_restore(new_path); } break; } } while(1); int i; for (i = 0; i < z_size; ++i) { free(zips[i]); free(zips_desc[i]); } free(zips); return result; }
STATUS wipe_item_show(menuUnit *p) { #ifdef DUALSYSTEM_PARTITIONS int wipe_system_num; if (is_tdb_enabled()) { if (p->result == WIPE_FACTORY) { if (RET_YES == miui_confirm(5, "<~choose.system.title>", "<~choose.system.text>", "@alert", "<~choice.system0.name>", "<~choice.system1.name>")) { wipe_system_num = 0; } else { wipe_system_num = 1; } } } #endif if (RET_YES == miui_confirm(3, p->name, p->desc, p->icon)) { miui_busy_process(); switch(p->result) { case WIPE_FACTORY: #ifdef DUALSYSTEM_PARTITIONS if (is_tdb_enabled()) { miuiIntent_send(INTENT_MOUNT, 1, "/data"); if (wipe_system_num == 0) { __system("rm -rf /data/system0"); } else { __system("rm -rf /data/system1"); } } else { miuiIntent_send(INTENT_WIPE, 1, "/cache"); miuiIntent_send(INTENT_WIPE, 1, "/data"); } #else miuiIntent_send(INTENT_WIPE, 1, "/cache"); miuiIntent_send(INTENT_WIPE, 1, "/data"); #endif break; case WIPE_DATA: miuiIntent_send(INTENT_WIPE, 1, "/data"); break; case WIPE_CACHE: miuiIntent_send(INTENT_WIPE, 1, "/cache"); break; case WIPE_DALVIK: miuiIntent_send(INTENT_WIPE, 1, "dalvik-cache"); break; case FORMAT_SYSTEM: miuiIntent_send(INTENT_FORMAT, 1, "/system"); break; #ifdef DUALSYSTEM_PARTITIONS case FORMAT_SYSTEM1: miuiIntent_send(INTENT_FORMAT, 1, "/system1"); break; #endif case FORMAT_DATA: miuiIntent_send(INTENT_FORMAT, 1, "/data"); break; case FORMAT_CACHE: miuiIntent_send(INTENT_FORMAT, 1, "/cache"); break; case FORMAT_BOOT: miuiIntent_send(INTENT_FORMAT, 1, "/boot"); break; #ifdef DUALSYSTEM_PARTITIONS case FORMAT_BOOT1: miuiIntent_send(INTENT_FORMAT, 1, "/boot1"); break; #endif case FORMAT_SDCARD: miuiIntent_send(INTENT_FORMAT, 1, "/sdcard"); break; case FORMAT_ALL: miuiIntent_send(INTENT_FORMAT, 1, "/system"); miuiIntent_send(INTENT_FORMAT, 1, "/data"); miuiIntent_send(INTENT_FORMAT, 1, "/cache"); break; default: assert_if_fail(0); break; } } return MENU_BACK; }