goat3dgfx

view src/datapath.cc @ 9:25b911c7c35c

fixed some line endings fixed the cubemap2.jpg file in examples/cubemap/data which was resized improperly causing seams...
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 18 Nov 2013 04:10:19 +0200
parents
children 7d6b667821cf
line source
1 #include <stdio.h>
2 #include <set>
3 #include <string>
4 #include "logger.h"
5 #include "datapath.h"
7 static std::set<std::string> paths;
9 void add_data_path(const char *path)
10 {
11 paths.insert(path);
12 }
14 #ifndef TARGET_IPHONE
15 std::string datafile_path(const char *fname)
16 {
17 std::string res;
18 if(!fname) {
19 return res;
20 }
22 std::set<std::string>::const_iterator it = paths.begin();
23 while(it != paths.end()) {
24 const std::string &path = *it++;
25 res = path + "/" + std::string(fname);
26 FILE *fp = fopen(res.c_str(), "r");
27 if(fp) {
28 fclose(fp);
29 return res;
30 }
31 }
33 // It's not found. Return the name itself just in case it's right here
34 return std::string(fname);
35 }
36 #else
37 #include <CoreFoundation/CoreFoundation.h>
39 std::string datafile_path(const char *fname)
40 {
41 std::string res;
42 if(!fname) {
43 return res;
44 }
46 CFBundleRef bundle;
47 CFURLRef url;
48 CFStringRef cfname;
50 cfname = CFStringCreateWithCString(0, fname, kCFStringEncodingASCII);
52 bundle = CFBundleGetMainBundle();
53 if(!(url = CFBundleCopyResourceURL(bundle, cfname, 0, 0))) {
54 CFRelease(cfname);
55 return fname;
56 }
57 CFRelease(cfname);
59 char path[1024];
60 if(!CFURLGetFileSystemRepresentation(url, 1, (unsigned char*)path, sizeof path)) {
61 CFRelease(url);
62 return fname;
63 }
64 CFRelease(url);
65 return std::string(path);
66 }
67 #endif