• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ PHYSFS_openRead函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中PHYSFS_openRead函数的典型用法代码示例。如果您正苦于以下问题:C++ PHYSFS_openRead函数的具体用法?C++ PHYSFS_openRead怎么用?C++ PHYSFS_openRead使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了PHYSFS_openRead函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: PHYSFS_openRead

bool j1Physfs::OpenFile(const char* file)
{
	if (0 == PHYSFS_exists(file))
	{
		return false; //file doesn't exist
	}

	PHYSFS_file* myfile = PHYSFS_openRead(file);

	// Get the lenght of the file
	file_lenght = PHYSFS_fileLength(myfile);

	// Get the file data.
	file_data = new Uint32[file_lenght];

	int length_read = PHYSFS_read(myfile, file_data, 1, file_lenght);

	if (length_read != (int)file_lenght)
	{
		delete[] file_data;
		file_data = 0;
		return false;
	}

	PHYSFS_close(myfile);


	return true;
}
开发者ID:kellazo,项目名称:GameDevelopment,代码行数:29,代码来源:j1Physfs.cpp


示例2: impl

File::File(const MountedFilePath& mountedFilePath, DataStream::OpenMode openMode)
   : impl(std::make_unique<File_Impl>()), mountedFilePath(mountedFilePath)
{
   const char* path = mountedFilePath.path.c_str();

   int fileExists = PHYSFS_exists(path);

   if (fileExists == 0)
   {
      throw Exception(std::string("File ") + path + " does not exist in the search path");
   }

   switch (openMode)
   {
   case OpenMode::Read:
      impl->physfsFileHandle = PHYSFS_openRead(path);
      break;

   case OpenMode::Write:
      impl->physfsFileHandle = PHYSFS_openWrite(path);
      break;

   case OpenMode::Append:
      impl->physfsFileHandle = PHYSFS_openAppend(path);
      break;
   }

   if (impl->physfsFileHandle == nullptr)
   {
      throw Exception(std::string("Failed to open file ") + path + "\n" + PHYSFS_getLastError());
   }
}
开发者ID:ShacharAvni,项目名称:Locus-Game-Engine,代码行数:32,代码来源:File.cpp


示例3: seed_open

static int seed_open(lua_State *L)
// filename, mode -> physfs file
{
    static const char * modes[] = { "rb", /*"wb", "ab",*/ NULL };
    enum { READ /*, WRITE, APPEND*/ };

    const char * filename = luaL_checkstring(L, 1);
    int mode = luaL_checkoption(L, 2, "rb", modes);

    PHYSFS_file * file;

    if(mode == READ)
        file = PHYSFS_openRead(filename);
    //else if(mode == WRITE)
    //    file = PHYSFS_openWrite(filename);
    //else if(mode == APPEND)
    //    file = PHYSFS_openAppend(filename);
    else assert(0);

    if(file)
    {
        *(PHYSFS_file **)lua_newuserdata(L, sizeof(file)) = file;
        luaL_getmetatable(L, "seed.file");
        lua_setmetatable(L, -2);
        return 1;
    }
    else
    {
        lua_pushnil(L);
        lua_pushstring(L, PHYSFS_getLastError());
        return 2;
    }
}
开发者ID:Chingliu,项目名称:seed,代码行数:33,代码来源:seed.c


示例4: loadQImage

static QImage loadQImage(char const *fileName, char const *format = nullptr)
{
	PHYSFS_file *fileHandle = PHYSFS_openRead(fileName);
	if (fileHandle == nullptr)
	{
		return {};
	}
	int64_t fileSizeGuess = PHYSFS_fileLength(fileHandle);  // PHYSFS_fileLength may return -1.
	int64_t lengthRead = 0;
	std::vector<unsigned char> data(fileSizeGuess != -1? fileSizeGuess : 16384);
	while (true)
	{
		int64_t moreRead = PHYSFS_read(fileHandle, &data[lengthRead], 1, data.size() - lengthRead);
		lengthRead += std::max<int64_t>(moreRead, 0);
		if (lengthRead < data.size())
		{
			PHYSFS_close(fileHandle);
			data.resize(lengthRead);
			QImage image;
			image.loadFromData(&data[0], data.size(), format);
			return std::move(image);
		}
		data.resize(data.size() + 16384);
	}
}
开发者ID:C1annad,项目名称:warzone2100,代码行数:25,代码来源:wzapp_qt.cpp


