/** With irrlicht the constructor creates a NULL device. This is necessary to * handle the Chicken/egg problem with irrlicht: access to the file system * is given from the device, but we can't create the device before reading * the user_config file (for resolution, fullscreen). So we create a dummy * device here to begin with, which is then later (once the real device * exists) changed in reInit(). * */ FileManager::FileManager(char *argv[]) { #ifdef __APPLE__ // irrLicht's createDevice method has a nasty habit of messing the CWD. // since the code above may rely on it, save it to be able to restore it after. char buffer[256]; getcwd(buffer, 256); #endif //std::cout << "^^^^^^^^ CREATING m_device (NULL) in FileManager ^^^^^^^^\n"; m_device = createDevice(video::EDT_NULL); #ifdef __APPLE__ chdir( buffer ); #endif 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("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 ; #else m_root_dir = "/mnt/sdcard/stk" ;//"/usr/local/share/games/supertuxkart" ; #endif // We can't use _() here, since translations will only be initalised // after the filemanager (to get the path to the tranlsations from it) fprintf(stderr, "Data files will be fetched from: '%s'\n", m_root_dir.c_str() ); checkAndCreateConfigDir(); #ifdef ADDONS_MANAGER checkAndCreateAddonsDir(); #endif } // FileManager
/** With irrlicht the constructor creates a NULL device. This is necessary to * handle the Chicken/egg problem with irrlicht: access to the file system * is given from the device, but we can't create the device before reading * the user_config file (for resolution, fullscreen). So we create a dummy * device here to begin with, which is then later (once the real device * exists) changed in reInit(). * */ FileManager::FileManager() { m_subdir_name.resize(ASSET_COUNT); m_subdir_name[CHALLENGE ] = "challenges"; m_subdir_name[FONT ] = "fonts"; m_subdir_name[GFX ] = "gfx"; m_subdir_name[GRANDPRIX ] = "grandprix"; m_subdir_name[GUI ] = "gui"; m_subdir_name[MODEL ] = "models"; m_subdir_name[MUSIC ] = "music"; m_subdir_name[TRANSLATION] = "po"; m_subdir_name[TEXTURE ] = "textures"; m_subdir_name[SFX ] = "sfx"; m_subdir_name[SKIN ] = "skins"; m_subdir_name[SHADER ] = "shaders"; #ifdef __APPLE__ // irrLicht's createDevice method has a nasty habit of messing the CWD. // since the code above may rely on it, save it to be able to restore // it after. char buffer[256]; getcwd(buffer, 256); #endif #ifdef __APPLE__ chdir( buffer ); #endif m_file_system = irr_driver->getDevice()->getFileSystem(); m_file_system->grab(); irr::io::path exe_path; // Search for the root directory // ============================= // 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. std::string root_dir; if(m_file_system->existFile(CommandLine::getExecName().c_str())) exe_path = m_file_system->getFileDir(CommandLine::getExecName().c_str()); if(exe_path.size()==0 || exe_path[exe_path.size()-1]!='/') exe_path += "/"; if ( getenv ( "SUPERTUXKART_DATADIR" ) != NULL ) root_dir = std::string(getenv("SUPERTUXKART_DATADIR"))+"/" ; #ifdef __APPLE__ else if( macSetBundlePathIfRelevant( root_dir ) ) { root_dir = root_dir + "data/"; } #endif else if(m_file_system->existFile("data")) root_dir = "data/" ; else if(m_file_system->existFile("../data")) root_dir = "../data/" ; else if(m_file_system->existFile("../../data")) root_dir = "../../data/" ; // Test for old style build environment, with executable in root of stk else if(m_file_system->existFile(exe_path+"data")) root_dir = (exe_path+"data/").c_str(); // Check for windows cmake style: bld/Debug/bin/supertuxkart.exe else if (m_file_system->existFile(exe_path + "../../../data")) root_dir = (exe_path + "../../../data/").c_str(); else if (m_file_system->existFile(exe_path + "../data")) { root_dir = exe_path.c_str(); root_dir += "../data/"; } else { #ifdef SUPERTUXKART_DATADIR root_dir = SUPERTUXKART_DATADIR; if(root_dir.size()==0 || root_dir[root_dir.size()-1]!='/') root_dir+='/'; #else root_dir = "/usr/local/share/games/supertuxkart/"; #endif } addRootDirs(root_dir); if( fileExists(root_dir+"../../stk-assets")) addRootDirs(root_dir+"../../stk-assets"); if ( getenv ( "SUPERTUXKART_ROOT_PATH" ) != NULL ) addRootDirs(getenv("SUPERTUXKART_ROOT_PATH")); checkAndCreateConfigDir(); checkAndCreateAddonsDir(); checkAndCreateScreenshotDir(); #ifdef WIN32 redirectOutput(); #endif // We can't use _() here, since translations will only be initalised // after the filemanager (to get the path to the tranlsations from it) for(unsigned int i=0; i<m_root_dirs.size(); i++) Log::info("[FileManager]", "Data files will be fetched from: '%s'", m_root_dirs[i].c_str()); Log::info("[FileManager]", "User directory is '%s'.", m_user_config_dir.c_str()); Log::info("[FileManager]", "Addons files will be stored in '%s'.", m_addons_dir.c_str()); Log::info("[FileManager]", "Screenshots will be stored in '%s'.", m_screenshot_dir.c_str()); /** Now search for the path to all needed subdirectories. */ // ========================================================== // This must be done here since otherwise translations will not be found. std::vector<bool> dir_found; dir_found.resize(ASSET_COUNT, false); for(unsigned int i=0; i<m_root_dirs.size(); i++) { if(fileExists(m_root_dirs[i]+"tracks/")) TrackManager::addTrackSearchDir(m_root_dirs[i]+"tracks/"); if(fileExists(m_root_dirs[i]+"karts/")) KartPropertiesManager::addKartSearchDir(m_root_dirs[i]+"karts/"); for(unsigned int j=ASSET_MIN; j<=ASSET_MAX; j++) { if(!dir_found[j] && fileExists(m_root_dirs[i]+m_subdir_name[j])) { dir_found[j] = true; m_subdir_name[j] = m_root_dirs[i]+m_subdir_name[j]+"/"; } // !dir_found && file_exist } // for j=ASSET_MIN; j<=ASSET_MAX } // for i<m_root_dirs bool was_error = false; for(unsigned int i=ASSET_MIN; i<=ASSET_MAX; i++) { if(!dir_found[i]) { Log::warn("[FileManager]", "Directory '%s' not found, aborting.", m_subdir_name[i].c_str()); was_error = true; } else Log::info("[FileManager]", "Asset %d will be loaded from '%s'.", i, m_subdir_name[i].c_str()); } if(was_error) Log::fatal("[FileManager]", "Not all assets found - aborting."); } // FileManager
/** The constructor of the file manager creates an irrlicht file system and * detects paths for the user config file and assets base directory (data). * A second initialisation is done later once (see init()), once the user * config file is read. This is necessary since part of discoverPaths * depend on artist debug mode. */ FileManager::FileManager() { m_subdir_name.resize(ASSET_COUNT); m_subdir_name[CHALLENGE ] = "challenges"; m_subdir_name[FONT ] = "fonts"; m_subdir_name[GFX ] = "gfx"; m_subdir_name[GRANDPRIX ] = "grandprix"; m_subdir_name[GUI ] = "gui"; m_subdir_name[LIBRARY ] = "library"; m_subdir_name[MODEL ] = "models"; m_subdir_name[MUSIC ] = "music"; m_subdir_name[SCRIPT ] = "tracks"; m_subdir_name[SFX ] = "sfx"; m_subdir_name[SKIN ] = "skins"; m_subdir_name[SHADER ] = "shaders"; m_subdir_name[TEXTURE ] = "textures"; m_subdir_name[TRANSLATION] = "po"; #ifdef __APPLE__ // irrLicht's createDevice method has a nasty habit of messing the CWD. // since the code above may rely on it, save it to be able to restore // it after. char buffer[256]; getcwd(buffer, 256); #endif #ifdef __APPLE__ chdir( buffer ); #endif m_file_system = irr::io::createFileSystem(); irr::io::path exe_path; // Search for the root directory // ============================= // 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. std::string root_dir; if(m_file_system->existFile(CommandLine::getExecName().c_str())) exe_path = m_file_system->getFileDir(CommandLine::getExecName().c_str()); if(exe_path.size()==0 || exe_path[exe_path.size()-1]!='/') exe_path += "/"; if ( getenv ( "SUPERTUXKART_DATADIR" ) != NULL ) root_dir = std::string(getenv("SUPERTUXKART_DATADIR"))+"/data/" ; #ifdef __APPLE__ else if( macSetBundlePathIfRelevant( root_dir ) ) { root_dir = root_dir + "data/"; } #endif else if(m_file_system->existFile("data")) root_dir = "data/" ; else if(m_file_system->existFile("../data")) root_dir = "../data/" ; else if(m_file_system->existFile("../../data")) root_dir = "../../data/" ; // Test for old style build environment, with executable in root of stk else if(m_file_system->existFile(exe_path+"data")) root_dir = (exe_path+"data/").c_str(); // Check for windows cmake style: bld/Debug/bin/supertuxkart.exe else if (m_file_system->existFile(exe_path + "../../../data")) root_dir = (exe_path + "../../../data/").c_str(); else if (m_file_system->existFile(exe_path + "../data")) { root_dir = exe_path.c_str(); root_dir += "../data/"; } else { #ifdef SUPERTUXKART_DATADIR root_dir = SUPERTUXKART_DATADIR"/data/"; if(root_dir.size()==0 || root_dir[root_dir.size()-1]!='/') root_dir+='/'; #else root_dir = "/usr/local/share/games/supertuxkart/"; #endif } addRootDirs(root_dir); if( fileExists(root_dir+"../../stk-assets")) addRootDirs(root_dir+"../../stk-assets"); if( fileExists(root_dir+"../../supertuxkart-assets")) addRootDirs(root_dir+"../../supertuxkart-assets"); if ( getenv ( "SUPERTUXKART_ROOT_PATH" ) != NULL ) addRootDirs(getenv("SUPERTUXKART_ROOT_PATH")); checkAndCreateConfigDir(); checkAndCreateAddonsDir(); checkAndCreateScreenshotDir(); checkAndCreateCachedTexturesDir(); checkAndCreateGPDir(); redirectOutput(); } // FileManager