From 168c3c8b342e72c5e278379706f187ceadbf57a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sun, 4 Aug 2013 11:07:07 +0200 Subject: [PATCH] HaikuDepot: Added ability to load archived BBitmaps resourced. * SharedBitmap should probably be moved into its own file. * Untested as of yet. --- src/apps/haiku-depot/PackageInfo.cpp | 52 ++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/src/apps/haiku-depot/PackageInfo.cpp b/src/apps/haiku-depot/PackageInfo.cpp index 4c71e89447..2b2f5d8e89 100644 --- a/src/apps/haiku-depot/PackageInfo.cpp +++ b/src/apps/haiku-depot/PackageInfo.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -106,22 +107,45 @@ SharedBitmap::_CreateBitmapFromResource(int32 size) const size_t dataSize; const void* data = resources.LoadResource(B_VECTOR_ICON_TYPE, fResourceID, &dataSize); - if (data == NULL) - return NULL; - - BBitmap* bitmap = new BBitmap(BRect(0, 0, size - 1, size - 1), 0, B_RGBA32); - status = bitmap->InitCheck(); - if (status == B_OK) { - status = BIconUtils::GetVectorIcon( - reinterpret_cast(data), dataSize, bitmap); - }; - - if (status != B_OK) { - delete bitmap; - bitmap = NULL; + if (data != NULL) { + BBitmap* bitmap = new BBitmap(BRect(0, 0, size - 1, size - 1), 0, + B_RGBA32); + status = bitmap->InitCheck(); + if (status == B_OK) { + status = BIconUtils::GetVectorIcon( + reinterpret_cast(data), dataSize, bitmap); + }; + + if (status != B_OK) { + delete bitmap; + bitmap = NULL; + } + + return bitmap; } - return bitmap; + data = resources.LoadResource(B_MESSAGE_TYPE, fResourceID, &dataSize); + if (data != NULL) { + BMemoryIO stream(data, dataSize); + + // Try to read as an archived bitmap. + BMessage archive; + status = archive.Unflatten(&stream); + if (status != B_OK) + return NULL; + + BBitmap* bitmap = new BBitmap(&archive); + + status = bitmap->InitCheck(); + if (status != B_OK) { + delete bitmap; + bitmap = NULL; + } + + return bitmap; + } + + return NULL; }