// static bool OTPaths::AppendFolder(String& out_strPath, const String& strBasePath, const String& strFolderName) { if (!strBasePath.Exists()) { otErr << __FUNCTION__ << ": Null: " << "strBasePath" << " passed in!\n"; OT_FAIL; } if (!strFolderName.Exists()) { otErr << __FUNCTION__ << ": Null: " << "strFolderName" << " passed in!\n"; OT_FAIL; } String l_strBasePath_fix(""), l_strFolderName_fix(""); if (!FixPath(strBasePath, l_strBasePath_fix, true)) return false; if (!FixPath(strFolderName, l_strFolderName_fix, true)) return false; std::string l_strBasePath(l_strBasePath_fix.Get()), l_strFolderName(l_strFolderName_fix.Get()); l_strBasePath.append(l_strFolderName); const String l_strPath(l_strBasePath); out_strPath = l_strPath; return true; }
const bool OTPaths::AppendFolder(OTString & out_strPath, const OTString & strBasePath, const OTString & strFolderName) { if (!strBasePath.Exists()) { OTLog::sError("%s: Null: %s passed in!\n", __FUNCTION__, "strBasePath"); OT_ASSERT(false); } if (!strFolderName.Exists()) { OTLog::sError("%s: Null: %s passed in!\n", __FUNCTION__, "strFolderName"); OT_ASSERT(false); } OTString l_strBasePath_fix(""), l_strFolderName_fix(""); if(!FixPath(strBasePath,l_strBasePath_fix,true)) return false; if(!FixPath(strFolderName,l_strFolderName_fix,true)) return false; std::string l_strBasePath(l_strBasePath_fix.Get()), l_strFolderName(l_strFolderName_fix.Get()); l_strBasePath.append(l_strFolderName); const OTString l_strPath(l_strBasePath); out_strPath = l_strPath; return true; }
// static const bool OTDataFolder::Init(const OTString & strThreadContext) { if (NULL != pDataFolder) return false; // we already have a data dir setup. if (!strThreadContext.Exists()) { OTLog::sError("%s: Null: %s passed in!\n", __FUNCTION__, "strThreadContext" ); OT_ASSERT(false); } if (3 > strThreadContext.GetLength()) { OTLog::sError("%s: Too Short: %s !\n", __FUNCTION__, "strThreadContext" ); OT_ASSERT(false); } pDataFolder = new OTDataFolder; // make the new instance pDataFolder->m_bInitialized = false; // setup the config instance. OTSettings * pSettings(new OTSettings(OTPaths::GlobalConfigFile())); pSettings->Reset(); if (!pSettings->Load()) return false; // setup the RelativeKey OTString l_strRelativeKey(""); l_strRelativeKey.Format("%s%s",strThreadContext.Get(),OT_CONFIG_ISRELATIVE); bool l_IsRelative(false), l_Exist(false); OTString l_strFolderName(""), l_strDataConifgFilename(""); // check the config for an existing configuration. if(!pSettings->Check_bool("data_path",l_strRelativeKey,l_IsRelative,l_Exist)) { return false; } // is data folder relative if (l_Exist) { if(!pSettings->Check_str("data_path",strThreadContext,l_strFolderName,l_Exist)) { return false; } // what is the data folder if (l_Exist) { if(!pSettings->Check_str("data_config",strThreadContext,l_strDataConifgFilename,l_Exist)) { return false; } // what is config file name if (l_Exist) { if (l_IsRelative) // data folder path { if(!OTPaths::AppendFolder(pDataFolder->m_strDataFolderPath, OTPaths::AppDataFolder(), l_strFolderName)) { return false; } } else { pDataFolder->m_strDataFolderPath = l_strFolderName; } // data config file path. if(!OTPaths::AppendFile(pDataFolder->m_strDataConifgFilePath, OTPaths::AppDataFolder(), l_strDataConifgFilename)) { return false; } pDataFolder->m_bInitialized = true; return true; } } } // if we get here we do not have a valid config, lets set one. // setup the default conifg file-name; l_strFolderName.Format("%s%s",strThreadContext.Get(), DATA_FOLDER_EXT); l_strDataConifgFilename.Format("%s%s",strThreadContext.Get(), CONFIG_FILE_EXT); if(!pSettings->Set_bool("data_path", l_strRelativeKey, true, l_Exist)) { return false; } if(!pSettings->Set_str("data_path", strThreadContext, l_strFolderName,l_Exist)) { return false; } if(!pSettings->Set_str("data_config", strThreadContext, l_strDataConifgFilename, l_Exist)) { return false; } if(!OTPaths::AppendFolder(pDataFolder->m_strDataFolderPath,OTPaths::AppDataFolder(),l_strFolderName)) { return false; } if(!OTPaths::AppendFile(pDataFolder->m_strDataConifgFilePath, OTPaths::AppDataFolder(), l_strDataConifgFilename)) { return false; } // save config if (!pSettings->Save()) return false; pSettings->Reset(); if (NULL != pSettings) delete pSettings; pSettings = NULL; // have set the default dir, now returning true; pDataFolder->m_bInitialized = true; return true; }