Ejemplo n.º 1
0
static int title_gui(void)
{
    int id, jd, kd;

    /* Build the title GUI. */

    if ((id = gui_vstack(0)))
    {
        gui_label(id, "Neverball", GUI_LRG, GUI_ALL, 0, 0);

        gui_space(id);

        if ((jd = gui_harray(id)))
        {
            gui_filler(jd);

            if ((kd = gui_varray(jd)))
            {
                if (config_cheat())
                    play_id = gui_start(kd, sgettext("menu^Cheat"),
                                        GUI_MED, TITLE_PLAY, 0);
                else
                    play_id = gui_start(kd, sgettext("menu^Play"),
                                        GUI_MED, TITLE_PLAY, 0);

                gui_state(kd, sgettext("menu^Replay"),  GUI_MED, TITLE_DEMO, 0);
                gui_state(kd, sgettext("menu^Help"),    GUI_MED, TITLE_HELP, 0);
                gui_state(kd, sgettext("menu^Options"), GUI_MED, TITLE_CONF, 0);
                gui_state(kd, sgettext("menu^Exit"),    GUI_MED, TITLE_EXIT, 0);

                /* Hilight the start button. */

                gui_set_hilite(play_id, 1);
            }

            gui_filler(jd);
        }
        gui_layout(id, 0, 0);
    }

    return id;
}
Ejemplo n.º 2
0
static int fall_out_enter(void)
{
    int id, jd, kd;

    /* Reset hack. */
    resume = 0;

    if ((id = gui_vstack(0)))
    {
        kd = gui_label(id, _("Fall-out!"), GUI_LRG, GUI_ALL, gui_gry, gui_red);

        gui_space(id);

        if ((jd = gui_harray(id)))
        {
            if (progress_dead())
                gui_start(jd, _("Exit"), GUI_SML, FALL_OUT_OVER, 0);

            if (progress_next_avail())
                gui_start(jd, _("Next Level"),  GUI_SML, FALL_OUT_NEXT, 0);

            if (progress_same_avail())
                gui_start(jd, _("Retry Level"), GUI_SML, FALL_OUT_SAME, 0);

            if (demo_saved())
                gui_state(jd, _("Save Replay"), GUI_SML, FALL_OUT_SAVE, 0);
        }

        gui_space(id);

        gui_pulse(kd, 1.2f);
        gui_layout(id, 0, 0);
    }

    audio_music_fade_out(2.0f);
    /* audio_play(AUD_FALL, 1.0f); */

    video_clr_grab();

    return id;
}
Ejemplo n.º 3
0
void conf_header(int id, const char *text, int token)
{
    int jd;

    if ((jd = gui_harray(id)))
    {
        gui_label(jd, text, GUI_SML, 0, 0);
        gui_space(jd);
        gui_start(jd, _("Back"), GUI_SML, token, 0);
    }

    gui_space(id);
}
Ejemplo n.º 4
0
static int demo_end_gui(void)
{
    int id, jd, kd;

    if ((id = gui_vstack(0)))
    {
        if (demo_paused)
            kd = gui_label(id, _("Replay"), GUI_LRG, gui_gry, gui_red);
        else
            kd = gui_label(id, _("Replay Ends"), GUI_LRG, gui_gry, gui_red);

        gui_space(id);

        if ((jd = video.device_w < video.device_h ? gui_vstack(id) : gui_harray(id)))
        {
            if (standalone)
            {
                gui_start(jd, _("Quit"), GUI_MED, DEMO_QUIT, 0);
            }
            else
            {
                gui_start(jd, _("Keep"), GUI_MED, DEMO_KEEP, 0);
                gui_state(jd, _("Delete"), GUI_MED, DEMO_DEL, 0);
            }

            if (demo_paused)
                gui_start(jd, _("Continue"), GUI_MED, DEMO_CONTINUE, 0);
            else
                gui_state(jd, _("Repeat"),   GUI_MED, DEMO_REPLAY,   0);
        }

        gui_pulse(kd, 1.2f);
        gui_layout(id, 0, 0);
    }

    return id;
}
Ejemplo n.º 5
0
static int title_enter(struct state *st, struct state *prev)
{
    int id, jd, kd;

    /* Build the title GUI. */

    if ((id = gui_vstack(0)))
    {
#ifdef GCWZERO
        jd = gui_label(id, "Neverputt", GUI_LRG, 0, 0);
        if (jd) {
            gui_set_fill(jd);
            gui_set_rect(jd, GUI_TOP);
        }
        int credit_label;
        if ((credit_label = gui_label(id, "GCW Zero port by Senquack", GUI_SML, gui_wht, gui_wht))) {
            gui_set_rect(credit_label, GUI_BOT);
        }
#else
        gui_label(id, "Neverputt", GUI_LRG, 0, 0);
#endif //GCWZERO

        gui_space(id);

        if ((jd = gui_harray(id)))
        {
            gui_filler(jd);

            if ((kd = gui_varray(jd)))
            {
                gui_start(kd, gt_prefix("menu^Play"),    GUI_MED, TITLE_PLAY, 1);
                gui_state(kd, gt_prefix("menu^Options"), GUI_MED, TITLE_CONF, 0);
                gui_state(kd, gt_prefix("menu^Exit"),    GUI_MED, TITLE_EXIT, 0);
            }

            gui_filler(jd);
        }
        gui_layout(id, 0, 0);
    }

    course_init();
    course_rand();

    return id;
}
Ejemplo n.º 6
0
static int title_enter(void)
{
    int id, jd, kd;

    /* Build the title GUI. */

    if ((id = gui_vstack(0)))
    {
        gui_label(id, "Neverball", GUI_LRG, GUI_ALL, 0, 0);
        gui_space(id);

        if ((jd = gui_harray(id)))
        {
            gui_filler(jd);

            if ((kd = gui_varray(jd)))
            {
                gui_start(kd, "Play",    GUI_MED, TITLE_PLAY, 1);
                gui_state(kd, "Replay",  GUI_MED, TITLE_DEMO, 0);
                gui_state(kd, "Help",    GUI_MED, TITLE_HELP, 0);
                gui_state(kd, "Options", GUI_MED, TITLE_CONF, 0);
                gui_state(kd, "Exit",    GUI_MED, TITLE_EXIT, 0);
            }

            gui_filler(jd);
        }
        gui_layout(id, 0, 0);
    }

    /* Start the title screen music. */

    audio_music_fade_to(0.5f, "bgm/tittle.mod");

    /* Initialize the first level of the first set for display. */

    game_init("map-rlk/title.sol",
              "map-back/jupiter.sol", "png/space.png", 0, 1);

    real_time = 0.0f;
    demo_time = 0.0f;
    mode = 0;

    return id;
}
Ejemplo n.º 7
0
static int demo_del_gui(void)
{
    int id, jd, kd;

    if ((id = gui_vstack(0)))
    {
        kd = gui_label(id, _("Delete Replay?"), GUI_MED, gui_red, gui_red);

        if ((jd = gui_harray(id)))
        {
            gui_start(jd, _("Keep"),   GUI_SML, DEMO_KEEP, 0);
            gui_state(jd, _("Delete"), GUI_SML, DEMO_DEL,  0);
        }

        gui_pulse(kd, 1.2f);
        gui_layout(id, 0, 0);
    }

    return id;
}
Ejemplo n.º 8
0
static int demo_del_enter(void)
{
    int id, jd, kd;

    if ((id = gui_vstack(0)))
    {
        kd = gui_label(id, _("Delete Replay?"), GUI_MED, GUI_ALL, gui_red, gui_red);

        if ((jd = gui_harray(id)))
        {
            gui_start(jd, _("No"),  GUI_SML, DEMO_KEEP, 1);
            gui_state(jd, _("Yes"), GUI_SML, DEMO_DEL,  0);
        }

        gui_pulse(kd, 1.2f);
        gui_layout(id, 0, 0);
    }
    audio_music_fade_out(2.0f);

    return id;
}
Ejemplo n.º 9
0
static int demo_del_gui(void)
{
    int id, jd, kd;

    if ((id = gui_vstack(0)))
    {
        kd = gui_label(id, _("Delete?"), GUI_LRG, gui_gry, gui_red);

        gui_space(id);

        if ((jd = video.device_w < video.device_h ? gui_vstack(id) : gui_harray(id)))
        {
            gui_start(jd, _("Keep"),   GUI_MED, DEMO_KEEP, 0);
            gui_state(jd, _("Delete"), GUI_MED, DEMO_DEL,  0);
        }

        gui_pulse(kd, 1.2f);
        gui_layout(id, 0, 0);
    }

    return id;
}
Ejemplo n.º 10
0
static int pause_enter(void)
{
    int id, jd, td;

    audio_music_fade_out(0.2f);

    if ((id = gui_vstack(0)))
    {
        td = gui_label(id, _("Paused"), GUI_LRG, GUI_ALL, 0, 0);
        gui_space(id);

        if ((jd = gui_harray(id)))
        {
            gui_state(jd, _("Quit"), GUI_SML, PAUSE_QUIT, 0);
            gui_start(jd, _("Continue"), GUI_SML, PAUSE_CONTINUE, 1);
        }

        gui_pulse(td, 1.2f);
        gui_layout(id, 0, 0);
    }

    hud_init();
    return id;
}
Ejemplo n.º 11
0
static int done_gui(void)
{
    const char *s1 = _("New Set Record");
    const char *s2 = _("Set Complete");

    int id;

    int high = progress_set_high();

    if ((id = gui_vstack(0)))
    {
        int gid;

        if (high)
            gid = gui_label(id, s1, GUI_MED, gui_grn, gui_grn);
        else
            gid = gui_label(id, s2, GUI_MED, gui_blu, gui_grn);

        gui_space(id);
        gui_score_board(id, GUI_SCORE_COIN | GUI_SCORE_TIME, 1, high);
        gui_space(id);

        gui_start(id, _("Select Level"), GUI_SML, GUI_BACK, 0);

        if (!resume)
            gui_pulse(gid, 1.2f);

        gui_layout(id, 0, 0);
    }

    set_score_board(set_score(curr_set(), SCORE_COIN), progress_score_rank(),
                    set_score(curr_set(), SCORE_TIME), progress_times_rank(),
                    NULL, -1);

    return id;
}
Ejemplo n.º 12
0
static int start_enter(void)
{
    int w = config_get_d(CONFIG_WIDTH);
    int h = config_get_d(CONFIG_HEIGHT);

    int id, jd, kd, ld;

    if ((id = gui_vstack(0)))
    {
        if ((jd = gui_harray(id)))
        {
            gui_label(jd, "Level", GUI_SML, GUI_ALL, gui_yel, gui_red);
            gui_filler(jd);
            gui_filler(jd);
            gui_start(jd, "Back",  GUI_SML, START_BACK, 0);
        }

        if ((jd = gui_harray(id)))
        {
            shot_id = gui_image(jd, "shot-rlk/easy.png", 7 * w / 16, 7 * h / 16);

            if ((kd = gui_varray(jd)))
            {
                if ((ld = gui_harray(kd)))
                {
                    gui_level(ld, "05",  5);
                    gui_level(ld, "04",  4);
                    gui_level(ld, "03",  3);
                    gui_level(ld, "02",  2);
                    gui_level(ld, "01",  1);
                }
                if ((ld = gui_harray(kd)))
                {
                    gui_level(ld, "10", 10);
                    gui_level(ld, "09",  9);
                    gui_level(ld, "08",  8);
                    gui_level(ld, "07",  7);
                    gui_level(ld, "06",  6);
                }
                if ((ld = gui_harray(kd)))
                {
                    gui_level(ld, "15", 15);
                    gui_level(ld, "14", 14);
                    gui_level(ld, "13", 13);
                    gui_level(ld, "12", 12);
                    gui_level(ld, "11", 11);
                }
                if ((ld = gui_harray(kd)))
                {
                    gui_level(ld, "20", 20);
                    gui_level(ld, "19", 19);
                    gui_level(ld, "18", 18);
                    gui_level(ld, "17", 17);
                    gui_level(ld, "16", 16);
                }
                if ((ld = gui_harray(kd)))
                {
                    gui_level(ld, "25", 25);
                    gui_level(ld, "24", 24);
                    gui_level(ld, "23", 23);
                    gui_level(ld, "22", 22);
                    gui_level(ld, "21", 21);
                }
            }
        }
        gui_space(id);

        if ((jd = gui_harray(id)))
        {
            gui_most_coins(jd, 3, 4);
            gui_best_times(jd, 3, 4);
        }

        gui_layout(id, 0, 0);
        set_most_coins(0, 3);
        set_best_times(0, 3);
    }

    start_point(id,80,396,0,0);
    return id;
}
Ejemplo n.º 13
0
int main(int argc, char **argv) {
	// Recovery needs to install world-readable files, so clear umask
	// set by init
	umask(0);

	Log_Offset = 0;

	// Set up temporary log file (/tmp/recovery.log)
	freopen(TMP_LOG_FILE, "a", stdout);
	setbuf(stdout, NULL);
	freopen(TMP_LOG_FILE, "a", stderr);
	setbuf(stderr, NULL);

	signal(SIGPIPE, SIG_IGN);

	// Handle ADB sideload
	if (argc == 3 && strcmp(argv[1], "--adbd") == 0) {
		property_set("ctl.stop", "adbd");
		adb_main(argv[2]);
		return 0;
	}

#ifdef RECOVERY_SDCARD_ON_DATA
	datamedia = true;
#endif

	char crash_prop_val[PROPERTY_VALUE_MAX];
	int crash_counter;
	property_get("twrp.crash_counter", crash_prop_val, "-1");
	crash_counter = atoi(crash_prop_val) + 1;
	snprintf(crash_prop_val, sizeof(crash_prop_val), "%d", crash_counter);
	property_set("twrp.crash_counter", crash_prop_val);
	property_set("ro.twrp.boot", "1");
	property_set("ro.twrp.version", TW_VERSION_STR);

	time_t StartupTime = time(NULL);
	printf("Starting TWRP %s on %s (pid %d)\n", TW_VERSION_STR, ctime(&StartupTime), getpid());

	// Load default values to set DataManager constants and handle ifdefs
	DataManager::SetDefaultValues();
	printf("Starting the UI...");
	gui_init();
	printf("=> Linking mtab\n");
	symlink("/proc/mounts", "/etc/mtab");
	if (TWFunc::Path_Exists("/etc/twrp.fstab")) {
		if (TWFunc::Path_Exists("/etc/recovery.fstab")) {
			printf("Renaming regular /etc/recovery.fstab -> /etc/recovery.fstab.bak\n");
			rename("/etc/recovery.fstab", "/etc/recovery.fstab.bak");
		}
		printf("Moving /etc/twrp.fstab -> /etc/recovery.fstab\n");
		rename("/etc/twrp.fstab", "/etc/recovery.fstab");
	}
	printf("=> Processing recovery.fstab\n");
	if (!PartitionManager.Process_Fstab("/etc/recovery.fstab", 1)) {
		LOGERR("Failing out of recovery due to problem with recovery.fstab.\n");
		return -1;
	}
	PartitionManager.Output_Partition_Logging();
	// Load up all the resources
	gui_loadResources();

#ifdef HAVE_SELINUX
	if (TWFunc::Path_Exists("/prebuilt_file_contexts")) {
		if (TWFunc::Path_Exists("/file_contexts")) {
			printf("Renaming regular /file_contexts -> /file_contexts.bak\n");
			rename("/file_contexts", "/file_contexts.bak");
		}
		printf("Moving /prebuilt_file_contexts -> /file_contexts\n");
		rename("/prebuilt_file_contexts", "/file_contexts");
	}
	struct selinux_opt selinux_options[] = {
		{ SELABEL_OPT_PATH, "/file_contexts" }
	};
	selinux_handle = selabel_open(SELABEL_CTX_FILE, selinux_options, 1);
	if (!selinux_handle)
		printf("No file contexts for SELinux\n");
	else
		printf("SELinux contexts loaded from /file_contexts\n");
	{ // Check to ensure SELinux can be supported by the kernel
		char *contexts = NULL;

		if (PartitionManager.Mount_By_Path("/cache", true) && TWFunc::Path_Exists("/cache/recovery")) {
			lgetfilecon("/cache/recovery", &contexts);
			if (!contexts) {
				lsetfilecon("/cache/recovery", "test");
				lgetfilecon("/cache/recovery", &contexts);
			}
		} else {
			LOGINFO("Could not check /cache/recovery SELinux contexts, using /sbin/teamwin instead which may be inaccurate.\n");
			lgetfilecon("/sbin/teamwin", &contexts);
		}
		if (!contexts) {
			gui_print_color("warning", "Kernel does not have support for reading SELinux contexts.\n");
		} else {
			free(contexts);
			gui_print("Full SELinux support is present.\n");
		}
	}
#else
	gui_print_color("warning", "No SELinux support (no libselinux).\n");
#endif

	PartitionManager.Mount_By_Path("/cache", true);

	string Zip_File, Reboot_Value;
	bool Cache_Wipe = false, Factory_Reset = false, Perform_Backup = false, Shutdown = false;

	{
		TWPartition* misc = PartitionManager.Find_Partition_By_Path("/misc");
		if (misc != NULL) {
			if (misc->Current_File_System == "emmc") {
				set_device_type('e');
				set_device_name(misc->Actual_Block_Device.c_str());
			} else if (misc->Current_File_System == "mtd") {
				set_device_type('m');
				set_device_name(misc->MTD_Name.c_str());
			} else {
				LOGERR("Unknown file system for /misc\n");
			}
		}
		get_args(&argc, &argv);

		int index, index2, len;
		char* argptr;
		char* ptr;
		printf("Startup Commands: ");
		for (index = 1; index < argc; index++) {
			argptr = argv[index];
			printf(" '%s'", argv[index]);
			len = strlen(argv[index]);
			if (*argptr == '-') {argptr++; len--;}
			if (*argptr == '-') {argptr++; len--;}
			if (*argptr == 'u') {
				ptr = argptr;
				index2 = 0;
				while (*ptr != '=' && *ptr != '\n')
					ptr++;
				// skip the = before grabbing Zip_File
				while (*ptr == '=')
					ptr++;
				if (*ptr) {
					Zip_File = ptr;
				} else
					LOGERR("argument error specifying zip file\n");
			} else if (*argptr == 'w') {
				if (len == 9)
					Factory_Reset = true;
				else if (len == 10)
					Cache_Wipe = true;
			} else if (*argptr == 'n') {
				Perform_Backup = true;
			} else if (*argptr == 'p') {
				Shutdown = true;
			} else if (*argptr == 's') {
				ptr = argptr;
				index2 = 0;
				while (*ptr != '=' && *ptr != '\n')
					ptr++;
				if (*ptr) {
					Reboot_Value = *ptr;
				}
			}
		}
		printf("\n");
	}

	if(crash_counter == 0) {
		property_list(Print_Prop, NULL);
		printf("\n");
	} else {
		printf("twrp.crash_counter=%d\n", crash_counter);
	}

	// Check for and run startup script if script exists
	TWFunc::check_and_run_script("/sbin/runatboot.sh", "boot");
	TWFunc::check_and_run_script("/sbin/postrecoveryboot.sh", "boot");

#ifdef TW_INCLUDE_INJECTTWRP
	// Back up TWRP Ramdisk if needed:
	TWPartition* Boot = PartitionManager.Find_Partition_By_Path("/boot");
	LOGINFO("Backing up TWRP ramdisk...\n");
	if (Boot == NULL || Boot->Current_File_System != "emmc")
		TWFunc::Exec_Cmd("injecttwrp --backup /tmp/backup_recovery_ramdisk.img");
	else {
		string injectcmd = "injecttwrp --backup /tmp/backup_recovery_ramdisk.img bd=" + Boot->Actual_Block_Device;
		TWFunc::Exec_Cmd(injectcmd);
	}
	LOGINFO("Backup of TWRP ramdisk done.\n");
#endif

	bool Keep_Going = true;
	if (Perform_Backup) {
		DataManager::SetValue(TW_BACKUP_NAME, "(Auto Generate)");
		if (!OpenRecoveryScript::Insert_ORS_Command("backup BSDCAE\n"))
			Keep_Going = false;
	}
	if (Keep_Going && !Zip_File.empty()) {
		string ORSCommand = "install " + Zip_File;

		if (!OpenRecoveryScript::Insert_ORS_Command(ORSCommand))
			Keep_Going = false;
	}
	if (Keep_Going) {
		if (Factory_Reset) {
			if (!OpenRecoveryScript::Insert_ORS_Command("wipe data\n"))
				Keep_Going = false;
		} else if (Cache_Wipe) {
			if (!OpenRecoveryScript::Insert_ORS_Command("wipe cache\n"))
				Keep_Going = false;
		}
	}

	TWFunc::Update_Log_File();
	// Offer to decrypt if the device is encrypted
	if (DataManager::GetIntValue(TW_IS_ENCRYPTED) != 0) {
		LOGINFO("Is encrypted, do decrypt page first\n");
		if (gui_startPage("decrypt", 1, 1) != 0) {
			LOGERR("Failed to start decrypt GUI page.\n");
		} else {
			// Check for and load custom theme if present
			gui_loadCustomResources();
		}
	} else if (datamedia) {
		if (tw_get_default_metadata(DataManager::GetSettingsStoragePath().c_str()) != 0) {
			LOGINFO("Failed to get default contexts and file mode for storage files.\n");
		} else {
			LOGINFO("Got default contexts and file mode for storage files.\n");
		}
	}

	// Read the settings file
#ifdef TW_HAS_MTP
	// We unmount partitions sometimes during early boot which may override
	// the default of MTP being enabled by auto toggling MTP off. This
	// will force it back to enabled then get overridden by the settings
	// file, assuming that an entry for tw_mtp_enabled is set.
	DataManager::SetValue("tw_mtp_enabled", 1);
#endif
	DataManager::ReadSettingsFile();

	// Fixup the RTC clock on devices which require it
	if(crash_counter == 0)
		TWFunc::Fixup_Time_On_Boot();

	// Run any outstanding OpenRecoveryScript
	if (DataManager::GetIntValue(TW_IS_ENCRYPTED) == 0 && (TWFunc::Path_Exists(SCRIPT_FILE_TMP) || TWFunc::Path_Exists(SCRIPT_FILE_CACHE))) {
		OpenRecoveryScript::Run_OpenRecoveryScript();
	}

#ifdef TW_HAS_MTP
	// Enable MTP?
	char mtp_crash_check[PROPERTY_VALUE_MAX];
	property_get("mtp.crash_check", mtp_crash_check, "0");
	if (strcmp(mtp_crash_check, "0") == 0) {
		property_set("mtp.crash_check", "1");
		if (DataManager::GetIntValue("tw_mtp_enabled") == 1 && ((DataManager::GetIntValue(TW_IS_ENCRYPTED) != 0 && DataManager::GetIntValue(TW_IS_DECRYPTED) != 0) || DataManager::GetIntValue(TW_IS_ENCRYPTED) == 0)) {
			LOGINFO("Enabling MTP during startup\n");
			if (!PartitionManager.Enable_MTP())
				PartitionManager.Disable_MTP();
			else
				gui_print("MTP Enabled\n");
		} else {
			PartitionManager.Disable_MTP();
		}
		property_set("mtp.crash_check", "0");
	} else {
		gui_print_color("warning", "MTP Crashed, not starting MTP on boot.\n");
		DataManager::SetValue("tw_mtp_enabled", 0);
		PartitionManager.Disable_MTP();
	}
#else
	PartitionManager.Disable_MTP();
#endif

	// Launch the main GUI
	gui_start();

	// Disable flashing of stock recovery
	TWFunc::Disable_Stock_Recovery_Replace();
	// Check for su to see if the device is rooted or not
	if (PartitionManager.Mount_By_Path("/system", false)) {
		if (TWFunc::Path_Exists("/supersu/su") && !TWFunc::Path_Exists("/system/bin/su") && !TWFunc::Path_Exists("/system/xbin/su") && !TWFunc::Path_Exists("/system/bin/.ext/.su")) {
			// Device doesn't have su installed
			DataManager::SetValue("tw_busy", 1);
			if (gui_startPage("installsu", 1, 1) != 0) {
				LOGERR("Failed to start SuperSU install page.\n");
			}
		}
		sync();
		PartitionManager.UnMount_By_Path("/system", false);
	}

	// Reboot
	TWFunc::Update_Intent_File(Reboot_Value);
	TWFunc::Update_Log_File();
	gui_print("Rebooting...\n");
	string Reboot_Arg;
	DataManager::GetValue("tw_reboot_arg", Reboot_Arg);
	if (Reboot_Arg == "recovery")
		TWFunc::tw_reboot(rb_recovery);
	else if (Reboot_Arg == "poweroff")
		TWFunc::tw_reboot(rb_poweroff);
	else if (Reboot_Arg == "bootloader")
		TWFunc::tw_reboot(rb_bootloader);
	else if (Reboot_Arg == "download")
		TWFunc::tw_reboot(rb_download);
	else
		TWFunc::tw_reboot(rb_system);

	return 0;
}
Ejemplo n.º 14
0
int
main(int argc, char **argv) {
    // Recovery needs to install world-readable files, so clear umask
    // set by init
    umask(0);

    time_t start = time(NULL);

    // If these fail, there's not really anywhere to complain...
    freopen(TEMPORARY_LOG_FILE, "a", stdout); setbuf(stdout, NULL);
    freopen(TEMPORARY_LOG_FILE, "a", stderr); setbuf(stderr, NULL);

    // If this binary is started with the single argument "--adbd",
    // instead of being the normal recovery binary, it turns into kind
    // of a stripped-down version of adbd that only supports the
    // 'sideload' command.  Note this must be a real argument, not
    // anything in the command file or bootloader control block; the
    // only way recovery should be run with this argument is when it
    // starts a copy of itself from the apply_from_adb() function.
    if (argc == 3 && strcmp(argv[1], "--adbd") == 0) {
        adb_main(argv[2]);
        return 0;
    }

    printf("Starting TWRP %s on %s", TW_VERSION_STR, ctime(&start));

    Device* device = make_device();
    ui = device->GetUI();

	//ui->Init();
    //ui->SetBackground(RecoveryUI::NONE);
    //load_volume_table();

	// Load default values to set DataManager constants and handle ifdefs
	DataManager_LoadDefaults();
	printf("Starting the UI...");
	gui_init();
	printf("=> Linking mtab\n");
	system("ln -s /proc/mounts /etc/mtab"); // Link mtab for mke2fs
	printf("=> Processing recovery.fstab\n");
	if (!PartitionManager.Process_Fstab("/etc/recovery.fstab", 1)) {
		LOGE("Failing out of recovery due to problem with recovery.fstab.\n");
		//return -1;
	}
	PartitionManager.Output_Partition_Logging();
	// Load up all the resources
	gui_loadResources();

    get_args(&argc, &argv);

    int previous_runs = 0;
    const char *send_intent = NULL;
    const char *update_package = NULL;
    int wipe_data = 0, wipe_cache = 0;
    bool just_exit = false;
	bool perform_backup = false;

    int arg;
    while ((arg = getopt_long(argc, argv, "", OPTIONS, NULL)) != -1) {
        switch (arg) {
        case 'p': previous_runs = atoi(optarg); break;
        case 's': send_intent = optarg; break;
        case 'u': update_package = optarg; break;
        case 'w': wipe_data = wipe_cache = 1; break;
        case 'c': wipe_cache = 1; break;
        case 't': ui->ShowText(true); break;
        case 'x': just_exit = true; break;
        case 'n': perform_backup = true; LOGI("nandroid\n"); break;
        case '?':
            LOGE("Invalid command argument\n");
            continue;
        }
    }

#ifdef HAVE_SELINUX
    struct selinux_opt seopts[] = {
      { SELABEL_OPT_PATH, "/file_contexts" }
    };

    sehandle = selabel_open(SELABEL_CTX_FILE, seopts, 1);

    if (!sehandle) {
        fprintf(stderr, "Warning: No file_contexts\n");
        ui->Print("Warning:  No file_contexts\n");
    }
#endif

    //device->StartRecovery();

    printf("Command:");
    for (arg = 0; arg < argc; arg++) {
        printf(" \"%s\"", argv[arg]);
    }
    printf("\n");

    if (update_package) {
        // For backwards compatibility on the cache partition only, if
        // we're given an old 'root' path "CACHE:foo", change it to
        // "/cache/foo".
        if (strncmp(update_package, "CACHE:", 6) == 0) {
            int len = strlen(update_package) + 10;
            char* modified_path = (char*)malloc(len);
            strlcpy(modified_path, "/cache/", len);
            strlcat(modified_path, update_package+6, len);
            printf("(replacing path \"%s\" with \"%s\")\n",
                   update_package, modified_path);
            update_package = modified_path;
        }
    }
    printf("\n");

    property_list(print_property, NULL);
    printf("\n");

	// Check for and run startup script if script exists
	TWFunc::check_and_run_script("/sbin/runatboot.sh", "boot");
	TWFunc::check_and_run_script("/sbin/postrecoveryboot.sh", "boot");

#ifdef TW_INCLUDE_INJECTTWRP
	// Back up TWRP Ramdisk if needed:
	LOGI("Backing up TWRP ramdisk...\n");
	system("injecttwrp --backup /tmp/backup_recovery_ramdisk.img");
	LOGI("Backup of TWRP ramdisk done.\n");
#endif

    int status = INSTALL_SUCCESS;

	if (perform_backup) {
		char empt[50];
		gui_console_only();
		strcpy(empt, "(Current Date)");
		DataManager_SetStrValue(TW_BACKUP_NAME, empt);
		if (OpenRecoveryScript::Backup_Command("BSDCAE") != 0)
			status = INSTALL_ERROR;
	}
	if (status == INSTALL_SUCCESS) { // Prevent other actions if backup failed
    if (update_package != NULL) {
		gui_console_only();
		if (OpenRecoveryScript::Install_Command(update_package) == 0)
			status = INSTALL_SUCCESS;
		else
			status = INSTALL_ERROR;
		/*
        status = install_package(update_package, &wipe_cache, TEMPORARY_INSTALL_FILE);
        if (status == INSTALL_SUCCESS && wipe_cache) {
            if (erase_volume("/cache")) {
                LOGE("Cache wipe (requested by package) failed.");
            }
        }
        if (status != INSTALL_SUCCESS) ui->Print("Installation aborted.\n");
		*/
    } else if (wipe_data) {
		gui_console_only();
		if (!PartitionManager.Factory_Reset()) status = INSTALL_ERROR;
		/*
        if (device->WipeData()) status = INSTALL_ERROR;
        if (erase_volume("/data")) status = INSTALL_ERROR;
        if (wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR;
		*/
        if (status != INSTALL_SUCCESS) ui->Print("Data wipe failed.\n");
    } else if (wipe_cache) {
		gui_console_only();
        if (wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR;
        if (status != INSTALL_SUCCESS) ui->Print("Cache wipe failed.\n");
    } else if (!just_exit) {
        status = INSTALL_ERROR;  // No command specified
    }
	}

    //if (status != INSTALL_SUCCESS) ui->SetBackground(RecoveryUI::ERROR);
    if (status != INSTALL_SUCCESS /*|| ui->IsTextVisible()*/) {
		finish_recovery(NULL);
		DataManager_ReadSettingsFile();
		if (PartitionManager.Mount_By_Path("/system", false) && TWFunc::Path_Exists("/system/recovery-from-boot.p")) {
			system("mv /system/recovery-from-boot.p /system/recovery-from-boot.bak");
			ui_print("Renamed stock recovery file in /system to prevent\nthe stock ROM from replacing TWRP.\n");
		}
		PartitionManager.UnMount_By_Path("/system", false);
		if (DataManager_GetIntValue(TW_IS_ENCRYPTED) == 0 && OpenRecoveryScript::check_for_script_file()) {
			gui_console_only();
			if (OpenRecoveryScript::run_script_file() != 0) {
				// There was an error, boot the recovery
				gui_start();
			} else {
				usleep(2000000); // Sleep for 2 seconds before rebooting
			}
		} else
			gui_start();
		//prompt_and_wait(device);
    }

    // Otherwise, get ready to boot the main system...
    finish_recovery(send_intent);
    ui->Print("Rebooting...\n");
#ifdef ANDROID_RB_RESTART
    android_reboot(ANDROID_RB_RESTART, 0, 0);
#else
	reboot(RB_AUTOBOOT);
#endif
    return EXIT_SUCCESS;
}
Ejemplo n.º 15
0
int main(int argc, char *argv[])
{
    cal_path();
    setlocale(LC_MESSAGES, "");
    bindtextdomain("opvdm", get_lang_path());
    textdomain("opvdm");

    timer_init(0);
    timer_init(1);
    dbus_init();
    set_ewe_lock_file("", "");
    cell.onlypos = FALSE;

    char pwd[1000];
    if (getcwd(pwd, 1000) == NULL) {
        ewe("IO error\n");
    }

    dump_init(&cell);
    dump_load_config(&cell);

    remove("snapshots.zip");
    remove("light_dump.zip");

    hard_limit_init();

//char path[PATH_MAX];
//char dest[PATH_MAX];
//pid_t pid = getpid();
//sprintf(path, "/proc/%d/exe", pid);

//if (readlink(path, dest, PATH_MAX) == -1)
//{
//      printf("error\n");
//      exit(1);
//}
//  char *base = strrchr(dest, '/');
//*base='/';
//*(base+1)=0;
    set_plot_script_dir(pwd);

//set_plot_script_dir(char * in)
    if (scanarg(argv, argc, "--help") == TRUE) {
        printf("opvdm_core - Organic Photovoltaic Device Model\n");
        printf(copyright);
        printf("\n");
        printf("Usage: opvdm_core [options]\n");
        printf("\n");
        printf("Options:\n");
        printf("\n");
        printf("\t--outputpath\toutput data path");
        printf("\t--inputpath\t sets the input path\n");
        printf("\t--version\tdisplays the current version\n");
        printf("\t--zip_results\t zip the results\n");
        printf("\t--optics\t runs only optical simulation\n");
        printf("\t--cpus\t sets the number of CPUs\n");
        printf("\n");
        printf
        ("Additional information about opvdm is available at www.opvdm.com.\n");
        printf("\n");
        printf
        ("Report bugs to: [email protected]\n\n");
        exit(0);
    }
    if (scanarg(argv, argc, "--version") == TRUE) {
        printf("opvdm_core, Version %s\n", opvdm_ver);
        printf(copyright);
        printf(this_is_free_software);
        printf
        ("There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or\n");
        printf("FITNESS FOR A PARTICULAR PURPOSE.\n");
        printf("\n");
        exit(0);
    }

    if (geteuid() == 0) {
        ewe("Don't run me as root!\n");
    }

    set_dump_status(dump_stop_plot, FALSE);
    set_dump_status(dump_print_text, TRUE);

    set_io_dump(FALSE);
    srand(time(0));
    textcolor(fg_green);
    randomprint(_("Organic Photovoltaic Device Model (www.opvdm.com)\n"));
    randomprint(_
                ("You should have received a copy of the GNU General Public License\n"));
    randomprint(_
                ("along with this software.  If not, see www.gnu.org/licenses/.\n"));
    randomprint("\n");
    randomprint(_
                ("If you wish to collaborate in anyway please get in touch:\n"));
    randomprint(_("[email protected]\n"));
    randomprint(_("www.roderickmackenzie.eu/contact.html\n"));
    randomprint("\n");
    textcolor(fg_reset);

    globalserver.on = FALSE;
    globalserver.cpus = 1;
    globalserver.readconfig = TRUE;

    if (scanarg(argv, argc, "--outputpath") == TRUE) {
        strcpy(sim_output_path(),
               get_arg_plusone(argv, argc, "--outputpath"));
    } else {
        strcpy(sim_output_path(), pwd);
    }

    if (scanarg(argv, argc, "--inputpath") == TRUE) {
        strcpy(sim_input_path(),
               get_arg_plusone(argv, argc, "--inputpath"));
    } else {
        strcpy(sim_input_path(), sim_output_path());
    }

    dump_load_config(&cell);

    if (scanarg(argv, argc, "--onlypos") == TRUE) {
        cell.onlypos = TRUE;
    }

    char name[200];
    struct inp_file inp;
    inp_init(&inp);
    inp_load_from_path(&inp, sim_input_path(), "ver.inp");
    inp_check(&inp, 1.0);
    inp_search_string(&inp, name, "#core");
    inp_free(&inp);

    if (strcmp(name, opvdm_ver) != 0) {
        printf
        ("Software is version %s and the input files are version %s\n",
         opvdm_ver, name);
        exit(0);
    }

    gui_start();
    if (scanarg(argv, argc, "--optics") == FALSE)
        server_init(&globalserver);

    if (scanarg(argv, argc, "--lock") == TRUE) {
        server_set_dbus_finish_signal(&globalserver,
                                      get_arg_plusone(argv, argc,
                                              "--lock"));
    }

    int ret = 0;

    int do_fit = FALSE;

    if (scanarg(argv, argc, "--fit") == TRUE)
        do_fit = TRUE;

    FILE *f = fopen("fit.inp", "r");
    if (f != NULL) {
        fclose(f);
        inp_init(&inp);
        inp_load_from_path(&inp, pwd, "fit.inp");
        int fit_temp;
        inp_search_int(&inp, &fit_temp, "#do_fit");
        if (fit_temp == 1) {
            do_fit = TRUE;
        }

        inp_free(&inp);
    }

    if (do_fit == TRUE) {
        set_dump_status(dump_lock, FALSE);
        set_dump_status(dump_print_text, FALSE);
        set_dump_status(dump_iodump, FALSE);
        set_dump_status(dump_optics, FALSE);
        set_dump_status(dump_newton, FALSE);
        set_dump_status(dump_plot, FALSE);
        set_dump_status(dump_stop_plot, FALSE);
        set_dump_status(dump_opt_for_fit, FALSE);
        set_dump_status(dump_print_newtonerror, FALSE);
        set_dump_status(dump_print_converge, FALSE);
        set_dump_status(dump_print_pos_error, FALSE);
        set_dump_status(dump_lock, TRUE);
    }
#include "main_args.c"
    if (scanarg(argv, argc, "--optics") == TRUE) {
        gui_start();
        struct light two;
        light_init(&two, &cell, pwd);
        //light_set_dx(&cell.mylight,cell.ymesh[1]-cell.ymesh[0]);
        light_load_config(&two);
        two.disable_transfer_to_electrical_mesh = TRUE;
        set_dump_status(dump_lock, FALSE);
        set_dump_status(dump_optics, TRUE);
        set_dump_status(dump_optics_verbose, TRUE);
        double Psun;
        inp_init(&inp);
        inp_load_from_path(&inp, pwd, "light.inp");
        inp_search_double(&inp, &(Psun), "#Psun");
        Psun = 1.0;	//fabs(Psun);
        inp_free(&inp);

        light_solve_and_update(&cell, &two, Psun, 0.0);
        light_dump(&two);
        light_free(&two);
        complex_solver_free();
    } else {
        gen_dos_fd_gaus_fd();

        server_add_job(&globalserver, cell.outputpath, cell.inputpath);
        print_jobs(&globalserver);
        ret = server_run_jobs(&globalserver);

    }

    server_shut_down(&globalserver);

    if (scanarg(argv, argc, "--zip_results") == TRUE) {
        printf("zipping results\n");
        int ret;
        char temp[200];
        DIR *dir = opendir("snapshots");
        if (dir) {
            closedir(dir);
            ret =
                system("zip -r -j -q snapshots.zip ./snapshots/*");
            if (ret == -1) {
                printf("tar returned error\n");
            }

            join_path(2, temp, cell.outputpath, "snapshots");
            remove_dir(temp);

        }

        dir = opendir("light_dump");
        if (dir) {
            closedir(dir);
            ret =
                system
                ("zip -r -j -q light_dump.zip ./light_dump/*");
            if (ret == -1) {
                printf("tar returned error\n");
            }

            join_path(2, temp, cell.outputpath, "light_dump");
            remove_dir(temp);

        }

    }

    hard_limit_free();
    if (ret != 0) {
        return 1;
    }
    return 0;
}
Ejemplo n.º 16
0
int
main(int argc, char **argv) {
    // Recovery needs to install world-readable files, so clear umask
    // set by init
    umask(0);

    time_t start = time(NULL);

    // If these fail, there's not really anywhere to complain...
    freopen(TEMPORARY_LOG_FILE, "a", stdout); setbuf(stdout, NULL);
    freopen(TEMPORARY_LOG_FILE, "a", stderr); setbuf(stderr, NULL);

    // If this binary is started with the single argument "--adbd",
    // instead of being the normal recovery binary, it turns into kind
    // of a stripped-down version of adbd that only supports the
    // 'sideload' command.  Note this must be a real argument, not
    // anything in the command file or bootloader control block; the
    // only way recovery should be run with this argument is when it
    // starts a copy of itself from the apply_from_adb() function.
    if (argc == 3 && strcmp(argv[1], "--adbd") == 0) {
        adb_main(argv[2]);
        return 0;
    }

    printf("Starting TWRP %s on %s", TW_VERSION_STR, ctime(&start));

    Device* device = make_device();
    ui = device->GetUI();

	//ui->Init();
    //ui->SetBackground(RecoveryUI::NONE);
    //load_volume_table();

	// Load default values to set DataManager constants and handle ifdefs
	DataManager_LoadDefaults();
	printf("Starting the UI...");
	gui_init();
	printf("=> Linking mtab\n");
	symlink("/proc/mounts", "/etc/mtab");
	printf("=> Processing recovery.fstab\n");
	if (!PartitionManager.Process_Fstab("/etc/recovery.fstab", 1)) {
		LOGE("Failing out of recovery due to problem with recovery.fstab.\n");
		//return -1;
	}
	PartitionManager.Output_Partition_Logging();
	// Load up all the resources
	gui_loadResources();

	PartitionManager.Mount_By_Path("/cache", true);
    get_args(&argc, &argv);

    int previous_runs = 0;
    const char *send_intent = NULL;
    const char *update_package = NULL;
    int wipe_data = 0, wipe_cache = 0;
    bool just_exit = false;
	bool perform_backup = false;

    int arg;
    while ((arg = getopt_long(argc, argv, "", OPTIONS, NULL)) != -1) {
        switch (arg) {
        case 'p': previous_runs = atoi(optarg); break;
        case 's': send_intent = optarg; break;
        case 'u': update_package = optarg; break;
        case 'w': wipe_data = wipe_cache = 1; break;
        case 'c': wipe_cache = 1; break;
        case 't': ui->ShowText(true); break;
        case 'x': just_exit = true; break;
        case 'n': perform_backup = true; LOGI("nandroid\n"); break;
        case '?':
            LOGE("Invalid command argument\n");
            continue;
        }
    }

#ifdef HAVE_SELINUX
    struct selinux_opt seopts[] = {
      { SELABEL_OPT_PATH, "/file_contexts" }
    };

    sehandle = selabel_open(SELABEL_CTX_FILE, seopts, 1);

    if (!sehandle) {
        fprintf(stderr, "Warning: No file_contexts\n");
        ui->Print("Warning:  No file_contexts\n");
    }
#endif

    //device->StartRecovery();

    printf("Command:");
    for (arg = 0; arg < argc; arg++) {
        printf(" \"%s\"", argv[arg]);
    }
    printf("\n");

    if (update_package) {
        // For backwards compatibility on the cache partition only, if
        // we're given an old 'root' path "CACHE:foo", change it to
        // "/cache/foo".
        if (strncmp(update_package, "CACHE:", 6) == 0) {
            int len = strlen(update_package) + 10;
            char* modified_path = (char*)malloc(len);
            strlcpy(modified_path, "/cache/", len);
            strlcat(modified_path, update_package+6, len);
            printf("(replacing path \"%s\" with \"%s\")\n",
                   update_package, modified_path);
            update_package = modified_path;
        }
    }
    printf("\n");

    property_list(print_property, NULL);
    printf("\n");

	// Check for and run startup script if script exists
	TWFunc::check_and_run_script("/sbin/runatboot.sh", "boot");
	TWFunc::check_and_run_script("/sbin/postrecoveryboot.sh", "boot");

#ifdef TW_INCLUDE_INJECTTWRP
	// Back up TWRP Ramdisk if needed:
	TWPartition* Boot = PartitionManager.Find_Partition_By_Path("/boot");
	string result;
	LOGI("Backing up TWRP ramdisk...\n");
	if (Boot == NULL || Boot->Current_File_System != "emmc")
		TWFunc::Exec_Cmd("injecttwrp --backup /tmp/backup_recovery_ramdisk.img", result);
	else {
		string injectcmd = "injecttwrp --backup /tmp/backup_recovery_ramdisk.img bd=" + Boot->Actual_Block_Device;
		TWFunc::Exec_Cmd(injectcmd, result);
	}
	LOGI("Backup of TWRP ramdisk done.\n");
#endif

    int status = INSTALL_SUCCESS;
	string ORSCommand;

	if (perform_backup) {
		char empt[50];
		gui_console_only();
		strcpy(empt, "(Current Date)");
		DataManager_SetStrValue(TW_BACKUP_NAME, empt);
		if (!OpenRecoveryScript::Insert_ORS_Command("backup BSDCAE\n"))
			status = INSTALL_ERROR;
	}
	if (status == INSTALL_SUCCESS) { // Prevent other actions if backup failed
    if (update_package != NULL) {
		ORSCommand = "install ";
		ORSCommand += update_package;
		ORSCommand += "\n";

		if (OpenRecoveryScript::Insert_ORS_Command(ORSCommand))
			status = INSTALL_SUCCESS;
		else
			status = INSTALL_ERROR;
		/*
        status = install_package(update_package, &wipe_cache, TEMPORARY_INSTALL_FILE);
        if (status == INSTALL_SUCCESS && wipe_cache) {
            if (erase_volume("/cache")) {
                LOGE("Cache wipe (requested by package) failed.");
            }
        }
        if (status != INSTALL_SUCCESS) ui->Print("Installation aborted.\n");
		*/
    } else if (wipe_data) {
		if (!OpenRecoveryScript::Insert_ORS_Command("wipe data\n"))
			status = INSTALL_ERROR;
		/*
        if (device->WipeData()) status = INSTALL_ERROR;
        if (erase_volume("/data")) status = INSTALL_ERROR;
        if (wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR;
		*/
        if (status != INSTALL_SUCCESS) ui->Print("Data wipe failed.\n");
    } else if (wipe_cache) {
        if (!OpenRecoveryScript::Insert_ORS_Command("wipe cache\n"))
			status = INSTALL_ERROR;
        if (status != INSTALL_SUCCESS) ui->Print("Cache wipe failed.\n");
    } else if (!just_exit) {
        status = INSTALL_ERROR;  // No command specified
    }
	}

	finish_recovery(NULL);
	// Offer to decrypt if the device is encrypted
	if (DataManager_GetIntValue(TW_IS_ENCRYPTED) != 0) {
		LOGI("Is encrypted, do decrypt page first\n");
		if (gui_startPage("decrypt") != 0) {
			LOGE("Failed to start decrypt GUI page.\n");
		}
	}

	// Read the settings file
	DataManager_ReadSettingsFile();
	// Run any outstanding OpenRecoveryScript
	if (DataManager_GetIntValue(TW_IS_ENCRYPTED) == 0 && (TWFunc::Path_Exists(SCRIPT_FILE_TMP) || TWFunc::Path_Exists(SCRIPT_FILE_CACHE))) {
		OpenRecoveryScript::Run_OpenRecoveryScript();
	}
	// Launch the main GUI
	gui_start();

	// Check for su to see if the device is rooted or not
	if (PartitionManager.Mount_By_Path("/system", false)) {
		// Disable flashing of stock recovery
		if (TWFunc::Path_Exists("/system/recovery-from-boot.p")) {
			rename("/system/recovery-from-boot.p", "/system/recovery-from-boot.bak");
			ui_print("Renamed stock recovery file in /system to prevent\nthe stock ROM from replacing TWRP.\n");
		}
		if (TWFunc::Path_Exists("/supersu/su") && !TWFunc::Path_Exists("/system/bin/su") && !TWFunc::Path_Exists("/system/xbin/su") && !TWFunc::Path_Exists("/system/bin/.ext/.su")) {
			// Device doesn't have su installed
			DataManager_SetIntValue("tw_busy", 1);
			if (gui_startPage("installsu") != 0) {
				LOGE("Failed to start decrypt GUI page.\n");
			}
		} else if (TWFunc::Check_su_Perms() > 0) {
			// su perms are set incorrectly
			DataManager_SetIntValue("tw_busy", 1);
			if (gui_startPage("fixsu") != 0) {
				LOGE("Failed to start decrypt GUI page.\n");
			}
		}
		sync();
		PartitionManager.UnMount_By_Path("/system", false);
	}

    // Otherwise, get ready to boot the main system...
    finish_recovery(send_intent);
    ui->Print("Rebooting...\n");
	char backup_arg_char[50];
	strcpy(backup_arg_char, DataManager_GetStrValue("tw_reboot_arg"));
	string backup_arg = backup_arg_char;
	if (backup_arg == "recovery")
		TWFunc::tw_reboot(rb_recovery);
	else if (backup_arg == "poweroff")
		TWFunc::tw_reboot(rb_poweroff);
	else if (backup_arg == "bootloader")
		TWFunc::tw_reboot(rb_bootloader);
	else if (backup_arg == "download")
		TWFunc::tw_reboot(rb_download);
	else
		TWFunc::tw_reboot(rb_system);

#ifdef ANDROID_RB_RESTART
    android_reboot(ANDROID_RB_RESTART, 0, 0);
#else
	reboot(RB_AUTOBOOT);
#endif
    return EXIT_SUCCESS;
}
Ejemplo n.º 17
0
int systest_run(void)
{
    gui_start(&root_menu);
    return 0;
}
Ejemplo n.º 18
0
static int conf_enter(struct state *st, struct state *prev)
{
    int id, jd, kd;
    int i;

    back_init("back/gui.png");

    /* Initialize the configuration GUI. */

    if ((id = gui_vstack(0)))
    {
        if ((jd = gui_harray(id)))
        {
            gui_label(jd, _("Options"), GUI_SML, 0, 0);
            gui_space(jd);
            gui_start(jd, _("Back"),    GUI_SML, CONF_BACK, 0);
        }

        gui_space(id);

        if ((jd = gui_harray(id)) &&
            (kd = gui_harray(jd)))
        {
            gui_state(kd, _("Configure"), GUI_SML, CONF_VIDEO, 0);

            gui_label(jd, _("Graphics"),  GUI_SML, 0, 0);
        }

        gui_space(id);

        if ((jd = gui_harray(id)) &&
            (kd = gui_harray(jd)))
        {
            /* A series of empty buttons forms the sound volume control. */

            int s = config_get_d(CONFIG_SOUND_VOLUME);

            for (i = 10; i >= 0; i--)
            {
                sound_id[i] = gui_state(kd, NULL, GUI_SML, 100 + i, 0);
                gui_set_hilite(sound_id[i], (s == i));
            }

            gui_label(jd, _("Sound Volume"), GUI_SML, 0, 0);
        }

        if ((jd = gui_harray(id)) &&
            (kd = gui_harray(jd)))
        {
            /* A series of empty buttons forms the music volume control. */

            int m = config_get_d(CONFIG_MUSIC_VOLUME);

            for (i = 10; i >= 0; i--)
            {
                music_id[i] = gui_state(kd, NULL, GUI_SML, 200 + i, 0);
                gui_set_hilite(music_id[i], (m == i));
            }

            gui_label(jd, _("Music Volume"), GUI_SML, 0, 0);
        }

        gui_space(id);

        if ((jd = gui_harray(id)) &&
            (kd = gui_harray(jd)))
        {
            gui_state(kd, _("Select"), GUI_SML, CONF_LANG, 0);

            gui_label(jd, _("Language"),  GUI_SML, 0, 0);
        }

        gui_layout(id, 0, 0);
    }

    audio_music_fade_to(0.5f, "bgm/inter.ogg");

    return id;
}
Ejemplo n.º 19
0
int main(int argc, char *argv[])
{
    int s = socket(AF_INET, SOCK_STREAM, 0);
    struct sockaddr_in server;

    if (s < 0){
        perror("Can't open socket");
        exit(1);
    }

    if (argc < 2){
        printf("No server specified.\n");
        exit(1);
    }

    server.sin_addr.s_addr = inet_addr(argv[1]);
    server.sin_family = AF_INET;
    server.sin_port = htons(DEFAULT_PORT);

    if (connect(s , (struct sockaddr *)&server , sizeof(server)) < 0){
        printf("Could not connect to host\n");
        exit(1);
    }


// Pass these to gui_start() and use them instead of stdin/stdout.
    int infd, outfd;

    // start GUI
    if((gui_start(&infd, &outfd)) < 0) {
        fprintf(stderr, "Failed to start GUI -- exiting\n");
        return -1;
    }


    polls[0].fd = s;
    polls[0].events = POLLIN;



    polls[1].fd = infd;
    polls[1].events = POLLIN;

    while (1) {
        printf("Poll\n");

        if (poll(polls, 2, -1) == -1){
            perror("Error polling.\n");
            continue;
        }

        if (polls[1].revents & POLLERR){
            puts("Error. Exit.");
            exit(1);
        }
        if (polls[1].revents & POLLHUP){
            puts("Error. Exit.");
            exit(1);
        }


        if(polls[1].revents & POLLIN){
            char *message = NULL;
            int messagelen = 0;
            int len = 0;
            char buf[1024];
            while ((len = read(infd, buf, 1024)) > 0){
                message = realloc(message, messagelen+len);
                memcpy(message+messagelen, buf, len);
                char *found = (char*) memmem(message+messagelen, len, "\n", 1);
                if (found != NULL){
                    messagelen = found - message;
                    message = realloc(message, messagelen);
                    break;
                }
                messagelen += len;
            }
            write(s, message, messagelen);
            write(s, "\n", 1);
            free(message);
        }


        if (polls[0].revents & POLLIN){
            char *message = NULL;
            int messagelen = 0;
            int len = 0;
            char buf[1024];
            while ((len = read(s, buf, 1024)) > 0){
                message = realloc(message, messagelen+len);
                memcpy(message+messagelen, buf, len);
                char *found = (char*) memmem(message+messagelen, len, "\n", 1);
                if (found != NULL){
                    messagelen = found - message;
                    message = realloc(message, messagelen);
                    break;
                }
                messagelen += len;
            }
            write(outfd, message, messagelen);
            write(outfd, "\n", 1);
            free(message);
        }

    }

    return 0;
}
Ejemplo n.º 20
0
static int start_gui(void)
{
    int w = video.device_w;
    int h = video.device_h;
    int i, j;

    int id, jd, kd, ld;

    if ((id = gui_vstack(0)))
    {
        if ((jd = gui_hstack(id)))
        {

            gui_label(jd, set_name(curr_set()), GUI_SML, gui_yel, gui_red);
            gui_filler(jd);
            gui_start(jd, _("Back"),  GUI_SML, GUI_BACK, 0);
        }

        gui_space(id);

        if ((jd = gui_harray(id)))
        {
            if (config_cheat())
            {
                if ((kd = gui_vstack(jd)))
                {
                    shot_id = gui_image(kd, set_shot(curr_set()),
                                        6 * w / 16, 6 * h / 16);
                    file_id = gui_label(kd, " ", GUI_SML, gui_yel, gui_red);
                }
            }
            else
            {
                shot_id = gui_image(jd, set_shot(curr_set()),
                                    7 * w / 16, 7 * h / 16);
            }

            if ((kd = gui_varray(jd)))
            {
                for (i = 0; i < 5; i++)
                    if ((ld = gui_harray(kd)))
                        for (j = 4; j >= 0; j--)
                            gui_level(ld, i * 5 + j);

                challenge_id = gui_state(kd, _("Challenge"), GUI_SML,
                                         START_CHALLENGE, 0);

                gui_set_hilite(challenge_id, curr_mode() == MODE_CHALLENGE);
            }
        }
        gui_space(id);
        gui_score_board(id, (GUI_SCORE_COIN |
                             GUI_SCORE_TIME |
                             GUI_SCORE_GOAL), 0, 0);
        gui_space(id);

        if ((jd = gui_hstack(id)))
        {
            gui_filler(jd);

            if ((kd = gui_harray(jd)))
            {
                int btn0, btn1;

                btn0 = gui_state(kd, _("Unlocked"), GUI_SML, START_LOCK_GOALS, 0);
                btn1 = gui_state(kd, _("Locked"),   GUI_SML, START_LOCK_GOALS, 1);

                if (config_get_d(CONFIG_LOCK_GOALS))
                    gui_set_hilite(btn1, 1);
                else
                    gui_set_hilite(btn0, 1);
            }

            gui_space(jd);

            gui_label(jd, _("Goal State in Completed Levels"), GUI_SML, 0, 0);

            gui_filler(jd);
        }

        gui_layout(id, 0, 0);

        if (file_id)
            gui_set_trunc(file_id, TRUNC_HEAD);

        set_score_board(NULL, -1, NULL, -1, NULL, -1);
    }

    return id;
}
Ejemplo n.º 21
0
static int conf_enter(struct state *st, struct state *prev)
{
    int id, jd, kd;
    int btn0, btn1;
    int i;

    back_init("back/gui.png");

    /* Initialize the configuration GUI. */

    if ((id = gui_vstack(0)))
    {
        int f = config_get_d(CONFIG_FULLSCREEN);
        int t = config_get_d(CONFIG_TEXTURES);
        int h = config_get_d(CONFIG_SHADOW);
        int s = config_get_d(CONFIG_SOUND_VOLUME);
        int m = config_get_d(CONFIG_MUSIC_VOLUME);

        char resolution[20];

        sprintf(resolution, "%d x %d",
                config_get_d(CONFIG_WIDTH),
                config_get_d(CONFIG_HEIGHT));

        if ((jd = gui_harray(id)))
        {
            gui_label(jd, _("Options"), GUI_SML, GUI_ALL, 0, 0);
            gui_space(jd);
            gui_start(jd, _("Back"),    GUI_SML, CONF_BACK, 0);
        }

        gui_space(id);

        if ((jd = gui_harray(id)) &&
            (kd = gui_harray(jd)))
        {
            btn0 = gui_state(kd, _("No"),  GUI_SML, CONF_WIN,  0);
            btn1 = gui_state(kd, _("Yes"), GUI_SML, CONF_FULL, 0);

            if (f) gui_set_hilite(btn1, 1);
            else   gui_set_hilite(btn0, 1);

            gui_label(jd, _("Fullscreen"), GUI_SML, GUI_ALL, 0, 0);
        }

        if ((jd = gui_harray(id)) &&
            (kd = gui_harray(jd)))
        {
            gui_state(kd, resolution, GUI_SML, CONF_RESOL, 0);

            gui_label(jd, _("Resolution"), GUI_SML, GUI_ALL, 0, 0);
        }

        gui_space(id);

        if ((jd = gui_harray(id)) &&
            (kd = gui_harray(jd)))
        {
            btn0 = gui_state(kd, _("Low"),  GUI_SML, CONF_TEXLO, 0);
            btn1 = gui_state(kd, _("High"), GUI_SML, CONF_TEXHI, 0);

            gui_set_hilite(btn0, (t == 2));
            gui_set_hilite(btn1, (t == 1));

            gui_label(jd, _("Textures"), GUI_SML, GUI_ALL, 0, 0);
        }

        if ((jd = gui_harray(id)) &&
            (kd = gui_harray(jd)))
        {
            btn0 = gui_state(kd, _("Off"),  GUI_SML, CONF_SHDOF, (h == 0));
            btn1 = gui_state(kd, _("On"),   GUI_SML, CONF_SHDON, (h == 1));

            if (h) gui_set_hilite(btn1, 1);
            else   gui_set_hilite(btn0, 1);

            gui_label(jd, _("Shadow"), GUI_SML, GUI_ALL, 0, 0);
        }

        gui_space(id);

        if ((jd = gui_harray(id)) &&
            (kd = gui_harray(jd)))
        {
            /* A series of empty buttons forms the sound volume control. */

            for (i = 10; i >= 0; i--)
            {
                sound_id[i] = gui_state(kd, NULL, GUI_SML, 100 + i, 0);

                gui_set_hilite(sound_id[i], (s == i));
            }

            gui_label(jd, _("Sound Volume"), GUI_SML, GUI_ALL, 0, 0);
        }

        if ((jd = gui_harray(id)) &&
            (kd = gui_harray(jd)))
        {
            /* A series of empty buttons forms the music volume control. */

            for (i = 10; i >= 0; i--)
            {
                music_id[i] = gui_state(kd, NULL, GUI_SML, 200 + i, 0);

                gui_set_hilite(music_id[i], (m == i));
            }

            gui_label(jd, _("Music Volume"), GUI_SML, GUI_ALL, 0, 0);
        }

        gui_layout(id, 0, 0);
    }

    audio_music_fade_to(0.5f, "bgm/inter.ogg");

    return id;
}
Ejemplo n.º 22
0
static int goal_enter(void)
{
    const char *s1 = _("New Record");
    const char *s2 = _("GOAL");

    int id, jd, kd, ld, md;

    const struct level *l = get_level(curr_level());

    int high = progress_lvl_high();

    if (new_name)
    {
        progress_rename(0);
        new_name = 0;
    }

    if ((id = gui_vstack(0)))
    {
        int gid;

        if (high)
            gid = gui_label(id, s1, GUI_MED, GUI_ALL, gui_grn, gui_grn);
        else
            gid = gui_label(id, s2, GUI_LRG, GUI_ALL, gui_blu, gui_grn);

        gui_space(id);

        if (curr_mode() == MODE_CHALLENGE)
        {
            int coins, score, balls;
            char msg[MAXSTR] = "";
            int i;

            /* Reverse-engineer initial score and balls. */

            if (resume)
            {
                coins = 0;
                score = curr_score();
                balls = curr_balls();
            }
            else
            {
                coins = curr_coins();
                score = curr_score() - coins;
                balls = curr_balls();

                for (i = curr_score(); i > score; i--)
                    if (progress_reward_ball(i))
                        balls--;
            }

            sprintf(msg, ngettext("%d new bonus level",
                                  "%d new bonus levels",
                                  curr_bonus()), curr_bonus());

            if ((jd = gui_hstack(id)))
            {
                gui_filler(jd);

                if ((kd = gui_vstack(jd)))
                {
                    if ((ld = gui_hstack(kd)))
                    {
                        if ((md = gui_harray(ld)))
                        {
                            balls_id = gui_count(md, 100, GUI_MED, GUI_NE);
                            gui_label(md, _("Balls"), GUI_SML, 0,
                                      gui_wht, gui_wht);
                        }
                        if ((md = gui_harray(ld)))
                        {
                            score_id = gui_count(md, 1000, GUI_MED, 0);
                            gui_label(md, _("Score"), GUI_SML, 0,
                                      gui_wht, gui_wht);
                        }
                        if ((md = gui_harray(ld)))
                        {
                            coins_id = gui_count(md, 100, GUI_MED, 0);
                            gui_label(md, _("Coins"), GUI_SML, GUI_NW,
                                      gui_wht, gui_wht);
                        }

                        gui_set_count(balls_id, balls);
                        gui_set_count(score_id, score);
                        gui_set_count(coins_id, coins);
                    }

                    gui_label(kd, msg, GUI_SML, GUI_BOT, 0, 0);
                }

                gui_filler(jd);
            }

            gui_space(id);
        }
        else
        {
            balls_id = score_id = coins_id = 0;
        }

        gui_score_board(id, (GUI_MOST_COINS |
                             GUI_BEST_TIMES |
                             GUI_FAST_UNLOCK), 1, high);

        gui_space(id);

        if ((jd = gui_harray(id)))
        {
            if      (progress_done())
                gui_start(jd, _("Finish"), GUI_SML, GOAL_DONE, 0);
            else if (progress_last())
                gui_start(jd, _("Finish"), GUI_SML, GOAL_LAST, 0);

            if (progress_next_avail())
                gui_start(jd, _("Next Level"),  GUI_SML, GOAL_NEXT, 0);

            if (progress_same_avail())
                gui_start(jd, _("Retry Level"), GUI_SML, GOAL_SAME, 0);

            if (demo_saved())
                gui_state(jd, _("Save Replay"), GUI_SML, GOAL_SAVE, 0);
        }

        if (!resume)
            gui_pulse(gid, 1.2f);

        gui_layout(id, 0, 0);

    }

    set_score_board(&l->score.most_coins,  progress_coin_rank(),
                    &l->score.best_times,  progress_time_rank(),
                    &l->score.fast_unlock, progress_goal_rank());

    audio_music_fade_out(2.0f);

    video_clr_grab();

    /* Reset hack. */
    resume = 0;

    return id;
}
Ejemplo n.º 23
0
static int goal_gui(void)
{
    const char *s1 = _("New Record");
    const char *s2 = _("GOAL");

    int id, jd, kd, ld, md;

    int high = progress_lvl_high();

    if ((id = gui_vstack(0)))
    {
        int gid = 0;

        if (curr_mode() == MODE_CHALLENGE)
        {
            int coins, score, balls;
            int i;

            /* Reverse-engineer initial score and balls. */

            if (resume)
            {
                coins = 0;
                score = curr_score();
                balls = curr_balls();
            }
            else
            {
                coins = curr_coins();
                score = curr_score() - coins;
                balls = curr_balls();

                for (i = curr_score(); i > score; i--)
                    if (progress_reward_ball(i))
                        balls--;
            }

            /*if ((jd = gui_hstack(id)))
            {
                gui_filler(jd);*/

                if ((kd = gui_vstack(id)))
                {
                    if ((ld = video.device_w < video.device_h ? gui_vstack(kd) : gui_hstack(kd)))
                    {
                        if ((md = gui_harray(ld)))
                        {
                            balls_id = gui_count(md, 100, GUI_MED);
                            gui_label(md, _("Balls"), GUI_MED,
                                      gui_wht, gui_wht);
                        }
                        if ((md = gui_harray(ld)))
                        {
                            score_id = gui_count(md, 1000, GUI_MED);
                            gui_label(md, _("Score"), GUI_MED,
                                      gui_wht, gui_wht);
                        }
                        if ((md = gui_harray(ld)))
                        {
                            coins_id = gui_count(md, 100, GUI_MED);
                            gui_label(md, _("Coins"), GUI_MED,
                                      gui_wht, gui_wht);
                        }

                        gui_set_count(balls_id, balls);
                        gui_set_count(score_id, score);
                        gui_set_count(coins_id, coins);
                    }

                    if ((ld = gui_harray(kd)))
                    {
                        const struct level *l;

                        gui_label(ld, "", GUI_SML, 0, 0);

                        for (i = MAXLVL - 1; i >= 0; i--)
                            if ((l = get_level(i)) && level_bonus(l))
                            {
                                const GLubyte *c = (level_opened(l) ?
                                                    gui_grn : gui_gry);

                                gui_label(ld, level_name(l), GUI_SML, c, c);
                            }

                        gui_label(ld, "", GUI_SML, 0, 0);
                    }

                    gui_set_rect(kd, GUI_ALL);
                }

                /*gui_filler(jd);
            }*/

            gui_space(id);
        }
        else
        {
            gid = gui_label(id, high ? s1 : s2, GUI_LRG, gui_blu, gui_grn);
            gui_space(id);

            balls_id = score_id = coins_id = 0;
        }

        gui_score_board(id, (GUI_SCORE_COIN |
                             GUI_SCORE_TIME |
                             GUI_SCORE_GOAL |
                             GUI_SCORE_SAVE), 1, high);

        gui_space(id);

        if ((jd = gui_harray(id)))
        {
            if      (progress_done())
                gui_start(jd, _("Finish"), GUI_MED, GOAL_DONE, 0);
            else if (progress_last())
                gui_start(jd, _("Finish"), GUI_MED, GOAL_LAST, 0);

            if (progress_next_avail())
                gui_start(jd, _("Next"),  GUI_MED, GOAL_NEXT, 0);

            if (progress_same_avail())
                gui_start(jd, _("Retry"), GUI_MED, GOAL_SAME, 0);

            if (!progress_done() && !progress_last())
                gui_start(jd, _("Quit"), GUI_MED, GOAL_DONE, 0);
            //if (demo_saved())
            //    gui_state(jd, _("Save Replay"), GUI_SML, GOAL_SAVE, 0);
        }

        if (!resume && gid)
            gui_pulse(gid, 1.2f);

        gui_layout(id, 0, 0);

    }

    set_score_board(level_score(curr_level(), SCORE_COIN), progress_coin_rank(),
                    level_score(curr_level(), SCORE_TIME), progress_time_rank(),
                    level_score(curr_level(), SCORE_GOAL), progress_goal_rank());

    return id;
}
Ejemplo n.º 24
0
void game_start()
{
	#ifndef SKIP_INTRO
	
		
		resetPpSwirl ();
		level_load("menu2.wmb");
		wait(3);
		
		setHdr(LVL_INTRO_HDR_STRENGTH, LVL_INTRO_HDR_THRESHOLD, LVL_INTRO_HDR_EXPOSURE);
		
		camera->arc = 60;
		camera->ambient = 0;
		fog_color = 0;
		
		camera_path("path1");
		PANEL* panBlack = pan_create(" ", 100);
		vec_set(panBlack.blue, vector(8,8,8));
		pan_setdigits(panBlack, 0, 5, 5, "Press [Space] to skip", font_create("Arial#24b"), 1, vDummy);
		pan_setcolor(panBlack, 1, 1, vector(255,255,255));
		set(panBlack, SHOW | LIGHT | OVERLAY);
		
		var vMediaHandle = snd_play(g_musicIntro, 100, 0);
		
		while (key_esc || key_space || key_enter)
			wait(1);
		
		while (snd_playing(vMediaHandle) && !key_esc && !key_space && !key_enter)
			wait(1);
		
		proc_kill((void*)camera_path);
		ptr_remove(panBlack);
		
		snd_stop(vMediaHandle);
		vMediaHandle = 0;
	
	#endif
	
	nPlayerLifes = 3;
	flying_man = 0;
	gui_start();
	
	// standard start level = temple
	#ifndef SKIP_TO
		lvlTempleInit();
	#else
		
		#ifdef SKIP_TO_LOTTIFANTLEVEL
			lvlLfInit();
		#endif
	
		#ifdef SKIP_TO_BOSSLEVEL
			lvlBossInit();
		#endif
		
		#ifdef SKIP_TO_LAVASTAGE
			lvlLavastageInit();
		#endif
		
		#ifdef SKIP_TO_CREDITS
			creditsInit();
		#endif
		
	#endif
}