Beispiel #1
0
static int Lua_FS_setSearchPath(lua_State *L) {
	const char *str;
	char **search_path = PHYSFS_getSearchPath();
	char **copy = search_path;
	int n, maxn;

	luaL_checktype(L, 1, LUA_TTABLE);

	/* clear the search path */
	while (*copy != NULL) {
		PHYSFS_removeFromSearchPath(*copy++);
	}

	PHYSFS_freeList(search_path);
	maxn = lua_objlen(L, 1);
	for (n = 1; n <= maxn; n++) {
		lua_pushinteger(L, n);
		lua_gettable(L, -2);
		str = lua_tostring(L, -1);
		if (PHYSFS_addToSearchPath(str, 1) == 0) {
			return luaL_error(L,	"Error: Could not add directory or archive '%s' "
									"to search path: %s", str, PHYSFS_getLastError());
		}
		/* remove the string */
		lua_pop(L, 1);
	}

	return 0;
}
bool FileSystem::removeAllSearchPaths()
{
	bool ret = false;

	char **paths;
	for (paths = PHYSFS_getSearchPath(); *paths != NULL; paths++)
	{
		PHYSFS_removeFromSearchPath(*paths);
	}

	if (*(paths = PHYSFS_getSearchPath()) == NULL)
		ret = true;

	PHYSFS_freeList(paths);


	return ret;
}
Beispiel #3
0
StringList getSearchPath() {
	StringList pathList;
	char ** pathBegin = PHYSFS_getSearchPath();
	for (char ** path = pathBegin; *path != NULL; path++) {
		pathList.push_back(*path);
	}
	PHYSFS_freeList(pathBegin);
	return pathList;
}
Beispiel #4
0
const char *physfscdromDrive::GetInfo() {
	char **files = PHYSFS_getSearchPath(), **list = files;
	sprintf(info,"PHYSFS directory %s in ",basedir);
	while (*files != NULL) {
		strcat(info,*files++);
		strcat(info,", ");
	}
	strcat(info,"CD-ROM mode (read-only)");
	PHYSFS_freeList(list);
	return info;
}
Beispiel #5
0
void printSearchPath( void )
{
	char ** i, ** searchPath;

	debug(LOG_WZ, "Search paths:");
	searchPath = PHYSFS_getSearchPath();
	for (i = searchPath; *i != NULL; i++) {
		debug(LOG_WZ, "    [%s]", *i);
	}
	PHYSFS_freeList( searchPath );
}
  StringVector getSearchPath()
  {
    char** locList = PHYSFS_getSearchPath();
    if (locList == 0)
      throw Exception(PHYSFS_getLastError());

    StringVector list;
    for (char** l = locList; *l != 0; ++l)
      list.push_back(*l);
    PHYSFS_freeList(locList);
    return list;
  }
Beispiel #7
0
void physfs_printSearchPath()
{
    char ** i, ** searchPath;

    debug(0, "%s", "Search paths:");
    searchPath = PHYSFS_getSearchPath();
    for (i = searchPath; *i != NULL; i++)
    {
        debug(0, "    [%s]", *i);
    }
    PHYSFS_freeList(searchPath);
}
void
CommandLineArguments::print_datadir() const
{
  // Print the datadir searchpath to stdout, one path per
  // line. Then exit. Intended for use by the supertux-editor.
  char **sp;
  sp = PHYSFS_getSearchPath();
  if (sp)
    for (size_t sp_index = 0; sp[sp_index]; sp_index++)
      std::cout << sp[sp_index] << std::endl;
  PHYSFS_freeList(sp);
}
Beispiel #9
0
 void print_search_path()
 {
   const char* writedir = PHYSFS_getWriteDir();
   log_info << "PhysfsWritedDir: " << (writedir ? writedir : "(null)") << std::endl;
   log_info << "PhysfsSearchPath:" << std::endl;
   char** searchpath = PHYSFS_getSearchPath();
   for(char** i = searchpath; *i != NULL; ++i)
   {
     log_info << "  " << *i << std::endl;
   }
   PHYSFS_freeList(searchpath);
 }