示例5: PHYSFS_openRead

	bool FileManager::loadFile(const std::string & path, std::vector<u8>& out)
	{
		auto file = PHYSFS_openRead(path.c_str());

		if (file == nullptr)
		{
			Log::write(Log::Error, fmt::format("Error: Unable to open file for reading. {}", path));
			return false;
		}

		auto length = PHYSFS_fileLength(file);

		if (length == -1)
		{
			Log::write(Log::Error, fmt::format("Error: Unable to get file length. {}", path));
			return false;
		}

		out.resize(length + 1);
		auto num = PHYSFS_read(file, out.data(), sizeof(out[0]), length);

		if (num < length / sizeof(out[0]))
		{
			Log::write(Log::Error, fmt::format("Error: Unable to read file contents. {}", path));
			return false;
		}

		return true;
	}
开发者ID:Wezthal,项目名称:DerpEngine,代码行数:29,代码来源:fileManager.cpp


示例6: fontSetEnumCB

static void fontSetEnumCB(void *data, const char *,
                          const char *fname)
{
	FontSetsCBData *d = static_cast<FontSetsCBData*>(data);
	FileSystemPrivate *p = d->p;

	/* Only consider filenames with font extensions */
	const char *ext = p->findExt(fname);

	if (!ext)
		return;

	std::string lower(ext);
	strToLower(lower);

	if (!contains(p->extensions[FileSystem::Font], lower))
		return;

	std::string filename("Fonts/");
	filename += fname;

	PHYSFS_File *handle = PHYSFS_openRead(filename.c_str());

	if (!handle)
		return;

	SDL_RWops ops;
	p->initReadOps(handle, ops, false);

	d->sfs->initFontSetCB(ops, filename);

	SDL_RWclose(&ops);
}
开发者ID:Daverball,项目名称:mkxp,代码行数:33,代码来源:filesystem.cpp


示例7: switch

Lux::Core::OpenedFile* Lux::Core::FileHandler::OpenFile(const String a_File, FileOpenMode a_OpenMode)
{
    OpenedFile* retFile = nullptr;
    switch (a_OpenMode)
    {
    case Lux::Core::FileHandler::FILE_OPEN_READ:
        retFile = PHYSFS_openRead(a_File.c_str());
        break;
    case Lux::Core::FileHandler::FILE_OPEN_WRITE:
        retFile = PHYSFS_openWrite(a_File.c_str());
        break;
    case Lux::Core::FileHandler::FILE_OPEN_APPEND:
        retFile = PHYSFS_openAppend(a_File.c_str());
        break;
    default:
        Utility::ThrowError("Unsupported file open mode.");
        break;
    }

    if (retFile == nullptr)
    {
        Utility::ThrowError("Could not open specified file: " + a_File + " . " + PHYSFS_getLastError());
    }

    return retFile;
}
开发者ID:lotsopa,项目名称:Lux,代码行数:26,代码来源:LuxFileHandler.cpp


示例8: PHYSFS_openRead

natU8* FileManager::Read(const natChar* _filename, size_t* _size)
{
//#if defined(WINDOWS_TARGET)
	PHYSFS_file* file = PHYSFS_openRead(_filename);
	assert(file);

	*_size = PHYSFS_fileLength(file);
	assert(*_size != 0);

	natU8* buffer = new natU8[*_size];
	PHYSFS_read(file, buffer, 1, static_cast<PHYSFS_uint32>(*_size));
	PHYSFS_close(file);

	return buffer;
/*#elif defined(EMSCRIPTEN_TARGET)
	std::ifstream file(_filename, std::ios::in|std::ios::binary|std::ios::ate);
	assert(file.is_open());

	*_size = file.tellg();
	assert(*_size != 0);

	natU8* buffer = new natU8[*_size];
	file.seekg (0, std::ios::beg);
	file.read ((char*)buffer, *_size);
	file.close();

	return buffer;
#else

#endif*/
}
开发者ID:ricklesauceur,项目名称:dukecorporation,代码行数:31,代码来源:filemanager.cpp


示例9: PHYSFS_openRead

const char* kp::file::read(const char* filename)
{
    PHYSFS_File* handle = PHYSFS_openRead(filename);

    if(handle == NULL)
    {
        //kp::debug::error("PHYSFS_openRead(%s): %s", filename, PHYSFS_getLastError());
        
        return NULL;
    }

    // Create a buffer big enough for the file
    PHYSFS_sint64 size = PHYSFS_fileLength(handle);

    // Append an extra byte to the string so we can null terminate it
    char* buffer = new char[size+1];

    // Read the bytes
    if(PHYSFS_readBytes(handle, buffer, size) != size)
    {
        //kp::debug::error("PHYSFS_read: %s", PHYSFS_getLastError());
        
        return NULL;
    }

    // Null terminate the buffer
    buffer[size] = '\0';

    // Close the file handle
    PHYSFS_close(handle);

    return buffer;
}
开发者ID:keithpitt,项目名称:engine,代码行数:33,代码来源:file.cpp


示例10: THROW_EXCEPTION

//==================================================
//! Load a file from the VFS into memory, can throw a FileIOException
//==================================================
void System::VFS::LoadRaw( const string& strFilename, vector<byte>& data ) {
	// Check to see if it exists
	if( !PHYSFS_exists(strFilename.c_str()) ) {
		THROW_EXCEPTION( FileReadException() << FileIOExceptionFilename(strFilename) );
	}
	
	// Open the file
	shared_ptr<PHYSFS_file> pFile( PHYSFS_openRead(strFilename.c_str()), PHYSFS_close );
	if( pFile.get() == NULL ) {
		THROW_EXCEPTION( FileReadException() << FileIOExceptionFilename(strFilename) );
	}

	// Try to read the number of bytes, fail if we can't
	PHYSFS_sint64 nBytes= PHYSFS_fileLength( pFile.get() );
	if( nBytes < 0 ) {
		THROW_EXCEPTION( FileReadException() << FileIOExceptionFilename(strFilename) );
	}
	data.resize( unsigned(nBytes) );

	// Try to read the data
	PHYSFS_sint64 nBytesRead= PHYSFS_read( pFile.get(), &data[0], sizeof(byte), data.size() );
	// Check for unexpected length
	if( nBytesRead != nBytes ) {
		data.resize( unsigned(nBytesRead) );
		THROW_EXCEPTION( FileReadException() << FileIOExceptionFilename(strFilename) );
	}
}
开发者ID:schnarf,项目名称:Phaedrus-FPS,代码行数:30,代码来源:VFS.cpp


示例11: PHYSFS_openRead

int FileSystem::load(const char* file, char **buffer) const
{
	int ret = 0;

	PHYSFS_file *file_handle = PHYSFS_openRead(file);
	if (file_handle != NULL)
	{
		PHYSFS_sint64 size = PHYSFS_fileLength(file_handle);
		if (size > 0)
		{
			*buffer = new char[(int)size];
			PHYSFS_sint64 bytes_readed = PHYSFS_read(file_handle, *buffer, 1, size);
			if (bytes_readed != size)
			{
				LOG("File system error while reading from file %s: %s", file, PHYSFS_getLastError());
				RELEASE(buffer);
			}
			else
				ret = (int)size;
		}

		if (PHYSFS_close(file_handle) == 0)
			LOG("File %s is not closed properly. Error: %s", file, PHYSFS_getLastError());
	}

	return ret;
}
开发者ID:N4bi,项目名称:Research-Particle_system,代码行数:27,代码来源:FileSystem.cpp


示例12: cmd_filelength

static int cmd_filelength(char *args)
{
    PHYSFS_File *f;

    if (*args == '\"')
    {
        args++;
        args[strlen(args) - 1] = '\0';
    } /* if */

    f = PHYSFS_openRead(args);
    if (f == NULL)
        printf("failed to open. Reason: [%s].\n", PHYSFS_getLastError());
    else
    {
        PHYSFS_sint64 len = PHYSFS_fileLength(f);
        if (len == -1)
            printf("failed to determine length. Reason: [%s].\n", PHYSFS_getLastError());
        else
            printf(" (cast to int) %d bytes.\n", (int) len);

        PHYSFS_close(f);
    } /* else */

    return(1);
} /* cmd_filelength */
开发者ID:AppZone-India,项目名称:Android-ImageMagick,代码行数:26,代码来源:test_physfs.c


示例13: Exception

	PHYSFS_File *openReadHandle(const char *filename,
	                            char *extBuf,
	                            size_t extBufN)
	{
		char found[512];

		if (!completeFilename(filename, found, sizeof(found)))
			throw Exception(Exception::NoFileError, "%s", filename);

		PHYSFS_File *handle = PHYSFS_openRead(found);

		if (!handle)
			throw Exception(Exception::PHYSFSError, "PhysFS: %s", PHYSFS_getLastError());

		if (!extBuf)
			return handle;

		for (char *q = found+strlen(found); q > found; --q)
		{
			if (*q == '/')
				break;

			if (*q != '.')
				continue;

			strcpySafe(extBuf, q+1, extBufN, -1);
			break;
		}

		return handle;
	}
