Add core_info/rom_history extensions from Apple ports to mainline

This commit is contained in:
twinaphex 2014-04-26 21:41:47 +02:00
parent 9e865d22c9
commit 0ddc7d57fd
8 changed files with 123 additions and 161 deletions

View File

@ -21,7 +21,6 @@
#import <CoreFoundation/CoreFoundation.h>
#include "../../frontend/info/core_info.h"
#include "core_info_ext.h"
#include "setting_data.h"
#include "apple_export.h"

View File

@ -1,121 +0,0 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2013-2014 - Jason Fetters
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "core_info_ext.h"
static core_info_list_t* global_core_list = 0;
static char core_config_path[PATH_MAX];
void apple_core_info_set_core_path(const char* core_path)
{
if (global_core_list)
core_info_list_free(global_core_list);
global_core_list = core_path ? core_info_list_new(core_path) : 0;
if (!global_core_list)
RARCH_WARN("No cores were found at %s", core_path ? core_path : "(null");
}
void apple_core_info_set_config_path(const char* config_path)
{
if (!config_path || strlcpy(core_config_path, config_path, sizeof(core_config_path)) >= PATH_MAX)
*core_config_path = '\0';
}
core_info_list_t *apple_core_info_list_get(void)
{
if (!global_core_list)
RARCH_WARN("core_info_list_get() called before core_info_set_core_path()");
return global_core_list;
}
const core_info_t *apple_core_info_list_get_by_id(const char* core_id)
{
if (core_id)
{
const core_info_list_t* cores = apple_core_info_list_get();
for (int i = 0; i != cores->count; i ++)
if (cores->list[i].path && strcmp(core_id, cores->list[i].path) == 0)
return &cores->list[i];
}
return 0;
}
const char *apple_core_info_get_id(const core_info_t* info, char* buffer, size_t buffer_length)
{
if (!buffer || !buffer_length)
return "";
if (info && info->path && strlcpy(buffer, info->path, buffer_length) < buffer_length)
return buffer;
*buffer = 0;
return buffer;
}
const char *apple_core_info_get_custom_config(const char* core_id, char* buffer, size_t buffer_length)
{
if (!core_id || !buffer || !buffer_length)
return 0;
snprintf(buffer, buffer_length, "%s/%s", core_config_path, path_basename(core_id));
fill_pathname(buffer, buffer, ".cfg", buffer_length);
return buffer;
}
bool apple_core_info_has_custom_config(const char* core_id)
{
char path[PATH_MAX];
if (!core_id)
return false;
apple_core_info_get_custom_config(core_id, path, sizeof(path));
return path_file_exists(path);
}
// ROM HISTORY EXTENSIONS
const char* apple_rom_history_get_path(rom_history_t* history, uint32_t index)
{
const char *path, *core_path, *core_name;
rom_history_get_index(history, index, &path, &core_path, &core_name);
if (path)
return path;
return "";
}
const char *apple_rom_history_get_core_path(rom_history_t* history, uint32_t index)
{
const char *path, *core_path, *core_name;
rom_history_get_index(history, index, &path, &core_path, &core_name);
if (core_path)
return core_path;
return "";
}
const char *apple_rom_history_get_core_name(rom_history_t* history, uint32_t index)
{
const char *path, *core_path, *core_name;
rom_history_get_index(history, index, &path, &core_path, &core_name);
if (core_name)
return core_name;
return "";
}

View File

@ -1,38 +0,0 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2013-2014 - Jason Fetters
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __APPLE_RARCH_CORE_INFO_EXT_H__
#define __APPLE_RARCH_CORE_INFO_EXT_H__
#include "../../frontend/info/core_info.h"
#include "../../frontend/menu/history.h"
void apple_core_info_set_core_path(const char* core_path);
void apple_core_info_set_config_path(const char* config_path);
core_info_list_t* apple_core_info_list_get(void);
const core_info_t* apple_core_info_list_get_by_id(const char* core_id);
const char* apple_core_info_get_id(const core_info_t* info, char* buffer, size_t buffer_length);
const char* apple_core_info_get_custom_config(const char* core_id, char* buffer, size_t buffer_length);
bool apple_core_info_has_custom_config(const char* core_id);
// ROM HISTORY EXTENSIONS
const char* apple_rom_history_get_path(rom_history_t* history, uint32_t index);
const char* apple_rom_history_get_core_path(rom_history_t* history, uint32_t index);
const char* apple_rom_history_get_core_name(rom_history_t* history, uint32_t index);
#endif

View File

