Beispiel #1
0
void INI::save_file(const chowstring & fn, bool force)
{
    if (fn.empty() || (read_only && !force))
        return;
    changed = false;
    filename = convert_path(fn);
    std::cout << "Saving: " << filename << std::endl;
    platform_create_directories(get_path_dirname(filename));
    std::stringstream out;
    get_data(out);
    chowstring outs = out.str();

    if (!encrypt_key.empty())
        encrypt_ini_data(outs, encrypt_key);

    if (use_compression) {
        compress_huffman(outs, filename.c_str());
        return;
    }

#ifdef CHOWDREN_USE_BLOWFISH_CACHE
    if (BlowfishObject::set_cache(filename, outs))
        return;
#endif

    FSFile fp(filename.c_str(), "w");
    if (!fp.is_open()) {
        std::cout << "Could not save INI file: " << filename << std::endl;
        return;
    }
	if (!outs.empty())
        fp.write(&outs[0], outs.size());
    fp.close();
}
Beispiel #2
0
static struct purple_pref *
find_pref_parent(const char *name)
{
	char *parent_name = get_path_dirname(name);
	struct purple_pref *ret = &prefs;

	if(!purple_strequal(parent_name, "/")) {
		ret = find_pref(parent_name);
	}

	g_free(parent_name);
	return ret;
}
Beispiel #3
0
void INI::load_file(const chowstring & fn, bool read_only, bool merge,
                    bool overwrite)
{
    chowstring new_filename = convert_path(fn);
#ifdef CHOWDREN_CACHE_INI
    if (new_filename == filename)
        return;
#endif

#ifndef CHOWDREN_AUTOSAVE_ON_CHANGE
    if (auto_save && changed)
        save_file(false);
#endif

    this->read_only = read_only;
    filename = new_filename;

#ifdef CHOWDREN_USE_BLOWFISH_CACHE
    const chowstring & cache = BlowfishObject::get_cache(filename);
    if (!cache.empty()) {
        std::cout << "Using Blowfish cache for " << filename << std::endl;
        load_string(cache, merge);
        return;
    }
#endif

#ifdef CHOWDREN_CACHE_INI
    chowstring cache_key = filename;
    to_lower(cache_key);
    data = &ini_cache[cache_key];
    is_global = true;
    if (!data->empty())
        return;
#else
    if (!merge)
        reset(false);
#endif

    std::cout << "Loading " << filename << " (" << get_name() << ")"
        << std::endl;
    platform_create_directories(get_path_dirname(filename));

    chowstring new_data;
    if (!encrypt_key.empty() || use_compression) {
        bool decompressed = false;

        if (use_compression) {
            if (decompress_huffman(filename.c_str(), new_data))
                decompressed = true;
        }

        if (!use_compression || !decompressed) {
            if (!read_file(filename.c_str(), new_data))
                return;
        }

        if (!encrypt_key.empty()) {
            encrypt_ini_data(new_data, encrypt_key);
        }
    } else {
        if (!read_file(filename.c_str(), new_data))
            return;
    }

    int e = ini_parse_string(new_data, _parse_handler, this);
    if (e != 0) {
        std::cout << "INI load failed (" << filename << ") with code " << e
            << std::endl;
    }
}