开发者ID:AlexandreSousa,项目名称:mkxp,代码行数:31,代码来源:filesystem.cpp


示例14: resolvePath

void ResourceManager::loadFile(const std::string& fileName, std::iostream& out)
{
    out.clear(std::ios::goodbit);
    if(m_hasSearchPath) {
        std::string fullPath = resolvePath(fileName);
        PHYSFS_file* file = PHYSFS_openRead(fullPath.c_str());
        if(!file) {
            out.clear(std::ios::failbit);
            stdext::throw_exception(stdext::format("failed to load file '%s': %s", fullPath.c_str(), PHYSFS_getLastError()));
        } else {
            int fileSize = PHYSFS_fileLength(file);
            if(fileSize > 0) {
                std::vector<char> buffer(fileSize);
                PHYSFS_read(file, (void*)&buffer[0], 1, fileSize);
                out.write(&buffer[0], fileSize);
            } else
                out.clear(std::ios::eofbit);
            PHYSFS_close(file);
            out.seekg(0, std::ios::beg);
        }
    } else {
        std::ifstream fin(fileName);
        if(!fin) {
            out.clear(std::ios::failbit);
            stdext::throw_exception(stdext::format("failed to load file '%s': %s", fileName.c_str(), PHYSFS_getLastError()));
        } else {
            out << fin.rdbuf();
        }
    }
}
开发者ID:LeandroPerrotta,项目名称:otclient,代码行数:30,代码来源:resourcemanager.cpp


示例15: PHYSFS_openRead

// Read a whole file and put it in a new buffer
unsigned int j1FileSystem::Load(const char* file, char** buffer) const
{
	unsigned int ret = 0;

	PHYSFS_file* fs_file = PHYSFS_openRead(file);

	if(fs_file != NULL)
	{
		PHYSFS_sint32 size = PHYSFS_fileLength(fs_file);

		if(size > 0)
		{
			*buffer = new char[size];
			int readed = PHYSFS_read(fs_file, *buffer, 1, size);
			if(readed != size)
			{
				LOG("File System error while reading from file %s: %s\n", file, PHYSFS_getLastError());
				RELEASE(buffer);
			}
			else
				ret = readed;
		}

		if(PHYSFS_close(fs_file) == 0)
			LOG("File System error while closing file %s: %s\n", file, PHYSFS_getLastError());
	}
	else
		LOG("File System error while opening file %s: %s\n", file, PHYSFS_getLastError());

	return ret;
}
开发者ID:weprikjm,项目名称:DevSegonaClasse,代码行数:32,代码来源:j1FileSystem.cpp


示例16: get_physfs_SDLRWops

SDL_RWops* get_physfs_SDLRWops(const std::string& filename)
{
  // check this as PHYSFS seems to be buggy and still returns a
  // valid pointer in this case
  if(filename.empty()) {
    throw std::runtime_error("Couldn't open file: empty filename");
  }

  PHYSFS_file* file = (PHYSFS_file*) PHYSFS_openRead(filename.c_str());
  if(!file) {
    std::stringstream msg;
    msg << "Couldn't open '" << filename << "': "
        << PHYSFS_getLastError();
    throw std::runtime_error(msg.str());
  }

  SDL_RWops* ops = new SDL_RWops();
  ops->type = 0;
  ops->hidden.unknown.data1 = file;
  ops->seek = funcSeek;
  ops->read = funcRead;
  ops->write = 0;
  ops->close = funcClose;
  return ops;
}
开发者ID:CRS-ECHO51,项目名称:supertux,代码行数:25,代码来源:physfs_sdl.cpp


示例17: SetWindowIcon

