All file read operations should be done through FileLoader. 29/209229/3
authorAnton Obzhirov <a.obzhirov@samsung.com>
Wed, 3 Jul 2019 14:01:53 +0000 (15:01 +0100)
committerAnton Obzhirov <a.obzhirov@samsung.com>
Fri, 5 Jul 2019 11:00:01 +0000 (11:00 +0000)
Change-Id: I2078c71affd10d5bcf57c606effd95ae1bc79bd4

builder/dali-builder.cpp
examples/builder/examples.cpp
examples/fpp-game/game-utils.cpp
examples/ray-marching/ray-marching-example.cpp
examples/refraction-effect/refraction-effect-example.cpp
examples/rendering-basic-pbr/ktx-loader.cpp
examples/rendering-basic-pbr/rendering-basic-pbr-example.cpp
examples/simple-text-renderer/simple-text-renderer-example.cpp

index 4481c3d..5445fd1 100644 (file)
@@ -27,6 +27,7 @@
 //------------------------------------------------------------------------------
 
 #include <dali/dali.h>
+#include <dali/devel-api/adaptor-framework/file-loader.h>
 #include <dali-toolkit/dali-toolkit.h>
 #include <dali-toolkit/devel-api/builder/builder.h>
 #include <dali-toolkit/devel-api/builder/tree-node.h>
@@ -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<char>(t)), std::istreambuf_iterator<char>());
+    std::streampos bufferSize = 0;
+    Dali::Vector<char> fileBuffer;
+    if( !Dali::FileLoader::ReadFile( filename, bufferSize, fileBuffer, FileLoader::FileType::BINARY ) )
+    {
+      return std::string();
+    }
+
+    return std::string( &fileBuffer[0], bufferSize );
   };
 };
 
index ba47e28..e022227 100644 (file)
@@ -43,6 +43,7 @@
 #include <cstring>
 
 #include <dali/integration-api/debug.h>
+#include <dali/devel-api/adaptor-framework/file-loader.h>
 #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<char>(t)),
-                     std::istreambuf_iterator<char>());
+  std::streampos bufferSize = 0;
+  Dali::Vector<char> fileBuffer;
+  if( !Dali::FileLoader::ReadFile( fn, bufferSize, fileBuffer, FileLoader::FileType::BINARY ) )
+  {
+    return std::string();
+  }
+
+  return std::string( &fileBuffer[0], bufferSize );
 };
 
 typedef std::vector<std::string> FileList;
index 8cb99f1..12ac001 100644 (file)
@@ -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 <inttypes.h>
 #include <stdio.h>
+#include <dali/integration-api/debug.h>
+#include <dali/devel-api/adaptor-framework/file-loader.h>
 
 #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<char> 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 ) )
index d638217..4a6f7a3 100644 (file)
@@ -20,6 +20,8 @@
 #include "shared/view.h"
 #include "shared/utility.h"
 #include <stdio.h>
+#include <dali/integration-api/debug.h>
+#include <dali/devel-api/adaptor-framework/file-loader.h>
 
 using namespace Dali;
 using Dali::Toolkit::TextLabel;
@@ -41,12 +43,16 @@ bool LoadShaderCode( const char* path, const char* filename, std::vector<char>&
 {
   std::string fullpath( path );
   fullpath += filename;
-  FILE* file = fopen( fullpath.c_str(), "rb" );
-  if( ! file )
+
+  std::streampos bufferSize = 0;
+  Dali::Vector<char> 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 ) )
   {
index 14c4878..ffbc59a 100644 (file)
@@ -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 <dali/dali.h>
 #include <dali-toolkit/dali-toolkit.h>
 #include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
+#include <dali/integration-api/debug.h>
+#include <dali/devel-api/adaptor-framework/file-loader.h>
 
-#include <fstream>
 #include <sstream>
 #include <limits>
 
@@ -471,14 +472,22 @@ private:
       std::vector<Vector3>& vertexPositions,
       Vector<unsigned int>& faceIndices)
   {
-    std::ifstream ifs( objFileName.c_str(), std::ios::in );
+    std::streampos bufferSize = 0;
+    Dali::Vector<char> 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<float>::max();
     boundingBox[1]=boundingBox[3]=boundingBox[5] = -std::numeric_limits<float>::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<float>& boundingBox,
index 175d6c3..627d74b 100644 (file)
@@ -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 <memory.h>
 #include <stdio.h>
 #include <stdint.h>
+#include <dali/integration-api/debug.h>
+#include <dali/devel-api/adaptor-framework/file-loader.h>
 
 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<char> 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;
index 931f5fb..9d2a9d1 100644 (file)
@@ -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 <dali/integration-api/debug.h>
+#include <dali/devel-api/adaptor-framework/file-loader.h>
 
 using namespace Dali;
 using namespace Toolkit;
@@ -390,7 +392,15 @@ public:
   */
   bool LoadShaderCode( const std::string& fullpath, std::vector<char>& output )
   {
-    FILE* file = fopen( fullpath.c_str(), "rb" );
+    std::streampos bufferSize = 0;
+    Dali::Vector<char> 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;
index 3f8116f..c980170 100644 (file)
@@ -26,9 +26,6 @@
 #include <dali-toolkit/devel-api/text/text-utils-devel.h>
 #include <devel-api/adaptor-framework/image-loading.h>
 
-#include <iostream>
-#include <fstream>
-
 using namespace std;
 using namespace Dali;
 using namespace Dali::Toolkit;