2014-10-16 21:03:24 +00:00
|
|
|
#include "compat.h"
|
2006-04-13 20:47:06 +00:00
|
|
|
#include "osxbits.h"
|
2014-10-20 07:37:29 +00:00
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
#import <AppKit/AppKit.h>
|
2006-07-01 01:40:18 +00:00
|
|
|
|
|
|
|
#ifndef MAC_OS_VERSION_10_3
|
|
|
|
# define MAC_OS_VERSION_10_3 1030
|
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2014-10-16 21:03:24 +00:00
|
|
|
int osx_msgbox(const char *name, const char *msg)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2014-10-16 21:03:24 +00:00
|
|
|
NSString *mmsg = [[NSString alloc] initWithUTF8String:msg];
|
2006-07-01 01:40:18 +00:00
|
|
|
|
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
|
|
|
|
NSAlert *alert = [[NSAlert alloc] init];
|
2006-04-13 20:47:06 +00:00
|
|
|
[alert addButtonWithTitle: @"OK"];
|
2006-07-01 01:40:18 +00:00
|
|
|
[alert setInformativeText: mmsg];
|
2006-04-13 20:47:06 +00:00
|
|
|
[alert setAlertStyle: NSInformationalAlertStyle];
|
2014-10-16 21:03:24 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
[alert runModal];
|
2014-10-16 21:03:24 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
[alert release];
|
2006-07-01 01:40:18 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
NSRunAlertPanel(nil, mmsg, @"OK", nil, nil);
|
|
|
|
#endif
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
[mmsg release];
|
2014-10-16 21:03:24 +00:00
|
|
|
|
|
|
|
UNREFERENCED_PARAMETER(name);
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-16 21:03:24 +00:00
|
|
|
int osx_ynbox(const char *name, const char *msg)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2014-10-16 21:03:24 +00:00
|
|
|
NSString *mmsg = [[NSString alloc] initWithUTF8String:msg];
|
2006-04-13 20:47:06 +00:00
|
|
|
int r;
|
|
|
|
|
2006-07-01 01:40:18 +00:00
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
|
|
|
|
NSAlert *alert = [[NSAlert alloc] init];
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
[alert addButtonWithTitle:@"Yes"];
|
|
|
|
[alert addButtonWithTitle:@"No"];
|
2006-07-01 01:40:18 +00:00
|
|
|
[alert setInformativeText: mmsg];
|
2006-04-13 20:47:06 +00:00
|
|
|
[alert setAlertStyle: NSInformationalAlertStyle];
|
2014-10-16 21:03:24 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
r = ([alert runModal] == NSAlertFirstButtonReturn);
|
|
|
|
|
|
|
|
[alert release];
|
2006-07-01 01:40:18 +00:00
|
|
|
#else
|
|
|
|
r = (NSRunAlertPanel(nil, mmsg, @"Yes", @"No", nil) == NSAlertDefaultReturn);
|
|
|
|
#endif
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
[mmsg release];
|
2014-10-16 21:03:24 +00:00
|
|
|
|
|
|
|
UNREFERENCED_PARAMETER(name);
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
return r;
|
|
|
|
}
|
2014-12-08 04:31:57 +00:00
|
|
|
|
|
|
|
char *osx_gethomedir(void)
|
|
|
|
{
|
|
|
|
NSString *path = NSHomeDirectory();
|
|
|
|
const char *Cpath = [path UTF8String];
|
|
|
|
char *returnpath = NULL;
|
|
|
|
|
|
|
|
if (Cpath)
|
|
|
|
returnpath = Bstrdup(Cpath);
|
|
|
|
|
|
|
|
[path release];
|
|
|
|
|
|
|
|
return returnpath;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *osx_getsupportdir(void)
|
|
|
|
{
|
|
|
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
|
|
|
|
char *returnpath = NULL;
|
|
|
|
|
|
|
|
if ([paths count] > 0)
|
|
|
|
{
|
|
|
|
const char *Cpath = [[paths objectAtIndex:0] UTF8String];
|
|
|
|
|
|
|
|
if (Cpath)
|
|
|
|
returnpath = Bstrdup(Cpath);
|
|
|
|
}
|
|
|
|
|
|
|
|
[paths release];
|
|
|
|
|
|
|
|
return returnpath;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *osx_getappdir(void)
|
|
|
|
{
|
|
|
|
CFBundleRef mainBundle;
|
|
|
|
CFURLRef resUrl, fullUrl;
|
|
|
|
CFStringRef str;
|
|
|
|
const char *s;
|
|
|
|
char *dir = NULL;
|
|
|
|
|
|
|
|
mainBundle = CFBundleGetMainBundle();
|
|
|
|
if (!mainBundle) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
resUrl = CFBundleCopyResourcesDirectoryURL(mainBundle);
|
|
|
|
CFRelease(mainBundle);
|
|
|
|
if (!resUrl) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
fullUrl = CFURLCopyAbsoluteURL(resUrl);
|
|
|
|
if (fullUrl) {
|
|
|
|
CFRelease(resUrl);
|
|
|
|
resUrl = fullUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
str = CFURLCopyFileSystemPath(resUrl, kCFURLPOSIXPathStyle);
|
|
|
|
CFRelease(resUrl);
|
|
|
|
if (!str) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
s = CFStringGetCStringPtr(str, CFStringGetSystemEncoding());
|
|
|
|
if (s) {
|
|
|
|
dir = strdup(s);
|
|
|
|
}
|
|
|
|
CFRelease(str);
|
|
|
|
|
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *osx_getapplicationsdir(void)
|
|
|
|
{
|
|
|
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSAllApplicationsDirectory, NSLocalDomainMask, YES);
|
|
|
|
char *returnpath = NULL;
|
|
|
|
|
|
|
|
if ([paths count] > 0)
|
|
|
|
{
|
|
|
|
const char *Cpath = [[paths objectAtIndex:0] UTF8String];
|
|
|
|
|
|
|
|
if (Cpath)
|
|
|
|
returnpath = Bstrdup(Cpath);
|
|
|
|
}
|
|
|
|
|
|
|
|
[paths release];
|
|
|
|
|
|
|
|
return returnpath;
|
|
|
|
}
|