- Unison::VFS::FileSystem &fs = Unison::VFS::FileSystem::get();
- std::string application = "supertux2";
- std::string userdir = fs.get_user_dir();
- std::string dirsep = fs.get_dir_sep();
- std::string writedir = userdir + "." + application;
- fs.set_write_dir(writedir);
- fs.mount(writedir, "/", true);
-
- // Search for archives and add them to the search path
- const char* archiveExt = ".zip";
- std::vector<std::string> rc = fs.ls("/");
- for(std::vector<std::string>::iterator iter = rc.begin(); iter != rc.end(); ++iter)
- {
- std::string ext = iter->substr(iter->length() - 4);
- if(strcasecmp(ext.c_str(), archiveExt) == 0)
- {
- std::string dir = fs.get_real_dir(*iter);
- fs.mount(dir + fs.get_dir_sep() + *iter, "/", true);
- }
- }
-
- // when started from source dir...
- std::string dir = fs.get_base_dir();
- dir += "/data";
- std::string testfname = dir;
- testfname += "/credits.txt";
- bool sourcedir = false;
- FILE* f = fopen(testfname.c_str(), "r");
- if(f) {
- fclose(f);
- fs.mount(dir, "/", true);
- sourcedir = true;
- /*if(!PHYSFS_addToSearchPath(dir.c_str(), 1)) {
- log_warning << "Couldn't add '" << dir << "' to physfs searchpath: " << PHYSFS_getLastError() << std::endl;
- } else {
- sourcedir = true;
- }*/
- }
-
-#ifdef MACOSX
- // when started from Application file on Mac OS X...
- char path[PATH_MAX];
- CFBundleRef mainBundle = CFBundleGetMainBundle();
- assert(mainBundle != 0);
- CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle);
- assert(mainBundleURL != 0);
- CFStringRef pathStr = CFUrlCopyFileSystemPath(mainBundleURL, kCFURLPOSIXPathStyle);
- assert(pathStr != 0);
- CFStringGetCString(pathStr, path, PATH_MAX, kCFStringEncodingUTF8);
- CFRelease(mainBundleURL);
- CFRelease(pathStr);
-
- dir = std::string(path) + "/Contents/Resources/data";
- testfname = dir + "/credits.txt";
- sourcedir = false;
- f = fopen(testfname.c_str(), "r");
- if(f) {
- fclose(f);
- fs.mount(dir, "/", true);
- sourcedir = true;
- /*if(!PHYSFS_addToSearchPath(dir.c_str(), 1)) {
- log_warning << "Couldn't add '" << dir << "' to physfs searchpath: " << PHYSFS_getLastError() << std::endl;
- } else {
- sourcedir = true;
- }*/
- }
-#endif
-
-#ifdef _WIN32
- fs.mount(".\\data", "/", true);
- //PHYSFS_addToSearchPath(".\\data", 1);
-#endif
-
- if(!sourcedir) {
-#if defined(APPDATADIR) || defined(ENABLE_BINRELOC)
- std::string datadir;
-#ifdef ENABLE_BINRELOC
-
- char* dir;
- br_init (NULL);
- dir = br_find_data_dir(APPDATADIR);
- datadir = dir;
- free(dir);
-
-#else
- datadir = APPDATADIR;
-#endif
- datadir += "/";
- datadir += application;
- fs.mount(datadir, "/", true);
- /*if(!PHYSFS_addToSearchPath(datadir.c_str(), 1)) {
- log_warning << "Couldn't add '" << datadir << "' to physfs searchpath: " << PHYSFS_getLastError() << std::endl;
- }*/
-#endif
- }
-
- // allow symbolic links
- //PHYSFS_permitSymbolicLinks(1);
- //fs.follow_sym_links(true);
-
- //show search Path
- std::vector<std::string> searchpath = fs.get_search_path();
- for(std::vector<std::string>::iterator iter = searchpath.begin(); iter != searchpath.end(); ++iter)
- log_info << "[" << *iter << "] is in the search path" << std::endl;
- /*
- char** searchpath = PHYSFS_getSearchPath();
- for(char** i = searchpath; *i != NULL; i++)
- log_info << "[" << *i << "] is in the search path" << std::endl;
- PHYSFS_freeList(searchpath);
- */
-
-#if 0