Ejemplo n.º 1
0
const bool	OTSettings::Set_long(const OTString & strSection, const OTString & strKey, const long	  & lValue,   bool & out_bNewOrUpdate, const OTString & strComment)
{
	if (! strSection.Exists())		{ OTLog::vError("%s: Error: %s is Empty!\n", __FUNCTION__, "strSection"			); OT_ASSERT(false); }
	if (strSection.Compare(""))		{ OTLog::vError("%s: Error: %s is Blank!\n", __FUNCTION__, "strSection"			); OT_ASSERT(false); }

	if (! strKey.Exists())			{ OTLog::vError("%s: Error: %s is Empty!\n", __FUNCTION__, "strKey"				); OT_ASSERT(false); }
	if (strKey.Compare(""))			{ OTLog::vError("%s: Error: %s is Blank!\n", __FUNCTION__, "strKey"				); OT_ASSERT(false); }

	OTString strValue; strValue.Format("%ld",lValue);

	const char * const szComment = (strComment.Exists() && !strComment.Compare("")) ? strComment.Get() : NULL;
	
	OTString strOldValue, strNewValue;
	bool bOldKeyExist, bNewKeyExist;

	// Check if Old Key exists.
	if(! Check_str(strSection,strKey,strOldValue,bOldKeyExist)) return false;

	if (bOldKeyExist)
	{
		if (strValue.Compare(strOldValue))
		{
			out_bNewOrUpdate = false;
			return true;
		}
	}

	// Log to Output Setting Change
	if (! LogChange_str(strSection,strKey,strValue)) return false;

	// Set New Value
	SI_Error rc = p_iniSimple -> SetLongValue(strSection.Get(),strKey.Get(),lValue,szComment,false,true);
	if (0 > rc) return false;

	// Check if the new value is the same as intended.
	if (! Check_str(strSection,strKey,strNewValue,bNewKeyExist)) return false;

	if (bNewKeyExist)
	{
		if (strValue.Compare(strNewValue))
		{
			// Success
			out_bNewOrUpdate = true;
			return true;
		}
	}

	// If we get here, error!
	OT_ASSERT(false);
	return false;
}
Ejemplo n.º 2
0
bool Settings::CheckSet_str(const String& strSection, const String& strKey,
                              const String& strDefault, std::string& out_strResult,
                              bool& out_bIsNew, const String& strComment)
{
    if (!strSection.Exists()) {
        otErr << __FUNCTION__ << ": Error: "
              << "strSection"
              << " is Empty!\n";
        OT_FAIL;
    }
    if (!strKey.Exists()) {
        otErr << __FUNCTION__ << ": Error: "
              << "strKey"
              << " is Empty!\n";
        OT_FAIL;
    }

    const char* const szDefault =
        (strDefault.Exists() && !strDefault.Compare("")) ? strDefault.Get()
                                                         : nullptr;

    String strTempResult;
    bool bKeyExist;
    if (!Check_str(strSection, strKey, strTempResult, bKeyExist)) return false;

    if (bKeyExist) {
        // Already have a key, lets use it's value.
        out_bIsNew = false;
        out_strResult = strTempResult.Get();
        return true;
    }
    else {
        bool bNewKeyCheck;
        if (!Set_str(strSection, strKey, strDefault, bNewKeyCheck, strComment))
            return false;

        if (nullptr == szDefault) // The Default is to have no key.
        {
            // Success
            out_bIsNew = false;
            out_strResult = "";
            return true;
        }

        if (bNewKeyCheck) {
            // Success
            out_bIsNew = true;
            out_strResult = strDefault.Get();
            return true;
        }
    }

    // If we get here, error!
    OT_FAIL;
}
Ejemplo n.º 3
0
const bool	OTSettings::CheckSet_str (const OTString & strSection, const OTString & strKey, const OTString & strDefault, OTString & out_strResult, bool & out_bIsNew, const OTString & strComment)
{
	if (! strSection.Exists())			{ OTLog::vError("%s: Error: %s is Empty!\n", __FUNCTION__, "strSection"			); OT_ASSERT(false); }
	if (! strKey.Exists())				{ OTLog::vError("%s: Error: %s is Empty!\n", __FUNCTION__, "strKey"				); OT_ASSERT(false); }

	const char * const szDefault = (strDefault.Exists() && !strDefault.Compare("")) ? strDefault.Get() : NULL;

	OTString strTempResult;
	bool bKeyExist, bNewKeyCheck;
	if (! Check_str(strSection,strKey,strTempResult,bKeyExist)) return false;

	if (bKeyExist)
	{
		// Already have a key, lets use it's value.
		out_bIsNew = false;
		out_strResult = strTempResult;
		return true;
	}
	else
	{
		if (! Set_str(strSection,strKey,strDefault,bNewKeyCheck,strComment)) return false;

		if (NULL == szDefault) // The Default is to have no key.
		{
			// Success
			out_bIsNew = false;
			out_strResult = "";
			return true;
		}
		
		if (bNewKeyCheck)
		{
			// Success
			out_bIsNew = true;
			out_strResult = strDefault;
			return true;
		}
	}

	// If we get here, error!
	OT_ASSERT(false);
	return false;
}
Ejemplo n.º 4
0
bool Settings::Set_long(const String& strSection, const String& strKey,
                          const int64_t& lValue, bool& out_bNewOrUpdate,
                          const String& strComment)
{
    if (!strSection.Exists()) {
        otErr << __FUNCTION__ << ": Error: "
              << "strSection"
              << " is Empty!\n";
        OT_FAIL;
    }
    if (strSection.Compare("")) {
        otErr << __FUNCTION__ << ": Error: "
              << "strSection"
              << " is Blank!\n";
        OT_FAIL;
    }

    if (!strKey.Exists()) {
        otErr << __FUNCTION__ << ": Error: "
              << "strKey"
              << " is Empty!\n";
        OT_FAIL;
    }
    if (strKey.Compare("")) {
        otErr << __FUNCTION__ << ": Error: "
              << "strKey"
              << " is Blank!\n";
        OT_FAIL;
    }

    String strValue;
    strValue.Format("%" PRId64, lValue);

    const char* const szComment =
        (strComment.Exists() && !strComment.Compare("")) ? strComment.Get()
                                                         : nullptr;

    String strOldValue, strNewValue;
    bool bOldKeyExist, bNewKeyExist;

    // Check if Old Key exists.
    if (!Check_str(strSection, strKey, strOldValue, bOldKeyExist)) return false;

    if (bOldKeyExist) {
        if (strValue.Compare(strOldValue)) {
            out_bNewOrUpdate = false;
            return true;
        }
    }

    // Log to Output Setting Change
    if (!LogChange_str(strSection, strKey, strValue)) return false;

    // Set New Value
    SI_Error rc = pvt->iniSimple.SetLongValue(strSection.Get(), strKey.Get(),
                                              lValue, szComment, false, true);
    if (0 > rc) return false;

    // Check if the new value is the same as intended.
    if (!Check_str(strSection, strKey, strNewValue, bNewKeyExist)) return false;

    if (bNewKeyExist) {
        if (strValue.Compare(strNewValue)) {
            // Success
            out_bNewOrUpdate = true;
            return true;
        }
    }

    // If we get here, error!
    OT_FAIL;
}
Ejemplo n.º 5
0
bool Settings::Set_str(const String& strSection, const String& strKey,
                         const String& strValue, bool& out_bNewOrUpdate,
                         const String& strComment)
{
    if (!strSection.Exists()) {
        otErr << __FUNCTION__ << ": Error: "
              << "strSection"
              << " is Empty!\n";
        OT_FAIL;
    }
    if (strSection.Compare("")) {
        otErr << __FUNCTION__ << ": Error: "
              << "strSection"
              << " is Blank!\n";
        OT_FAIL;
    }

    if (!strKey.Exists()) {
        otErr << __FUNCTION__ << ": Error: "
              << "strKey"
              << " is Empty!\n";
        OT_FAIL;
    }
    if (strKey.Compare("")) {
        otErr << __FUNCTION__ << ": Error: "
              << "strKey"
              << " is Blank!\n";
        OT_FAIL;
    }

    // if (nullptr == m_strConfigurationFileExactPath){ otErr << "%s: Error:
    // %s is a nullptr!\n", __FUNCTION__, "p_iniSimple"); OT_FAIL; }

    const char* const szValue =
        (strValue.Exists() && !strValue.Compare("")) ? strValue.Get() : nullptr;
    const char* const szComment =
        (strComment.Exists() && !strComment.Compare("")) ? strComment.Get()
                                                         : nullptr;

    String strOldValue, strNewValue;
    bool bOldKeyExist, bNewKeyExist;

    // Check if Old Key exists.
    if (!Check_str(strSection, strKey, strOldValue, bOldKeyExist)) return false;

    if (bOldKeyExist) {
        if (strValue.Compare(strOldValue)) {
            out_bNewOrUpdate = false;
            return true;
        }
    }

    // Log to Output Setting Change
    if (!LogChange_str(strSection, strKey, strValue)) return false;

    // Set New Value
    SI_Error rc = pvt->iniSimple.SetValue(strSection.Get(), strKey.Get(),
                                          szValue, szComment, true);
    if (0 > rc) return false;

    if (nullptr == szValue) // We set the key's value to null, thus removing it.
    {
        if (bOldKeyExist)
            out_bNewOrUpdate = true;
        else
            out_bNewOrUpdate = false;

        return true;
    }

    // Check if the new value is the same as intended.
    if (!Check_str(strSection, strKey, strNewValue, bNewKeyExist)) return false;

    if (bNewKeyExist) {
        if (strValue.Compare(strNewValue)) {
            // Success
            out_bNewOrUpdate = true;
            return true;
        }
    }

    // If we get here, error!
    OT_FAIL;
}
Ejemplo n.º 6
0
const bool	OTSettings::Set_str (const OTString & strSection, const OTString & strKey, const OTString & strValue, bool & out_bNewOrUpdate, const OTString & strComment)
{
	if (! strSection.Exists())		{ OTLog::vError("%s: Error: %s is Empty!\n", __FUNCTION__, "strSection"			); OT_ASSERT(false); return false; }
	if (strSection.Compare(""))		{ OTLog::vError("%s: Error: %s is Blank!\n", __FUNCTION__, "strSection"			); OT_ASSERT(false); return false;  }

	if (! strKey.Exists())			{ OTLog::vError("%s: Error: %s is Empty!\n", __FUNCTION__, "strKey"				); OT_ASSERT(false); return false; }
	if (strKey.Compare(""))			{ OTLog::vError("%s: Error: %s is Blank!\n", __FUNCTION__, "strKey"				); OT_ASSERT(false); return false; }

	if (NULL == p_iniSimple)		{ OTLog::vError("%s: Error: %s is a NULL!\n", __FUNCTION__, "p_iniSimple"	); OT_ASSERT(false); return false; }
	//if (NULL == this->m_strConfigurationFileExactPath)		{ OTLog::vError("%s: Error: %s is a NULL!\n", __FUNCTION__, "p_iniSimple"	); OT_ASSERT(false); return false; }

	const char * const szValue	 = (strValue.Exists()	&& !strValue.Compare("")  ) ? strValue.Get()   : NULL;
	const char * const szComment = (strComment.Exists() && !strComment.Compare("")) ? strComment.Get() : NULL;

	OTString strOldValue, strNewValue;
	bool bOldKeyExist, bNewKeyExist;

	// Check if Old Key exists.
	if(! Check_str(strSection,strKey,strOldValue,bOldKeyExist)) return false;

	if (bOldKeyExist)
	{
		if (strValue.Compare(strOldValue))
		{
			out_bNewOrUpdate = false;
			return true;
		}
	}

	// Log to Output Setting Change
	if (! LogChange_str(strSection,strKey,strValue)) return false;

	

	// Set New Value
	SI_Error rc = p_iniSimple -> SetValue(strSection.Get(), strKey.Get(), szValue, szComment, true);
	if (0 > rc) return false;

	if (NULL == szValue)  // We set the key's value to null, thus removing it.
	{
		if (bOldKeyExist) out_bNewOrUpdate = true;
		else out_bNewOrUpdate = false;
		
		return true;
	}

	// Check if the new value is the same as intended.
	if (! Check_str(strSection,strKey,strNewValue,bNewKeyExist)) return false;

	if (bNewKeyExist)
	{
		if (strValue.Compare(strNewValue))
		{
			// Success
			out_bNewOrUpdate = true;
			return true;
		}
	}

	// If we get here, error!
	OT_ASSERT(false);
	return false;
}