Use FileStream API in demo.
[platform/core/uifw/dali-demo.git] / examples / rendering-basic-pbr / ktx-loader.cpp
index 175d6c3..579724e 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-stream.h>
 
 namespace PbrDemo
 {
@@ -92,8 +94,8 @@ 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");
-
+  Dali::FileStream fileStream( path, Dali::FileStream::READ | Dali::FileStream::BINARY );
+  FILE* fp = fileStream.GetFile();
   if( NULL == fp )
   {
     return false;
@@ -104,7 +106,6 @@ bool LoadCubeMapFromKtxFile( const std::string& path, CubeData& cubedata )
   int result = fread(&header,1,sizeof(KtxFileHeader),fp);
   if( 0 == result )
   {
-    fclose( fp );
     return false;
   }
 
@@ -115,14 +116,12 @@ bool LoadCubeMapFromKtxFile( const std::string& path, CubeData& cubedata )
 
   if( fseek(fp, imageSizeOffset, SEEK_END) )
   {
-    fclose( fp );
     return false;
   }
 
   lSize = ftell(fp);
   if( lSize == -1L )
   {
-    fclose( fp );
     return false;
   }
 
@@ -130,7 +129,6 @@ bool LoadCubeMapFromKtxFile( const std::string& path, CubeData& cubedata )
 
   if( fseek(fp, imageSizeOffset, SEEK_SET) )
   {
-    fclose( fp );
     return false;
   }