mirror of
https://github.com/libretro/RetroArch.git
synced 2024-11-23 16:09:47 +00:00
add name matching
This commit is contained in:
parent
45514e60a7
commit
3306f5274a
@ -1166,7 +1166,7 @@ ifeq ($(HAVE_NETWORKING), 1)
|
||||
tasks/task_http.o \
|
||||
tasks/task_netplay_lan_scan.o \
|
||||
tasks/task_wifi.o \
|
||||
tasks/task_netplay_crc.o
|
||||
tasks/task_netplay_find_content.o
|
||||
|
||||
ifneq ($(HAVE_SOCKET_LEGACY),1)
|
||||
OBJ += $(LIBRETRO_COMM_DIR)/net/net_ifinfo.o
|
||||
|
@ -910,7 +910,7 @@ NETPLAY
|
||||
#include "../tasks/task_http.c"
|
||||
#include "../tasks/task_netplay_lan_scan.c"
|
||||
#include "../tasks/task_wifi.c"
|
||||
#include "../tasks/task_netplay_crc.c"
|
||||
#include "../tasks/task_netplay_find_content.c"
|
||||
#endif
|
||||
|
||||
/*============================================================
|
||||
|
@ -3135,7 +3135,7 @@ static int action_ok_netplay_connect_room(const char *path,
|
||||
netplay_room_list[idx - 1].address,
|
||||
netplay_room_list[idx - 1].port);
|
||||
|
||||
RARCH_LOG("Connecting to: %s with game: %s/%08x",
|
||||
RARCH_LOG("Connecting to: %s with game: %s/%08x\n",
|
||||
netplay_room_list[idx - 1].address,
|
||||
netplay_room_list[idx - 1].gamename,
|
||||
netplay_room_list[idx - 1].gamecrc);
|
||||
|
221
tasks/task_netplay_find_content.c
Normal file
221
tasks/task_netplay_find_content.c
Normal file
@ -0,0 +1,221 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2016 - Jean-André Santoni
|
||||
*
|
||||
* 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"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
struct string_list *lpl_list;
|
||||
char crc[PATH_MAX_LENGTH];
|
||||
char path[PATH_MAX_LENGTH];
|
||||
char hostname[512];
|
||||
char corename[PATH_MAX_LENGTH];
|
||||
bool found;
|
||||
} netplay_crc_handle_t;
|
||||
|
||||
static void netplay_crc_scan_callback(void *task_data,
|
||||
void *user_data, const char *error)
|
||||
{
|
||||
int i;
|
||||
netplay_crc_handle_t *state = (netplay_crc_handle_t*)task_data;
|
||||
core_info_list_t *info = NULL;
|
||||
content_ctx_info_t content_info = {0};
|
||||
|
||||
core_info_get_list(&info);
|
||||
|
||||
if (!state)
|
||||
return;
|
||||
|
||||
for (i=0; i < info->count; i++)
|
||||
{
|
||||
if(string_is_equal(info->list[i].core_name, state->corename))
|
||||
break;
|
||||
}
|
||||
|
||||
command_event(CMD_EVENT_NETPLAY_INIT_DIRECT_DEFERRED, state->hostname);
|
||||
task_push_content_load_default(
|
||||
info->list[i].path, state->path,
|
||||
&content_info,
|
||||
CORE_TYPE_PLAIN,
|
||||
CONTENT_MODE_LOAD_CONTENT_WITH_NEW_CORE_FROM_MENU,
|
||||
NULL, NULL);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (state->lpl_list->size == 0)
|
||||
goto no_playlists;
|
||||
|
||||
if (atoi(state->crc) != 0)
|
||||
{
|
||||
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);
|
||||
{
|
||||
for (j = 0; j < playlist->size; j++)
|
||||
{
|
||||
if (string_is_equal(playlist->entries[j].crc32, state->crc))
|
||||
{
|
||||
strlcpy(state->path, playlist->entries[j].path, sizeof(state->path));
|
||||
state->found = true;
|
||||
task_set_data(task, state);
|
||||
task_set_progress(task, 100);
|
||||
task_set_title(task, strdup("Compatible content found"));
|
||||
task_set_finished(task, true);
|
||||
string_list_free(state->lpl_list);
|
||||
return;
|
||||
}
|
||||
task_set_progress(task, (int)(j/playlist->size*100.0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
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);
|
||||
{
|
||||
for (j = 0; j < playlist->size; j++)
|
||||
{
|
||||
printf("paths: %s %s\n", playlist->entries[j].path, state->path);
|
||||
if (strstr(playlist->entries[j].path, state->path))
|
||||
{
|
||||
strlcpy(state->path, playlist->entries[j].path, sizeof(state->path));
|
||||
state->found = true;
|
||||
task_set_data(task, state);
|
||||
task_set_progress(task, 100);
|
||||
task_set_title(task, strdup("Compatible content found"));
|
||||
task_set_finished(task, true);
|
||||
string_list_free(state->lpl_list);
|
||||
return;
|
||||
}
|
||||
|
||||
task_set_progress(task, (int)(j/playlist->size*100.0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
no_playlists:
|
||||
string_list_free(state->lpl_list);
|
||||
task_set_progress(task, 100);
|
||||
task_set_title(task, strdup("Couldn't find compatible content"));
|
||||
task_set_finished(task, true);
|
||||
return;
|
||||
}
|
||||
|
||||
bool task_push_netplay_crc_scan(uint32_t crc,
|
||||
const char *hostname, const char *corename)
|
||||
{
|
||||
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));
|
||||
|
||||
if (!task || !state)
|
||||
goto error;
|
||||
|
||||
state->crc[0] = '\0';
|
||||
snprintf(state->crc, sizeof(state->crc), "%08X|crc", crc);
|
||||
|
||||
state->hostname[0] = '\0';
|
||||
snprintf(state->hostname, sizeof(state->hostname), "%s", hostname);
|
||||
|
||||
state->corename[0] = '\0';
|
||||
snprintf(state->corename, sizeof(state->corename), "%s", corename);
|
||||
|
||||
state->lpl_list = dir_list_new(settings->directory.playlist,
|
||||
NULL, true, true, true, false);
|
||||
|
||||
state->found = false;
|
||||
|
||||
/* 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;
|
||||
task->title = strdup("Looking for matching content...");
|
||||
|
||||
task_queue_ctl(TASK_QUEUE_CTL_PUSH, task);
|
||||
|
||||
return true;
|
||||
|
||||
error:
|
||||
if (state)
|
||||
free(state);
|
||||
if (task)
|
||||
free(task);
|
||||
|
||||
return false;
|
||||
}
|
Loading…
Reference in New Issue
Block a user