/* * Copyright 2006-2010, 2023, Haiku. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * Stephan Aßmus * Zardshard */ #include "MessageImporter.h" #include #include #include #ifdef ICON_O_MATIC #include #endif #include #include #include #include "Container.h" #include "Defines.h" #include "Icon.h" #include "PathSourceShape.h" #ifdef ICON_O_MATIC #include "ReferenceImage.h" #endif #include "Shape.h" #include "Style.h" #include "VectorPath.h" using std::nothrow; MessageImporter::MessageImporter() #ifdef ICON_O_MATIC : Importer() #endif { } MessageImporter::~MessageImporter() { } status_t MessageImporter::Import(Icon* icon, BPositionIO* stream) { #ifdef ICON_O_MATIC status_t ret = Init(icon); if (ret < B_OK) { printf("MessageImporter::Import() - " "Init() error: %s\n", strerror(ret)); return ret; } #else status_t ret; #endif uint32 magic = 0; ssize_t size = sizeof(magic); off_t position = stream->Position(); ssize_t read = stream->Read(&magic, size); if (read != size) { if (read < 0) ret = (status_t)read; else ret = B_IO_ERROR; return ret; } if (B_BENDIAN_TO_HOST_INT32(magic) != kNativeIconMagicNumber) { // this might be an old native icon file, where // we didn't prepend the magic number yet, seek back if (stream->Seek(position, SEEK_SET) != position) { printf("MessageImporter::Import() - " "failed to seek back to beginning of stream\n"); return B_IO_ERROR; } } BMessage archive; ret = archive.Unflatten(stream); if (ret != B_OK) return ret; // paths Container* paths = icon->Paths(); ret = _ImportPaths(&archive, paths); if (ret < B_OK) { printf("MessageImporter::Import() - " "error importing paths: %s\n", strerror(ret)); return ret; } // styles Container