From 9c6fcc7be58a9e1ebe39fbf7d4347b745d61b867 Mon Sep 17 00:00:00 2001 From: Ardekantur Date: Thu, 24 Jun 2010 21:24:16 -0400 Subject: [PATCH] Mac Build - Fix bundle directory location --- game/engine.cpp | 20 ++++++++++++++++---- game/main.cpp | 13 +++++++------ tools/fileops.cpp | 26 ++++++++++++++++++++++++++ tools/fileops.hpp | 6 ++++++ 4 files changed, 55 insertions(+), 10 deletions(-) diff --git a/game/engine.cpp b/game/engine.cpp index e23f8272a..9cb3d90b6 100644 --- a/game/engine.cpp +++ b/game/engine.cpp @@ -56,7 +56,12 @@ void OMW::Engine::addResourcesDirectory (const boost::filesystem::path& path) void OMW::Engine::setDataDir (const boost::filesystem::path& dataDir) { - mDataDir = boost::filesystem::system_complete (dataDir); +#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE + mDataDir = boost::filesystem::system_complete (macBundlePath() + "/Contents/MacOS/" + dataDir.directory_string()); +#else + mDataDir = boost::filesystem::system_complete (dataDir); +#endif + } // Set start cell name (only interiors for now) @@ -85,14 +90,21 @@ void OMW::Engine::go() assert (!mMaster.empty()); std::cout << "Hello, fellow traveler!\n"; - + std::cout << "Your data directory for today is: " << mDataDir << "\n"; std::cout << "Initializing OGRE\n"; + + std::string plugin_cfg_location = "plugins.cfg"; + std::string ogre_cfg_location = "ogre.cfg"; - const char* plugCfg = "plugins.cfg"; +#ifdef OGRE_PLATFORM == OGRE_PLATFORM_APPLE + std::cout << "[Apple]" << std::endl; + plugin_cfg_location = macBundlePath() + "/Contents/MacOS/" + plugin_cfg_location; + ogre_cfg_location = macBundlePath() + "/Contents/MacOS/" + ogre_cfg_location; +#endif - mOgre.configure(!isFile("ogre.cfg"), plugCfg, false); + mOgre.configure(!isFile(ogre_cfg_location.c_str()), plugin_cfg_location.c_str(), false); addResourcesDirectory (mDataDir / "Meshes"); addResourcesDirectory (mDataDir / "Textures"); diff --git a/game/main.cpp b/game/main.cpp index 477e4aba9..3cb6b5b38 100644 --- a/game/main.cpp +++ b/game/main.cpp @@ -5,6 +5,7 @@ #include +#include "tools/fileops.hpp" #include "engine.hpp" using namespace std; @@ -30,18 +31,18 @@ bool parseOptions (int argc, char**argv, OMW::Engine& engine) boost::program_options::variables_map variables; - std::ifstream configFile ("openmw.cfg"); +#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE + std::string configFilePath(macBundlePath() + "/Contents/MacOS/openmw.cfg"); + std::ifstream configFile (configFilePath.c_str()); +#else + std::ifstream configFile ("openmw.cfg"); +#endif boost::program_options::parsed_options valid_opts = boost::program_options::command_line_parser(argc, argv).options(desc).allow_unregistered().run(); boost::program_options::store(valid_opts, variables); boost::program_options::notify(variables); - /* - boost::program_options::store ( - boost::program_options::parse_command_line (argc, argv, desc), variables); - boost::program_options::notify (variables); - */ if (configFile.is_open()) boost::program_options::store ( diff --git a/tools/fileops.cpp b/tools/fileops.cpp index bb859836b..b7e3b389e 100644 --- a/tools/fileops.cpp +++ b/tools/fileops.cpp @@ -1,8 +1,34 @@ #include "fileops.hpp" #include +#include + bool isFile(const char *name) { boost::filesystem::path cfg_file_path(name); return boost::filesystem::exists(cfg_file_path); } + +#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE +#include + +std::string macBundlePath() +{ + char path[1024]; + CFBundleRef mainBundle = CFBundleGetMainBundle(); + assert(mainBundle); + + CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle); + assert(mainBundleURL); + + CFStringRef cfStringRef = CFURLCopyFileSystemPath(mainBundleURL, kCFURLPOSIXPathStyle); + assert(cfStringRef); + + CFStringGetCString(cfStringRef, path, 1024, kCFStringEncodingASCII); + + CFRelease(mainBundleURL); + CFRelease(cfStringRef); + + return std::string(path); +} +#endif diff --git a/tools/fileops.hpp b/tools/fileops.hpp index 6a5ad7c61..004f01dd6 100644 --- a/tools/fileops.hpp +++ b/tools/fileops.hpp @@ -1,7 +1,13 @@ #ifndef __FILEOPS_H_ #define __FILEOPS_H_ +#include + /// Check if a given path is an existing file (not a directory) bool isFile(const char *name); +#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE +std::string macBundlePath(); +#endif + #endif