コード例 #1
0
ファイル: CacheSettingsWidget.cpp プロジェクト: Chiru/naali
    void CacheSettingsWidget::SettingsSaved()
    {
        // Update asset config
        int new_asset_cache_limit = spinBox_assets->value()*1024*1024;
        if (new_asset_cache_limit != current_assets_max_size_)
        {
            current_assets_max_size_ = new_asset_cache_limit;
            QSettings cache_config(QSettings::IniFormat, QSettings::UserScope, APPLICATION_NAME, "configuration/CacheSettings");
            cache_config.beginGroup("AssetCache");
            cache_config.setValue("MaxSize", current_assets_max_size_);
            cache_config.endGroup();
            cache_config.sync();

            // Emit new asset cache values
            emit AssetSettingsSaved(current_assets_max_size_);
        }
        
        // Update texture config
        int new_texture_cache_limit = spinBox_textures->value()*1024*1024;
        bool new_cache_evertything = !checkBox_decode_only_jpeg2000->isChecked();
        if (new_cache_evertything != current_textures_cache_everything_ || new_texture_cache_limit != current_textures_max_size_)
        {
            current_textures_cache_everything_ = new_cache_evertything;
            current_textures_max_size_ = new_texture_cache_limit;

            QSettings cache_config(QSettings::IniFormat, QSettings::UserScope, APPLICATION_NAME, "configuration/CacheSettings");
            cache_config.beginGroup("TextureCache");
            cache_config.setValue("CacheEverything", current_textures_cache_everything_);
            cache_config.setValue("MaxSize", current_textures_max_size_);
            cache_config.endGroup();
            cache_config.sync();
    
            // Emit new texture cache values
            emit TextureSettingsSaved(current_textures_max_size_, current_textures_cache_everything_);
        }
    }
コード例 #2
0
ファイル: CacheSettingsWidget.cpp プロジェクト: Chiru/naali
    void CacheSettingsWidget::ReadConfig()
    {
        bool default_textures_cache_everything = false;
        int default_textures_max_size = 500*1024*1024;
        int default_assets_max_size = 300*1024*1024;

        // Init config file if file/segments doesent exist
        QSettings cache_config(QSettings::IniFormat, QSettings::UserScope, APPLICATION_NAME, "configuration/CacheSettings");
        QString segment = "AssetCache";
        QFile config_file(cache_config.fileName());
        if (!config_file.exists())
        {
            cache_config.beginGroup("TextureCache");
            cache_config.setValue("CacheEverything", default_textures_cache_everything);
            cache_config.setValue("MaxSize", default_textures_max_size);
            cache_config.endGroup();

            cache_config.beginGroup("AssetCache");
            cache_config.setValue("MaxSize", default_assets_max_size);
            cache_config.endGroup();
            cache_config.sync();
        }
        else if (!cache_config.childGroups().contains("TextureCache"))
        {
            cache_config.beginGroup("TextureCache");
            cache_config.setValue("CacheEverything", default_textures_cache_everything);
            cache_config.setValue("MaxSize", default_textures_max_size);
            cache_config.endGroup();
            cache_config.sync();
        }
        else if (!cache_config.childGroups().contains("AssetCache"))
        {
            cache_config.beginGroup("AssetCache");
            cache_config.setValue("MaxSize", default_assets_max_size);
            cache_config.endGroup();
            cache_config.sync();
        }

        // Read config and update ui with them
        // Note: The key-value pairs might not be there even if the segment exists, lets do one more set of checks
        QVariant val;
        segment = "TextureCache/CacheEverything";
        val = cache_config.value(segment);
        if (val.isNull())
        {
            cache_config.setValue(segment, default_textures_cache_everything);
            current_textures_cache_everything_ = default_textures_cache_everything;
        }
        else
            current_textures_cache_everything_ = val.toBool();

        segment = "TextureCache/MaxSize";
        val = cache_config.value(segment);
        if (val.isNull())
        {
            cache_config.setValue(segment, default_textures_max_size);
            current_textures_max_size_ = default_textures_max_size;
        }
        else
            current_textures_max_size_ = val.toInt();
        
        segment = "AssetCache/MaxSize";
        val = cache_config.value(segment);
        if (val.isNull())
        {
            cache_config.setValue(segment, default_assets_max_size);
            current_assets_max_size_ = default_assets_max_size;
        }
        else
            current_assets_max_size_ = val.toInt();

        cache_config.sync();
    }
コード例 #3
0
ファイル: global.c プロジェクト: 503serviceunavailable/magma
/**
 * @brief	Load all magma configuration options specified by the user on the command line.
 * @note	Each key/value pair extracted from the database is submitted to the following logic:
 *	 			If a config option was loaded from the database, the key must allow it to be configurable via the database.
 *	 			Check to see that any key that has previously been set is allowed to be overwritten.
 * 				If the key is required, it may not contain an empty value.
 * 			Finally, this function sets the appropriate magma key corresponding to the config key.
 * 			All leftover keys not matched to global magma keys will be configured via servers, relay, and cache server options.
 * @return	true if all database config options were parsed and evaluated successfully, or false on failure.
 */
