150 #include "TargetConditionals.h"
154 #include <mach-o/dyld.h>
158 #define CONFIG_FILE_EXT ".cfg"
159 #define DATA_FOLDER_EXT "_data"
160 #define OT_CONFIG_ISRELATIVE "_is_relative"
165 OTDataFolder* OTDataFolder::pDataFolder;
169 if (
nullptr != pDataFolder)
172 if (!strThreadContext.
Exists()) {
173 otErr << __FUNCTION__ <<
": Null: "
174 <<
"strThreadContext"
179 otErr << __FUNCTION__ <<
": Too Short: "
180 <<
"strThreadContext"
187 pDataFolder->m_bInitialized =
false;
192 if (!pSettings->Load())
return false;
196 l_strRelativeKey.
Format(
"%s%s", strThreadContext.
Get(),
199 bool l_IsRelative(
false), l_Exist(
false);
200 OTString l_strFolderName(
""), l_strDataConifgFilename(
"");
203 if (!pSettings->
Check_bool(
"data_path", l_strRelativeKey, l_IsRelative,
209 if (!pSettings->
Check_str(
"data_path", strThreadContext,
210 l_strFolderName, l_Exist)) {
215 if (!pSettings->
Check_str(
"data_config", strThreadContext,
216 l_strDataConifgFilename, l_Exist)) {
230 pDataFolder->m_strDataFolderPath = l_strFolderName;
236 l_strDataConifgFilename)) {
240 pDataFolder->m_bInitialized =
true;
250 l_strDataConifgFilename.
Format(
"%s%s", strThreadContext.
Get(),
253 if (!pSettings->
Set_bool(
"data_path", l_strRelativeKey,
true, l_Exist)) {
256 if (!pSettings->
Set_str(
"data_path", strThreadContext, l_strFolderName,
260 if (!pSettings->
Set_str(
"data_config", strThreadContext,
261 l_strDataConifgFilename, l_Exist)) {
271 l_strDataConifgFilename)) {
276 if (!pSettings->Save())
return false;
279 if (
nullptr != pSettings)
delete pSettings;
284 pDataFolder->m_bInitialized =
true;
290 if (
nullptr == pDataFolder)
293 return pDataFolder->m_bInitialized;
298 if (
nullptr != pDataFolder) {
300 pDataFolder =
nullptr;
304 pDataFolder =
nullptr;
317 return strDataFolder;
321 return strDataFolder;
327 if (
nullptr != pDataFolder) {
328 if (
true == pDataFolder->m_bInitialized) {
329 if (pDataFolder->m_strDataFolderPath.
Exists()) {
330 strDataFolder = pDataFolder->m_strDataFolderPath;
341 if (
nullptr != pDataFolder) {
342 if (
true == pDataFolder->m_bInitialized) {
343 if (pDataFolder->m_strDataConifgFilePath.
Exists()) {
344 strConfigFilePath = pDataFolder->m_strDataConifgFilePath;
static EXPORT bool Cleanup()
EXPORT bool Check_str(const OTString &strSection, const OTString &strKey, OTString &out_strResult, bool &out_bKeyExist) const
static EXPORT bool GetConfigFilePath(OTString &strConfigFilePath)
EXPORT bool Set_bool(const OTString &strSection, const OTString &strKey, const bool &bValue, bool &out_bNewOrUpdate, const OTString &strComment="")
EXPORT uint32_t GetLength() const
static EXPORT bool IsInitialized()
EXPORT bool Exists() const
static EXPORT bool Init(const OTString &strThreadContext)
static EXPORT const OTString & AppDataFolder()
EXPORT void Format(const char *fmt,...)
static EXPORT bool AppendFolder(OTString &out_strPath, const OTString &strBasePath, const OTString &strFolderName)
EXPORT bool Set_str(const OTString &strSection, const OTString &strKey, const OTString &strValue, bool &out_bNewOrUpdate, const OTString &strComment="")
EXPORT bool Check_bool(const OTString &strSection, const OTString &strKey, bool &out_bResult, bool &out_bKeyExist) const
EXPORT const char * Get() const
OTLOG_IMPORT OTLogStream otErr
#define OT_CONFIG_ISRELATIVE
static EXPORT bool AppendFile(OTString &out_strPath, const OTString &strBasePath, const OTString &strFileName)
static EXPORT OTString Get()
static EXPORT const OTString & GlobalConfigFile()