mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-29 03:36:40 +00:00
Merge branch 'remove-lowlevelfile' into 'master'
Remove obsolete LowLevelFile See merge request OpenMW/openmw!2156
This commit is contained in:
commit
5078b6822a
5 changed files with 15 additions and 94 deletions
|
@ -214,7 +214,7 @@ IF(NOT WIN32 AND NOT APPLE)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
add_component_dir (files
|
add_component_dir (files
|
||||||
linuxpath androidpath windowspath macospath fixedpath multidircollection collections configurationmanager
|
linuxpath androidpath windowspath macospath fixedpath multidircollection collections configurationmanager
|
||||||
lowlevelfile constrainedfilestream memorystream hash configfileparser openfile constrainedfilestreambuf
|
constrainedfilestream memorystream hash configfileparser openfile constrainedfilestreambuf
|
||||||
)
|
)
|
||||||
|
|
||||||
add_component_dir (compiler
|
add_component_dir (compiler
|
||||||
|
|
|
@ -5,14 +5,16 @@
|
||||||
|
|
||||||
namespace Files
|
namespace Files
|
||||||
{
|
{
|
||||||
|
namespace File = Platform::File;
|
||||||
|
|
||||||
ConstrainedFileStreamBuf::ConstrainedFileStreamBuf(const std::string& fname, std::size_t start, std::size_t length)
|
ConstrainedFileStreamBuf::ConstrainedFileStreamBuf(const std::string& fname, std::size_t start, std::size_t length)
|
||||||
: mOrigin(start)
|
: mOrigin(start)
|
||||||
{
|
{
|
||||||
mFile.open(fname.c_str());
|
mFile = File::open(fname.c_str());
|
||||||
mSize = length != std::numeric_limits<std::size_t>::max() ? length : mFile.size () - start;
|
mSize = length != std::numeric_limits<std::size_t>::max() ? length : File::size(mFile) - start;
|
||||||
|
|
||||||
if (start != 0)
|
if (start != 0)
|
||||||
mFile.seek(start);
|
File::seek(mFile, start);
|
||||||
|
|
||||||
setg(nullptr, nullptr, nullptr);
|
setg(nullptr, nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
@ -21,10 +23,10 @@ namespace Files
|
||||||
{
|
{
|
||||||
if (gptr() == egptr())
|
if (gptr() == egptr())
|
||||||
{
|
{
|
||||||
const std::size_t toRead = std::min((mOrigin + mSize) - (mFile.tell()), sizeof(mBuffer));
|
const std::size_t toRead = std::min((mOrigin + mSize) - (File::tell(mFile)), sizeof(mBuffer));
|
||||||
// Read in the next chunk of data, and set the read pointers on success
|
// Read in the next chunk of data, and set the read pointers on success
|
||||||
// Failure will throw exception in LowLevelFile
|
// Failure will throw exception.
|
||||||
const std::size_t got = mFile.read(mBuffer, toRead);
|
const std::size_t got = File::read(mFile, mBuffer, toRead);
|
||||||
setg(&mBuffer[0], &mBuffer[0], &mBuffer[0] + got);
|
setg(&mBuffer[0], &mBuffer[0], &mBuffer[0] + got);
|
||||||
}
|
}
|
||||||
if (gptr() == egptr())
|
if (gptr() == egptr())
|
||||||
|
@ -46,7 +48,7 @@ namespace Files
|
||||||
newPos = offset;
|
newPos = offset;
|
||||||
break;
|
break;
|
||||||
case std::ios_base::cur:
|
case std::ios_base::cur:
|
||||||
newPos = (mFile.tell() - mOrigin - (egptr() - gptr())) + offset;
|
newPos = (File::tell(mFile) - mOrigin - (egptr() - gptr())) + offset;
|
||||||
break;
|
break;
|
||||||
case std::ios_base::end:
|
case std::ios_base::end:
|
||||||
newPos = mSize + offset;
|
newPos = mSize + offset;
|
||||||
|
@ -58,7 +60,7 @@ namespace Files
|
||||||
if (newPos > mSize)
|
if (newPos > mSize)
|
||||||
return traits_type::eof();
|
return traits_type::eof();
|
||||||
|
|
||||||
mFile.seek(mOrigin + newPos);
|
File::seek(mFile, mOrigin + newPos);
|
||||||
|
|
||||||
// Clear read pointers so underflow() gets called on the next read attempt.
|
// Clear read pointers so underflow() gets called on the next read attempt.
|
||||||
setg(nullptr, nullptr, nullptr);
|
setg(nullptr, nullptr, nullptr);
|
||||||
|
@ -74,7 +76,7 @@ namespace Files
|
||||||
if (static_cast<std::size_t>(pos) > mSize)
|
if (static_cast<std::size_t>(pos) > mSize)
|
||||||
return traits_type::eof();
|
return traits_type::eof();
|
||||||
|
|
||||||
mFile.seek(mOrigin + pos);
|
File::seek(mFile, mOrigin + pos);
|
||||||
|
|
||||||
// Clear read pointers so underflow() gets called on the next read attempt.
|
// Clear read pointers so underflow() gets called on the next read attempt.
|
||||||
setg(nullptr, nullptr, nullptr);
|
setg(nullptr, nullptr, nullptr);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef OPENMW_CONSTRAINEDFILESTREAMBUF_H
|
#ifndef OPENMW_CONSTRAINEDFILESTREAMBUF_H
|
||||||
#define OPENMW_CONSTRAINEDFILESTREAMBUF_H
|
#define OPENMW_CONSTRAINEDFILESTREAMBUF_H
|
||||||
|
|
||||||
#include "lowlevelfile.hpp"
|
#include <components/platform/file.hpp>
|
||||||
|
|
||||||
#include <streambuf>
|
#include <streambuf>
|
||||||
|
|
||||||
|
@ -22,8 +22,8 @@ namespace Files
|
||||||
private:
|
private:
|
||||||
std::size_t mOrigin;
|
std::size_t mOrigin;
|
||||||
std::size_t mSize;
|
std::size_t mSize;
|
||||||
LowLevelFile mFile;
|
Platform::File::Handle mFile{ Platform::File::Handle::Invalid };
|
||||||
char mBuffer[8192]{0};
|
char mBuffer[8192]{ 0 };
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,53 +0,0 @@
|
||||||
#include "lowlevelfile.hpp"
|
|
||||||
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <sstream>
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
namespace File = Platform::File;
|
|
||||||
|
|
||||||
LowLevelFile::~LowLevelFile()
|
|
||||||
{
|
|
||||||
if (mHandle != File::Handle::Invalid)
|
|
||||||
File::close(mHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LowLevelFile::open(char const* filename)
|
|
||||||
{
|
|
||||||
mHandle = File::open(filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LowLevelFile::close()
|
|
||||||
{
|
|
||||||
if (mHandle != File::Handle::Invalid)
|
|
||||||
File::close(mHandle);
|
|
||||||
mHandle = File::Handle::Invalid;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t LowLevelFile::size()
|
|
||||||
{
|
|
||||||
assert(mHandle != File::Handle::Invalid);
|
|
||||||
|
|
||||||
return File::size(mHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LowLevelFile::seek(size_t position)
|
|
||||||
{
|
|
||||||
assert(mHandle != File::Handle::Invalid);
|
|
||||||
|
|
||||||
return File::seek(mHandle, position);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t LowLevelFile::tell()
|
|
||||||
{
|
|
||||||
assert(mHandle != File::Handle::Invalid);
|
|
||||||
|
|
||||||
return File::tell(mHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t LowLevelFile::read(void* data, size_t size)
|
|
||||||
{
|
|
||||||
assert(mHandle != File::Handle::Invalid);
|
|
||||||
|
|
||||||
return File::read(mHandle, data, size);
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
#ifndef COMPONENTS_FILES_LOWLEVELFILE_HPP
|
|
||||||
#define COMPONENTS_FILES_LOWLEVELFILE_HPP
|
|
||||||
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
#include <components/platform/file.hpp>
|
|
||||||
|
|
||||||
class LowLevelFile
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
~LowLevelFile();
|
|
||||||
|
|
||||||
void open(char const* filename);
|
|
||||||
void close();
|
|
||||||
|
|
||||||
size_t size();
|
|
||||||
|
|
||||||
void seek(size_t Position);
|
|
||||||
size_t tell();
|
|
||||||
|
|
||||||
size_t read(void* data, size_t size);
|
|
||||||
|
|
||||||
private:
|
|
||||||
Platform::File::Handle mHandle{ Platform::File::Handle::Invalid };
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
Loading…
Reference in a new issue