added some error checks, small cleanup
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19094 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -35,7 +35,6 @@ struct _BPictureExtent_ {
|
|||||||
status_t SetSize(const int32 &size);
|
status_t SetSize(const int32 &size);
|
||||||
|
|
||||||
bool AddPicture(BPicture *picture) { return fPictures.AddItem(picture); }
|
bool AddPicture(BPicture *picture) { return fPictures.AddItem(picture); }
|
||||||
|
|
||||||
void DeletePicture(const int32 &index)
|
void DeletePicture(const int32 &index)
|
||||||
{ delete static_cast<BPicture *>(fPictures.RemoveItem(index)); }
|
{ delete static_cast<BPicture *>(fPictures.RemoveItem(index)); }
|
||||||
BPicture *PictureAt(const int32 &index)
|
BPicture *PictureAt(const int32 &index)
|
||||||
@@ -54,6 +53,12 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct picture_header {
|
||||||
|
int32 magic1; // ?
|
||||||
|
int32 magic2; // ?
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
BPicture::BPicture()
|
BPicture::BPicture()
|
||||||
:
|
:
|
||||||
token(-1),
|
token(-1),
|
||||||
@@ -225,7 +230,7 @@ BPicture::Archive(BMessage *archive, bool deep) const
|
|||||||
for (int32 i = 0; i < extent->CountPictures(); i++) {
|
for (int32 i = 0; i < extent->CountPictures(); i++) {
|
||||||
BMessage picMsg;
|
BMessage picMsg;
|
||||||
|
|
||||||
((BPicture*)extent->PictureAt(i))->Archive(&picMsg, deep);
|
extent->PictureAt(i)->Archive(&picMsg, deep);
|
||||||
err = archive->AddMessage("piclib", &picMsg);
|
err = archive->AddMessage("piclib", &picMsg);
|
||||||
if (err != B_OK)
|
if (err != B_OK)
|
||||||
break;
|
break;
|
||||||
@@ -260,49 +265,56 @@ BPicture::Flatten(BDataIO *stream)
|
|||||||
if (!assert_local_copy())
|
if (!assert_local_copy())
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
// TODO check the header
|
const picture_header header = { 2, 0 };
|
||||||
int32 bla1 = 2;
|
status_t status = stream->Write(&header, sizeof(header));
|
||||||
int32 bla2 = 0;
|
if (status < B_OK)
|
||||||
int32 count = 0;
|
return status;
|
||||||
|
|
||||||
stream->Write(&bla1, sizeof(bla1));
|
int32 count = extent->CountPictures();
|
||||||
stream->Write(&bla2, sizeof(bla2));
|
if (count > 0) {
|
||||||
|
status = stream->Write(&count, sizeof(count));
|
||||||
|
if (status < B_OK)
|
||||||
|
return status;
|
||||||
|
|
||||||
count = extent->CountPictures();
|
for (int32 i = 0; i < extent->CountPictures(); i++) {
|
||||||
stream->Write(&count, sizeof(count));
|
status = extent->PictureAt(i)->Flatten(stream);
|
||||||
|
if (status < B_OK)
|
||||||
for (int32 i = 0; i < extent->CountPictures(); i++)
|
return status;
|
||||||
(extent->PictureAt(i))->Flatten(stream);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int32 size = extent->Size();
|
int32 size = extent->Size();
|
||||||
stream->Write(&size, sizeof(size));
|
status = stream->Write(&size, sizeof(size));
|
||||||
stream->Write(extent->Data(), extent->Size());
|
if (status == B_OK)
|
||||||
|
status = stream->Write(extent->Data(), extent->Size());
|
||||||
|
|
||||||
return B_OK;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BPicture::Unflatten(BDataIO *stream)
|
BPicture::Unflatten(BDataIO *stream)
|
||||||
{
|
{
|
||||||
// TODO check the header
|
picture_header header;
|
||||||
int32 bla1 = 2;
|
if (stream->Read(&header, sizeof(header)) < sizeof(header)
|
||||||
int32 bla2 = 0;
|
|| header.magic1 != 2 || header.magic2 != 0)
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
int32 count = 0;
|
int32 count = 0;
|
||||||
|
status_t status = stream->Read(&count, sizeof(count));
|
||||||
stream->Read(&bla1, 4);
|
if (status < B_OK)
|
||||||
stream->Read(&bla2, 4);
|
return status;
|
||||||
|
|
||||||
stream->Read(&count, 4);
|
|
||||||
|
|
||||||
for (int32 i = 0; i < count; i++) {
|
for (int32 i = 0; i < count; i++) {
|
||||||
BPicture *pic = new BPicture;
|
BPicture *pic = new BPicture;
|
||||||
|
status = pic->Unflatten(stream);
|
||||||
|
if (status < B_OK)
|
||||||
|
return status;
|
||||||
|
|
||||||
pic->Unflatten(stream);
|
|
||||||
extent->AddPicture(pic);
|
extent->AddPicture(pic);
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t status = extent->ImportData(stream);
|
status = extent->ImportData(stream);
|
||||||
if (status < B_OK)
|
if (status < B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user