示例#1
0
ResourceCache::ResourceCache() {
	PHYSFS_init(NULL);
	PHYSFS_addToSearchPath("data/images.zip", 1);
	PHYSFS_addToSearchPath("data/sounds.zip", 1);
	al_init_image_addon();
	al_init_acodec_addon();
	al_set_physfs_file_interface();
}
示例#2
0
void ResourceManager::initialize()
{
    PHYSFS_permitSymbolicLinks(1);

    const std::string worldDataPath =
            Configuration::getValue("worldDataPath", "example");

    // world first to allow overriding of server's libraries
    PHYSFS_addToSearchPath(worldDataPath.c_str(), 1);
    PHYSFS_addToSearchPath(".", 1);
    PHYSFS_addToSearchPath(PKG_DATADIR, 1);
}
示例#3
0
int main(int argc, char *argv[])
{

    printf("Init physfs\n");
    PHYSFS_init(argv[0]);
    PHYSFS_addToSearchPath(PHYSFS_getBaseDir(), 1);
    PHYSFS_addToSearchPath("data.7z", 1);
    printf("Init physfs end\n");

	Main main;
	main.Execute();
	return 0;
}
示例#4
0
int main()
{
  // Set up the library and paths
  PHYSFS_init("blah");
  PHYSFS_addToSearchPath("test.zip", 1);
  PHYSFS_addToSearchPath("./", 1);

  // Create our interface
  PhysVFS vfs;

  // Run the test
  testAll(vfs);

  return 0;
}
示例#5
0
ZipFileSystem::ZipFileSystem(const String& filePath, const String& root) : mRoot(root){
	PHYSFS_init(NULL);

	// TODO handle root directory

	PHYSFS_addToSearchPath(filePath.c_str(), 0);
}
示例#6
0
文件: FileIO.c 项目: scriptum/Engine
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;
}
示例#7
0
/**Prepends an archive to be searched for files
 * \param ardhivename The path to the archive (can also be a folder)
 * \return Nonzero on success */
int Filesystem::PrependPath( const string& archivename ) {
	int retval;
	if ( (retval = PHYSFS_addToSearchPath(archivename.c_str(), 0)) == 0 )
		LogMsg(ERR,"Error on prepends to search path %s.\n%s",archivename.c_str(),
				PHYSFS_getLastError());
	return retval;
}
示例#8
0
void ObjectClass::loadSettings() {
	std::stringstream file;
	file.str(utils::getTextFile(this->package, "objects/" + this->objectClass + ".txt"));

	std::string line;
	while (file.good()) {
		getline(file, line);

		std::string value;
		float valueFloat;
		if (line.length() == 0 || line.at(0) == '#') {
			// Ignore comment lines
		} else if (this->parseLine(line, "name", value)) {
			this->name = value;
		} else if (this->parseLine(line, "flipside", value)) {
			if (value.find(".") != std::string::npos) {
				std::vector<std::string> path = utils::splitString(value, '.');
				PHYSFS_addToSearchPath((path[0] + ".zip").c_str(), 1);
				this->flipsideImage = path[0] + "/objects/" + path[1];
			} else {
				this->flipsideImage = this->package + "/objects/" + value;
			}
		} else if (this->parseLineFloat(line, "gridwidth", valueFloat)) {
			this->gridSize.x = valueFloat;
		} else if (this->parseLineFloat(line, "gridheight", valueFloat)) {
			this->gridSize.y = valueFloat;
		} else if (this->parseLineFloat(line, "scale", valueFloat)) {
			this->scale = valueFloat;
		} else {
			std::cout << "Warning: Could not parse '" << line << "' in " << this->objectClass << ".txt" << std::endl;
		}
	}
}
示例#9
0
  void find_datadir()
  {
    std::string datadir;
    if (m_forced_datadir)
    {
      datadir = *m_forced_datadir;
    }
    else if (const char* env_datadir = getenv("SUPERTUX2_DATA_DIR"))
    {
      datadir = env_datadir;
    }
    else
    {
      // check if we run from source dir
      char* basepath_c = SDL_GetBasePath();
      std::string basepath = basepath_c;
      SDL_free(basepath_c);

      datadir = FileSystem::join(basepath, "data");
      std::string testfname = FileSystem::join(datadir, "credits.txt");
      if (!FileSystem::exists(testfname))
      {
        // if the game is not run from the source directory, try to find
        // the global install location
        datadir = datadir.substr(0, datadir.rfind(INSTALL_SUBDIR_BIN));
        datadir = FileSystem::join(datadir, INSTALL_SUBDIR_SHARE);
      }
    }

    if (!PHYSFS_addToSearchPath(datadir.c_str(), 1))
    {
      log_warning << "Couldn't add '" << datadir << "' to physfs searchpath: " << PHYSFS_getLastError() << std::endl;
    }
  }