Beispiel #10
0
static int Lua_FS_getSearchPath(lua_State *L) {
	char **search_path = PHYSFS_getSearchPath();
	char **copy = search_path;
	int n = 1;
	lua_newtable(L);
	while (*copy != NULL) {
		lua_pushstring(L, *copy++);
		lua_rawseti(L, -2, n++);
	}
	PHYSFS_freeList(search_path);

	return 1;
}
Beispiel #11
0
const char *physfsDrive::GetInfo() {
	char **files = PHYSFS_getSearchPath(), **list = files;
	sprintf(info,"PHYSFS directory %s in ",basedir);
	while (*files != NULL) {
		strcat(info,*files++);
		strcat(info,", ");
	}
	if (PHYSFS_getWriteDir() != NULL) {
		strcat(info,"writing to ");
		strcat(info,PHYSFS_getWriteDir());
	} else {
		strcat(info,"read-only");
	}
	PHYSFS_freeList(list);
	return info;
}
Beispiel #12
0
// checks if path is already added to Searchpath. Returns 0 if yes, 1 if not.
int PHYSFSX_isNewPath(const char *path)
{
	int is_new_path = 1;
	char **i, **list;
	
	list = PHYSFS_getSearchPath();
	for (i = list; *i != NULL; i++)
	{
		if (!strcmp(path, *i))
		{
			is_new_path = 0;
		}
	}
	PHYSFS_freeList(list);
	
	return is_new_path;
}
Beispiel #13
0
void PHYSFSX_listSearchPathContent()
{
	char **i, **list;

	con_printf(CON_DEBUG, "PHYSFS: Listing contents of Search Path.\n");
	list = PHYSFS_getSearchPath();
	for (i = list; *i != NULL; i++)
		con_printf(CON_DEBUG, "PHYSFS: [%s] is in the Search Path.\n", *i);
	PHYSFS_freeList(list);

	list = PHYSFS_enumerateFiles("");
	for (i = list; *i != NULL; i++)
		con_printf(CON_DEBUG, "PHYSFS: * We've got [%s].\n", *i);
	PHYSFS_freeList(list);
	
	con_printf(CON_DEBUG, "\n");
}
static int cmd_getsearchpath(char *args)
{
    char **rc = PHYSFS_getSearchPath();
    (void)args;
    if (rc == NULL)
        printf("Failure. reason: %s.\n", PHYSFS_getLastError());
    else
    {
        int dir_count;
        char **i;
        for (i = rc, dir_count = 0; *i != NULL; i++, dir_count++)
            printf("%s\n", *i);

        printf("\n total (%d) directories.\n", dir_count);
        PHYSFS_freeList(rc);
    } /* else */

    return(1);
} /* cmd_getcdromdirs */
Beispiel #15
0
int main(int argc, char* argv[])
{
    PHYSFS_init(NULL);

    {
        PHYSFS_Version compiled;
        PHYSFS_Version linked;

        PHYSFS_VERSION(&compiled);
        PHYSFS_getLinkedVersion(&linked);
        printf("We compiled against PhysFS version %d.%d.%d ...\n",
                compiled.major, compiled.minor, compiled.patch);
        printf("But we linked against PhysFS version %d.%d.%d.\n",
                linked.major, linked.minor, linked.patch);
    }

    {
        const PHYSFS_ArchiveInfo** i;
        for(i = PHYSFS_supportedArchiveTypes(); *i != NULL; i++)
        {
            printf("Supported archive: [%s], which is [%s].\n",
                (*i)->extension, (*i)->description);
        }
    }

    {
        char **cds = PHYSFS_getCdRomDirs();
        char **i;
        for (i = cds; *i != NULL; i++)
            printf("cdrom dir [%s] is available.\n", *i);
        PHYSFS_freeList(cds);
    }

    {
        char **i;
        for (i = PHYSFS_getSearchPath(); *i != NULL; i++)
            printf("[%s] is in the search path.\n", *i);
        PHYSFS_freeList(i);
    }

    PHYSFS_deinit();
}
Beispiel #16
0
bool Lux::Core::FileHandler::ResourcePathExists(const String a_Path)
{
    char** path = PHYSFS_getSearchPath();

    if (path == nullptr)
    {
        String errstr("Error fetching the search path. ");
        errstr.append(PHYSFS_getLastError());
        Utility::ThrowError(errstr);
    }

    // Search for the string inside the current search path
    bool retval = false;
    for (char** i = path; i != nullptr; i++)
    {
        if (a_Path.compare(*i) == 0)
        {
            retval = true;
            break;
        }
    }
    PHYSFS_freeList(path); // Free the list
    return retval;
}
Beispiel #17
0
static MapFileList listMapFiles()
{
	MapFileList ret, filtered, oldSearchPath;

	char **subdirlist = PHYSFS_enumerateFiles("maps");

	for (char **i = subdirlist; *i != NULL; ++i)
	{
		std::string wzfile = *i;
		if (*i[0] == '.' || wzfile.substr(wzfile.find_last_of(".")+1) != "wz")
		{
			continue;
		}

		std::string realFileName = std::string("maps/") + *i;
		ret.push_back(realFileName);
	}
	PHYSFS_freeList(subdirlist);
	// save our current search path(s)
	debug(LOG_WZ, "Map search paths:");
	char **searchPath = PHYSFS_getSearchPath();
	for (char **i = searchPath; *i != NULL; i++)
	{
		debug(LOG_WZ, "    [%s]", *i);
		oldSearchPath.push_back(*i);
		PHYSFS_removeFromSearchPath(*i);
	}
	PHYSFS_freeList(searchPath);

	for (MapFileList::iterator realFileName = ret.begin(); realFileName != ret.end(); ++realFileName)
	{
		std::string realFilePathAndName = PHYSFS_getWriteDir() + *realFileName;
		PHYSFS_addToSearchPath(realFilePathAndName.c_str(), PHYSFS_APPEND);
		int unsafe = 0;
		char **filelist = PHYSFS_enumerateFiles("multiplay/maps");

		for (char **file = filelist; *file != NULL; ++file)
		{
			std::string isDir = std::string("multiplay/maps/") + *file;
			if (PHYSFS_isDirectory(isDir.c_str()))
				continue;
			std::string checkfile = *file;
			debug(LOG_WZ,"checking ... %s", *file);
			if (checkfile.substr(checkfile.find_last_of(".")+ 1) == "gam")
			{
				if (unsafe++ > 1)
				{
					debug(LOG_ERROR, "Map packs are not supported! %s NOT added.", realFilePathAndName.c_str());
					break;
				}
			}
		}
		PHYSFS_freeList(filelist);
		if (unsafe < 2)
		{
			filtered.push_back(realFileName->c_str());
		}
		PHYSFS_removeFromSearchPath(realFilePathAndName.c_str());
	}

	// restore our search path(s) again
	for (MapFileList::iterator restorePaths = oldSearchPath.begin(); restorePaths != oldSearchPath.end(); ++restorePaths)
	{
		PHYSFS_addToSearchPath(restorePaths->c_str(), PHYSFS_APPEND);
	}
	debug(LOG_WZ, "Search paths restored");
	printSearchPath();

	return filtered;
}
Beispiel #18
0
static MapFileList listMapFiles()
{
	MapFileList ret, filtered, oldSearchPath;

	char **subdirlist = PHYSFS_enumerateFiles("maps");

	for (char **i = subdirlist; *i != nullptr; ++i)
	{
		std::string wzfile = *i;
		if (*i[0] == '.' || wzfile.substr(wzfile.find_last_of('.') + 1) != "wz")
		{
			continue;
		}

		std::string realFileName = std::string("maps/") + *i;
		ret.push_back(realFileName);
	}
	PHYSFS_freeList(subdirlist);
	// save our current search path(s)
	debug(LOG_WZ, "Map search paths:");
	char **searchPath = PHYSFS_getSearchPath();
	for (char **i = searchPath; *i != nullptr; i++)
	{
		debug(LOG_WZ, "    [%s]", *i);
		oldSearchPath.push_back(*i);
		WZ_PHYSFS_unmount(*i);
	}
	PHYSFS_freeList(searchPath);

	for (const auto &realFileName : ret)
	{
		std::string realFilePathAndName = PHYSFS_getWriteDir() + realFileName;
		if (PHYSFS_mount(realFilePathAndName.c_str(), NULL, PHYSFS_APPEND))
		{
			int unsafe = 0;
			char **filelist = PHYSFS_enumerateFiles("multiplay/maps");

			for (char **file = filelist; *file != nullptr; ++file)
			{
				std::string isDir = std::string("multiplay/maps/") + *file;
				if (WZ_PHYSFS_isDirectory(isDir.c_str()))
				{
					continue;
				}
				std::string checkfile = *file;
				debug(LOG_WZ, "checking ... %s", *file);
				if (checkfile.substr(checkfile.find_last_of('.') + 1) == "gam")
				{
					if (unsafe++ > 1)
					{
						debug(LOG_ERROR, "Map packs are not supported! %s NOT added.", realFilePathAndName.c_str());
						break;
					}
				}
			}
			PHYSFS_freeList(filelist);
			if (unsafe < 2)
			{
				filtered.push_back(realFileName);
			}
			WZ_PHYSFS_unmount(realFilePathAndName.c_str());
		}
		else
		{
			debug(LOG_POPUP, "Could not mount %s, because: %s.\nPlease delete or move the file specified.", realFilePathAndName.c_str(), WZ_PHYSFS_getLastError());
		}
	}

	// restore our search path(s) again
	for (const auto &restorePaths : oldSearchPath)
	{
		PHYSFS_mount(restorePaths.c_str(), NULL, PHYSFS_APPEND);
	}
	debug(LOG_WZ, "Search paths restored");
	printSearchPath();

	return filtered;
}
Beispiel #19
0
static void init_physfs(const char* argv0)
{
  if(!PHYSFS_init(argv0)) {
    std::stringstream msg;
    msg << "Couldn't initialize physfs: " << PHYSFS_getLastError();
    throw std::runtime_error(msg.str());
  }

  // Initialize physfs (this is a slightly modified version of
  // PHYSFS_setSaneConfig
  const char* application = PACKAGE_NAME;
  const char* userdir = PHYSFS_getUserDir();
  const char* dirsep = PHYSFS_getDirSeparator();
  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;

  // Search for archives and add them to the search path
  const char* archiveExt = "zip";
  char** rc = PHYSFS_enumerateFiles("/");
  size_t extlen = strlen(archiveExt);

  for(char** i = rc; *i != 0; ++i) {
    size_t l = strlen(*i);
    if((l > extlen) && ((*i)[l - extlen - 1] == '.')) {
      const char* ext = (*i) + (l - extlen);
      if(strcasecmp(ext, archiveExt) == 0) {
        const char* d = PHYSFS_getRealDir(*i);
        char* str = new char[strlen(d) + strlen(dirsep) + l + 1];
        sprintf(str, "%s%s%s", d, dirsep, *i);
        PHYSFS_addToSearchPath(str, 1);
        delete[] str;
      }
    }
  }
  
  PHYSFS_freeList(rc);

  // 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;
    }
  }

