예제 #1
0
파일: Config.cpp 프로젝트: pnedev/nppgtags
/**
 *  \brief
 */
bool Settings::Save() const
{
    CPath cfgFile;
    INpp::Get().GetPluginsConfDir(cfgFile);
    cfgFile += cPluginCfgFileName;

    FILE* fp;
    _tfopen_s(&fp, cfgFile.C_str(), _T("wt"));
    if (fp == NULL)
        return false;

    bool success = false;
    if (_ftprintf_s(fp, _T("%s\n"), cInfo) > 0)
    if (_ftprintf_s(fp, _T("%s%s\n"), cUseDefDbKey, (_useDefDb ? _T("yes") : _T("no"))) > 0)
    if (_ftprintf_s(fp, _T("%s%s\n"), cDefDbPathKey, _defDbPath.C_str()) > 0)
    if (_ftprintf_s(fp, _T("%s%s\n"), cREOptionKey, (_re ? _T("yes") : _T("no"))) > 0)
    if (_ftprintf_s(fp, _T("%s%s\n\n"), cICOptionKey, (_ic ? _T("yes") : _T("no"))) > 0)
    if (_genericDbCfg.Write(fp))
        success = true;

    fclose(fp);

    if (success)
        _dirty = false;

    return success;
}
예제 #2
0
파일: Config.cpp 프로젝트: pnedev/nppgtags
/**
 *  \brief
 */
bool Settings::Load()
{
    SetDefaults();

    CPath cfgFile;
    INpp::Get().GetPluginsConfDir(cfgFile);
    cfgFile += cPluginCfgFileName;

    if (!cfgFile.FileExists())
        return false;

    FILE* fp;
    _tfopen_s(&fp, cfgFile.C_str(), _T("rt"));
    if (fp == NULL)
        return false;

    bool success = true;

    TCHAR line[8192];
    while (_fgetts(line, _countof(line), fp))
    {
        // Comment or empty line
        if (line[0] == _T('#') || line[0] == _T('\n'))
            continue;

        // Strip newline from the end of the line
        line[_tcslen(line) - 1] = 0;

        if (!_tcsncmp(line, cUseDefDbKey, _countof(cUseDefDbKey) - 1))
        {
            const unsigned pos = _countof(cUseDefDbKey) - 1;
            if (!_tcsncmp(&line[pos], _T("yes"), _countof(_T("yes")) - 1))
                _useDefDb = true;
            else
                _useDefDb = false;
        }
        else if (!_tcsncmp(line, cDefDbPathKey, _countof(cDefDbPathKey) - 1))
        {
            const unsigned pos = _countof(cDefDbPathKey) - 1;
            _defDbPath = &line[pos];
            _defDbPath.AsFolder();
            if (!_defDbPath.Exists())
                _defDbPath.Clear();
        }
        else if (!_tcsncmp(line, cREOptionKey, _countof(cREOptionKey) - 1))
        {
            const unsigned pos = _countof(cREOptionKey) - 1;
            if (!_tcsncmp(&line[pos], _T("yes"), _countof(_T("yes")) - 1))
                _re = true;
            else
                _re = false;
        }
        else if (!_tcsncmp(line, cICOptionKey, _countof(cICOptionKey) - 1))
        {
            const unsigned pos = _countof(cICOptionKey) - 1;
            if (!_tcsncmp(&line[pos], _T("yes"), _countof(_T("yes")) - 1))
                _ic = true;
            else
                _ic = false;
        }
        else if (!_genericDbCfg.ReadOption(line))
        {
            success = false;
            SetDefaults();
            break;
        }
    }

    fclose(fp);

    return success;
}