Browse Source

some modernization of CFileInputStream implementation code

Zyx-2000 9 years ago
parent
commit
933b7c1f5e

+ 0 - 1
launcher/modManager/cmodlistview_moc.h

@@ -1,6 +1,5 @@
 #pragma once
 
-#include "StdInc.h"
 #include "../../lib/CConfigHandler.h"
 
 namespace Ui {

+ 7 - 21
lib/filesystem/CFileInputStream.cpp

@@ -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();

+ 6 - 18
lib/filesystem/CFileInputStream.h

@@ -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;
 

+ 1 - 1
lib/filesystem/FileStream.cpp

@@ -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)