GRAPHICS: Cleanup WinCursorGroup functions a bit
ScopedPtr is now used on the streams to avoid having repetitive delete calls.
This commit is contained in:
parent
b158a40844
commit
4e7b66b1bc
1 changed files with 5 additions and 19 deletions
|
@ -26,6 +26,7 @@
|
||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/file.h"
|
#include "common/file.h"
|
||||||
#include "common/memstream.h"
|
#include "common/memstream.h"
|
||||||
|
#include "common/ptr.h"
|
||||||
#include "common/str.h"
|
#include "common/str.h"
|
||||||
#include "common/stream.h"
|
#include "common/stream.h"
|
||||||
#include "common/winexe_ne.h"
|
#include "common/winexe_ne.h"
|
||||||
|
@ -208,7 +209,7 @@ WinCursorGroup::~WinCursorGroup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
WinCursorGroup *WinCursorGroup::createCursorGroup(Common::NEResources &exe, const Common::WinResourceID &id) {
|
WinCursorGroup *WinCursorGroup::createCursorGroup(Common::NEResources &exe, const Common::WinResourceID &id) {
|
||||||
Common::SeekableReadStream *stream = exe.getResource(Common::kNEGroupCursor, id);
|
Common::ScopedPtr<Common::SeekableReadStream> stream(exe.getResource(Common::kNEGroupCursor, id));
|
||||||
|
|
||||||
if (!stream || stream->size() <= 6)
|
if (!stream || stream->size() <= 6)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -227,7 +228,6 @@ WinCursorGroup *WinCursorGroup::createCursorGroup(Common::NEResources &exe, cons
|
||||||
|
|
||||||
// Plane count
|
// Plane count
|
||||||
if (stream->readUint16LE() != 1) {
|
if (stream->readUint16LE() != 1) {
|
||||||
delete stream;
|
|
||||||
delete group;
|
delete group;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -235,7 +235,6 @@ WinCursorGroup *WinCursorGroup::createCursorGroup(Common::NEResources &exe, cons
|
||||||
// Bits per pixel
|
// Bits per pixel
|
||||||
// NE cursors can only be 1bpp
|
// NE cursors can only be 1bpp
|
||||||
if (stream->readUint16LE() != 1) {
|
if (stream->readUint16LE() != 1) {
|
||||||
delete stream;
|
|
||||||
delete group;
|
delete group;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -243,36 +242,30 @@ WinCursorGroup *WinCursorGroup::createCursorGroup(Common::NEResources &exe, cons
|
||||||
stream->readUint32LE(); // data size
|
stream->readUint32LE(); // data size
|
||||||
uint32 cursorId = stream->readUint32LE();
|
uint32 cursorId = stream->readUint32LE();
|
||||||
|
|
||||||
Common::SeekableReadStream *cursorStream = exe.getResource(Common::kNECursor, cursorId);
|
Common::ScopedPtr<Common::SeekableReadStream> cursorStream(exe.getResource(Common::kNECursor, cursorId));
|
||||||
if (!cursorStream) {
|
if (!cursorStream) {
|
||||||
delete stream;
|
|
||||||
delete group;
|
delete group;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
WinCursor *cursor = new WinCursor();
|
WinCursor *cursor = new WinCursor();
|
||||||
if (!cursor->readFromStream(*cursorStream)) {
|
if (!cursor->readFromStream(*cursorStream)) {
|
||||||
delete stream;
|
|
||||||
delete cursorStream;
|
|
||||||
delete cursor;
|
delete cursor;
|
||||||
delete group;
|
delete group;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete cursorStream;
|
|
||||||
|
|
||||||
CursorItem item;
|
CursorItem item;
|
||||||
item.id = cursorId;
|
item.id = cursorId;
|
||||||
item.cursor = cursor;
|
item.cursor = cursor;
|
||||||
group->cursors.push_back(item);
|
group->cursors.push_back(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete stream;
|
|
||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
WinCursorGroup *WinCursorGroup::createCursorGroup(Common::PEResources &exe, const Common::WinResourceID &id) {
|
WinCursorGroup *WinCursorGroup::createCursorGroup(Common::PEResources &exe, const Common::WinResourceID &id) {
|
||||||
Common::SeekableReadStream *stream = exe.getResource(Common::kPEGroupCursor, id);
|
Common::ScopedPtr<Common::SeekableReadStream> stream(exe.getResource(Common::kPEGroupCursor, id));
|
||||||
|
|
||||||
if (!stream || stream->size() <= 6)
|
if (!stream || stream->size() <= 6)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -291,7 +284,6 @@ WinCursorGroup *WinCursorGroup::createCursorGroup(Common::PEResources &exe, cons
|
||||||
|
|
||||||
// Plane count
|
// Plane count
|
||||||
if (stream->readUint16LE() != 1) {
|
if (stream->readUint16LE() != 1) {
|
||||||
delete stream;
|
|
||||||
delete group;
|
delete group;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -300,31 +292,25 @@ WinCursorGroup *WinCursorGroup::createCursorGroup(Common::PEResources &exe, cons
|
||||||
stream->readUint32LE(); // data size
|
stream->readUint32LE(); // data size
|
||||||
uint32 cursorId = stream->readUint16LE();
|
uint32 cursorId = stream->readUint16LE();
|
||||||
|
|
||||||
Common::SeekableReadStream *cursorStream = exe.getResource(Common::kPECursor, cursorId);
|
Common::ScopedPtr<Common::SeekableReadStream> cursorStream(exe.getResource(Common::kPECursor, cursorId));
|
||||||
if (!cursorStream) {
|
if (!cursorStream) {
|
||||||
delete stream;
|
|
||||||
delete group;
|
delete group;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
WinCursor *cursor = new WinCursor();
|
WinCursor *cursor = new WinCursor();
|
||||||
if (!cursor->readFromStream(*cursorStream)) {
|
if (!cursor->readFromStream(*cursorStream)) {
|
||||||
delete stream;
|
|
||||||
delete cursorStream;
|
|
||||||
delete cursor;
|
delete cursor;
|
||||||
delete group;
|
delete group;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete cursorStream;
|
|
||||||
|
|
||||||
CursorItem item;
|
CursorItem item;
|
||||||
item.id = cursorId;
|
item.id = cursorId;
|
||||||
item.cursor = cursor;
|
item.cursor = cursor;
|
||||||
group->cursors.push_back(item);
|
group->cursors.push_back(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete stream;
|
|
||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue