2013-07-27 15:40:21 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 00:50:59 +00:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2015-01-07 16:46:50 +00:00
|
|
|
* Copyright (C) 2011-2015 - Daniel De Matteis
|
2014-01-01 00:50:59 +00:00
|
|
|
* Copyright (C) 2012-2014 - Jason Fetters
|
2015-01-07 16:46:50 +00:00
|
|
|
* Copyright (C) 2014-2015 - Jay McCarthy
|
2013-07-27 15:40:21 +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.
|
2013-07-27 15:45:56 +00:00
|
|
|
* * You should have received a copy of the GNU General Public License along with RetroArch.
|
2013-07-27 15:40:21 +00:00
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2014-10-17 15:05:27 +00:00
|
|
|
#include "../../apple/common/CFExtensions.h"
|
2013-07-28 21:01:16 +00:00
|
|
|
|
2014-05-03 05:17:59 +00:00
|
|
|
#include "../frontend.h"
|
2015-01-12 22:52:45 +00:00
|
|
|
#ifdef IOS
|
2015-01-26 10:17:38 +00:00
|
|
|
#include "../../menu/drivers/ios.h"
|
2015-01-12 22:52:45 +00:00
|
|
|
#endif
|
2013-07-27 15:40:21 +00:00
|
|
|
|
|
|
|
#include <stdint.h>
|
2014-10-21 03:05:52 +00:00
|
|
|
#include <boolean.h>
|
2013-07-27 15:40:21 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2015-04-07 17:18:36 +00:00
|
|
|
static bool CopyModel(char** model, uint32_t *majorRev, uint32_t *minorRev)
|
|
|
|
{
|
2015-04-07 17:30:24 +00:00
|
|
|
#ifdef OSX
|
2015-04-07 18:57:43 +00:00
|
|
|
int mib[2];
|
|
|
|
int count;
|
|
|
|
unsigned long modelLen;
|
|
|
|
char *revStr;
|
2015-04-07 17:30:24 +00:00
|
|
|
#endif
|
2015-04-07 18:57:43 +00:00
|
|
|
char *machineModel;
|
|
|
|
bool success = true;
|
|
|
|
size_t length = 1024;
|
|
|
|
|
|
|
|
if (!model || !majorRev || !minorRev)
|
|
|
|
{
|
|
|
|
RARCH_ERR("CopyModel: Passing NULL arguments\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-07 17:30:24 +00:00
|
|
|
#ifdef IOS
|
2015-04-07 18:57:43 +00:00
|
|
|
sysctlbyname("hw.machine", NULL, &length, NULL, 0);
|
2015-04-07 17:30:24 +00:00
|
|
|
#endif
|
2015-04-07 18:57:43 +00:00
|
|
|
|
|
|
|
machineModel = malloc(length);
|
|
|
|
|
|
|
|
if (!machineModel)
|
|
|
|
{
|
|
|
|
success = false;
|
|
|
|
goto exit;
|
|
|
|
}
|
2015-04-07 17:30:24 +00:00
|
|
|
#ifdef IOS
|
2015-04-07 18:57:43 +00:00
|
|
|
sysctlbyname("hw.machine", machineModel, &length, NULL, 0);
|
|
|
|
*model = strndup(machineModel, length);
|
2015-04-07 17:30:24 +00:00
|
|
|
#else
|
2015-04-07 18:57:43 +00:00
|
|
|
mib[0] = CTL_HW;
|
|
|
|
mib[1] = HW_MODEL;
|
|
|
|
|
|
|
|
if (sysctl(mib, 2, machineModel, &length, NULL, 0))
|
|
|
|
{
|
|
|
|
printf("CopyModel: sysctl (error %d)\n", errno);
|
|
|
|
success = false;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
modelLen = strcspn(machineModel, "0123456789");
|
|
|
|
|
|
|
|
if (modelLen == 0)
|
|
|
|
{
|
|
|
|
RARCH_ERR("CopyModel: Could not find machine model name\n");
|
|
|
|
success = false;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
*model = strndup(machineModel, modelLen);
|
|
|
|
|
|
|
|
if (*model == NULL)
|
|
|
|
{
|
|
|
|
RARCH_ERR("CopyModel: Could not find machine model name\n");
|
|
|
|
success = false;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
*majorRev = 0;
|
|
|
|
*minorRev = 0;
|
|
|
|
revStr = strpbrk(machineModel, "0123456789");
|
|
|
|
|
|
|
|
if (!revStr)
|
|
|
|
{
|
|
|
|
RARCH_ERR("CopyModel: Could not find machine version number, inferred value is 0,0\n");
|
|
|
|
success = true;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
count = sscanf(revStr, "%d,%d", majorRev, minorRev);
|
|
|
|
|
|
|
|
if (count < 2)
|
|
|
|
{
|
|
|
|
RARCH_ERR("CopyModel: Could not find machine version number\n");
|
|
|
|
if (count < 1)
|
|
|
|
*majorRev = 0;
|
|
|
|
*minorRev = 0;
|
|
|
|
success = true;
|
|
|
|
goto exit;
|
|
|
|
}
|
2015-04-07 17:30:24 +00:00
|
|
|
#endif
|
2015-04-07 18:57:43 +00:00
|
|
|
|
2015-04-07 17:18:36 +00:00
|
|
|
exit:
|
2015-04-07 18:57:43 +00:00
|
|
|
if (machineModel)
|
|
|
|
free(machineModel);
|
|
|
|
if (!success)
|
|
|
|
{
|
|
|
|
if (*model)
|
|
|
|
free(*model);
|
|
|
|
*model = NULL;
|
|
|
|
*majorRev = 0;
|
|
|
|
*minorRev = 0;
|
|
|
|
}
|
|
|
|
return success;
|
2015-04-07 17:18:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void frontend_apple_get_name(char *name, size_t sizeof_name)
|
|
|
|
{
|
|
|
|
uint32_t major_rev, minor_rev;
|
|
|
|
CopyModel(&name, &major_rev, &minor_rev);
|
|
|
|
}
|
|
|
|
|
2014-10-07 02:43:59 +00:00
|
|
|
static void frontend_apple_get_environment_settings(int *argc, char *argv[],
|
|
|
|
void *args, void *params_data)
|
|
|
|
{
|
2015-03-12 23:54:44 +00:00
|
|
|
char temp_dir[PATH_MAX_LENGTH];
|
2015-03-13 00:33:45 +00:00
|
|
|
char bundle_path_buf[PATH_MAX_LENGTH], home_dir_buf[PATH_MAX_LENGTH];
|
2014-10-07 02:43:59 +00:00
|
|
|
CFURLRef bundle_url;
|
2015-01-09 01:12:08 +00:00
|
|
|
CFStringRef bundle_path;
|
2014-10-07 02:43:59 +00:00
|
|
|
CFBundleRef bundle = CFBundleGetMainBundle();
|
2015-01-09 16:44:00 +00:00
|
|
|
|
2015-03-13 00:22:20 +00:00
|
|
|
(void)temp_dir;
|
2015-01-09 01:12:08 +00:00
|
|
|
|
2014-10-07 02:43:59 +00:00
|
|
|
if (!bundle)
|
|
|
|
return;
|
2015-01-09 01:12:08 +00:00
|
|
|
|
|
|
|
bundle_url = CFBundleCopyBundleURL(bundle);
|
|
|
|
bundle_path = CFURLCopyPath(bundle_url);
|
2014-10-07 14:51:25 +00:00
|
|
|
|
2014-10-18 02:36:02 +00:00
|
|
|
CFStringGetCString(bundle_path, bundle_path_buf, sizeof(bundle_path_buf), kCFStringEncodingUTF8);
|
2014-10-07 14:51:25 +00:00
|
|
|
(void)home_dir_buf;
|
2015-03-13 00:21:20 +00:00
|
|
|
|
2015-03-12 23:54:44 +00:00
|
|
|
CFSearchPathForDirectoriesInDomains(CFDocumentDirectory, CFUserDomainMask, 1, home_dir_buf, sizeof(home_dir_buf));
|
|
|
|
|
2015-03-13 00:33:45 +00:00
|
|
|
#ifdef OSX
|
|
|
|
strlcat(home_dir_buf, "/RetroArch", sizeof(home_dir_buf));
|
|
|
|
#endif
|
|
|
|
|
2015-03-12 22:32:19 +00:00
|
|
|
fill_pathname_join(g_defaults.core_dir, home_dir_buf, "modules", sizeof(g_defaults.core_dir));
|
|
|
|
fill_pathname_join(g_defaults.core_info_dir, home_dir_buf, "info", sizeof(g_defaults.core_info_dir));
|
2015-03-13 00:33:45 +00:00
|
|
|
fill_pathname_join(g_defaults.overlay_dir, home_dir_buf, "overlays", sizeof(g_defaults.overlay_dir));
|
2015-04-07 05:25:53 +00:00
|
|
|
fill_pathname_join(g_defaults.autoconfig_dir, home_dir_buf, "autoconfig/hid", sizeof(g_defaults.autoconfig_dir));
|
2015-03-12 22:40:51 +00:00
|
|
|
fill_pathname_join(g_defaults.assets_dir, home_dir_buf, "assets", sizeof(g_defaults.assets_dir));
|
2015-03-13 00:33:45 +00:00
|
|
|
fill_pathname_join(g_defaults.system_dir, home_dir_buf, ".RetroArch", sizeof(g_defaults.system_dir));
|
2014-10-07 02:43:59 +00:00
|
|
|
strlcpy(g_defaults.menu_config_dir, g_defaults.system_dir, sizeof(g_defaults.menu_config_dir));
|
|
|
|
fill_pathname_join(g_defaults.config_path, g_defaults.menu_config_dir, "retroarch.cfg", sizeof(g_defaults.config_path));
|
2015-03-13 00:33:45 +00:00
|
|
|
fill_pathname_join(g_defaults.database_dir, home_dir_buf, "rdb", sizeof(g_defaults.database_dir));
|
|
|
|
fill_pathname_join(g_defaults.cursor_dir, home_dir_buf, "cursors", sizeof(g_defaults.cursor_dir));
|
|
|
|
fill_pathname_join(g_defaults.cheats_dir, home_dir_buf, "cht", sizeof(g_defaults.cheats_dir));
|
2014-10-07 02:43:59 +00:00
|
|
|
strlcpy(g_defaults.sram_dir, g_defaults.system_dir, sizeof(g_defaults.sram_dir));
|
|
|
|
strlcpy(g_defaults.savestate_dir, g_defaults.system_dir, sizeof(g_defaults.savestate_dir));
|
2015-03-13 02:47:25 +00:00
|
|
|
|
2015-03-13 00:33:45 +00:00
|
|
|
CFTemporaryDirectory(temp_dir, sizeof(temp_dir));
|
|
|
|
strlcpy(g_defaults.extraction_dir, temp_dir, sizeof(g_defaults.extraction_dir));
|
2015-03-13 02:47:25 +00:00
|
|
|
|
2015-03-13 00:33:45 +00:00
|
|
|
fill_pathname_join(g_defaults.shader_dir, home_dir_buf, "shaders_glsl", sizeof(g_defaults.shader_dir));
|
2015-03-13 02:47:25 +00:00
|
|
|
|
|
|
|
#if defined(OSX)
|
2015-03-13 02:49:42 +00:00
|
|
|
#ifdef HAVE_CG
|
2015-03-13 00:33:45 +00:00
|
|
|
fill_pathname_join(g_defaults.shader_dir, home_dir_buf, "shaders_cg", sizeof(g_defaults.shader_dir));
|
2015-03-13 02:49:42 +00:00
|
|
|
#endif
|
2015-03-13 00:33:45 +00:00
|
|
|
fill_pathname_join(g_defaults.audio_filter_dir, home_dir_buf, "audio_filters", sizeof(g_defaults.audio_filter_dir));
|
|
|
|
fill_pathname_join(g_defaults.video_filter_dir, home_dir_buf, "video_filters", sizeof(g_defaults.video_filter_dir));
|
|
|
|
#endif
|
|
|
|
|
2014-10-07 02:43:59 +00:00
|
|
|
path_mkdir(bundle_path_buf);
|
2015-03-13 00:33:45 +00:00
|
|
|
|
2014-10-07 02:55:14 +00:00
|
|
|
if (access(bundle_path_buf, 0755) != 0)
|
2014-10-07 02:43:59 +00:00
|
|
|
RARCH_ERR("Failed to create or access base directory: %s\n", bundle_path_buf);
|
2015-03-13 00:33:45 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
path_mkdir(g_defaults.system_dir);
|
|
|
|
|
|
|
|
if (access(g_defaults.system_dir, 0755) != 0)
|
|
|
|
RARCH_ERR("Failed to create or access system directory: %s.\n", g_defaults.system_dir);
|
|
|
|
}
|
2014-10-07 02:43:59 +00:00
|
|
|
|
|
|
|
CFRelease(bundle_path);
|
|
|
|
CFRelease(bundle_url);
|
2014-05-03 05:11:23 +00:00
|
|
|
}
|
|
|
|
|
2014-07-22 03:13:48 +00:00
|
|
|
extern void apple_rarch_exited(void);
|
|
|
|
|
2014-10-17 03:27:54 +00:00
|
|
|
static void frontend_apple_load_content(void)
|
2014-10-17 01:55:16 +00:00
|
|
|
{
|
2015-03-21 21:28:12 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
if (!driver->menu_ctx)
|
2015-03-13 01:33:32 +00:00
|
|
|
return;
|
2015-03-21 21:28:12 +00:00
|
|
|
if (!driver->menu)
|
2015-03-13 01:33:32 +00:00
|
|
|
return;
|
2015-03-21 21:28:12 +00:00
|
|
|
if (!driver->menu->userdata)
|
2015-03-13 01:33:32 +00:00
|
|
|
return;
|
|
|
|
|
2015-01-05 01:43:44 +00:00
|
|
|
#ifdef IOS
|
2015-03-21 21:30:58 +00:00
|
|
|
if (driver->menu_ctx == &menu_ctx_ios)
|
2015-01-05 01:43:44 +00:00
|
|
|
{
|
2015-03-21 21:30:58 +00:00
|
|
|
ios_handle_t *ih = (ios_handle_t*)driver->menu->userdata;
|
2015-01-09 01:12:08 +00:00
|
|
|
if (ih)
|
|
|
|
ih->notify_content_loaded();
|
2014-12-31 20:24:50 +00:00
|
|
|
}
|
2015-01-05 01:43:44 +00:00
|
|
|
#endif
|
2014-10-17 01:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-07-22 03:13:48 +00:00
|
|
|
static void frontend_apple_shutdown(bool unused)
|
|
|
|
{
|
|
|
|
apple_rarch_exited();
|
|
|
|
}
|
|
|
|
|
2014-05-16 20:20:33 +00:00
|
|
|
static int frontend_apple_get_rating(void)
|
|
|
|
{
|
2015-04-07 18:42:48 +00:00
|
|
|
char model[PATH_MAX_LENGTH];
|
2015-04-07 18:57:20 +00:00
|
|
|
|
2015-04-07 18:42:48 +00:00
|
|
|
frontend_apple_get_name(model, sizeof(model));
|
2015-04-07 18:57:20 +00:00
|
|
|
|
|
|
|
/* iPhone 4 */
|
|
|
|
#if 0
|
|
|
|
if (strstr(model, "iPhone3"))
|
|
|
|
return -1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* iPad 1 */
|
|
|
|
#if 0
|
|
|
|
if (strstr(model, "iPad1,1"))
|
|
|
|
return -1;
|
|
|
|
#endif
|
|
|
|
|
2015-04-07 18:42:48 +00:00
|
|
|
/* iPhone 4S */
|
|
|
|
if (strstr(model, "iPhone4,1"))
|
2015-04-07 18:57:20 +00:00
|
|
|
return 8;
|
|
|
|
|
2015-04-07 18:42:48 +00:00
|
|
|
/* iPad 2/iPad Mini 1 */
|
|
|
|
if (strstr(model, "iPad2"))
|
2015-04-07 18:57:20 +00:00
|
|
|
return 9;
|
|
|
|
|
|
|
|
/* iPhone 5/5C */
|
|
|
|
if (strstr(model, "iPhone5"))
|
|
|
|
return 13;
|
|
|
|
|
|
|
|
/* iPhone 5S */
|
|
|
|
if (strstr(model, "iPhone6,1") || strstr(model, "iPhone6,2"))
|
|
|
|
return 14;
|
|
|
|
|
2015-04-07 18:42:48 +00:00
|
|
|
/* iPad Air/iPad Mini 2 */
|
|
|
|
if (strstr(model, "iPad4"))
|
2015-04-07 18:57:20 +00:00
|
|
|
return 15;
|
|
|
|
|
|
|
|
/* iPhone 6, iPhone 6 Plus */
|
|
|
|
if (strstr(model, "iPhone7"))
|
|
|
|
return 16;
|
|
|
|
|
2015-04-07 18:42:48 +00:00
|
|
|
/* iPad Air 2 */
|
|
|
|
if (strstr(model, "iPad5,3") || strstr(model, "iPad5,4"))
|
2015-04-07 18:59:06 +00:00
|
|
|
return 18;
|
2015-04-07 18:57:20 +00:00
|
|
|
|
2015-04-07 18:42:48 +00:00
|
|
|
/* TODO/FIXME -
|
2015-04-07 18:57:20 +00:00
|
|
|
- more ratings for more systems
|
|
|
|
- determine rating more intelligently*/
|
2014-05-16 20:20:33 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2015-04-07 17:18:36 +00:00
|
|
|
|
2013-07-27 15:40:21 +00:00
|
|
|
const frontend_ctx_driver_t frontend_ctx_apple = {
|
2014-10-07 02:43:59 +00:00
|
|
|
frontend_apple_get_environment_settings, /* environment_get */
|
2013-07-27 15:40:21 +00:00
|
|
|
NULL, /* init */
|
|
|
|
NULL, /* deinit */
|
|
|
|
NULL, /* exitspawn */
|
|
|
|
NULL, /* process_args */
|
|
|
|
NULL, /* exec */
|
2014-10-02 19:39:29 +00:00
|
|
|
NULL, /* set_fork */
|
2014-07-22 03:13:48 +00:00
|
|
|
frontend_apple_shutdown, /* shutdown */
|
2015-04-07 17:18:36 +00:00
|
|
|
frontend_apple_get_name, /* get_name */
|
2014-05-16 20:20:33 +00:00
|
|
|
frontend_apple_get_rating, /* get_rating */
|
2014-10-17 03:27:54 +00:00
|
|
|
frontend_apple_load_content, /* load_content */
|
2013-07-27 15:40:21 +00:00
|
|
|
"apple",
|
|
|
|
};
|