From: <au...@us...> - 2010-01-01 17:01:41
|
Revision: 4379 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=4379&view=rev Author: auria Date: 2010-01-01 17:01:32 +0000 (Fri, 01 Jan 2010) Log Message: ----------- Config dir cleanup by Graham Harrias (thanks\!) Modified Paths: -------------- main/trunk/src/io/file_manager.cpp Modified: main/trunk/src/io/file_manager.cpp =================================================================== --- main/trunk/src/io/file_manager.cpp 2009-12-30 21:28:59 UTC (rev 4378) +++ main/trunk/src/io/file_manager.cpp 2010-01-01 17:01:32 UTC (rev 4379) @@ -23,6 +23,7 @@ #include <stdexcept> #include <sstream> #include <sys/stat.h> +#include <iostream> #include <string> #ifdef WIN32 # include <io.h> @@ -31,15 +32,12 @@ # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) // Some portabilty defines # endif -# define CONFIGDIR "." -#elif defined(__APPLE__) -# include <unistd.h> -# define CONFIGDIR "Library/Application Support/SuperTuxKart" #else # include <unistd.h> -# define CONFIGDIR ".supertuxkart" #endif +#define CONFIGDIR "supertuxkart" + #include "irrlicht.h" #include "btBulletDynamicsCommon.h" @@ -348,26 +346,35 @@ std::ostringstream s; if(getenv("APPDATA")!=NULL) { - s<<getenv("APPDATA")<<"/supertuxkart/"; + s<<getenv("APPDATA")<<"/"<<CONFIGDIR<<"/"; DIRNAME=s.str(); } else DIRNAME="."; -#else - if(getenv("HOME")!=NULL) - { +#endif +#ifdef linux + // Use new standards for config directory + if (getenv("XDG_CONFIG_HOME")!=NULL){ + DIRNAME = getenv("XDG_CONFIG_HOME"); + }else if (getenv("HOME")!=NULL){ + DIRNAME = getenv("HOME"); + DIRNAME += "/.config"; + }else{ + std::cerr << "No home directory, this should NOT happen!\n"; + // This is what was here before, it looks rather questionable. + DIRNAME="."; + } + DIRNAME += "/"; + DIRNAME += CONFIGDIR; +#endif +#ifdef __APPLE__ + if (getenv("HOME")!=NULL){ DIRNAME = getenv("HOME"); - } - else - { - #ifdef __APPLE__ - fprintf(stderr, "Home directory is undefined, this should NOT happen!\n"); + }else{ + std::cerr << "No home directory, this should NOT happen!\n"; // Fall back to system-wide app data (rather than user-specific data), but should not happen anyway. DIRNAME = ""; - #else - DIRNAME = "."; - #endif - } - DIRNAME += "/"; + } + DIRNAME += "/Library/Application Support/"; DIRNAME += CONFIGDIR; #endif return DIRNAME; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2010-02-21 01:51:05
|
Revision: 4783 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=4783&view=rev Author: auria Date: 2010-02-21 01:50:59 +0000 (Sun, 21 Feb 2010) Log Message: ----------- Fixed config dir fallback on linux/unix; last resort should be ~/.supertuxkart, not ~/supertuxkart Modified Paths: -------------- main/trunk/src/io/file_manager.cpp Modified: main/trunk/src/io/file_manager.cpp =================================================================== --- main/trunk/src/io/file_manager.cpp 2010-02-21 00:43:36 UTC (rev 4782) +++ main/trunk/src/io/file_manager.cpp 2010-02-21 01:50:59 UTC (rev 4783) @@ -428,6 +428,7 @@ fprintf(stderr, "Can't create dir '%s', falling back to use '%s'.\n", m_config_dir.c_str(), getenv("HOME")); m_config_dir = getenv("HOME"); + m_config_dir += "."; } } # endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hik...@us...> - 2010-04-15 23:53:37
|
Revision: 5200 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=5200&view=rev Author: hikerstk Date: 2010-04-15 23:53:31 +0000 (Thu, 15 Apr 2010) Log Message: ----------- Removed unnecessary call (the directory was already added), which was also incorrect and caused a warning to be printed. Modified Paths: -------------- main/trunk/src/io/file_manager.cpp Modified: main/trunk/src/io/file_manager.cpp =================================================================== --- main/trunk/src/io/file_manager.cpp 2010-04-14 19:18:13 UTC (rev 5199) +++ main/trunk/src/io/file_manager.cpp 2010-04-15 23:53:31 UTC (rev 5200) @@ -184,9 +184,7 @@ pushTextureSearchPath(m_root_dir+"/data/textures/"); pushModelSearchPath (m_root_dir+"/data/models/" ); pushMusicSearchPath (m_root_dir+"/data/music/" ); - m_file_system->addFileArchive("data/models/", - /*ignoreCase*/false, - /*ignorePaths*/false); + // Add more paths from the STK_MUSIC_PATH environment variable if(getenv("SUPERTUXKART_MUSIC_PATH")!=NULL) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hik...@us...> - 2010-07-01 13:58:28
|
Revision: 5607 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=5607&view=rev Author: hikerstk Date: 2010-07-01 13:58:22 +0000 (Thu, 01 Jul 2010) Log Message: ----------- Removed unused variable. Modified Paths: -------------- main/trunk/src/io/file_manager.cpp Modified: main/trunk/src/io/file_manager.cpp =================================================================== --- main/trunk/src/io/file_manager.cpp 2010-07-01 13:11:40 UTC (rev 5606) +++ main/trunk/src/io/file_manager.cpp 2010-07-01 13:58:22 UTC (rev 5607) @@ -361,7 +361,6 @@ */ bool FileManager::checkAndCreateDirectory(const std::string &path) { - io::path p=m_file_system->getWorkingDirectory(); // irrlicht apparently returns true for files and directory // (using access/_access internally): if(m_file_system->existFile(io::path(path.c_str()))) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2010-07-01 16:59:28
|
Revision: 5611 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=5611&view=rev Author: auria Date: 2010-07-01 16:59:22 +0000 (Thu, 01 Jul 2010) Log Message: ----------- Implemented get addons dir for OS X Modified Paths: -------------- main/trunk/src/io/file_manager.cpp Modified: main/trunk/src/io/file_manager.cpp =================================================================== --- main/trunk/src/io/file_manager.cpp 2010-07-01 16:50:34 UTC (rev 5610) +++ main/trunk/src/io/file_manager.cpp 2010-07-01 16:59:22 UTC (rev 5611) @@ -449,12 +449,12 @@ #ifdef ADDONS_MANAGER void FileManager::checkAndCreateAddonsDir() { -#ifdef WIN32 +#if defined(WIN32) //TODO +#elif defined(__APPLE__) + m_addons_dir = getenv("HOME"); + m_addons_dir += "/Library/Application Support/SuperTuxKart"; #else -# ifdef __APPLE__ -//TODO -# else // Remaining unix variants. Use the new standards for config directory // i.e. either XDG_CONFIG_HOME or $HOME/.config if (getenv("XDG_DATA_HOME")!=NULL){ @@ -478,12 +478,13 @@ m_addons_dir += "."; } } -# endif -#endif + const std::string CONFIGDIR("supertuxkart"); - + m_addons_dir += "/"; m_addons_dir += CONFIGDIR; +#endif + if(!checkAndCreateDirectory(m_addons_dir)) { fprintf(stderr, "Can not create config dir '%s', falling back to '.'.\n", This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2010-07-01 18:11:28
|
Revision: 5615 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=5615&view=rev Author: auria Date: 2010-07-01 18:11:22 +0000 (Thu, 01 Jul 2010) Log Message: ----------- Fixed uglyness on OS X where directories called both SuperTuxKart and supertuxkart would be attempted to be created in App Support Modified Paths: -------------- main/trunk/src/io/file_manager.cpp Modified: main/trunk/src/io/file_manager.cpp =================================================================== --- main/trunk/src/io/file_manager.cpp 2010-07-01 18:06:18 UTC (rev 5614) +++ main/trunk/src/io/file_manager.cpp 2010-07-01 18:11:22 UTC (rev 5615) @@ -380,7 +380,7 @@ /** Checks if the config directory exists, and it not, tries to create it. */ void FileManager::checkAndCreateConfigDir() { -#ifdef WIN32 +#if defined(WIN32) // Try to use the APPDATA directory to store config files and highscore // lists. If not defined, used the current directory. if(getenv("APPDATA")!=NULL) @@ -395,8 +395,11 @@ } else m_config_dir = "."; -#else -# ifdef __APPLE__ + const std::string CONFIGDIR("supertuxkart"); + + m_config_dir += "/"; + m_config_dir += CONFIGDIR; +#elif defined(__APPLE__) if (getenv("HOME")!=NULL) { m_config_dir = getenv("HOME"); @@ -408,6 +411,8 @@ m_config_dir = ""; } m_config_dir += "/Library/Application Support/"; + const std::string CONFIGDIR("SuperTuxKart"); + m_config_dir += CONFIGDIR; # else // Remaining unix variants. Use the new standards for config directory // i.e. either XDG_CONFIG_HOME or $HOME/.config @@ -432,12 +437,12 @@ m_config_dir += "."; } } -# endif -#endif const std::string CONFIGDIR("supertuxkart"); - + m_config_dir += "/"; m_config_dir += CONFIGDIR; +#endif + if(!checkAndCreateDirectory(m_config_dir)) { fprintf(stderr, "Can not create config dir '%s', falling back to '.'.\n", This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2010-07-01 19:09:47
|
Revision: 5614 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=5614&view=rev Author: auria Date: 2010-07-01 18:06:18 +0000 (Thu, 01 Jul 2010) Log Message: ----------- Better error checking Modified Paths: -------------- main/trunk/src/io/file_manager.cpp Modified: main/trunk/src/io/file_manager.cpp =================================================================== --- main/trunk/src/io/file_manager.cpp 2010-07-01 17:42:12 UTC (rev 5613) +++ main/trunk/src/io/file_manager.cpp 2010-07-01 18:06:18 UTC (rev 5614) @@ -488,14 +488,16 @@ if(!checkAndCreateDirectory(m_addons_dir)) { - fprintf(stderr, "Can not create config dir '%s', falling back to '.'.\n", - m_addons_dir.c_str()); + fprintf(stderr, "Can not create add-ons dir '%s', falling back to '.'.\n", m_addons_dir.c_str()); m_config_dir = "."; } else { //we hope that there will be no problem since we created the other dir - checkAndCreateDirectory(m_addons_dir + "/data/"); + if (!checkAndCreateDirectory(m_addons_dir + "/data/")) + { + fprintf(stderr, "Failed to create add-ons data dir at '%s'\n", (m_addons_dir + "/data/").c_str()); + } } return; } // checkAndCreateAddonsDir This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <xa...@us...> - 2010-07-02 17:14:15
|
Revision: 5619 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=5619&view=rev Author: xapantu Date: 2010-07-02 17:14:09 +0000 (Fri, 02 Jul 2010) Log Message: ----------- improve the checkandcreatedirectory recursive function file_manager using the stringutils split function Modified Paths: -------------- main/trunk/src/io/file_manager.cpp Modified: main/trunk/src/io/file_manager.cpp =================================================================== --- main/trunk/src/io/file_manager.cpp 2010-07-02 16:54:08 UTC (rev 5618) +++ main/trunk/src/io/file_manager.cpp 2010-07-02 17:14:09 UTC (rev 5619) @@ -384,23 +384,21 @@ if(m_file_system->existFile(io::path(path.c_str()))) return true; - - for(int i = 0; i <= path.size(); i++) + std::vector<std::string> split = StringUtils::split(path,'/'); + std::string current_path =""; + for(unsigned int i=0; i<split.size(); i++) { - if(path.c_str()[i] == '/') + current_path += split[i] + "/"; + std::cout << "Checking for: " << current_path << std::endl; + if(m_file_system->existFile(io::path(current_path.c_str()))) + std::cout << "The directory exist." << std::endl; + else { - std::string current_path = path.substr(0, i + 1); - std::cout << "Checking for: " << current_path << std::endl; - if(m_file_system->existFile(io::path(current_path.c_str()))) - std::cout << "The directory exist." << std::endl; - else + if(!checkAndCreateDirectory(current_path)) { - if(!checkAndCreateDirectory(current_path)) - { - fprintf(stderr, "Can't create dir '%s'", - current_path.c_str()); - break; - } + fprintf(stderr, "Can't create dir '%s'", + current_path.c_str()); + break; } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hik...@us...> - 2010-09-14 00:56:48
|
Revision: 5989 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=5989&view=rev Author: hikerstk Date: 2010-09-14 00:56:42 +0000 (Tue, 14 Sep 2010) Log Message: ----------- Added "/" to the end of some getXXXDir functions, so that the "/" doesn't have to be added elsewhere all the time. Modified Paths: -------------- main/trunk/src/io/file_manager.cpp Modified: main/trunk/src/io/file_manager.cpp =================================================================== --- main/trunk/src/io/file_manager.cpp 2010-09-14 00:50:56 UTC (rev 5988) +++ main/trunk/src/io/file_manager.cpp 2010-09-14 00:56:42 UTC (rev 5989) @@ -326,12 +326,12 @@ //----------------------------------------------------------------------------- std::string FileManager::getGUIDir() const { - return m_root_dir+"/data/gui"; + return m_root_dir+"/data/gui/"; } //----------------------------------------------------------------------------- std::string FileManager::getKartDir() const { - return m_root_dir+"/data/karts"; + return m_root_dir+"/data/karts/"; } // getKartDir //----------------------------------------------------------------------------- @@ -355,7 +355,7 @@ // e.g. to load a model from a kart directory std::string basename = (kart_name!="") ? kart_name : StringUtils::removeExtension(fname); - return getKartDir()+"/"+basename+"/"+fname; + return getKartDir()+basename+"/"+fname; } // getKartFile //----------------------------------------------------------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hik...@us...> - 2010-09-14 06:05:54
|
Revision: 6000 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=6000&view=rev Author: hikerstk Date: 2010-09-14 06:05:48 +0000 (Tue, 14 Sep 2010) Log Message: ----------- Fixed memory leak. Modified Paths: -------------- main/trunk/src/io/file_manager.cpp Modified: main/trunk/src/io/file_manager.cpp =================================================================== --- main/trunk/src/io/file_manager.cpp 2010-09-14 05:23:59 UTC (rev 5999) +++ main/trunk/src/io/file_manager.cpp 2010-09-14 06:05:48 UTC (rev 6000) @@ -628,11 +628,12 @@ for(int n=0; n<(int)files->getFileCount(); n++) { - //printf("---- Entry : %s \n", (make_full_path ? path+"/"+ files->getFileName(n) : files->getFileName(n)).c_str()); - result.insert(make_full_path ? path+"/"+ files->getFileName(n).c_str() : files->getFileName(n).c_str()); + result.insert(make_full_path ? path+"/"+ files->getFileName(n).c_str() + : files->getFileName(n).c_str() ); } m_file_system->changeWorkingDirectoryTo( previous_cwd.c_str() ); + files->drop(); } // listFiles //----------------------------------------------------------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hik...@us...> - 2010-11-28 20:54:51
|
Revision: 6745 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=6745&view=rev Author: hikerstk Date: 2010-11-28 20:54:45 +0000 (Sun, 28 Nov 2010) Log Message: ----------- Fixed memory leak. Modified Paths: -------------- main/trunk/src/io/file_manager.cpp Modified: main/trunk/src/io/file_manager.cpp =================================================================== --- main/trunk/src/io/file_manager.cpp 2010-11-28 18:57:31 UTC (rev 6744) +++ main/trunk/src/io/file_manager.cpp 2010-11-28 20:54:45 UTC (rev 6745) @@ -233,6 +233,7 @@ io::IXMLReader *xml_reader = createXMLReader(filename); if(!xml_reader) return NULL; return new XMLNode(xml_reader); + xml_reader->drop(); } // getXMLTree //----------------------------------------------------------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2010-12-12 00:53:31
|
Revision: 6956 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=6956&view=rev Author: auria Date: 2010-12-12 00:53:25 +0000 (Sun, 12 Dec 2010) Log Message: ----------- Fixed memory leak (Joerg: phew, I'm not the only one writing stupid code ;) Modified Paths: -------------- main/trunk/src/io/file_manager.cpp Modified: main/trunk/src/io/file_manager.cpp =================================================================== --- main/trunk/src/io/file_manager.cpp 2010-12-11 21:52:52 UTC (rev 6955) +++ main/trunk/src/io/file_manager.cpp 2010-12-12 00:53:25 UTC (rev 6956) @@ -232,8 +232,9 @@ { io::IXMLReader *xml_reader = createXMLReader(filename); if(!xml_reader) return NULL; - return new XMLNode(xml_reader); + XMLNode* node = new XMLNode(xml_reader); xml_reader->drop(); + return node; } // getXMLTree //----------------------------------------------------------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hik...@us...> - 2011-01-03 03:31:17
|
Revision: 7220 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=7220&view=rev Author: hikerstk Date: 2011-01-03 03:31:11 +0000 (Mon, 03 Jan 2011) Log Message: ----------- Minor code cleanup. Modified Paths: -------------- main/trunk/src/io/file_manager.cpp Modified: main/trunk/src/io/file_manager.cpp =================================================================== --- main/trunk/src/io/file_manager.cpp 2011-01-03 03:28:18 UTC (rev 7219) +++ main/trunk/src/io/file_manager.cpp 2011-01-03 03:31:11 UTC (rev 7220) @@ -633,8 +633,9 @@ } // getChallengeFile //----------------------------------------------------------------------------- -void FileManager::listFiles(std::set<std::string>& result, const std::string& dir, - bool is_full_path, bool make_full_path) const +void FileManager::listFiles(std::set<std::string>& result, + const std::string& dir, bool is_full_path, + bool make_full_path) const { result.clear(); @@ -675,12 +676,17 @@ void FileManager::checkAndCreateDirForAddons(std::string addons_name, std::string addons_type) { - bool success = checkAndCreateDirectory(getAddonsDir() + addons_type); + std::string path = getAddonsFile(addons_type); + bool success = checkAndCreateDirectory(path); if(!success) + { std::cout << "There is a problem with the addons dir." << std::endl; - checkAndCreateDirectory(getAddonsDir() + addons_type + addons_name); + return; + } + checkAndCreateDirectory(path+"/"+addons_name); +} // checkAndCreateDirForAddons -} +// ---------------------------------------------------------------------------- bool FileManager::removeDirectory(char const *name) { #ifndef WIN32 @@ -706,7 +712,8 @@ /*this condition handles if it is the current directory (.) or the parent directory (..), these names work only on unix-based I think*/ - if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) + if (strcmp(entry->d_name, ".") == 0 || + strcmp(entry->d_name, "..") == 0) { continue; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hik...@us...> - 2011-01-05 03:58:49
|
Revision: 7262 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=7262&view=rev Author: hikerstk Date: 2011-01-05 03:58:43 +0000 (Wed, 05 Jan 2011) Log Message: ----------- Added support for SUPERTUXKART_SAVEDIR environment variable to specify/overwrite where the user-specific files are written to. Modified Paths: -------------- main/trunk/src/io/file_manager.cpp Modified: main/trunk/src/io/file_manager.cpp =================================================================== --- main/trunk/src/io/file_manager.cpp 2011-01-05 03:09:07 UTC (rev 7261) +++ main/trunk/src/io/file_manager.cpp 2011-01-05 03:58:43 UTC (rev 7262) @@ -129,13 +129,13 @@ m_file_system = m_device->getFileSystem(); m_is_full_path = false; - irr::io::path exe_path; + 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(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" ) ; @@ -409,73 +409,82 @@ /** Checks if the config directory exists, and it not, tries to create it. */ void FileManager::checkAndCreateConfigDir() { + if(getenv("SUPERTUXKART_SAVEDIR") && + checkAndCreateDirectory(getenv("SUPERTUXKART_SAVEDIR")) ) + { + m_config_dir = getenv("SUPERTUXKART_SAVEDIR"); + } + else + { #if defined(WIN32) - // Try to use the APPDATA directory to store config files and highscore - // lists. If not defined, used the current directory. - if(getenv("APPDATA")!=NULL) - { - m_config_dir = getenv("APPDATA"); - if(!checkAndCreateDirectory(m_config_dir)) + // Try to use the APPDATA directory to store config files and highscore + // lists. If not defined, used the current directory. + if(getenv("APPDATA")!=NULL) { - fprintf(stderr, + m_config_dir = getenv("APPDATA"); + if(!checkAndCreateDirectory(m_config_dir)) + { + fprintf(stderr, "Can't create config dir '%s', falling back to '.'.\n", m_config_dir.c_str()); + m_config_dir = "."; + } + } + else m_config_dir = "."; - } - } - else - m_config_dir = "."; - const std::string CONFIGDIR("supertuxkart"); + const std::string CONFIGDIR("supertuxkart"); - m_config_dir += "/"; - m_config_dir += CONFIGDIR; + m_config_dir += "/"; + m_config_dir += CONFIGDIR; #elif defined(__APPLE__) - if (getenv("HOME")!=NULL) - { - m_config_dir = getenv("HOME"); - } - else - { - std::cerr << "No home directory, this should NOT happen!\n"; - // Fall back to system-wide app data (rather than user-specific data), - // but should not happen anyway. - m_config_dir = ""; - } - m_config_dir += "/Library/Application Support/"; - const std::string CONFIGDIR("SuperTuxKart"); - m_config_dir += CONFIGDIR; + if (getenv("HOME")!=NULL) + { + m_config_dir = getenv("HOME"); + } + else + { + std::cerr << "No home directory, this should NOT happen!\n"; + // Fall back to system-wide app data (rather than user-specific data), + // but should not happen anyway. + m_config_dir = ""; + } + m_config_dir += "/Library/Application Support/"; + const std::string CONFIGDIR("SuperTuxKart"); + m_config_dir += CONFIGDIR; # else - // Remaining unix variants. Use the new standards for config directory - // i.e. either XDG_CONFIG_HOME or $HOME/.config - if (getenv("XDG_CONFIG_HOME")!=NULL){ - m_config_dir = getenv("XDG_CONFIG_HOME"); - } - else if (!getenv("HOME")) - { - std::cerr << "No home directory, this should NOT happen " - << "- trying '.' for config files!\n"; - m_config_dir = "."; - } - else - { - m_config_dir = getenv("HOME"); - m_config_dir += "/.config"; - if(!checkAndCreateDirectory(m_config_dir)) + // Remaining unix variants. Use the new standards for config directory + // i.e. either XDG_CONFIG_HOME or $HOME/.config + if (getenv("XDG_CONFIG_HOME")!=NULL){ + m_config_dir = getenv("XDG_CONFIG_HOME"); + } + else if (!getenv("HOME")) { - // If $HOME/.config can not be created: - fprintf(stderr, + std::cerr << "No home directory, this should NOT happen " + << "- trying '.' for config files!\n"; + m_config_dir = "."; + } + else + { + m_config_dir = getenv("HOME"); + m_config_dir += "/.config"; + if(!checkAndCreateDirectory(m_config_dir)) + { + // If $HOME/.config can not be created: + fprintf(stderr, "Can't create dir '%s', falling back to use '%s'.\n", m_config_dir.c_str(), getenv("HOME")); - m_config_dir = getenv("HOME"); - m_config_dir += "."; + m_config_dir = getenv("HOME"); + m_config_dir += "."; + } } - } - const std::string CONFIGDIR("supertuxkart"); + const std::string CONFIGDIR("supertuxkart"); - m_config_dir += "/"; - m_config_dir += CONFIGDIR; + m_config_dir += "/"; + m_config_dir += CONFIGDIR; #endif + } // if(getenv("SUPERTUXKART_SAVEDIR") && checkAndCreateDirectory(...)) + if(!checkAndCreateDirectory(m_config_dir)) { fprintf(stderr, @@ -497,19 +506,19 @@ #else // Remaining unix variants. Use the new standards for config directory // i.e. either XDG_CONFIG_HOME or $HOME/.config - if (getenv("XDG_DATA_HOME")!=NULL){ - m_addons_dir = getenv("XDG_DATA_HOME"); - } + if (getenv("XDG_DATA_HOME")!=NULL){ + m_addons_dir = getenv("XDG_DATA_HOME"); + } else if (!getenv("HOME")) { - std::cerr << "No home directory, this should NOT happen " + std::cerr << "No home directory, this should NOT happen " << "- trying '.addons' for addons files!\n"; m_addons_dir = "stkaddons"; } else { - m_addons_dir = getenv("HOME"); - m_addons_dir += "/.local/share"; + m_addons_dir = getenv("HOME"); + m_addons_dir += "/.local/share"; if(!checkAndCreateDirectory(m_config_dir)) { // If $HOME/.config can not be created: @@ -719,17 +728,17 @@ ::RemoveDirectory(name); return true; #if 0 - SHFILEOPSTRUCT sh; - sh.hwnd = NULL; - sh.wFunc = FO_DELETE; - sh.pFrom = repertoire; - sh.pTo = NULL; - sh.fFlags = FOF_NOCONFIRMATION|FOF_SILENT; - sh.fAnyOperationsAborted = FALSE; - sh.lpszProgressTitle = NULL; - sh.hNameMappings = NULL; - - return (SHFileOperation(&sh)==0); + SHFILEOPSTRUCT sh; + sh.hwnd = NULL; + sh.wFunc = FO_DELETE; + sh.pFrom = repertoire; + sh.pTo = NULL; + sh.fFlags = FOF_NOCONFIRMATION|FOF_SILENT; + sh.fAnyOperationsAborted = FALSE; + sh.lpszProgressTitle = NULL; + sh.hNameMappings = NULL; + + return (SHFileOperation(&sh)==0); #endif #endif } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2011-01-16 19:43:00
|
Revision: 7453 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=7453&view=rev Author: auria Date: 2011-01-16 19:42:52 +0000 (Sun, 16 Jan 2011) Log Message: ----------- Make file manager a bit less verbose, it's normal that createXMLTree does not always find the file Modified Paths: -------------- main/trunk/src/io/file_manager.cpp Modified: main/trunk/src/io/file_manager.cpp =================================================================== --- main/trunk/src/io/file_manager.cpp 2011-01-16 19:38:59 UTC (rev 7452) +++ main/trunk/src/io/file_manager.cpp 2011-01-16 19:42:52 UTC (rev 7453) @@ -238,7 +238,10 @@ } catch (std::runtime_error& e) { - fprintf(stderr, "[FileManager::createXMLTree] %s\n", e.what()); + if (UserConfigParams::m_verbosity >= 3) + { + fprintf(stderr, "[FileManager::createXMLTree] %s\n", e.what()); + } return NULL; } } // getXMLTree This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hik...@us...> - 2011-02-02 22:15:12
|
Revision: 7580 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=7580&view=rev Author: hikerstk Date: 2011-02-02 22:15:01 +0000 (Wed, 02 Feb 2011) Log Message: ----------- Fixed compilation bug on non-windows machines. Modified Paths: -------------- main/trunk/src/io/file_manager.cpp Modified: main/trunk/src/io/file_manager.cpp =================================================================== --- main/trunk/src/io/file_manager.cpp 2011-02-02 22:04:13 UTC (rev 7579) +++ main/trunk/src/io/file_manager.cpp 2011-02-02 22:15:01 UTC (rev 7580) @@ -32,7 +32,6 @@ # include <sys/stat.h> # include <sys/types.h> // For RemoveDirectory -# include <Windows.h> #else # include <direct.h> #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hik...@us...> - 2011-02-02 23:13:35
|
Revision: 7584 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=7584&view=rev Author: hikerstk Date: 2011-02-02 23:13:29 +0000 (Wed, 02 Feb 2011) Log Message: ----------- Fixed removeDirectory function on windows. Modified Paths: -------------- main/trunk/src/io/file_manager.cpp Modified: main/trunk/src/io/file_manager.cpp =================================================================== --- main/trunk/src/io/file_manager.cpp 2011-02-02 23:12:32 UTC (rev 7583) +++ main/trunk/src/io/file_manager.cpp 2011-02-02 23:13:29 UTC (rev 7584) @@ -34,6 +34,7 @@ // For RemoveDirectory #else # include <direct.h> +# include <Windows.h> #endif /*Needed by the remove directory function */ @@ -750,8 +751,7 @@ } } #ifdef WIN32 -//FIXME return RemoveDirectory(name.c_str()); - return false; + return RemoveDirectory(name.c_str())==TRUE; #else return remove(name.c_str())==0; #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hik...@us...> - 2011-05-01 14:30:56
|
Revision: 8490 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=8490&view=rev Author: hikerstk Date: 2011-05-01 14:30:50 +0000 (Sun, 01 May 2011) Log Message: ----------- Fixed incorrect 'priority' of texture search path: data/texture/mossy_stone.png was loaded for jungle instead of data/tracks/jungle/mossy_stone.png. Modified Paths: -------------- main/trunk/src/io/file_manager.cpp Modified: main/trunk/src/io/file_manager.cpp =================================================================== --- main/trunk/src/io/file_manager.cpp 2011-05-01 02:02:05 UTC (rev 8489) +++ main/trunk/src/io/file_manager.cpp 2011-05-01 14:30:50 UTC (rev 8490) @@ -261,20 +261,50 @@ void FileManager::pushModelSearchPath(const std::string& path) { m_model_search_path.push_back(path); + const int n=m_file_system->getFileArchiveCount(); m_file_system->addFileArchive(createAbsoluteFilename(path), /*ignoreCase*/false, /*ignorePaths*/false, io::EFAT_FOLDER); + // A later added file archive should be searched first (so that + // track specific models are found before models in data/models). + // This is not necessary if this is the first member, of ir the + // addFileArchive call did not add this file systems (this can + // happen if the file archive has been added prevously, which + // commonly happens since each kart/track specific path is added + // twice: once for textures and once for models. + if(n>0 && (int)m_file_system->getFileArchiveCount()>n) + { + // In this case move the just added file archive + // (which has index n) to position 0 (by -n positions): + m_file_system->moveFileArchive(n, -n); + } } // pushModelSearchPath //----------------------------------------------------------------------------- void FileManager::pushTextureSearchPath(const std::string& path) { m_texture_search_path.push_back(path); + const int n=m_file_system->getFileArchiveCount(); m_file_system->addFileArchive(createAbsoluteFilename(path), /*ignoreCase*/false, /*ignorePaths*/false, io::EFAT_FOLDER); + // A later added file archive should be searched first (so that + // e.g. track specific textures are found before textures in + // data/textures). + // This is not necessary if this is the first member, of ir the + // addFileArchive call did not add this file systems (this can + // happen if the file archive has been added prevously, which + // commonly happens since each kart/track specific path is added + // twice: once for textures and once for models. + // (which has index n) to position 0 (by -n positions): + if(n>0 && (int)m_file_system->getFileArchiveCount()>n) + { + // In this case move the just added file archive + // (which has index n) to position 0 (by -n positions): + m_file_system->moveFileArchive(n, -n); + } } // pushTextureSearchPath //----------------------------------------------------------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hik...@us...> - 2011-05-09 12:28:58
|
Revision: 8549 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=8549&view=rev Author: hikerstk Date: 2011-05-09 12:28:52 +0000 (Mon, 09 May 2011) Log Message: ----------- Used bitmask for verbosity. Modified Paths: -------------- main/trunk/src/io/file_manager.cpp Modified: main/trunk/src/io/file_manager.cpp =================================================================== --- main/trunk/src/io/file_manager.cpp 2011-05-09 00:50:54 UTC (rev 8548) +++ main/trunk/src/io/file_manager.cpp 2011-05-09 12:28:52 UTC (rev 8549) @@ -238,7 +238,7 @@ } catch (std::runtime_error& e) { - if (UserConfigParams::m_verbosity >= 3) + if (UserConfigParams::logMisc()) { fprintf(stderr, "[FileManager::createXMLTree] %s\n", e.what()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2011-05-13 01:29:24
|
Revision: 8560 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=8560&view=rev Author: auria Date: 2011-05-13 01:29:18 +0000 (Fri, 13 May 2011) Log Message: ----------- Use a better path for add-ons on OSX, before I had chosen a poor location and addon files were among config files Modified Paths: -------------- main/trunk/src/io/file_manager.cpp Modified: main/trunk/src/io/file_manager.cpp =================================================================== --- main/trunk/src/io/file_manager.cpp 2011-05-13 01:09:13 UTC (rev 8559) +++ main/trunk/src/io/file_manager.cpp 2011-05-13 01:29:18 UTC (rev 8560) @@ -545,7 +545,7 @@ m_addons_dir = m_config_dir+"/addons"; #elif defined(__APPLE__) m_addons_dir = getenv("HOME"); - m_addons_dir += "/Library/Application Support/SuperTuxKart"; + m_addons_dir += "/Library/Application Support/SuperTuxKart/Addons"; #else // Remaining unix variants. Use the new standards for config directory // i.e. either XDG_CONFIG_HOME or $HOME/.config This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hik...@us...> - 2011-05-29 23:07:58
|
Revision: 8761 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=8761&view=rev Author: hikerstk Date: 2011-05-29 23:07:52 +0000 (Sun, 29 May 2011) Log Message: ----------- Added 'addons' subdirectory to linux addons directory. This allows later if necessary to have different versions of addons directory (which is what Windows and Macs already support). NOTE for linux users: this means that currently installed addons will not be found anymore. I would recommend to delete existing files in .local/share/supertuxkart. Modified Paths: -------------- main/trunk/src/io/file_manager.cpp Modified: main/trunk/src/io/file_manager.cpp =================================================================== --- main/trunk/src/io/file_manager.cpp 2011-05-29 23:06:04 UTC (rev 8760) +++ main/trunk/src/io/file_manager.cpp 2011-05-29 23:07:52 UTC (rev 8761) @@ -573,10 +573,18 @@ } } - const std::string CONFIGDIR("supertuxkart"); - - m_addons_dir += "/"; - m_addons_dir += CONFIGDIR; + m_addons_dir += "/supertuxkart": + if(!checkAndCreateDirectory(m_config_dir)) + { + // If $HOME/.config can not be created: + fprintf(stderr, + "Can't create dir '%s', falling back to use '%s'.\n", + m_config_dir.c_str(), getenv("HOME")); + m_addons_dir = getenv("HOME"); + m_addons_dir += "."; + } + m_addons_dir += "/addons"; + #endif if(!checkAndCreateDirectory(m_addons_dir)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hik...@us...> - 2011-05-29 23:50:26
|
Revision: 8766 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=8766&view=rev Author: hikerstk Date: 2011-05-29 23:50:20 +0000 (Sun, 29 May 2011) Log Message: ----------- Fixed typo. Modified Paths: -------------- main/trunk/src/io/file_manager.cpp Modified: main/trunk/src/io/file_manager.cpp =================================================================== --- main/trunk/src/io/file_manager.cpp 2011-05-29 23:47:26 UTC (rev 8765) +++ main/trunk/src/io/file_manager.cpp 2011-05-29 23:50:20 UTC (rev 8766) @@ -573,7 +573,7 @@ } } - m_addons_dir += "/supertuxkart": + m_addons_dir += "/supertuxkart"; if(!checkAndCreateDirectory(m_config_dir)) { // If $HOME/.config can not be created: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hik...@us...> - 2011-06-15 13:04:27
|
Revision: 8935 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=8935&view=rev Author: hikerstk Date: 2011-06-15 13:04:15 +0000 (Wed, 15 Jun 2011) Log Message: ----------- Fixed minor typos in comments. Modified Paths: -------------- main/trunk/src/io/file_manager.cpp Modified: main/trunk/src/io/file_manager.cpp =================================================================== --- main/trunk/src/io/file_manager.cpp 2011-06-15 01:49:22 UTC (rev 8934) +++ main/trunk/src/io/file_manager.cpp 2011-06-15 13:04:15 UTC (rev 8935) @@ -268,11 +268,11 @@ io::EFAT_FOLDER); // A later added file archive should be searched first (so that // track specific models are found before models in data/models). - // This is not necessary if this is the first member, of ir the + // This is not necessary if this is the first member, or if the // addFileArchive call did not add this file systems (this can // happen if the file archive has been added prevously, which // commonly happens since each kart/track specific path is added - // twice: once for textures and once for models. + // twice: once for textures and once for models). if(n>0 && (int)m_file_system->getFileArchiveCount()>n) { // In this case move the just added file archive @@ -293,12 +293,11 @@ // A later added file archive should be searched first (so that // e.g. track specific textures are found before textures in // data/textures). - // This is not necessary if this is the first member, of ir the + // This is not necessary if this is the first member, or if the // addFileArchive call did not add this file systems (this can - // happen if the file archive has been added prevously, which + // happen if the file archive has been added previously, which // commonly happens since each kart/track specific path is added - // twice: once for textures and once for models. - // (which has index n) to position 0 (by -n positions): + // twice: once for textures and once for models). if(n>0 && (int)m_file_system->getFileArchiveCount()>n) { // In this case move the just added file archive This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hik...@us...> - 2011-06-23 07:18:11
|
Revision: 9018 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=9018&view=rev Author: hikerstk Date: 2011-06-23 07:18:05 +0000 (Thu, 23 Jun 2011) Log Message: ----------- Fixed several copy&paste errors in checkAndCreateAddonsDir (instead of creating m_addons_dir, the code was creating m_config_dir, so the addons directories would not be created correctly) - see #280. Also improved error handling and error messages. The file_manager now checks for $XDG_DATA_HOME, $HOME/.local/share, $HOME/.stkaddons or else "." as a base directory for addons (under which it will create supertuxkart/addons). Modified Paths: -------------- main/trunk/src/io/file_manager.cpp Modified: main/trunk/src/io/file_manager.cpp =================================================================== --- main/trunk/src/io/file_manager.cpp 2011-06-23 02:07:47 UTC (rev 9017) +++ main/trunk/src/io/file_manager.cpp 2011-06-23 07:18:05 UTC (rev 9018) @@ -538,6 +538,10 @@ } // checkAndCreateConfigDir // ---------------------------------------------------------------------------- +/** Creates the directories for the addons data. This will set m_addons_dir + * with the appropriate path, and also create the subdirectories in this + * directory. + */ void FileManager::checkAndCreateAddonsDir() { #if defined(WIN32) @@ -547,40 +551,60 @@ m_addons_dir += "/Library/Application Support/SuperTuxKart/Addons"; #else // Remaining unix variants. Use the new standards for config directory - // i.e. either XDG_CONFIG_HOME or $HOME/.config - if (getenv("XDG_DATA_HOME")!=NULL){ + // i.e. either XDG_CONFIG_HOME or $HOME/.local/share + + bool dir_ok = false; + + if (getenv("XDG_DATA_HOME")!=NULL) + { m_addons_dir = getenv("XDG_DATA_HOME"); + dir_ok = checkAndCreateDirectory(m_addons_dir); + if(!dir_ok) + std::cerr << "[FileManager] Cannot create $XDG_DATA_HOME.\n"; + + // Do an additional test here, e.g. in case that XDG_DATA_HOME is '/' + // and since dir_ok is set, it would not test any of the other options + // like $HOME/.local/share + dir_ok = checkAndCreateDirectory(m_addons_dir+"/supertuxkart"); + if(!dir_ok) + std::cerr << "[FileManager] Cannot create $XDG_DATA_HOME/supertuxkart.\n"; } - else if (!getenv("HOME")) + + if(!dir_ok && getenv("HOME")) { - std::cerr << "No home directory, this should NOT happen " - << "- trying '.addons' for addons files!\n"; - m_addons_dir = "stkaddons"; + // Use ~/.local/share : + m_addons_dir = getenv("HOME"); + m_addons_dir += "/.local/share"; + // This tests for ".local" and then for ".local/share" + dir_ok = checkAndCreateDirectoryP(m_addons_dir); + if(!dir_ok) + std::cerr << "[FileManager] Cannot create $HOME/.local/share.\n"; } - else + if(!dir_ok && getenv("HOME")) { + // Use ~/.local/share : m_addons_dir = getenv("HOME"); - m_addons_dir += "/.local/share"; - if(!checkAndCreateDirectory(m_config_dir)) - { - // If $HOME/.config can not be created: - fprintf(stderr, - "Can't create dir '%s', falling back to use '%s'.\n", - m_config_dir.c_str(), getenv("HOME")); - m_addons_dir = getenv("HOME"); - m_addons_dir += "."; - } + m_addons_dir += "/.stkaddons"; + dir_ok = checkAndCreateDirectory(m_addons_dir); + if(!dir_ok) + std::cerr << "[FileManager] Cannot create $HOME/.stkaddons.\n"; } + if(!dir_ok) + { + std::cerr << "[FileManager] Falling back to use '.'."; + m_addons_dir = "."; + } + m_addons_dir += "/supertuxkart"; - if(!checkAndCreateDirectory(m_config_dir)) + dir_ok = checkAndCreateDirectory(m_addons_dir); + if(!dir_ok) { - // If $HOME/.config can not be created: - fprintf(stderr, - "Can't create dir '%s', falling back to use '%s'.\n", - m_config_dir.c_str(), getenv("HOME")); - m_addons_dir = getenv("HOME"); - m_addons_dir += "."; + // If the directory can not be created, abort + std::cerr << " [FileManager] Cannot create directory '" + << m_addons_dir<<"', falling back to use '.'.\n"; + m_addons_dir="."; + } m_addons_dir += "/addons"; @@ -589,19 +613,20 @@ if(!checkAndCreateDirectory(m_addons_dir)) { fprintf(stderr, - "Can not create add-ons dir '%s', falling back to '.'.\n", + "[FileManager] Can not create add-ons dir '%s', falling back to '.'.\n", m_addons_dir.c_str()); - m_config_dir = "."; + m_addons_dir = "."; } + std::cout << "[FileManager] Addons files will be stored in '"<<m_addons_dir<<"'.\n"; if (!checkAndCreateDirectory(m_addons_dir + "/icons/")) { - fprintf(stderr, "Failed to create add-ons icon dir at '%s'\n", + fprintf(stderr, "[FileManager] Failed to create add-ons icon dir at '%s'\n", (m_addons_dir + "/icons/").c_str()); } if (!checkAndCreateDirectory(m_addons_dir + "/tmp/")) { - fprintf(stderr, "Failed to create add-ons tmp dir at '%s'\n", + fprintf(stderr, "[FileManager] Failed to create add-ons tmp dir at '%s'\n", (m_addons_dir + "/tmp/").c_str()); } } // checkAndCreateAddonsDir This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hik...@us...> - 2011-06-23 11:26:37
|
Revision: 9019 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=9019&view=rev Author: hikerstk Date: 2011-06-23 11:26:30 +0000 (Thu, 23 Jun 2011) Log Message: ----------- Improved documentation. Modified Paths: -------------- main/trunk/src/io/file_manager.cpp Modified: main/trunk/src/io/file_manager.cpp =================================================================== --- main/trunk/src/io/file_manager.cpp 2011-06-23 07:18:05 UTC (rev 9018) +++ main/trunk/src/io/file_manager.cpp 2011-06-23 11:26:30 UTC (rev 9019) @@ -103,6 +103,7 @@ } #endif +// ============================================================================ FileManager* file_manager = 0; /** With irrlicht the constructor creates a NULL device. This is necessary to @@ -258,6 +259,9 @@ } // createAbsoluteFilename //----------------------------------------------------------------------------- +/** Adds a model search path to the list of model search paths. + * This path will be searched before any other existing paths. + */ void FileManager::pushModelSearchPath(const std::string& path) { m_model_search_path.push_back(path); @@ -282,6 +286,9 @@ } // pushModelSearchPath //----------------------------------------------------------------------------- +/** Adds a texture search path to the list of texture search paths. + * This path will be searched before any other existing paths. + */ void FileManager::pushTextureSearchPath(const std::string& path) { m_texture_search_path.push_back(path); @@ -307,6 +314,8 @@ } // pushTextureSearchPath //----------------------------------------------------------------------------- +/** Removes the last added texture search path from the list of paths. + */ void FileManager::popTextureSearchPath() { std::string dir = m_texture_search_path.back(); @@ -315,6 +324,8 @@ } // popTextureSearchPath //----------------------------------------------------------------------------- +/** Removes the last added model search path from the list of paths. + */ void FileManager::popModelSearchPath() { std::string dir = m_model_search_path.back(); @@ -323,14 +334,21 @@ } // popModelSearchPath //----------------------------------------------------------------------------- +/** Tries to find the specified file in any of the given search paths. + * \param full_path On return contains the full path of the file, or + * "" if the file is not found. + * \param file_name The name of the file to look for. + * \param search_path The list of paths to search for the file. + * \return True if the file is found, false otherwise. + */ bool FileManager::findFile(std::string& full_path, - const std::string& fname, + const std::string& file_name, const std::vector<std::string>& search_path) const { for(std::vector<std::string>::const_reverse_iterator i = search_path.rbegin(); i != search_path.rend(); ++i) { - full_path = *i + "/" + fname; + full_path = *i + "/" + file_name; if(m_file_system->existFile(full_path.c_str())) return true; } full_path=""; @@ -338,62 +356,87 @@ } // findFile //----------------------------------------------------------------------------- -std::string FileManager::getTextureFile(const std::string& FNAME) const +/** Returns the full path of a texture file name by searching for this + * file in all texture search paths. + * \param file_name Name of the texture file to search. + * \return The full path for the texture, or "" if the texture was not found. + */ +std::string FileManager::getTextureFile(const std::string& file_name) const { std::string path; - // FIXME: work around when loading and converting tracks: FNAME - // (which is based on an irrlicht return value) contains the - // full path - //if(m_file_system->existFile(FNAME.c_str())) return FNAME; - findFile(path, FNAME, m_texture_search_path); + findFile(path, file_name, m_texture_search_path); return path; -} // makeTexturePath +} // getTextureFile //----------------------------------------------------------------------------- -std::string FileManager::getModelFile(const std::string& FNAME) const +/** Returns the full path of a model file name by searching for this + * file in all model search paths. + * \param file_name Name of the model file to search. + * \return The full path for the model, or "" if the model was not found. + */ +std::string FileManager::getModelFile(const std::string& file_name) const { std::string path; - findFile(path, FNAME, m_model_search_path); + findFile(path, file_name, m_model_search_path); return path; } // getModelFile //----------------------------------------------------------------------------- +/** Returns the data directory. + */ std::string FileManager::getDataDir() const { return m_root_dir+"/data/"; -} +} // getDataDir + //----------------------------------------------------------------------------- +/** Returns the GUI directory. + */ std::string FileManager::getGUIDir() const { return m_root_dir+"/data/gui/"; -} +} // getGUIDir //----------------------------------------------------------------------------- +/** Returns the translation directory. + */ std::string FileManager::getTranslationDir() const { return m_root_dir+"/data/po"; } // getTranslationDir //----------------------------------------------------------------------------- +/** Returns the list of all directories in which music files are searched. + */ std::vector<std::string> FileManager::getMusicDirs() const { return m_music_search_path; } // getMusicDirs //----------------------------------------------------------------------------- -std::string FileManager::getDataFile(const std::string& fname) const +/** Returns the full path of a file in the data directory. + * \param file_name The file name (potentially including a path) to + * be used in the data directory. + */ +std::string FileManager::getDataFile(const std::string& file_name) const { - return m_root_dir+"/data/"+fname; + return m_root_dir+"/data/"+file_name; } // getDataFile //----------------------------------------------------------------------------- -std::string FileManager::getGfxFile(const std::string& fname) const +/** Returns the full path of graphical effect file + * \param file_name Name of the graphical effect file. + */ +std::string FileManager::getGfxFile(const std::string& file_name) const { - return m_root_dir+"/data/gfx/"+fname; + return m_root_dir+"/data/gfx/"+file_name; } //----------------------------------------------------------------------------- -/** If the directory specified in path does not exist, it is created. - * \params path Directory to test. - * \return True if the directory exists or could be created, false otherwise. +/** If the directory specified in path does not exist, it is created. This + * function does not support recursive operations, so if a directory "a/b" + * is tested, and "a" does not exist, this function will fail. + * \params path Directory to test. + * \return True if the directory exists or could be created, + * false otherwise. */ bool FileManager::checkAndCreateDirectory(const std::string &path) { @@ -402,7 +445,7 @@ if(m_file_system->existFile(io::path(path.c_str()))) return true; - std::cout << "creating directory <" << path << ">" << std::endl; + std::cout << "{FioleManager] Creating directory \"" << path << "\"\n"; // Otherwise try to create the directory: #if defined(WIN32) && !defined(__CYGWIN__) @@ -414,6 +457,11 @@ } // checkAndCreateDirectory //----------------------------------------------------------------------------- +/** If the directory specified in path does not exist, it is created + * recursively (mkdir -p style). + * \params path Directory to test. + * \return True if the directory exists or could be created, false otherwise. + */ bool FileManager::checkAndCreateDirectoryP(const std::string &path) { // irrlicht apparently returns true for files and directory @@ -421,23 +469,20 @@ if(m_file_system->existFile(io::path(path.c_str()))) return true; - std::cout << "creating directory(ies) <" << path << "> ..." << std::endl; + std::cout << "[FileManager] Creating directory(ies) '" << path << "'.\n"; std::vector<std::string> split = StringUtils::split(path,'/'); std::string current_path = ""; for (unsigned int i=0; i<split.size(); i++) { current_path += split[i] + "/"; - std::cout << " Checking for: " << current_path << std::endl; - if (m_file_system->existFile(io::path(current_path.c_str()))) + std::cout << "[FileManager] Checking for: '" + << current_path << "'.\n"; + if (!m_file_system->existFile(io::path(current_path.c_str()))) { - //std::cout << "The directory exist." << std::endl; - } - else - { if (!checkAndCreateDirectory(current_path)) { - fprintf(stderr, "Can't create dir '%s'", + fprintf(stderr, "[FileManager] Can't create dir '%s'", current_path.c_str()); break; } @@ -447,8 +492,12 @@ return error; } // checkAndCreateDirectory + //----------------------------------------------------------------------------- -/** Checks if the config directory exists, and it not, tries to create it. */ +/** Checks if the config directory exists, and it not, tries to create it. + * It will set m_config_dir to the path to which user-specific config files + * are stored. + */ void FileManager::checkAndCreateConfigDir() { if(getenv("SUPERTUXKART_SAVEDIR") && @@ -466,9 +515,8 @@ m_config_dir = getenv("APPDATA"); if(!checkAndCreateDirectory(m_config_dir)) { - fprintf(stderr, - "Can't create config dir '%s', falling back to '.'.\n", - m_config_dir.c_str()); + std::cerr << "[FileManager] Can't create config dir '" + << m_config_dir << "', falling back to '.'.\n"; m_config_dir = "."; } } @@ -485,7 +533,7 @@ } else { - std::cerr << "No home directory, this should NOT happen!\n"; + std::cerr << "[FileManager] No home directory, this should NOT happen!\n"; // Fall back to system-wide app data (rather than user-specific data), // but should not happen anyway. m_config_dir = ""; @@ -501,7 +549,7 @@ } else if (!getenv("HOME")) { - std::cerr << "No home directory, this should NOT happen " + std::cerr << "[FileManager] No home directory, this should NOT happen " << "- trying '.' for config files!\n"; m_config_dir = "."; } @@ -512,26 +560,21 @@ if(!checkAndCreateDirectory(m_config_dir)) { // If $HOME/.config can not be created: - fprintf(stderr, - "Can't create dir '%s', falling back to use '%s'.\n", - m_config_dir.c_str(), getenv("HOME")); + std::cerr << "[FileManager] Cannot create directory '" + << m_config_dir <<"', falling back to use '" + << getenv("HOME")<< "'.\n"; m_config_dir = getenv("HOME"); - m_config_dir += "."; } } - const std::string CONFIGDIR("supertuxkart"); - - m_config_dir += "/"; - m_config_dir += CONFIGDIR; + m_config_dir += "/supertuxkart"; #endif } // if(getenv("SUPERTUXKART_SAVEDIR") && checkAndCreateDirectory(...)) if(!checkAndCreateDirectory(m_config_dir)) { - fprintf(stderr, - "Can not create config dir '%s', falling back to '.'.\n", - m_config_dir.c_str()); + std::cerr << "[FileManager] Can not create config dir '" + << m_config_dir << "', falling back to '.'.\n"; m_config_dir = "."; } return; @@ -582,7 +625,7 @@ } if(!dir_ok && getenv("HOME")) { - // Use ~/.local/share : + // Use ~/.stkaddons m_addons_dir = getenv("HOME"); m_addons_dir += "/.stkaddons"; dir_ok = checkAndCreateDirectory(m_addons_dir); @@ -639,70 +682,97 @@ } // getADdonsDir //----------------------------------------------------------------------------- -/** Returns a filename in the addons directory. +/** Returns the full path of a file in the addons directory. * \param name Name of the file. */ std::string FileManager::getAddonsFile(const std::string &name) { return getAddonsDir()+"/"+name; -} +} // getAddonsFile //----------------------------------------------------------------------------- +/** Returns the full path of the config directory. + */ std::string FileManager::getConfigDir() const { return m_config_dir; } // getConfigDir //----------------------------------------------------------------------------- -std::string FileManager::getLogFile(const std::string& fname) const +/** Returns the full path of a file in the user config directory which is + * used to store stdout/stderr if it is redirected. + * \param name Name of the file. + */ +std::string FileManager::getLogFile(const std::string& file_name) const { - return getConfigDir()+"/"+fname; + return getConfigDir()+"/"+file_name; } // getLogFile //----------------------------------------------------------------------------- -std::string FileManager::getMusicFile(const std::string& fname) const +/** Returns the full path of a music file by searching all music search paths. + * It throws an exception if the file is not found. + * \param file_name File name to search for. + */ +std::string FileManager::getMusicFile(const std::string& file_name) const { std::string path; - const bool success = findFile(path, fname, m_music_search_path); + const bool success = findFile(path, file_name, m_music_search_path); if (!success) { throw std::runtime_error( - "[FileManager::getMusicFile] Cannot find music file <"+fname+">"); + "[FileManager::getMusicFile] Cannot find music file '" + +file_name+"'."); } return path; } // getMusicFile //----------------------------------------------------------------------------- -std::string FileManager::getSFXFile(const std::string& fname) const +/** Returns the full path of a sound effect file. + * \param file_name Name of the sound effect file. + */ +std::string FileManager::getSFXFile(const std::string& file_name) const { - return m_root_dir+"/data/sfx/"+fname; + return m_root_dir+"/data/sfx/"+file_name; } // getSFXFile + //----------------------------------------------------------------------------- -std::string FileManager::getFontFile(const std::string& fname) const +/** Returns the full path of a font file. + * \param file_name Name of the font file. + */ +std::string FileManager::getFontFile(const std::string& file_name) const { - return m_root_dir+"/data/fonts/"+fname; + return m_root_dir+"/data/fonts/"+file_name; } // getFontFile + //----------------------------------------------------------------------------- -std::string FileManager::getHighscoreFile(const std::string& fname) const +/** Returns the full path of a highscore file (which is stored in the user + * specific config directory). + * \param file_name Name of the sound effect file. + */ +std::string FileManager::getHighscoreFile(const std::string& file_name) const { - return getConfigDir()+"/"+fname; + return getConfigDir()+"/"+file_name; } // getHighscoreFile //----------------------------------------------------------------------------- -/** Returns the full path of the challenge file. */ -std::string FileManager::getChallengeFile(const std::string &fname) const +/** Returns the full path of the challenge file (which is stored in a user + * specific config area). + * \param file_name Name of the file. + */ +std::string FileManager::getChallengeFile(const std::string &file_name) const { - return getConfigDir()+"/"+fname; + return getConfigDir()+"/"+file_name; } // getChallengeFile //----------------------------------------------------------------------------- -/** Returns the full path of the tutorial file. */ -std::string FileManager::getTutorialFile(const std::string &fname) const +/** Returns the full path of the tutorial file. + * \param file_name Name of the tutorial file to return. + */ +std::string FileManager::getTutorialFile(const std::string &file_name) const { - return getConfigDir()+"/"+fname; + return getConfigDir()+"/"+file_name; } // getTutorialFile - //----------------------------------------------------------------------------- /** Returns true if the given name is a directory. * \param path File name to test. @@ -716,6 +786,14 @@ } // isDirectory //----------------------------------------------------------------------------- +/** Returns a list of files in a given directory. + * \param result A reference to a std::vector<std::string> which will + * hold all files in a directory. The vector will be cleared. + * \param dir The director for which to get the directory listing. + * \param is_full_path True if directory is already a full path, + * otherwise m_root_dir is used. + * \param make_full_path If set to true, all listed files will be full paths. + */ void FileManager::listFiles(std::set<std::string>& result, const std::string& dir, bool is_full_path, bool make_full_path) const @@ -751,7 +829,11 @@ } // listFiles //----------------------------------------------------------------------------- - +/** Creates a directory for an addon. + * \param addons_name Name of the directory to create. + * \param addons_type The type, which is used as a subdirectory. E.g.: + * 'karts' (m_addons_dir/karts/name will be created). + */ void FileManager::checkAndCreateDirForAddons(std::string addons_name, std::string addons_type) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |