// static bool OTPaths::LoadSetScriptsFolder // ie. PrefixFolder() + [ if (NOT Android) // "lib/opentxs/" ] (OTSettings& config, // optional const String& strScriptsFolder, // optional const bool& bIsRelative // optional ) { if (&config == &s_settings) ConfigureDefaultSettings(); const bool bPreLoaded(config.IsLoaded()); if (!bPreLoaded) { config.Reset(); if (!config.Load()) { OT_FAIL; } } String strRelativeKey = ""; strRelativeKey.Format("%s%s", "scripts", OT_CONFIG_ISRELATIVE); // local vairables. bool bConfigIsRelative = false; String strConfigFolder = ""; // lets first check what we have in the configuration: { bool bKeyIsNew = false; if (!config.CheckSet_bool("paths", strRelativeKey, true, bConfigIsRelative, bKeyIsNew)) { return false; } if (!config.CheckSet_str("paths", "scripts", OT_SCRIPTS_DIR, strConfigFolder, bKeyIsNew)) { return false; } } // lets first test if there was a folder passed in if ((strScriptsFolder.Exists()) && (3 < strScriptsFolder.GetLength())) { // we have a folder passed in, lets now check if we need to update // anything: if (bConfigIsRelative != bIsRelative) { bConfigIsRelative = bIsRelative; bool bNewOrUpdated = false; if (!config.Set_bool("paths", strRelativeKey, bConfigIsRelative, bNewOrUpdated)) { return false; } } if (!strConfigFolder.Compare(strScriptsFolder)) { strConfigFolder = strScriptsFolder; // update folder bool bNewOrUpdated = false; if (!config.Set_str("paths", "scripts", strConfigFolder, bNewOrUpdated)) { return false; } } } if (bConfigIsRelative) { if (!FixPath(strConfigFolder, strConfigFolder, true)) { OT_FAIL; } String strPrefixScriptPath = ""; AppendFolder(strPrefixScriptPath, PrefixFolder(), strConfigFolder); String strAppBinaryScriptPath = ""; // if the AppBinaryFolder is set, we will attempt to use this script // path instead. // however if the directory dosn't exist, we will default back to // appending to the prefix. // TODO: Make the prefix path set to AppBinaryFolder. (da2ce7) if (AppBinaryFolder().Exists()) { AppendFolder(strAppBinaryScriptPath, AppBinaryFolder(), strConfigFolder); if (!OTPaths::FolderExists(strAppBinaryScriptPath)) { otOut << __FUNCTION__ << ": Warning: Cannot Find: " << strAppBinaryScriptPath << ", using default!"; strAppBinaryScriptPath = ""; // don't have anything here. } } s_strScriptsFolder = strAppBinaryScriptPath.Exists() ? strAppBinaryScriptPath : strPrefixScriptPath; if (!s_strScriptsFolder.Exists()) OT_FAIL; } else { if (!ToReal(strConfigFolder, strConfigFolder)) { OT_FAIL; } if (!FixPath(strConfigFolder, strConfigFolder, true)) { OT_FAIL; } s_strScriptsFolder = strConfigFolder; // set } if (!bPreLoaded) { if (!config.Save()) { OT_FAIL; } config.Reset(); } return true; // success }
const bool OTPaths::LoadSetScriptsFolder // ie. PrefixFolder() + lib/opentxs/ ( OTSettings * pConfig, //optional const OTString & strScriptsFolder, //optional const bool & bIsRelative //optional ) { if (NULL == pConfig) { OT_ASSERT(false); return false; } const bool bPreLoaded(pConfig->IsLoaded()); if (!bPreLoaded) { pConfig->Reset(); if(!pConfig->Load()) { OT_ASSERT(false); return false; } } OTString strRelativeKey = ""; strRelativeKey.Format("%s%s","scripts",OT_CONFIG_ISRELATIVE); // local vairables. bool bConfigIsRelative = false; OTString strConfigFolder = ""; bool bKeyIsNew = false; if (!pConfig->CheckSet_bool("paths",strRelativeKey,true,bConfigIsRelative,bKeyIsNew)) { return false; } if (!pConfig->CheckSet_str("paths","scripts",OT_SCRIPTS_DIR,strConfigFolder,bKeyIsNew)) { return false; } if (!strConfigFolder.Compare(strScriptsFolder)) // only if we need to. { if(strScriptsFolder.Exists() && (3 < strScriptsFolder.GetLength())) { // update the local vairables. bConfigIsRelative = bIsRelative; strConfigFolder = strScriptsFolder; bool bNewOrUpdated = false; if (!pConfig->Set_bool("paths","scripts_is_",bConfigIsRelative,bNewOrUpdated)) { return false; } if (!pConfig->Set_str( "paths","scripts",strConfigFolder,bNewOrUpdated)) {return false; } } } if(bIsRelative) { if(!FixPath(strConfigFolder,strConfigFolder,true)) { OT_ASSERT(false); return false; } OTString strScriptPath = ""; if(AppendFolder(strScriptPath,PrefixFolder(),strConfigFolder)); else { OT_ASSERT(false); return false; } m_strScriptsFolder = strScriptPath; // set } else { if(!ToReal(strConfigFolder,strConfigFolder)) { OT_ASSERT(false); return false; } if(!FixPath(strConfigFolder,strConfigFolder,true)) { OT_ASSERT(false); return false; } m_strScriptsFolder = strConfigFolder; // set } if (!bPreLoaded) { if(!pConfig->Save()) { OT_ASSERT(false); return false; } pConfig->Reset(); } return true; // success }
const bool OTPaths::LoadSetScriptsFolder // ie. PrefixFolder() + lib/opentxs/ ( OTSettings * pConfig, //optional const OTString & strScriptsFolder, //optional const bool & bIsRelative //optional ) { if (NULL == pConfig) { OT_ASSERT(false); return false; } const bool bPreLoaded(pConfig->IsLoaded()); if (!bPreLoaded) { pConfig->Reset(); if(!pConfig->Load()) { OT_ASSERT(false); return false; } } OTString strRelativeKey = ""; strRelativeKey.Format("%s%s","scripts",OT_CONFIG_ISRELATIVE); // local vairables. bool bConfigIsRelative = false; OTString strConfigFolder = ""; // lets first check what we have in the configuration: { bool bKeyIsNew = false; if (!pConfig->CheckSet_bool("paths",strRelativeKey,true,bConfigIsRelative,bKeyIsNew)) { return false; } if (!pConfig->CheckSet_str("paths","scripts",OT_SCRIPTS_DIR,strConfigFolder,bKeyIsNew)) { return false; } } // lets first test if there was a folder passed in if ((strScriptsFolder.Exists()) && (3 < strScriptsFolder.GetLength())) { // we have a folder passed in, lets now check if we need to update anything: if (bConfigIsRelative != bIsRelative) { bConfigIsRelative = bIsRelative; bool bNewOrUpdated = false; if (!pConfig->Set_bool("paths", strRelativeKey, bConfigIsRelative, bNewOrUpdated)) { return false; } } if (!strConfigFolder.Compare(strScriptsFolder)) { strConfigFolder = strScriptsFolder; // update folder bool bNewOrUpdated = false; if (!pConfig->Set_str( "paths", "scripts", strConfigFolder, bNewOrUpdated)) { return false; } } } if(bConfigIsRelative) { if(!FixPath(strConfigFolder,strConfigFolder,true)) { OT_ASSERT(false); return false; } OTString strScriptPath = ""; if(!AppendFolder(strScriptPath, PrefixFolder(), strConfigFolder)) { OT_ASSERT(false); return false; } m_strScriptsFolder = strScriptPath; // set } else { if(!ToReal(strConfigFolder, strConfigFolder)) { OT_ASSERT(false); return false; } if(!FixPath(strConfigFolder, strConfigFolder, true)) { OT_ASSERT(false); return false; } m_strScriptsFolder = strConfigFolder; // set } if (!bPreLoaded) { if(!pConfig->Save()) { OT_ASSERT(false); return false; } pConfig->Reset(); } return true; // success }