2013-03-22 20:27:34 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 00:50:59 +00:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2017-01-22 12:40:32 +00:00
|
|
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
2013-03-22 20:27:34 +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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2014-10-21 03:05:52 +00:00
|
|
|
#include <boolean.h>
|
2013-03-22 20:27:34 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2014-10-22 01:52:23 +00:00
|
|
|
#include <file/config_file.h>
|
2014-10-21 22:23:06 +00:00
|
|
|
#include <file/file_path.h>
|
2016-03-20 13:53:54 +00:00
|
|
|
#include <lists/dir_list.h>
|
2015-11-29 00:57:16 +00:00
|
|
|
#include <retro_miscellaneous.h>
|
2016-01-02 00:38:02 +00:00
|
|
|
#include <string/stdstring.h>
|
2016-02-03 14:23:13 +00:00
|
|
|
#include <compat/strl.h>
|
2015-09-01 10:10:26 +00:00
|
|
|
|
2016-09-11 16:08:58 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "../config.h"
|
|
|
|
#endif
|
|
|
|
|
2015-01-12 20:21:08 +00:00
|
|
|
#include "frontend_driver.h"
|
2015-11-29 00:57:16 +00:00
|
|
|
#include "../defaults.h"
|
2015-11-23 11:03:38 +00:00
|
|
|
#include "../verbosity.h"
|
2013-11-15 16:42:43 +00:00
|
|
|
|
2014-06-12 16:06:29 +00:00
|
|
|
struct defaults g_defaults;
|
2013-03-22 20:27:34 +00:00
|
|
|
|
2014-08-20 14:26:34 +00:00
|
|
|
/*We need to set libretro to the first entry in the cores
|
|
|
|
* directory so that it will be saved to the config file
|
|
|
|
*/
|
2013-03-22 20:27:34 +00:00
|
|
|
static void find_first_libretro_core(char *first_file,
|
|
|
|
size_t size_of_first_file, const char *dir,
|
|
|
|
const char * ext)
|
|
|
|
{
|
2014-06-06 21:20:21 +00:00
|
|
|
size_t i;
|
2016-09-29 18:18:45 +00:00
|
|
|
bool ret = false;
|
2016-08-28 04:14:50 +00:00
|
|
|
struct string_list *list = dir_list_new(dir, ext, false, true, false, false);
|
2013-03-22 20:27:34 +00:00
|
|
|
|
|
|
|
if (!list)
|
|
|
|
{
|
2016-02-03 14:30:17 +00:00
|
|
|
RARCH_ERR("Couldn't read directory."
|
|
|
|
" Cannot infer default libretro core.\n");
|
2013-03-22 20:27:34 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-02-03 14:30:17 +00:00
|
|
|
|
|
|
|
RARCH_LOG("Searching for valid libretro implementation in: \"%s\".\n",
|
|
|
|
dir);
|
2017-12-12 07:55:31 +00:00
|
|
|
|
2014-06-06 21:20:21 +00:00
|
|
|
for (i = 0; i < list->size && !ret; i++)
|
2013-03-22 20:27:34 +00:00
|
|
|
{
|
2016-09-29 18:18:45 +00:00
|
|
|
char fname[PATH_MAX_LENGTH] = {0};
|
|
|
|
char salamander_name[PATH_MAX_LENGTH] = {0};
|
|
|
|
const char *libretro_elem = (const char*)list->elems[i].data;
|
2013-03-22 20:27:34 +00:00
|
|
|
|
2014-06-06 21:20:21 +00:00
|
|
|
RARCH_LOG("Checking library: \"%s\".\n", libretro_elem);
|
2013-03-22 20:27:34 +00:00
|
|
|
|
2014-06-06 21:20:21 +00:00
|
|
|
if (!libretro_elem)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
fill_pathname_base(fname, libretro_elem, sizeof(fname));
|
2013-03-22 20:27:34 +00:00
|
|
|
|
2016-02-03 14:30:17 +00:00
|
|
|
if (!frontend_driver_get_salamander_basename(
|
|
|
|
salamander_name, sizeof(salamander_name)))
|
2016-02-03 12:36:00 +00:00
|
|
|
break;
|
|
|
|
|
2016-10-04 08:29:32 +00:00
|
|
|
if (!strncmp(fname, salamander_name, sizeof(fname)))
|
2014-06-06 21:20:21 +00:00
|
|
|
{
|
2016-02-03 12:36:00 +00:00
|
|
|
if (list->size == (i + 1))
|
2014-06-06 21:20:21 +00:00
|
|
|
{
|
2016-02-03 14:30:17 +00:00
|
|
|
RARCH_WARN("Entry is RetroArch Salamander itself, "
|
|
|
|
"but is last entry. No choice but to set it.\n");
|
2014-06-06 21:20:21 +00:00
|
|
|
strlcpy(first_file, fname, size_of_first_file);
|
2013-03-22 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2014-06-06 21:20:21 +00:00
|
|
|
continue;
|
2013-03-22 20:27:34 +00:00
|
|
|
}
|
2014-06-06 21:20:21 +00:00
|
|
|
|
|
|
|
strlcpy(first_file, fname, size_of_first_file);
|
|
|
|
RARCH_LOG("First found libretro core is: \"%s\".\n", first_file);
|
|
|
|
ret = true;
|
2013-03-22 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dir_list_free(list);
|
|
|
|
}
|
|
|
|
|
2017-12-12 07:55:31 +00:00
|
|
|
/* Last fallback - we'll need to start the first executable file
|
2016-09-29 18:18:45 +00:00
|
|
|
* we can find in the RetroArch cores directory.
|
|
|
|
*/
|
2015-06-02 16:28:51 +00:00
|
|
|
static void find_and_set_first_file(char *s, size_t len,
|
2014-08-20 14:26:34 +00:00
|
|
|
const char *ext)
|
2014-06-04 22:51:47 +00:00
|
|
|
{
|
|
|
|
|
2015-01-09 17:04:29 +00:00
|
|
|
char first_file[PATH_MAX_LENGTH] = {0};
|
2014-06-04 22:51:47 +00:00
|
|
|
find_first_libretro_core(first_file, sizeof(first_file),
|
2017-05-23 17:43:58 +00:00
|
|
|
g_defaults.dirs[DEFAULT_DIR_CORE], ext);
|
2014-06-04 22:51:47 +00:00
|
|
|
|
2015-12-26 06:45:19 +00:00
|
|
|
if (string_is_empty(first_file))
|
2014-06-04 22:51:47 +00:00
|
|
|
{
|
|
|
|
RARCH_ERR("Failed last fallback - RetroArch Salamander will exit.\n");
|
2015-12-26 06:45:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-23 17:43:58 +00:00
|
|
|
fill_pathname_join(s, g_defaults.dirs[DEFAULT_DIR_CORE], first_file, len);
|
2015-12-26 06:45:19 +00:00
|
|
|
RARCH_LOG("libretro_path now set to: %s.\n", s);
|
2014-06-04 22:51:47 +00:00
|
|
|
}
|
|
|
|
|
2015-06-02 16:28:51 +00:00
|
|
|
static void salamander_init(char *s, size_t len)
|
2014-06-05 04:12:41 +00:00
|
|
|
{
|
2014-08-20 14:26:34 +00:00
|
|
|
/* normal executable loading path */
|
2016-09-18 19:57:51 +00:00
|
|
|
bool config_exists = config_file_exists(g_defaults.path.config);
|
2014-06-05 04:12:41 +00:00
|
|
|
|
2016-09-18 19:57:51 +00:00
|
|
|
if (config_exists)
|
2014-06-05 04:12:41 +00:00
|
|
|
{
|
2016-09-29 18:18:45 +00:00
|
|
|
char tmp_str[PATH_MAX_LENGTH] = {0};
|
|
|
|
config_file_t * conf = (config_file_t*)
|
|
|
|
config_file_new(g_defaults.path.config);
|
2014-06-05 04:12:41 +00:00
|
|
|
|
|
|
|
if (conf)
|
|
|
|
{
|
|
|
|
config_get_array(conf, "libretro_path", tmp_str, sizeof(tmp_str));
|
|
|
|
config_file_free(conf);
|
2016-07-31 19:24:16 +00:00
|
|
|
|
2017-04-23 10:17:51 +00:00
|
|
|
if (memcmp(tmp_str, "builtin", 7) != 0)
|
2016-07-31 19:24:16 +00:00
|
|
|
strlcpy(s, tmp_str, len);
|
2014-06-05 04:12:41 +00:00
|
|
|
}
|
|
|
|
#ifdef GEKKO
|
2017-12-12 07:55:31 +00:00
|
|
|
/* stupid libfat bug or something; sometimes it says
|
2016-02-03 14:30:17 +00:00
|
|
|
* the file is there when it doesn't. */
|
2017-12-12 07:55:31 +00:00
|
|
|
else
|
2016-02-03 14:30:17 +00:00
|
|
|
{
|
2016-09-18 19:57:51 +00:00
|
|
|
config_exists = false;
|
2016-02-03 14:30:17 +00:00
|
|
|
}
|
2014-06-05 04:12:41 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-09-18 19:57:51 +00:00
|
|
|
if (!config_exists || string_is_equal(s, ""))
|
2016-02-03 14:23:13 +00:00
|
|
|
{
|
2016-09-29 18:18:45 +00:00
|
|
|
char executable_name[PATH_MAX_LENGTH] = {0};
|
2016-02-03 14:23:13 +00:00
|
|
|
|
2016-02-03 14:30:17 +00:00
|
|
|
frontend_driver_get_core_extension(
|
|
|
|
executable_name, sizeof(executable_name));
|
2016-02-03 14:23:13 +00:00
|
|
|
find_and_set_first_file(s, len, executable_name);
|
|
|
|
}
|
2014-06-05 04:12:41 +00:00
|
|
|
else
|
2015-06-07 22:33:49 +00:00
|
|
|
RARCH_LOG("Start [%s] found in retroarch.cfg.\n", s);
|
2014-06-05 04:12:41 +00:00
|
|
|
|
2016-09-18 19:57:51 +00:00
|
|
|
if (!config_exists)
|
2014-06-05 04:12:41 +00:00
|
|
|
{
|
2014-06-06 21:20:21 +00:00
|
|
|
config_file_t *conf = (config_file_t*)config_file_new(NULL);
|
2014-06-05 04:12:41 +00:00
|
|
|
|
|
|
|
if (conf)
|
|
|
|
{
|
2015-06-07 22:33:49 +00:00
|
|
|
config_set_string(conf, "libretro_path", s);
|
2015-07-27 15:18:10 +00:00
|
|
|
config_file_write(conf, g_defaults.path.config);
|
2014-06-05 04:12:41 +00:00
|
|
|
config_file_free(conf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-01-25 18:52:31 +00:00
|
|
|
#ifdef HAVE_MAIN
|
|
|
|
int salamander_main(int argc, char *argv[])
|
|
|
|
#else
|
2013-03-22 20:27:34 +00:00
|
|
|
int main(int argc, char *argv[])
|
2017-01-25 18:52:31 +00:00
|
|
|
#endif
|
2013-03-22 20:27:34 +00:00
|
|
|
{
|
2016-09-29 18:18:45 +00:00
|
|
|
char libretro_path[PATH_MAX_LENGTH] = {0};
|
|
|
|
void *args = NULL;
|
|
|
|
struct rarch_main_wrap *wrap_args = NULL;
|
|
|
|
frontend_ctx_driver_t *frontend_ctx = (frontend_ctx_driver_t*)frontend_ctx_init_first();
|
2013-11-15 16:42:43 +00:00
|
|
|
|
|
|
|
if (!frontend_ctx)
|
2013-07-26 18:58:47 +00:00
|
|
|
return 0;
|
|
|
|
|
2013-11-15 04:02:39 +00:00
|
|
|
if (frontend_ctx && frontend_ctx->init)
|
|
|
|
frontend_ctx->init(args);
|
2014-02-24 17:23:12 +00:00
|
|
|
|
|
|
|
if (frontend_ctx && frontend_ctx->environment_get)
|
2014-06-03 01:35:12 +00:00
|
|
|
frontend_ctx->environment_get(&argc, argv, args, wrap_args);
|
2014-02-24 17:23:12 +00:00
|
|
|
|
2014-06-05 04:12:41 +00:00
|
|
|
salamander_init(libretro_path, sizeof(libretro_path));
|
2013-11-15 04:02:39 +00:00
|
|
|
|
|
|
|
if (frontend_ctx && frontend_ctx->deinit)
|
|
|
|
frontend_ctx->deinit(args);
|
2014-02-24 17:23:12 +00:00
|
|
|
|
2013-11-15 04:02:39 +00:00
|
|
|
if (frontend_ctx && frontend_ctx->exitspawn)
|
2014-06-05 04:12:41 +00:00
|
|
|
frontend_ctx->exitspawn(libretro_path, sizeof(libretro_path));
|
2013-03-22 20:27:34 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|