void usage(char * prog, int ret);
/* Does the given file exist and is it accessible? */
-int FileSystem::faccessible(const std::string& filename)
+bool FileSystem::faccessible(const std::string& filename)
{
struct stat filestat;
if (stat(filename.c_str(), &filestat) == -1)
}
/* Can we write to this location? */
-int FileSystem::fwriteable(const std::string& filename)
+bool FileSystem::fwriteable(const std::string& filename)
{
FILE* fi;
fi = fopen(filename.c_str(), "wa");
}
/* Makes sure a directory is created in either the SuperTux home directory or the SuperTux base directory.*/
-int FileSystem::fcreatedir(const std::string& relative_dir)
+bool FileSystem::fcreatedir(const std::string& relative_dir)
{
std::string path = st_dir + "/" + relative_dir + "/";
if(mkdir(path.c_str(),0755) != 0)
return sdirs;
}
+std::string FileSystem::dirname(const std::string& filename)
+{
+ std::string::size_type p = filename.find_last_of('/');
+ if(p == std::string::npos)
+ return "";
+
+ return filename.substr(0, p+1);
+}
+
void Setup::init(const std::string& _package_name,
const std::string& _package_symbol_name,
const std::string& _package_version)
// try current directory as datadir
if(datadir.empty()) {
- if(FileSystem::faccessible("./data/intro.txt"))
+ if(FileSystem::faccessible("./data/credits.txt"))
datadir = "./data/";
}
{
std::string exedir = std::string(dirname(exe_file)) + "/";
- datadir = exedir + "../data/"; // SuperTux run from source dir
+ datadir = exedir + "./data/"; // SuperTux run from source dir
if (access(datadir.c_str(), F_OK) != 0)
{
- datadir = exedir + "../../data/"; //SuperTux run from source dir (with libtool script)
+ datadir = exedir + "../../../../data/"; //SuperTux run from source dir (with libtool script)
if (access(datadir.c_str(), F_OK) != 0)
{