Exemplo n.º 1
0
int check_create_folder(void)
{
    DIR *dirp;

	if ((dirp = opendir(FOLDER_PATH)) == NULL) {
		if(FIO_CreateDirectory(FOLDER_PATH)) {
			return FALSE;
		} else {
			return TRUE;
		}
    } else {
    	closedir(dirp);
    	return TRUE;
    }
}
Exemplo n.º 2
0
static char* config_choose_startup_preset()
{
    int size = 0;

    /* by default, work in ML/SETTINGS dir */
    snprintf(config_dir, sizeof(config_dir), "ML/SETTINGS/");

    /* check for a preset file selected in menu */
    char* preset_name = (char*) read_entire_file(config_preset_file, &size);
    if (preset_name)
    {
        if (streq(preset_name, "Startup mode"))
        {
            /* will handle later */
            config_preset_index = config_new_preset_index = 1;
        }
        else if (streq(preset_name, "Startup key"))
        {
            /* will handle later */
            config_preset_index = config_new_preset_index = 2;
        }
        else
        {
            snprintf(config_selected_by_name, sizeof(config_selected_by_name), preset_name);
            char preset_dir[0x80];
            snprintf(preset_dir, sizeof(preset_dir), "ML/SETTINGS/%s", preset_name);
            if (!is_dir(preset_dir)) {
                FIO_CreateDirectory(preset_dir);
            }
            if (is_dir(preset_dir))
            {
                snprintf(config_dir, sizeof(config_dir), "%s/", preset_dir);
            }
        }
        fio_free(preset_name);
    }

    /* scan the preset files and populate the menu */
    config_preset_scan();

    /* special cases: key pressed at startup, or startup mode */

    /* key pressed at startup */
    if (config_preset_index == 2)
    {
        if (config_selected_by_key[0])
        {
            char preset_dir[0x80];
            snprintf(preset_dir, sizeof(preset_dir), "ML/SETTINGS/%s.KEY", config_selected_by_key);
            if (!is_dir(preset_dir)) {
                FIO_CreateDirectory(preset_dir);
            }
            if (is_dir(preset_dir))
            {
                /* success */
                snprintf(config_dir, sizeof(config_dir), "%s/", preset_dir);
                return config_selected_by_key;
            }
        }
        /* didn't work */
        return 0;
    }
    else config_selected_by_key[0] = 0;

    /* startup shooting mode (if selected in menu) */
    if (config_preset_index == 1)
    {
        snprintf(config_selected_by_mode, sizeof(config_selected_by_mode), "%s", get_shootmode_name(shooting_mode_custom));
        char preset_dir[0x80];
        snprintf(preset_dir, sizeof(preset_dir), "ML/SETTINGS/%s.MOD", config_selected_by_mode);
        if (!is_dir(preset_dir)) {
            FIO_CreateDirectory(preset_dir);
        }
        if (is_dir(preset_dir))
        {
            /* success */
            snprintf(config_dir, sizeof(config_dir), "%s/", preset_dir);
            return config_selected_by_mode;
        }
        /* didn't work */
        return 0;
    }

    /* lookup the current preset in menu */
    for (int i = 0; i < config_preset_num; i++)
    {
        if (streq(config_preset_choices[i], config_selected_by_name))
        {
            config_preset_index = config_new_preset_index = i;
            return config_selected_by_name;
        }
    }

    /* using default config */
    return 0;
}