+ // User has not that a datadir, so we try some magic
+ if (datadir.empty())
+ {
+ // Detect datadir
+ char exe_file[PATH_MAX];
+ if (readlink("/proc/self/exe", exe_file, PATH_MAX) < 0)
+ {
+ puts("Couldn't read /proc/self/exe, using default path: " DATA_PREFIX);
+ }
+ else
+ {
+ std::string exedir = std::string(dirname(exe_file)) + "/";
+
+ datadir = exedir + "../data/"; // SuperTux run from source dir
+ if (access(datadir.c_str(), F_OK) != 0)
+ {
+ datadir = exedir + "../share/supertux/"; // SuperTux run from PATH
+ if (access(datadir.c_str(), F_OK) != 0)
+ { // If all fails, fall back to compiled path
+ datadir = DATA_PREFIX;
+ }
+ }
+ }
+ }
+ printf("Datadir: %s\n", datadir.c_str());