mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-10-26 16:17:57 +03:00
Renamed TSafeDataPointer to TScopedBuffer.
--HG-- branch : dev
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
#include <eepp/audio/inputsoundfile.hpp>
|
||||
#include <eepp/system/mutex.hpp>
|
||||
#include <eepp/system/time.hpp>
|
||||
#include <eepp/system/safedatapointer.hpp>
|
||||
#include <eepp/system/scopedbuffer.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -239,7 +239,7 @@ class EE_API Music : public SoundStream
|
||||
std::vector<Int16> mSamples; ///< Temporary buffer of samples
|
||||
Mutex mMutex; ///< Mutex protecting the data
|
||||
Span<Uint64> mLoopSpan; ///< Loop Range Specifier
|
||||
SafeDataPointer mData;
|
||||
ScopedBuffer mData;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
@@ -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<Uint8> mPixelBuffer; ///< Pixel buffer holding a glyph's pixels before being written to the texture
|
||||
|
||||
@@ -52,7 +52,7 @@ class EE_API DirectoryPack : public Pack {
|
||||
bool extractFileToMemory( const std::string& path, std::vector<Uint8>& 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 );
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <eepp/core.hpp>
|
||||
#include <eepp/system/safedatapointer.hpp>
|
||||
#include <eepp/system/scopedbuffer.hpp>
|
||||
|
||||
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
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define EE_SYSTEM_IOSTREAMDEFLATE_HPP
|
||||
|
||||
#include <eepp/system/iostream.hpp>
|
||||
#include <eepp/system/safedatapointer.hpp>
|
||||
#include <eepp/system/scopedbuffer.hpp>
|
||||
#include <eepp/system/compression.hpp>
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define EE_SYSTEM_IOSTREAMINFLATE_HPP
|
||||
|
||||
#include <eepp/system/iostream.hpp>
|
||||
#include <eepp/system/safedatapointer.hpp>
|
||||
#include <eepp/system/scopedbuffer.hpp>
|
||||
#include <eepp/system/compression.hpp>
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define EE_SYSTEMCPACK_HPP
|
||||
|
||||
#include <eepp/system/mutex.hpp>
|
||||
#include <eepp/system/safedatapointer.hpp>
|
||||
#include <eepp/system/scopedbuffer.hpp>
|
||||
#include <eepp/system/iostream.hpp>
|
||||
|
||||
namespace EE { namespace System {
|
||||
@@ -52,7 +52,7 @@ class EE_API Pack : protected Mutex {
|
||||
virtual bool extractFileToMemory( const std::string& path, std::vector<Uint8>& 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;
|
||||
|
||||
@@ -53,7 +53,7 @@ class EE_API Pak : public Pack {
|
||||
bool extractFileToMemory( const std::string& path, std::vector<Uint8>& 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 );
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
#ifndef EE_SYSTEM_SAFEDATAPOINTER
|
||||
#define EE_SYSTEM_SAFEDATAPOINTER
|
||||
|
||||
#include <eepp/config.hpp>
|
||||
#include <eepp/core/memorymanager.hpp>
|
||||
#include <cstddef>
|
||||
|
||||
namespace EE { namespace System {
|
||||
|
||||
/** @brief Keep a pointer and release it in the SafeDataPointer destructor */
|
||||
template <typename T>
|
||||
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 <typename T>
|
||||
TSafeDataPointer<T>::TSafeDataPointer() :
|
||||
data( NULL ),
|
||||
size( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
TSafeDataPointer<T>::TSafeDataPointer( Uint32 size ) :
|
||||
data( eeNewArray( T, size ) ),
|
||||
size( size )
|
||||
{
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
TSafeDataPointer<T>::TSafeDataPointer( T * data, Uint32 size ) :
|
||||
data( data ),
|
||||
size( size )
|
||||
{
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
TSafeDataPointer<T>::~TSafeDataPointer() {
|
||||
clear();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void TSafeDataPointer<T>::clear() {
|
||||
eeSAFE_DELETE_ARRAY( data );
|
||||
}
|
||||
|
||||
typedef TSafeDataPointer<Uint8> SafeDataPointer;
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,153 @@
|
||||
#ifndef EE_SYSTEM_SCOPEDBUFFER
|
||||
#define EE_SYSTEM_SCOPEDBUFFER
|
||||
|
||||
#include <eepp/config.hpp>
|
||||
#include <eepp/core/memorymanager.hpp>
|
||||
#include <eepp/core/debug.hpp>
|
||||
#include <eepp/core/noncopyable.hpp>
|
||||
#include <cstddef>
|
||||
|
||||
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 <typename T>
|
||||
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<T>& 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 <typename T>
|
||||
TScopedBuffer<T>::TScopedBuffer() :
|
||||
mData( NULL ),
|
||||
mSize( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
TScopedBuffer<T>::TScopedBuffer( std::size_t length ) :
|
||||
mData( eeNewArray( T, length ) ),
|
||||
mSize( length )
|
||||
{
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
TScopedBuffer<T>::TScopedBuffer( T * data, std::size_t length ) :
|
||||
mData( data ),
|
||||
mSize( length )
|
||||
{
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
TScopedBuffer<T>::~TScopedBuffer() {
|
||||
clear();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void TScopedBuffer<T>::clear() {
|
||||
eeSAFE_DELETE_ARRAY( mData );
|
||||
mSize = 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T& TScopedBuffer<T>::operator[]( std::size_t i ) const {
|
||||
eeASSERT( i < mSize && NULL != mData );
|
||||
return mData[i];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool TScopedBuffer<T>::operator()() const {
|
||||
return NULL != mData;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T * TScopedBuffer<T>::get() const {
|
||||
return mData;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const std::size_t& TScopedBuffer<T>::size() const {
|
||||
return mSize;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const std::size_t& TScopedBuffer<T>::length() const {
|
||||
return mSize;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool TScopedBuffer<T>::isEmpty() const {
|
||||
return mData == NULL;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void TScopedBuffer<T>::swap(TScopedBuffer<T>& b) {
|
||||
std::swap(mData, b.mData);
|
||||
std::swap(mSize, b.mSize);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void TScopedBuffer<T>::reset(T * p, const std::size_t& size) {
|
||||
eeASSERT( p == 0 || p != mData );
|
||||
clear();
|
||||
mData = p;
|
||||
mSize = size;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void TScopedBuffer<T>::reset(const std::size_t& size) {
|
||||
clear();
|
||||
mData = eeNewArray( T, ( size ) );
|
||||
mSize = size;
|
||||
}
|
||||
|
||||
typedef TScopedBuffer<Uint8> ScopedBuffer;
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
@@ -51,7 +51,7 @@ class EE_API Zip : public Pack {
|
||||
bool extractFileToMemory( const std::string& path, std::vector<Uint8>& 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 );
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<const char*> ( mData.data ), mData.size );
|
||||
return openFromMemory( reinterpret_cast<const char*> ( mData.get() ), mData.length() );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <eepp/audio/alcheck.hpp>
|
||||
#include <eepp/core/debug.hpp>
|
||||
#include <eepp/system/pack.hpp>
|
||||
#include <eepp/system/safedatapointer.hpp>
|
||||
#include <eepp/system/scopedbuffer.hpp>
|
||||
#include <eepp/system/pack.hpp>
|
||||
#include <eepp/system/filesystem.hpp>
|
||||
#include <eepp/system/packmanager.hpp>
|
||||
@@ -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<const char*> ( PData.data ), PData.size );
|
||||
if ( pack->isOpen() && pack->extractFileToMemory( filePackPath, buffer ) )
|
||||
Ret = loadFromMemory( reinterpret_cast<const char*> ( buffer.get() ), buffer.length() );
|
||||
|
||||
return Ret;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <eepp/audio/mp3info.hpp>
|
||||
#include <eepp/system/safedatapointer.hpp>
|
||||
#include <eepp/system/scopedbuffer.hpp>
|
||||
|
||||
static size_t drmp3_func_read(void* data, void* ptr, size_t size) {
|
||||
IOStream* stream = static_cast<IOStream*>(data);
|
||||
@@ -73,15 +73,15 @@ Uint64 SoundFileReaderMp3::read(Int16* samples, Uint64 maxCount) {
|
||||
while (count < maxCount) {
|
||||
const int samplesToRead = static_cast<int>(maxCount - count);
|
||||
int frames = samplesToRead / mChannelCount;
|
||||
TSafeDataPointer<float> rSamples( samplesToRead );
|
||||
TScopedBuffer<float> 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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
+24
-24
@@ -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() );
|
||||
}
|
||||
|
||||
@@ -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<char*> ( PData.data ), PData.size );
|
||||
setSource( reinterpret_cast<char*> ( 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<char*> ( PData.data ), PData.size );
|
||||
setSource( reinterpret_cast<char*> ( buffer.get() ), buffer.length() );
|
||||
}
|
||||
|
||||
compile();
|
||||
|
||||
@@ -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<const Uint8*> ( PData.data ), PData.size, FilePackPath );
|
||||
loadFromMemory( buffer.get(), buffer.length(), FilePackPath );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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<const char*> ( PData.data ), PData.size );
|
||||
return loadFromMemory( reinterpret_cast<const char*> ( buffer.get() ), buffer.length() );
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -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 ];
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <eepp/system/compression.hpp>
|
||||
#include <eepp/system/safedatapointer.hpp>
|
||||
#include <eepp/system/scopedbuffer.hpp>
|
||||
#include <eepp/system/iostreammemory.hpp>
|
||||
#include <eepp/core/debug.hpp>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -88,7 +88,7 @@ bool DirectoryPack::extractFileToMemory( const std::string& path, std::vector<Ui
|
||||
return FileSystem::fileGet( mPath + path, data );
|
||||
}
|
||||
|
||||
bool DirectoryPack::extractFileToMemory( const std::string& path, SafeDataPointer& data ) {
|
||||
bool DirectoryPack::extractFileToMemory( const std::string& path, ScopedBuffer& data ) {
|
||||
return FileSystem::fileGet( mPath + path, data );
|
||||
}
|
||||
|
||||
|
||||
@@ -47,16 +47,13 @@ std::string FileSystem::getOSSlash() {
|
||||
#endif
|
||||
}
|
||||
|
||||
bool FileSystem::fileGet( const std::string& path, SafeDataPointer& data ) {
|
||||
bool FileSystem::fileGet( const std::string& path, ScopedBuffer& data ) {
|
||||
if ( fileExists( path ) ) {
|
||||
IOStreamFile fs ( path );
|
||||
|
||||
eeSAFE_DELETE( data.data );
|
||||
data.reset( fileSize( path ) );
|
||||
|
||||
data.size = fileSize( path );
|
||||
data.data = eeNewArray( Uint8, ( data.size ) );
|
||||
|
||||
fs.read( reinterpret_cast<char*> ( data.data ), data.size );
|
||||
fs.read( reinterpret_cast<char*> ( 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<char> 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 );
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<Uint8>& 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<char*> ( data.data ), mPakFiles[Pos].file_length );
|
||||
mPak.fs->read( reinterpret_cast<char*> ( 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<std::string, std::string> paths ) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<char*>( safeDataPointer.data ), safeDataPointer.size );
|
||||
TScopedBuffer<char> 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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Uint8>& 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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<UIMenuSubMenu*> ( mItems[i] );
|
||||
|
||||
if ( tMenu->getSubMenu() == Ctrl )
|
||||
|
||||
@@ -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<char*>( safeDataPointer.data ), safeDataPointer.size );
|
||||
TScopedBuffer<char> 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;
|
||||
|
||||
Reference in New Issue
Block a user