From d6b91f8fc306a8cec42674ed57fa5ca0b7a0f13b Mon Sep 17 00:00:00 2001 From: hikerstk Date: Tue, 12 Jan 2010 02:02:13 +0000 Subject: [PATCH] Applied Stephen Just's patch 2926028: search for data directory relative to the executable, which allows STK to be started/debugged in VS without having to set a working directory. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@4439 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/io/file_manager.cpp | 20 ++++++++++++++++---- src/io/file_manager.hpp | 2 +- src/main.cpp | 7 ++++--- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/io/file_manager.cpp b/src/io/file_manager.cpp index 970fcb4d7..b5791f38c 100644 --- a/src/io/file_manager.cpp +++ b/src/io/file_manager.cpp @@ -90,7 +90,7 @@ FileManager* file_manager = 0; * exists) changed in reInit(). * */ -FileManager::FileManager() +FileManager::FileManager(char *argv[]) { #ifdef __APPLE__ // irrLicht's createDevice method has a nasty habit of messing the CWD. @@ -108,18 +108,30 @@ FileManager::FileManager() m_file_system = m_device->getFileSystem(); m_is_full_path = false; + irr::io::path exe_path; + + // Also check for data dirs relative to the path of the executable. + // This is esp. useful for Visual Studio, since it's not necessary + // to define the working directory when debugging, it works automatically. + if(m_file_system->existFile(argv[0])) + exe_path = m_file_system->getFileDir(argv[0]); + if ( getenv ( "SUPERTUXKART_DATADIR" ) != NULL ) m_root_dir= getenv ( "SUPERTUXKART_DATADIR" ) ; #ifdef __APPLE__ else if( macSetBundlePathIfRelevant( m_root_dir ) ) { /* nothing to do */ } #endif - // else if(m_file_system->existFile("/Developer/games/supertuxkart/data/stk_config.xml")) - // m_root_dir = "/Developer/games/supertuxkart" ; - // FIXME - existFile() fails to detect the file, even though it exists, on my computer else if(m_file_system->existFile("data/stk_config.xml")) m_root_dir = "." ; else if(m_file_system->existFile("../data/stk_config.xml")) m_root_dir = ".." ; + else if(m_file_system->existFile(exe_path+"/data/stk_config.xml")) + m_root_dir = exe_path.c_str(); + else if(m_file_system->existFile(exe_path+"/../data/stk_config.xml")) + { + m_root_dir = exe_path.c_str(); + m_root_dir += "/.."; + } else #ifdef SUPERTUXKART_DATADIR m_root_dir = SUPERTUXKART_DATADIR ; diff --git a/src/io/file_manager.hpp b/src/io/file_manager.hpp index 541276c40..d8f939881 100644 --- a/src/io/file_manager.hpp +++ b/src/io/file_manager.hpp @@ -53,7 +53,7 @@ private: io::path createAbsoluteFilename(const std::string &f); public: - FileManager(); + FileManager(char *argv[]); ~FileManager(); void setDevice(IrrlichtDevice *device); void dropFileSystem(); diff --git a/src/main.cpp b/src/main.cpp index 11fc2041f..e595df460 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -492,9 +492,9 @@ int handleCmdLine(int argc, char **argv) //============================================================================= /** Initialises the minimum number of managers to get access to user_config. */ -void initUserConfig() +void initUserConfig(char *argv[]) { - file_manager = new FileManager(); + file_manager = new FileManager(argv); translations = new Translations(); // needs file_manager user_config = new UserConfig(); // needs file_manager } // initUserConfig @@ -579,7 +579,8 @@ int main(int argc, char *argv[] ) // Init the minimum managers so that user config exists, then // handle all command line options that do not need (or must // not have) other managers initialised: - initUserConfig(); + initUserConfig(argv); // argv passed so config file can be + // found more reliably handleCmdLinePreliminary(argc, argv); initRest();