@ -24,6 +24,9 @@
#include "../../config.h"
#endif
static core_info_list_t* global_core_list = 0;
static char core_config_path[PATH_MAX];
static void core_info_list_resolve_all_extensions(core_info_list_t *core_info_list)
{
size_t i, all_ext_len = 0;
@ -402,3 +405,73 @@ void core_info_list_get_missing_firmware(core_info_list_t *core_info_list,
qsort(info->firmware, info->firmware_count, sizeof(*info->firmware), core_info_firmware_cmp);
}
void core_info_set_core_path(const char* core_path)
{
if (global_core_list)
core_info_list_free(global_core_list);
global_core_list = core_path ? core_info_list_new(core_path) : 0;
if (!global_core_list)
RARCH_WARN("No cores were found at %s", core_path ? core_path : "(null");
}
void core_info_set_config_path(const char* config_path)
{
if (!config_path || strlcpy(core_config_path, config_path, sizeof(core_config_path)) >= PATH_MAX)
*core_config_path = '\0';
}
core_info_list_t *core_info_list_get(void)
{
if (!global_core_list)
RARCH_WARN("core_info_list_get() called before core_info_set_core_path()");
return global_core_list;
}
const core_info_t *core_info_list_get_by_id(const char* core_id)
{
int i;
const core_info_list_t* cores = (const core_info_list_t*)core_info_list_get();
if (core_id)
for (i = 0; i < cores->count; i ++)
if (cores->list[i].path && strcmp(core_id, cores->list[i].path) == 0)
return &cores->list[i];
return 0;
}
const char *core_info_get_id(const core_info_t* info, char* buffer, size_t buffer_length)
{
if (!buffer || !buffer_length)
return "";
if (info && info->path && strlcpy(buffer, info->path, buffer_length) < buffer_length)
return buffer;
*buffer = 0;
return buffer;
}
const char *core_info_get_custom_config(const char* core_id, char* buffer, size_t buffer_length)
{
if (!core_id || !buffer || !buffer_length)
return 0;
snprintf(buffer, buffer_length, "%s/%s", core_config_path, path_basename(core_id));
fill_pathname(buffer, buffer, ".cfg", buffer_length);
return buffer;
}
bool core_info_has_custom_config(const char* core_id)
{
char path[PATH_MAX];
if (!core_id)
return false;
core_info_get_custom_config(core_id, path, sizeof(path));
return path_file_exists(path);
}

View File

@ -1,5 +1,7 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2014 - Daniel De Matteis
* Copyright (C) 2013-2014 - Jason Fetters
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
@ -84,6 +86,16 @@ const char *core_info_list_get_all_extensions(core_info_list_t *core_info_list);
bool core_info_list_get_display_name(core_info_list_t *core_info_list, const char *path, char *buf, size_t size);
void core_info_set_core_path(const char* core_path);
void core_info_set_config_path(const char* config_path);
core_info_list_t* core_info_list_get(void);
const core_info_t* core_info_list_get_by_id(const char* core_id);
const char* core_info_get_id(const core_info_t* info, char* buffer, size_t buffer_length);
const char* core_info_get_custom_config(const char* core_id, char* buffer, size_t buffer_length);
bool core_info_has_custom_config(const char* core_id);
#ifdef __cplusplus
}
#endif

View File

@ -1,5 +1,7 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2014 - Daniel De Matteis
* Copyright (C) 2013-2014 - Jason Fetters
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
@ -211,3 +213,32 @@ error:
return NULL;
}
const char* rom_history_get_path(rom_history_t* history, unsigned index)
{
const char *path, *core_path, *core_name;
rom_history_get_index(history, index, &path, &core_path, &core_name);
if (path)
return path;
return "";
}
const char *rom_history_get_core_path(rom_history_t* history, unsigned index)
{
const char *path, *core_path, *core_name;
rom_history_get_index(history, index, &path, &core_path, &core_name);
if (core_path)
return core_path;
return "";
}
const char *rom_history_get_core_name(rom_history_t* history, unsigned index)
{
const char *path, *core_path, *core_name;
rom_history_get_index(history, index, &path, &core_path, &core_name);
if (core_name)
return core_name;
return "";
}

View File

@ -40,6 +40,13 @@ void rom_history_push(rom_history_t *hist,
const char *path, const char *core_path,
const char *core_name);
const char* rom_history_get_path(rom_history_t* history,
unsigned index);
const char* rom_history_get_core_path(rom_history_t* history,
unsigned index);
const char* rom_history_get_core_name(rom_history_t* history,
unsigned index);
#ifdef __cplusplus
}
#endif

View File

@ -660,7 +660,6 @@ XML
#if defined(IOS) || defined(OSX)
#include "../apple/common/setting_data.c"
#include "../apple/common/core_info_ext.c"
#endif
#ifdef __cplusplus