Use FileStream API in demo. 34/209734/2
authorAnton Obzhirov <a.obzhirov@samsung.com>
Wed, 10 Jul 2019 08:35:09 +0000 (09:35 +0100)
committerAnton Obzhirov <a.obzhirov@samsung.com>
Wed, 10 Jul 2019 16:23:56 +0000 (17:23 +0100)
Change-Id: I6d738a54558b5adced956917f9f0de3d6fa2b0d7

examples/fpp-game/game-utils.cpp
examples/ray-marching/ray-marching-example.cpp
examples/rendering-basic-pbr/ktx-loader.cpp
examples/rendering-basic-pbr/rendering-basic-pbr-example.cpp

index 12ac001..1f3f502 100644 (file)
@@ -18,7 +18,7 @@
 #include <inttypes.h>
 #include <stdio.h>
 #include <dali/integration-api/debug.h>
 #include <inttypes.h>
 #include <stdio.h>
 #include <dali/integration-api/debug.h>
-#include <dali/devel-api/adaptor-framework/file-loader.h>
+#include <dali/devel-api/adaptor-framework/file-stream.h>
 
 #include "game-utils.h"
 
 
 #include "game-utils.h"
 
@@ -26,32 +26,25 @@ namespace GameUtils
 {
 bool LoadFile( const char* filename, ByteArray& bytes )
 {
 {
 bool LoadFile( const char* filename, ByteArray& bytes )
 {
-  std::streampos bufferSize = 0;
-  Dali::Vector<char> 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 ) )
     {
   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 ) )
     {
       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 );
       return false;
     }
     size_t result = fread( bytes.data(), 1, bytes.size(), fin );
-    fclose( fin );
     return ( result != 0 );
   }
     return ( result != 0 );
   }
+
   return false;
 }
 
   return false;
 }
 
index 4a6f7a3..2a7b959 100644 (file)
@@ -21,7 +21,7 @@
 #include "shared/utility.h"
 #include <stdio.h>
 #include <dali/integration-api/debug.h>
 #include "shared/utility.h"
 #include <stdio.h>
 #include <dali/integration-api/debug.h>
-#include <dali/devel-api/adaptor-framework/file-loader.h>
+#include <dali/devel-api/adaptor-framework/file-stream.h>
 
 using namespace Dali;
 using Dali::Toolkit::TextLabel;
 
 using namespace Dali;
 using Dali::Toolkit::TextLabel;
@@ -44,17 +44,15 @@ bool LoadShaderCode( const char* path, const char* filename, std::vector<char>&
   std::string fullpath( path );
   fullpath += filename;
 
   std::string fullpath( path );
   fullpath += filename;
 
-  std::streampos bufferSize = 0;
-  Dali::Vector<char> 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;
   }
 
   {
     return false;
   }
 
-  FILE* file = fmemopen( &fileBuffer[0], bufferSize, "rb" );
-
   bool retValue = false;
   bool retValue = false;
-  if( ! fseek( file, 0, SEEK_END ) )
+  if( !fseek( file, 0, SEEK_END ) )
   {
     long int size = ftell( file );
 
   {
     long int size = ftell( file );
 
@@ -69,7 +67,6 @@ bool LoadShaderCode( const char* path, const char* filename, std::vector<char>&
     }
   }
 
     }
   }
 
-  fclose( file );
   return retValue;
 }
 
   return retValue;
 }
 
index 627d74b..579724e 100644 (file)
@@ -23,7 +23,7 @@
 #include <stdio.h>
 #include <stdint.h>
 #include <dali/integration-api/debug.h>
 #include <stdio.h>
 #include <stdint.h>
 #include <dali/integration-api/debug.h>
-#include <dali/devel-api/adaptor-framework/file-loader.h>
+#include <dali/devel-api/adaptor-framework/file-stream.h>
 
 namespace PbrDemo
 {
 
 namespace PbrDemo
 {
@@ -94,14 +94,8 @@ bool ConvertPixelFormat(const uint32_t ktxPixelFormat, Dali::Pixel::Format& form
 
 bool LoadCubeMapFromKtxFile( const std::string& path, CubeData& cubedata )
 {
 
 bool LoadCubeMapFromKtxFile( const std::string& path, CubeData& cubedata )
 {
-  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" );
+  Dali::FileStream fileStream( path, Dali::FileStream::READ | Dali::FileStream::BINARY );
+  FILE* fp = fileStream.GetFile();
   if( NULL == fp )
   {
     return false;
   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 )
   {
   int result = fread(&header,1,sizeof(KtxFileHeader),fp);
   if( 0 == result )
   {
-    fclose( fp );
     return false;
   }
 
     return false;
   }
 
@@ -123,14 +116,12 @@ bool LoadCubeMapFromKtxFile( const std::string& path, CubeData& cubedata )
 
   if( fseek(fp, imageSizeOffset, SEEK_END) )
   {
 
   if( fseek(fp, imageSizeOffset, SEEK_END) )
   {
-    fclose( fp );
     return false;
   }
 
   lSize = ftell(fp);
   if( lSize == -1L )
   {
     return false;
   }
 
   lSize = ftell(fp);
   if( lSize == -1L )
   {
-    fclose( fp );
     return false;
   }
 
     return false;
   }
 
@@ -138,7 +129,6 @@ bool LoadCubeMapFromKtxFile( const std::string& path, CubeData& cubedata )
 
   if( fseek(fp, imageSizeOffset, SEEK_SET) )
   {
 
   if( fseek(fp, imageSizeOffset, SEEK_SET) )
   {
-    fclose( fp );
     return false;
   }
 
     return false;
   }
 
index 2d3a001..1239401 100644 (file)
@@ -26,7 +26,7 @@
 #include "model-skybox.h"
 #include "model-pbr.h"
 #include <dali/integration-api/debug.h>
 #include "model-skybox.h"
 #include "model-pbr.h"
 #include <dali/integration-api/debug.h>
-#include <dali/devel-api/adaptor-framework/file-loader.h>
+#include <dali/devel-api/adaptor-framework/file-stream.h>
 
 using namespace Dali;
 using namespace Toolkit;
 
 using namespace Dali;
 using namespace Toolkit;
@@ -392,15 +392,8 @@ public:
   */
   bool LoadShaderCode( const std::string& fullpath, std::vector<char>& output )
   {
   */
   bool LoadShaderCode( const std::string& fullpath, std::vector<char>& output )
   {
-    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\"", 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;
     if( NULL == file )
     {
       return false;
@@ -421,7 +414,7 @@ public:
         retValue = ( result >= 0 );
       }
     }
         retValue = ( result >= 0 );
       }
     }
-    fclose( file );
+
     return retValue;
   }
 
     return retValue;
   }