+ // allow symbolic links
+ PHYSFS_permitSymbolicLinks(1);
+
+ // Initialize physfs (this is a slightly modified version of
+ // PHYSFS_setSaneConfig
+ const char* application = "supertux2"; //instead of PACKAGE_NAME so we can coexist with MS1
+ const char* userdir = PHYSFS_getUserDir();
+ char* writedir = new char[strlen(userdir) + strlen(application) + 2];
+
+ // Set configuration directory
+ sprintf(writedir, "%s.%s", userdir, application);
+ if(!PHYSFS_setWriteDir(writedir)) {
+ // try to create the directory
+ char* mkdir = new char[strlen(application) + 2];
+ sprintf(mkdir, ".%s", application);
+ if(!PHYSFS_setWriteDir(userdir) || !PHYSFS_mkdir(mkdir)) {
+ std::ostringstream msg;
+ msg << "Failed creating configuration directory '"
+ << writedir << "': " << PHYSFS_getLastError();
+ delete[] writedir;
+ delete[] mkdir;
+ throw std::runtime_error(msg.str());
+ }
+ delete[] mkdir;
+
+ if(!PHYSFS_setWriteDir(writedir)) {
+ std::ostringstream msg;
+ msg << "Failed to use configuration directory '"
+ << writedir << "': " << PHYSFS_getLastError();
+ delete[] writedir;
+ throw std::runtime_error(msg.str());
+ }
+ }
+ PHYSFS_addToSearchPath(writedir, 0);
+ delete[] writedir;
+
+ // when started from source dir...
+ std::string dir = PHYSFS_getBaseDir();
+ dir += "/data";
+ std::string testfname = dir;
+ testfname += "/credits.txt";
+ bool sourcedir = false;
+ FILE* f = fopen(testfname.c_str(), "r");
+ if(f) {
+ fclose(f);
+ if(!PHYSFS_addToSearchPath(dir.c_str(), 1)) {
+ log_warning << "Couldn't add '" << dir << "' to physfs searchpath: " << PHYSFS_getLastError() << std::endl;
+ } else {
+ sourcedir = true;