void prompt_and_wait() { // Main Menu #define ITEM_APPLY_SDCARD 0 #define ITEM_NANDROID_MENU 1 #define ITEM_MAIN_WIPE_MENU 2 #define ITEM_ADVANCED_MENU 3 #define ITEM_MOUNT_MENU 4 #define ITEM_USB_TOGGLE 5 #define ITEM_REBOOT 6 #define ITEM_SHUTDOWN 7 finish_recovery(NULL); ui_reset_progress(); // buying a split second for mmc driver to load to avoid error on some devices getLocations(); tw_set_defaults(); read_s_file(); char** headers = prepend_title((const char**)MENU_HEADERS); char* MENU_ITEMS[] = { "Install Zip", "Nandroid Menu", "Wipe Menu", "Advanced Menu", "Mount Menu", "USB Storage Toggle", "Reboot system now", "Power down system", NULL }; for (;;) { go_home = 0; go_menu = 0; menu_loc_idx = 0; ui_reset_progress(); int chosen_item = get_menu_selection(headers, MENU_ITEMS, 0, 0); // device-specific code may take some action here. It may // return one of the core actions handled in the switch // statement below. chosen_item = device_perform_action(chosen_item); // delay reading settings during boot due to timings issues with sdcard not being available // read settings file once and only once after the user makes a menu selection if (need_to_read_settings_file) { need_to_read_settings_file = 0; } switch (chosen_item) { case ITEM_APPLY_SDCARD: install_zip_menu(0); break; case ITEM_NANDROID_MENU: nandroid_menu(); break; case ITEM_MAIN_WIPE_MENU: main_wipe_menu(); break; case ITEM_ADVANCED_MENU: advanced_menu(); break; case ITEM_MOUNT_MENU: mount_menu(0); break; case ITEM_USB_TOGGLE: usb_storage_toggle(); break; case ITEM_REBOOT: return; case ITEM_SHUTDOWN: __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_POWER_OFF, NULL); break; } if (go_menu) { advanced_menu(); } } }
// Read from Settings file Function void read_s_file() { if (ensure_path_mounted("/sdcard") != 0) { LOGI("=> Can not mount /sdcard, running on default settings\n"); // Can't mount sdcard, default settings should be unchanged. } else { FILE *fp; // define file fp = fopen(TW_SETTINGS_FILE, "r"); // Open file for read if (fp == NULL) { LOGI("=> Can not open settings file, will try to create file.\n"); // Can't open file, default settings should be unchanged. write_s_file(); // call save settings function if settings file doesn't exist } else { int i = 0; int len; char s_line[TW_MAX_SETTINGS_CHARS+2]; // Set max characters + 2 (because of terminating and carriage return) while(i < TW_MAX_NUM_SETTINGS) { fgets(s_line, TW_MAX_SETTINGS_CHARS+2, fp); // Read a line from file len = strlen(s_line); // get length of line if (s_line[len-1] == '\n') { // if last char is carriage return s_line[len-1] = 0; // remove it by setting it to 0 } if (i == TW_VERSION) { if (strcmp(s_line,tw_version_val) != 0) { LOGI("=> Wrong recoverywin version detected, default settings applied.\n"); // tw_set_defaults(); write_s_file(); break; } } else if (i == TW_NAN_SYSTEM) { strcpy(tw_nan_system_val, s_line); } else if (i == TW_NAN_DATA) { strcpy(tw_nan_data_val, s_line); } else if (i == TW_NAN_BOOT) { strcpy(tw_nan_boot_val, s_line); } else if (i == TW_NAN_RECOVERY) { strcpy(tw_nan_recovery_val, s_line); } else if (i == TW_NAN_CACHE) { strcpy(tw_nan_cache_val, s_line); } else if (i == TW_NAN_WIMAX) { strcpy(tw_nan_wimax_val, s_line); } else if (i == TW_NAN_ANDSEC) { strcpy(tw_nan_andsec_val, s_line); } else if (i == TW_NAN_SDEXT) { strcpy(tw_nan_sdext_val, s_line); } else if (i == TW_REBOOT_AFTER_FLASH) { strcpy(tw_reboot_after_flash_option, s_line); } else if (i == TW_SIGNED_ZIP) { strcpy(tw_signed_zip_val, s_line); } else if (i == TW_COLOR_THEME) { strcpy(tw_color_theme_val, s_line); } else if (i == TW_USE_COMPRESSION) { strcpy(tw_use_compression_val, s_line); } else if (i == TW_TIME_ZONE) { strcpy(tw_time_zone_val, s_line); } else if (i == TW_ZIP_LOCATION) { strcpy(tw_zip_location_val, s_line); } i++; // increment loop } fclose(fp); // close file } } update_tz_environment_variables(); set_theme(tw_color_theme_val); }