(PS3) Works with new dir_list code

This commit is contained in:
Twinaphex 2012-06-23 18:01:21 +02:00 committed by Themaister
parent 9f60e48a98
commit 5b5ba8ac58
6 changed files with 36 additions and 41 deletions

View File

@ -803,7 +803,8 @@ void rarch_config_load(const char * conf_name, const char * libretro_dir_path, c
if(!strcmp(g_settings.libretro, ""))
{
const char *first_file = rarch_manage_libretro_set_first_file(libretro_dir_path, exe_ext);
char first_file[PATH_MAX];
rarch_manage_libretro_set_first_file(first_file, sizeof(first_file), libretro_dir_path, exe_ext);
if(first_file != NULL)
strlcpy(g_settings.libretro, first_file, sizeof(g_settings.libretro));
}

View File

@ -22,11 +22,10 @@ const char * path, const char * extensions)
strlcpy(filebrowser->dir[filebrowser->directory_stack_size], path,
sizeof(filebrowser->dir[filebrowser->directory_stack_size]));
filebrowser->current_dir.elems = dir_list_new(path, extensions, true);
filebrowser->current_dir.size = dir_list_size(filebrowser->current_dir.elems);
filebrowser->current_dir.list = dir_list_new(path, extensions, true);
filebrowser->current_dir.ptr = 0;
dir_list_sort(filebrowser->current_dir.elems, true);
dir_list_sort(filebrowser->current_dir.list, true);
}
static void filebrowser_new(filebrowser_t * filebrowser, const char * start_dir,
@ -49,10 +48,9 @@ void filebrowser_set_current_path(filebrowser_t *filebrowser, const char *path)
void filebrowser_free(filebrowser_t * filebrowser)
{
dir_list_free(filebrowser->current_dir.elems);
dir_list_free(filebrowser->current_dir.list);
filebrowser->current_dir.elems = NULL;
filebrowser->current_dir.size = 0;
filebrowser->current_dir.list = NULL;
filebrowser->current_dir.ptr = 0;
}
@ -82,7 +80,12 @@ const char * filebrowser_get_current_dir (filebrowser_t *filebrowser)
const char * filebrowser_get_current_path (filebrowser_t *filebrowser)
{
return filebrowser->current_dir.elems[filebrowser->current_dir.ptr];
return filebrowser->current_dir.list->elems[filebrowser->current_dir.ptr].data;
}
bool filebrowser_get_current_path_isdir (filebrowser_t *filebrowser)
{
return filebrowser->current_dir.list->elems[filebrowser->current_dir.ptr].attr.b;
}
size_t filebrowser_get_current_index (filebrowser_t *filebrowser)
@ -98,15 +101,15 @@ void filebrowser_set_current_at (filebrowser_t *filebrowser, size_t pos)
static void filebrowser_set_current_increment (filebrowser_t *filebrowser, bool allow_wraparound)
{
filebrowser->current_dir.ptr++;
if (filebrowser->current_dir.ptr >= filebrowser->current_dir.size && allow_wraparound)
if (filebrowser->current_dir.ptr >= filebrowser->current_dir.list->size && allow_wraparound)
filebrowser->current_dir.ptr = 0;
}
static void filebrowser_set_current_decrement (filebrowser_t *filebrowser, bool allow_wraparound)
{
filebrowser->current_dir.ptr--;
if (filebrowser->current_dir.ptr >= filebrowser->current_dir.size && allow_wraparound)
filebrowser->current_dir.ptr = filebrowser->current_dir.size - 1;
if (filebrowser->current_dir.ptr >= filebrowser->current_dir.list->size && allow_wraparound)
filebrowser->current_dir.ptr = filebrowser->current_dir.list->size - 1;
}
void filebrowser_iterate(filebrowser_t *filebrowser, filebrowser_action_t action)
@ -129,7 +132,7 @@ void filebrowser_iterate(filebrowser_t *filebrowser, filebrowser_action_t action
break;
case FILEBROWSER_ACTION_RIGHT:
filebrowser->current_dir.ptr = (min(filebrowser->current_dir.ptr + 5,
filebrowser->current_dir.size-1));
filebrowser->current_dir.list->size-1));
break;
case FILEBROWSER_ACTION_SCROLL_UP:
if (filebrowser->current_dir.ptr <= entries_to_scroll)
@ -145,11 +148,11 @@ void filebrowser_iterate(filebrowser_t *filebrowser, filebrowser_action_t action
break;
case FILEBROWSER_ACTION_SCROLL_DOWN:
filebrowser->current_dir.ptr = (min(filebrowser->current_dir.ptr +
entries_to_scroll, filebrowser->current_dir.size-1));
entries_to_scroll, filebrowser->current_dir.list->size-1));
break;
case FILEBROWSER_ACTION_SCROLL_DOWN_SMOOTH:
filebrowser->current_dir.ptr = (min(filebrowser->current_dir.ptr + 50,
filebrowser->current_dir.size-1));
filebrowser->current_dir.list->size-1));
if(!filebrowser->current_dir.ptr) filebrowser->current_dir.ptr = 0;
break;
case FILEBROWSER_ACTION_OK:

View File

@ -28,8 +28,7 @@ typedef struct
uint32_t directory_stack_size;
char dir[MAX_DIR_STACK][512];
struct {
char **elems;
size_t size;
struct string_list *list;
size_t ptr;
} current_dir;
char root_dir[PATH_MAX];
@ -54,6 +53,7 @@ typedef enum
const char * filebrowser_get_current_dir (filebrowser_t *filebrowser);
const char * filebrowser_get_current_path (filebrowser_t *filebrowser);
bool filebrowser_get_current_path_isdir (filebrowser_t *filebrowser);
size_t filebrowser_get_current_index (filebrowser_t *filebrowser);
void filebrowser_set_root(filebrowser_t *filebrowser, const char *root_dir);
void filebrowser_free(filebrowser_t *filebrowser);

