From: Anton Obzhirov Date: Wed, 3 Jul 2019 14:01:53 +0000 (+0100) Subject: All file read operations should be done through FileLoader. X-Git-Tag: dali_1.4.28~5 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-demo.git;a=commitdiff_plain;h=refs%2Fchanges%2F29%2F209229%2F3 All file read operations should be done through FileLoader. Change-Id: I2078c71affd10d5bcf57c606effd95ae1bc79bd4 --- diff --git a/builder/dali-builder.cpp b/builder/dali-builder.cpp index 4481c3d..5445fd1 100644 --- a/builder/dali-builder.cpp +++ b/builder/dali-builder.cpp @@ -27,6 +27,7 @@ //------------------------------------------------------------------------------ #include +#include #include #include #include @@ -102,10 +103,16 @@ private: std::time_t mLastTime; std::string mstringPath; - std::string GetFileContents(const std::string &fn) + std::string GetFileContents(const std::string &filename) { - std::ifstream t(fn.c_str()); - return std::string((std::istreambuf_iterator(t)), std::istreambuf_iterator()); + std::streampos bufferSize = 0; + Dali::Vector fileBuffer; + if( !Dali::FileLoader::ReadFile( filename, bufferSize, fileBuffer, FileLoader::FileType::BINARY ) ) + { + return std::string(); + } + + return std::string( &fileBuffer[0], bufferSize ); }; }; diff --git a/examples/builder/examples.cpp b/examples/builder/examples.cpp index ba47e28..e022227 100644 --- a/examples/builder/examples.cpp +++ b/examples/builder/examples.cpp @@ -43,6 +43,7 @@ #include #include +#include #include "shared/view.h" #define TOKEN_STRING(x) #x @@ -86,9 +87,14 @@ std::string ReplaceQuotes(const std::string &single_quoted) std::string GetFileContents(const std::string &fn) { - std::ifstream t(fn.c_str()); - return std::string((std::istreambuf_iterator(t)), - std::istreambuf_iterator()); + std::streampos bufferSize = 0; + Dali::Vector fileBuffer; + if( !Dali::FileLoader::ReadFile( fn, bufferSize, fileBuffer, FileLoader::FileType::BINARY ) ) + { + return std::string(); + } + + return std::string( &fileBuffer[0], bufferSize ); }; typedef std::vector FileList; diff --git a/examples/fpp-game/game-utils.cpp b/examples/fpp-game/game-utils.cpp index 8cb99f1..12ac001 100644 --- a/examples/fpp-game/game-utils.cpp +++ b/examples/fpp-game/game-utils.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2019 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,8 @@ #include #include +#include +#include #include "game-utils.h" @@ -24,7 +26,14 @@ namespace GameUtils { bool LoadFile( const char* filename, ByteArray& bytes ) { - FILE* fin = fopen( filename, "rb" ); + std::streampos bufferSize = 0; + Dali::Vector fileBuffer; + if( !Dali::FileLoader::ReadFile( filename, bufferSize, fileBuffer, Dali::FileLoader::FileType::BINARY ) ) + { + return false; + } + + FILE* fin = fmemopen( &fileBuffer[0], bufferSize, "rb" ); if( fin ) { if( fseek( fin, 0, SEEK_END ) ) diff --git a/examples/ray-marching/ray-marching-example.cpp b/examples/ray-marching/ray-marching-example.cpp index d638217..4a6f7a3 100644 --- a/examples/ray-marching/ray-marching-example.cpp +++ b/examples/ray-marching/ray-marching-example.cpp @@ -20,6 +20,8 @@ #include "shared/view.h" #include "shared/utility.h" #include +#include +#include using namespace Dali; using Dali::Toolkit::TextLabel; @@ -41,12 +43,16 @@ bool LoadShaderCode( const char* path, const char* filename, std::vector& { std::string fullpath( path ); fullpath += filename; - FILE* file = fopen( fullpath.c_str(), "rb" ); - if( ! file ) + + std::streampos bufferSize = 0; + Dali::Vector fileBuffer; + if( !Dali::FileLoader::ReadFile( fullpath, bufferSize, fileBuffer, Dali::FileLoader::FileType::BINARY ) ) { return false; } + FILE* file = fmemopen( &fileBuffer[0], bufferSize, "rb" ); + bool retValue = false; if( ! fseek( file, 0, SEEK_END ) ) { diff --git a/examples/refraction-effect/refraction-effect-example.cpp b/examples/refraction-effect/refraction-effect-example.cpp index 14c4878..ffbc59a 100644 --- a/examples/refraction-effect/refraction-effect-example.cpp +++ b/examples/refraction-effect/refraction-effect-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2019 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,8 +19,9 @@ #include #include #include +#include +#include -#include #include #include @@ -471,14 +472,22 @@ private: std::vector& vertexPositions, Vector& faceIndices) { - std::ifstream ifs( objFileName.c_str(), std::ios::in ); + std::streampos bufferSize = 0; + Dali::Vector fileBuffer; + if( !Dali::FileLoader::ReadFile( objFileName, bufferSize, fileBuffer, Dali::FileLoader::FileType::TEXT ) ) + { + DALI_LOG_WARNING( "file open failed for: \"%s\"", objFileName ); + return; + } + + std::stringstream iss( &fileBuffer[0], std::ios::in ); boundingBox.Resize( 6 ); boundingBox[0]=boundingBox[2]=boundingBox[4] = std::numeric_limits::max(); boundingBox[1]=boundingBox[3]=boundingBox[5] = -std::numeric_limits::max(); std::string line; - while( std::getline( ifs, line ) ) + while( std::getline( iss, line ) ) { if( line[0] == 'v' && std::isspace(line[1])) // vertex { @@ -518,8 +527,6 @@ private: faceIndices.PushBack( indices[2*step]-1 ); } } - - ifs.close(); } void ShapeResizeAndTexureCoordinateCalculation( const Vector& boundingBox, diff --git a/examples/rendering-basic-pbr/ktx-loader.cpp b/examples/rendering-basic-pbr/ktx-loader.cpp index 175d6c3..627d74b 100644 --- a/examples/rendering-basic-pbr/ktx-loader.cpp +++ b/examples/rendering-basic-pbr/ktx-loader.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2019 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,8 @@ #include #include #include +#include +#include namespace PbrDemo { @@ -92,8 +94,14 @@ bool ConvertPixelFormat(const uint32_t ktxPixelFormat, Dali::Pixel::Format& form bool LoadCubeMapFromKtxFile( const std::string& path, CubeData& cubedata ) { - FILE* fp = fopen(path.c_str(),"rb"); + 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" ); if( NULL == 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 931f5fb..9d2a9d1 100644 --- a/examples/rendering-basic-pbr/rendering-basic-pbr-example.cpp +++ b/examples/rendering-basic-pbr/rendering-basic-pbr-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2019 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,8 @@ #include "ktx-loader.h" #include "model-skybox.h" #include "model-pbr.h" +#include +#include using namespace Dali; using namespace Toolkit; @@ -390,7 +392,15 @@ public: */ bool LoadShaderCode( const std::string& fullpath, std::vector& output ) { - FILE* file = fopen( fullpath.c_str(), "rb" ); + 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\"", path ); + return false; + } + + FILE* file = fmemopen( &fileBuffer[0], bufferSize, "rb" ); if( NULL == file ) { return false; diff --git a/examples/simple-text-renderer/simple-text-renderer-example.cpp b/examples/simple-text-renderer/simple-text-renderer-example.cpp index 3f8116f..c980170 100644 --- a/examples/simple-text-renderer/simple-text-renderer-example.cpp +++ b/examples/simple-text-renderer/simple-text-renderer-example.cpp @@ -26,9 +26,6 @@ #include #include -#include -#include - using namespace std; using namespace Dali; using namespace Dali::Toolkit;