当前位置: 首页>>代码示例>>C++>>正文


C++ PHYSFS_openRead函数代码示例

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


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


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