forked from yvt/xtbook
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOSXSpecific.mm
68 lines (59 loc) · 1.72 KB
/
OSXSpecific.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* OSXSpecific.m
* XTBook
*
* Created by Nexhawks on 12/22/10.
* Copyright 2011 Nexhawks. All rights reserved.
*/
#import "OSXSpecific.h"
using namespace std;
void showErrorAlert(const char *str){
NSAlert *alert=[NSAlert alertWithMessageText:@"Error while initializing XTBook."
defaultButton:@"Exit"
alternateButton:nil
otherButton:nil
informativeTextWithFormat:@"%@", [NSString stringWithUTF8String:str]];
[alert runModal];
}
void showOpenPanel(const char *ext, char *fnOut){
NSOpenPanel *panel;
NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];
panel=[NSOpenPanel openPanel];
[panel setAllowedFileTypes:[NSArray arrayWithObject:[NSString stringWithUTF8String:ext]]];
[panel setAllowsMultipleSelection:NO];
[panel setCanChooseDirectories:NO];
[panel setCanChooseFiles:YES];
if([panel runModal]==NSFileHandlingPanelOKButton){
NSURL *url=[panel URL];
NSString *path=[url path];
strcpy(fnOut, [path UTF8String]);
}else{
fnOut[0]=0;
}
[pool drain];
}
/*
// DEPRECATED.
std::vector<std::string> pathsInBundleResourceDirectory(const char *dirName, const char *fileType){
NSArray *paths;
NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];
paths=[[NSBundle mainBundle] pathsForResourcesOfType:[NSString stringWithUTF8String:fileType]
inDirectory:[NSString stringWithUTF8String:dirName]];
vector<string> ret;
for(NSString *path in paths){
std::string str;
str=[path UTF8String];
ret.push_back(str);
}
[pool drain];
return ret;
}
*/
std::string appDirOSX(){
NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];
NSString *str;
str=[[NSBundle mainBundle] resourcePath];
string ret=[str UTF8String];
[pool drain];
return ret;
}