1 | /*
|
---|
2 | -----------------------------------------------------------------------------
|
---|
3 | This source file is part of OGRE
|
---|
4 | (Object-oriented Graphics Rendering Engine)
|
---|
5 | For the latest info, see http://www.ogre3d.org/
|
---|
6 |
|
---|
7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
8 | Also see acknowledgements in Readme.html
|
---|
9 |
|
---|
10 | This program is free software; you can redistribute it and/or modify it under
|
---|
11 | the terms of the GNU Lesser General License as published by the Free Software
|
---|
12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
13 | version.
|
---|
14 |
|
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU Lesser General License along with
|
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
23 | -----------------------------------------------------------------------------
|
---|
24 | */
|
---|
25 |
|
---|
26 | #include <CoreFoundation/CoreFoundation.h>
|
---|
27 |
|
---|
28 | #include "OgreString.h"
|
---|
29 | #include "macPlugins.h"
|
---|
30 |
|
---|
31 | namespace Ogre {
|
---|
32 |
|
---|
33 | CFBundleRef mac_loadExeBundle(const char *name) {
|
---|
34 | CFBundleRef baseBundle = CFBundleGetBundleWithIdentifier(CFSTR("org.ogre3d.Ogre"));
|
---|
35 | CFBundleRef mainBundle = CFBundleGetMainBundle();
|
---|
36 | CFStringRef nameRef = CFStringCreateWithCString(NULL, name, kCFStringEncodingASCII);
|
---|
37 | CFURLRef bundleURL = 0; //URL of bundle to load
|
---|
38 | CFBundleRef bundle = 0; //bundle to load
|
---|
39 |
|
---|
40 | //cut off .bundle if present
|
---|
41 | if(CFStringHasSuffix(nameRef, CFSTR(".bundle"))) {
|
---|
42 | CFStringRef nameTempRef = nameRef;
|
---|
43 | int end = CFStringGetLength(nameTempRef) - CFStringGetLength(CFSTR(".bundle"));
|
---|
44 | nameRef = CFStringCreateWithSubstring(NULL, nameTempRef, CFRangeMake(0, end));
|
---|
45 | CFRelease(nameTempRef);
|
---|
46 | }
|
---|
47 |
|
---|
48 | //assume relative to Resources/ directory of Main bundle
|
---|
49 | bundleURL = CFBundleCopyResourceURL(mainBundle, nameRef, CFSTR("bundle"), NULL);
|
---|
50 | if(bundleURL) {
|
---|
51 | bundle = CFBundleCreate(NULL, bundleURL);
|
---|
52 | CFRelease(bundleURL);
|
---|
53 | }
|
---|
54 |
|
---|
55 | //otherwise, try Resources/ directory of Ogre Framework bundle
|
---|
56 | if(!bundle) {
|
---|
57 | bundleURL = CFBundleCopyResourceURL(baseBundle, nameRef, CFSTR("bundle"), NULL);
|
---|
58 | if(bundleURL) {
|
---|
59 | bundle = CFBundleCreate(NULL, bundleURL);
|
---|
60 | CFRelease(bundleURL);
|
---|
61 | }
|
---|
62 | }
|
---|
63 | CFRelease(nameRef);
|
---|
64 |
|
---|
65 | if(bundle) {
|
---|
66 | if(CFBundleLoadExecutable(bundle)) {
|
---|
67 | return bundle;
|
---|
68 | }
|
---|
69 | else {
|
---|
70 | CFRelease(bundle);
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | return 0;
|
---|
75 | }
|
---|
76 |
|
---|
77 | void *mac_getBundleSym(CFBundleRef bundle, const char *name) {
|
---|
78 | CFStringRef nameRef = CFStringCreateWithCString(NULL, name, kCFStringEncodingASCII);
|
---|
79 | void *sym = CFBundleGetFunctionPointerForName(bundle, nameRef);
|
---|
80 | CFRelease(nameRef);
|
---|
81 | return sym;
|
---|
82 | }
|
---|
83 |
|
---|
84 | //returns 1 on error, 0 otherwise
|
---|
85 | bool mac_unloadExeBundle(CFBundleRef bundle) {
|
---|
86 | if(bundle) {
|
---|
87 | //no-op, can't unload Obj-C bundles without crashing
|
---|
88 | return 0;
|
---|
89 | }
|
---|
90 | return 1;
|
---|
91 | }
|
---|
92 |
|
---|
93 | const char *mac_errorBundle() {
|
---|
94 | return "Unknown Error";
|
---|
95 | }
|
---|
96 |
|
---|
97 | } |
---|