2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file FIo_NormalRegistry.cpp
19 * @brief This is the implementation file for _NormalRegistry class.
25 #include <FBaseInteger.h>
26 #include <FBaseDouble.h>
27 #include <FBaseFloat.h>
28 #include <FBaseUuId.h>
29 #include <FBaseByteBuffer.h>
30 #include <FBaseColIEnumerator.h>
31 #include <FBaseUtilStringTokenizer.h>
32 #include <FBaseResult.h>
33 #include <FBaseSysLog.h>
35 #include <FIoRegistry.h>
37 #include <FBase_StringConverter.h>
38 #include <FIo_FileImpl.h>
39 #include <FIo_NormalRegistry.h>
40 #include <FIo_SecureIoUtil.h>
42 using namespace Tizen::Base;
44 namespace Tizen { namespace Io
47 _NormalRegistry::_NormalRegistry(void)
51 _NormalRegistry::~_NormalRegistry(void)
53 if (_write == true && _FileImpl::IsFileExist(_regPath) == true && _update == true)
58 _sectionList.RemoveAll(true);
60 delete[] _pBuffer; //clear existing buffer
66 _NormalRegistry::Construct(const String& regPath, const char* pOpenMode)
68 SysAssertf(_constructed == false, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class\n");
70 bool isValidOpenMode = this->VerifyRegistryOpenMode(pOpenMode);
71 SysTryReturnResult(NID_IO, isValidOpenMode == true, E_INVALID_ARG, "The specified openMode is invalid. (%s)", pOpenMode);
73 result r = this->Load(regPath, pOpenMode);
74 SysSecureTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Failed to load the registry file (%ls).",
75 GetErrorMessage(r), regPath.GetPointer());
77 if (_pBuffer && _length >= SECURE_REG_HEADER_SIZE_V1)
79 r = _SecureIoUtil::CheckSecureRegistryHeader(&_pBuffer, &_length, regPath, false);
80 SysTryReturnResult(NID_IO, !IsFailed(r), E_INVALID_ARG, "Can not open the secure file in normal mode.");
84 SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Failed to parse the registry file (%ls).",
85 GetErrorMessage(r), regPath.GetPointer());
89 _regPath.Append(regPath);
95 _NormalRegistry::Flush(void)
97 result r = this->PrepareToWrite();
98 SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Failed to prepare to write.", GetErrorMessage(r));
101 SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Failed to write registry file.", GetErrorMessage(r));