Skip to content

Commit

Permalink
Move DeflatedArchive[Text]File classes to archive namespace, plus som…
Browse files Browse the repository at this point in the history
…e refactoring.
  • Loading branch information
codereader committed Aug 30, 2017
1 parent 141c647 commit 42ad416
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 33 deletions.
43 changes: 27 additions & 16 deletions plugins/archivezip/DeflatedArchiveFile.h
Expand Up @@ -4,38 +4,49 @@
#include "stream/filestream.h"
#include "DeflatedInputStream.h"

namespace archive
{

class DeflatedArchiveFile :
public ArchiveFile
{
std::string m_name;
FileInputStream m_istream;
SubFileInputStream m_substream;
archive::DeflatedInputStream m_zipstream;
FileInputStream::size_type m_size;
private:
std::string _name;
FileInputStream _istream;
SubFileInputStream _substream; // provides a subset of _istream
DeflatedInputStream _zipstream; // inflates data from _subStream
FileInputStream::size_type _size;

public:
typedef FileInputStream::size_type size_type;
typedef FileInputStream::position_type position_type;

DeflatedArchiveFile(const std::string& name,
const std::string& archiveName,
const std::string& archiveName, // path to the ZIP file
position_type position,
size_type stream_size,
size_type file_size) :
m_name(name),
m_istream(archiveName),
m_substream(m_istream, position, stream_size),
m_zipstream(m_substream), m_size(file_size)
_name(name),
_istream(archiveName),
_substream(_istream, position, stream_size),
_zipstream(_substream),
_size(file_size)
{}

size_type size() const {
return m_size;
size_type size() const override
{
return _size;
}

const std::string& getName() const {
return m_name;
const std::string& getName() const override
{
return _name;
}

InputStream& getInputStream() {
return m_zipstream;
InputStream& getInputStream() override
{
return _zipstream;
}
};

}
43 changes: 26 additions & 17 deletions plugins/archivezip/DeflatedArchiveTextFile.h
Expand Up @@ -3,24 +3,28 @@
#include "iarchive.h"
#include "iregistry.h"
#include "gamelib.h"
#include "archivelib.h"

namespace archive
{

/**
* ArchiveFile stored in a ZIP in DEFLATE format.
*/
class DeflatedArchiveTextFile :
public ArchiveTextFile
{
std::string m_name;
FileInputStream m_istream;
SubFileInputStream m_substream;
archive::DeflatedInputStream m_zipstream;
BinaryToTextInputStream<archive::DeflatedInputStream> m_textStream;
private:
std::string _name;
FileInputStream _istream;
SubFileInputStream _substream; // reads subset of _istream
DeflatedInputStream _zipstream; // inflates data from _substream
BinaryToTextInputStream<DeflatedInputStream> _textStream; // converts data from _zipstream

// Mod directory containing this file
const std::string _modDir;

public:

typedef FileInputStream::size_type size_type;
typedef FileInputStream::position_type position_type;

Expand All @@ -31,30 +35,35 @@ class DeflatedArchiveTextFile :
* The name of the mod directory this file's archive is located in.
*/
DeflatedArchiveTextFile(const std::string& name,
const std::string& archiveName,
const std::string& archiveName, // full path to ZIP file
const std::string& modDir,
position_type position,
size_type stream_size)
: m_name(name),
m_istream(archiveName),
m_substream(m_istream, position, stream_size),
m_zipstream(m_substream),
m_textStream(m_zipstream),
: _name(name),
_istream(archiveName),
_substream(_istream, position, stream_size),
_zipstream(_substream),
_textStream(_zipstream),
_modDir(game::current::getModPath(modDir))
{}

TextInputStream& getInputStream() {
return m_textStream;
TextInputStream& getInputStream() override
{
return _textStream;
}

const std::string& getName() const {
return m_name;
const std::string& getName() const override
{
return _name;
}

/**
* Return mod directory of this file.
*/
std::string getModName() const {
std::string getModName() const override
{
return _modDir;
}
};

}

0 comments on commit 42ad416

Please sign in to comment.