2017-01-22 23:39:07 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2017-02-15 23:25:21 +00:00
|
|
|
* Copyright (C) 2017 - Jean-André Santoni
|
|
|
|
* Copyright (C) 2017 - Andrés Suárez
|
2017-01-22 23:39:07 +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 <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <file/nbio.h>
|
|
|
|
#include <formats/image.h>
|
|
|
|
#include <compat/strl.h>
|
|
|
|
#include <retro_assert.h>
|
|
|
|
#include <retro_miscellaneous.h>
|
|
|
|
#include <lists/string_list.h>
|
|
|
|
#include <rhash.h>
|
|
|
|
#include <string/stdstring.h>
|
|
|
|
#include <file/file_path.h>
|
|
|
|
#include <lists/dir_list.h>
|
|
|
|
|
|
|
|
#include "tasks_internal.h"
|
|
|
|
#include "../file_path_special.h"
|
|
|
|
#include "../verbosity.h"
|
|
|
|
#include "../configuration.h"
|
|
|
|
#include "../playlist.h"
|
|
|
|
#include "../command.h"
|
|
|
|
#include "../core_info.h"
|
2017-01-23 03:45:48 +00:00
|
|
|
#include "../../runloop.h"
|
2017-01-22 23:39:07 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
struct string_list *lpl_list;
|
2017-01-24 23:39:17 +00:00
|
|
|
char content_crc[PATH_MAX_LENGTH];
|
|
|
|
char content_path[PATH_MAX_LENGTH];
|
2017-01-22 23:39:07 +00:00
|
|
|
char hostname[512];
|
2017-01-24 23:39:17 +00:00
|
|
|
char core_name[PATH_MAX_LENGTH];
|
|
|
|
char core_path[PATH_MAX_LENGTH];
|
|
|
|
char core_extensions[PATH_MAX_LENGTH];
|
2017-01-22 23:39:07 +00:00
|
|
|
bool found;
|
|
|
|
} netplay_crc_handle_t;
|
|
|
|
|
|
|
|
static void netplay_crc_scan_callback(void *task_data,
|
|
|
|
void *user_data, const char *error)
|
|
|
|
{
|
|
|
|
netplay_crc_handle_t *state = (netplay_crc_handle_t*)task_data;
|
|
|
|
content_ctx_info_t content_info = {0};
|
|
|
|
|
|
|
|
if (!state)
|
|
|
|
return;
|
|
|
|
|
2017-01-29 03:12:34 +00:00
|
|
|
fflush(stdout);
|
2017-02-10 02:10:40 +00:00
|
|
|
if (!string_is_empty(state->core_path) && !string_is_empty(state->content_path) &&
|
|
|
|
!string_is_equal(state->content_path, "N/A"))
|
2017-01-23 03:45:48 +00:00
|
|
|
{
|
|
|
|
command_event(CMD_EVENT_NETPLAY_INIT_DIRECT_DEFERRED, state->hostname);
|
2017-02-21 03:31:03 +00:00
|
|
|
task_push_content_load_content_with_new_core_from_menu(
|
2017-01-24 23:39:17 +00:00
|
|
|
state->core_path, state->content_path,
|
2017-01-23 03:45:48 +00:00
|
|
|
&content_info,
|
|
|
|
CORE_TYPE_PLAIN,
|
|
|
|
NULL, NULL);
|
|
|
|
}
|
2017-02-10 02:10:40 +00:00
|
|
|
else if (!string_is_empty(state->core_path) && !string_is_empty(state->content_path) &&
|
|
|
|
string_is_equal(state->content_path, "N/A"))
|
2017-01-29 03:12:34 +00:00
|
|
|
{
|
2017-02-21 02:54:34 +00:00
|
|
|
content_ctx_info_t content_info = {0};
|
|
|
|
|
2017-02-10 02:22:52 +00:00
|
|
|
command_event(CMD_EVENT_NETPLAY_INIT_DIRECT_DEFERRED, state->hostname);
|
2017-02-21 03:07:40 +00:00
|
|
|
task_push_content_load_nothing_with_new_core_from_menu(
|
2017-01-29 03:12:34 +00:00
|
|
|
state->core_path, NULL,
|
2017-02-10 02:10:40 +00:00
|
|
|
&content_info,
|
2017-01-29 03:12:34 +00:00
|
|
|
CORE_TYPE_PLAIN,
|
|
|
|
NULL, NULL);
|
2017-02-21 02:54:34 +00:00
|
|
|
|
|
|
|
task_push_content_load_nothing_with_current_core_from_menu(&content_info);
|
2017-01-29 03:12:34 +00:00
|
|
|
}
|
2017-01-23 03:45:48 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* TO-DO: Inform the user no compatible core or content was found */
|
|
|
|
RARCH_LOG("Couldn't find a suitable %s\n",
|
2017-01-24 23:39:17 +00:00
|
|
|
string_is_empty(state->content_path) ? "content file" : "core");
|
2017-01-23 03:45:48 +00:00
|
|
|
runloop_msg_queue_push(
|
|
|
|
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_LOAD_CONTENT_MANUALLY),
|
|
|
|
1, 480, true);
|
|
|
|
}
|
2017-01-23 02:56:06 +00:00
|
|
|
|
2017-01-22 23:39:07 +00:00
|
|
|
|
|
|
|
free(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void task_netplay_crc_scan_handler(retro_task_t *task)
|
|
|
|
{
|
|
|
|
size_t i, j;
|
|
|
|
netplay_crc_handle_t *state = (netplay_crc_handle_t*)task->state;
|
|
|
|
|
|
|
|
task_set_progress(task, 0);
|
|
|
|
task_set_title(task, strdup("Looking for compatible content..."));
|
|
|
|
task_set_finished(task, false);
|
|
|
|
|
|
|
|
if (!state->lpl_list)
|
|
|
|
{
|
|
|
|
task_set_progress(task, 100);
|
|
|
|
task_set_title(task, strdup("Playlist directory not found"));
|
|
|
|
task_set_finished(task, true);
|
|
|
|
free(state);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-19 16:58:09 +00:00
|
|
|
if (state->lpl_list->size == 0 &&
|
|
|
|
!string_is_equal(state->content_path, "N/A"))
|
2017-01-22 23:39:07 +00:00
|
|
|
goto no_playlists;
|
2017-01-29 03:12:34 +00:00
|
|
|
|
2017-02-02 19:11:20 +00:00
|
|
|
/* Lobby reports content CRC, try to use CRC matching
|
|
|
|
content with no CRC uses 00000000 */
|
2017-01-24 23:39:17 +00:00
|
|
|
if (!string_is_equal(state->content_crc, "00000000|crc"))
|
2017-01-22 23:39:07 +00:00
|
|
|
{
|
2017-02-02 19:11:20 +00:00
|
|
|
|
2017-01-24 15:50:40 +00:00
|
|
|
RARCH_LOG("Using CRC matching\n");
|
|
|
|
|
2017-01-22 23:39:07 +00:00
|
|
|
for (i = 0; i < state->lpl_list->size; i++)
|
|
|
|
{
|
|
|
|
playlist_t *playlist = NULL;
|
|
|
|
const char *lpl_path = state->lpl_list->elems[i].data;
|
|
|
|
|
|
|
|
if (!strstr(lpl_path, file_path_str(FILE_PATH_LPL_EXTENSION)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
playlist = playlist_init(lpl_path, 99999);
|
2017-01-23 23:48:40 +00:00
|
|
|
|
|
|
|
for (j = 0; j < playlist->size; j++)
|
2017-01-22 23:39:07 +00:00
|
|
|
{
|
2017-01-24 23:45:26 +00:00
|
|
|
if (string_is_equal(playlist->entries[j].crc32, state->content_crc) &&
|
|
|
|
strstr(state->core_extensions, path_get_extension(playlist->entries[j].path)))
|
2017-01-22 23:39:07 +00:00
|
|
|
{
|
2017-01-24 15:50:40 +00:00
|
|
|
RARCH_LOG("CRC Match %s\n", playlist->entries[j].crc32);
|
2017-01-24 23:39:17 +00:00
|
|
|
strlcpy(state->content_path, playlist->entries[j].path, sizeof(state->content_path));
|
2017-01-23 23:48:40 +00:00
|
|
|
state->found = true;
|
|
|
|
task_set_data(task, state);
|
|
|
|
task_set_progress(task, 100);
|
2017-01-31 18:40:43 +00:00
|
|
|
task_set_title(task, strdup(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_COMPAT_CONTENT_FOUND)));
|
2017-01-23 23:48:40 +00:00
|
|
|
task_set_finished(task, true);
|
|
|
|
string_list_free(state->lpl_list);
|
|
|
|
free(playlist);
|
|
|
|
return;
|
2017-01-22 23:39:07 +00:00
|
|
|
}
|
2017-01-23 23:48:40 +00:00
|
|
|
|
|
|
|
task_set_progress(task, (int)(j/playlist->size*100.0));
|
2017-01-22 23:39:07 +00:00
|
|
|
}
|
2017-01-23 23:48:40 +00:00
|
|
|
|
|
|
|
free(playlist);
|
2017-01-22 23:39:07 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-02 19:11:20 +00:00
|
|
|
/* Lobby reports core doesn't need content */
|
2017-01-29 03:12:34 +00:00
|
|
|
else if(string_is_equal(state->content_path, "N/A"))
|
|
|
|
{
|
|
|
|
state->found = true;
|
|
|
|
task_set_data(task, state);
|
|
|
|
task_set_progress(task, 100);
|
2017-01-31 18:40:43 +00:00
|
|
|
task_set_title(task, strdup(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_COMPAT_CONTENT_FOUND)));
|
2017-01-29 03:12:34 +00:00
|
|
|
task_set_finished(task, true);
|
|
|
|
return;
|
|
|
|
}
|
2017-02-02 19:11:20 +00:00
|
|
|
/* Lobby reports that the core needs content but
|
|
|
|
the CRC wasn't reported */
|
2017-01-22 23:39:07 +00:00
|
|
|
else
|
|
|
|
{
|
2017-01-24 15:50:40 +00:00
|
|
|
RARCH_LOG("Using filename matching\n");
|
2017-01-22 23:39:07 +00:00
|
|
|
for (i = 0; i < state->lpl_list->size; i++)
|
|
|
|
{
|
|
|
|
playlist_t *playlist = NULL;
|
|
|
|
const char *lpl_path = state->lpl_list->elems[i].data;
|
|
|
|
|
|
|
|
if (!strstr(lpl_path, file_path_str(FILE_PATH_LPL_EXTENSION)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
playlist = playlist_init(lpl_path, 99999);
|
2017-01-23 23:48:40 +00:00
|
|
|
|
|
|
|
for (j = 0; j < playlist->size; j++)
|
2017-01-22 23:39:07 +00:00
|
|
|
{
|
2017-01-24 15:50:40 +00:00
|
|
|
char entry[PATH_MAX_LENGTH];
|
2017-01-24 02:21:26 +00:00
|
|
|
const char* buf = path_basename(playlist->entries[j].path);
|
2017-01-24 15:50:40 +00:00
|
|
|
|
|
|
|
entry[0] = '\0';
|
|
|
|
|
2017-01-24 15:56:22 +00:00
|
|
|
strlcpy(entry, buf, sizeof(entry));
|
|
|
|
|
2017-01-24 15:50:40 +00:00
|
|
|
path_remove_extension(entry);
|
|
|
|
|
|
|
|
if ( !string_is_empty(entry) &&
|
2017-01-24 23:45:26 +00:00
|
|
|
string_is_equal(entry, state->content_path) &&
|
|
|
|
strstr(state->core_extensions, path_get_extension(playlist->entries[j].path)))
|
2017-01-22 23:39:07 +00:00
|
|
|
{
|
2017-01-24 15:50:40 +00:00
|
|
|
RARCH_LOG("Filename match %s\n", playlist->entries[j].path);
|
|
|
|
|
2017-01-24 23:39:17 +00:00
|
|
|
strlcpy(state->content_path, playlist->entries[j].path, sizeof(state->content_path));
|
2017-01-23 23:48:40 +00:00
|
|
|
state->found = true;
|
|
|
|
task_set_data(task, state);
|
|
|
|
task_set_progress(task, 100);
|
2017-01-31 18:40:43 +00:00
|
|
|
task_set_title(task, strdup(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_COMPAT_CONTENT_FOUND)));
|
2017-01-23 23:48:40 +00:00
|
|
|
task_set_finished(task, true);
|
|
|
|
string_list_free(state->lpl_list);
|
|
|
|
free(playlist);
|
|
|
|
return;
|
2017-01-22 23:39:07 +00:00
|
|
|
}
|
2017-01-23 23:48:40 +00:00
|
|
|
|
|
|
|
task_set_progress(task, (int)(j/playlist->size*100.0));
|
2017-01-22 23:39:07 +00:00
|
|
|
}
|
2017-01-23 23:48:40 +00:00
|
|
|
|
|
|
|
free(playlist);
|
2017-01-22 23:39:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
no_playlists:
|
|
|
|
string_list_free(state->lpl_list);
|
|
|
|
task_set_progress(task, 100);
|
2017-02-02 19:32:01 +00:00
|
|
|
task_set_title(task, strdup("Content not found, try manual load or disconnect from host"));
|
2017-01-22 23:39:07 +00:00
|
|
|
task_set_finished(task, true);
|
2017-02-02 19:32:01 +00:00
|
|
|
command_event(CMD_EVENT_NETPLAY_INIT_DIRECT_DEFERRED, state->hostname);
|
2017-01-23 02:56:06 +00:00
|
|
|
free(state);
|
2017-01-22 23:39:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-22 23:57:50 +00:00
|
|
|
bool task_push_netplay_crc_scan(uint32_t crc, char* name,
|
2017-01-24 23:39:17 +00:00
|
|
|
const char *hostname, const char *core_name)
|
2017-01-22 23:39:07 +00:00
|
|
|
{
|
2017-01-24 23:35:57 +00:00
|
|
|
int i;
|
2017-01-25 01:00:44 +00:00
|
|
|
core_info_list_t *info = NULL;
|
2017-01-22 23:39:07 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
retro_task_t *task = (retro_task_t *)calloc(1, sizeof(*task));
|
|
|
|
netplay_crc_handle_t *state = (netplay_crc_handle_t*)calloc(1, sizeof(*state));
|
|
|
|
|
2017-01-25 01:00:44 +00:00
|
|
|
core_info_get_list(&info);
|
2017-01-24 23:35:57 +00:00
|
|
|
|
2017-01-22 23:39:07 +00:00
|
|
|
if (!task || !state)
|
|
|
|
goto error;
|
|
|
|
|
2017-01-25 01:00:44 +00:00
|
|
|
state->content_crc[0] = '\0';
|
2017-01-24 23:39:17 +00:00
|
|
|
state->content_path[0] = '\0';
|
2017-01-25 01:00:44 +00:00
|
|
|
state->hostname[0] = '\0';
|
|
|
|
state->core_name[0] = '\0';
|
2017-01-22 23:39:07 +00:00
|
|
|
|
2017-01-25 01:00:44 +00:00
|
|
|
snprintf(state->content_crc, sizeof(state->content_crc), "%08X|crc", crc);
|
2017-01-22 23:39:07 +00:00
|
|
|
|
2017-01-25 01:00:44 +00:00
|
|
|
strlcpy(state->content_path, name, sizeof(state->content_path));
|
|
|
|
strlcpy(state->hostname, hostname, sizeof(state->hostname));
|
|
|
|
strlcpy(state->core_name, core_name, sizeof(state->core_name));
|
2017-01-22 23:39:07 +00:00
|
|
|
|
|
|
|
state->lpl_list = dir_list_new(settings->directory.playlist,
|
|
|
|
NULL, true, true, true, false);
|
|
|
|
|
|
|
|
state->found = false;
|
|
|
|
|
2017-01-24 23:35:57 +00:00
|
|
|
for (i=0; i < info->count; i++)
|
|
|
|
{
|
|
|
|
/* check if the core name matches.
|
|
|
|
TO-DO :we could try to load the core too to check
|
|
|
|
if the version string matches too */
|
2017-01-29 03:12:34 +00:00
|
|
|
#if 0
|
|
|
|
printf("Info: %s State: %s", info->list[i].core_name, state->core_name);
|
|
|
|
#endif
|
2017-01-24 23:39:17 +00:00
|
|
|
if(string_is_equal(info->list[i].core_name, state->core_name))
|
2017-01-24 23:35:57 +00:00
|
|
|
{
|
2017-01-25 01:00:44 +00:00
|
|
|
strlcpy(state->core_path, info->list[i].path, sizeof(state->core_path));
|
2017-02-10 02:10:40 +00:00
|
|
|
|
2017-02-15 23:15:42 +00:00
|
|
|
if (!string_is_equal(state->content_path, "N/A") &&
|
|
|
|
!string_is_empty(info->list[i].supported_extensions))
|
2017-02-10 02:10:40 +00:00
|
|
|
{
|
|
|
|
strlcpy(state->core_extensions,
|
|
|
|
info->list[i].supported_extensions, sizeof(state->core_extensions));
|
|
|
|
}
|
2017-01-24 23:35:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-22 23:39:07 +00:00
|
|
|
/* blocking means no other task can run while this one is running,
|
|
|
|
* which is the default */
|
|
|
|
task->type = TASK_TYPE_BLOCKING;
|
|
|
|
task->state = state;
|
|
|
|
task->handler = task_netplay_crc_scan_handler;
|
|
|
|
task->callback = netplay_crc_scan_callback;
|
2017-01-23 13:15:26 +00:00
|
|
|
task->title = strdup("Looking for matching content...");
|
2017-01-22 23:39:07 +00:00
|
|
|
|
|
|
|
task_queue_ctl(TASK_QUEUE_CTL_PUSH, task);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
error:
|
|
|
|
if (state)
|
|
|
|
free(state);
|
|
|
|
if (task)
|
|
|
|
free(task);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|