#ifdef MACOSX
  // when started from Application file on Mac OS X...
  dir = PHYSFS_getBaseDir();
  dir += "SuperTux.app/Contents/Resources/data";
  testfname = dir + "/credits.txt";
  sourcedir = false;
  f = fopen(testfname.c_str(), "r");
  if(f) {
    fclose(f);
    if(!PHYSFS_addToSearchPath(dir.c_str(), 1)) {
      msg_warning << "Couldn't add '" << dir << "' to physfs searchpath: " << PHYSFS_getLastError() << std::endl;
    } else {
      sourcedir = true;
    }
  }
#endif

  if(!sourcedir) {
#if defined(APPDATADIR) || defined(ENABLE_BINRELOC)
    std::string datadir;
#ifdef ENABLE_BINRELOC
    char* brdatadir = br_strcat(DATADIR, "/" PACKAGE_NAME);
    datadir = brdatadir;
    free(brdatadir);
#else
    datadir = APPDATADIR;
#endif
    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);

  //show search Path
  for(char** i = PHYSFS_getSearchPath(); *i != NULL; i++)
    log_info << "[" << *i << "] is in the search path" << std::endl;
}
void initPhysfs(const char* argv0)
{
    if(!PHYSFS_init(argv0)) {
        std::stringstream msg;
        msg << "Couldn't initialize physfs: " << PHYSFS_getLastError();
        throw std::runtime_error(msg.str());
    }

    // Initialize physfs (this is a slightly modified version of
    // PHYSFS_setSaneConfig
    const char* application = /* PACKAGE_NAME */ "lincity";
    const char* userdir = PHYSFS_getUserDir();
    const char* dirsep = PHYSFS_getDirSeparator();
    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;
   
    // Search for archives and add them to the search path
    const char* archiveExt = "zip";
    char** rc = PHYSFS_enumerateFiles("/");
    size_t extlen = strlen(archiveExt);

    for(char** i = rc; *i != 0; ++i) {
        size_t l = strlen(*i);
        if((l > extlen) && ((*i)[l - extlen - 1] == '.')) {
            const char* ext = (*i) + (l - extlen);
            if(strcasecmp(ext, archiveExt) == 0) {
                const char* d = PHYSFS_getRealDir(*i);
                char* str = new char[strlen(d) + strlen(dirsep) + l + 1];
                sprintf(str, "%s%s%s", d, dirsep, *i);
                PHYSFS_addToSearchPath(str, 1);
                delete[] str;
            }
        }
    }

    PHYSFS_freeList(rc);
            
    // when started from source dir...
    std::string dir = PHYSFS_getBaseDir();
    dir += "/data";
    std::string testfname = dir;
    testfname += "/images/tiles/images.xml";
    FILE* f = fopen(testfname.c_str(), "r");
    if(f) {
        fclose(f);
        if(!PHYSFS_addToSearchPath(dir.c_str(), 1)) {
#ifdef DEBUG
            std::cout << "Warning: Couldn't add '" << dir << 
                "' to physfs searchpath: " << PHYSFS_getLastError() << "\n";
#endif
        }
    }

#if defined(APPDATADIR) || defined(ENABLE_BINRELOC)
    std::string datadir;
#ifdef ENABLE_BINRELOC
    BrInitError error;
    if (br_init (&error) == 0 && error != BR_INIT_ERROR_DISABLED) {
        printf ("Warning: BinReloc failed to initialize (error code %d)\n",
                error);
        printf ("Will fallback to hardcoded default path.\n");
    }
    
    char* brdatadir = br_find_data_dir("/usr/local/share");
    datadir = brdatadir;
    datadir += "/" PACKAGE_NAME;
    free(brdatadir);
#else
    datadir = APPDATADIR;
#endif
    
    if(!PHYSFS_addToSearchPath(datadir.c_str(), 1)) {
        std::cout << "Couldn't add '" << datadir
            << "' to physfs searchpath: " << PHYSFS_getLastError() << "\n";
    }
#endif

    // allow symbolic links
    PHYSFS_permitSymbolicLinks(1);

    //show search Path 
    for(char** i = PHYSFS_getSearchPath(); *i != NULL; i++)
        printf("[%s] is in the search path.\n", *i);

    // ugly: set LINCITY_HOME environment variable
    const char* lincityhome = PHYSFS_getRealDir("colour.pal");
    if(lincityhome == 0) {
        throw std::runtime_error("Couldn't locate lincity data (colour.pal).");
    }
    std::cout << "LINCITY_HOME: " << lincityhome << "\n";
    char tmp[256];
    snprintf(tmp, sizeof(tmp), "LINCITY_HOME=%s", lincityhome);
    putenv(tmp);
}