Esempio n. 1
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;
}