void SetWindowIcon(photon_window &window, const std::string &filename){
    if(PHYSFS_exists(filename.c_str())){
        auto fp = PHYSFS_openRead(filename.c_str());
        intmax_t length = PHYSFS_fileLength(fp);
        if(length > 0){
            uint8_t *buffer = new uint8_t[length];

            PHYSFS_read(fp, buffer, 1, length);

            PHYSFS_close(fp);

            SDL_RWops *rw = SDL_RWFromMem(buffer, length);
            SDL_Surface *icon = IMG_Load_RW(rw, 1);

            if(icon == nullptr){
                PrintToLog("ERROR: icon loading failed! %s", IMG_GetError());
            }

            SDL_SetWindowIcon(window.window_SDL, icon);

            SDL_FreeSurface(icon);
            delete[] buffer;
        }else{
            PrintToLog("ERROR: Unable to open image file \"%s\"!");
        }
    }else{
        PrintToLog("ERROR: Image file \"%s\" does not exist!", filename.c_str());
    }
}
开发者ID:chipgw,项目名称:photon-legacy,代码行数:29,代码来源:window_managment.cpp


示例18: dataAudioCfgLoad

/* Load an audio file */
static bool dataAudioCfgLoad(const char* fileName, void **ppData)
{
	bool success;
	PHYSFS_file* fileHandle;

	*ppData = NULL;

	if (audio_Disabled())
	{
		return true;
	}
	debug(LOG_WZ, "Reading...[directory: %s] %s", PHYSFS_getRealDir(fileName), fileName);
	fileHandle = PHYSFS_openRead(fileName);

	if (fileHandle == NULL)
	{
		return false;
	}

	success = ParseResourceFile(fileHandle);

	PHYSFS_close(fileHandle);

	return success;
}
开发者ID:BG1,项目名称:warzone2100,代码行数:26,代码来源:data.cpp


示例19: readSurfaces

static bool readSurfaces( const char *filename, std::vector< RenderSurface > &surfaces )
{
	uint64_t hashedName = HashedString( 0, filename );
	char outfile[256];
	PHYSFS_mkdir( "static_models/" );
	sprintf( outfile, "static_models/%08x_%08x.sm", (uint32_t)(hashedName>>32), (uint32_t)(hashedName&0xffffffff) );
	PHYSFS_File *model = PHYSFS_openRead( outfile );
	if ( model )
	{
		unsigned int ver, numSurf;
		PHYSFS_readULE32( model, &ver );
		PHYSFS_readULE32( model, &numSurf );
		surfaces.resize( numSurf );
		for ( uint32_t i=0; i<surfaces.size(); i++ )
		{
			RenderSurface &surf = surfaces[i];
			PHYSFS_readCStr( model, surf.name );
			std::string mat;
			PHYSFS_readCStr( model, mat );
			surf.mat = materialManager()->Load( mat.c_str() );

			ModelGeometry *geom = new ModelGeometry;
			surf.geom = geom;
			PHYSFS_readSLE32( model, &geom->m_numIndices );
			PHYSFS_readSLE32( model, &geom->m_numVerts );
			geom->m_indices = new unsigned short[geom->m_numIndices];
			geom->m_verts = new ModelVert[geom->m_numVerts];
			PHYSFS_read( model, geom->m_indices, sizeof(uint16_t)*geom->m_numIndices, 1 );
			PHYSFS_read( model, geom->m_verts, sizeof(geom->m_verts[0])*geom->m_numVerts, 1 );
		}
		PHYSFS_close( model );
		return true;
	}
	return false;
}
开发者ID:mikearmstrong001,项目名称:script,代码行数:35,代码来源:model_static.cpp


示例20: snprintf

//Open a file for reading, set up a buffer
PHYSFS_file *PHYSFSX_openReadBuffered(const char *filename)
{
	PHYSFS_file *fp;
	PHYSFS_uint64 bufSize;
	char filename2[PATH_MAX];
	
	if (filename[0] == '\x01')
	{
		//FIXME: don't look in dir, only in hogfile
		filename++;
	}
	
	snprintf(filename2, sizeof(filename2), "%s", filename);
	PHYSFSEXT_locateCorrectCase(filename2);
	
	fp = PHYSFS_openRead(filename2);
	if (!fp)
		return NULL;
	
	bufSize = PHYSFS_fileLength(fp);
	while (!PHYSFS_setBuffer(fp, bufSize) && bufSize)
		bufSize /= 2;	// even if the error isn't memory full, for a 20MB file it'll only do this 8 times
	
	return fp;
}
开发者ID:Mako88,项目名称:DXX-Retro,代码行数:26,代码来源:physfsx.c



注:本文中的PHYSFS_openRead函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ PHYSFS_openWrite函数代码示例发布时间:2022-05-30
下一篇:
C++ PHYSFS_init函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap