From: Anton Obzhirov Date: Wed, 10 Jul 2019 08:35:09 +0000 (+0100) Subject: Use FileStream API in demo. X-Git-Tag: dali_1.4.28~1^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-demo.git;a=commitdiff_plain;h=3ed8a2ec80028af2772bb63b007f3c406e550391 Use FileStream API in demo. Change-Id: I6d738a54558b5adced956917f9f0de3d6fa2b0d7 --- diff --git a/examples/fpp-game/game-utils.cpp b/examples/fpp-game/game-utils.cpp index 12ac001..1f3f502 100644 --- a/examples/fpp-game/game-utils.cpp +++ b/examples/fpp-game/game-utils.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include "game-utils.h" @@ -26,32 +26,25 @@ namespace GameUtils { bool LoadFile( const char* filename, ByteArray& bytes ) { - std::streampos bufferSize = 0; - Dali::Vector fileBuffer; - if( !Dali::FileLoader::ReadFile( filename, bufferSize, fileBuffer, Dali::FileLoader::FileType::BINARY ) ) - { - return false; - } + Dali::FileStream fileStream( filename, Dali::FileStream::READ | Dali::FileStream::BINARY ); + FILE* fin = fileStream.GetFile(); - FILE* fin = fmemopen( &fileBuffer[0], bufferSize, "rb" ); if( fin ) { if( fseek( fin, 0, SEEK_END ) ) { - fclose(fin); return false; } bytes.resize( ftell( fin ) ); std::fill( bytes.begin(), bytes.end(), 0 ); if( fseek( fin, 0, SEEK_SET ) ) { - fclose( fin ); return false; } size_t result = fread( bytes.data(), 1, bytes.size(), fin ); - fclose( fin ); return ( result != 0 ); } + return false; } diff --git a/examples/ray-marching/ray-marching-example.cpp b/examples/ray-marching/ray-marching-example.cpp index 4a6f7a3..2a7b959 100644 --- a/examples/ray-marching/ray-marching-example.cpp +++ b/examples/ray-marching/ray-marching-example.cpp @@ -21,7 +21,7 @@ #include "shared/utility.h" #include #include -#include +#include using namespace Dali; using Dali::Toolkit::TextLabel; @@ -44,17 +44,15 @@ bool LoadShaderCode( const char* path, const char* filename, std::vector& std::string fullpath( path ); fullpath += filename; - std::streampos bufferSize = 0; - Dali::Vector fileBuffer; - if( !Dali::FileLoader::ReadFile( fullpath, bufferSize, fileBuffer, Dali::FileLoader::FileType::BINARY ) ) + Dali::FileStream fileStream( fullpath, Dali::FileStream::READ | Dali::FileStream::BINARY ); + FILE* file = fileStream.GetFile(); + if( !file ) { return false; } - FILE* file = fmemopen( &fileBuffer[0], bufferSize, "rb" ); - bool retValue = false; - if( ! fseek( file, 0, SEEK_END ) ) + if( !fseek( file, 0, SEEK_END ) ) { long int size = ftell( file ); @@ -69,7 +67,6 @@ bool LoadShaderCode( const char* path, const char* filename, std::vector& } } - fclose( file ); return retValue; } diff --git a/examples/rendering-basic-pbr/ktx-loader.cpp b/examples/rendering-basic-pbr/ktx-loader.cpp index 627d74b..579724e 100644 --- a/examples/rendering-basic-pbr/ktx-loader.cpp +++ b/examples/rendering-basic-pbr/ktx-loader.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include namespace PbrDemo { @@ -94,14 +94,8 @@ bool ConvertPixelFormat(const uint32_t ktxPixelFormat, Dali::Pixel::Format& form bool LoadCubeMapFromKtxFile( const std::string& path, CubeData& cubedata ) { - std::streampos bufferSize = 0; - Dali::Vector fileBuffer; - if( !Dali::FileLoader::ReadFile( path, bufferSize, fileBuffer, FileLoader::FileType::BINARY ) ) - { - return false; - } - - FILE* fp = fmemopen( &fileBuffer[0], bufferSize, "rb" ); + Dali::FileStream fileStream( path, Dali::FileStream::READ | Dali::FileStream::BINARY ); + FILE* fp = fileStream.GetFile(); if( NULL == fp ) { return false; @@ -112,7 +106,6 @@ bool LoadCubeMapFromKtxFile( const std::string& path, CubeData& cubedata ) int result = fread(&header,1,sizeof(KtxFileHeader),fp); if( 0 == result ) { - fclose( fp ); return false; } @@ -123,14 +116,12 @@ bool LoadCubeMapFromKtxFile( const std::string& path, CubeData& cubedata ) if( fseek(fp, imageSizeOffset, SEEK_END) ) { - fclose( fp ); return false; } lSize = ftell(fp); if( lSize == -1L ) { - fclose( fp ); return false; } @@ -138,7 +129,6 @@ bool LoadCubeMapFromKtxFile( const std::string& path, CubeData& cubedata ) if( fseek(fp, imageSizeOffset, SEEK_SET) ) { - fclose( fp ); return false; } diff --git a/examples/rendering-basic-pbr/rendering-basic-pbr-example.cpp b/examples/rendering-basic-pbr/rendering-basic-pbr-example.cpp index 2d3a001..1239401 100644 --- a/examples/rendering-basic-pbr/rendering-basic-pbr-example.cpp +++ b/examples/rendering-basic-pbr/rendering-basic-pbr-example.cpp @@ -26,7 +26,7 @@ #include "model-skybox.h" #include "model-pbr.h" #include -#include +#include using namespace Dali; using namespace Toolkit; @@ -392,15 +392,8 @@ public: */ bool LoadShaderCode( const std::string& fullpath, std::vector& output ) { - std::streampos bufferSize = 0; - Dali::Vector fileBuffer; - if( !Dali::FileLoader::ReadFile( fullpath, bufferSize, fileBuffer, FileLoader::FileType::BINARY ) ) - { - DALI_LOG_WARNING( "file open failed for: \"%s\"", fullpath ); - return false; - } - - FILE* file = fmemopen( &fileBuffer[0], bufferSize, "rb" ); + Dali::FileStream fileStream( fullpath, FileStream::READ | FileStream::BINARY ); + FILE* file = fileStream.GetFile(); if( NULL == file ) { return false; @@ -421,7 +414,7 @@ public: retValue = ( result >= 0 ); } } - fclose( file ); + return retValue; }