mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-06-04 20:46:29 +03:00
Renamed TSafeDataPointer to TScopedBuffer.
--HG-- branch : dev
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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