示例#10
0
/*!
 * Tries to mount a list of directories, found in /basedir/subdir/<list>.
 * \param basedir Base directory
 * \param subdir A subdirectory of basedir
 * \param appendToPath Whether to append or prepend
 * \param checkList List of directories to check. NULL means any.
 */
void addSubdirs( const char * basedir, const char * subdir, const bool appendToPath, char * checkList[], bool addToModList )
{
	char tmpstr[PATH_MAX];
	char buf[256];
	char ** subdirlist = PHYSFS_enumerateFiles( subdir );
	char ** i = subdirlist;
	while( *i != NULL )
	{
#ifdef DEBUG
		debug( LOG_NEVER, "addSubdirs: Examining subdir: [%s]", *i );
#endif // DEBUG
		if (*i[0] != '.' && (!checkList || inList(checkList, *i)))
		{
			snprintf(tmpstr, sizeof(tmpstr), "%s%s%s%s", basedir, subdir, PHYSFS_getDirSeparator(), *i);
#ifdef DEBUG
			debug( LOG_NEVER, "addSubdirs: Adding [%s] to search path", tmpstr );
#endif // DEBUG
			if (addToModList)
			{
				addLoadedMod(*i);
				snprintf(buf, sizeof(buf), "mod: %s", *i);
				addDumpInfo(buf);
			}
			PHYSFS_addToSearchPath( tmpstr, appendToPath );
		}
		i++;
	}
	PHYSFS_freeList( subdirlist );
}
示例#11
0
bool Resources::addToSearchPath(const char* directory, bool append) {
    if(!PHYSFS_addToSearchPath(directory, append)) {
        PError << "Couldn't add '" << directory << "' to searchpath: " << PHYSFS_getLastError() << endl;
        return PFalse;
    };
    return PTrue;
}
示例#12
0
void
AddonManager::enable_addon(const AddonId& addon_id)
{
  log_debug << "enabling addon " << addon_id << std::endl;
  Addon& addon = get_installed_addon(addon_id);
  if (addon.is_enabled())
  {
    log_warning << "Tried enabling already enabled Add-on" << std::endl;
  }
  else
  {
    log_debug << "Adding archive \"" << addon.get_install_filename() << "\" to search path" << std::endl;
    //int PHYSFS_mount(addon.installed_install_filename.c_str(), "addons/", 0)
    if (PHYSFS_addToSearchPath(addon.get_install_filename().c_str(), 0) == 0)
    {
      log_warning << "Could not add " << addon.get_install_filename() << " to search path: "
                  << PHYSFS_getLastError() << std::endl;
    }
    else
    {
      if(addon.get_type() == Addon::LANGUAGEPACK)
      {
        PHYSFS_enumerateFilesCallback(addon.get_id().c_str(), add_to_dictionary_path, NULL);
      }
      addon.set_enabled(true);
    }
  }
}
示例#13
0
//==================================================
//! Constructor
//==================================================
System::VFS::VFS() {
	// Initialize PhysicsFS
	PHYSFS_init( NULL );
	
	// Hardcoded paths for now
	PHYSFS_addToSearchPath( "/Users/aaron/Documents/Phaedrus-FPS/Resources/", 1 );
}
示例#14
0
util::VersionInfo Application::initPhysFS(const std::string& arg0)
{
    PHYSFS_Version ver;
    PHYSFS_init(arg0.c_str());
    PHYSFS_addToSearchPath(PHYSFS_getBaseDir(),0);
    PHYSFS_getLinkedVersion(&ver);
    return util::VersionInfo(ver.major, ver.minor, ver.patch);
}
bool ResourceManager::addToSearchPath(const std::string& path, bool insertInFront)
{
    if(!PHYSFS_addToSearchPath(path.c_str(), insertInFront ? 0 : 1))
        return false;
    //g_logger.debug(stdext::format("Add search path %s", path));
    m_hasSearchPath = true;
    return true;
}
示例#16
0
void FileSystem::addToSearchPath(const std::string& dirname, bool append)
{
	/// \todo check if dir exists?
	/// \todo use PHYSFS_mount? PHYSFS_addToSearchPath is listed as legacy function only there for binary 
	///  compatibility with older version.
	/// \todo check return value
	PHYSFS_addToSearchPath(dirname.c_str(), append ? 1 : 0);
}
示例#17
0
physfsDrive::physfsDrive(const char * startdir,Bit16u _bytes_sector,Bit8u _sectors_cluster,Bit16u _total_clusters,Bit16u _free_clusters,Bit8u _mediaid)
		   :localDrive(startdir,_bytes_sector,_sectors_cluster,_total_clusters,_free_clusters,_mediaid) {

	char newname[CROSS_LEN+1];

	/* No writedir given, use capture directory */
	if(startdir[0] == ':') {
		strcpy(newname,capturedir.c_str());
		strcat(newname,startdir);
	} else {
		strcpy(newname,startdir);
	}

	CROSS_FILENAME(newname);	
	if (!physfs_used) {
		PHYSFS_init("");
		PHYSFS_permitSymbolicLinks(1);
	}

	physfs_used++;
	char *lastdir = newname;
	char *dir = strchr(lastdir+(((lastdir[0]|0x20) >= 'a' && (lastdir[0]|0x20) <= 'z')?2:0),':');
	while (dir) {
		*dir++ = 0;
		if((lastdir == newname) && !strchr(dir+(((dir[0]|0x20) >= 'a' && (dir[0]|0x20) <= 'z')?2:0),':')) {
			// If the first parameter is a directory, the next one has to be the archive file,
			// do not confuse it with basedir if trailing : is not there!
			int tmp = strlen(dir)-1;
			dir[tmp++] = ':';
			dir[tmp++] = CROSS_FILESPLIT;
			dir[tmp] = '\0';
		}
		if (*lastdir && PHYSFS_addToSearchPath(lastdir,true) == 0) {
			LOG_MSG("PHYSFS couldn't add '%s': %s",lastdir,PHYSFS_getLastError());
		}
		lastdir = dir;
		dir = strchr(lastdir+(((lastdir[0]|0x20) >= 'a' && (lastdir[0]|0x20) <= 'z')?2:0),':');
	}
	const char *oldwrite = PHYSFS_getWriteDir();
	if (oldwrite) oldwrite = strdup(oldwrite);
	if (!PHYSFS_setWriteDir(newname)) {
		if (!oldwrite)
			LOG_MSG("PHYSFS can't use '%s' for writing, you might encounter problems",newname);
		else
			PHYSFS_setWriteDir(oldwrite);
	}
	if (oldwrite) free((char *)oldwrite);
	
	strcpy(basedir,lastdir);

	allocation.bytes_sector=_bytes_sector;
	allocation.sectors_cluster=_sectors_cluster;
	allocation.total_clusters=_total_clusters;
	allocation.free_clusters=_free_clusters;
	allocation.mediaid=_mediaid;

	dirCache.SetBaseDir(basedir, this);
}
示例#18
0
/* 
 * Add archives to the game.
 * 1) archives from Sharepath/Data to extend/replace builtin game content
 * 2) archived demos
 */
void PHYSFSX_addArchiveContent()
{
	char **list = NULL;
	static const char *const archive_exts[] = { ".zip", ".7z", NULL };
	char *file[2];
	int i = 0, content_updated = 0;

	con_printf(CON_DEBUG, "PHYSFS: Adding archives to the game.\n");
	// find files in Searchpath ...
	list = PHYSFSX_findFiles("", archive_exts);
	// if found, add them...
	for (i = 0; list[i] != NULL; i++)
	{
		MALLOC(file[0], char, PATH_MAX);
		MALLOC(file[1], char, PATH_MAX);
		snprintf(file[0], sizeof(char)*PATH_MAX, "%s", list[i]);
		PHYSFSX_getRealPath(file[0],file[1]);
		if (PHYSFS_addToSearchPath(file[1], 0))
		{
			con_printf(CON_DEBUG, "PHYSFS: Added %s to Search Path\n",file[1]);
			content_updated = 1;
		}
		d_free(file[0]);
		d_free(file[1]);
	}
	PHYSFS_freeList(list);
	list = NULL;

#if PHYSFS_VER_MAJOR >= 2
	// find files in DEMO_DIR ...
	list = PHYSFSX_findFiles(DEMO_DIR, archive_exts);
	// if found, add them...
	for (i = 0; list[i] != NULL; i++)
	{
		MALLOC(file[0], char, PATH_MAX);
		MALLOC(file[1], char, PATH_MAX);
		snprintf(file[0], sizeof(char)*PATH_MAX, "%s%s", DEMO_DIR, list[i]);
		PHYSFSX_getRealPath(file[0],file[1]);
		if (PHYSFS_mount(file[1], DEMO_DIR, 0))
		{
			con_printf(CON_DEBUG, "PHYSFS: Added %s to %s\n",file[1], DEMO_DIR);
			content_updated = 1;
		}
		d_free(file[0]);
		d_free(file[1]);
	}

	PHYSFS_freeList(list);
	list = NULL;
#endif

	if (content_updated)
	{
		con_printf(CON_DEBUG, "Game content updated!\n");
		PHYSFSX_listSearchPathContent();
	}
}
示例#19
0
int main(int argc, char **argv)
{
	char filename[PATH_MAX];
	char path[PATH_MAX], *delim;
	GAMEMAP *map;

	if (argc != 2)
	{
		printf("Usage: %s <map>\n", argv[0]);
		return -1;
	}
	strcpy(path, argv[1]);
	delim = strrchr(path, '/');
	if (delim)
	{
		*delim = '\0';
		delim++;
		strcpy(filename, delim);
	}
	else
	{
		path[1] = '.';
		path[1] = '\0';
		strcpy(filename, argv[1]);
	}
	PHYSFS_init(argv[0]);
	PHYSFS_addToSearchPath(path, 1);

	map = mapLoad(filename);
	if (map)
	{
		char tilesetName[PATH_MAX];

		if (map->tileset == TILESET_ARIZONA) { strcpy(tilesetName, "Arizona"); }
		else if (map->tileset == TILESET_URBAN) { strcpy(tilesetName, "Urban"); }
		else if (map->tileset == TILESET_ROCKIES) { strcpy(tilesetName, "Rockies"); }
		else { strcpy(tilesetName, "(unknown)"); }

		printf("Loaded map: %s\n", filename);
		printf("\tMap version: %d\n", (int)map->mapVersion);
		printf("\tGame version: %d\n", (int)map->gameVersion);
		printf("\tWidth: %d\n", (int)map->width);
		printf("\tHeight: %d\n", (int)map->height);
		printf("\tGateways: %d\n", (int)map->numGateways);
		printf("\tPlayers: %d\n", (int)map->numPlayers);
		printf("\tFeatures: %d\n", (int)map->numFeatures);
		printf("\tDroids: %d\n", (int)map->numDroids);
		printf("\tStructures: %d\n", (int)map->numStructures);
		printf("\tScroll limits: (%d, %d, %d, %d)\n",
			   (int)map->scrollMinX, (int)map->scrollMinY, (int)map->scrollMaxX, (int)map->scrollMaxY);
		printf("\tLevel name: %s\n", map->levelName);
		printf("\tTileset: %s\n", tilesetName);
	}
	mapFree(map);

	return 0;
}
示例#20
0
 virtual void SetUp(void) {
     glfwInit();
     glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
     window = glfwCreateWindow(TEST_WIDTH, TEST_HEIGHT, "gtest", nullptr, nullptr);
     glfwSetWindowPos(window, 300, 300);
     glfwMakeContextCurrent(window);
     ASSERT_EQ(GLEW_OK, glewInit());
     PHYSFS_init("gtest");
     PHYSFS_addToSearchPath("data", true);
 }
