139 #include "simpleini/SimpleIni.h"
161 if (!strConfigurationFileExactPath.
Exists()) {
162 otErr << __FUNCTION__ <<
": Error: "
163 <<
"strConfigurationFileExactPath"
168 bool bFolderCreated(
false);
175 otErr << __FUNCTION__ <<
": Bad: "
177 <<
" is not Empty!\n";
189 strConfigurationFileExactPath.
Get());
190 if (0 > rc)
return false;
195 SI_Error rc = pvt->
iniSimple.LoadFile(strConfigurationFileExactPath.
Get());
204 if (!strConfigurationFileExactPath.Exists()) {
205 otErr << __FUNCTION__ <<
": Error: "
206 <<
"strConfigurationFileExactPath"
211 SI_Error rc = pvt->
iniSimple.SaveFile(strConfigurationFileExactPath.Get());
218 bool OTSettings::LogChange_str(
const OTString& strSection,
219 const OTString& strKey,
const OTString& strValue)
221 if (!strSection.Exists()) {
222 otErr << __FUNCTION__ <<
": Error: "
227 if (!strKey.Exists()) {
228 otErr << __FUNCTION__ <<
": Error: "
234 const char*
const szValue = (strValue.Exists() && !strValue.Compare(
""))
238 OTString strCategory, strOption;
242 otWarn <<
"Setting " << strCategory <<
" " << strOption <<
" " << szValue
250 , m_strConfigurationFileExactPath(strConfigFilePath)
252 if (!m_strConfigurationFileExactPath.
Exists()) {
253 otErr << __FUNCTION__ <<
": Error: "
254 <<
"m_strConfigurationFileExactPath"
262 m_strConfigurationFileExactPath.
Set(strConfigFilePath.
Get());
279 if (
Load(m_strConfigurationFileExactPath)) {
289 return Save(m_strConfigurationFileExactPath);
310 OTString& out_strResult,
bool& out_bKeyExist)
const
312 if (!strSection.
Exists()) {
313 otErr << __FUNCTION__ <<
": Error: "
319 otErr << __FUNCTION__ <<
": Error: "
326 otErr << __FUNCTION__ <<
": Error: "
332 otErr << __FUNCTION__ <<
": Error: "
343 out_bKeyExist =
true;
344 out_strResult = strVar;
347 out_bKeyExist =
false;
355 int64_t& out_lResult,
bool& out_bKeyExist)
const
357 if (!strSection.
Exists()) {
358 otErr << __FUNCTION__ <<
": Error: "
364 otErr << __FUNCTION__ <<
": Error: "
371 otErr << __FUNCTION__ <<
": Error: "
377 otErr << __FUNCTION__ <<
": Error: "
388 out_bKeyExist =
true;
393 out_bKeyExist =
false;
401 bool& out_bResult,
bool& out_bKeyExist)
const
403 if (!strSection.
Exists()) {
404 otErr << __FUNCTION__ <<
": Error: "
410 otErr << __FUNCTION__ <<
": Error: "
417 otErr << __FUNCTION__ <<
": Error: "
423 otErr << __FUNCTION__ <<
": Error: "
435 out_bKeyExist =
true;
442 out_bKeyExist =
false;
450 const OTString& strValue,
bool& out_bNewOrUpdate,
453 if (!strSection.
Exists()) {
454 otErr << __FUNCTION__ <<
": Error: "
460 otErr << __FUNCTION__ <<
": Error: "
467 otErr << __FUNCTION__ <<
": Error: "
473 otErr << __FUNCTION__ <<
": Error: "
482 const char*
const szValue =
484 const char*
const szComment =
489 bool bOldKeyExist, bNewKeyExist;
492 if (!
Check_str(strSection, strKey, strOldValue, bOldKeyExist))
return false;
495 if (strValue.
Compare(strOldValue)) {
496 out_bNewOrUpdate =
false;
502 if (!LogChange_str(strSection, strKey, strValue))
return false;
506 szValue, szComment,
true);
507 if (0 > rc)
return false;
509 if (
nullptr == szValue)
512 out_bNewOrUpdate =
true;
514 out_bNewOrUpdate =
false;
520 if (!
Check_str(strSection, strKey, strNewValue, bNewKeyExist))
return false;
523 if (strValue.
Compare(strNewValue)) {
525 out_bNewOrUpdate =
true;
535 const int64_t& lValue,
bool& out_bNewOrUpdate,
538 if (!strSection.
Exists()) {
539 otErr << __FUNCTION__ <<
": Error: "
545 otErr << __FUNCTION__ <<
": Error: "
552 otErr << __FUNCTION__ <<
": Error: "
558 otErr << __FUNCTION__ <<
": Error: "
565 strValue.
Format(
"%lld", lValue);
567 const char*
const szComment =
572 bool bOldKeyExist, bNewKeyExist;
575 if (!
Check_str(strSection, strKey, strOldValue, bOldKeyExist))
return false;
578 if (strValue.
Compare(strOldValue)) {
579 out_bNewOrUpdate =
false;
585 if (!LogChange_str(strSection, strKey, strValue))
return false;
588 SI_Error rc = pvt->
iniSimple.SetLongValue(strSection.
Get(), strKey.
Get(),
589 lValue, szComment,
false,
true);
590 if (0 > rc)
return false;
593 if (!
Check_str(strSection, strKey, strNewValue, bNewKeyExist))
return false;
596 if (strValue.
Compare(strNewValue)) {
598 out_bNewOrUpdate =
true;
608 const bool& bValue,
bool& out_bNewOrUpdate,
611 if (!strSection.
Exists()) {
612 otErr << __FUNCTION__ <<
": Error: "
618 otErr << __FUNCTION__ <<
": Error: "
623 const OTString strValue(bValue ?
"true" :
"false");
625 return Set_str(strSection, strKey, strValue, out_bNewOrUpdate, strComment);
630 bool& out_bIsNewSection)
632 if (!strSection.
Exists()) {
633 otErr << __FUNCTION__ <<
": Error: "
638 if (!strComment.
Exists()) {
639 otErr << __FUNCTION__ <<
": Error: "
645 const char*
const szComment =
649 const int64_t lSectionSize =
652 if (1 > lSectionSize) {
653 out_bIsNewSection =
true;
654 SI_Error rc = pvt->
iniSimple.SetValue(strSection.
Get(),
nullptr,
655 nullptr, szComment,
false);
656 if (0 > rc)
return false;
659 out_bIsNewSection =
false;
667 OTString& out_strResult,
bool& out_bIsNew,
670 if (!strSection.
Exists()) {
671 otErr << __FUNCTION__ <<
": Error: "
677 otErr << __FUNCTION__ <<
": Error: "
683 const char*
const szDefault =
689 if (!
Check_str(strSection, strKey, strTempResult, bKeyExist))
return false;
694 out_strResult = strTempResult;
699 if (!
Set_str(strSection, strKey, strDefault, bNewKeyCheck, strComment))
702 if (
nullptr == szDefault)
713 out_strResult = strDefault;
723 const OTString& strKey,
const int64_t& lDefault,
724 int64_t& out_lResult,
bool& out_bIsNew,
727 if (!strSection.
Exists()) {
728 otErr << __FUNCTION__ <<
": Error: "
734 otErr << __FUNCTION__ <<
": Error: "
742 if (!
Check_long(strSection, strKey, lTempResult, bKeyExist))
return false;
747 out_lResult = lTempResult;
752 if (!
Set_long(strSection, strKey, lDefault, bNewKeyCheck, strComment))
757 out_lResult = lDefault;
767 const OTString& strKey,
const bool& bDefault,
768 bool& out_bResult,
bool& out_bIsNew,
771 if (!strSection.
Exists()) {
772 otErr << __FUNCTION__ <<
": Error: "
778 otErr << __FUNCTION__ <<
": Error: "
784 bool bKeyExist, bTempResult;
785 if (!
Check_bool(strSection, strKey, bTempResult, bKeyExist))
return false;
790 out_bResult = bTempResult;
795 if (!
Set_bool(strSection, strKey, bDefault, bNewKeyCheck, strComment))
800 out_bResult = bDefault;
810 const OTString& strKey,
bool& bVariableName)
813 return CheckSet_bool(strSection, strKey, bVariableName, bVariableName,
static EXPORT bool FileExists(const OTString &strFilePath, int64_t &nFileLength)
EXPORT bool Check_str(const OTString &strSection, const OTString &strKey, OTString &out_strResult, bool &out_bKeyExist) const
EXPORT bool Set_bool(const OTString &strSection, const OTString &strKey, const bool &bValue, bool &out_bNewOrUpdate, const OTString &strComment="")
EXPORT bool Exists() const
EXPORT void Format(const char *fmt,...)
EXPORT bool IsEmpty() const
EXPORT bool Compare(const char *compare) const
EXPORT void Set(const char *data, uint32_t enforcedMaxLength=0)
EXPORT bool Set_long(const OTString &strSection, const OTString &strKey, const int64_t &lValue, bool &out_bNewOrUpdate, const OTString &strComment="")
EXPORT bool Set_str(const OTString &strSection, const OTString &strKey, const OTString &strValue, bool &out_bNewOrUpdate, const OTString &strComment="")
static EXPORT bool BuildFilePath(const OTString &strFolderPath, bool &out_bFolderCreated)
EXPORT bool CheckSet_str(const OTString &strSection, const OTString &strKey, const OTString &strDefault, OTString &out_strResult, bool &out_bIsNew, const OTString &strComment="")
EXPORT bool Check_bool(const OTString &strSection, const OTString &strKey, bool &out_bResult, bool &out_bKeyExist) const
OTLOG_IMPORT OTLogStream otWarn
EXPORT const char * Get() const
EXPORT bool SetOption_bool(const OTString &strSection, const OTString &strKey, bool &bVariableName)
OTLOG_IMPORT OTLogStream otErr
EXPORT bool CheckSet_long(const OTString &strSection, const OTString &strKey, const int64_t &lDefault, int64_t &out_lResult, bool &out_bIsNew, const OTString &strComment="")
EXPORT bool Check_long(const OTString &strSection, const OTString &strKey, int64_t &out_lResult, bool &out_bKeyExist) const
EXPORT bool CheckSetSection(const OTString &strSection, const OTString &strComment, bool &out_bIsNewSection)
EXPORT const bool & IsLoaded() const
static EXPORT bool StringFill(OTString &out_strString, const char *szString, int32_t iLength, const char *szAppend=nullptr)
EXPORT void SetConfigFilePath(const OTString &strConfigFilePath)
EXPORT bool CheckSet_bool(const OTString &strSection, const OTString &strKey, const bool &bDefault, bool &out_bResult, bool &out_bIsNew, const OTString &strComment="")