bool_t config_load_cmdline_settings(void) {
	multi_t name;
	magma_keys_t *key;
	inx_cursor_t *cursor;
	nvp_t *config_pairs = NULL;
	stringer_t *value;

	// If not set, then bail out.
	if (!cmdline_config_data)
		return true;

	// Load the command line options and convert them into a name/value pair structure.
	if (!(config_pairs = nvp_alloc())) {
		st_free(cmdline_config_data);
		return false;
	}
	else if (nvp_parse(config_pairs, cmdline_config_data) < 0) {
		nvp_free(config_pairs);
		st_free(cmdline_config_data);
		return false;
	}
	else if (!(cursor = inx_cursor_alloc(config_pairs->pairs))) {
		nvp_free(config_pairs);
		st_free(cmdline_config_data);
		return false;
	}

	// Our command line config data won't be necessary anymore.
	st_free(cmdline_config_data);

	// Run through all of the magma_keys and see if there is a matching name/value pair.
	while (!mt_is_empty(name = inx_cursor_key_next(cursor))) {

		value = inx_cursor_value_active(cursor);

		if ((key = config_key_lookup(name.val.st))) {

			// Make sure the setting can be provided via the configuration file.
			if (!key->file && value) {
					log_critical("%s cannot be changed using command line option.", key->name);
					inx_cursor_free(cursor);
					nvp_free(config_pairs);
					return false;
			}
			// Make sure the required magma_keys are not set to NULL.
			else if (key->required && st_empty(value)) {
				log_critical("%s requires a legal value.", key->name);
				inx_cursor_free(cursor);
				nvp_free(config_pairs);
				return false;
			}

			// Attempt to set the value.
			else if (!config_value_set(key, value)) {
				inx_cursor_free(cursor);
				nvp_free(config_pairs);
				return false;
			}

			// If a legit value was provided, then record that we've set this parameter.
			key->set = true;
		}

		// If we haven't had a match yet, check if its a server param.
		else if (name.val.st && !st_cmp_ci_starts(name.val.st, CONSTANT("magma.servers"))) {
			servers_config(name.val.st, value);
		}

		// If we haven't had a match yet, check if its a relay instance.
		else if (name.val.st && !st_cmp_ci_starts(name.val.st, CONSTANT("magma.relay"))) {
			relay_config(name.val.st, value);
		}

		else if (name.val.st && !st_cmp_ci_starts(name.val.st, CONSTANT("magma.iface.cache.host"))) {
			cache_config(name.val.st, value);
		}

		else {
			log_critical("%.*s is not a valid setting.", st_length_int(name.val.st), st_char_get(name.val.st));
			inx_cursor_free(cursor);
			nvp_free(config_pairs);
			return false;
		}
	}

	inx_cursor_free(cursor);
	nvp_free(config_pairs);

	return true;
}
コード例 #4
0
ファイル: global.c プロジェクト: 503serviceunavailable/magma
/**
 * @brief	Load all magma configuration options present in the database.
 * @note	Each key/value pair extracted from the database is submitted to the following logic:
 *	 			If a config option was loaded from the database, the key must allow it to be configurable via the database.
 *	 			Check to see that any key that has previously been set is allowed to be overwritten.
 * 				If the key is required, it may not contain an empty value.
 * 			Finally, this function sets the appropriate magma key corresponding to the config key.
 * 			All leftover keys not matched to global magma keys will be configured via servers, relay, and cache server options.
 * @return	true if all database config options were parsed and evaluated successfully, or false on failure.
 */
bool_t config_load_database_settings(void) {

	row_t *row;
	uint64_t rows;
	magma_keys_t *key;
	table_t *database_pairs;
	stringer_t *value, *name;

	if (!(magma.host.number = config_fetch_host_number()) || !(database_pairs = config_fetch_settings())) {
		return false;
	}

	// Loop through each of the row returned.
	rows = res_row_count(database_pairs);
	for (uint64_t i = 0; i < rows && (row = res_row_get(database_pairs, i)); i++) {

			name = PLACER(res_field_block(row, 0), res_field_length(row, 0));
			value = PLACER(res_field_block(row, 1), res_field_length(row, 1));

			if ((key = config_key_lookup(name))) {
				// Make sure the setting can be provided via the database.
				if (!key->database) {
					log_critical("%s cannot be changed using the database.", key->name);
					res_table_free(database_pairs);
					return false;
				}

				// Make sure the setting can be provided via the database.
				else if (key->set && !key->overwrite) {
					log_critical("%s has already been set and cannot be overwritten.", key->name);
					res_table_free(database_pairs);
					return false;
				}

				// Make sure the required magma_keys are not set to NULL.
				else if (key->required && st_empty(value)) {
					log_critical("%s requires a legal value.", key->name);
					res_table_free(database_pairs);
					return false;
				}

				// Attempt to set the value.
				else if (!config_value_set(key, value)) {
					res_table_free(database_pairs);
					return false;
				}

				// Record that we've set this parameter.
				key->set = true;
			}

			// If we haven't had a match yet, check if its a server param.
			else if (!st_cmp_ci_starts(name, CONSTANT("magma.servers"))) {
				servers_config(name, value);
			}

			// If we haven't had a match yet, check if its a relay instance.
			else if (!st_cmp_ci_starts(name, CONSTANT("magma.relay"))) {
				relay_config(name, value);
			}

			else if (!st_cmp_ci_starts(name, CONSTANT("magma.iface.cache.host"))) {
				cache_config(name, value);
			}

			// Otherwise if we still haven't matched a value, report an error.
			else {
				log_critical("%.*s is not a valid setting.", st_length_int(name), st_char_get(name));
				res_table_free(database_pairs);
				return false;
			}

	}

	res_table_free(database_pairs);
	return true;
}