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
|
#pragma once
|
||||||
|
|
||||||
#include "StdInc.h"
|
|
||||||
#include "../../lib/CConfigHandler.h"
|
#include "../../lib/CConfigHandler.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
@ -4,39 +4,25 @@
|
|||||||
#include "CFileInfo.h"
|
#include "CFileInfo.h"
|
||||||
|
|
||||||
CFileInputStream::CFileInputStream(const boost::filesystem::path & file, si64 start, si64 size)
|
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())
|
if (fileStream.fail())
|
||||||
throw std::runtime_error("File " + file.string() + " isn't available.");
|
throw std::runtime_error("File " + file.string() + " isn't available.");
|
||||||
|
|
||||||
dataStart = start;
|
|
||||||
dataSize = size;
|
|
||||||
|
|
||||||
if (dataSize == 0)
|
if (dataSize == 0)
|
||||||
{
|
{
|
||||||
fileStream.seekg(0, std::ios::end);
|
fileStream.seekg(0, std::ios::end);
|
||||||
dataSize = tell();
|
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 CFileInputStream::read(ui8 * data, si64 size)
|
||||||
{
|
{
|
||||||
si64 origin = tell();
|
si64 origin = tell();
|
||||||
|
@ -24,22 +24,21 @@ public:
|
|||||||
/**
|
/**
|
||||||
* C-tor. Opens the specified file.
|
* 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);
|
CFileInputStream(const boost::filesystem::path & file, si64 start = 0, si64 size = 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* C-tor. Opens the specified file.
|
* 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);
|
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.
|
* Reads n bytes from the stream into the data buffer.
|
||||||
*
|
*
|
||||||
@ -80,17 +79,6 @@ public:
|
|||||||
si64 getSize() override;
|
si64 getSize() override;
|
||||||
|
|
||||||
private:
|
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 dataStart;
|
||||||
si64 dataSize;
|
si64 dataSize;
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ zlib_filefunc64_def* FileStream::GetMinizipFilefunc()
|
|||||||
return &MinizipFilefunc;
|
return &MinizipFilefunc;
|
||||||
}
|
}
|
||||||
|
|
||||||
template class DLL_LINKAGE boost::iostreams::stream<FileBuf>;
|
template class boost::iostreams::stream<FileBuf>;
|
||||||
|
|
||||||
/*static*/
|
/*static*/
|
||||||
bool FileStream::CreateFile(const boost::filesystem::path& filename)
|
bool FileStream::CreateFile(const boost::filesystem::path& filename)
|
||||||
|
Loading…
Reference in New Issue
Block a user