示例#1
0
// Export
status_t
RDefExporter::Export(const Icon* icon, BPositionIO* stream)
{
    BMallocIO buffer;
    status_t ret = FlatIconExporter::Export(icon, &buffer);
    if (ret < B_OK)
        return ret;

    return _Export((const uint8*)buffer.Buffer(), buffer.BufferLength(), stream);
}
示例#2
0
// Export
status_t
MessageExporter::Export(const Icon* icon, BPositionIO* stream)
{
	status_t ret = B_OK;
	BMessage archive;

	PathContainer* paths = icon->Paths();
	StyleContainer* styles = icon->Styles();

	// paths
	if (ret == B_OK) {
		BMessage allPaths;
		int32 count = paths->CountPaths();
		for (int32 i = 0; i < count; i++) {
			VectorPath* path = paths->PathAtFast(i);
			BMessage pathArchive;
			ret = _Export(path, &pathArchive);
			if (ret < B_OK)
				break;
			ret = allPaths.AddMessage("path", &pathArchive);
			if (ret < B_OK)
				break;
		}
	
		if (ret == B_OK)
			ret = archive.AddMessage("paths", &allPaths);
	}

	// styles
	if (ret == B_OK) {
		BMessage allStyles;
		int32 count = styles->CountStyles();
		for (int32 i = 0; i < count; i++) {
			Style* style = styles->StyleAtFast(i);
			BMessage styleArchive;
			ret = _Export(style, &styleArchive);
			if (ret < B_OK)
				break;
			ret = allStyles.AddMessage("style", &styleArchive);
			if (ret < B_OK)
				break;
		}
	
		if (ret == B_OK)
			ret = archive.AddMessage("styles", &allStyles);
	}

	// shapes
	if (ret == B_OK) {
		BMessage allShapes;
		ShapeContainer* shapes = icon->Shapes();
		int32 count = shapes->CountShapes();
		for (int32 i = 0; i < count; i++) {
			Shape* shape = shapes->ShapeAtFast(i);
			BMessage shapeArchive;
			ret = _Export(shape, paths, styles, &shapeArchive);
			if (ret < B_OK)
				break;
			ret = allShapes.AddMessage("shape", &shapeArchive);
			if (ret < B_OK)
				break;
		}
	
		if (ret == B_OK)
			ret = archive.AddMessage("shapes", &allShapes);
	}

	// prepend the magic number to the file which
	// later tells us that this file is one of us
	if (ret == B_OK) {
		ssize_t size = sizeof(uint32);
		uint32 magic = B_HOST_TO_BENDIAN_INT32(kNativeIconMagicNumber);
		ssize_t written = stream->Write(&magic, size);
		if (written != size) {
			if (written < 0)
				ret = (status_t)written;
			else
				ret = B_IO_ERROR;
		}
	}

	if (ret == B_OK)
		ret = archive.Flatten(stream);

	return ret;
}