Exemple #1
0
bool ConfigFile::saveToFile(const String &filename) {
	DumpFile file;
	if (file.open(filename))
		return saveToStream(file);
	else
		return false;
}
Exemple #2
0
bool ConfigManager::save() {
	if (!_config)
		return true;

	UString file = getConfigFile();

	try {

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

		_config->save(config);

	} catch (Exception &e) {
		e.add("Failed saving config file \"%s\"", file.c_str());
		printException(e, "WARNING: ");
		return false;
	}

	// We saved our changes, so we're no in a not-changed state again
	_changed = false;

	return true;
}
Exemple #3
0
void ConfigManager::flushToDisk() {
#ifndef __DC__
	WriteStream *stream;

	if (_filename.empty()) {
		// Write to the default config file
		assert(g_system);
		stream = g_system->createConfigWriteStream();
		if (!stream)    // If writing to the config file is not possible, do nothing
			return;
	} else {
		DumpFile *dump = new DumpFile();
		assert(dump);

		if (!dump->open(_filename)) {
			warning("Unable to write configuration file: %s", _filename.c_str());
			delete dump;
			return;
		}

		stream = dump;
	}

	// Write the application domain
	writeDomain(*stream, kApplicationDomain, _appDomain);

#ifdef ENABLE_KEYMAPPER
	// Write the keymapper domain
	writeDomain(*stream, kKeymapperDomain, _keymapperDomain);
#endif

	DomainMap::const_iterator d;

	// Write the miscellaneous domains next
	for (d = _miscDomains.begin(); d != _miscDomains.end(); ++d) {
		writeDomain(*stream, d->_key, d->_value);
	}

	// First write the domains in _domainSaveOrder, in that order.
	// Note: It's possible for _domainSaveOrder to list domains which
	// are not present anymore, so we validate each name.
	Array<String>::const_iterator i;
	for (i = _domainSaveOrder.begin(); i != _domainSaveOrder.end(); ++i) {
		if (_gameDomains.contains(*i)) {
			writeDomain(*stream, *i, _gameDomains[*i]);
		}
	}

	// Now write the domains which haven't been written yet
	for (d = _gameDomains.begin(); d != _gameDomains.end(); ++d) {
		if (find(_domainSaveOrder.begin(), _domainSaveOrder.end(), d->_key) == _domainSaveOrder.end())
			writeDomain(*stream, d->_key, d->_value);
	}

	delete stream;

#endif // !__DC__
}