diff --git a/include/eepp/audio/music.hpp b/include/eepp/audio/music.hpp index 584f39538..e3970aacd 100644 --- a/include/eepp/audio/music.hpp +++ b/include/eepp/audio/music.hpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include @@ -239,7 +239,7 @@ class EE_API Music : public SoundStream std::vector mSamples; ///< Temporary buffer of samples Mutex mMutex; ///< Mutex protecting the data Span mLoopSpan; ///< Loop Range Specifier - SafeDataPointer mData; + ScopedBuffer mData; }; }} diff --git a/include/eepp/graphics/fonttruetype.hpp b/include/eepp/graphics/fonttruetype.hpp index 471c201c0..4d7690740 100644 --- a/include/eepp/graphics/fonttruetype.hpp +++ b/include/eepp/graphics/fonttruetype.hpp @@ -86,7 +86,7 @@ class EE_API FontTrueType : public Font { void* mStreamRec; ///< Pointer to the stream rec instance (it is typeless to avoid exposing implementation details) void* mStroker; ///< Pointer to the stroker (it is typeless to avoid exposing implementation details) int* mRefCount; ///< Reference counter used by implicit sharing - SafeDataPointer mMemCopy; + mutable ScopedBuffer mMemCopy; ///< If loaded from memory, this is the file copy in memory Font::Info mInfo; ///< Information about the font mutable PageTable mPages; ///< Table containing the glyphs pages by character size mutable std::vector mPixelBuffer; ///< Pixel buffer holding a glyph's pixels before being written to the texture diff --git a/include/eepp/system/directorypack.hpp b/include/eepp/system/directorypack.hpp index 55cc5ec2c..53a861957 100644 --- a/include/eepp/system/directorypack.hpp +++ b/include/eepp/system/directorypack.hpp @@ -52,7 +52,7 @@ class EE_API DirectoryPack : public Pack { bool extractFileToMemory( const std::string& path, std::vector& data ); /** Extract a file to memory from the pakFile */ - bool extractFileToMemory( const std::string& path, SafeDataPointer& data ); + bool extractFileToMemory( const std::string& path, ScopedBuffer& data ); /** Check if a file exists in the pack file and return the number of the file, otherwise return -1. */ Int32 exists( const std::string& path ); diff --git a/include/eepp/system/filesystem.hpp b/include/eepp/system/filesystem.hpp index 5da11ecf4..709817987 100644 --- a/include/eepp/system/filesystem.hpp +++ b/include/eepp/system/filesystem.hpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include namespace EE { namespace System { @@ -25,10 +25,10 @@ class EE_API FileSystem { /** Copy a file to memory * @param path The file path - * @param data A SafeDataPointer to allocate the data to memory - * @return True if returned the file to the SafeDataPointer + * @param data A ScopedBuffer to allocate the data to memory + * @return True if returned the file to the ScopedBuffer */ - static bool fileGet( const std::string& path, SafeDataPointer& data ); + static bool fileGet( const std::string& path, ScopedBuffer& data ); /** Copy a file to location. * @param src Source File Path diff --git a/include/eepp/system/iostreamdeflate.hpp b/include/eepp/system/iostreamdeflate.hpp index d92e24801..eab4223bc 100644 --- a/include/eepp/system/iostreamdeflate.hpp +++ b/include/eepp/system/iostreamdeflate.hpp @@ -2,7 +2,7 @@ #define EE_SYSTEM_IOSTREAMDEFLATE_HPP #include -#include +#include #include namespace EE { namespace System { @@ -40,7 +40,7 @@ class EE_API IOStreamDeflate : public IOStream { protected: IOStream& mStream; Compression::Mode mMode; - SafeDataPointer mBuffer; + ScopedBuffer mBuffer; LocalStreamData * mLocalStream; }; diff --git a/include/eepp/system/iostreaminflate.hpp b/include/eepp/system/iostreaminflate.hpp index 5564ee96f..8eaacfae3 100644 --- a/include/eepp/system/iostreaminflate.hpp +++ b/include/eepp/system/iostreaminflate.hpp @@ -2,7 +2,7 @@ #define EE_SYSTEM_IOSTREAMINFLATE_HPP #include -#include +#include #include namespace EE { namespace System { @@ -39,7 +39,7 @@ class EE_API IOStreamInflate : public IOStream { protected: IOStream& mStream; Compression::Mode mMode; - SafeDataPointer mBuffer; + ScopedBuffer mBuffer; LocalStreamData * mLocalStream; }; diff --git a/include/eepp/system/pack.hpp b/include/eepp/system/pack.hpp index bb371436f..5bdb9469c 100755 --- a/include/eepp/system/pack.hpp +++ b/include/eepp/system/pack.hpp @@ -2,7 +2,7 @@ #define EE_SYSTEMCPACK_HPP #include -#include +#include #include namespace EE { namespace System { @@ -52,7 +52,7 @@ class EE_API Pack : protected Mutex { virtual bool extractFileToMemory( const std::string& path, std::vector& data ) = 0; /** Extract a file to memory from the pack file */ - virtual bool extractFileToMemory( const std::string& path, SafeDataPointer& data ) = 0; + virtual bool extractFileToMemory( const std::string& path, ScopedBuffer& data ) = 0; /** Check if a file exists in the pack file and return the number of the file, otherwise return -1. */ virtual Int32 exists( const std::string& path ) = 0; diff --git a/include/eepp/system/pak.hpp b/include/eepp/system/pak.hpp index 952bf6808..75668f444 100755 --- a/include/eepp/system/pak.hpp +++ b/include/eepp/system/pak.hpp @@ -53,7 +53,7 @@ class EE_API Pak : public Pack { bool extractFileToMemory( const std::string& path, std::vector& data ); /** Extract a file to memory from the pakFile */ - bool extractFileToMemory( const std::string& path, SafeDataPointer& data ); + bool extractFileToMemory( const std::string& path, ScopedBuffer& data ); /** Check if a file exists in the pakFile and return the number of the file, otherwise return -1. */ Int32 exists( const std::string& path ); diff --git a/include/eepp/system/safedatapointer.hpp b/include/eepp/system/safedatapointer.hpp deleted file mode 100644 index 0f572d1d2..000000000 --- a/include/eepp/system/safedatapointer.hpp +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef EE_SYSTEM_SAFEDATAPOINTER -#define EE_SYSTEM_SAFEDATAPOINTER - -#include -#include -#include - -namespace EE { namespace System { - -/** @brief Keep a pointer and release it in the SafeDataPointer destructor */ -template -class TSafeDataPointer { - public: - TSafeDataPointer(); - - TSafeDataPointer( Uint32 size ); - - TSafeDataPointer( T * data, Uint32 size ); - - /** @brief The destructor deletes the buffer */ - ~TSafeDataPointer(); - - void clear(); - - /** Pointer to the buffer */ - T * data; - - /** Buffer size */ - Uint32 size; -}; - - -template -TSafeDataPointer::TSafeDataPointer() : - data( NULL ), - size( 0 ) -{ -} - -template -TSafeDataPointer::TSafeDataPointer( Uint32 size ) : - data( eeNewArray( T, size ) ), - size( size ) -{ -} - -template -TSafeDataPointer::TSafeDataPointer( T * data, Uint32 size ) : - data( data ), - size( size ) -{ -} - -template -TSafeDataPointer::~TSafeDataPointer() { - clear(); -} - -template -void TSafeDataPointer::clear() { - eeSAFE_DELETE_ARRAY( data ); -} - -typedef TSafeDataPointer SafeDataPointer; - -}} - -#endif diff --git a/include/eepp/system/scopedbuffer.hpp b/include/eepp/system/scopedbuffer.hpp new file mode 100644 index 000000000..a6d401924 --- /dev/null +++ b/include/eepp/system/scopedbuffer.hpp @@ -0,0 +1,153 @@ +#ifndef EE_SYSTEM_SCOPEDBUFFER +#define EE_SYSTEM_SCOPEDBUFFER + +#include +#include +#include +#include +#include + +namespace EE { namespace System { + +/** @brief Keep a pointer to a buffer and release it when the ScopedBuffer goes out of scope. + +The TScopedBuffer class template stores a pointer to a dynamically allocated array. +(Dynamically allocated arrays are allocated with the C++ new[] expression.) +The array pointed to is guaranteed to be deleted, either on destruction of the TScopedBuffer, +or via an explicit reset. + +The TScopedBuffer template is a simple solution for simple needs. +It supplies a basic "resource acquisition is initialization" facility, +without shared-ownership or transfer-of-ownership semantics. +Both its name and enforcement of semantics (by being NonCopyable) signal its +intent to retain ownership solely within the current scope. +*/ +template +class TScopedBuffer : NonCopyable { + public: + TScopedBuffer(); + + TScopedBuffer( std::size_t length ); + + TScopedBuffer( T * data, std::size_t length ); + + /** @brief The destructor deletes the buffer */ + ~TScopedBuffer(); + + void clear(); + + T& operator[]( std::size_t i ) const; + + bool operator()() const; + + T * get() const; + + void swap(TScopedBuffer& b); + + void reset(T * p = 0, const std::size_t& size = 0); + + void reset(const std::size_t& size = 0); + + bool isEmpty() const; + + const std::size_t& size() const; + + const std::size_t& length() const; + + private: + /** Pointer to the buffer */ + T * mData; + + /** Buffer size */ + std::size_t mSize; +}; + +template +TScopedBuffer::TScopedBuffer() : + mData( NULL ), + mSize( 0 ) +{ +} + +template +TScopedBuffer::TScopedBuffer( std::size_t length ) : + mData( eeNewArray( T, length ) ), + mSize( length ) +{ +} + +template +TScopedBuffer::TScopedBuffer( T * data, std::size_t length ) : + mData( data ), + mSize( length ) +{ +} + +template +TScopedBuffer::~TScopedBuffer() { + clear(); +} + +template +void TScopedBuffer::clear() { + eeSAFE_DELETE_ARRAY( mData ); + mSize = 0; +} + +template +T& TScopedBuffer::operator[]( std::size_t i ) const { + eeASSERT( i < mSize && NULL != mData ); + return mData[i]; +} + +template +bool TScopedBuffer::operator()() const { + return NULL != mData; +} + +template +T * TScopedBuffer::get() const { + return mData; +} + +template +const std::size_t& TScopedBuffer::size() const { + return mSize; +} + +template +const std::size_t& TScopedBuffer::length() const { + return mSize; +} + +template +bool TScopedBuffer::isEmpty() const { + return mData == NULL; +} + +template +void TScopedBuffer::swap(TScopedBuffer& b) { + std::swap(mData, b.mData); + std::swap(mSize, b.mSize); +} + +template +void TScopedBuffer::reset(T * p, const std::size_t& size) { + eeASSERT( p == 0 || p != mData ); + clear(); + mData = p; + mSize = size; +} + +template +void TScopedBuffer::reset(const std::size_t& size) { + clear(); + mData = eeNewArray( T, ( size ) ); + mSize = size; +} + +typedef TScopedBuffer ScopedBuffer; + +}} + +#endif diff --git a/include/eepp/system/zip.hpp b/include/eepp/system/zip.hpp index 9eadaf3cd..f64228ef8 100644 --- a/include/eepp/system/zip.hpp +++ b/include/eepp/system/zip.hpp @@ -51,7 +51,7 @@ class EE_API Zip : public Pack { bool extractFileToMemory( const std::string& path, std::vector& data ); /** Extract a file to memory from the pakFile */ - bool extractFileToMemory( const std::string& path, SafeDataPointer& data ); + bool extractFileToMemory( const std::string& path, ScopedBuffer& data ); /** Check if a file exists in the pack file and return the number of the file, otherwise return -1. */ Int32 exists( const std::string& path ); diff --git a/projects/linux/ee.files b/projects/linux/ee.files index e3841c305..ef9e03f61 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -267,7 +267,7 @@ ../../include/eepp/system/rc4.hpp ../../include/eepp/system/resourceloader.hpp ../../include/eepp/system/resourcemanager.hpp -../../include/eepp/system/safedatapointer.hpp +../../include/eepp/system/scopedbuffer.hpp ../../include/eepp/system/singleton.hpp ../../include/eepp/system/sys.hpp ../../include/eepp/system/thread.hpp diff --git a/src/eepp/audio/music.cpp b/src/eepp/audio/music.cpp index cf93d2944..cf72b7de9 100644 --- a/src/eepp/audio/music.cpp +++ b/src/eepp/audio/music.cpp @@ -81,7 +81,7 @@ bool Music::openFromStream(IOStream& stream) { bool Music::openFromPack(Pack * pack, const std::string & filePackPath) { if ( pack->isOpen() && pack->extractFileToMemory( filePackPath, mData ) ) - return openFromMemory( reinterpret_cast ( mData.data ), mData.size ); + return openFromMemory( reinterpret_cast ( mData.get() ), mData.length() ); return false; } diff --git a/src/eepp/audio/soundbuffer.cpp b/src/eepp/audio/soundbuffer.cpp index 90dab69fa..6daf7a815 100644 --- a/src/eepp/audio/soundbuffer.cpp +++ b/src/eepp/audio/soundbuffer.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include @@ -105,10 +105,10 @@ bool SoundBuffer::loadFromSamples(const Int16* samples, Uint64 sampleCount, unsi bool SoundBuffer::loadFromPack(Pack * pack, std::string filePackPath) { bool Ret = false; - SafeDataPointer PData; + ScopedBuffer buffer; - if ( pack->isOpen() && pack->extractFileToMemory( filePackPath, PData ) ) - Ret = loadFromMemory( reinterpret_cast ( PData.data ), PData.size ); + if ( pack->isOpen() && pack->extractFileToMemory( filePackPath, buffer ) ) + Ret = loadFromMemory( reinterpret_cast ( buffer.get() ), buffer.length() ); return Ret; } diff --git a/src/eepp/audio/soundfilereadermp3.cpp b/src/eepp/audio/soundfilereadermp3.cpp index 203fce15b..9bc8e942b 100644 --- a/src/eepp/audio/soundfilereadermp3.cpp +++ b/src/eepp/audio/soundfilereadermp3.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include static size_t drmp3_func_read(void* data, void* ptr, size_t size) { IOStream* stream = static_cast(data); @@ -73,15 +73,15 @@ Uint64 SoundFileReaderMp3::read(Int16* samples, Uint64 maxCount) { while (count < maxCount) { const int samplesToRead = static_cast(maxCount - count); int frames = samplesToRead / mChannelCount; - TSafeDataPointer rSamples( samplesToRead ); + TScopedBuffer rSamples( samplesToRead ); - long framesRead = drmp3_read_pcm_frames_f32( mMp3, frames, rSamples.data ); + long framesRead = drmp3_read_pcm_frames_f32( mMp3, frames, rSamples.get() ); if (framesRead > 0) { long samplesRead = framesRead * mChannelCount; for ( int i = 0; i < samplesRead; i++ ) - samples[i] = rSamples.data[i] * 32768.f; + samples[i] = rSamples[i] * 32768.f; count += samplesRead; samples += samplesRead; diff --git a/src/eepp/graphics/fonttruetype.cpp b/src/eepp/graphics/fonttruetype.cpp index 2c3f936fc..8792a8de2 100644 --- a/src/eepp/graphics/fonttruetype.cpp +++ b/src/eepp/graphics/fonttruetype.cpp @@ -242,7 +242,7 @@ bool FontTrueType::loadFromPack( Pack * pack, std::string filePackPath ) { mMemCopy.clear(); if ( pack->isOpen() && pack->extractFileToMemory( filePackPath, mMemCopy ) ) { - Ret = loadFromMemory( mMemCopy.data, mMemCopy.size ); + Ret = loadFromMemory( mMemCopy.get(), mMemCopy.length() ); } return Ret; @@ -367,8 +367,9 @@ Texture* FontTrueType::getTexture(unsigned int characterSize) const { } FontTrueType& FontTrueType::operator =(const FontTrueType& right) { - FontTrueType temp(right); + FontTrueType temp(right.getName()); + temp.mMemCopy.swap(right.mMemCopy); std::swap(mLibrary, temp.mLibrary); std::swap(mFace, temp.mFace); std::swap(mStreamRec, temp.mStreamRec); diff --git a/src/eepp/graphics/image.cpp b/src/eepp/graphics/image.cpp index 142086d49..e87d04eb0 100644 --- a/src/eepp/graphics/image.cpp +++ b/src/eepp/graphics/image.cpp @@ -284,18 +284,18 @@ bool Image::getInfo( const std::string& path, int * width, int * height, int * c Pack * tPack = PackManager::instance()->exists( npath ); if ( NULL != tPack ) { - SafeDataPointer PData; + ScopedBuffer buffer; - tPack->extractFileToMemory( npath, PData ); + tPack->extractFileToMemory( npath, buffer ); - res = 0 != stbi_info_from_memory( PData.data, PData.size, width, height, channels ); + res = 0 != stbi_info_from_memory( buffer.get(), buffer.length(), width, height, channels ); - if ( !res && svg_test_from_memory( PData.data, PData.size ) ) { - SafeDataPointer data( PData.size + 1 ); - memcpy( data.data, PData.data, PData.size ); - data.data[PData.size] = '\0'; + if ( !res && svg_test_from_memory( buffer.get(), buffer.length() ) ) { + ScopedBuffer data( buffer.length() + 1 ); + memcpy( data.get(), buffer.get(), buffer.length() ); + data[buffer.length()] = '\0'; - NSVGimage * image = nsvgParse( (char*)data.data, "px", 96.0f ); + NSVGimage * image = nsvgParse( (char*)data.get(), "px", 96.0f ); if ( NULL != image ) { *width = image->width * imageFormatConfiguration.svgScale(); @@ -467,10 +467,10 @@ Image::Image( const Uint8 * imageData, const unsigned int & imageDataSize, const mLoadedFromStbi = true; } else if ( svg_test_from_memory( imageData, imageDataSize ) ) { - SafeDataPointer data( imageDataSize + 1 ); - memcpy( data.data, imageData, imageDataSize ); - data.data[imageDataSize] = '\0'; - svgLoad( nsvgParse( (char*)data.data, "px", 96.0f ) ); + ScopedBuffer data( imageDataSize + 1 ); + memcpy( data.get(), imageData, imageDataSize ); + data[imageDataSize] = '\0'; + svgLoad( nsvgParse( (char*)data.get(), "px", 96.0f ) ); } else { std::string reason = "."; @@ -526,14 +526,14 @@ Image::Image( IOStream & stream, const unsigned int& forceChannels, const Format mLoadedFromStbi = true; } else if ( svg_test_from_stream( stream ) ) { - SafeDataPointer data( stream.getSize() + 1 ); + ScopedBuffer data( stream.getSize() + 1 ); stream.seek( 0 ); - stream.read( (char*)data.data, data.size - 1 ); + stream.read( (char*)data.get(), data.length() - 1 ); - data.data[data.size - 1] = '\0'; + data[data.length() - 1] = '\0'; - svgLoad( nsvgParse( (char*)data.data, "px", 96.0f ) ); + svgLoad( nsvgParse( (char*)data.get(), "px", 96.0f ) ); } else { eePRINTL( "Failed to load image. Reason: %s", stbi_failure_reason() ); } @@ -580,12 +580,12 @@ void Image::svgLoad( NSVGimage * image ) { void Image::loadFromPack( Pack * Pack, const std::string& FilePackPath ) { if ( NULL != Pack && Pack->isOpen() && -1 != Pack->exists( FilePackPath ) ) { - SafeDataPointer PData; + ScopedBuffer buffer; - Pack->extractFileToMemory( FilePackPath, PData ); + Pack->extractFileToMemory( FilePackPath, buffer ); int w, h, c; - Uint8 * data = stbi_load_from_memory( PData.data, PData.size, &w, &h, &c, mChannels ); + Uint8 * data = stbi_load_from_memory( buffer.get(), buffer.length(), &w, &h, &c, mChannels ); if ( NULL != data ) { mPixels = data; @@ -598,11 +598,11 @@ void Image::loadFromPack( Pack * Pack, const std::string& FilePackPath ) { mSize = mWidth * mHeight * mChannels; mLoadedFromStbi = true; - } else if ( svg_test_from_memory( PData.data, PData.size ) ) { - SafeDataPointer data( PData.size + 1 ); - memcpy( data.data, PData.data, PData.size ); - data.data[PData.size] = '\0'; - svgLoad( nsvgParse( (char*)data.data, "px", 96.0f ) ); + } else if ( svg_test_from_memory( buffer.get(), buffer.length() ) ) { + ScopedBuffer data( buffer.length() + 1 ); + memcpy( data.get(), buffer.get(), buffer.length() ); + data[buffer.length()] = '\0'; + svgLoad( nsvgParse( (char*)data.get(), "px", 96.0f ) ); } else { eePRINTL( "Failed to load image %s. Reason: %s", FilePackPath.c_str(), stbi_failure_reason() ); } diff --git a/src/eepp/graphics/shader.cpp b/src/eepp/graphics/shader.cpp index 43599342e..cb3b083f7 100644 --- a/src/eepp/graphics/shader.cpp +++ b/src/eepp/graphics/shader.cpp @@ -30,21 +30,21 @@ Shader::Shader( const Uint32& Type, const std::string& Filename ) { mFilename = FileSystem::fileNameFromPath( Filename ); if ( FileSystem::fileExists( Filename ) ) { - SafeDataPointer PData; + ScopedBuffer buffer; - FileSystem::fileGet( Filename, PData ); + FileSystem::fileGet( Filename, buffer ); - setSource( (const char*)PData.data, PData.size ); + setSource( (const char*)buffer.get(), buffer.length() ); } else { std::string tPath = Filename; Pack * tPack = NULL; if ( PackManager::instance()->isFallbackToPacksActive() && NULL != ( tPack = PackManager::instance()->exists( tPath ) ) ) { - SafeDataPointer PData; + ScopedBuffer buffer; - tPack->extractFileToMemory( tPath, PData ); + tPack->extractFileToMemory( tPath, buffer ); - setSource( reinterpret_cast ( PData.data ), PData.size ); + setSource( reinterpret_cast ( buffer.get() ), buffer.length() ); } else { eePRINTL( "Couldn't open shader object: %s", Filename.c_str() ); } @@ -62,16 +62,16 @@ Shader::Shader( const Uint32& Type, const char * Data, const Uint32& DataSize ) } Shader::Shader( const Uint32& Type, Pack * Pack, const std::string& Filename ) { - SafeDataPointer PData; + ScopedBuffer buffer; Init( Type ); mFilename = FileSystem::fileNameFromPath( Filename ); if ( NULL != Pack && Pack->isOpen() && -1 != Pack->exists( Filename ) ) { - Pack->extractFileToMemory( Filename, PData ); + Pack->extractFileToMemory( Filename, buffer ); - setSource( reinterpret_cast ( PData.data ), PData.size ); + setSource( reinterpret_cast ( buffer.get() ), buffer.length() ); } compile(); diff --git a/src/eepp/graphics/textureatlasloader.cpp b/src/eepp/graphics/textureatlasloader.cpp index db6717475..ca53bad06 100644 --- a/src/eepp/graphics/textureatlasloader.cpp +++ b/src/eepp/graphics/textureatlasloader.cpp @@ -193,11 +193,11 @@ void TextureAtlasLoader::loadFromPack( Pack * Pack, const std::string& FilePackP if ( NULL != Pack && Pack->isOpen() && -1 != Pack->exists( FilePackPath ) ) { mPack = Pack; - SafeDataPointer PData; + ScopedBuffer buffer; - Pack->extractFileToMemory( FilePackPath, PData ); + Pack->extractFileToMemory( FilePackPath, buffer ); - loadFromMemory( reinterpret_cast ( PData.data ), PData.size, FilePackPath ); + loadFromMemory( buffer.get(), buffer.length(), FilePackPath ); } } diff --git a/src/eepp/graphics/textureloader.cpp b/src/eepp/graphics/textureloader.cpp index d8caa35db..dc2e00012 100644 --- a/src/eepp/graphics/textureloader.cpp +++ b/src/eepp/graphics/textureloader.cpp @@ -278,11 +278,11 @@ void TextureLoader::loadFromFile() { } void TextureLoader::loadFromPack() { - SafeDataPointer PData; + ScopedBuffer buffer; - if ( NULL != mPack && mPack->isOpen() && mPack->extractFileToMemory( mFilepath, PData ) ) { - mImagePtr = PData.data; - mSize = PData.size; + if ( NULL != mPack && mPack->isOpen() && mPack->extractFileToMemory( mFilepath, buffer ) ) { + mImagePtr = buffer.get(); + mSize = buffer.length(); loadFromMemory(); } diff --git a/src/eepp/maps/tilemap.cpp b/src/eepp/maps/tilemap.cpp index 695a96917..9efd6ffff 100644 --- a/src/eepp/maps/tilemap.cpp +++ b/src/eepp/maps/tilemap.cpp @@ -1072,13 +1072,13 @@ bool TileMap::loadFromFile( const std::string& path ) { bool TileMap::loadFromPack( Pack * Pack, const std::string& FilePackPath ) { if ( NULL != Pack && Pack->isOpen() && -1 != Pack->exists( FilePackPath ) ) { - SafeDataPointer PData; + ScopedBuffer buffer; - Pack->extractFileToMemory( FilePackPath, PData ); + Pack->extractFileToMemory( FilePackPath, buffer ); mPath = FilePackPath; - return loadFromMemory( reinterpret_cast ( PData.data ), PData.size ); + return loadFromMemory( reinterpret_cast ( buffer.get() ), buffer.length() ); } return false; diff --git a/src/eepp/network/ssl/backend/mbedtls/mbedtlssocket.cpp b/src/eepp/network/ssl/backend/mbedtls/mbedtlssocket.cpp index 2f32240a0..ef6791e7c 100644 --- a/src/eepp/network/ssl/backend/mbedtls/mbedtlssocket.cpp +++ b/src/eepp/network/ssl/backend/mbedtls/mbedtlssocket.cpp @@ -14,7 +14,7 @@ bool MbedTLSSocket::init() { mbedtls_x509_crt_init(&sCACert); //! Load the certificates and config - SafeDataPointer data; + ScopedBuffer data; if ( FileSystem::fileExists( SSLSocket::CertificatesPath ) ) { FileSystem::fileGet( SSLSocket::CertificatesPath, data ); @@ -28,12 +28,12 @@ bool MbedTLSSocket::init() { } } - if ( data.size > 0 ) { - SafeDataPointer dataZeroEnded( data.size + 1 ); - memcpy( dataZeroEnded.data, data.data, data.size ); - dataZeroEnded.data[ data.size ] = '\0'; + if ( data.length() > 0 ) { + ScopedBuffer dataZeroEnded( data.length() + 1 ); + memcpy( dataZeroEnded.get(), data.get(), data.length() ); + dataZeroEnded[ data.length() ] = '\0'; - int err = mbedtls_x509_crt_parse( &sCACert, (const unsigned char*)dataZeroEnded.data, dataZeroEnded.size ); + int err = mbedtls_x509_crt_parse( &sCACert, (const unsigned char*)dataZeroEnded.get(), dataZeroEnded.length() ); if ( err != 0 ) { char errStr[ 1024 ]; diff --git a/src/eepp/network/ssl/backend/openssl/opensslsocket.cpp b/src/eepp/network/ssl/backend/openssl/opensslsocket.cpp index 43063f4e7..994f6b482 100644 --- a/src/eepp/network/ssl/backend/openssl/opensslsocket.cpp +++ b/src/eepp/network/ssl/backend/openssl/opensslsocket.cpp @@ -152,13 +152,13 @@ bool OpenSSLSocket::init() { //! Load the certificates and config if ( FileSystem::fileExists( SSLSocket::CertificatesPath ) ) { - SafeDataPointer data; + ScopedBuffer data; FileSystem::fileGet( SSLSocket::CertificatesPath, data ); - if ( data.size > 0 ) { + if ( data.length() > 0 ) { BIO* mem = BIO_new(BIO_s_mem()); - BIO_puts( mem, (const char*) data.data ); + BIO_puts( mem, (const char*) data.get() ); while( true ) { X509 * cert = PEM_read_bio_X509(mem, NULL, 0, NULL); diff --git a/src/eepp/system/compression.cpp b/src/eepp/system/compression.cpp index 440bc0e0e..38c056453 100644 --- a/src/eepp/system/compression.cpp +++ b/src/eepp/system/compression.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include @@ -102,15 +102,15 @@ Compression::Status Compression::decompress(IOStream& dst, IOStream& src, Mode m case MODE_DEFLATE: case MODE_GZIP: { - SafeDataPointer buffer( DEFLATE_CHUNK_SIZE ); - SafeDataPointer bufferDst( DEFLATE_CHUNK_SIZE ); + ScopedBuffer buffer( DEFLATE_CHUNK_SIZE ); + ScopedBuffer bufferDst( DEFLATE_CHUNK_SIZE ); src.seek( 0 ); int windowBits = mode == Compression::MODE_DEFLATE ? MAX_WBITS : MAX_WBITS | 16; z_stream strm = {}; - strm.next_in = buffer.data; + strm.next_in = buffer.get(); int err = inflateInit2(&strm, windowBits); if (err != Z_OK) @@ -123,14 +123,14 @@ Compression::Status Compression::decompress(IOStream& dst, IOStream& src, Mode m Uint32 totalRead = 0; while ( totalRead < totalSize ) { - bytesRead = src.read( (char*)buffer.data, buffer.size ); + bytesRead = src.read( (char*)buffer.get(), buffer.length() ); strm.avail_in = bytesRead; - strm.next_in = buffer.data; + strm.next_in = buffer.get(); do { - strm.avail_out = bufferDst.size; - strm.next_out = bufferDst.data; + strm.avail_out = bufferDst.length(); + strm.next_out = bufferDst.get(); zlibStatus = inflate(&strm, Z_NO_FLUSH); switch (zlibStatus) { @@ -143,9 +143,9 @@ Compression::Status Compression::decompress(IOStream& dst, IOStream& src, Mode m return (Status)zlibStatus; } - have = bufferDst.size- strm.avail_out; + have = bufferDst.length()- strm.avail_out; - dst.write( (const char*)bufferDst.data, have ); + dst.write( (const char*)bufferDst.get(), have ); } while (strm.avail_out == 0); totalRead += bytesRead; diff --git a/src/eepp/system/directorypack.cpp b/src/eepp/system/directorypack.cpp index e171877a9..2b36fa16f 100644 --- a/src/eepp/system/directorypack.cpp +++ b/src/eepp/system/directorypack.cpp @@ -88,7 +88,7 @@ bool DirectoryPack::extractFileToMemory( const std::string& path, std::vector ( data.data ), data.size ); + fs.read( reinterpret_cast ( data.get() ), data.length() ); return true; } @@ -88,10 +85,8 @@ bool FileSystem::fileCopy( const std::string& src, const std::string& dst ) { Int64 allocate = ( size < chunksize ) ? size : chunksize; Int64 copysize = 0; - SafeDataPointer data; - data.size = (Uint32)allocate; - data.data = eeNewArray( Uint8, ( data.size ) ); - char * buff = (char*)data.data; + TScopedBuffer data( allocate ); + char * buff = data.get(); IOStreamFile in( src, "rb" ); IOStreamFile out( dst, "wb" ); @@ -105,7 +100,7 @@ bool FileSystem::fileCopy( const std::string& src, const std::string& dst ) { } in.read ( &buff[0], copysize ); - out.write ( (const char*)&buff[0], copysize ); + out.write ( &buff[0], copysize ); size_left -= copysize; } while ( size_left > 0 ); diff --git a/src/eepp/system/inifile.cpp b/src/eepp/system/inifile.cpp index 43720618e..66f833187 100755 --- a/src/eepp/system/inifile.cpp +++ b/src/eepp/system/inifile.cpp @@ -56,11 +56,11 @@ IniFile::IniFile( IOStream& stream, const bool& shouldReadFile ) : bool IniFile::loadFromPack( Pack * Pack, std::string iniPackPath ) { if ( NULL != Pack && Pack->isOpen() && -1 != Pack->exists( iniPackPath ) ) { - SafeDataPointer PData; + ScopedBuffer buffer; - Pack->extractFileToMemory( iniPackPath, PData ); + Pack->extractFileToMemory( iniPackPath, buffer ); - return loadFromMemory( PData.data, PData.size ); + return loadFromMemory( buffer.get(), buffer.length() ); } return false; diff --git a/src/eepp/system/iostreamdeflate.cpp b/src/eepp/system/iostreamdeflate.cpp index 9862ab702..f8c52afc3 100644 --- a/src/eepp/system/iostreamdeflate.cpp +++ b/src/eepp/system/iostreamdeflate.cpp @@ -38,24 +38,24 @@ IOStreamDeflate::~IOStreamDeflate() { if (rc != Z_OK && rc != Z_STREAM_END) return; - mStream.write((char*)mBuffer.data, mBuffer.size - zstr.avail_out); + mStream.write((char*)mBuffer.get(), mBuffer.length() - zstr.avail_out); if (!mStream.isOpen()) return; - zstr.next_out = (unsigned char*) mBuffer.data; - zstr.avail_out = mBuffer.size; + zstr.next_out = (unsigned char*) mBuffer.get(); + zstr.avail_out = mBuffer.length(); while (rc != Z_STREAM_END) { rc = deflate(&zstr, Z_FINISH); if (rc != Z_OK && rc != Z_STREAM_END) return; - mStream.write((char*)mBuffer.data, mBuffer.size - zstr.avail_out); + mStream.write((char*)mBuffer.get(), mBuffer.length() - zstr.avail_out); if (!mStream.isOpen()) return; - zstr.next_out = (unsigned char*) mBuffer.data; - zstr.avail_out = mBuffer.size; + zstr.next_out = (unsigned char*) mBuffer.get(); + zstr.avail_out = mBuffer.length(); } } } @@ -77,11 +77,11 @@ ios_size IOStreamDeflate::read(char * buffer, ios_size length) { ios_size n = 0; if ( mStream.isOpen()) { - n = mStream.read((char*)mBuffer.data, mBuffer.size); + n = mStream.read((char*)mBuffer.get(), mBuffer.length()); } if (n > 0) { - zstr.next_in = (unsigned char*) mBuffer.data; + zstr.next_in = (unsigned char*) mBuffer.get(); zstr.avail_in = n; } else { zstr.next_in = NULL; @@ -110,11 +110,11 @@ ios_size IOStreamDeflate::read(char * buffer, ios_size length) { ios_size n = 0; if (mStream.isOpen()) { - n = mStream.read((char*)mBuffer.data, mBuffer.size); + n = mStream.read((char*)mBuffer.get(), mBuffer.length()); } if (n > 0) { - zstr.next_in = (unsigned char*) mBuffer.data; + zstr.next_in = (unsigned char*) mBuffer.get(); zstr.avail_in = n; } else { zstr.next_in = NULL; @@ -135,8 +135,8 @@ ios_size IOStreamDeflate::write(const char * buffer, ios_size length) { zstr.next_in = (unsigned char*) buffer; zstr.avail_in = length; - zstr.next_out = mBuffer.data; - zstr.avail_out = mBuffer.size; + zstr.next_out = mBuffer.get(); + zstr.avail_out = mBuffer.length(); for (;;) { int rc = deflate(&zstr, Z_NO_FLUSH); @@ -145,23 +145,23 @@ ios_size IOStreamDeflate::write(const char * buffer, ios_size length) { return 0; if (zstr.avail_out == 0) { - ios_size ret = mStream.write( (const char*)mBuffer.data, mBuffer.size); + ios_size ret = mStream.write( (const char*)mBuffer.get(), mBuffer.length()); if (ret == 0) return 0; - zstr.next_out = (unsigned char*) mBuffer.data; - zstr.avail_out = mBuffer.size; + zstr.next_out = (unsigned char*) mBuffer.get(); + zstr.avail_out = mBuffer.length(); } if (zstr.avail_in == 0) { - ios_size ret = mStream.write( (const char*)mBuffer.data, mBuffer.size - zstr.avail_out); + ios_size ret = mStream.write( (const char*)mBuffer.get(), mBuffer.length() - zstr.avail_out); if (ret == 0) return 0; - zstr.next_out = (unsigned char*) mBuffer.data; - zstr.avail_out = mBuffer.size; + zstr.next_out = (unsigned char*) mBuffer.get(); + zstr.avail_out = mBuffer.length(); break; } diff --git a/src/eepp/system/iostreaminflate.cpp b/src/eepp/system/iostreaminflate.cpp index 269a1a4dc..ee6d2f176 100644 --- a/src/eepp/system/iostreaminflate.cpp +++ b/src/eepp/system/iostreaminflate.cpp @@ -42,10 +42,10 @@ ios_size IOStreamInflate::read(char * buffer, ios_size length) { ios_size n = 0; if ( mStream.isOpen()) { - n = mStream.read((char*)mBuffer.data, mBuffer.size); + n = mStream.read((char*)mBuffer.get(), mBuffer.length()); } - zstr.next_in = (unsigned char*) mBuffer.data; + zstr.next_in = (unsigned char*) mBuffer.get(); zstr.avail_in = n; } @@ -78,11 +78,11 @@ ios_size IOStreamInflate::read(char * buffer, ios_size length) { ios_size n = 0; if (mStream.isOpen()) { - n = mStream.read((char*)mBuffer.data, mBuffer.size); + n = mStream.read((char*)mBuffer.get(), mBuffer.length()); } if (n > 0) { - zstr.next_in = (unsigned char*) mBuffer.data; + zstr.next_in = (unsigned char*) mBuffer.get(); zstr.avail_in = n; } else { return length - zstr.avail_out; @@ -99,14 +99,14 @@ ios_size IOStreamInflate::write(const char * buffer, ios_size length) { zstr.next_in = (unsigned char*) buffer; zstr.avail_in = length; - zstr.next_out = mBuffer.data; - zstr.avail_out = mBuffer.size; + zstr.next_out = mBuffer.get(); + zstr.avail_out = mBuffer.length(); for (;;) { int rc = inflate(&zstr, Z_NO_FLUSH); if (rc == Z_STREAM_END) { - length = mStream.write( (const char*)mBuffer.data, mBuffer.size - zstr.avail_out); + length = mStream.write( (const char*)mBuffer.get(), mBuffer.length() - zstr.avail_out); mLocalStream->state = rc; @@ -117,23 +117,23 @@ ios_size IOStreamInflate::write(const char * buffer, ios_size length) { return 0; if (zstr.avail_out == 0) { - ios_size ret = mStream.write( (const char*)mBuffer.data, mBuffer.size); + ios_size ret = mStream.write( (const char*)mBuffer.get(), mBuffer.length()); if (ret == 0) return 0; - zstr.next_out = (unsigned char*) mBuffer.data; - zstr.avail_out = mBuffer.size; + zstr.next_out = (unsigned char*) mBuffer.get(); + zstr.avail_out = mBuffer.length(); } if (zstr.avail_in == 0) { - ios_size ret = mStream.write( (const char*)mBuffer.data, mBuffer.size - zstr.avail_out); + ios_size ret = mStream.write( (const char*)mBuffer.get(), mBuffer.length() - zstr.avail_out); if (ret == 0) return 0; - zstr.next_out = (unsigned char*) mBuffer.data; - zstr.avail_out = mBuffer.size; + zstr.next_out = (unsigned char*) mBuffer.get(); + zstr.avail_out = mBuffer.length(); break; } diff --git a/src/eepp/system/iostreamzip.cpp b/src/eepp/system/iostreamzip.cpp index f777e3364..5f61f2fca 100644 --- a/src/eepp/system/iostreamzip.cpp +++ b/src/eepp/system/iostreamzip.cpp @@ -58,8 +58,8 @@ ios_size IOStreamZip::seek( ios_size position ) { mFile = zip_fopen_index( mZip, zs.index, 0 ); if ( 0 != position ) { - SafeDataPointer ptr( position ); - read( (char*)ptr.data, position ); + ScopedBuffer ptr( position ); + read( (char*)ptr.get(), position ); } mPos = position; diff --git a/src/eepp/system/pak.cpp b/src/eepp/system/pak.cpp index 6b49350a5..2e1c713b2 100755 --- a/src/eepp/system/pak.cpp +++ b/src/eepp/system/pak.cpp @@ -133,10 +133,10 @@ bool Pak::extractFile( const std::string& path , const std::string& dest ) { Int32 Pos = exists( path ); if ( Pos != -1 ) { - SafeDataPointer data; + ScopedBuffer data; if ( extractFileToMemory( path, data ) ) { - FileSystem::fileWrite( path, data.data, data.size ); + FileSystem::fileWrite( path, data.get(), data.length() ); } Ret = true; @@ -173,7 +173,7 @@ bool Pak::extractFileToMemory( const std::string& path, std::vector& data return Ret; } -bool Pak::extractFileToMemory( const std::string& path, SafeDataPointer& data ) { +bool Pak::extractFileToMemory( const std::string& path, ScopedBuffer& data ) { if ( NULL == mPak.fs || !mPak.fs->isOpen() ) { return false; } @@ -185,11 +185,10 @@ bool Pak::extractFileToMemory( const std::string& path, SafeDataPointer& data ) Int32 Pos = exists( path ); if ( Pos != -1 ) { - data.size = mPakFiles[Pos].file_length; - data.data = eeNewArray( Uint8, ( data.size ) ); + data.reset( mPakFiles[Pos].file_length ); mPak.fs->seek( mPakFiles[Pos].file_position ); - mPak.fs->read( reinterpret_cast ( data.data ), mPakFiles[Pos].file_length ); + mPak.fs->read( reinterpret_cast ( data.get() ), data.length() ); Ret = true; } @@ -279,11 +278,11 @@ bool Pak::addFile( const std::string& path, const std::string& inpack ) { if ( path.size() > 56 ) return false; - SafeDataPointer file; + ScopedBuffer file; FileSystem::fileGet( path, file ); - return addFile( file.data, file.size, inpack ); + return addFile( file.get(), file.length(), inpack ); } bool Pak::addFiles( std::map paths ) { diff --git a/src/eepp/system/rc4.cpp b/src/eepp/system/rc4.cpp index 345dbb08c..200064fed 100644 --- a/src/eepp/system/rc4.cpp +++ b/src/eepp/system/rc4.cpp @@ -72,13 +72,13 @@ bool RC4::encryptFile( const std::string& SourceFile, const std::string& DestFil if ( !FileSystem::fileExists( SourceFile ) ) return false; - SafeDataPointer data; + ScopedBuffer data; FileSystem::fileGet( SourceFile, data ); - encryptByte( data.data, data.size ); + encryptByte( data.get(), data.length() ); - FileSystem::fileWrite( DestFile, data.data, data.size ); + FileSystem::fileWrite( DestFile, data.get(), data.length() ); return true; } diff --git a/src/eepp/system/translator.cpp b/src/eepp/system/translator.cpp index ceff51e46..06efba65d 100644 --- a/src/eepp/system/translator.cpp +++ b/src/eepp/system/translator.cpp @@ -114,11 +114,11 @@ void Translator::loadFromStream( IOStream& stream, std::string lang ) { return; ios_size bufferSize = stream.getSize(); - SafeDataPointer safeDataPointer( bufferSize ); - stream.read( reinterpret_cast( safeDataPointer.data ), safeDataPointer.size ); + TScopedBuffer scopedBuffer( bufferSize ); + stream.read( scopedBuffer.get(), scopedBuffer.length() ); pugi::xml_document doc; - pugi::xml_parse_result result = doc.load_buffer( safeDataPointer.data, safeDataPointer.size ); + pugi::xml_parse_result result = doc.load_buffer( scopedBuffer.get(), scopedBuffer.length() ); if ( result ) { loadNodes( doc.first_child(), lang ); @@ -130,12 +130,12 @@ void Translator::loadFromStream( IOStream& stream, std::string lang ) { } void Translator::loadFromPack( Pack * pack, const std::string& FilePackPath, std::string lang ) { - SafeDataPointer PData; + ScopedBuffer buffer; - if ( pack->isOpen() && pack->extractFileToMemory( FilePackPath, PData ) ) { + if ( pack->isOpen() && pack->extractFileToMemory( FilePackPath, buffer ) ) { lang = lang.size() == 2 ? lang : FileSystem::fileRemoveExtension( FileSystem::fileNameFromPath( FilePackPath ) ); - loadFromMemory( PData.data, PData.size, lang ); + loadFromMemory( buffer.get(), buffer.length(), lang ); } } diff --git a/src/eepp/system/zip.cpp b/src/eepp/system/zip.cpp index b94a01f3b..f2bc5fada 100644 --- a/src/eepp/system/zip.cpp +++ b/src/eepp/system/zip.cpp @@ -80,11 +80,11 @@ bool Zip::close() { } bool Zip::addFile( const std::string& path, const std::string& inpack ) { - SafeDataPointer file; + ScopedBuffer file; FileSystem::fileGet( path, file ); - return addFile( file.data, file.size, inpack ); + return addFile( file.get(), file.length(), inpack ); } bool Zip::addFile( const Uint8 * data, const Uint32& dataSize, const std::string& inpack ) { @@ -148,12 +148,12 @@ bool Zip::extractFile( const std::string& path , const std::string& dest ) { bool Ret; - SafeDataPointer data; + ScopedBuffer data; Ret = extractFileToMemory( path, data ); if ( Ret ) - FileSystem::fileWrite( dest, data.data, data.size ); + FileSystem::fileWrite( dest, data.get(), data.length() ); unlock(); @@ -194,7 +194,7 @@ bool Zip::extractFileToMemory( const std::string& path, std::vector& data return Ret; } -bool Zip::extractFileToMemory( const std::string& path, SafeDataPointer& data ) { +bool Zip::extractFileToMemory( const std::string& path, ScopedBuffer& data ) { lock(); bool Ret = false; @@ -210,10 +210,9 @@ bool Zip::extractFileToMemory( const std::string& path, SafeDataPointer& data ) struct zip_file * zf = zip_fopen_index( mZip, zs.index, 0 ); if ( NULL != zf ) { - data.size = (Uint32)zs.size; - data.data = eeNewArray( Uint8, ( data.size ) ); + data.reset( zs.size ); - Result = (Int32)zip_fread( zf, (void*)data.data, data.size ); + Result = (Int32)zip_fread( zf, (void*)data.get(), data.length() ); zip_fclose(zf); diff --git a/src/eepp/ui/css/stylesheetparser.cpp b/src/eepp/ui/css/stylesheetparser.cpp index 529b6a448..2c33b8831 100644 --- a/src/eepp/ui/css/stylesheetparser.cpp +++ b/src/eepp/ui/css/stylesheetparser.cpp @@ -42,10 +42,10 @@ bool StyleSheetParser::loadFromPack( Pack * pack, std::string filePackPath ) { bool Ret = false; - SafeDataPointer PData; + ScopedBuffer buffer; - if ( pack->isOpen() && pack->extractFileToMemory( filePackPath, PData ) ) { - Ret = loadFromMemory( PData.data, PData.size ); + if ( pack->isOpen() && pack->extractFileToMemory( filePackPath, buffer ) ) { + Ret = loadFromMemory( buffer.get(), buffer.length() ); } return Ret; diff --git a/src/eepp/ui/uimenu.cpp b/src/eepp/ui/uimenu.cpp index c6876a85c..e88a8c8d0 100644 --- a/src/eepp/ui/uimenu.cpp +++ b/src/eepp/ui/uimenu.cpp @@ -259,7 +259,7 @@ void UIMenu::insert( UINode * Control, const Uint32& Index ) { bool UIMenu::isSubMenu( Node * Ctrl ) { for ( Uint32 i = 0; i < mItems.size(); i++ ) { - if ( mItems[i]->isType( UI_TYPE_MENUSUBMENU ) ) { + if ( NULL != mItems[i] && mItems[i]->isType( UI_TYPE_MENUSUBMENU ) ) { UIMenuSubMenu * tMenu = reinterpret_cast ( mItems[i] ); if ( tMenu->getSubMenu() == Ctrl ) diff --git a/src/eepp/ui/uiscenenode.cpp b/src/eepp/ui/uiscenenode.cpp index 74655dbce..cc454ee3c 100644 --- a/src/eepp/ui/uiscenenode.cpp +++ b/src/eepp/ui/uiscenenode.cpp @@ -209,11 +209,11 @@ UIWidget * UISceneNode::loadLayoutFromStream( IOStream& stream, Node * parent ) return NULL; ios_size bufferSize = stream.getSize(); - SafeDataPointer safeDataPointer( eeNewArray( Uint8, bufferSize ), bufferSize ); - stream.read( reinterpret_cast( safeDataPointer.data ), safeDataPointer.size ); + TScopedBuffer scopedBuffer( bufferSize ); + stream.read( scopedBuffer.get(), scopedBuffer.length() ); pugi::xml_document doc; - pugi::xml_parse_result result = doc.load_buffer( safeDataPointer.data, safeDataPointer.size ); + pugi::xml_parse_result result = doc.load_buffer( scopedBuffer.get(), scopedBuffer.length() ); if ( result ) { return loadLayoutNodes( doc.first_child(), NULL != parent ? parent : this ); @@ -227,10 +227,10 @@ UIWidget * UISceneNode::loadLayoutFromStream( IOStream& stream, Node * parent ) } UIWidget * UISceneNode::loadLayoutFromPack( Pack * pack, const std::string& FilePackPath, Node * parent ) { - SafeDataPointer PData; + ScopedBuffer buffer; - if ( pack->isOpen() && pack->extractFileToMemory( FilePackPath, PData ) ) { - return loadLayoutFromMemory( PData.data, PData.size, parent ); + if ( pack->isOpen() && pack->extractFileToMemory( FilePackPath, buffer ) ) { + return loadLayoutFromMemory( buffer.get(), buffer.length(), parent ); } return NULL;