Added a file with a 'unique filename' with version number which is used by STK

to detect that stk is reading the right data files (and therefore avoids #2073,
in which stk finds the wrong data directory).
This commit is contained in:
hiker 2015-07-31 22:06:21 +10:00
parent b6165ce5f5
commit 78c592e4e5
4 changed files with 27 additions and 14 deletions

2
data/supertuxkart.git Normal file
View File

@ -0,0 +1,2 @@
This file is only here to help STK finding the right directory,
and to avoid problems with other directories called 'data'.

View File

@ -142,7 +142,7 @@ FileManager::FileManager()
m_file_system = irr::io::createFileSystem();
irr::io::path exe_path;
std::string exe_path;
// Search for the root directory
// =============================
@ -151,8 +151,11 @@ FileManager::FileManager()
// 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());
const std::string version = std::string("supertuxkart.") + STK_VERSION;
if (fileExists(CommandLine::getExecName()))
{
exe_path = StringUtils::getPath(CommandLine::getExecName());
}
if(exe_path.size()==0 || exe_path[exe_path.size()-1]!='/')
exe_path += "/";
if ( getenv ( "SUPERTUXKART_DATADIR" ) != NULL )
@ -160,19 +163,19 @@ FileManager::FileManager()
#ifdef __APPLE__
else if( macSetBundlePathIfRelevant( root_dir ) ) { root_dir = root_dir + "data/"; }
#endif
else if(m_file_system->existFile("data/stk_config.xml"))
else if(fileExists("data/", version))
root_dir = "data/" ;
else if(m_file_system->existFile("../data/stk_config.xml"))
else if(fileExists("../data/", version))
root_dir = "../data/" ;
else if(m_file_system->existFile("../../data/stk_config.xml"))
else if(fileExists("../../data/", version))
root_dir = "../../data/" ;
// Test for old style build environment, with executable in root of stk
else if(m_file_system->existFile(exe_path+"data/stk_config.xml"))
else if(fileExists(exe_path+"data/"+version))
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/stk_config.xml"))
root_dir = (exe_path + "../../../data/").c_str();
else if (m_file_system->existFile(exe_path + "../data/stk_config.xml"))
else if (fileExists(exe_path + "../../../data/"+version))
root_dir = exe_path + "../../../data/";
else if (fileExists(exe_path + "../data/"+version))
{
root_dir = exe_path.c_str();
root_dir += "../data/";
@ -186,10 +189,10 @@ FileManager::FileManager()
#endif
}
if (!m_file_system->existFile((root_dir + "stk_config.xml").c_str()))
if (!m_file_system->existFile((root_dir + version).c_str()))
{
Log::error("FileManager", "Could not file stk_config.xml in any "
"standard location (esp. ../data).");
Log::error("FileManager", "Could not file '%s'in any "
"standard location (esp. ../data).", version.c_str());
Log::error("FileManager",
"Last location checked '%s'.", root_dir.c_str());
Log::fatal("FileManager",

View File

@ -134,6 +134,14 @@ public:
std::string searchTexture(const std::string& fname) const;
std::string getUserConfigFile(const std::string& fname) const;
bool fileExists(const std::string& path) const;
// ------------------------------------------------------------------------
/** Convenience function to save some typing in the
* file manager constructor. */
bool fileExists(const char *prefix, const std::string& path) const
{
return fileExists(std::string(prefix) + path);
}
// ------------------------------------------------------------------------
void listFiles (std::set<std::string>& result,
const std::string& dir,
bool make_full_path=false) const;

View File

@ -1078,7 +1078,7 @@ int handleCmdLine()
void initUserConfig()
{
file_manager = new FileManager();
user_config = new UserConfig(); // needs file_manager
user_config = new UserConfig(); // needs file_manager
user_config->loadConfig();
// Some parts of the file manager needs user config (paths for models
// depend on artist debug flag). So init the rest of the file manager