Commit 05c25125 authored by David Skywalker's avatar David Skywalker
Browse files

cleaned libretro loading contents

parent 0aba4aea
......@@ -177,7 +177,7 @@ int HandleExtension(char *path,char *ext);
#include "retro_utils.h"
extern unsigned int bmp[WINDOW_MAX_SIZE];
extern char RPATH[512];
extern char retro_content_filepath[512];
extern int autorun;
extern int SND;
extern bool kbd_runcmd;
......@@ -1623,13 +1623,13 @@ void getConfigValueString (char* pchFileName, char* pchSection,
void loadConfiguration (void)
{
unsigned i, n, iSide, iSector, iRomNum;
char chFileName[_MAX_PATH + 1];
char chPath[_MAX_PATH + 1];
char chFileName[_MAX_PATH + 11];
char chPath[_MAX_PATH + 16];
(void)n;
strncpy(chFileName, chAppPath, sizeof(chFileName)-10);
strcat(chFileName, "/cap32.cfg");
strncat(chFileName, "/cap32.cfg", sizeof(chFileName) - 1);
memset(&CPC, 0, sizeof(CPC));
......@@ -2068,7 +2068,7 @@ int retro_disk_auto()
strcpy(Buffer, "|CPM");
} else {
strcpy(Buffer, "CAT");
printf("autoload not found\n");
printf("autoload: file to load not found\n");
}
} else {
......@@ -2078,14 +2078,15 @@ int retro_disk_auto()
else
if (first_bin != -1) cur_name_id = first_bin;
sprintf(Buffer, "RUN\"%s", cpc_dsk_dirent[cur_name_id]);
// check added to avoid warning on gcc >= 8
if(snprintf(Buffer, sizeof(Buffer), "RUN\"%s", (const char*) &cpc_dsk_dirent[cur_name_id][0]) < 0)
{
printf("autoload: snprintf failed");
}
}
}
//if (CPC.psp_explore_disk == CPC_EXPLORE_FULL_AUTO)
{
strcat(Buffer, "\n");
}
strcat(Buffer, "\n");
//printf("(%s)\n",Buffer);
kbd_buf_feed(Buffer);
......@@ -2135,17 +2136,28 @@ int loadadsk (char *arv,int drive)
{
if( HandleExtension(arv,"DSK") || HandleExtension(arv,"dsk") )
{
if(attach_disk(arv, drive) == 0)
{
retro_disk_auto();
sprintf(RPATH,"%s%d.SNA",arv,drive);
}
if(attach_disk(arv, drive) == 0)
{
retro_disk_auto();
snprintf(
retro_content_filepath,
sizeof(retro_computer_cfg),
"%s%d.SNA",
arv,
drive
);
}
}
else if( HandleExtension(arv,"sna") || HandleExtension(arv,"SNA") )
{
snapshot_load (arv);
sprintf(RPATH,"%s",arv);
snapshot_load(arv);
strncpy(
retro_content_filepath,
arv,
sizeof(retro_content_filepath) - 1
);
}
return 0;
}
......@@ -2231,4 +2243,4 @@ int capmain (int argc, char **argv)
emu_status = COMPUTER_READY; // set computer init as completed
return 0;
}
}
\ No newline at end of file
......@@ -13,15 +13,6 @@
#include "gfx/software.h"
#include "assets/ui.h"
//CORE VAR
#ifdef _WIN32
char slash = '\\';
#else
char slash = '/';
#endif
char RETRO_DIR[512];
char DISKA_NAME[512]="\0";
char DISKB_NAME[512]="\0";
char cart_name[512]="\0";
......@@ -80,9 +71,6 @@ uint32_t save_Screen[WINDOW_MAX_SIZE];
int32_t* audio_buffer = NULL;
int audio_buffer_size = 0;
//PATH
char RPATH[512];
// almost deprecated
int pauseg = 0;
int autorun = 0;
......@@ -113,6 +101,8 @@ const char *retro_save_directory;
const char *retro_system_directory;
const char *retro_content_directory;
char retro_system_data_directory[512];
char retro_system_bios_directory[512];
char retro_content_filepath[512];
/*static*/ retro_input_state_t input_state_cb;
/*static*/ retro_input_poll_t input_poll_cb;
......@@ -204,6 +194,7 @@ void Add_Option(const char* option)
sprintf(XARGV[PARAMCOUNT++],"%s",option);
}
// TODO: clean this...
int pre_main(const char *argv)
{
int i;
......@@ -218,13 +209,12 @@ int pre_main(const char *argv)
if(Only1Arg)
{ Add_Option("x64");
if (strlen(RPATH) >= strlen("crt"))
if(!strcasecmp(&RPATH[strlen(RPATH)-strlen("crt")], "crt"))
Add_Option("-cartcrt");
{
Add_Option("x64");
if(file_check_extension(retro_content_filepath, sizeof(retro_content_filepath), "crt", 3))
Add_Option("-cartcrt");
Add_Option(RPATH/*ARGUV[0]*/);
Add_Option(retro_content_filepath);
}
else
{ // Pass all cmdline args
......@@ -674,7 +664,7 @@ void Emu_init()
return;
}
emu_status = COMPUTER_BOOTING;
pre_main(RPATH);
pre_main(retro_content_filepath);
}
void Emu_uninit()
......@@ -957,121 +947,96 @@ void computer_load_bios() {
// TODO add load customs bios
// cart is like a system bios
if (strlen(RPATH) >= strlen(CPR_FILE_EXT))
if(!strcasecmp(&RPATH[strlen(RPATH)-strlen(CPR_FILE_EXT)], CPR_FILE_EXT))
{
int result = cart_insert(RPATH);
if(result != 0) {
retro_message("Error Loading Cart...");
} else {
sprintf(RPATH,"%s",RPATH);
}
if(file_check_extension(retro_content_filepath, sizeof(retro_content_filepath), CPR_FILE_EXT, 3))
{
int result = cart_insert(retro_content_filepath);
if(result != 0) {
retro_message("Error Loading Cart...");
}
}
}
// load content
void computer_load_file() {
int i;
// If it's a m3u file
if (strlen(RPATH) >= strlen(M3U_FILE_EXT))
if(!strcasecmp(&RPATH[strlen(RPATH)-strlen(M3U_FILE_EXT)], M3U_FILE_EXT))
{
// Parse the m3u file
dc_parse_m3u(dc, RPATH);
// Some debugging
log_cb(RETRO_LOG_INFO, "m3u file parsed, %d file(s) found\n", dc->count);
for(i = 0; i < dc->count; i++)
{
log_cb(RETRO_LOG_INFO, "file %d: %s\n", i+1, dc->files[i]);
}
// Init first image
dc->eject_state = false;
dc->index = 0;
retro_insert_image();
// If command was specified
if(dc->command)
{
// Execute the command
log_cb(RETRO_LOG_INFO, "Executing the specified command: %s\n", dc->command);
char* command = calloc(strlen(dc->command) + 1, sizeof(char));
sprintf(command, "%s\n", dc->command);
kbd_buf_feed(command);
free(command);
}
else if (dc->unit == DC_IMAGE_TYPE_FLOPPY)
{
// Autoplay
retro_disk_auto();
}
// If it's a snapshot
if(file_check_extension(retro_content_filepath, sizeof(retro_content_filepath), SNA_FILE_EXT, 3))
{
int error = snapshot_load (retro_content_filepath);
if (!error) {
LOGI("SNA loaded: %s\n", (char *)retro_content_filepath);
} else {
LOGI("SNA Error (%d): %s", error, (char *)retro_content_filepath);
}
// Prepare SNA
sprintf(RPATH,"%s%d.SNA",RPATH,0);
return;
}
return;
}
// If it's a m3u file
if(file_check_extension(retro_content_filepath, sizeof(retro_content_filepath), M3U_FILE_EXT, 3))
{
// Parse the m3u file
dc_parse_m3u(dc, retro_content_filepath);
// If it's a disk
if (strlen(RPATH) >= strlen(DSK_FILE_EXT))
if(!strcasecmp(&RPATH[strlen(RPATH)-strlen(DSK_FILE_EXT)], DSK_FILE_EXT))
// Some debugging
log_cb(RETRO_LOG_INFO, "m3u file parsed, %d file(s) found\n", dc->count);
for(i = 0; i < dc->count; i++)
{
// Add the file to disk control context
// Maybe, in a later version of retroarch, we could add disk on the fly (didn't find how to do this)
dc_add_file(dc, RPATH);
// Init first disk
dc->index = 0;
dc->eject_state = false;
LOGI("Disk (%d) inserted into drive A : %s\n", dc->index+1, dc->files[dc->index]);
attach_disk((char *)dc->files[dc->index],0);
retro_disk_auto();
log_cb(RETRO_LOG_INFO, "file %d: %s\n", i+1, dc->files[i]);
}
// Prepare SNA
sprintf(RPATH,"%s%d.SNA",RPATH,0);
// Init first image
dc->eject_state = false;
dc->index = 0;
retro_insert_image();
return;
// If command was specified
if(dc->command)
{
// Execute the command
log_cb(RETRO_LOG_INFO, "Executing the specified command: %s\n", dc->command);
char* command = calloc(strlen(dc->command) + 1, sizeof(char));
sprintf(command, "%s\n", dc->command);
kbd_buf_feed(command);
free(command);
}
// If it's a tape
if (strlen(RPATH) >= strlen(CDT_FILE_EXT))
if(!strcasecmp(&RPATH[strlen(RPATH)-strlen(CDT_FILE_EXT)], CDT_FILE_EXT))
else if (dc->unit == DC_IMAGE_TYPE_FLOPPY)
{
int error = tape_insert ((char *)RPATH);
if (!error) {
kbd_buf_feed("|TAPE\nRUN\"\n^");
LOGI("Tape inserted: %s\n", (char *)RPATH);
} else {
LOGI("Tape Error (%d): %s\n", error, (char *)RPATH);
}
// Prepare SNA
sprintf(RPATH,"%s%d.SNA",RPATH,0);
return;
// Autoplay
retro_disk_auto();
}
}
// If it's a snapshot
if (strlen(RPATH) >= strlen(SNA_FILE_EXT))
if(!strcasecmp(&RPATH[strlen(RPATH)-strlen(SNA_FILE_EXT)], SNA_FILE_EXT))
{
int error = snapshot_load (RPATH);
if (!error) {
LOGI("SNA loaded: %s\n", (char *)RPATH);
} else {
LOGI("SNA Error (%d): %s", error, (char *)RPATH);
}
// If it's a disk
if(file_check_extension(retro_content_filepath, sizeof(retro_content_filepath), DSK_FILE_EXT, 3))
{
// Add the file to disk control context
// Maybe, in a later version of retroarch, we could add disk on the fly (didn't find how to do this)
dc_add_file(dc, retro_content_filepath);
return;
}
// Init first disk
dc->index = 0;
dc->eject_state = false;
LOGI("Disk (%d) inserted into drive A : %s\n", dc->index+1, dc->files[dc->index]);
attach_disk((char *)dc->files[dc->index],0);
retro_disk_auto();
}
}
// If it's a tape
if(file_check_extension(retro_content_filepath, sizeof(retro_content_filepath), CDT_FILE_EXT, 3))
{
int error = tape_insert ((char *)retro_content_filepath);
if (!error) {
kbd_buf_feed("|TAPE\nRUN\"\n^");
LOGI("Tape inserted: %s\n", (char *)retro_content_filepath);
} else {
LOGI("Tape Error (%d): %s\n", error, (char *)retro_content_filepath);
}
}
void load_ui(void)
{
// Prepare SNA
strncat(retro_content_filepath, "0.SNA", sizeof(retro_content_filepath) - 1);
}
void retro_init(void)
......@@ -1113,14 +1078,29 @@ void retro_init(void)
retro_save_directory=retro_system_directory;
}
if(retro_system_directory==NULL)sprintf(RETRO_DIR, "%c",'.');
else sprintf(RETRO_DIR, "%s", retro_system_directory);
if(retro_system_directory == NULL)
{
strcpy(retro_system_bios_directory, ".");
}
else
{
strncpy(
retro_system_bios_directory,
retro_system_directory,
sizeof(retro_system_bios_directory) - 1
);
}
sprintf(retro_system_data_directory, "%s%cdata",RETRO_DIR, slash); // TODO: unused ?
// TODO: future use to load custom bios
path_join(
retro_system_data_directory,
retro_system_bios_directory,
"data"
);
LOGI("Retro SYSTEM_DIRECTORY %s\n",retro_system_directory);
LOGI("Retro SAVE_DIRECTORY %s\n",retro_save_directory);
LOGI("Retro CONTENT_DIRECTORY %s\n",retro_content_directory);
LOGI("Retro SYSTEM_DIRECTORY %s\n", retro_system_directory);
LOGI("Retro SAVE_DIRECTORY %s\n", retro_save_directory);
LOGI("Retro CONTENT_DIRECTORY %s\n", retro_content_directory);
#ifndef M16B
enum retro_pixel_format fmt =RETRO_PIXEL_FORMAT_XRGB8888;
......@@ -1285,9 +1265,9 @@ void retro_run(void)
bool retro_load_game(const struct retro_game_info *game)
{
if (game){
strcpy(RPATH, (const char *) game->path);
strcpy(retro_content_filepath, (const char *) game->path);
} else {
RPATH[0]='\0';
retro_content_filepath[0]='\0';
}
update_variables();
......
......@@ -20,16 +20,32 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "retro_utils.h"
#ifdef VITA
#include "file/file_path.h"
#endif
// Verify file extension
bool file_check_extension(const char *filename, const size_t filename_size, const char *ext, const size_t ext_size)
{
size_t file_len = strnlen(filename, filename_size);
size_t ext_len = strnlen(ext, ext_size);
if( ext_len > file_len || file_len >= filename_size - 1)
return false;
const char * file_ext = &filename[file_len - ext_len];
return (strncasecmp(file_ext, ext, filename_size) == 0);
}
// Verify if file exists
bool file_exists(const char *filename)
{
struct stat buf;
#ifdef VITA
if (path_is_valid(filename) && !path_is_directory(filename))
if (path_is_valid(filename) && !path_is_directory(filename))
#else
struct stat buf;
if (stat(filename, &buf) == 0 &&
(buf.st_mode & (S_IRUSR|S_IWUSR)) && !(buf.st_mode & S_IFDIR))
#endif
......
......@@ -34,6 +34,7 @@
#define RETRO_PATH_SEPARATOR "/"
#endif
bool file_check_extension(const char *filename, const size_t filename_size, const char *ext, const size_t ext_size);
void path_join(char* out, const char* basedir, const char* filename);
char* path_join_dup(const char* basedir, const char* filename);
bool file_exists(const char *filename);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment