2016-01-25 03:32:52 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2017-01-22 12:40:32 +00:00
|
|
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
2016-01-25 03:32:52 +00:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2016-09-05 22:56:00 +00:00
|
|
|
#include <compat/strl.h>
|
2016-01-25 04:38:22 +00:00
|
|
|
#include <retro_assert.h>
|
2016-03-20 15:29:14 +00:00
|
|
|
#include <streams/file_stream.h>
|
2016-01-25 03:44:54 +00:00
|
|
|
#include <file/file_path.h>
|
2016-05-06 03:38:04 +00:00
|
|
|
#include <retro_stat.h>
|
2016-01-25 04:43:27 +00:00
|
|
|
#include <string/stdstring.h>
|
2016-01-25 03:44:54 +00:00
|
|
|
|
2016-09-15 23:23:25 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "../config.h"
|
|
|
|
#endif
|
|
|
|
|
2016-01-25 03:32:52 +00:00
|
|
|
#include "menu_content.h"
|
2016-01-25 03:44:54 +00:00
|
|
|
#include "menu_driver.h"
|
|
|
|
#include "menu_display.h"
|
|
|
|
#include "menu_shader.h"
|
|
|
|
|
2016-01-25 04:38:22 +00:00
|
|
|
#include "../core_info.h"
|
2016-01-25 03:44:54 +00:00
|
|
|
#include "../configuration.h"
|
|
|
|
#include "../defaults.h"
|
|
|
|
#include "../playlist.h"
|
|
|
|
#include "../verbosity.h"
|
|
|
|
|
2016-01-25 04:43:27 +00:00
|
|
|
/**
|
2016-02-04 14:00:38 +00:00
|
|
|
* menu_content_load_from_playlist:
|
2016-01-25 04:43:27 +00:00
|
|
|
* @playlist : Playlist handle.
|
|
|
|
* @idx : Index in playlist.
|
|
|
|
*
|
|
|
|
* Initializes core and loads content based on playlist entry.
|
|
|
|
**/
|
2016-07-01 13:55:36 +00:00
|
|
|
bool menu_content_playlist_load(menu_content_ctx_playlist_info_t *info)
|
2016-01-25 04:43:27 +00:00
|
|
|
{
|
2016-12-04 03:42:01 +00:00
|
|
|
const char *path = NULL;
|
|
|
|
playlist_t *playlist = (playlist_t*)info->data;
|
2016-01-25 04:43:27 +00:00
|
|
|
|
|
|
|
if (!playlist)
|
2016-02-04 14:00:38 +00:00
|
|
|
return false;
|
2016-01-25 04:43:27 +00:00
|
|
|
|
2016-05-16 07:07:44 +00:00
|
|
|
playlist_get_index(playlist,
|
2016-06-30 16:25:19 +00:00
|
|
|
info->idx, &path, NULL, NULL, NULL, NULL, NULL);
|
2016-01-25 04:43:27 +00:00
|
|
|
|
2016-12-15 11:18:26 +00:00
|
|
|
if (string_is_empty(path))
|
|
|
|
return false;
|
|
|
|
|
2016-01-25 04:43:27 +00:00
|
|
|
{
|
|
|
|
unsigned i;
|
2016-05-06 03:38:04 +00:00
|
|
|
bool valid_path = false;
|
2016-01-25 04:43:27 +00:00
|
|
|
char *path_check = NULL;
|
|
|
|
char *path_tolower = strdup(path);
|
|
|
|
|
|
|
|
for (i = 0; i < strlen(path_tolower); ++i)
|
|
|
|
path_tolower[i] = tolower(path_tolower[i]);
|
|
|
|
|
2016-07-01 03:53:55 +00:00
|
|
|
if (strstr(path_tolower, file_path_str(FILE_PATH_ZIP_EXTENSION)))
|
|
|
|
strstr(path_tolower, file_path_str(FILE_PATH_ZIP_EXTENSION))[4] = '\0';
|
|
|
|
else if (strstr(path_tolower, file_path_str(FILE_PATH_7Z_EXTENSION)))
|
|
|
|
strstr(path_tolower, file_path_str(FILE_PATH_7Z_EXTENSION))[3] = '\0';
|
2016-01-25 04:43:27 +00:00
|
|
|
|
2016-02-15 05:53:22 +00:00
|
|
|
path_check = (char *)
|
|
|
|
calloc(strlen(path_tolower) + 1, sizeof(char));
|
|
|
|
|
2016-01-25 04:43:27 +00:00
|
|
|
strncpy(path_check, path, strlen(path_tolower));
|
|
|
|
|
2016-05-06 03:38:04 +00:00
|
|
|
valid_path = path_is_valid(path_check);
|
2016-02-04 14:29:37 +00:00
|
|
|
|
2016-05-06 03:38:04 +00:00
|
|
|
free(path_tolower);
|
2016-02-04 14:29:37 +00:00
|
|
|
free(path_check);
|
|
|
|
|
2016-05-06 03:38:04 +00:00
|
|
|
if (!valid_path)
|
2016-12-15 11:18:26 +00:00
|
|
|
return false;
|
2016-01-25 04:43:27 +00:00
|
|
|
}
|
|
|
|
|
2016-06-30 16:25:19 +00:00
|
|
|
return true;
|
2016-01-25 04:43:27 +00:00
|
|
|
}
|
|
|
|
|
2016-07-01 13:55:36 +00:00
|
|
|
bool menu_content_playlist_find_associated_core(const char *path, char *s, size_t len)
|
|
|
|
{
|
|
|
|
unsigned j;
|
2016-12-04 03:42:01 +00:00
|
|
|
bool ret = false;
|
|
|
|
settings_t *settings = config_get_ptr();
|
2016-07-01 13:55:36 +00:00
|
|
|
struct string_list *existing_core_names =
|
2017-04-28 20:59:13 +00:00
|
|
|
string_split(settings->arrays.playlist_names, ";");
|
2016-07-01 13:55:36 +00:00
|
|
|
struct string_list *existing_core_paths =
|
2017-04-28 20:59:13 +00:00
|
|
|
string_split(settings->arrays.playlist_cores, ";");
|
2016-07-01 13:55:36 +00:00
|
|
|
|
|
|
|
for (j = 0; j < existing_core_names->size; j++)
|
|
|
|
{
|
2016-12-15 11:18:26 +00:00
|
|
|
if (!string_is_equal(path, existing_core_names->elems[j].data))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (existing_core_paths)
|
2016-07-01 13:55:36 +00:00
|
|
|
{
|
2016-12-15 11:18:26 +00:00
|
|
|
const char *existing_core = existing_core_paths->elems[j].data;
|
2016-07-01 13:55:36 +00:00
|
|
|
|
2016-12-15 11:18:26 +00:00
|
|
|
if (existing_core)
|
|
|
|
{
|
|
|
|
strlcpy(s, existing_core, len);
|
|
|
|
ret = true;
|
2016-07-01 13:55:36 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-15 11:18:26 +00:00
|
|
|
|
|
|
|
break;
|
2016-07-01 13:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
string_list_free(existing_core_names);
|
|
|
|
string_list_free(existing_core_paths);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-01-25 04:38:22 +00:00
|
|
|
/**
|
2016-02-04 14:46:24 +00:00
|
|
|
* menu_content_find_first_core:
|
2016-01-25 04:38:22 +00:00
|
|
|
* @core_info : Core info list handle.
|
|
|
|
* @dir : Directory. Gets joined with @path.
|
|
|
|
* @path : Path. Gets joined with @dir.
|
|
|
|
* @menu_label : Label identifier of menu setting.
|
|
|
|
* @s : Deferred core path. Will be filled in
|
|
|
|
* by function.
|
|
|
|
* @len : Size of @s.
|
|
|
|
*
|
|
|
|
* Gets deferred core.
|
|
|
|
*
|
2016-02-04 14:46:52 +00:00
|
|
|
* Returns: false if there are multiple deferred cores and a
|
2016-01-25 04:38:22 +00:00
|
|
|
* selection needs to be made from a list, otherwise
|
2016-02-04 14:46:52 +00:00
|
|
|
* returns true and fills in @s with path to core.
|
2016-01-25 04:38:22 +00:00
|
|
|
**/
|
2016-06-15 16:55:20 +00:00
|
|
|
bool menu_content_find_first_core(menu_content_ctx_defer_info_t *def_info,
|
|
|
|
bool load_content_with_current_core,
|
2016-06-15 16:52:27 +00:00
|
|
|
char *new_core_path, size_t len)
|
2016-01-25 04:38:22 +00:00
|
|
|
{
|
2016-02-04 14:21:42 +00:00
|
|
|
const core_info_t *info = NULL;
|
|
|
|
size_t supported = 0;
|
2016-12-15 11:18:26 +00:00
|
|
|
core_info_list_t *core_info = (core_info_list_t*)def_info->data;
|
|
|
|
const char *default_info_dir = def_info->dir;
|
2016-01-25 04:38:22 +00:00
|
|
|
|
2016-05-27 02:41:39 +00:00
|
|
|
if (!string_is_empty(default_info_dir))
|
|
|
|
{
|
2017-02-21 20:20:33 +00:00
|
|
|
const char *default_info_path = def_info->path;
|
|
|
|
size_t default_info_length = def_info->len;
|
2016-05-27 02:41:39 +00:00
|
|
|
|
|
|
|
if (!string_is_empty(default_info_path))
|
|
|
|
fill_pathname_join(def_info->s,
|
|
|
|
default_info_dir, default_info_path,
|
|
|
|
default_info_length);
|
2016-01-25 04:38:22 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_COMPRESSION
|
2016-05-27 02:41:39 +00:00
|
|
|
if (path_is_compressed_file(default_info_dir))
|
|
|
|
{
|
|
|
|
size_t len = strlen(default_info_dir);
|
|
|
|
/* In case of a compressed archive, we have to join with a hash */
|
|
|
|
/* We are going to write at the position of dir: */
|
|
|
|
retro_assert(len < strlen(def_info->s));
|
|
|
|
def_info->s[len] = '#';
|
|
|
|
}
|
2016-01-25 04:38:22 +00:00
|
|
|
#endif
|
2016-05-27 02:41:39 +00:00
|
|
|
}
|
2016-01-25 04:38:22 +00:00
|
|
|
|
|
|
|
if (core_info)
|
2016-02-04 14:21:42 +00:00
|
|
|
core_info_list_get_supported_cores(core_info,
|
|
|
|
def_info->s, &info,
|
2016-01-25 04:38:22 +00:00
|
|
|
&supported);
|
|
|
|
|
|
|
|
/* We started the menu with 'Load Content', we are
|
|
|
|
* going to use the current core to load this. */
|
2016-06-14 20:11:10 +00:00
|
|
|
if (load_content_with_current_core)
|
2016-01-25 04:38:22 +00:00
|
|
|
{
|
2016-05-10 01:19:40 +00:00
|
|
|
core_info_get_current_core((core_info_t**)&info);
|
2016-01-25 04:38:22 +00:00
|
|
|
if (info)
|
|
|
|
{
|
2016-02-04 20:20:28 +00:00
|
|
|
RARCH_LOG("Use the current core (%s) to load this content...\n",
|
|
|
|
info->path);
|
2016-01-25 04:38:22 +00:00
|
|
|
supported = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* There are multiple deferred cores and a
|
|
|
|
* selection needs to be made from a list, return 0. */
|
|
|
|
if (supported != 1)
|
2016-02-04 14:21:42 +00:00
|
|
|
return false;
|
2016-01-25 04:38:22 +00:00
|
|
|
|
|
|
|
if (info)
|
2016-06-15 16:52:27 +00:00
|
|
|
strlcpy(new_core_path, info->path, len);
|
2016-01-25 04:38:22 +00:00
|
|
|
|
2016-02-04 14:21:42 +00:00
|
|
|
return true;
|
2016-01-25 04:38:22 +00:00
|
|
|
}
|