2013-02-20 19:52:52 -05:00
/ * RetroArch - A frontend for libretro .
2014-01-01 01:50:59 +01:00
* Copyright ( C ) 2013 -2014 - Jason Fetters
* Copyright ( C ) 2011 -2014 - Daniel De Matteis
2013-02-20 19:52:52 -05: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 / > .
* /
2013-02-06 09:54:15 -05:00
2013-06-11 06:07:09 -04:00
# include < string . h >
2013-04-04 07:54:33 +02:00
2013-07-06 18:24:25 -04:00
# import "RetroArch_Apple.h"
2013-04-04 07:54:33 +02:00
# include "rarch_wrapper.h"
2013-12-28 21:08:30 +01:00
# include "../../frontend/frontend.h"
2013-04-04 07:54:33 +02:00
2014-04-26 17:47:21 +02:00
# include "../../input/apple_input.h"
2013-07-07 16:01:58 -04:00
2014-02-11 19:03:38 +11:00
# include "../../file.h"
2013-02-10 19:32:22 -05:00
2013-07-07 17:50:17 -04:00
id < RetroArch_Platform > apple_platform ;
2013-07-06 18:24:25 -04:00
# pragma mark EMULATION
2013-08-14 10:07:36 -04:00
bool apple_is _running ;
bool apple_use _tv _mode ;
2013-11-22 15:30:02 +01:00
NSString * apple_core ;
2013-07-06 18:24:25 -04:00
2014-04-19 20:16:29 +02:00
static void apple_rarch _exited ( void )
2013-12-24 14:21:57 -05:00
{
2014-04-19 20:16:29 +02:00
NSString * used_core = ( NSString * ) apple_core ;
2013-12-24 14:21:57 -05:00
apple_core = 0 ;
if ( apple_is _running )
{
apple_is _running = false ;
[ apple_platform unloadingCore : used_core ] ;
}
# ifdef OSX
[ used_core release ] ;
# endif
if ( apple_use _tv _mode )
apple_run _core ( nil , 0 ) ;
}
2013-11-22 15:30:02 +01:00
void apple_run _core ( NSString * core , const char * file )
2013-07-06 18:24:25 -04:00
{
2013-12-30 17:17:35 +01:00
if ( apple_is _running )
return ;
[ apple_platform loadingCore : core withFile : file ] ;
apple_core = core ;
apple_is _running = true ;
2014-01-03 17:16:02 -05:00
static char core_path [ PATH_MAX ] ;
static char file_path [ PATH_MAX ] ;
if ( file && core )
{
strlcpy ( core_path , apple_core . UTF8String , sizeof ( core_path ) ) ;
strlcpy ( file_path , file , sizeof ( file_path ) ) ;
}
# ifdef IOS
2013-12-30 17:17:35 +01:00
static char config_path [ PATH_MAX ] ;
2014-01-03 17:16:02 -05:00
2014-04-26 21:48:42 +02:00
if ( core_info _has _custom _config ( apple_core . UTF8String ) )
core_info _get _custom _config ( apple_core . UTF8String , config_path , sizeof ( config_path ) ) ;
2013-12-30 17:17:35 +01:00
else
strlcpy ( config_path , apple_platform . globalConfigFile . UTF8String , sizeof ( config_path ) ) ;
static const char * const argv_game [ ] = { "retroarch" , "-c" , config_path , "-L" , core_path , file_path , 0 } ;
static const char * const argv_menu [ ] = { "retroarch" , "-c" , config_path , "--menu" , 0 } ;
int argc = ( file && core ) ? 6 : 4 ;
char * * argv = ( char * * ) ( ( file && core ) ? argv_game : argv_menu ) ;
2014-01-03 17:16:02 -05:00
# else
static const char * const argv_game [ ] = { "retroarch" , "-L" , core_path , file_path , 0 } ;
static const char * const argv_menu [ ] = { "retroarch" , "--menu" , 0 } ;
int argc = ( file && core ) ? 4 : 2 ;
char * * argv = ( char * * ) ( ( file && core ) ? argv_game : argv_menu ) ;
# endif
2013-12-30 17:17:35 +01:00
if ( apple_rarch _load _content ( argc , argv ) )
{
char basedir [ 256 ] ;
fill_pathname _basedir ( basedir , file ? file : "" , sizeof ( basedir ) ) ;
if ( file && access ( basedir , R_OK | W_OK | X_OK ) )
apple_display _alert ( BOXSTRING ( "The directory containing the selected file must have write premissions. This will prevent zipped content from loading, and will cause some cores to not function." ) , 0 ) ;
else
apple_display _alert ( BOXSTRING ( "Failed to load content." ) , 0 ) ;
apple_rarch _exited ( ) ;
}
2013-07-06 18:24:25 -04:00
}