Commit e7c19f9e authored by hybrid's avatar hybrid

Give access to LimitReadFiles.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2304 dfc29bdd-3216-0410-991c-e03cc46cb475
parent b426f83a
...@@ -53,6 +53,19 @@ public: ...@@ -53,6 +53,19 @@ public:
*/ */
virtual IReadFile* createMemoryReadFile(void* memory, s32 len, const core::string<c16>& fileName, bool deleteMemoryWhenDropped=false) =0; virtual IReadFile* createMemoryReadFile(void* memory, s32 len, const core::string<c16>& fileName, bool deleteMemoryWhenDropped=false) =0;
//! Creates an IReadFile interface for accessing files inside files.
/** This is useful e.g. for archives.
\param fileName: The name given to this file
\param alreadyOpenedFile: Pointer to the enclosing file
\param pos: Start of the file inside alreadyOpenedFile
\param areaSize: The length of the file
\return A pointer to the created file interface.
The returned pointer should be dropped when no longer needed.
See IReferenceCounted::drop() for more information.
*/
virtual IReadFile* createLimitReadFile(const core::string<c16>& fileName,
IReadFile* alreadyOpenedFile, long pos, long areaSize) =0;
//! Creates an IWriteFile interface for accessing memory like a file. //! Creates an IWriteFile interface for accessing memory like a file.
/** This allows you to use a pointer to memory where an IWriteFile is requested. /** This allows you to use a pointer to memory where an IWriteFile is requested.
You are responsible for allocating enough memory. You are responsible for allocating enough memory.
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "os.h" #include "os.h"
#include "CAttributes.h" #include "CAttributes.h"
#include "CMemoryFile.h" #include "CMemoryFile.h"
#include "CLimitReadFile.h"
#if defined (_IRR_WINDOWS_API_) #if defined (_IRR_WINDOWS_API_)
#if !defined ( _WIN32_WCE ) #if !defined ( _WIN32_WCE )
...@@ -93,6 +94,18 @@ IReadFile* CFileSystem::createMemoryReadFile(void* memory, s32 len, ...@@ -93,6 +94,18 @@ IReadFile* CFileSystem::createMemoryReadFile(void* memory, s32 len,
return new CMemoryFile(memory, len, fileName, deleteMemoryWhenDropped); return new CMemoryFile(memory, len, fileName, deleteMemoryWhenDropped);
} }
//! Creates an IReadFile interface for reading files inside files
IReadFile* CFileSystem::createLimitReadFile(const core::string<c16>& fileName,
IReadFile* alreadyOpenedFile, long pos, long areaSize)
{
if (!alreadyOpenedFile)
return 0;
else
return new CLimitReadFile(alreadyOpenedFile, pos, areaSize, fileName);
}
//! Creates an IReadFile interface for treating memory like a file. //! Creates an IReadFile interface for treating memory like a file.
IWriteFile* CFileSystem::createMemoryWriteFile(void* memory, s32 len, IWriteFile* CFileSystem::createMemoryWriteFile(void* memory, s32 len,
const core::string<c16>& fileName, bool deleteMemoryWhenDropped) const core::string<c16>& fileName, bool deleteMemoryWhenDropped)
......
...@@ -36,6 +36,9 @@ public: ...@@ -36,6 +36,9 @@ public:
//! Creates an IReadFile interface for accessing memory like a file. //! Creates an IReadFile interface for accessing memory like a file.
virtual IReadFile* createMemoryReadFile(void* memory, s32 len, const core::string<c16>& fileName, bool deleteMemoryWhenDropped = false); virtual IReadFile* createMemoryReadFile(void* memory, s32 len, const core::string<c16>& fileName, bool deleteMemoryWhenDropped = false);
//! Creates an IReadFile interface for accessing files inside files
virtual IReadFile* createLimitReadFile(const core::string<c16>& fileName, IReadFile* alreadyOpenedFile, long pos, long areaSize);
//! Creates an IWriteFile interface for accessing memory like a file. //! Creates an IWriteFile interface for accessing memory like a file.
virtual IWriteFile* createMemoryWriteFile(void* memory, s32 len, const core::string<c16>& fileName, bool deleteMemoryWhenDropped=false); virtual IWriteFile* createMemoryWriteFile(void* memory, s32 len, const core::string<c16>& fileName, bool deleteMemoryWhenDropped=false);
......
...@@ -11,9 +11,10 @@ namespace io ...@@ -11,9 +11,10 @@ namespace io
{ {
CLimitReadFile::CLimitReadFile(IReadFile* alreadyOpenedFile, long pos, long areaSize, CLimitReadFile::CLimitReadFile(IReadFile* alreadyOpenedFile, long pos,
const core::string<c16>& name) long areaSize, const core::string<c16>& name)
: Filename(name), AreaStart(0), AreaEnd(0), Pos(0), File(alreadyOpenedFile) : Filename(name), AreaStart(0), AreaEnd(0), Pos(0),
File(alreadyOpenedFile)
{ {
#ifdef _DEBUG #ifdef _DEBUG
setDebugName("CLimitReadFile"); setDebugName("CLimitReadFile");
...@@ -35,19 +36,18 @@ CLimitReadFile::~CLimitReadFile() ...@@ -35,19 +36,18 @@ CLimitReadFile::~CLimitReadFile()
} }
//! returns how much was read //! returns how much was read
s32 CLimitReadFile::read(void* buffer, u32 sizeToRead) s32 CLimitReadFile::read(void* buffer, u32 sizeToRead)
{ {
#if 1 #if 1
if ( 0 == File ) if (0 == File)
return 0; return 0;
s32 r = AreaStart + Pos; s32 r = AreaStart + Pos;
s32 toRead = core::s32_min( AreaEnd, r + sizeToRead ) - core::s32_max( AreaStart, r ); s32 toRead = core::s32_min(AreaEnd, r + sizeToRead) - core::s32_max(AreaStart, r);
if ( toRead < 0 ) if (toRead < 0)
return 0; return 0;
File->seek ( r ); File->seek(r);
r = File->read(buffer, toRead); r = File->read(buffer, toRead);
Pos += r; Pos += r;
return r; return r;
...@@ -65,14 +65,11 @@ s32 CLimitReadFile::read(void* buffer, u32 sizeToRead) ...@@ -65,14 +65,11 @@ s32 CLimitReadFile::read(void* buffer, u32 sizeToRead)
} }
//! changes position in file, returns true if successful //! changes position in file, returns true if successful
//! if relativeMovement==true, the pos is changed relative to current pos,
//! otherwise from begin of file
bool CLimitReadFile::seek(long finalPos, bool relativeMovement) bool CLimitReadFile::seek(long finalPos, bool relativeMovement)
{ {
#if 1 #if 1
Pos = core::s32_clamp ( finalPos + (relativeMovement ? Pos : 0 ), 0, AreaEnd - AreaStart ); Pos = core::s32_clamp(finalPos + (relativeMovement ? Pos : 0 ), 0, AreaEnd - AreaStart);
return true; return true;
#else #else
const long pos = File->getPos(); const long pos = File->getPos();
...@@ -101,7 +98,6 @@ long CLimitReadFile::getSize() const ...@@ -101,7 +98,6 @@ long CLimitReadFile::getSize() const
} }
//! returns where in the file we are. //! returns where in the file we are.
long CLimitReadFile::getPos() const long CLimitReadFile::getPos() const
{ {
...@@ -113,7 +109,6 @@ long CLimitReadFile::getPos() const ...@@ -113,7 +109,6 @@ long CLimitReadFile::getPos() const
} }
//! returns name of file //! returns name of file
const core::string<c16>& CLimitReadFile::getFileName() const const core::string<c16>& CLimitReadFile::getFileName() const
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment