mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
some modernization of CFileInputStream implementation code
This commit is contained in:
parent
f9b255c896
commit
933b7c1f5e
@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "StdInc.h"
|
||||
#include "../../lib/CConfigHandler.h"
|
||||
|
||||
namespace Ui {
|
||||
|
@ -4,39 +4,25 @@
|
||||
#include "CFileInfo.h"
|
||||
|
||||
CFileInputStream::CFileInputStream(const boost::filesystem::path & file, si64 start, si64 size)
|
||||
: dataStart{start},
|
||||
dataSize{size},
|
||||
fileStream{file, std::ios::in | std::ios::binary}
|
||||
{
|
||||
open(file, start, size);
|
||||
}
|
||||
|
||||
CFileInputStream::CFileInputStream(const CFileInfo & file, si64 start, si64 size)
|
||||
{
|
||||
open(file.getName(), start, size);
|
||||
}
|
||||
|
||||
CFileInputStream::~CFileInputStream()
|
||||
{
|
||||
fileStream.close();
|
||||
}
|
||||
|
||||
void CFileInputStream::open(const boost::filesystem::path & file, si64 start, si64 size)
|
||||
{
|
||||
fileStream.open(file, std::ios::in | std::ios::binary);
|
||||
|
||||
if (fileStream.fail())
|
||||
throw std::runtime_error("File " + file.string() + " isn't available.");
|
||||
|
||||
dataStart = start;
|
||||
dataSize = size;
|
||||
|
||||
if (dataSize == 0)
|
||||
{
|
||||
fileStream.seekg(0, std::ios::end);
|
||||
dataSize = tell();
|
||||
}
|
||||
|
||||
fileStream.seekg(start, std::ios::beg);
|
||||
fileStream.seekg(dataStart, std::ios::beg);
|
||||
}
|
||||
|
||||
CFileInputStream::CFileInputStream(const CFileInfo & file, si64 start, si64 size)
|
||||
: CFileInputStream{file.getName(), start, size} {}
|
||||
|
||||
si64 CFileInputStream::read(ui8 * data, si64 size)
|
||||
{
|
||||
si64 origin = tell();
|
||||
|
@ -24,22 +24,21 @@ public:
|
||||
/**
|
||||
* C-tor. Opens the specified file.
|
||||
*
|
||||
* @see CFileInputStream::open
|
||||
* @param file Path to the file.
|
||||
* @param start - offset from file start where real data starts (e.g file on archive)
|
||||
* @param size - size of real data in file (e.g file on archive) or 0 to use whole file
|
||||
*
|
||||
* @throws std::runtime_error if file wasn't found
|
||||
*/
|
||||
CFileInputStream(const boost::filesystem::path & file, si64 start = 0, si64 size = 0);
|
||||
|
||||
/**
|
||||
* C-tor. Opens the specified file.
|
||||
*
|
||||
* @see CFileInputStream::open
|
||||
* @see CFileInputStream::CFileInputStream(const boost::filesystem::path &, si64, si64)
|
||||
*/
|
||||
CFileInputStream(const CFileInfo & file, si64 start=0, si64 size=0);
|
||||
|
||||
/**
|
||||
* D-tor. Calls the close method implicitely, if the file is still opened.
|
||||
*/
|
||||
~CFileInputStream();
|
||||
|
||||
/**
|
||||
* Reads n bytes from the stream into the data buffer.
|
||||
*
|
||||
@ -80,17 +79,6 @@ public:
|
||||
si64 getSize() override;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Opens a file. If a file is currently opened, it will be closed.
|
||||
*
|
||||
* @param file Path to the file.
|
||||
* @param start - offset from file start where real data starts (e.g file on archive)
|
||||
* @param size - size of real data in file (e.g file on archive) or 0 to use whole file
|
||||
*
|
||||
* @throws std::runtime_error if file wasn't found
|
||||
*/
|
||||
void open(const boost::filesystem::path & file, si64 start, si64 size);
|
||||
|
||||
si64 dataStart;
|
||||
si64 dataSize;
|
||||
|
||||
|
@ -53,7 +53,7 @@ zlib_filefunc64_def* FileStream::GetMinizipFilefunc()
|
||||
return &MinizipFilefunc;
|
||||
}
|
||||
|
||||
template class DLL_LINKAGE boost::iostreams::stream<FileBuf>;
|
||||
template class boost::iostreams::stream<FileBuf>;
|
||||
|
||||
/*static*/
|
||||
bool FileStream::CreateFile(const boost::filesystem::path& filename)
|
||||
|
Loading…
Reference in New Issue
Block a user