예제 #1
0
RegexpData::RegexpData() {
    Json::Value root = loadJSONFile(RegexpData::REGEXPS_FILE);

    for(const auto& key: root.getMemberNames()) {
        m_regexpMap[key] = root[key].asString();
    }
}
예제 #2
0
Session::Session(std::string file)
{
    local_file = file;

    QFileInfo q_file(local_file.c_str());
    std::string date = q_file.absoluteDir().dirName().toStdString();

    root = loadJSONFile(local_file.c_str());
    loadFromJSON();

    setDate(date);
}
예제 #3
0
ConfigFile::ConfigFile(std::string path)
{
    this->path = path;

    std::cout << "Loading file at " << path << std::endl;

    root = loadJSONFile(path.c_str());

    if(root.empty())
    {
        //Invalid file
        generateFile();
    }
    else
    {
        //File is valid
        loadConfig();
    }
}
예제 #4
0
void Tulpa::loadByName(std::string name, bool load_sessions)
{
    this->name = name;
    local_file = std::string(TULPA_FOLDER) + this->name + std::string(".json");
    checkFolder(getFolder(local_file));

    this->name[0] = toupper(this->name[0]);

    unsigned int i=0;

    if(!checkFile(local_file))
    {
        root["personality_traits"] = Json::arrayValue;
        root["name"] = this->name;
        root["birth_time"] = (int)time(NULL);
        root["first_word_time"] = 0;

        saveJSONFile(root,local_file.c_str());
    }

    root = loadJSONFile(local_file.c_str());

    personality_traits.clear();

    while(root["personality_traits"][i] != Json::nullValue)
    {
        addPersonalityTrait(root["personality_traits"][i].asString());
        i++;
    }

    if(load_sessions)
    {
        i=0;
        while(root["session_id"][i] != Json::nullValue)
        {
            loadSession(root["session_id"][i].asInt());
            i++;
        }
    }

    birth_time = root["birth_time"].asString();
    first_word_time = root["first_word_time"].asString();
}
예제 #5
0
Project::Project(std::string configFilePath, QObject *parent) : QObject(parent)
{
    this->configFile = new QFile(configFilePath.c_str());
    QFileInfo fileInfo(configFile->fileName());

    if(configFile->exists())
    {
        //The file exists
        if (!configFile->open(QIODevice::ReadOnly))
        {
            QMessageBox::information(0,"Error","Failed to open configuration file " + configFile->fileName());
            //The file can't be read
            qDebug()<<"Failed to open configuration file "<<configFile->fileName();
        }
        else
        {
            //Continue loading
            this->rootFolder = fileInfo.absoluteDir();
            Json::Value root = loadJSONFile(configFile->fileName().toStdString().c_str());
            loadConfig(root);
        }
    }
}