Use FileStream API in demo.
[platform/core/uifw/dali-demo.git] / examples / rendering-basic-pbr / rendering-basic-pbr-example.cpp
index 920a7b8..1239401 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-stream.h>
 
 using namespace Dali;
 using namespace Toolkit;
@@ -390,21 +392,30 @@ public:
   */
   bool LoadShaderCode( const std::string& fullpath, std::vector<char>& output )
   {
-    FILE* f = fopen( fullpath.c_str(), "rb" );
-
-    if( NULL == f )
+    Dali::FileStream fileStream( fullpath, FileStream::READ | FileStream::BINARY );
+    FILE* file = fileStream.GetFile();
+    if( NULL == file )
     {
       return false;
     }
 
-    fseek( f, 0, SEEK_END );
-    size_t size = ftell( f );
-    fseek( f, 0, SEEK_SET );
-    output.resize( size + 1 );
-    std::fill( output.begin(), output.end(), 0 );
-    ssize_t result = fread( output.data(), size, 1, f );
-    fclose( f );
-    return ( result >= 0 );
+    bool retValue = false;
+    if( ! fseek( file, 0, SEEK_END ) )
+    {
+      long int size = ftell( file );
+
+      if( ( size != -1L ) &&
+        ( ! fseek( file, 0, SEEK_SET ) ) )
+      {
+        output.resize( size + 1 );
+        std::fill( output.begin(), output.end(), 0 );
+        ssize_t result = fread( output.data(), size, 1, file );
+
+        retValue = ( result >= 0 );
+      }
+    }
+
+    return retValue;
   }
 
   /**