Revert "[Tizen] Implement partial update"
[platform/core/uifw/dali-adaptor.git] / dali / internal / system / common / file-closer.h
index 78f6e5a..27c30ac 100755 (executable)
@@ -1,7 +1,7 @@
-#ifndef _DALI_INTERNAL_PLATFORM_FILECLOSER_H__
-#define _DALI_INTERNAL_PLATFORM_FILECLOSER_H__
+#ifndef DALI_INTERNAL_PLATFORM_FILECLOSER_H
+#define DALI_INTERNAL_PLATFORM_FILECLOSER_H
 /*
- * Copyright (c) 2014 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.
@@ -18,6 +18,7 @@
  */
 
 // INTERNAL INCLUDES
+#include <dali/devel-api/adaptor-framework/file-loader.h>
 
 // EXTERNAL INCLUDES
 #include <cstdio>
@@ -39,22 +40,51 @@ protected: // prevent this class being directly instantiated
   /**
    * @brief Construct a FileCloser guarding a new FILE* for accessing the path passed in.
    */
-  FileCloser( const char * const filename, const char * const mode )
-  : mFile(fopen(filename, mode))
+  FileCloser( const char* const filename, const char* const mode )
   {
-    DALI_ASSERT_DEBUG( filename != 0 && "Cant open a null filename." );
+    DALI_ASSERT_DEBUG( filename != 0 && "Can't open a null filename." );
     DALI_ASSERT_DEBUG( mode != 0 && "Null mode is undefined behaviour in spec." );
 
-    if( mFile == 0 )
+    Dali::FileLoader::FileType fileType = Dali::FileLoader::FileType::TEXT;
+
+    const char* modeStr = mode;
+    while( *modeStr )
+    {
+      switch ( *modeStr )
+      {
+      case 'r':
+        break;
+      case 'b':
+        fileType = FileLoader::FileType::BINARY;
+        break;
+      // Still has to use fopen for append and write modes
+      case 'a':
+      case 'w':
+      case '+':
+        mFile = fopen( filename, mode );
+        return;
+      default:
+        break;
+      }
+
+      ++modeStr;
+    }
+
+    std::streampos bufferSize = 0;
+    if( !Dali::FileLoader::ReadFile( filename, bufferSize, mFileBuffer, fileType ) )
+    {
+      mFile = nullptr;
+    }
+    else
     {
-      DALI_LOG_WARNING( "File open failed for: \"%s\" in mode: \"%s\".\n", filename, mode );
+      mFile = fmemopen( &mFileBuffer[0], bufferSize, mode );
     }
   }
 
   /**
    * @brief Construct a FileCloser guarding a FILE* for reading out of the memory buffer passed in.
    */
-  FileCloser( uint8_t* buffer, size_t dataSize, const char * const mode )
+  FileCloser( uint8_t* buffer, size_t dataSize, const char* const mode )
   : mFile( fmemopen( buffer, dataSize, mode) )
   {
   }
@@ -119,10 +149,13 @@ private:
 
 private:
   FILE* mFile;
+  Dali::Vector<char> mFileBuffer;
 };
 
-} /* namespace Platform */
-} /* namespace Internal */
-} /* namespace Dali */
+} // namespace Platform
+
+} // namespace Internal
+
+} // namespace Dali
 
-#endif /* _DALI_INTERNAL_PLATFORM_FILECLOSER_H__ */
+#endif // DALI_INTERNAL_PLATFORM_FILECLOSER_H