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

C++ PHYSFS_fileLength函数代码示例

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

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



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

示例1: open

int64 File::getSize()
{
	// If the file is closed, open it to
	// check the size.
	if (file == 0)
	{
		open(READ);
		int64 size = (int64)PHYSFS_fileLength(file);
		close();
		return size;
	}

	return (int64)PHYSFS_fileLength(file);
}
开发者ID:Ghor,项目名称:LoveEngineCore,代码行数:14,代码来源:File.cpp


示例2: open

	unsigned int File::getSize()
	{
		// If the file is closed, open it to
		// check the size.
		if(file == 0)
		{
			open(READ);
			unsigned int size = (unsigned int)PHYSFS_fileLength(file);
			close();
			return size;
		}

		return (unsigned int)PHYSFS_fileLength(file);
	}
开发者ID:leafo,项目名称:moonscript-love,代码行数:14,代码来源:File.cpp


示例3: close

	int File::getSize()
	{
		// If the file is closed, open it to
		// check the size.
		if(file == 0)
		{
			if(!open())
				return 0;
			int size = (int)PHYSFS_fileLength(file);
			close();
			return size;
		}

		return (int)PHYSFS_fileLength(file);
	}
开发者ID:icedman,项目名称:lov8,代码行数:15,代码来源:physFile.cpp


示例4: 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


示例5: PHYSFS_tell

IFileStreambuf::pos_type
IFileStreambuf::seekoff(off_type off, std::ios_base::seekdir dir,
                        std::ios_base::openmode mode)
{
  off_type pos = off;
  PHYSFS_sint64 ptell = PHYSFS_tell(file);

  switch(dir) {
    case std::ios_base::beg:
      break;
    case std::ios_base::cur:
      if(off == 0)
        return static_cast<pos_type> (ptell) - static_cast<pos_type> (egptr() - gptr());
      pos += static_cast<off_type> (ptell) - static_cast<off_type> (egptr() - gptr());
      break;
    case std::ios_base::end:
      pos += static_cast<off_type> (PHYSFS_fileLength(file));
      break;
    default:
      assert(false);
      return pos_type(off_type(-1));
  }

  return seekpos(static_cast<pos_type> (pos), mode);
}
开发者ID:maxteufel,项目名称:supertux,代码行数:25,代码来源:ifile_streambuf.cpp


示例6: l_filesystem_require

static int l_filesystem_require(lua_State* state)
{
  if(!lua_isstring(state, 1))
    return luaL_error(state, "The argument must be a string.");

  const char* filename = lua_tostring(state, 1);

  char myBuf[2048] = {0};

  PHYSFS_file* myfile = PHYSFS_openRead(filename);
  if(!myfile)
    printf("%s %s \n", "No .lua file named in directory ", filename);
  PHYSFS_sint64 fileLngth = PHYSFS_fileLength(myfile);
  PHYSFS_read (myfile, myBuf, 1, fileLngth);
  int status = 0;

  status = luaL_loadbuffer(state, (const char *)myBuf, fileLngth, filename) || lua_pcall(state, 0,0,0);
  if(status != 0) luaL_error(state,lua_tostring(state,-1));

  PHYSFS_close(myfile);

  switch (status)
    {
    case LUA_ERRMEM:
      return luaL_error(state, "Memory allocation error: %s\n", lua_tostring(state, -1));
    case LUA_ERRSYNTAX:
      return luaL_error(state, "Syntax error: %s\n", lua_tostring(state, -1));
    default: // success
      return 1;
    }

  return 1;
}
开发者ID:Murii,项目名称:CLove,代码行数:33,代码来源:filesystem.c


示例7: fs_seek

int fs_seek(fs_file fh, long offset, int whence)
{
    PHYSFS_uint64 pos = 0;
    PHYSFS_sint64 cur = PHYSFS_tell(fh->handle);
    PHYSFS_sint64 len = PHYSFS_fileLength(fh->handle);

    switch (whence)
    {
    case SEEK_SET:
        pos = offset;
        break;

    case SEEK_CUR:
        if (cur < 0)
            return -1;
        pos = cur + offset;
        break;

    case SEEK_END:
        if (len < 0)
            return -1;
        pos = len + offset;
        break;
    }

    return PHYSFS_seek(fh->handle, pos);
}
开发者ID:L0rdK,项目名称:neverball-sdl2,代码行数:27,代码来源:fs_physfs.c


示例8: PHYSFS_openRead

void*
ResourceManager::loadFile(const std::string &fileName, int &fileSize)
{
    // Attempt to open the specified file using PhysicsFS
    PHYSFS_file *file = PHYSFS_openRead(fileName.c_str());

    // If the handler is an invalid pointer indicate failure
    if (file == NULL) {
        logger->log("Warning: Failed to load %s: %s",
                fileName.c_str(), PHYSFS_getLastError());
        return NULL;
    }

    // Log the real dir of the file
    logger->log("Loaded %s/%s", PHYSFS_getRealDir(fileName.c_str()),
            fileName.c_str());

    // Get the size of the file
    fileSize = PHYSFS_fileLength(file);

    // Allocate memory and load the file
    void *buffer = malloc(fileSize);
    PHYSFS_read(file, buffer, 1, fileSize);

    // Close the file and let the user deallocate the memory
    PHYSFS_close(file);

    return buffer;
}
开发者ID:igneus,项目名称:particled,代码行数:29,代码来源:resourcemanager.cpp


