mirror of
https://github.com/scummvm/scummvm.git
synced 2026-06-20 05:45:29 +00:00
GRIM: Clean a bit lab
This commit is contained in:
+6
-33
@@ -20,10 +20,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "common/endian.h"
|
||||
#include "common/file.h"
|
||||
#include "common/substream.h"
|
||||
#include "common/memstream.h"
|
||||
|
||||
#include "engines/grim/grim.h"
|
||||
#include "engines/grim/lab.h"
|
||||
@@ -44,30 +42,17 @@ Common::SeekableReadStream *LabEntry::createReadStream() const {
|
||||
return _parent->createReadStreamForMember(_name);
|
||||
}
|
||||
|
||||
bool Lab::open(const byte *memLab, const uint32 size) {
|
||||
_f = new Common::MemoryReadStream(memLab, size);
|
||||
_labFileName = "";
|
||||
_memLab = memLab;
|
||||
|
||||
return loadLab();
|
||||
}
|
||||
|
||||
bool Lab::open(const Common::String &filename) {
|
||||
_labFileName = filename;
|
||||
|
||||
close();
|
||||
|
||||
Common::File *file = new Common::File();
|
||||
if (!file->open(filename)) {
|
||||
delete file;
|
||||
_f = new Common::File();
|
||||
if (!_f->open(filename)) {
|
||||
close();
|
||||
return false;
|
||||
}
|
||||
|
||||
_f = (Common::SeekableReadStream *)file;
|
||||
return loadLab();
|
||||
}
|
||||
|
||||
bool Lab::loadLab() {
|
||||
if (_f->readUint32BE() != MKTAG('L','A','B','N')) {
|
||||
close();
|
||||
return false;
|
||||
@@ -80,6 +65,9 @@ bool Lab::loadLab() {
|
||||
else
|
||||
parseMonkey4FileTable();
|
||||
|
||||
delete _f;
|
||||
_f = NULL;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -146,12 +134,6 @@ void Lab::parseMonkey4FileTable() {
|
||||
delete[] stringTable;
|
||||
}
|
||||
|
||||
bool Lab::hasFile(const Common::String &filename) {
|
||||
Common::String fname(filename);
|
||||
fname.toLowercase();
|
||||
return _entries.contains(fname);
|
||||
}
|
||||
|
||||
bool Lab::hasFile(const Common::String &filename) const {
|
||||
Common::String fname(filename);
|
||||
fname.toLowercase();
|
||||
@@ -186,12 +168,6 @@ Common::SeekableReadStream *Lab::createReadStreamForMember(const Common::String
|
||||
fname.toLowercase();
|
||||
LabEntryPtr i = _entries[fname];
|
||||
|
||||
/*If the whole Lab has been loaded into ram, we return a MemoryReadStream
|
||||
that map requested data directly, without copying them. Otherwise open a new
|
||||
stream from disk.*/
|
||||
if(_memLab)
|
||||
return new Common::MemoryReadStream((_memLab + i->_offset), i->_len, DisposeAfterUse::NO);
|
||||
|
||||
Common::File *file = new Common::File();
|
||||
file->open(_labFileName);
|
||||
return new Common::SeekableSubReadStream(file, i->_offset, i->_offset + i->_len, DisposeAfterUse::YES );
|
||||
@@ -201,9 +177,6 @@ void Lab::close() {
|
||||
delete _f;
|
||||
_f = NULL;
|
||||
|
||||
if(_memLab)
|
||||
delete _memLab;
|
||||
|
||||
_entries.clear();
|
||||
}
|
||||
|
||||
|
||||
+2
-11
@@ -23,12 +23,7 @@
|
||||
#ifndef GRIM_LAB_H
|
||||
#define GRIM_LAB_H
|
||||
|
||||
#include "common/hashmap.h"
|
||||
#include "common/hash-str.h"
|
||||
#include "common/str.h"
|
||||
#include "common/archive.h"
|
||||
#include "common/file.h"
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Grim {
|
||||
|
||||
@@ -48,27 +43,23 @@ public:
|
||||
|
||||
class Lab : public Common::Archive {
|
||||
public:
|
||||
Lab() : _f(NULL), _memLab(NULL) { }
|
||||
Lab() : _f(NULL) { }
|
||||
~Lab() { close(); }
|
||||
|
||||
bool open(const Common::String &filename);
|
||||
bool open(const byte *memLab, const uint32 size);
|
||||
void close();
|
||||
|
||||
// Common::Archive implementation
|
||||
virtual bool hasFile(const Common::String &name); //TODO: Remove at next scummvm sync
|
||||
virtual bool hasFile(const Common::String &name) const;
|
||||
virtual int listMembers(Common::ArchiveMemberList &list) const;
|
||||
virtual const Common::ArchiveMemberPtr getMember(const Common::String &name) const;
|
||||
virtual Common::SeekableReadStream *createReadStreamForMember(const Common::String &name) const;
|
||||
|
||||
private:
|
||||
bool loadLab();
|
||||
void parseGrimFileTable();
|
||||
void parseMonkey4FileTable();
|
||||
|
||||
Common::SeekableReadStream *_f;
|
||||
const byte *_memLab;
|
||||
Common::File *_f;
|
||||
Common::String _labFileName;
|
||||
typedef Common::SharedPtr<LabEntry> LabEntryPtr;
|
||||
typedef Common::HashMap<Common::String, LabEntryPtr, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> LabMap;
|
||||
|
||||
Reference in New Issue
Block a user