From 95926cb7fc6faae6a460bcde2cc32c205fcc0c9e Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 21 Mar 2013 17:02:41 -0700 Subject: [PATCH] conditional chdir for OS X resources, revert windows Head changes --- interface/src/Audio.cpp | 4 +++- interface/src/Head.cpp | 6 ++++-- interface/src/main.cpp | 1 + shared/src/SharedUtil.cpp | 20 ++++++++++++++++++++ shared/src/SharedUtil.h | 2 ++ 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index c62303d6f4..5fc5d55dcf 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -438,7 +438,9 @@ Audio::Audio(Oscilloscope *s, Head *linkedHead) { // read the walking sound from the raw file and store it // in the in memory array - FILE *soundFile = fopen("interface.app/Contents/Resources/audio/walking.raw", "r"); + + switchToResourcesIfRequired(); + FILE *soundFile = fopen("audio/walking.raw", "r"); // get length of file: std::fseek(soundFile, 0, SEEK_END); diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 7b7445f7e2..4f22d010e0 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -8,11 +8,12 @@ #include #include -#include "Head.h" #include #include #include #include +#include +#include "Head.h" using namespace std; @@ -31,7 +32,7 @@ float browThickness = 0.16; const float DECAY = 0.1; -char iris_texture_file[] = "interface.app/Contents/Resources/images/green_eye.png"; +char iris_texture_file[] = "images/green_eye.png"; vector iris_texture; unsigned int iris_texture_width = 512; @@ -77,6 +78,7 @@ Head::Head() hand = new Hand(glm::vec3(skinColor[0], skinColor[1], skinColor[2])); if (iris_texture.size() == 0) { + switchToResourcesIfRequired(); unsigned error = lodepng::decode(iris_texture, iris_texture_width, iris_texture_height, iris_texture_file); if (error != 0) { std::cout << "error " << error << ": " << lodepng_error_text(error) << std::endl; diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 574c5d2812..ed04b45403 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -921,6 +921,7 @@ int main(int argc, char** argv) } } #endif + // Lookup the IP address of things we have hostnames if (atoi(DOMAIN_IP) == 0) { struct hostent* pHostInfo; diff --git a/shared/src/SharedUtil.cpp b/shared/src/SharedUtil.cpp index a272177097..72dca7277a 100644 --- a/shared/src/SharedUtil.cpp +++ b/shared/src/SharedUtil.cpp @@ -10,6 +10,10 @@ #include #include "SharedUtil.h" +#ifdef __APPLE__ +#include +#endif + double usecTimestamp(timeval *time) { return (time->tv_sec * 1000000.0 + time->tv_usec); } @@ -55,4 +59,20 @@ int numberOfOnes(unsigned char byte) { bool oneAtBit(unsigned char byte, int bitIndex) { return (byte >> (7 - bitIndex) & 1); +} + +void switchToResourcesIfRequired() { +#ifdef __APPLE__ + CFBundleRef mainBundle = CFBundleGetMainBundle(); + CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle); + char path[PATH_MAX]; + if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX)) // Error: expected unqualified-id before 'if' + { + // error! + } + CFRelease(resourcesURL); // error: expected constructor, destructor or type conversion before '(' token + + chdir(path); // error: expected constructor, destructor or type conversion before '(' token + std::cout << "Current Path: " << path << std::endl; // error: expected constructor, destructor or type conversion before '<<' token +#endif } \ No newline at end of file diff --git a/shared/src/SharedUtil.h b/shared/src/SharedUtil.h index 967d0e9786..3c53721deb 100644 --- a/shared/src/SharedUtil.h +++ b/shared/src/SharedUtil.h @@ -29,4 +29,6 @@ void outputBits(unsigned char byte); int numberOfOnes(unsigned char byte); bool oneAtBit(unsigned char byte, int bitIndex); +void switchToResourcesIfRequired(); + #endif /* defined(__hifi__SharedUtil__) */