本文整理汇总了C++中PHYSFS_fileLength函数的典型用法代码示例。如果您正苦于以下问题:C++ PHYSFS_fileLength函数的具体用法?C++ PHYSFS_fileLength怎么用?C++ PHYSFS_fileLength使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PHYSFS_fileLength函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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);
}
示例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);
}
示例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*/
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}