Beispiel #1
0
bool ConfigFile::saveToStream(WriteStream &stream) {
	for (List<Section>::iterator i = _sections.begin(); i != _sections.end(); ++i) {
		// Write out the section comment, if any
		if (! i->comment.empty()) {
			stream.writeString(i->comment);
		}

		// Write out the section name
		stream.writeByte('[');
		stream.writeString(i->name);
		stream.writeByte(']');
		stream.writeByte('\n');

		// Write out the key/value pairs
		for (List<KeyValue>::iterator kv = i->keys.begin(); kv != i->keys.end(); ++kv) {
			// Write out the comment, if any
			if (! kv->comment.empty()) {
				stream.writeString(kv->comment);
			}
			// Write out the key/value pair
			stream.writeString(kv->key);
			stream.writeByte('=');
			stream.writeString(kv->value);
			stream.writeByte('\n');
		}
	}

	stream.flush();
	return !stream.err();
}
Beispiel #2
0
void FoxPro::saveRecords(WriteStream &dbf) const {
	// Write the records
	for (size_t i = 0; i < _records.size(); i++) {
		const Record &record = _records[i];

		dbf.writeByte(record.deleted ? '*' : ' ');

		for (size_t j = 0; j < _fields.size(); j++)
			dbf.write(record.fields[j], _fields[j].size);
	}

	dbf.writeByte(0x1A); // Records end marker
}
Beispiel #3
0
void ConfigManager::writeDomain(WriteStream &stream, const String &name, const Domain &domain) {
	if (domain.empty())
		return;     // Don't bother writing empty domains.

	// WORKAROUND: Fix for bug #1972625 "ALL: On-the-fly targets are
	// written to the config file": Do not save domains that came from
	// the command line
	if (domain.contains("id_came_from_command_line"))
		return;

	String comment;

	// Write domain comment (if any)
	comment = domain.getDomainComment();
	if (!comment.empty())
		stream.writeString(comment);

	// Write domain start
	stream.writeByte('[');
	stream.writeString(name);
	stream.writeByte(']');
#ifdef _WIN32
	stream.writeByte('\r');
	stream.writeByte('\n');
#else
	stream.writeByte('\n');
#endif

	// Write all key/value pairs in this domain, including comments
	Domain::const_iterator x;
	for (x = domain.begin(); x != domain.end(); ++x) {
		if (!x->_value.empty()) {
			// Write comment (if any)
			if (domain.hasKVComment(x->_key)) {
				comment = domain.getKVComment(x->_key);
				stream.writeString(comment);
			}
			// Write the key/value pair
			stream.writeString(x->_key);
			stream.writeByte('=');
			stream.writeString(x->_value);
#ifdef _WIN32
			stream.writeByte('\r');
			stream.writeByte('\n');
#else
			stream.writeByte('\n');
#endif
		}
	}
#ifdef _WIN32
	stream.writeByte('\r');
	stream.writeByte('\n');
#else
	stream.writeByte('\n');
#endif
}
Beispiel #4
0
void FoxPro::saveFields(WriteStream &dbf) const {
	for (size_t i = 0; i < _fields.size(); i++) {
		const Field &field = _fields[i];

		int l = strlen(field.name.c_str());

		dbf.write(field.name.c_str(), MIN(10, l));
		dbf.writeByte(0x00);

		while ((10 - l++) > 0)
			dbf.writeByte(0x00);

		dbf.writeByte((byte) ((char) field.type));

		dbf.writeUint32LE(field.offset);

		dbf.writeByte(field.size);
		dbf.writeByte(field.decimals);
		dbf.writeByte(field.flags);

		dbf.writeUint32LE(field.autoIncNext);
		dbf.writeByte    (field.autoIncStep);

		dbf.writeUint32LE(0x00000000); // Reserved
		dbf.writeUint32LE(0x00000000); // Reserved
	}

	dbf.writeByte(0x0D); // Field end marker
}
Beispiel #5
0
void writeStringFixed(WriteStream &stream, const Common::UString &str, Encoding encoding, size_t length) {
	if (length == 0)
		return;

	ScopedPtr<MemoryReadStream> data(convertString(str, encoding, false));

	size_t n = stream.writeStream(*data, length);
	while (n++ < length)
		stream.writeByte(0);
}
Beispiel #6
0
void FoxPro::saveHeader(WriteStream &dbf) const {
	dbf.writeByte(0xF5); // Version

	dbf.writeByte(_lastUpdate.year() - 2000);
	dbf.writeByte(_lastUpdate.month());
	dbf.writeByte(_lastUpdate.day());

	dbf.writeUint32LE(_records.size());

	//                    Header + fields + field end marker
	uint16 firstRecordPos = 32 + _fields.size() * 32 + 1;
	dbf.writeUint16LE(firstRecordPos);

	uint16 recordSize = _fields.back().offset + _fields.back().size;
	dbf.writeUint16LE(recordSize);

	dbf.writeUint32LE(0x00000000); // Reserved
	dbf.writeUint32LE(0x00000000); // Reserved
	dbf.writeUint32LE(0x00000000); // Reserved
	dbf.writeUint32LE(0x00000000); // Reserved

	uint8 flags = (_hasIndex ? 0x01 : 0x00) | (_hasMemo ? 0x02 : 0x00);
	dbf.writeByte(flags);

	dbf.writeByte(0x00); // Codepage marker

	dbf.writeUint16LE(0x0000); // Reserved
}
Beispiel #7
0
void writeStringFixed(WriteStream &stream, const Common::UString &str, Encoding encoding, size_t length) {
	MemoryReadStream *data = 0;
	try {
		data = convertString(str, encoding, false);

		size_t n = stream.writeStream(*data, length);
		while (n++ < length)
			stream.writeByte(0);

	} catch (...) {
		delete data;
		throw;
	}

	delete data;
}
Beispiel #8
0
void ConfigFile::save(WriteStream &stream) const {
	// Write file prologue
	if (!_prologue.empty()) {
		stream.writeString(_prologue);
		stream.writeByte('\n');
		stream.writeByte('\n');
	}

	// Domains
	for (DomainList::const_iterator domain = _domainList.begin(); domain != _domainList.end(); ++domain) {
		// Write domain prologue
		if (!(*domain)->_prologue.empty()) {
			stream.writeString((*domain)->_prologue);
			stream.writeByte('\n');
		}

		// Write domain name
		stream.writeByte('[');
		stream.writeString((*domain)->_name);
		stream.writeByte(']');

		// Write domain comment
		if (!(*domain)->_comment.empty()) {
			stream.writeByte(' ');
			stream.writeString((*domain)->_comment);
		}

		stream.writeByte('\n');

		// Lines
		for (ConfigDomain::LineList::const_iterator line = (*domain)->_lines.begin(); line != (*domain)->_lines.end(); ++line) {
			// Write key
			if (line->key != (*domain)->_keys.end()) {
				stream.writeString(line->key->first);
				stream.writeByte('=');
				stream.writeString(line->key->second);
				if (!line->comment.empty())
					stream.writeByte(' ');
			}

			// Write comment
			if (!line->comment.empty())
				stream.writeString(line->comment);

			stream.writeByte('\n');
		}

		stream.writeByte('\n');
	}

	// Write the epilogue
	if (!_epilogue.empty()) {
		stream.writeString(_epilogue);
		stream.writeByte('\n');
	}

	stream.flush();
}