2013-07-27 17:40:21 +02:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 01:50:59 +01:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2015-01-07 17:46:50 +01:00
|
|
|
* Copyright (C) 2011-2015 - Daniel De Matteis
|
2014-01-01 01:50:59 +01:00
|
|
|
* Copyright (C) 2012-2014 - Jason Fetters
|
2015-01-07 17:46:50 +01:00
|
|
|
* Copyright (C) 2014-2015 - Jay McCarthy
|
2013-07-27 17:40:21 +02: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 17:45:56 +02:00
|
|
|
* * You should have received a copy of the GNU General Public License along with RetroArch.
|
2013-07-27 17:40:21 +02:00
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2015-04-19 17:12:20 +02:00
|
|
|
#include <CoreFoundation/CoreFoundation.h>
|
2015-04-20 14:05:55 +02:00
|
|
|
#include <CoreFoundation/CFArray.h>
|
2015-04-19 17:12:20 +02:00
|
|
|
#include <retro_miscellaneous.h>
|
|
|
|
#include <file/file_path.h>
|
2015-04-20 12:54:04 +02:00
|
|
|
|
2015-04-20 14:05:55 +02:00
|
|
|
#ifdef __OBJC__
|
|
|
|
#include <Foundation/NSPathUtilities.h>
|
|
|
|
#endif
|
2013-07-28 23:01:16 +02:00
|
|
|
|
2015-04-07 22:17:41 +02:00
|
|
|
#include "../frontend_driver.h"
|
2015-04-12 05:45:28 +02:00
|
|
|
#include "../../ui/ui_companion_driver.h"
|
2015-04-19 17:12:20 +02:00
|
|
|
#include "../../general.h"
|
2013-07-27 17:40:21 +02:00
|
|
|
|
|
|
|
#include <stdint.h>
|
2014-10-21 05:05:52 +02:00
|
|
|
#include <boolean.h>
|
2013-07-27 17:40:21 +02:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2015-04-18 21:14:30 +02:00
|
|
|
#include <sys/utsname.h>
|
|
|
|
|
2015-04-18 15:07:04 +02:00
|
|
|
#if defined(OSX)
|
|
|
|
#include <Carbon/Carbon.h>
|
|
|
|
#include <IOKit/ps/IOPowerSources.h>
|
|
|
|
#include <IOKit/ps/IOPSKeys.h>
|
2015-04-20 14:05:55 +02:00
|
|
|
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
2015-04-20 21:00:40 +02:00
|
|
|
CFApplicationDirectory = 1, /* Supported applications (Applications) */
|
|
|
|
CFDemoApplicationDirectory = 2, /* Unsupported applications, demonstration versions (Demos) */
|
|
|
|
CFDeveloperApplicationDirectory = 3, /* Developer applications (Developer/Applications). DEPRECATED - there is no one single Developer directory. */
|
|
|
|
CFAdminApplicationDirectory = 4, /* System and network administration applications (Administration) */
|
|
|
|
CFLibraryDirectory = 5, /* various documentation, support, and configuration files, resources (Library) */
|
|
|
|
CFDeveloperDirectory = 6, /* developer resources (Developer) DEPRECATED - there is no one single Developer directory. */
|
|
|
|
CFUserDirectory = 7, /* User home directories (Users) */
|
|
|
|
CFDocumentationDirectory = 8, /* Documentation (Documentation) */
|
|
|
|
CFDocumentDirectory = 9, /* Documents (Documents) */
|
|
|
|
CFCoreServiceDirectory = 10, /* Location of CoreServices directory (System/Library/CoreServices) */
|
|
|
|
CFAutosavedInformationDirectory = 11, /* Location of autosaved documents (Documents/Autosaved) */
|
|
|
|
CFDesktopDirectory = 12, /* Location of user's desktop */
|
|
|
|
CFCachesDirectory = 13, /* Location of discardable cache files (Library/Caches) */
|
|
|
|
CFApplicationSupportDirectory = 14, /* Location of application support files (plug-ins, etc) (Library/Application Support) */
|
|
|
|
CFDownloadsDirectory = 15, /* Location of the user's "Downloads" directory */
|
|
|
|
CFInputMethodsDirectory = 16, /* Input methods (Library/Input Methods) */
|
|
|
|
CFMoviesDirectory = 17, /* Location of user's Movies directory (~/Movies) */
|
|
|
|
CFMusicDirectory = 18, /* Location of user's Music directory (~/Music) */
|
|
|
|
CFPicturesDirectory = 19, /* Location of user's Pictures directory (~/Pictures) */
|
|
|
|
CFPrinterDescriptionDirectory = 20, /* Location of system's PPDs directory (Library/Printers/PPDs) */
|
|
|
|
CFSharedPublicDirectory = 21, /* Location of user's Public sharing directory (~/Public) */
|
|
|
|
CFPreferencePanesDirectory = 22, /* Location of the PreferencePanes directory for use with System Preferences (Library/PreferencePanes) */
|
|
|
|
CFApplicationScriptsDirectory = 23, /* Location of the user scripts folder for the calling application (~/Library/Application Scripts/code-signing-id) */
|
|
|
|
CFItemReplacementDirectory = 99, /* For use with NSFileManager's URLForDirectory:inDomain:appropriateForURL:create:error: */
|
|
|
|
CFAllApplicationsDirectory = 100, /* all directories where applications can occur */
|
|
|
|
CFAllLibrariesDirectory = 101, /* all directories where resources can occur */
|
|
|
|
CFTrashDirectory = 102 /* location of Trash directory */
|
2015-04-20 14:05:55 +02:00
|
|
|
} CFSearchPathDirectory;
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
2015-04-20 21:00:40 +02:00
|
|
|
CFUserDomainMask = 1, /* user's home directory --- place to install user's personal items (~) */
|
|
|
|
CFLocalDomainMask = 2, /* local to the current machine --- place to install items available to everyone on this machine (/Library) */
|
|
|
|
CFNetworkDomainMask = 4, /* publically available location in the local area network --- place to install items available on the network (/Network) */
|
|
|
|
CFSystemDomainMask = 8, /* provided by Apple, unmodifiable (/System) */
|
|
|
|
CFAllDomainsMask = 0x0ffff /* All domains: all of the above and future items */
|
2015-04-20 14:05:55 +02:00
|
|
|
} CFDomainMask;
|
|
|
|
|
|
|
|
#ifndef __has_feature
|
|
|
|
/* Compatibility with non-Clang compilers. */
|
|
|
|
#define __has_feature(x) 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CF_RETURNS_RETAINED
|
|
|
|
#if __has_feature(attribute_cf_returns_retained)
|
|
|
|
#define CF_RETURNS_RETAINED __attribute__((cf_returns_retained))
|
|
|
|
#else
|
|
|
|
#define CF_RETURNS_RETAINED
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
NS_INLINE CF_RETURNS_RETAINED CFTypeRef CFBridgingRetainCompat(id X)
|
|
|
|
{
|
|
|
|
#if __has_feature(objc_arc)
|
2015-04-20 14:07:45 +02:00
|
|
|
return (__bridge_retained CFTypeRef)X;
|
2015-04-20 14:05:55 +02:00
|
|
|
#else
|
2015-04-20 14:07:45 +02:00
|
|
|
return X;
|
2015-04-20 14:05:55 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static NSSearchPathDirectory NSConvertFlagsCF(unsigned flags)
|
|
|
|
{
|
2015-04-20 14:07:45 +02:00
|
|
|
switch (flags)
|
|
|
|
{
|
|
|
|
case CFDocumentDirectory:
|
|
|
|
return NSDocumentDirectory;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2015-04-20 14:05:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static NSSearchPathDomainMask NSConvertDomainFlagsCF(unsigned flags)
|
|
|
|
{
|
2015-04-20 14:07:45 +02:00
|
|
|
switch (flags)
|
|
|
|
{
|
|
|
|
case CFUserDomainMask:
|
|
|
|
return NSUserDomainMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2015-04-20 14:05:55 +02:00
|
|
|
}
|
|
|
|
|
2015-04-20 14:07:45 +02:00
|
|
|
static void CFSearchPathForDirectoriesInDomains(unsigned flags,
|
|
|
|
unsigned domain_mask, unsigned expand_tilde,
|
|
|
|
char *buf, size_t sizeof_buf)
|
2015-04-20 14:05:55 +02:00
|
|
|
{
|
|
|
|
CFTypeRef array_val = (CFTypeRef)CFBridgingRetainCompat(
|
|
|
|
NSSearchPathForDirectoriesInDomains(NSConvertFlagsCF(flags),
|
|
|
|
NSConvertDomainFlagsCF(domain_mask), (BOOL)expand_tilde));
|
|
|
|
CFArrayRef array = array_val ? CFRetain(array_val) : NULL;
|
|
|
|
CFTypeRef path_val = (CFTypeRef)CFArrayGetValueAtIndex(array, 0);
|
|
|
|
CFStringRef path = path_val ? CFRetain(path_val) : NULL;
|
|
|
|
if (!path || !array)
|
|
|
|
return;
|
2015-04-20 14:07:45 +02:00
|
|
|
|
2015-04-20 14:05:55 +02:00
|
|
|
CFStringGetCString(path, buf, sizeof_buf, kCFStringEncodingUTF8);
|
|
|
|
CFRelease(path);
|
|
|
|
CFRelease(array);
|
|
|
|
}
|
|
|
|
|
2015-04-20 14:07:45 +02:00
|
|
|
static void CFTemporaryDirectory(char *buf, size_t sizeof_buf)
|
2015-04-20 14:05:55 +02:00
|
|
|
{
|
|
|
|
#if __has_feature(objc_arc)
|
2015-04-20 14:07:45 +02:00
|
|
|
CFStringRef path = (__bridge_retained CFStringRef)NSTemporaryDirectory();
|
2015-04-20 14:05:55 +02:00
|
|
|
#else
|
2015-04-20 14:07:45 +02:00
|
|
|
CFStringRef path = (CFStringRef)NSTemporaryDirectory();
|
2015-04-18 15:07:04 +02:00
|
|
|
#endif
|
2015-04-20 14:07:45 +02:00
|
|
|
CFStringGetCString(path, buf, sizeof_buf, kCFStringEncodingUTF8);
|
2015-04-20 14:05:55 +02:00
|
|
|
}
|
2015-04-18 15:07:04 +02:00
|
|
|
|
|
|
|
#if defined(IOS)
|
2015-04-13 18:25:04 +02:00
|
|
|
void get_ios_version(int *major, int *minor);
|
2015-04-18 16:42:49 +02:00
|
|
|
|
|
|
|
enum frontend_powerstate ios_get_powerstate(int *seconds, int *percent);
|
2015-04-13 18:25:04 +02:00
|
|
|
#endif
|
|
|
|
|
2015-04-18 15:07:04 +02:00
|
|
|
#if defined(OSX)
|
2015-04-18 16:42:49 +02:00
|
|
|
|
2015-04-18 15:07:04 +02:00
|
|
|
#define PMGMT_STRMATCH(a,b) (CFStringCompare(a, b, 0) == kCFCompareEqualTo)
|
|
|
|
#define PMGMT_GETVAL(k,v) CFDictionaryGetValueIfPresent(dict, CFSTR(k), (const void **) v)
|
|
|
|
|
|
|
|
/* Note that AC power sources also include a laptop battery it is charging. */
|
|
|
|
static void checkps(CFDictionaryRef dict, bool * have_ac, bool * have_battery,
|
2015-04-20 14:07:45 +02:00
|
|
|
bool * charging, int *seconds, int *percent)
|
2015-04-18 15:07:04 +02:00
|
|
|
{
|
2015-04-20 14:07:45 +02:00
|
|
|
CFStringRef strval; /* don't CFRelease() this. */
|
|
|
|
CFBooleanRef bval;
|
|
|
|
CFNumberRef numval;
|
|
|
|
bool charge = false;
|
|
|
|
bool choose = false;
|
|
|
|
bool is_ac = false;
|
|
|
|
int secs = -1;
|
|
|
|
int maxpct = -1;
|
|
|
|
int pct = -1;
|
|
|
|
|
|
|
|
if ((PMGMT_GETVAL(kIOPSIsPresentKey, &bval)) && (bval == kCFBooleanFalse))
|
2015-04-20 21:00:40 +02:00
|
|
|
return;
|
2015-04-20 14:07:45 +02:00
|
|
|
|
|
|
|
if (!PMGMT_GETVAL(kIOPSPowerSourceStateKey, &strval))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (PMGMT_STRMATCH(strval, CFSTR(kIOPSACPowerValue)))
|
|
|
|
is_ac = *have_ac = true;
|
|
|
|
else if (!PMGMT_STRMATCH(strval, CFSTR(kIOPSBatteryPowerValue)))
|
|
|
|
return; /* not a battery? */
|
|
|
|
|
|
|
|
if ((PMGMT_GETVAL(kIOPSIsChargingKey, &bval)) && (bval == kCFBooleanTrue))
|
|
|
|
charge = true;
|
|
|
|
|
|
|
|
if (PMGMT_GETVAL(kIOPSMaxCapacityKey, &numval))
|
|
|
|
{
|
|
|
|
SInt32 val = -1;
|
|
|
|
CFNumberGetValue(numval, kCFNumberSInt32Type, &val);
|
|
|
|
if (val > 0)
|
|
|
|
{
|
|
|
|
*have_battery = true;
|
|
|
|
maxpct = (int) val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PMGMT_GETVAL(kIOPSMaxCapacityKey, &numval))
|
|
|
|
{
|
|
|
|
SInt32 val = -1;
|
|
|
|
CFNumberGetValue(numval, kCFNumberSInt32Type, &val);
|
|
|
|
if (val > 0)
|
|
|
|
{
|
|
|
|
*have_battery = true;
|
|
|
|
maxpct = (int) val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PMGMT_GETVAL(kIOPSTimeToEmptyKey, &numval))
|
|
|
|
{
|
|
|
|
SInt32 val = -1;
|
|
|
|
CFNumberGetValue(numval, kCFNumberSInt32Type, &val);
|
|
|
|
|
|
|
|
/* Mac OS X reports 0 minutes until empty if you're plugged in. :( */
|
|
|
|
if ((val == 0) && (is_ac))
|
|
|
|
val = -1; /* !!! FIXME: calc from timeToFull and capacity? */
|
|
|
|
|
|
|
|
secs = (int) val;
|
|
|
|
if (secs > 0)
|
|
|
|
secs *= 60; /* value is in minutes, so convert to seconds. */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PMGMT_GETVAL(kIOPSCurrentCapacityKey, &numval))
|
|
|
|
{
|
|
|
|
SInt32 val = -1;
|
|
|
|
CFNumberGetValue(numval, kCFNumberSInt32Type, &val);
|
|
|
|
pct = (int) val;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((pct > 0) && (maxpct > 0))
|
|
|
|
pct = (int) ((((double) pct) / ((double) maxpct)) * 100.0);
|
|
|
|
|
|
|
|
if (pct > 100)
|
|
|
|
pct = 100;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We pick the battery that claims to have the most minutes left.
|
|
|
|
* (failing a report of minutes, we'll take the highest percent.)
|
|
|
|
*/
|
|
|
|
if ((secs < 0) && (*seconds < 0))
|
|
|
|
{
|
|
|
|
if ((pct < 0) && (*percent < 0))
|
|
|
|
choose = true; /* at least we know there's a battery. */
|
|
|
|
if (pct > *percent)
|
|
|
|
choose = true;
|
|
|
|
}
|
|
|
|
else if (secs > *seconds)
|
|
|
|
choose = true;
|
|
|
|
|
|
|
|
if (choose)
|
|
|
|
{
|
|
|
|
*seconds = secs;
|
|
|
|
*percent = pct;
|
|
|
|
*charging = charge;
|
|
|
|
}
|
2015-04-18 15:07:04 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-04-20 17:19:51 +02:00
|
|
|
static void frontend_darwin_get_name(char *name, size_t sizeof_name)
|
2015-04-07 19:18:36 +02:00
|
|
|
{
|
2015-04-18 21:52:45 +02:00
|
|
|
#if defined(IOS)
|
2015-04-20 14:07:45 +02:00
|
|
|
struct utsname buffer;
|
|
|
|
|
|
|
|
if (uname(&buffer) != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
strlcpy(name, buffer.machine, sizeof_name);
|
2015-04-18 21:52:45 +02:00
|
|
|
#elif defined(OSX)
|
2015-04-20 14:07:45 +02:00
|
|
|
size_t length = 0;
|
|
|
|
sysctlbyname("hw.model", name, &length, NULL, 0);
|
2015-04-07 19:30:24 +02:00
|
|
|
#endif
|
2015-04-07 19:18:36 +02:00
|
|
|
}
|
|
|
|
|
2015-04-20 17:19:51 +02:00
|
|
|
static void frontend_darwin_get_os(char *name, size_t sizeof_name, int *major, int *minor)
|
2015-04-13 18:05:55 +02:00
|
|
|
{
|
|
|
|
(void)name;
|
|
|
|
(void)sizeof_name;
|
|
|
|
(void)major;
|
|
|
|
(void)minor;
|
2015-04-20 14:07:45 +02:00
|
|
|
|
2015-04-18 21:52:45 +02:00
|
|
|
#if defined(IOS)
|
2015-04-20 14:07:45 +02:00
|
|
|
get_ios_version(major, minor);
|
|
|
|
strlcpy(name, "iOS", sizeof_name);
|
2015-04-18 21:52:45 +02:00
|
|
|
#elif defined(OSX)
|
2015-04-20 14:07:45 +02:00
|
|
|
strlcpy(name, "OSX", sizeof_name);
|
2015-04-13 18:25:04 +02:00
|
|
|
#endif
|
2015-04-13 18:05:55 +02:00
|
|
|
}
|
|
|
|
|
2015-04-20 17:19:51 +02:00
|
|
|
static void frontend_darwin_get_environment_settings(int *argc, char *argv[],
|
2014-10-07 04:43:59 +02:00
|
|
|
void *args, void *params_data)
|
|
|
|
{
|
2015-03-13 00:54:44 +01:00
|
|
|
char temp_dir[PATH_MAX_LENGTH];
|
2015-03-13 01:33:45 +01:00
|
|
|
char bundle_path_buf[PATH_MAX_LENGTH], home_dir_buf[PATH_MAX_LENGTH];
|
2014-10-07 04:43:59 +02:00
|
|
|
CFURLRef bundle_url;
|
2015-01-09 02:12:08 +01:00
|
|
|
CFStringRef bundle_path;
|
2014-10-07 04:43:59 +02:00
|
|
|
CFBundleRef bundle = CFBundleGetMainBundle();
|
2015-04-20 14:07:45 +02:00
|
|
|
|
2015-03-13 01:22:20 +01:00
|
|
|
(void)temp_dir;
|
2015-01-09 02:12:08 +01:00
|
|
|
|
2014-10-07 04:43:59 +02:00
|
|
|
if (!bundle)
|
|
|
|
return;
|
2015-01-09 02:12:08 +01:00
|
|
|
|
|
|
|
bundle_url = CFBundleCopyBundleURL(bundle);
|
|
|
|
bundle_path = CFURLCopyPath(bundle_url);
|
2015-04-20 14:07:45 +02:00
|
|
|
|
2014-10-18 04:36:02 +02:00
|
|
|
CFStringGetCString(bundle_path, bundle_path_buf, sizeof(bundle_path_buf), kCFStringEncodingUTF8);
|
2014-10-07 16:51:25 +02:00
|
|
|
(void)home_dir_buf;
|
2015-03-13 01:21:20 +01:00
|
|
|
|
2015-03-13 00:54:44 +01:00
|
|
|
CFSearchPathForDirectoriesInDomains(CFDocumentDirectory, CFUserDomainMask, 1, home_dir_buf, sizeof(home_dir_buf));
|
2015-04-20 14:07:45 +02:00
|
|
|
|
2015-03-13 01:33:45 +01:00
|
|
|
#ifdef OSX
|
2015-04-20 14:07:45 +02:00
|
|
|
strlcat(home_dir_buf, "/RetroArch", sizeof(home_dir_buf));
|
2015-03-13 01:33:45 +01:00
|
|
|
#endif
|
2015-04-20 14:07:45 +02:00
|
|
|
|
2015-03-12 23:32:19 +01: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 01:33:45 +01:00
|
|
|
fill_pathname_join(g_defaults.overlay_dir, home_dir_buf, "overlays", sizeof(g_defaults.overlay_dir));
|
2015-04-07 07:25:53 +02:00
|
|
|
fill_pathname_join(g_defaults.autoconfig_dir, home_dir_buf, "autoconfig/hid", sizeof(g_defaults.autoconfig_dir));
|
2015-03-12 23:40:51 +01:00
|
|
|
fill_pathname_join(g_defaults.assets_dir, home_dir_buf, "assets", sizeof(g_defaults.assets_dir));
|
2015-03-13 01:33:45 +01:00
|
|
|
fill_pathname_join(g_defaults.system_dir, home_dir_buf, ".RetroArch", sizeof(g_defaults.system_dir));
|
2014-10-07 04:43:59 +02: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 01:33:45 +01: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 04:43:59 +02: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-04-20 14:07:45 +02:00
|
|
|
|
2015-03-13 01:33:45 +01:00
|
|
|
CFTemporaryDirectory(temp_dir, sizeof(temp_dir));
|
|
|
|
strlcpy(g_defaults.extraction_dir, temp_dir, sizeof(g_defaults.extraction_dir));
|
2015-04-20 14:07:45 +02:00
|
|
|
|
2015-03-13 01:33:45 +01:00
|
|
|
fill_pathname_join(g_defaults.shader_dir, home_dir_buf, "shaders_glsl", sizeof(g_defaults.shader_dir));
|
2015-04-20 14:07:45 +02:00
|
|
|
|
2015-03-13 03:47:25 +01:00
|
|
|
#if defined(OSX)
|
2015-03-13 03:49:42 +01:00
|
|
|
#ifdef HAVE_CG
|
2015-03-13 01:33:45 +01:00
|
|
|
fill_pathname_join(g_defaults.shader_dir, home_dir_buf, "shaders_cg", sizeof(g_defaults.shader_dir));
|
2015-03-13 03:49:42 +01:00
|
|
|
#endif
|
2015-04-20 14:07:45 +02: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));
|
2015-03-13 01:33:45 +01:00
|
|
|
#endif
|
2015-04-20 14:07:45 +02:00
|
|
|
|
2014-10-07 04:43:59 +02:00
|
|
|
path_mkdir(bundle_path_buf);
|
2015-04-20 14:07:45 +02:00
|
|
|
|
2014-10-07 04:55:14 +02:00
|
|
|
if (access(bundle_path_buf, 0755) != 0)
|
2014-10-07 04:43:59 +02:00
|
|
|
RARCH_ERR("Failed to create or access base directory: %s\n", bundle_path_buf);
|
2015-04-20 14:07:45 +02: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 04:43:59 +02:00
|
|
|
|
|
|
|
CFRelease(bundle_path);
|
|
|
|
CFRelease(bundle_url);
|
2014-05-03 07:11:23 +02:00
|
|
|
}
|
|
|
|
|
2015-04-20 17:19:51 +02:00
|
|
|
static void frontend_darwin_load_content(void)
|
2014-10-17 03:55:16 +02:00
|
|
|
{
|
2015-04-12 03:18:37 +02:00
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
const ui_companion_driver_t *ui = ui_companion_get_ptr();
|
2015-04-20 14:07:45 +02:00
|
|
|
|
2015-04-12 17:07:17 +02:00
|
|
|
if (ui && ui->notify_content_loaded)
|
2015-04-12 03:18:37 +02:00
|
|
|
ui->notify_content_loaded(driver->ui_companion_data);
|
2014-10-17 03:55:16 +02:00
|
|
|
}
|
|
|
|
|
2015-04-20 17:19:51 +02:00
|
|
|
static int frontend_darwin_get_rating(void)
|
2014-05-16 22:20:33 +02:00
|
|
|
{
|
2015-04-07 20:42:48 +02:00
|
|
|
char model[PATH_MAX_LENGTH];
|
2015-04-07 20:57:20 +02:00
|
|
|
|
2015-04-20 17:19:51 +02:00
|
|
|
frontend_darwin_get_name(model, sizeof(model));
|
2015-04-07 20:57:20 +02: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 20:42:48 +02:00
|
|
|
/* iPhone 4S */
|
|
|
|
if (strstr(model, "iPhone4,1"))
|
2015-04-07 20:57:20 +02:00
|
|
|
return 8;
|
|
|
|
|
2015-04-07 20:42:48 +02:00
|
|
|
/* iPad 2/iPad Mini 1 */
|
|
|
|
if (strstr(model, "iPad2"))
|
2015-04-07 20:57:20 +02: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 21:02:34 +02:00
|
|
|
/* iPad Mini 2/3 */
|
|
|
|
if ( strstr(model, "iPad4,4")
|
|
|
|
|| strstr(model, "iPad4,5")
|
|
|
|
|| strstr(model, "iPad4,6")
|
|
|
|
|| strstr(model, "iPad4,7")
|
|
|
|
|| strstr(model, "iPad4,8")
|
|
|
|
|| strstr(model, "iPad4,9")
|
2015-04-20 14:07:45 +02:00
|
|
|
)
|
2015-04-07 21:07:09 +02:00
|
|
|
return 15;
|
|
|
|
|
|
|
|
/* iPad Air */
|
|
|
|
if ( strstr(model, "iPad4,1")
|
|
|
|
|| strstr(model, "iPad4,2")
|
|
|
|
|| strstr(model, "iPad4,3")
|
|
|
|
)
|
2015-04-07 21:02:34 +02:00
|
|
|
return 16;
|
2015-04-07 20:57:20 +02:00
|
|
|
|
|
|
|
/* iPhone 6, iPhone 6 Plus */
|
|
|
|
if (strstr(model, "iPhone7"))
|
2015-04-07 21:02:34 +02:00
|
|
|
return 17;
|
2015-04-07 20:57:20 +02:00
|
|
|
|
2015-04-07 20:42:48 +02:00
|
|
|
/* iPad Air 2 */
|
|
|
|
if (strstr(model, "iPad5,3") || strstr(model, "iPad5,4"))
|
2015-04-07 20:59:06 +02:00
|
|
|
return 18;
|
2015-04-07 20:57:20 +02:00
|
|
|
|
2015-04-07 20:42:48 +02:00
|
|
|
/* TODO/FIXME -
|
2015-04-07 20:57:20 +02:00
|
|
|
- more ratings for more systems
|
|
|
|
- determine rating more intelligently*/
|
2014-05-16 22:20:33 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2015-04-07 19:18:36 +02:00
|
|
|
|
2015-04-20 17:19:51 +02:00
|
|
|
static enum frontend_powerstate frontend_darwin_get_powerstate(int *seconds, int *percent)
|
2015-04-18 15:07:04 +02:00
|
|
|
{
|
2015-04-18 15:09:03 +02:00
|
|
|
enum frontend_powerstate ret = FRONTEND_POWERSTATE_NONE;
|
2015-04-18 15:07:04 +02:00
|
|
|
#if defined(OSX)
|
2015-04-18 15:09:03 +02:00
|
|
|
CFIndex i, total;
|
|
|
|
CFArrayRef list;
|
|
|
|
bool have_ac, have_battery, charging;
|
|
|
|
CFTypeRef blob = IOPSCopyPowerSourcesInfo();
|
|
|
|
|
|
|
|
*seconds = -1;
|
|
|
|
*percent = -1;
|
|
|
|
|
|
|
|
if (!blob)
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
list = IOPSCopyPowerSourcesList(blob);
|
|
|
|
|
|
|
|
if (!list)
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
/* don't CFRelease() the list items, or dictionaries! */
|
|
|
|
have_ac = false;
|
|
|
|
have_battery = false;
|
|
|
|
charging = false;
|
|
|
|
total = CFArrayGetCount(list);
|
|
|
|
|
|
|
|
for (i = 0; i < total; i++)
|
|
|
|
{
|
|
|
|
CFTypeRef ps = (CFTypeRef)CFArrayGetValueAtIndex(list, i);
|
|
|
|
CFDictionaryRef dict = IOPSGetPowerSourceDescription(blob, ps);
|
|
|
|
if (dict)
|
|
|
|
checkps(dict, &have_ac, &have_battery, &charging,
|
|
|
|
seconds, percent);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!have_battery)
|
|
|
|
ret = FRONTEND_POWERSTATE_NO_SOURCE;
|
|
|
|
else if (charging)
|
|
|
|
ret = FRONTEND_POWERSTATE_CHARGING;
|
|
|
|
else if (have_ac)
|
|
|
|
ret = FRONTEND_POWERSTATE_CHARGED;
|
|
|
|
else
|
|
|
|
ret = FRONTEND_POWERSTATE_ON_POWER_SOURCE;
|
|
|
|
|
|
|
|
CFRelease(list);
|
|
|
|
end:
|
|
|
|
if (blob)
|
|
|
|
CFRelease(blob);
|
2015-04-18 16:42:49 +02:00
|
|
|
#elif defined(IOS)
|
|
|
|
ret = ios_get_powerstate(seconds, percent);
|
2015-04-18 15:07:04 +02:00
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
2015-04-13 18:05:55 +02:00
|
|
|
|
2015-04-20 17:19:51 +02:00
|
|
|
enum frontend_architecture frontend_darwin_get_architecture(void)
|
2015-04-18 20:03:59 +02:00
|
|
|
{
|
2015-04-18 21:14:30 +02:00
|
|
|
struct utsname buffer;
|
2015-04-20 14:07:45 +02:00
|
|
|
|
2015-04-18 21:14:30 +02:00
|
|
|
if (uname(&buffer) != 0)
|
|
|
|
return FRONTEND_ARCH_NONE;
|
2015-04-20 14:07:45 +02:00
|
|
|
|
2015-04-18 21:14:30 +02:00
|
|
|
#ifdef OSX
|
|
|
|
if (!strcmp(buffer.machine, "x86_64"))
|
2015-04-20 14:07:45 +02:00
|
|
|
return FRONTEND_ARCH_X86_64;
|
|
|
|
if (!strcmp(buffer.machine, "x86"))
|
|
|
|
return FRONTEND_ARCH_X86;
|
|
|
|
if (!strcmp(buffer.machine, "Power Macintosh"))
|
|
|
|
return FRONTEND_ARCH_PPC;
|
2015-04-18 21:14:30 +02:00
|
|
|
#endif
|
2015-04-20 14:07:45 +02:00
|
|
|
|
2015-04-18 20:03:59 +02:00
|
|
|
return FRONTEND_ARCH_NONE;
|
|
|
|
}
|
2015-04-13 18:05:55 +02:00
|
|
|
|
2015-04-20 17:19:51 +02:00
|
|
|
const frontend_ctx_driver_t frontend_ctx_darwin = {
|
|
|
|
frontend_darwin_get_environment_settings,
|
2013-07-27 17:40:21 +02:00
|
|
|
NULL, /* init */
|
|
|
|
NULL, /* deinit */
|
|
|
|
NULL, /* exitspawn */
|
|
|
|
NULL, /* process_args */
|
|
|
|
NULL, /* exec */
|
2014-10-02 21:39:29 +02:00
|
|
|
NULL, /* set_fork */
|
2015-04-20 17:10:28 +02:00
|
|
|
NULL, /* shutdown */
|
2015-04-20 17:19:51 +02:00
|
|
|
frontend_darwin_get_name,
|
|
|
|
frontend_darwin_get_os,
|
|
|
|
frontend_darwin_get_rating,
|
|
|
|
frontend_darwin_load_content,
|
|
|
|
frontend_darwin_get_architecture,
|
|
|
|
frontend_darwin_get_powerstate,
|
|
|
|
"darwin",
|
2013-07-27 17:40:21 +02:00
|
|
|
};
|