void Config::saveStateCache()
{
    Eet_File *ef;
    std::string file = Utils::getCacheFile("iostates.cache");
    std::string tmp = file + "_tmp";
    ConfigStateCache *cache;

    cache = new ConfigStateCache;
    cache->version = CONFIG_STATES_CACHE_VERSION;
    cache->states = cache_states;

    ef = eet_open(tmp.c_str(), EET_FILE_MODE_WRITE);
    if (!ef)
    {
        cWarning() <<  "Could not open iostates.cache for write !";
        delete cache;
        return;
    }

    Eina_Bool ret = eet_data_write(ef, edd_cache, "calaos/states/cache", cache, EINA_TRUE);

    eet_close(ef);
    delete cache;

    if (ret)
    {
        ecore_file_unlink(file.c_str());
        ecore_file_mv(tmp.c_str(), file.c_str());
    }

    cInfo() <<  "State cache file written successfully (" << file << ")";
}
Exemplo n.º 2
0
static Eina_Bool
_ephoto_on_config_save(void *data)
{
   Ephoto *ephoto = data;
   Eet_File *ef;
   char buf[4096], buf2[4096];

   snprintf(buf, sizeof(buf), "%s/.config/ephoto/ephoto.cfg", getenv("HOME"));
   snprintf(buf2, sizeof(buf2), "%s.tmp", buf);

   ef = eet_open(buf2, EET_FILE_MODE_WRITE);
   if (!ef) goto save_end;

   eet_data_write(ef, edd, "config", ephoto->config, 1);
   if (eet_close(ef)) goto save_end;

   if (!ecore_file_mv(buf2, buf)) goto save_end;

   INF("Config saved");

save_end:
   ecore_file_unlink(buf2);

   if (save_timer)
     {
        ecore_timer_del(save_timer);
        save_timer = NULL;
     }

   return ECORE_CALLBACK_CANCEL;
}
void Config::SaveConfigRule()
{
    std::string file = Utils::getConfigFile(RULES_CONFIG);
    std::string tmp = file + "_tmp";

    cInfo() <<  "Saving " << file << "...";

    TiXmlDocument document;
    TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "UTF-8", "");
    TiXmlElement *rulesnode = new TiXmlElement("calaos:rules");
    rulesnode->SetAttribute("xmlns:calaos", "http://www.calaos.fr");
    document.LinkEndChild(decl);
    document.LinkEndChild(rulesnode);

    for (int i = 0;i < ListeRule::Instance().size();i++)
    {
        Rule *rule = ListeRule::Instance().get_rule(i);
        rule->SaveToXml(rulesnode);
    }

    if (document.SaveFile(tmp))
    {
        ecore_file_unlink(file.c_str());
        ecore_file_mv(tmp.c_str(), file.c_str());
    }

    cInfo() <<  "Done.";
}