Merge "Optimising GetHashCode()" into devel_3.0_main
[platform/framework/native/appfw.git] / src / io / FIo_RegistryCore.cpp
index 5ca9166..6cee81a 100644 (file)
@@ -1,5 +1,4 @@
 //
-// Open Service Platform
 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
 //
 // Licensed under the Apache License, Version 2.0 (the License);
@@ -23,6 +22,8 @@
 #include <unistd.h>
 #include <new>
 #include <unique_ptr.h>
+#include <string.h>
+#include <errno.h>
 
 #include <FBaseInteger.h>
 #include <FBaseDouble.h>
@@ -38,6 +39,8 @@
 #include <FIoRegistry.h>
 
 #include <FBase_StringConverter.h>
+#include <FBase_LocalizedNumParser.h>
+#include <FBase_NativeError.h>
 #include <FApp_AppInfo.h>
 #include "FIo_FileImpl.h"
 #include "FIo_NormalRegistry.h"
@@ -304,7 +307,10 @@ _RegistryCore::Parse(void)
                                                   "[E_PARSING_FAILED] Entry name could not be parsed.");
                        }
 
-                       line.SubString(firstTokenPos + 1, entryVal); // extract entry value
+                       if (line.GetLength() > firstTokenPos + 1)
+                       {
+                               line.SubString(firstTokenPos + 1, entryVal); // extract entry value
+                       }
 
                        // check if entry value contains invalid chars
                        pEntryValue.reset(_StringConverter::CopyToCharArrayN(entryVal));
@@ -992,20 +998,16 @@ _RegistryCore::Write(void)
                return E_SUCCESS;
        }
 
-       result r = E_SUCCESS;
-
-       String openMode(L"w+");
-       unique_ptr<_FileImpl> pFileImpl(new (std::nothrow) _FileImpl);
-       SysTryReturnResult(NID_IO, pFileImpl != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
+       result r = __pFileImpl->Seek(FILESEEKPOSITION_BEGIN, 0);
+       SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
 
-       //TODO: Secure mode is to be handled
-       r = pFileImpl->Construct(_regPath, "w+", null);
+       r = __pFileImpl->Truncate(0);
        SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
 
-       r = pFileImpl->Write(_pBuffer, _length);
+       r = __pFileImpl->Write(_pBuffer, _length);
        SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
 
-       r = pFileImpl->Flush();
+       r = __pFileImpl->Flush();
        SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
 
        return r;
@@ -1035,8 +1037,9 @@ _RegistryCore::PrepareToWrite(void)
        if (_sectionList.GetCount() == 0)
        {
                unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(_regPath));
-               truncate(pFilePath.get(), 0);
-
+               int res = truncate(pFilePath.get(), 0);
+               SysTryReturnResult(NID_IO, res == 0, __ConvertNativeErrorToResult(errno),
+                               "Failed to truncate. errno: %d (%s)", errno, strerror(errno));
                return E_SUCCESS;
        }
 
@@ -1321,7 +1324,6 @@ _RegistryCore::GetEntryValue(int sectionIndex, int entryIndex, _RegValueType typ
 {
        _RegistrySection* pRegSection = null;
        _RegistryEntry* pRegEntry = null;
-       IEnumerator* pEntryEnum = null;
        result r = E_SUCCESS;
        int listSize = 0;
        int tmpEntryIndex = -1;
@@ -1351,7 +1353,7 @@ _RegistryCore::GetEntryValue(int sectionIndex, int entryIndex, _RegValueType typ
        SysTryReturnVoidResult(NID_IO, entryIndex < entryListSize, E_KEY_NOT_FOUND, "[E_KEY_NOT_FOUND]Entry not found.");
 
        // read the entries for this section
-       pEntryEnum = pRegSection->__entryList.GetEnumeratorN();
+       unique_ptr< IEnumerator > pEntryEnum(pRegSection->__entryList.GetEnumeratorN());
        SysTryReturnVoidResult(NID_IO, pEntryEnum != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND]Entry list is empty.");
 
        tmpEntryIndex = entryIndex;
@@ -1479,7 +1481,6 @@ _RegistryCore::DecodeData(const String& strValueEncoded, _RegValueType type, voi
                                        // for positive values.
        {
                double retDoubleVal = 0;
-               result r = E_SUCCESS;
 
                if (*pSize != sizeof(double))
                {
@@ -1487,10 +1488,12 @@ _RegistryCore::DecodeData(const String& strValueEncoded, _RegValueType type, voi
                        return;
                }
 
-               r = Double::Parse(strValueEncoded, retDoubleVal);
-               SysTryReturnVoidResult(NID_IO, !IsFailed(r), E_PARSING_FAILED, "[%s] Propagated.", GetErrorMessage(r));
+               retDoubleVal = _LocalizedNumParser::ToDouble(strValueEncoded, "C");
+               result r = GetLastResult();
+               SysTryReturnVoidResult(NID_IO, r == E_SUCCESS, E_PARSING_FAILED, "[%s] Propagated.", GetErrorMessage(r));
 
                *(double*) pValue = retDoubleVal;
+
                break;
        }