From: Anton Obzhirov Date: Tue, 2 Jul 2019 16:07:37 +0000 (+0100) Subject: All file read operations should be done through FileLoader. X-Git-Tag: dali_1.4.28~6 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=d8b52fede008a48f35867f059f3385dbde63bf22 All file read operations should be done through FileLoader. Change-Id: I3c5cd1a538efb1863aaf6e6f6b349e8619452169 --- diff --git a/automated-tests/src/dali-toolkit-styling/CMakeLists.txt b/automated-tests/src/dali-toolkit-styling/CMakeLists.txt index 58225f0..68bbd23 100644 --- a/automated-tests/src/dali-toolkit-styling/CMakeLists.txt +++ b/automated-tests/src/dali-toolkit-styling/CMakeLists.txt @@ -21,7 +21,6 @@ LIST(APPEND TC_SOURCES ../dali-toolkit/dali-toolkit-test-utils/toolkit-event-thread-callback.cpp ../dali-toolkit/dali-toolkit-test-utils/toolkit-environment-variable.cpp ../dali-toolkit/dali-toolkit-test-utils/toolkit-feedback-player.cpp - ../dali-toolkit/dali-toolkit-test-utils/toolkit-file-loader.cpp ../dali-toolkit/dali-toolkit-test-utils/toolkit-input-method-context.cpp ../dali-toolkit/dali-toolkit-test-utils/toolkit-lifecycle-controller.cpp ../dali-toolkit/dali-toolkit-test-utils/toolkit-native-image-source.cpp diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-file-loader.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-file-loader.cpp deleted file mode 100644 index d1611c7..0000000 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-file-loader.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2018 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -namespace Dali -{ - -namespace FileLoader -{ - -int ReadFile( - const std::string& filename, - Dali::Vector & memblock, - FileLoader::FileType fileType) -{ - return 0; -} - -int ReadFile( - const std::string& filename, - std::streampos& fileSize, - Dali::Vector & memblock, - FileLoader::FileType fileType) -{ - return 0; -} - -std::streampos GetFileSize(const std::string& filename) -{ - return 0; -} - -} -} diff --git a/dali-toolkit/internal/builder/builder-filesystem.h b/dali-toolkit/internal/builder/builder-filesystem.h index 75e9d28..947f8ce 100755 --- a/dali-toolkit/internal/builder/builder-filesystem.h +++ b/dali-toolkit/internal/builder/builder-filesystem.h @@ -27,6 +27,8 @@ #include #include +#include + inline std::string ExpandPath(const std::string &name) { wordexp_t p; @@ -54,8 +56,14 @@ inline std::string ExePath(void) inline 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, Dali::FileLoader::FileType::BINARY ) ) + { + return std::string(); + } + + return std::string( &fileBuffer[0], bufferSize ); } #endif // DALI_TOOLKIT_INTERNAL_BUILDER_FILESYSTEM_H diff --git a/dali-toolkit/internal/controls/scene3d-view/gltf-loader.cpp b/dali-toolkit/internal/controls/scene3d-view/gltf-loader.cpp index 4115fb7..e1d9d34 100644 --- a/dali-toolkit/internal/controls/scene3d-view/gltf-loader.cpp +++ b/dali-toolkit/internal/controls/scene3d-view/gltf-loader.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 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. @@ -20,7 +20,6 @@ #include // EXTERNAL INCLUDES -#include #include #include #include @@ -237,12 +236,15 @@ void FitBuffer( Dali::Vector& bufferDestination, Dali::Vector& buffe template bool ReadBinFile( Vector &dataBuffer, std::string url, int32_t offset, int32_t count ) { - dataBuffer.Resize( count ); - FILE* fp = fopen( url.c_str(), "rb" ); - if( fp == NULL ) + std::streampos bufferSize = 0; + Dali::Vector fileBuffer; + if( !Dali::FileLoader::ReadFile( url, bufferSize, fileBuffer, FileLoader::FileType::BINARY ) ) { return false; } + + FILE* fp = fmemopen( &fileBuffer[0], bufferSize, "rb" ); + dataBuffer.Resize( count ); ssize_t result = -1; if( !fseek( fp, offset, SEEK_SET ) ) { @@ -1228,11 +1230,16 @@ bool Loader::LoadScene( const std::string& filePath, Internal::Scene3dView& scen bool Loader::ParseGltf( const std::string& filePath ) { - std::ifstream fileStream( filePath.c_str() ); - std::string fileBuffer( ( std::istreambuf_iterator( fileStream ) ), - ( std::istreambuf_iterator() ) ); - mParser = Dali::Toolkit::JsonParser::New(); + std::streampos bufferSize = 0; + Dali::Vector buffer; + std::string fileBuffer; + if( !Dali::FileLoader::ReadFile( filePath, bufferSize, buffer, FileLoader::FileType::BINARY ) ) + { + return false; + } + fileBuffer.assign( &buffer[0], bufferSize ); + mParser = Dali::Toolkit::JsonParser::New(); return mParser.Parse( fileBuffer ); } diff --git a/dali-toolkit/internal/visuals/mesh/mesh-visual.cpp b/dali-toolkit/internal/visuals/mesh/mesh-visual.cpp index 0d81192..19357f5 100644 --- a/dali-toolkit/internal/visuals/mesh/mesh-visual.cpp +++ b/dali-toolkit/internal/visuals/mesh/mesh-visual.cpp @@ -25,7 +25,6 @@ #include #include #include -#include //INTERNAL INCLUDES #include