mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-11 07:18:11 -05:00
Replace FileAPI with c++ streams and std::filesystem
This commit is contained in:
@ -1,16 +1,17 @@
|
||||
#include "LoadingFileStream.h"
|
||||
|
||||
LoadingFileStream::LoadingFileStream(FileAPI::File* file)
|
||||
LoadingFileStream::LoadingFileStream(std::istream& stream)
|
||||
: m_stream(stream)
|
||||
{
|
||||
m_file = file;
|
||||
}
|
||||
|
||||
size_t LoadingFileStream::Load(void* buffer, const size_t length)
|
||||
{
|
||||
return m_file->Read(buffer, 1, length);
|
||||
m_stream.read(static_cast<char*>(buffer), length);
|
||||
return static_cast<size_t>(m_stream.gcount());
|
||||
}
|
||||
|
||||
int64_t LoadingFileStream::Pos()
|
||||
{
|
||||
return m_file->Pos();
|
||||
return m_stream.tellg();
|
||||
}
|
@ -1,13 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <istream>
|
||||
|
||||
#include "ILoadingStream.h"
|
||||
#include "Utils/FileAPI.h"
|
||||
|
||||
class LoadingFileStream final : public ILoadingStream
|
||||
{
|
||||
FileAPI::File* m_file;
|
||||
std::istream& m_stream;
|
||||
|
||||
public:
|
||||
explicit LoadingFileStream(FileAPI::File* file);
|
||||
explicit LoadingFileStream(std::istream& stream);
|
||||
|
||||
size_t Load(void* buffer, size_t length) override;
|
||||
int64_t Pos() override;
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "StepDumpData.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
StepDumpData::StepDumpData(const unsigned int dumpCount)
|
||||
{
|
||||
m_dump_count = dumpCount;
|
||||
@ -10,7 +12,7 @@ void StepDumpData::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
|
||||
uint8_t tempBuffer[128];
|
||||
unsigned int dumpedBytes = 0;
|
||||
|
||||
FileAPI::File tempFile = FileAPI::Open("dump.dat", FileAPI::Mode::MODE_WRITE);
|
||||
std::ofstream tempFile("dump.dat", std::fstream::out | std::fstream::binary);
|
||||
|
||||
while (dumpedBytes < m_dump_count)
|
||||
{
|
||||
@ -25,14 +27,14 @@ void StepDumpData::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
|
||||
toDump = sizeof(tempBuffer);
|
||||
}
|
||||
|
||||
const size_t loadedSize = stream->Load(tempBuffer, toDump);
|
||||
const auto loadedSize = stream->Load(tempBuffer, toDump);
|
||||
dumpedBytes += loadedSize;
|
||||
|
||||
if (loadedSize == 0)
|
||||
break;
|
||||
|
||||
tempFile.Write(tempBuffer, 1, loadedSize);
|
||||
tempFile.write(reinterpret_cast<char*>(tempBuffer), loadedSize);
|
||||
}
|
||||
|
||||
tempFile.Close();
|
||||
tempFile.close();
|
||||
}
|
@ -12,13 +12,13 @@ ZoneLoader::ZoneLoader(Zone* zone)
|
||||
|
||||
ZoneLoader::~ZoneLoader()
|
||||
{
|
||||
for(auto step : m_steps)
|
||||
for(auto* step : m_steps)
|
||||
{
|
||||
delete step;
|
||||
}
|
||||
m_steps.clear();
|
||||
|
||||
for(auto processor : m_processors)
|
||||
for(auto* processor : m_processors)
|
||||
{
|
||||
delete processor;
|
||||
}
|
||||
@ -27,9 +27,9 @@ ZoneLoader::~ZoneLoader()
|
||||
|
||||
ILoadingStream* ZoneLoader::BuildLoadingChain(ILoadingStream* rootStream)
|
||||
{
|
||||
ILoadingStream* currentStream = rootStream;
|
||||
auto* currentStream = rootStream;
|
||||
|
||||
for(auto processor : m_processors)
|
||||
for(auto* processor : m_processors)
|
||||
{
|
||||
processor->SetBaseStream(currentStream);
|
||||
|
||||
@ -74,14 +74,14 @@ void ZoneLoader::RemoveStreamProcessor(StreamProcessor* streamProcessor)
|
||||
}
|
||||
}
|
||||
|
||||
Zone* ZoneLoader::LoadZone(FileAPI::File* file)
|
||||
Zone* ZoneLoader::LoadZone(std::istream& stream)
|
||||
{
|
||||
LoadingFileStream fileStream(file);
|
||||
ILoadingStream* endStream = BuildLoadingChain(&fileStream);
|
||||
LoadingFileStream fileStream(stream);
|
||||
auto* endStream = BuildLoadingChain(&fileStream);
|
||||
|
||||
try
|
||||
{
|
||||
for(auto step : m_steps)
|
||||
for(auto* step : m_steps)
|
||||
{
|
||||
step->PerformStep(this, endStream);
|
||||
|
||||
|
@ -3,10 +3,10 @@
|
||||
#include "ILoadingStep.h"
|
||||
#include "Zone/Zone.h"
|
||||
#include "Zone/XBlock.h"
|
||||
#include "Utils/FileAPI.h"
|
||||
#include "StreamProcessor.h"
|
||||
|
||||
#include <vector>
|
||||
#include <istream>
|
||||
|
||||
class ILoadingStep;
|
||||
|
||||
@ -33,5 +33,5 @@ public:
|
||||
|
||||
void RemoveStreamProcessor(StreamProcessor* streamProcessor);
|
||||
|
||||
Zone* LoadZone(FileAPI::File* file);
|
||||
Zone* LoadZone(std::istream& stream);
|
||||
};
|
||||
|
Reference in New Issue
Block a user