Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/Mac/Ogre/src/macPlugins.cpp @ 8

Last change on this file since 8 was 8, checked in by anonymous, 17 years ago

mac ordner

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