Ejemplo n.º 1
0
ReadFile* openRead(const char* filename)
{
    PHYSFS_file* file = PHYSFS_openRead(filename);
    if(!file)
    {
		int fn_length = strlen(filename)+1;
		char fn[fn_length];
		memcpy(fn, filename, fn_length); // includes \0;

		char * folder_sep = strrchr(fn, '/');
		char * fn_start = fn;
		char ** filelist = 0;
		if ( folder_sep )
		{
			*folder_sep = 0;
			filelist = enumerateFiles(fn);
			*folder_sep = '/';
			fn_start = folder_sep+1;
		}
		else
		{
			filelist = enumerateFiles(".");
			folder_sep = fn;
		}

		if ( filelist )
		{
			for(char** curfile = filelist; *curfile != 0; curfile++)
			{
				if ( strcasecmp(*curfile, fn_start) == 0 )
				{
					memcpy(fn_start, *curfile, fn_length-(folder_sep-fn));
					file = PHYSFS_openRead(fn);
					break;
				}
			}
			freeList(filelist);
		}

		if ( !file )
		{
			throw Exception("couldn't open file '%s' for reading: %s", filename,
						PHYSFS_getLastError());
		}
	}

    return new ReadFile(file);
}
Ejemplo n.º 2
0
 StringVector getDirListing(const std::string& dir)
 {
   StringVector tmpList = enumerateFiles(dir);
   // now filter the list to only keep dirs
   StringVector list;
   for (StringVector::iterator it = tmpList.begin(); it != tmpList.end(); ++it)
   {
     if (isDirectory(*it))
       list.push_back(*it);
   }
   return list;
 }
Ejemplo n.º 3
0
ResourceRO * Resources::RetrieveRead(PString & filename) {
    PHYSFS_file* file = PHYSFS_openRead(filename);
    if(!file) {
		const int fn_length = filename.GetLength()+1;
		char fn[4096];
		memcpy(fn, filename.GetPointer(), fn_length); // includes \0;

		char * folder_sep = strrchr(fn, '/');
		char * fn_start = fn;
		char ** filelist = 0;
		if ( folder_sep ) {
			*folder_sep = 0;
			filelist = enumerateFiles(fn);
			*folder_sep = '/';
			fn_start = folder_sep+1;
		} else {
			filelist = enumerateFiles(".");
			folder_sep = fn;
		};
		if (filelist) {
			for(char** curfile = filelist; *curfile != 0; curfile++) {
				if ( strcasecmp(*curfile, fn_start) == 0 ) {
					memcpy(fn_start, *curfile, fn_length-(folder_sep-fn));
					file = PHYSFS_openRead(fn);
					break;
				};
			};
			freeList(filelist);
		};
		if (!file) {
            PError << "couldn't open file '" << filename << "' for reading: " << PHYSFS_getLastError() << endl;
            return NULL;
		};
	};
    return new ResourceRO(file);
}