Exemplo n.º 1
0
bool ConfigManager::save() {
	if (!_config)
		return true;

	if (!getBool("saveconf", true))
		return true;

	// Create the directories in the path, if necessary
	UString file = FilePath::canonicalize(getConfigFile());

	try {
		FilePath::createDirectories(FilePath::getDirectory(file));

		// Open and save the config
		WriteFile config;
		if (!config.open(file))
			throw Exception(kOpenError);

		save(config, true);

	} catch (...) {
		exceptionDispatcherWarning("Failed saving config file \"%s\"", file.c_str());
		return false;
	}

	return true;
}
Exemplo n.º 2
0
bool ConfigManager::load() {
	clear();

	// Check that the config file actually exists.
	UString file = getConfigFile();
	if (!FilePath::isRegularFile(file))
		return false;

	try {

		// Open and load the config
		ReadFile config;
		if (!config.open(file))
			throw Exception(kOpenError);

		_config = new ConfigFile;
		_config->load(config);

		// Get the application domain
		_domainApp = _config->addDomain(kDomainApp);

	} catch (...) {
		exceptionDispatcherWarning("Failed loading config file \"%s\"", file.c_str());
		return false;
	}

	return true;
}
Exemplo n.º 3
0
uint ConfigDomain::getUint(const UString &key, uint def) const {
	UString value;
	if (!getKey(key, value))
		return def;

	uint x = def;
	try {
		parseString(value, x);
	} catch (...) {
		exceptionDispatcherWarning();
	}

	return x;
}
Exemplo n.º 4
0
bool ConfigDomain::getBool(const UString &key, bool def) const {
	UString value;
	if (!getKey(key, value))
		return def;

	bool x = def;
	try {
		parseString(value, x);
	} catch (...) {
		exceptionDispatcherWarning();
	}

	return x;
}
Exemplo n.º 5
0
double ConfigDomain::getDouble(const UString &key, double def) const {
	UString value;
	if (!getKey(key, value))
		return def;

	double x = def;
	try {
		parseString(value, x);
	} catch (...) {
		exceptionDispatcherWarning();
	}

	return x;
}