示例#21
0
文件: filesystem.c 项目: Murii/CLove
static int l_filesystem_setSource(lua_State* state)
{
  const char* p = l_tools_toStringOrError(state, 1);

  int a = PHYSFS_addToSearchPath(p, 1);
  if(!a)
    printf("%s %s \n", "Couldn't set source", p);

  return 1;
}
示例#22
0
bool ResourceManager::addToSearchPath(const std::string &path, bool append)
{
    logger->log("Adding to PhysicsFS: %s", path.c_str());
    if (!PHYSFS_addToSearchPath(path.c_str(), append ? 1 : 0))
    {
        logger->log("Error: %s", PHYSFS_getLastError());
        return false;
    }
    return true;
}
示例#23
0
 void ResourceManager::addPath(const std::string &path)
 {
     if (PHYSFS_addToSearchPath(path.c_str(), 0) == 0)
     {
         if (logger)
         {
             logger->logError("Unable to add path: " + path);
             logger->logError(PHYSFS_getLastError());
         }
     }
 }
示例#24
0
bool Lux::Core::FileHandler::AddResourcePath(const String a_Path)
{
    int res = PHYSFS_addToSearchPath(a_Path.c_str(), 0);

    if (res == 0)
    {
        LUX_LOG(Utility::logWARNING) << "Directory: " << a_Path << " was not added to the search path. " << PHYSFS_getLastError();
        return false;
    }

    return true;
}
示例#25
0
// Add a searchpath, but that searchpath is relative to an existing searchpath
// It will add the first one it finds and return 1, if it doesn't find any it returns 0
int PHYSFSX_addRelToSearchPath(const char *relname, int add_to_end)
{
	char relname2[PATH_MAX], pathname[PATH_MAX];

	snprintf(relname2, sizeof(relname2), "%s", relname);
	PHYSFSEXT_locateCorrectCase(relname2);

	if (!PHYSFSX_getRealPath(relname2, pathname))
		return 0;

	return PHYSFS_addToSearchPath(pathname, add_to_end);
}
示例#26
0
bool buildMapList()
{
	if (!loadLevFile("gamedesc.lev", mod_campaign, false, NULL))
	{
		return false;
	}
	loadLevFile("addon.lev", mod_multiplay, false, NULL);
	WZ_Maps.clear();
	MapFileList realFileNames = listMapFiles();
	for (MapFileList::iterator realFileName = realFileNames.begin(); realFileName != realFileNames.end(); ++realFileName)
	{
		bool mapmod = false;
		struct WZmaps CurrentMap;
		std::string realFilePathAndName = PHYSFS_getRealDir(realFileName->c_str()) + *realFileName;

		PHYSFS_addToSearchPath(realFilePathAndName.c_str(), PHYSFS_APPEND);

		char **filelist = PHYSFS_enumerateFiles("");
		for (char **file = filelist; *file != NULL; ++file)
		{
			std::string checkfile = *file;
			size_t len = strlen(*file);
			if (len > 10 && !strcasecmp(*file + (len - 10), ".addon.lev"))  // Do not add addon.lev again
			{
				loadLevFile(*file, mod_multiplay, true, realFileName->c_str());
			}
			// add support for X player maps using a new name to prevent conflicts.
			if (len > 13 && !strcasecmp(*file + (len - 13), ".xplayers.lev"))
			{
				loadLevFile(*file, mod_multiplay, true, realFileName->c_str());
			}
		}
		PHYSFS_freeList(filelist);

		if (PHYSFS_removeFromSearchPath(realFilePathAndName.c_str()) == 0)
		{
			debug(LOG_ERROR, "Could not unmount %s, %s", realFilePathAndName.c_str(), PHYSFS_getLastError());
		}

		 mapmod = CheckInMap(realFilePathAndName.c_str(), "WZMap", "WZMap");
		 if (!mapmod)
		 {
			mapmod = CheckInMap(realFilePathAndName.c_str(), "WZMap", "WZMap/multiplay");
		 }

		CurrentMap.MapName = realFileName->c_str();
		CurrentMap.isMapMod = mapmod;
		WZ_Maps.push_back(CurrentMap);
	}

	return true;
}
示例#27
0
static unsigned int init_datafile(char *argv[])
{

    /* load main game datafile (usually a zip) into memory */
    if (!PHYSFS_init(argv[0])) {
        fprintf(stderr, "Could not init PhysFS\n");
        return false;
    }
    PHYSFS_addToSearchPath(DATAPACKNAME, 1);
    al_set_standard_file_interface();
    al_set_physfs_file_interface();
    return true;

}
示例#28
0
文件: main.cpp 项目: leyyin/supertux
  void find_datadir()
  {
    std::string datadir;
    if (m_forced_datadir)
    {
      datadir = *m_forced_datadir;
    }
    else if (const char* env_datadir = getenv("SUPERTUX2_DATA_DIR"))
    {
      datadir = env_datadir;
    }
    else
    {
      // check if we run from source dir
      char* basepath_c = SDL_GetBasePath();
      std::string basepath = basepath_c;
      SDL_free(basepath_c);

      // If we are on windows, the data directory is one directory above the binary
#ifdef WIN32
      const std::array<std::string, 2> subdirs = { "data", "../data" };
#else
      const std::array<std::string, 1> subdirs = { "data" };
#endif
      bool found = false;
      for (const std::string &subdir : subdirs)
      {
        datadir = FileSystem::join(basepath, subdir);
        if (FileSystem::exists(FileSystem::join(datadir, "credits.txt")))
        {
          found = true;
          break;
        }
      }
      if (!found)
      {
        // if the game is not run from the source directory, try to find
        // the global install location
        datadir = datadir.substr(0, datadir.rfind(INSTALL_SUBDIR_BIN));
        datadir = FileSystem::join(datadir, INSTALL_SUBDIR_SHARE);
      }
    }

    if (!PHYSFS_addToSearchPath(datadir.c_str(), 1))
    {
      log_warning << "Couldn't add '" << datadir << "' to physfs searchpath: " << PHYSFS_getLastError() << std::endl;
    }
  }
示例#29
0
void App::scanForPK3()
{
	logstream() << "Scanning for pk3s...\n";
#ifdef WIN32
	_finddatai64_t fdata;
	base::String str(m_WorkingPath); str+="/*.pk3";
	intptr_t handle=_findfirsti64(str.cstr(),&fdata);

	if (handle!=-1) {
		do {
			logstream() << "Found " << fdata.name << "\n";
			PHYSFS_addToSearchPath(fdata.name,0);
		} while (_findnexti64(handle,&fdata)==0);
		_findclose(handle);
	}
#else // POSIX
#endif
}
示例#30
0
/**Initialize the PhysFS system
 * \return Nonzero on success. */
int Filesystem::Init( const char* argv0 ) {
	int retval;
	if ( (retval = PHYSFS_init(argv0)) == 0 )
		LogMsg(ERR,"Error initializing PhysicsFS. Reason: %s\n",PHYSFS_getLastError());

	if ( (retval = PHYSFS_setSaneConfig("games", "epiar", NULL, 0, 0 ) ) == 0 )
		LogMsg(ERR,"Could not set sane paths for PhysFS: %s\n", PHYSFS_getLastError());

	// Set up userDir
	if ( (retval = PHYSFS_mkdir("Resources/Definitions/") ) == 0 )
		LogMsg(ERR,"Could not set up the user dir: %s\n", PHYSFS_getLastError());

#ifdef DATADIR
	// If using autotools, include this prefix to help binary find data files for cases where 'make install' was used
	if ( (retval = PHYSFS_addToSearchPath(DATADIR, 1)) == 0 )
		LogMsg(INFO,"Not using DATADIR directory due to error, probably 'make install' not run yet. Reason: %s\n", PHYSFS_getLastError());
#endif /* DATADIR */
	
	return retval;
}