示例9: switch

int OSBasics::seek(OSFILE * stream, long int offset, int origin ) {
	switch(stream->fileType) {
		case OSFILE::TYPE_FILE:
			return fseek(stream->file, offset, origin);
			break;
		case OSFILE::TYPE_ARCHIVE_FILE:
			switch(origin) {
				case SEEK_SET:
					return PHYSFS_seek(stream->physFSFile, offset);
				break;
				case SEEK_CUR: {
					PHYSFS_sint64 curoffset = PHYSFS_tell(stream->physFSFile);					
					return PHYSFS_seek(stream->physFSFile, curoffset+offset);				
				}
				break;
				case SEEK_END: {
					PHYSFS_sint64 fileLength =  PHYSFS_fileLength(stream->physFSFile);
					return PHYSFS_seek(stream->physFSFile, fileLength-offset);
				}
				break;
			}
			break;			
	}
	return 0;	
}
开发者ID:RobLach,项目名称:Polycode,代码行数:25,代码来源:OSBasics.cpp


示例10: 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:Pau5erra,项目名称:XML,代码行数:32,代码来源:j1FileSystem.cpp


示例11: SDL_RWopsSeek

static Sint64 SDL_RWopsSeek(SDL_RWops *ops, int64_t offset, int whence)
{
	PHYSFS_File *f = sdlPHYS(ops);

	if (!f)
		return -1;

	int64_t base;

	switch (whence)
	{
	default:
	case RW_SEEK_SET :
		base = 0;
		break;
	case RW_SEEK_CUR :
		base = PHYSFS_tell(f);
		break;
	case RW_SEEK_END :
		base = PHYSFS_fileLength(f);
		break;
	}

	int result = PHYSFS_seek(f, base + offset);

	return (result != 0) ? PHYSFS_tell(f) : -1;
}
开发者ID:AlexandreSousa,项目名称:mkxp,代码行数:27,代码来源:filesystem.cpp


示例12: 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


示例13: 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


示例14: 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


示例15: 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


示例16: PHYSFS_fileLength

unsigned int Audio::File::length()
{
    if (!mFile) return 0u;
    auto status = PHYSFS_fileLength(mFile);
    if (status < 0) return 0u;
    return static_cast<unsigned int>(status);
}
开发者ID:dermoumi,项目名称:m2n,代码行数:7,代码来源:audio.cpp


示例17: switch

int
OggSoundFile::cb_seek(void* source, ogg_int64_t offset, int whence)
{
  PHYSFS_file* file = reinterpret_cast<PHYSFS_file*> (source);

  switch(whence) {
    case SEEK_SET:
      if(PHYSFS_seek(file, static_cast<PHYSFS_uint64> (offset)) == 0)
        return -1;
      break;
    case SEEK_CUR:
      if(PHYSFS_seek(file, PHYSFS_tell(file) + offset) == 0)
        return -1;
      break;
    case SEEK_END:
      if(PHYSFS_seek(file, PHYSFS_fileLength(file) + offset) == 0)
        return -1;
      break;
    default:
#ifdef DEBUG
      assert(false);
#else
      return -1;
#endif
  }
  return 0;
}
开发者ID:slackstone,项目名称:tuxjunior,代码行数:27,代码来源:sound_file.cpp


示例18: 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:Gokulakrishnansr,项目名称:cdogs-sdl,代码行数:26,代码来源:test_physfs.c


示例19: 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


示例20: PHYSFS_openRead

bool ResourceManager::copyFile(const std::string &src, const std::string &dst)
{
    PHYSFS_file *srcFile = PHYSFS_openRead(src.c_str());
    if (!srcFile)
    {
        logger->log("Read error: %s", PHYSFS_getLastError());
        return false;
    }
    PHYSFS_file *dstFile = PHYSFS_openWrite(dst.c_str());
    if (!dstFile)
    {
        logger->log("Write error: %s", PHYSFS_getLastError());
        PHYSFS_close(srcFile);
        return false;
    }

    int fileSize = PHYSFS_fileLength(srcFile);
    void *buf = malloc(fileSize);
    PHYSFS_read(srcFile, buf, 1, fileSize);
    PHYSFS_write(dstFile, buf, 1, fileSize);

    PHYSFS_close(srcFile);
    PHYSFS_close(dstFile);
    free(buf);
    return true;
}
开发者ID:Ablu,项目名称:invertika,代码行数:26,代码来源:resourcemanager.cpp



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ PHYSFS_getDirSeparator函数代码示例发布时间:2022-05-30
下一篇:
C++ PHYSFS_exists函数代码示例发布时间: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