1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 19:13:07 +01:00

Move ZipStream into new header

This commit is contained in:
ζeh Matt
2021-09-11 19:06:17 +03:00
parent 2e2bda8f70
commit 2daa356fbf
4 changed files with 93 additions and 70 deletions

View File

@@ -801,6 +801,7 @@
258C212125F84FA2B4C3BCAE /* RideUseSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 58DEACC694664E7C8DACB93D /* RideUseSystem.cpp */; };
E6C71B6165224F65AA87E65B /* RideUseSystem.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DA720D496604387806AC168 /* RideUseSystem.h */; };
C8D612EB56BD4214BEC0F7FF /* GroupVector.hpp in Headers */ = {isa = PBXBuildFile; fileRef = F4D523B8782E4C458AF1490D /* GroupVector.hpp */; };
B2F44E535BD14A03BE8B9D14 /* ZipStream.hpp in Headers */ = {isa = PBXBuildFile; fileRef = F28A181D311D4E078FDB090C /* ZipStream.hpp */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -1906,6 +1907,7 @@
58DEACC694664E7C8DACB93D /* RideUseSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RideUseSystem.cpp; path = src/openrct2/peep/RideUseSystem.cpp; sourceTree = SOURCE_ROOT; };
2DA720D496604387806AC168 /* RideUseSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RideUseSystem.h; path = src/openrct2/peep/RideUseSystem.h; sourceTree = SOURCE_ROOT; };
F4D523B8782E4C458AF1490D /* GroupVector.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = GroupVector.hpp; path = src/openrct2/core/GroupVector.hpp; sourceTree = SOURCE_ROOT; };
F28A181D311D4E078FDB090C /* ZipStream.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = ZipStream.hpp; path = src/openrct2/core/ZipStream.hpp; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -2576,6 +2578,7 @@
F76C839A1EC4E7CC00FA49E2 /* Zip.h */,
BA2317BF6FB54E328DEB7055 /* EnumMap.hpp */,
F4D523B8782E4C458AF1490D /* GroupVector.hpp */,
F28A181D311D4E078FDB090C /* ZipStream.hpp */,
);
path = core;
sourceTree = "<group>";
@@ -3659,6 +3662,7 @@
DEC539DE402F4B8993E4C357 /* ScTileElement.hpp in Headers */,
E6C71B6165224F65AA87E65B /* RideUseSystem.h in Headers */,
C8D612EB56BD4214BEC0F7FF /* GroupVector.hpp in Headers */,
B2F44E535BD14A03BE8B9D14 /* ZipStream.hpp in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@@ -0,0 +1,86 @@
/*****************************************************************************
* Copyright (c) 2014-2021 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#pragma once
#include "IStream.hpp"
#include "Zip.h"
#include <memory>
namespace OpenRCT2
{
/**
* Couples a zip archive and a zip item stream to ensure the lifetime of the zip archive is maintained
* for the lifetime of the stream.
*/
class ZipStreamWrapper final : public IStream
{
private:
std::unique_ptr<IZipArchive> _zipArchive;
std::unique_ptr<IStream> _base;
public:
ZipStreamWrapper(std::unique_ptr<IZipArchive> zipArchive, std::unique_ptr<IStream> base)
: _zipArchive(std::move(zipArchive))
, _base(std::move(base))
{
}
bool CanRead() const override
{
return _base->CanRead();
}
bool CanWrite() const override
{
return _base->CanWrite();
}
uint64_t GetLength() const override
{
return _base->GetLength();
}
uint64_t GetPosition() const override
{
return _base->GetPosition();
}
void SetPosition(uint64_t position) override
{
_base->SetPosition(position);
}
void Seek(int64_t offset, int32_t origin) override
{
_base->Seek(offset, origin);
}
void Read(void* buffer, uint64_t length) override
{
_base->Read(buffer, length);
}
void Write(const void* buffer, uint64_t length) override
{
_base->Write(buffer, length);
}
uint64_t TryRead(void* buffer, uint64_t length) override
{
return _base->TryRead(buffer, length);
}
const void* GetData() const override
{
return _base->GetData();
}
};
} // namespace OpenRCT2

View File

@@ -185,6 +185,7 @@
<ClInclude Include="core\StringBuilder.h" />
<ClInclude Include="core\StringReader.h" />
<ClInclude Include="core\Zip.h" />
<ClInclude Include="core\ZipStream.hpp" />
<ClInclude Include="Date.h" />
<ClInclude Include="Diagnostic.h" />
<ClInclude Include="drawing\Drawing.h" />
@@ -923,4 +924,4 @@
<ClCompile Include="world\Wall.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
</Project>
</Project>

View File

@@ -14,7 +14,7 @@
#include "../core/FileStream.h"
#include "../core/Memory.hpp"
#include "../core/String.hpp"
#include "../core/Zip.h"
#include "../core/ZipStream.hpp"
#include "../localisation/Language.h"
#include "../localisation/LocalisationService.h"
#include "../localisation/StringIds.h"
@@ -171,74 +171,6 @@ std::optional<uint8_t> rct_object_entry::GetSceneryType() const
}
}
/**
* Couples a zip archive and a zip item stream to ensure the lifetime of the zip archive is maintained
* for the lifetime of the stream.
*/
class ZipStreamWrapper final : public IStream
{
private:
std::unique_ptr<IZipArchive> _zipArchive;
std::unique_ptr<IStream> _base;
public:
ZipStreamWrapper(std::unique_ptr<IZipArchive> zipArchive, std::unique_ptr<IStream> base)
: _zipArchive(std::move(zipArchive))
, _base(std::move(base))
{
}
bool CanRead() const override
{
return _base->CanRead();
}
bool CanWrite() const override
{
return _base->CanWrite();
}
uint64_t GetLength() const override
{
return _base->GetLength();
}
uint64_t GetPosition() const override
{
return _base->GetPosition();
}
void SetPosition(uint64_t position) override
{
_base->SetPosition(position);
}
void Seek(int64_t offset, int32_t origin) override
{
_base->Seek(offset, origin);
}
void Read(void* buffer, uint64_t length) override
{
_base->Read(buffer, length);
}
void Write(const void* buffer, uint64_t length) override
{
_base->Write(buffer, length);
}
uint64_t TryRead(void* buffer, uint64_t length) override
{
return _base->TryRead(buffer, length);
}
const void* GetData() const override
{
return _base->GetData();
}
};
bool ObjectAsset::IsAvailable() const
{
if (_zipPath.empty())