View File

@ -74,24 +74,23 @@ done:
return retstr;
}
const char *rarch_manage_libretro_set_first_file(const char *libretro_path, const char * exe_ext)
void rarch_manage_libretro_set_first_file(char *first_file, size_t size_of_first_file, const char *libretro_path, const char * exe_ext)
{
//We need to set libretro to the first entry in the cores
//directory so that it will be saved to the config file
// FIXME: Use struct string_list*
char ** dir_list = dir_list_new(libretro_path, exe_ext, false);
struct string_list *dir_list = dir_list_new(libretro_path, exe_ext, false);
const char * retstr = NULL;
const char * first_exe;
if (!dir_list)
{
RARCH_ERR("Couldn't read directory.\n");
goto error;
RARCH_ERR("Failed to set first entry to libretro path.\n");
goto end;
}
first_exe = dir_list[0];
first_exe = dir_list->elems[0].data;
if(first_exe)
{
@ -113,21 +112,13 @@ const char *rarch_manage_libretro_set_first_file(const char *libretro_path, cons
}
}
// FIXME: Broken, returns a pointer to data on the stack.
retstr = fname_tmp;
strlcpy(first_file, fname_tmp, size_of_first_file);
#else
// FIXME: Broken, returns a pointer to dynamically allocated data
// which is freed before returning.
retstr = first_exe;
strlcpy(first_file, first_exe, size_of_first_file);
#endif
RARCH_LOG("Set first entry in libretro core dir to libretro path: [%s].\n", retstr);
goto end;
RARCH_LOG("Set first entry in libretro core dir to libretro path: [%s].\n", first_file);
}
// TODO: Should not use two layers of goto labels.
error:
RARCH_ERR("Failed to set first entry to libretro path.\n");
end:
dir_list_free(dir_list);
return retstr;
}

View File

@ -28,6 +28,6 @@ enum
};
const char *rarch_manage_libretro_install(const char *full_path, const char *path, const char *exe_ext);
const char *rarch_manage_libretro_set_first_file(const char *libretro_path, const char * exe_ext);
void rarch_manage_libretro_set_first_file(char *first_file, size_t size_of_first_file, const char *libretro_path, const char * exe_ext);
#endif

View File

@ -302,7 +302,7 @@ static void browser_update(filebrowser_t * b, const char *extensions)
static void browser_render(filebrowser_t * b)
{
gl_t *gl = driver.video_data;
uint32_t file_count = b->current_dir.size;
uint32_t file_count = b->current_dir.list->size;
int current_index, page_number, page_base, i;
float currentX, currentY, ySpacing;
@ -317,7 +317,7 @@ static void browser_render(filebrowser_t * b)
for ( i = page_base; i < file_count && i < page_base + NUM_ENTRY_PER_PAGE; ++i)
{
char fname_tmp[256];
fill_pathname_base(fname_tmp, b->current_dir.elems[i], sizeof(fname_tmp));
fill_pathname_base(fname_tmp, b->current_dir.list->elems[i].data, sizeof(fname_tmp));
currentY = currentY + ySpacing;
cellDbgFontPuts(currentX, currentY, FONT_SIZE, i == current_index ? RED : WHITE, fname_tmp);
gl_render_msg_post(gl);
@ -859,7 +859,7 @@ static void select_file(uint32_t menu_id)
if (CTRL_CROSS(button_was_pressed))
{
if(path_is_directory(filebrowser_get_current_path(&tmpBrowser)))
if(filebrowser_get_current_path_isdir(&tmpBrowser))
{
/*if 'filename' is in fact '..' - then pop back directory instead of
adding '..' to filename path */
@ -952,7 +952,7 @@ static void select_directory(uint32_t menu_id)
if (CTRL_SQUARE(button_was_pressed))
{
if(path_is_directory(filebrowser_get_current_path(&tmpBrowser)))
if(filebrowser_get_current_path_isdir(&tmpBrowser))
{
snprintf(path, sizeof(path), filebrowser_get_current_path(&tmpBrowser));
switch(menu_id)
@ -995,7 +995,7 @@ static void select_directory(uint32_t menu_id)
}
else if (CTRL_CROSS(button_was_pressed))
{
if(path_is_directory(filebrowser_get_current_path(&tmpBrowser)))
if(filebrowser_get_current_path_isdir(&tmpBrowser))
{
/* if 'filename' is in fact '..' - then pop back directory instead of
* adding '..' to filename path */
@ -1886,7 +1886,7 @@ static void menu_romselect_iterate(filebrowser_t *filebrowser, menu_romselect_ac
switch(action)
{
case MENU_ROMSELECT_ACTION_OK:
if(path_is_directory(filebrowser_get_current_path(filebrowser)))
if(filebrowser_get_current_path_isdir(filebrowser))
{
/*if 'filename' is in fact '..' - then pop back directory instead of adding '..' to filename path */
if(browser.current_dir.ptr == 0)
@ -1942,7 +1942,7 @@ static void select_rom(void)
menu_romselect_iterate(&browser, action);
}
if (path_is_directory(filebrowser_get_current_path(&browser)))
if (filebrowser_get_current_path_isdir(&browser))
{
if(!strcmp(filebrowser_get_current_path(&browser),"app_home") || !strcmp(filebrowser_get_current_path(&browser),"host_root"))
cellDbgFontPrintf(0.09f, 0.83f, 0.91f, RED, "WARNING - This path only works on DEX PS3 systems. Do not attempt to open\n this directory on CEX PS3 systems, or you might have to restart.");