2014-12-31 11:12:18 -10:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2015-01-01 14:57:56 -10:00
|
|
|
|
2014-12-31 11:12:18 -10:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2015-01-01 14:57:56 -10:00
|
|
|
|
2014-12-31 11:12:18 -10:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-01-01 14:57:56 -10:00
|
|
|
#ifndef XEEN_FILES_H
|
|
|
|
#define XEEN_FILES_H
|
2014-12-31 11:12:18 -10:00
|
|
|
|
|
|
|
#include "common/scummsys.h"
|
2015-01-01 14:57:56 -10:00
|
|
|
#include "common/array.h"
|
|
|
|
#include "common/file.h"
|
2015-01-11 14:21:57 -05:00
|
|
|
#include "common/serializer.h"
|
2015-01-01 14:57:56 -10:00
|
|
|
#include "graphics/surface.h"
|
2014-12-31 11:12:18 -10:00
|
|
|
|
|
|
|
namespace Xeen {
|
|
|
|
|
2016-09-17 20:06:43 -04:00
|
|
|
enum ArchiveType {
|
|
|
|
ANY_ARCHIVE = -1, GAME_ARCHIVE = 0, ALTSIDE_ARCHIVE = 1,
|
|
|
|
INTRO_ARCHIVE = 2
|
|
|
|
};
|
|
|
|
|
2015-01-01 14:57:56 -10:00
|
|
|
class XeenEngine;
|
2015-01-18 08:57:23 -05:00
|
|
|
class CCArchive;
|
2016-09-17 20:06:43 -04:00
|
|
|
class File;
|
2015-01-01 11:32:56 -10:00
|
|
|
|
2015-01-11 16:01:10 -05:00
|
|
|
#define SYNC_AS(SUFFIX,STREAM,TYPE,SIZE) \
|
|
|
|
template<typename T> \
|
|
|
|
void syncAs ## SUFFIX(T &val, Version minVersion = 0, Version maxVersion = kLastVersion) { \
|
|
|
|
if (_version < minVersion || _version > maxVersion) \
|
|
|
|
return; \
|
|
|
|
if (_loadStream) \
|
|
|
|
val = static_cast<TYPE>(_loadStream->read ## STREAM()); \
|
|
|
|
else { \
|
|
|
|
TYPE tmp = (TYPE)val; \
|
|
|
|
_saveStream->write ## STREAM(tmp); \
|
|
|
|
} \
|
|
|
|
_bytesSynced += SIZE; \
|
|
|
|
}
|
2016-09-17 20:06:43 -04:00
|
|
|
|
2015-01-02 11:01:41 -10:00
|
|
|
/*
|
|
|
|
* Main resource manager
|
|
|
|
*/
|
2015-01-01 14:57:56 -10:00
|
|
|
class FileManager {
|
2016-09-17 20:06:43 -04:00
|
|
|
friend class File;
|
|
|
|
private:
|
|
|
|
static CCArchive *_archives[3];
|
2015-01-01 14:57:56 -10:00
|
|
|
public:
|
2015-01-05 08:11:16 -05:00
|
|
|
bool _isDarkCc;
|
|
|
|
public:
|
2016-08-28 17:52:56 -04:00
|
|
|
/**
|
|
|
|
* Instantiates the resource manager
|
|
|
|
*/
|
2015-01-05 08:11:16 -05:00
|
|
|
FileManager(XeenEngine *vm);
|
|
|
|
|
2016-09-17 20:06:43 -04:00
|
|
|
/**
|
|
|
|
* Set which game side files to use
|
|
|
|
*/
|
|
|
|
void setGameCc(bool isDarkCc);
|
2015-01-01 14:57:56 -10:00
|
|
|
};
|
2015-01-01 11:32:56 -10:00
|
|
|
|
2015-01-01 14:57:56 -10:00
|
|
|
/**
|
|
|
|
* Derived file class
|
|
|
|
*/
|
|
|
|
class File : public Common::File {
|
2016-09-17 20:06:43 -04:00
|
|
|
public:
|
|
|
|
static ArchiveType _currentArchive;
|
2016-09-18 10:22:49 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets which archive is used by default
|
|
|
|
*/
|
|
|
|
static void setCurrentArchive(ArchiveType arcType) { _currentArchive = arcType; }
|
2015-01-01 14:57:56 -10:00
|
|
|
public:
|
|
|
|
File() : Common::File() {}
|
2016-09-18 10:22:49 -04:00
|
|
|
File(const Common::String &filename);
|
|
|
|
File(const Common::String &filename, ArchiveType archiveType);
|
|
|
|
File(const Common::String &filename, Common::Archive &archive);
|
2015-01-01 14:57:56 -10:00
|
|
|
virtual ~File() {}
|
2014-12-31 11:12:18 -10:00
|
|
|
|
2016-08-28 17:52:56 -04:00
|
|
|
/**
|
|
|
|
* Opens the given file, throwing an error if it can't be opened
|
|
|
|
*/
|
2016-09-17 20:06:43 -04:00
|
|
|
virtual bool open(const Common::String &filename);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens the given file, throwing an error if it can't be opened
|
|
|
|
*/
|
|
|
|
virtual bool open(const Common::String &filename, ArchiveType archiveType);
|
2016-08-28 17:52:56 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens the given file, throwing an error if it can't be opened
|
|
|
|
*/
|
2016-09-17 20:06:43 -04:00
|
|
|
virtual bool open(const Common::String &filename, Common::Archive &archive);
|
2015-01-21 20:42:44 -05:00
|
|
|
|
|
|
|
Common::String readString();
|
2015-01-01 14:57:56 -10:00
|
|
|
};
|
2014-12-31 16:14:45 -10:00
|
|
|
|
2015-01-11 14:21:57 -05:00
|
|
|
class XeenSerializer : public Common::Serializer {
|
|
|
|
private:
|
|
|
|
Common::SeekableReadStream *_in;
|
|
|
|
public:
|
|
|
|
XeenSerializer(Common::SeekableReadStream *in, Common::WriteStream *out) :
|
|
|
|
Common::Serializer(in, out), _in(in) {}
|
|
|
|
|
2015-01-11 16:01:10 -05:00
|
|
|
SYNC_AS(Sint8, Byte, int8, 1)
|
|
|
|
|
2015-01-11 14:21:57 -05:00
|
|
|
bool finished() const { return _in != nullptr && _in->pos() >= _in->size(); }
|
|
|
|
};
|
|
|
|
|
2015-01-02 11:01:41 -10:00
|
|
|
/**
|
2015-01-05 21:17:44 -05:00
|
|
|
* Details of a single entry in a CC file index
|
2015-01-02 11:01:41 -10:00
|
|
|
*/
|
2015-01-05 21:17:44 -05:00
|
|
|
struct CCEntry {
|
|
|
|
uint16 _id;
|
|
|
|
uint32 _offset;
|
|
|
|
uint16 _size;
|
|
|
|
|
|
|
|
CCEntry() : _id(0), _offset(0), _size(0) {}
|
|
|
|
CCEntry(uint16 id, uint32 offset, uint32 size)
|
|
|
|
: _id(id), _offset(offset), _size(size) {
|
|
|
|
}
|
|
|
|
};
|
2015-01-02 11:01:41 -10:00
|
|
|
|
2015-01-05 21:17:44 -05:00
|
|
|
/**
|
|
|
|
* Base Xeen CC file implementation
|
|
|
|
*/
|
|
|
|
class BaseCCArchive : public Common::Archive {
|
|
|
|
protected:
|
|
|
|
Common::Array<CCEntry> _index;
|
2015-01-02 11:01:41 -10:00
|
|
|
|
2016-08-28 17:52:56 -04:00
|
|
|
/**
|
|
|
|
* Load the index of a given CC file
|
|
|
|
*/
|
2015-01-02 11:01:41 -10:00
|
|
|
void loadIndex(Common::SeekableReadStream *stream);
|
|
|
|
|
2016-08-28 17:52:56 -04:00
|
|
|
/**
|
|
|
|
* Given a resource name, returns whether an entry exists, and returns
|
|
|
|
* the header index data for that entry
|
|
|
|
*/
|
2015-01-07 22:11:18 -05:00
|
|
|
virtual bool getHeaderEntry(const Common::String &resourceName, CCEntry &ccEntry) const;
|
2015-01-11 14:21:57 -05:00
|
|
|
public:
|
2016-08-28 17:52:56 -04:00
|
|
|
/**
|
|
|
|
* Hash a given filename to produce the Id that represents it
|
|
|
|
*/
|
2015-01-11 14:21:57 -05:00
|
|
|
static uint16 convertNameToId(const Common::String &resourceName);
|
2015-01-02 11:01:41 -10:00
|
|
|
public:
|
2015-01-05 21:17:44 -05:00
|
|
|
BaseCCArchive() {}
|
2015-01-02 11:01:41 -10:00
|
|
|
|
|
|
|
// Archive implementation
|
|
|
|
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;
|
2015-01-05 21:17:44 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Xeen CC file implementation
|
|
|
|
*/
|
|
|
|
class CCArchive : public BaseCCArchive {
|
|
|
|
private:
|
|
|
|
Common::String _filename;
|
2015-01-07 22:11:18 -05:00
|
|
|
Common::String _prefix;
|
2015-01-05 21:17:44 -05:00
|
|
|
bool _encoded;
|
2015-01-07 22:11:18 -05:00
|
|
|
protected:
|
|
|
|
virtual bool getHeaderEntry(const Common::String &resourceName, CCEntry &ccEntry) const;
|
2015-01-05 21:17:44 -05:00
|
|
|
public:
|
2015-01-07 22:11:18 -05:00
|
|
|
CCArchive(const Common::String &filename, bool encoded);
|
|
|
|
CCArchive(const Common::String &filename, const Common::String &prefix, bool encoded);
|
2015-01-05 21:17:44 -05:00
|
|
|
virtual ~CCArchive();
|
|
|
|
|
|
|
|
// Archive implementation
|
2015-01-02 11:01:41 -10:00
|
|
|
virtual Common::SeekableReadStream *createReadStreamForMember(const Common::String &name) const;
|
|
|
|
};
|
|
|
|
|
2014-12-31 11:12:18 -10:00
|
|
|
} // End of namespace Xeen
|
|
|
|
|
2015-01-01 14:57:56 -10:00
|
|
|
#endif /* XEEN_FILES_H */
|