Ejemplo n.º 1
0
// static
bool OTPaths::Set(OTSettings& config, const String& strSection,
                  const String& strKey, const String& strValue,
                  const bool& bIsRelative, bool& out_bIsNewOrUpdated,
                  const String& strComment)
{
    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_bIsNewOrUpdated = false;

    const bool bPreLoaded(config.IsLoaded());

    if (!bPreLoaded) // we only need to load, if not already loaded.
    {
        config.Reset();
        if (!config.Load()) {
            OT_FAIL;
        }
    }

    bool bBoolIsNew(false);
    String strRelativeKey("");

    strRelativeKey.Format("%s%s", strKey.Get(), OT_CONFIG_ISRELATIVE);

    if (config.Set_bool(strSection, strRelativeKey, bIsRelative, bBoolIsNew,
                        strComment)) {
        bool bStringIsNew = false;
        if (config.Set_str(strSection, strKey, strValue, bStringIsNew)) {
            if (bBoolIsNew && bStringIsNew) // using existing key
            {
                out_bIsNewOrUpdated = true;
            }

            if (!bPreLoaded) {
                if (!config.Save()) {
                    OT_FAIL;
                }
                config.Reset();
            }

            return true;
        }
    }

    // if we get here, there has been a error!
    OT_FAIL;
}
Ejemplo n.º 2
0
const bool OTPaths::Set(
	OTSettings * pConfig,
	const				  OTString	  & strSection,
	const				  OTString	  & strKey,
	const				  OTString	  & strValue,
	const				  bool		  & bIsRelative,
	bool		& out_bIsNewOrUpdated,
	const				  OTString	  & strComment
	)
{
	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_bIsNewOrUpdated = false;

	if (NULL == pConfig)  { OT_ASSERT(false); return false; }

	const bool bPreLoaded(pConfig->IsLoaded());

	if (!bPreLoaded)  // we only need to load, if not already loaded.
	{
		pConfig->Reset();
		if(!pConfig->Load()) { OT_ASSERT(false); return false; }
	}

	bool bBoolIsNew(false), bStringIsNew(false);
	OTString  strRelativeKey("");

	strRelativeKey.Format("%s%s",strKey.Get(),OT_CONFIG_ISRELATIVE);

	if(pConfig->Set_bool(strSection,strRelativeKey,bIsRelative,bBoolIsNew,strComment))
	{
		if(pConfig->Set_str(strSection,strKey,strValue,bStringIsNew))
		{
			if(bBoolIsNew && bStringIsNew) //using existing key
			{
				out_bIsNewOrUpdated = true;
			}

			if (!bPreLoaded)
			{
				if(!pConfig->Save()) { OT_ASSERT(false); return false; }
				pConfig->Reset();
			}

			return true;
		}
	}

	// if we get here, there has been a error!
	OT_ASSERT(false);
	pConfig->Reset();
	return false;
}
Ejemplo n.º 3
0
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;
}
Ejemplo n.º 4
0
// 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;
}