static void DebugDeallocator(void* block, ALLOCATION_TYPE type) { void* realBlock = block? ToReal(block) : nullptr; if (realBlock) { auto Info = static_cast<MEMINFO*>(realBlock); assert(Info->AllocationType == type); assert(GetMarker(Info) == EndMarker); UnregisterBlock(Info); } free(realBlock); }
// static bool OTPaths::BuildFilePath(const String& strFolderPath, bool& out_bFolderCreated) { out_bFolderCreated = false; String l_strFilePath_fix(""), l_strFilePath_real(""); if (!ToReal(strFolderPath, l_strFilePath_real)) return false; // path to real if (!FixPath(l_strFilePath_real, l_strFilePath_fix, false)) return false; // real to fixed real std::string l_strFilePath(l_strFilePath_fix.Get()); // fixed real path. std::vector<std::string> vFolders; split_byChar(vFolders, l_strFilePath, "/", split::no_empties); size_t nSize = vFolders.size(); std::string l_strPathPart(""); bool l_FolderExists(false), l_bBuiltFolder(false); const bool bLog(Log::IsInitialized()); for (size_t i = 0; i < nSize; i++) { #ifndef _WIN32 // aka UNIX if (0 == i) l_strPathPart += "/"; // add annother / for root. #endif l_strPathPart += vFolders[i]; if ((i + 1) == nSize) continue; // file should be skipped l_strPathPart += "/"; // is a folder, so should append / if (0 == i) continue; // / or x:/ should be skiped. String strPathPart(l_strPathPart); if (!ConfirmCreateFolder(strPathPart, l_FolderExists, l_bBuiltFolder)) return false; if (bLog && l_bBuiltFolder) otOut << __FUNCTION__ << ": Made new folder: " << l_strPathPart << ""; if (!out_bFolderCreated && l_bBuiltFolder) out_bFolderCreated = true; } return true; }
const bool OTPaths::BuildFolderPath(const OTString & strFolderPath, bool & out_bFolderCreated) { out_bFolderCreated = false; OTString l_strFolderPath_fix(""), l_strFolderPath_real(""); if (!ToReal(strFolderPath,l_strFolderPath_real)) return false; // path to real if (!FixPath(l_strFolderPath_real,l_strFolderPath_fix,true)) return false; // real to fixed real std::string l_strFolderPath(l_strFolderPath_fix.Get()); // fixed real path. std::vector<std::string> vFolders; OTString::split_byChar(vFolders,l_strFolderPath,"/",OTString::split::no_empties); size_t nSize = vFolders.size(); std::string l_strPathPart(""); bool l_FolderExists(false), l_bBuiltFolder(false); const bool bLog(OTLog::IsInitialized()); for (int i = 0; i < nSize; i++) { #ifndef _WIN32 // aka UNIX if(0 == i) l_strPathPart += "/"; //add annother / for root. #endif l_strPathPart += vFolders[i]; l_strPathPart += "/"; if(0 == i) continue; // / or x:/ should be skiped. OTString strPathPart(l_strPathPart); if(!ConfirmCreateFolder(strPathPart, l_FolderExists, l_bBuiltFolder)) return false; if (bLog && l_bBuiltFolder) OTLog::vOutput(0,"%s: Made new folder: %s\n", __FUNCTION__, l_strPathPart.c_str()); if (!out_bFolderCreated && l_bBuiltFolder) out_bFolderCreated = true; } return true; }
// this function dosn't change the "strRelativePath" so. It will only fix the strBasePath. const bool OTPaths::RelativeToCanonical(OTString & out_strCanonicalPath, const OTString & strBasePath, const OTString & strRelativePath) { if (!strBasePath.Exists()) { OTLog::sError("%s: Null: %s passed in!\n", __FUNCTION__, "strBasePath" ); OT_ASSERT(false); } if (!strRelativePath.Exists()) { OTLog::sError("%s: Null: %s passed in!\n", __FUNCTION__, "strRelativePath" ); OT_ASSERT(false); } OTString l_strBasePath_fix(""); if(!FixPath(strBasePath,l_strBasePath_fix,true)) return false; if(strRelativePath.Compare(".")) { out_strCanonicalPath = strBasePath; return true; } // if ".", return base path. std::string l_strBasePath(l_strBasePath_fix.Get()), l_strRelativePath(strRelativePath.Get()); l_strBasePath.append(l_strRelativePath); OTString l_strPath(l_strBasePath), l_strCanonicalPath(""); if(!ToReal(l_strPath,l_strCanonicalPath)) return false; out_strCanonicalPath = l_strCanonicalPath; return true; }
// this function dosn't change the "strRelativePath" so. It will only fix the // strBasePath. // static bool OTPaths::RelativeToCanonical(String& out_strCanonicalPath, const String& strBasePath, const String& strRelativePath) { if (!strBasePath.Exists()) { otErr << __FUNCTION__ << ": Null: " << "strBasePath" << " passed in!\n"; OT_FAIL; } if (!strRelativePath.Exists()) { otErr << __FUNCTION__ << ": Null: " << "strRelativePath" << " passed in!\n"; OT_FAIL; } String l_strBasePath_fix(""); if (!FixPath(strBasePath, l_strBasePath_fix, true)) return false; if (strRelativePath.Compare(".")) { out_strCanonicalPath = strBasePath; return true; } // if ".", return base path. std::string l_strBasePath(l_strBasePath_fix.Get()), l_strRelativePath(strRelativePath.Get()); l_strBasePath.append(l_strRelativePath); String l_strPath(l_strBasePath), l_strCanonicalPath(""); if (!ToReal(l_strPath, l_strCanonicalPath)) return false; out_strCanonicalPath = l_strCanonicalPath; return true; }
const bool OTPaths::Get( OTSettings * pConfig, const OTString & strSection, const OTString & strKey, OTString & out_strVar, bool & out_bIsRelative, bool & out_bKeyExist ) { if (!strSection.Exists()) { OTLog::sError("%s: Null: %s passed in!\n", __FUNCTION__, "strSection" ); OT_ASSERT(false); } if (!strKey.Exists()) { OTLog::sError("%s: Null: %s passed in!\n", __FUNCTION__, "strKey" ); OT_ASSERT(false); } out_strVar = ""; out_bIsRelative = false; out_bKeyExist = false; 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; } } bool bBoolExists(false), bStringExists(false), bIsRelative(false); OTString strRelativeKey(""), strOutFolder(""); strRelativeKey.Format("%s%s",strKey.Get(),OT_CONFIG_ISRELATIVE); if(pConfig->Check_bool(strSection,strRelativeKey,bIsRelative,bBoolExists)) { if(pConfig->Check_str(strSection,strKey,strOutFolder,bStringExists)) { if (bBoolExists && bStringExists) { if (!bIsRelative) // lets fix the path, so it dosn't matter how people write it in the config. { if(!ToReal(strOutFolder,strOutFolder)) { OT_ASSERT(false); return false; } if(!FixPath(strOutFolder,strOutFolder,true)) { OT_ASSERT(false); return false; } } out_strVar = strOutFolder; out_bIsRelative = bIsRelative; out_bKeyExist = true; } else { out_strVar = ""; out_bIsRelative = false; out_bKeyExist = false; } if (!bPreLoaded) { pConfig->Reset(); } return true; } } // if we get here, there has been a error! OT_ASSERT(false); pConfig->Reset(); return false; }
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 }
// The LoadSet Functions will update the static values. const bool OTPaths::LoadSetPrefixFolder // eg. /usr/local/ ( OTSettings * pConfig, //optional const OTString & strPrefixFolder //optional //const bool & bIsRelative (cannot be relative); ) { /* The prefix path is special. This path is tested if it is different to the one that would be automatically selected by this program (aka either compiled into, or from the registry, or the default user data directory). If the set path is different to what would be supplied and the ‘override path’ value is set. Then we will use that path. Otherwise, we will update the path in the configuration to link against the updated path. Users will need to set the ‘override path’ flag in the configuration, if they want to manually set the prefix path. */ 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; } } // get default path OTString strDefaultPrefixPath(OT_PREFIX_PATH); #ifdef _WIN32 OTString strTemp; if (OTPaths::Win_GetInstallFolderFromRegistry(strTemp)) { strDefaultPrefixPath = strTemp; } #endif // now check the configuration to see what values we have: OTString strConfigPath = ""; bool bNewPath = false; bool bHaveRelativePath = false; // should always be false. bool bPrefixPathOverride = false; bool bNoOverrideFlagWasSet = false; if(!pConfig->CheckSet_str("paths","prefix_path",strDefaultPrefixPath,strConfigPath,bNewPath)) { return false; } OTString strPrefixPathOverride("prefix_path_override"); if(!pConfig->CheckSet_bool("paths",strPrefixPathOverride,false,bPrefixPathOverride,bNoOverrideFlagWasSet,"; Set this if you don't want this path to change")) {return false; } OTString strLocalPrefixPath = ""; // if the caller has supplied a prefix folder, lets set that. if(strPrefixFolder.Exists() && (3 < strPrefixFolder.GetLength())) { if (!strConfigPath.Compare(strPrefixFolder)) { // we set the new path (from this function caller) bool bNewOrUpdate = false; if(!pConfig->Set_str("paths","prefix_path",strPrefixFolder,bNewOrUpdate)) { return false; } } strLocalPrefixPath = strPrefixFolder; // set } else { // we should update the path if (!bPrefixPathOverride) { if (!strConfigPath.Compare(strDefaultPrefixPath)) { // we set the new default path (since we have no overide set) bool bNewOrUpdate = false; if(!pConfig->Set_str("paths","prefix_path",strDefaultPrefixPath,bNewOrUpdate)) { return false; } } strLocalPrefixPath = strDefaultPrefixPath; // set } else { strLocalPrefixPath = strConfigPath; // set } } if (!strLocalPrefixPath.Exists()) { OT_ASSERT(false); } if(!ToReal(strLocalPrefixPath,strLocalPrefixPath)) { OT_ASSERT(false); return false; } if(!FixPath(strLocalPrefixPath,strLocalPrefixPath,true)) { OT_ASSERT(false); return false; } m_strPrefixFolder = strLocalPrefixPath; if (!bPreLoaded) { if(!pConfig->Save()) { OT_ASSERT(false); return false; } pConfig->Reset(); } return true; }
//--------------------------------------------------------------------------- void GregorianDate::ParseOut(const wxString &str) { #if DEBUG_GREGORIAN_VALIDATE //MessageInterface::ShowMessage(wxT("==> GregorianDate::ParseOut() str=%s\n"), str.c_str()); #endif // Check if non-empty string then parse out; otherwise, nothing. if (str != wxT("")) { StringTokenizer dateToken(str, wxT(" ")); if (dateToken.CountTokens() == 4) { wxString issString = (dateToken.GetToken(0)); wxStringInputStream issStringStream(issString); wxTextInputStream iss(issStringStream); Integer dayNum, yearNum; // Get the number iss >> dayNum; // Get the year yearNum = ToInteger(dateToken.GetToken(2)); // Check validity for year if (dateToken.GetToken(2).length() != 4 || yearNum < 1950) return; // throw GregorianDateException(); // Check validity for month // std::vector<wxString>::iterator pos; // pos = find(monthName.begin(),monthName.end(), // dateToken.GetToken(1)); // if (pos == monthName.end()) // return; // // throw GregorianDateException(); bool monthFound = false; Integer monthNum = 0; for (int i=0; i<12; i++) { if (GmatTimeConstants::MONTH_NAME_TEXT[i] == dateToken.GetToken(1)) { monthFound = true; monthNum = i+1; break; } } if (!monthFound) return; // Integer monthNum; // monthNum = (Integer) distance(monthName.begin(),pos) + 1; wxString tempYMD; tempYMD = dateToken.GetToken(2) + NumToString(monthNum); if (dateToken.GetToken(0).length() == 1) tempYMD += wxT("0"); tempYMD += dateToken.GetToken(0) + wxT("."); // Start with time StringTokenizer timeToken(dateToken.GetToken(3),wxT(":")); if (timeToken.CountTokens() == 3) { // // Check length of time format // if (timeToken.GetToken(0).length() != 2 || // timeToken.GetToken(1).length() != 2 || // timeToken.GetToken(2).length() != 6) // { // MessageInterface::ShowMessage( // wxT("\nWarning: invalid Gregorian format with time")); // return; // } // Check length of the hour format if (timeToken.GetToken(0).length() != 2) { MessageInterface::ShowMessage( wxT("\nWarning: invalid Gregorian time for hours format(HH)\n")); return; } // Check length of the minute format if (timeToken.GetToken(1).length() != 2) { MessageInterface::ShowMessage( wxT("\nWarning: invalid Gregorian time for minutes format(MM)\n")); return; } if (timeToken.GetToken(2).length() != 6) { MessageInterface::ShowMessage( wxT("\nWarning: invalid Gregorian time for seconds format(SS.mmm)\n")); return; } // Get hour and minute Integer hour, minute; hour = ToInteger(timeToken.GetToken(0)); minute = ToInteger(timeToken.GetToken(1)); tempYMD += timeToken.GetToken(0) + timeToken.GetToken(1); // Finally start with seconds wxString strSeconds = timeToken.GetToken(2); timeToken.Set(strSeconds,wxT(".")); // Check time format in second if (timeToken.CountTokens() != 2 || timeToken.GetToken(0).length() != 2 || timeToken.GetToken(1).length() != 3) { MessageInterface::ShowMessage( wxT("\nWarning: invalid Gregorian format with seconds")); return; } tempYMD += timeToken.GetToken(0) + timeToken.GetToken(1); // Get real number in seconds Real second = ToReal(strSeconds); #if DEBUG_GREGORIAN_VALIDATE //MessageInterface::ShowMessage // (wxT("==> GregorianDate::ParseOut() second=%.10f\n"), second); #endif // Finally check validity for the date if (!IsValidTime(yearNum,monthNum,dayNum,hour,minute,second)) { MessageInterface::ShowMessage( wxT("\nWarning: invalid Gregorian format from DateUtil")); return; } stringYMDHMS = tempYMD; //MessageInterface::ShowMessage // (wxT("==> GregorianDate::ParseOut() stringYMDHMS=%s\n"), // stringYMDHMS.c_str()); } isValid = true; }
// задание параметров для сумматора СЭМ-2 bool AutomaticE(void) { uchar i; if (OpenDeviceE() == 0) return(0); for (i=0; i<bMINORREPEATS; i++) { InitPush(0); PushChar(0x1B); PushChar('w'); Query(300+1, 2, 1); if (EscInput() == SER_GOODCHECK) break; if (fKey == true) return(0); } if (i == bMINORREPEATS) return(0); ShowPercent(75); InitPop((uint)132 + diCurr.ibLine*3);// K трансформации PopRealBCD(); dbKtrans = reBuffA; InitPop((uint)180 + diCurr.ibLine*3); // K преобразования PopRealBCD(); SetCanalsAll(); // сохранение К преобразования и К трасформации DelayOff(); for (i=0; i<bMINORREPEATS; i++) // чтение накопленной энергии { InitPush(0); PushChar(0x1B); PushChar('S'); Query(64+1, 2, 1); if (EscInput() == SER_GOODCHECK) break; if (fKey == true) return(0); } if (i == bMINORREPEATS) return(0); ShowPercent(100); InitPop(diCurr.ibLine*4); coFloat.mpbBuff[0] = PopChar(); coFloat.mpbBuff[1] = PopChar(); coFloat.mpbBuff[2] = PopChar(); coFloat.mpbBuff[3] = PopChar(); ToReal(); SetCanReal(mpreCount,ibDig); // сохранение показаний счётчиков return(1); }
// static bool OTPaths::Get(OTSettings& config, const String& strSection, const String& strKey, String& out_strVar, bool& out_bIsRelative, bool& out_bKeyExist) { if (!strSection.Exists()) { otErr << __FUNCTION__ << ": Null: " << "strSection" << " passed in!\n"; OT_FAIL; } if (!strKey.Exists()) { otErr << __FUNCTION__ << ": Null: " << "strKey" << " passed in!\n"; OT_FAIL; } out_strVar = ""; out_bIsRelative = false; out_bKeyExist = false; const bool bPreLoaded(config.IsLoaded()); if (!bPreLoaded) { config.Reset(); if (!config.Load()) { OT_FAIL; } } bool bBoolExists(false), bIsRelative(false); String strRelativeKey(""), strOutFolder(""); strRelativeKey.Format("%s%s", strKey.Get(), OT_CONFIG_ISRELATIVE); if (config.Check_bool(strSection, strRelativeKey, bIsRelative, bBoolExists)) { bool bStringExists = false; if (config.Check_str(strSection, strKey, strOutFolder, bStringExists)) { if (bBoolExists && bStringExists) { if (!bIsRelative) // lets fix the path, so it dosn't matter how // people write it in the config. { if (!ToReal(strOutFolder, strOutFolder)) { OT_FAIL; } if (!FixPath(strOutFolder, strOutFolder, true)) { OT_FAIL; } } out_strVar = strOutFolder; out_bIsRelative = bIsRelative; out_bKeyExist = true; } else { out_strVar = ""; out_bIsRelative = false; out_bKeyExist = false; } if (!bPreLoaded) { config.Reset(); } return true; } } // if we get here, there has been a error! OT_FAIL; }
// 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 }
// The LoadSet Functions will update the static values. // static bool OTPaths::LoadSetPrefixFolder // eg. /usr/local/ (OTSettings& config, // optional const String& strPrefixFolder // optional // const bool& bIsRelative (cannot be relative); ) { /* The prefix path is special. This path is tested if it is different to the one that would be automatically selected by this program (aka either compiled into, or from the registry, or the default user data directory). If the set path is different to what would be supplied and the override path value is set. Then we will use that path. Otherwise, we will update the path in the configuration to link against the updated path. Users will need to set the override path flag in the configuration, if they want to manually set the prefix path. */ if (&config == &s_settings) ConfigureDefaultSettings(); const bool bPreLoaded(config.IsLoaded()); if (!bPreLoaded) { config.Reset(); if (!config.Load()) { OT_FAIL; } } { // get default path String strDefaultPrefixPath(OT_PREFIX_PATH); { if (!strDefaultPrefixPath.Exists()) { otErr << __FUNCTION__ << ": Error: OT_PREFIX_PATH is not set!"; OT_FAIL; } #ifdef _WIN32 String strTemp; if (OTPaths::Win_GetInstallFolderFromRegistry(strTemp)) { strDefaultPrefixPath = strTemp; } #endif if (!ToReal(strDefaultPrefixPath, strDefaultPrefixPath)) { OT_FAIL; } if (!FixPath(strDefaultPrefixPath, strDefaultPrefixPath, true)) { OT_FAIL; } } String strLocalPrefixPath = ""; bool bPrefixPathOverride = false; { // now check the configuration to see what values we have: String strConfigPath = ""; bool bIsNew = false; String strPrefixPathOverride("prefix_path_override"); if (!config.CheckSet_str("paths", "prefix_path", strDefaultPrefixPath, strConfigPath, bIsNew)) { return false; } if (!config.CheckSet_bool( "paths", strPrefixPathOverride, false, bPrefixPathOverride, bIsNew, "; This will force the prefix not to change")) { return false; } // if the config dosn't have a prefix path set. Lets set the // default. // if a prefix path was passed in, we will override with that later. if (!strConfigPath.Exists() || (3 > strConfigPath.GetLength())) { otErr << __FUNCTION__ << ": Error: Bad " << "prefix_path" << " in config, will reset!"; strConfigPath = strDefaultPrefixPath; // set bPrefixPathOverride = false; // lets set the default path, and reset override bool bNewOrUpdate = false; if (!config.Set_str("paths", "prefix_path", strDefaultPrefixPath, bNewOrUpdate)) { return false; } if (!config.Set_bool("paths", strPrefixPathOverride, false, bNewOrUpdate)) { return false; } } strLocalPrefixPath = strConfigPath; } { if (!bPrefixPathOverride) { bool bUpdate = false; // default if (!strLocalPrefixPath.Compare(strDefaultPrefixPath)) { strLocalPrefixPath = strDefaultPrefixPath; bUpdate = true; } // passed in if (strPrefixFolder.Exists() && (3 < strPrefixFolder.GetLength())) { // a prefix folder was passed in... lets use it, and update // the config if the override isn't set String strTmp = strPrefixFolder; if (!ToReal(strTmp, strTmp)) { OT_FAIL; } if (!FixPath(strTmp, strTmp, true)) { OT_FAIL; } if (!strLocalPrefixPath.Compare(strTmp)) { strLocalPrefixPath = strTmp; bUpdate = true; } } // we need to update the path in the config if (bUpdate) { bool bNewOrUpdate = false; if (!config.Set_str("paths", "prefix_path", strLocalPrefixPath, bNewOrUpdate)) { return false; } } } } { if (!strLocalPrefixPath.Exists()) { OT_FAIL; } if (!ToReal(strLocalPrefixPath, strLocalPrefixPath)) { OT_FAIL; } if (!FixPath(strLocalPrefixPath, strLocalPrefixPath, true)) { OT_FAIL; } s_strPrefixFolder = strLocalPrefixPath; } } if (!bPreLoaded) { if (!config.Save()) { OT_FAIL; } config.Reset(); } return true; }
void Setup::decodeProperties(const std::vector<Property>& properties) { for (size_t iProp = 0; iProp < properties.size(); iProp++) { const Property& prop = properties[iProp]; if (prop.name == "setup.cameraLocation.x") { cameraLocation.x = ToReal(prop.value); } else if (prop.name == "setup.cameraLocation.y") { cameraLocation.y = ToReal(prop.value); } else if (prop.name == "setup.cameraLocation.z") { cameraLocation.z = ToReal(prop.value); } else if (prop.name == "setup.leftLaserLocation.x") { leftLaserLocation.x = ToReal(prop.value); } else if (prop.name == "setup.leftLaserLocation.y") { leftLaserLocation.y = ToReal(prop.value); } else if (prop.name == "setup.leftLaserLocation.z") { leftLaserLocation.z = ToReal(prop.value); } else if (prop.name == "setup.rightLaserLocation.x") { rightLaserLocation.x = ToReal(prop.value); } else if (prop.name == "setup.rightLaserLocation.y") { rightLaserLocation.y = ToReal(prop.value); } else if (prop.name == "setup.rightLaserLocation.z") { rightLaserLocation.z = ToReal(prop.value); } else if (prop.name == "setup.rightLaserPin") { rightLaserPin = ToInt(prop.value); } else if (prop.name == "setup.leftLaserPin") { leftLaserPin = ToInt(prop.value); } else if (prop.name == "setup.motorEnablePin") { motorEnablePin = ToInt(prop.value); } else if (prop.name == "setup.motorStepPin") { motorStepPin = ToInt(prop.value); } else if (prop.name == "setup.motorDirPin") { motorDirPin = ToInt(prop.value); } else if (prop.name == "setup.motorDirPinValue") { motorDirPinValue = ToInt(prop.value); } else if (prop.name == "setup.laserOnValue") { laserOnValue = ToInt(prop.value); } else if (prop.name == "setup.stepsPerRevolution") { stepsPerRevolution = ToInt(prop.value); } else if (prop.name == "setup.motorResponseDelay") { motorResponseDelay = ToInt(prop.value); } else if (prop.name == "setup.motorStepDelay") { motorStepDelay = ToInt(prop.value); } else if (prop.name == "setup.httpPort") { httpPort = ToInt(prop.value); } else if (prop.name == "setup.serialNumber") { serialNumber = prop.value; } else if (prop.name == "setup.unitOfLength") { unitOfLength = (UnitOfLength) ToInt(prop.value); } } }
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 }
void Setup::decodeProperties(const std::vector<Property>& properties) { for (size_t iProp = 0; iProp < properties.size(); iProp++) { const Property& prop = properties[iProp]; if (prop.name == "setup.cameraLocation.x") { cameraLocation.x = ToReal(prop.value); } else if (prop.name == "setup.cameraLocation.y") { cameraLocation.y = ToReal(prop.value); } else if (prop.name == "setup.cameraLocation.z") { cameraLocation.z = ToReal(prop.value); } else if (prop.name == "setup.leftLaserLocation.x") { leftLaserLocation.x = ToReal(prop.value); } else if (prop.name == "setup.leftLaserLocation.y") { leftLaserLocation.y = ToReal(prop.value); } else if (prop.name == "setup.leftLaserLocation.z") { leftLaserLocation.z = ToReal(prop.value); } else if (prop.name == "setup.rightLaserLocation.x") { rightLaserLocation.x = ToReal(prop.value); } else if (prop.name == "setup.rightLaserLocation.y") { rightLaserLocation.y = ToReal(prop.value); } else if (prop.name == "setup.rightLaserLocation.z") { rightLaserLocation.z = ToReal(prop.value); } else if (prop.name == "setup.rightLaserPin") { rightLaserPin = ToInt(prop.value); } else if (prop.name == "setup.leftLaserPin") { leftLaserPin = ToInt(prop.value); } else if (prop.name == "setup.motorEnablePin") { motorEnablePin = ToInt(prop.value); } else if (prop.name == "setup.motorStepPin") { motorStepPin = ToInt(prop.value); } else if (prop.name == "setup.motorDirPin") { motorDirPin = ToInt(prop.value); } else if (prop.name == "setup.motorDirPinValue") { motorDirPinValue = ToInt(prop.value); } else if (prop.name == "setup.laserOnValue") { laserOnValue = ToInt(prop.value); } else if (prop.name == "setup.stepsPerRevolution") { stepsPerRevolution = ToInt(prop.value); } else if (prop.name == "setup.motorResponseDelay") { motorResponseDelay = ToInt(prop.value); } else if (prop.name == "setup.motorStepDelay") { motorStepDelay = ToInt(prop.value); } else if (prop.name == "setup.httpPort") { httpPort = ToInt(prop.value); } else if (prop.name == "setup.serialNumber") { serialNumber = prop.value; } else if (prop.name == "setup.unitOfLength") { unitOfLength = (UnitOfLength) ToInt(prop.value); } else if (prop.name == "setup.haveLaserPlaneNormals") { haveLaserPlaneNormals = ToBool(prop.value); } else if (prop.name == "setup.leftLaserPlaneNormal.x") { leftLaserPlaneNormal.x = ToReal(prop.value); } else if (prop.name == "setup.leftLaserPlaneNormal.y") { leftLaserPlaneNormal.y = ToReal(prop.value); } else if (prop.name == "setup.leftLaserPlaneNormal.z") { leftLaserPlaneNormal.z = ToReal(prop.value); } else if (prop.name == "setup.rightLaserPlaneNormal.x") { rightLaserPlaneNormal.x = ToReal(prop.value); } else if (prop.name == "setup.rightLaserPlaneNormal.y") { rightLaserPlaneNormal.y = ToReal(prop.value); } else if (prop.name == "setup.rightLaserPlaneNormal.z") { rightLaserPlaneNormal.z = ToReal(prop.value); } else if (prop.name == "setup.leftLaserCalibrationTop.x") { leftLaserCalibrationTop.x = ToReal(prop.value); } else if (prop.name == "setup.leftLaserCalibrationTop.y") { leftLaserCalibrationTop.y = ToReal(prop.value); } else if (prop.name == "setup.leftLaserCalibrationBottom.x") { leftLaserCalibrationBottom.x = ToReal(prop.value); } else if (prop.name == "setup.leftLaserCalibrationBottom.y") { leftLaserCalibrationBottom.y = ToReal(prop.value); } else if (prop.name == "setup.rightLaserCalibrationTop.x") { rightLaserCalibrationTop.x = ToReal(prop.value); } else if (prop.name == "setup.rightLaserCalibrationTop.y") { rightLaserCalibrationTop.y = ToReal(prop.value); } else if (prop.name == "setup.rightLaserCalibrationBottom.x") { rightLaserCalibrationBottom.x = ToReal(prop.value); } else if (prop.name == "setup.rightLaserCalibrationBottom.y") { rightLaserCalibrationBottom.y = ToReal(prop.value); } else if (prop.name == "setup.enableLighting") { enableLighting = ToBool(prop.value); } else if (prop.name == "setup.lightingPin") { lightingPin = ToInt(prop.value); } else if (prop.name == "setup.enableAuthentication") { enableAuthentication = ToBool(prop.value); } else if (prop.name == "setup.passwordHash") { passwordHash = prop.value; } } }