mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2024-12-30 14:21:51 +00:00
Fixed bugs in OS X alert code and simplified; added more NULL checks in OS X resource code
This commit is contained in:
parent
df89563882
commit
bb90c8366a
2 changed files with 41 additions and 14 deletions
|
@ -25,19 +25,38 @@
|
||||||
#include "mac_alert.h"
|
#include "mac_alert.h"
|
||||||
#include <CoreFoundation/CoreFoundation.h>
|
#include <CoreFoundation/CoreFoundation.h>
|
||||||
|
|
||||||
|
#define CFSTRINGIFY(x) CFStringCreateWithCString(NULL, x, kCFStringEncodingASCII)
|
||||||
|
|
||||||
int MacShowAlert(const char *title, const char *message, const char *button1, const char *button2, const char *button3)
|
int MacShowAlert(const char *title, const char *message, const char *button1, const char *button2, const char *button3)
|
||||||
{
|
{
|
||||||
CFOptionFlags results;
|
CFOptionFlags results;
|
||||||
|
|
||||||
CFUserNotificationDisplayAlert(0,
|
CFStringRef cf_title = CFSTRINGIFY(title);
|
||||||
kCFUserNotificationStopAlertLevel | kCFUserNotificationNoDefaultButtonFlag,
|
CFStringRef cf_message = CFSTRINGIFY(message);
|
||||||
NULL, NULL, NULL,
|
CFStringRef cf_button1 = NULL;
|
||||||
CFStringCreateWithCString(NULL, title, kCFStringEncodingASCII),
|
CFStringRef cf_button2 = NULL;
|
||||||
CFStringCreateWithCString(NULL, message, kCFStringEncodingASCII),
|
CFStringRef cf_button3 = NULL;
|
||||||
button1 != NULL ? CFStringCreateWithCString(NULL, button1, kCFStringEncodingASCII) : NULL,
|
|
||||||
button2 != NULL ? CFStringCreateWithCString(NULL, button2, kCFStringEncodingASCII) : NULL,
|
if (button1 != NULL)
|
||||||
button3 != NULL ? CFStringCreateWithCString(NULL, button3, kCFStringEncodingASCII) : NULL,
|
cf_button1 = CFSTRINGIFY(button1);
|
||||||
&results);
|
if (button2 != NULL)
|
||||||
|
cf_button2 = CFSTRINGIFY(button2);
|
||||||
|
if (button3 != NULL)
|
||||||
|
cf_button3 = CFSTRINGIFY(button3);
|
||||||
|
|
||||||
|
CFOptionFlags alert_flags = kCFUserNotificationStopAlertLevel | kCFUserNotificationNoDefaultButtonFlag;
|
||||||
|
|
||||||
|
CFUserNotificationDisplayAlert(0, alert_flags, NULL, NULL, NULL, cf_title, cf_message,
|
||||||
|
cf_button1, cf_button2, cf_button3, &results);
|
||||||
|
|
||||||
|
if (cf_button1 != NULL)
|
||||||
|
CFRelease(cf_button1);
|
||||||
|
if (cf_button2 != NULL)
|
||||||
|
CFRelease(cf_button2);
|
||||||
|
if (cf_button3 != NULL)
|
||||||
|
CFRelease(cf_button3);
|
||||||
|
CFRelease(cf_message);
|
||||||
|
CFRelease(cf_title);
|
||||||
|
|
||||||
return (int)results;
|
return (int)results;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,11 +12,20 @@ void OSX_GetResourcesPath(char * buffer)
|
||||||
const int BUF_SIZE = 256; // because we somehow always know that
|
const int BUF_SIZE = 256; // because we somehow always know that
|
||||||
|
|
||||||
CFURLRef appUrlRef = CFBundleCopyBundleURL(mainBundle);
|
CFURLRef appUrlRef = CFBundleCopyBundleURL(mainBundle);
|
||||||
CFStringRef macPath = CFURLCopyFileSystemPath(appUrlRef, kCFURLPOSIXPathStyle);
|
CFStringRef macPath;
|
||||||
|
if (appUrlRef != NULL)
|
||||||
|
macPath = CFURLCopyFileSystemPath(appUrlRef, kCFURLPOSIXPathStyle);
|
||||||
|
else
|
||||||
|
macPath = NULL;
|
||||||
|
|
||||||
const char* rawPath = CFStringGetCStringPtr(macPath, kCFStringEncodingASCII);
|
const char* rawPath;
|
||||||
|
|
||||||
if (CFStringGetLength(macPath) + strlen("/Contents/Resources") < BUF_SIZE)
|
if (macPath != NULL)
|
||||||
|
rawPath = CFStringGetCStringPtr(macPath, kCFStringEncodingASCII);
|
||||||
|
else
|
||||||
|
rawPath = NULL;
|
||||||
|
|
||||||
|
if (rawPath != NULL && (CFStringGetLength(macPath) + strlen("/Contents/Resources") < BUF_SIZE))
|
||||||
{
|
{
|
||||||
strcpy(buffer, rawPath);
|
strcpy(buffer, rawPath);
|
||||||
strcat(buffer, "/Contents/Resources");
|
strcat(buffer, "/Contents/Resources");
|
||||||
|
@ -25,5 +34,4 @@ void OSX_GetResourcesPath(char * buffer)
|
||||||
CFRelease(macPath);
|
CFRelease(macPath);
|
||||||
CFRelease(appUrlRef);
|
CFRelease(appUrlRef);
|
||||||
}
|
}
|
||||||
CFRelease(mainBundle);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue