mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-06-21 17:47:13 +02:00
Major plugin refactor and cleanup.
Switched to POCO library for unified platform/library interface. Deprecated the external module API. It was creating more problems than solving. Removed most built-in libraries in favor of system libraries for easier maintenance. Cleaned and secured code with help from static analyzers.
This commit is contained in:
51
vendor/POCO/Zip/include/Poco/Zip/Add.h
vendored
Normal file
51
vendor/POCO/Zip/include/Poco/Zip/Add.h
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
//
|
||||
// Add.h
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Manipulation
|
||||
// Module: Add
|
||||
//
|
||||
// Definition of the Add class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Zip_Add_INCLUDED
|
||||
#define Zip_Add_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Zip/Zip.h"
|
||||
#include "Poco/Zip/ZipOperation.h"
|
||||
#include "Poco/Zip/ZipCommon.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Zip {
|
||||
|
||||
|
||||
class Zip_API Add: public ZipOperation
|
||||
/// Operation Add adds a new file entry to an existing Zip File
|
||||
{
|
||||
public:
|
||||
Add(const std::string& zipPath, const std::string& localPath, ZipCommon::CompressionMethod cm, ZipCommon::CompressionLevel cl);
|
||||
/// Creates the Add.
|
||||
|
||||
void execute(Compress& c, std::istream& input);
|
||||
/// Performs the add operation
|
||||
|
||||
private:
|
||||
const std::string _zipPath;
|
||||
const std::string _localPath;
|
||||
const ZipCommon::CompressionMethod _cm;
|
||||
const ZipCommon::CompressionLevel _cl;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Zip
|
||||
|
||||
|
||||
#endif // Zip_Add_INCLUDED
|
101
vendor/POCO/Zip/include/Poco/Zip/AutoDetectStream.h
vendored
Normal file
101
vendor/POCO/Zip/include/Poco/Zip/AutoDetectStream.h
vendored
Normal file
@ -0,0 +1,101 @@
|
||||
//
|
||||
// AutoDetectStream.h
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Zip
|
||||
// Module: AutoDetectStream
|
||||
//
|
||||
// Definition of the AutoDetectStream class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Zip_AutoDetectStream_INCLUDED
|
||||
#define Zip_AutoDetectStream_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Zip/Zip.h"
|
||||
#include "Poco/BufferedStreamBuf.h"
|
||||
#include <istream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Zip {
|
||||
|
||||
|
||||
class Zip_API AutoDetectStreamBuf: public Poco::BufferedStreamBuf
|
||||
/// AutoDetectStreamBuf automatically detects the end of a stream using the
|
||||
/// Data Descriptor signature.
|
||||
{
|
||||
public:
|
||||
AutoDetectStreamBuf(std::istream& in, const std::string& prefix, const std::string& postfix, bool reposition, Poco::UInt32 start, bool needsZip64);
|
||||
/// Creates the AutoDetectStream.
|
||||
|
||||
~AutoDetectStreamBuf();
|
||||
/// Destroys the AutoDetectStream.
|
||||
|
||||
protected:
|
||||
int readFromDevice(char* buffer, std::streamsize length);
|
||||
int writeToDevice(const char* buffer, std::streamsize length);
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
STREAM_BUFFER_SIZE = 1024
|
||||
};
|
||||
|
||||
std::istream* _pIstr;
|
||||
bool _eofDetected;
|
||||
int _matchCnt;
|
||||
std::string _prefix;
|
||||
std::string _postfix;
|
||||
bool _reposition;
|
||||
Poco::UInt32 _start;
|
||||
bool _needsZip64;
|
||||
Poco::UInt64 _length;
|
||||
};
|
||||
|
||||
|
||||
class Zip_API AutoDetectIOS: public virtual std::ios
|
||||
/// The base class for AutoDetectInputStream and AutoDetectOutputStream.
|
||||
///
|
||||
/// This class is needed to ensure the correct initialization
|
||||
/// order of the stream buffer and base classes.
|
||||
{
|
||||
public:
|
||||
AutoDetectIOS(std::istream& istr, const std::string& prefix, const std::string& postfix, bool reposition, Poco::UInt32 start, bool needsZip64);
|
||||
/// Creates the basic stream and connects it
|
||||
/// to the given input stream.
|
||||
|
||||
~AutoDetectIOS();
|
||||
/// Destroys the stream.
|
||||
|
||||
AutoDetectStreamBuf* rdbuf();
|
||||
/// Returns a pointer to the underlying streambuf.
|
||||
|
||||
protected:
|
||||
AutoDetectStreamBuf _buf;
|
||||
};
|
||||
|
||||
|
||||
class Zip_API AutoDetectInputStream: public AutoDetectIOS, public std::istream
|
||||
/// AutoDetectInputStream automatically detects the end of a stream using the
|
||||
/// Data Descriptor signature.
|
||||
{
|
||||
public:
|
||||
AutoDetectInputStream(std::istream& istr, const std::string& prefix = std::string(), const std::string& postfix = std::string(), bool reposition = false, Poco::UInt32 start = 0, bool needsZip64 = false);
|
||||
/// Creates the AutoDetectInputStream and connects it to the underlying stream.
|
||||
|
||||
~AutoDetectInputStream();
|
||||
/// Destroys the AutoDetectInputStream.
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Zip
|
||||
|
||||
|
||||
#endif // Zip_AutoDetectStream_INCLUDED
|
151
vendor/POCO/Zip/include/Poco/Zip/Compress.h
vendored
Normal file
151
vendor/POCO/Zip/include/Poco/Zip/Compress.h
vendored
Normal file
@ -0,0 +1,151 @@
|
||||
//
|
||||
// Compress.h
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Zip
|
||||
// Module: Compress
|
||||
//
|
||||
// Definition of the Compress class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Zip_Compress_INCLUDED
|
||||
#define Zip_Compress_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Zip/Zip.h"
|
||||
#include "Poco/Zip/ZipArchive.h"
|
||||
#include "Poco/FIFOEvent.h"
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#include <set>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Zip {
|
||||
|
||||
|
||||
class Zip_API Compress
|
||||
/// Compresses a directory or files as zip.
|
||||
{
|
||||
public:
|
||||
Poco::FIFOEvent<const ZipLocalFileHeader> EDone;
|
||||
|
||||
Compress(std::ostream& out, bool seekableOut, bool forceZip64 = false);
|
||||
/// seekableOut determines how we write the zip, setting it to true is recommended for local files (smaller zip file),
|
||||
/// if you are compressing directly to a network, you MUST set it to false
|
||||
/// If forceZip64 is set true then the file header is allocated with zip64 extension so that it can be updated after the file data is written
|
||||
/// if seekableOut is true in case the compressed or uncompressed size exceeds 32 bits.
|
||||
|
||||
~Compress();
|
||||
|
||||
void addFile(std::istream& input, const Poco::DateTime& lastModifiedAt, const Poco::Path& fileName, ZipCommon::CompressionMethod cm = ZipCommon::CM_DEFLATE, ZipCommon::CompressionLevel cl = ZipCommon::CL_MAXIMUM);
|
||||
/// Adds a single file to the Zip File. fileName must not be a directory name.
|
||||
|
||||
void addFile(const Poco::Path& file, const Poco::Path& fileName, ZipCommon::CompressionMethod cm = ZipCommon::CM_DEFLATE, ZipCommon::CompressionLevel cl = ZipCommon::CL_MAXIMUM);
|
||||
/// Adds a single file to the Zip File. fileName must not be a directory name. The file must exist physically!
|
||||
|
||||
void addDirectory(const Poco::Path& entryName, const Poco::DateTime& lastModifiedAt);
|
||||
/// Adds a directory entry excluding all children to the Zip file, entryName must not be empty.
|
||||
|
||||
void addRecursive(const Poco::Path& entry, ZipCommon::CompressionLevel cl = ZipCommon::CL_MAXIMUM, bool excludeRoot = true, const Poco::Path& name = Poco::Path());
|
||||
/// Adds a directory entry recursively to the zip file, set excludeRoot to false to exclude the parent directory.
|
||||
/// If excludeRoot is true you can specify an empty name to add the files as relative files
|
||||
|
||||
void addRecursive(const Poco::Path& entry, ZipCommon::CompressionMethod cm, ZipCommon::CompressionLevel cl = ZipCommon::CL_MAXIMUM, bool excludeRoot = true, const Poco::Path& name = Poco::Path());
|
||||
/// Adds a directory entry recursively to the zip file, set excludeRoot to false to exclude the parent directory.
|
||||
/// If excludeRoot is true you can specify an empty name to add the files as relative files
|
||||
|
||||
void setZipComment(const std::string& comment);
|
||||
/// Sets the Zip file comment.
|
||||
|
||||
const std::string& getZipComment() const;
|
||||
/// Returns the Zip file comment.
|
||||
|
||||
ZipArchive close();
|
||||
/// Finalizes the ZipArchive, closes it.
|
||||
|
||||
void setStoreExtensions(const std::set<std::string>& extensions);
|
||||
/// Sets the file extensions for which the CM_STORE compression method
|
||||
/// is used if CM_AUTO is specified in addFile() or addRecursive().
|
||||
/// For all other extensions, CM_DEFLATE is used. This is used to avoid
|
||||
/// double compression of already compressed file formats, which usually
|
||||
/// leads to worse results. Extensions will be converted to lower case.
|
||||
///
|
||||
/// The default extensions are:
|
||||
/// - gif
|
||||
/// - jpg
|
||||
/// - jpeg
|
||||
/// - png
|
||||
|
||||
const std::set<std::string>& getStoreExtensions() const;
|
||||
/// Returns the file extensions for which the CM_STORE compression method
|
||||
/// is used if CM_AUTO is specified in addFile() or addRecursive().
|
||||
///
|
||||
/// See setStoreExtensions() for more information.
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
COMPRESS_CHUNK_SIZE = 8192
|
||||
};
|
||||
|
||||
Compress(const Compress&);
|
||||
Compress& operator=(const Compress&);
|
||||
|
||||
void addEntry(std::istream& input, const Poco::DateTime& lastModifiedAt, const Poco::Path& fileName, ZipCommon::CompressionMethod cm = ZipCommon::CM_DEFLATE, ZipCommon::CompressionLevel cl = ZipCommon::CL_MAXIMUM);
|
||||
/// Either adds a file or a single directory entry (excluding subchildren) to the Zip file. the compression level will be ignored
|
||||
/// for directories.
|
||||
|
||||
void addFileRaw(std::istream& in, const ZipLocalFileHeader& hdr, const Poco::Path& fileName);
|
||||
/// copys an already compressed ZipEntry from in
|
||||
|
||||
private:
|
||||
std::set<std::string> _storeExtensions;
|
||||
std::ostream& _out;
|
||||
bool _seekableOut;
|
||||
bool _forceZip64;
|
||||
ZipArchive::FileHeaders _files;
|
||||
ZipArchive::FileInfos _infos;
|
||||
ZipArchive::DirectoryInfos _dirs;
|
||||
ZipArchive::DirectoryInfos64 _dirs64;
|
||||
Poco::UInt64 _offset;
|
||||
std::string _comment;
|
||||
|
||||
friend class Keep;
|
||||
friend class Rename;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
|
||||
|
||||
inline void Compress::setZipComment(const std::string& comment)
|
||||
{
|
||||
_comment = comment;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& Compress::getZipComment() const
|
||||
{
|
||||
return _comment;
|
||||
}
|
||||
|
||||
|
||||
inline const std::set<std::string>& Compress::getStoreExtensions() const
|
||||
{
|
||||
return _storeExtensions;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Zip
|
||||
|
||||
|
||||
#endif // Zip_Compress_INCLUDED
|
92
vendor/POCO/Zip/include/Poco/Zip/Decompress.h
vendored
Normal file
92
vendor/POCO/Zip/include/Poco/Zip/Decompress.h
vendored
Normal file
@ -0,0 +1,92 @@
|
||||
//
|
||||
// Decompress.h
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Zip
|
||||
// Module: Decompress
|
||||
//
|
||||
// Definition of the Decompress class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Zip_Decompress_INCLUDED
|
||||
#define Zip_Decompress_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Zip/Zip.h"
|
||||
#include "Poco/Zip/ParseCallback.h"
|
||||
#include "Poco/Zip/ZipArchive.h"
|
||||
#include "Poco/Path.h"
|
||||
#include "Poco/FIFOEvent.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Zip {
|
||||
|
||||
|
||||
class ZipArchive;
|
||||
|
||||
|
||||
class Zip_API Decompress: public ParseCallback
|
||||
/// Decompress extracts files from zip files, can be used to extract single files or all files
|
||||
{
|
||||
public:
|
||||
using ZipMapping = std::map<std::string, Poco::Path>;
|
||||
/// Maps key of FileInfo entries to their local decompressed representation
|
||||
|
||||
Poco::FIFOEvent<std::pair<const ZipLocalFileHeader, const std::string>> EError;
|
||||
/// Thrown whenever an error is detected when handling a ZipLocalFileHeader entry. The string contains an error message
|
||||
|
||||
Poco::FIFOEvent<std::pair<const ZipLocalFileHeader, const Poco::Path>> EOk;
|
||||
/// Thrown whenever a file was successfully decompressed
|
||||
|
||||
Decompress(std::istream& in, const Poco::Path& outputDir, bool flattenDirs = false, bool keepIncompleteFiles = false);
|
||||
/// Creates the Decompress. Note that istream must be good and at the very beginning of the file!
|
||||
/// Calling decompressAllFiles will cause the stream to be in state failed once the zip file is processed.
|
||||
/// outputDir must be a directory. If it doesn't exist yet, it will be automatically created.
|
||||
/// If flattenDirs is set to true, the directory structure of the zip file is not recreated.
|
||||
/// Instead, all files are extracted into one single directory.
|
||||
|
||||
~Decompress();
|
||||
/// Destroys the Decompress.
|
||||
|
||||
ZipArchive decompressAllFiles();
|
||||
/// Decompresses all files stored in the zip File. Can only be called once per Decompress object.
|
||||
/// Use mapping to retrieve the location of the decompressed files
|
||||
|
||||
bool handleZipEntry(std::istream& zipStream, const ZipLocalFileHeader& hdr);
|
||||
|
||||
const ZipMapping& mapping() const;
|
||||
/// A ZipMapping stores as key the full name of the ZipFileInfo/ZipLocalFileHeader and as value the decompressed file
|
||||
/// If for a ZipFileInfo no mapping exists, there was an error during decompression and the entry is considered to be corrupt
|
||||
|
||||
private:
|
||||
Decompress(const Decompress&);
|
||||
Decompress& operator=(const Decompress&);
|
||||
|
||||
void onOk(const void*, std::pair<const ZipLocalFileHeader, const Poco::Path>& val);
|
||||
|
||||
private:
|
||||
std::istream& _in;
|
||||
Poco::Path _outDir;
|
||||
bool _flattenDirs;
|
||||
bool _keepIncompleteFiles;
|
||||
ZipMapping _mapping;
|
||||
};
|
||||
|
||||
|
||||
inline const Decompress::ZipMapping& Decompress::mapping() const
|
||||
{
|
||||
return _mapping;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Zip
|
||||
|
||||
|
||||
#endif // Zip_Decompress_INCLUDED
|
48
vendor/POCO/Zip/include/Poco/Zip/Delete.h
vendored
Normal file
48
vendor/POCO/Zip/include/Poco/Zip/Delete.h
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
//
|
||||
// Delete.h
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Manipulation
|
||||
// Module: Delete
|
||||
//
|
||||
// Definition of the Delete class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Zip_Delete_INCLUDED
|
||||
#define Zip_Delete_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Zip/Zip.h"
|
||||
#include "Poco/Zip/ZipOperation.h"
|
||||
#include "Poco/Zip/ZipLocalFileHeader.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Zip {
|
||||
|
||||
|
||||
class Zip_API Delete: public ZipOperation
|
||||
/// Delete Operation removes an entry from a Zip
|
||||
{
|
||||
public:
|
||||
Delete(const ZipLocalFileHeader& hdr);
|
||||
/// Creates the Delete.
|
||||
|
||||
void execute(Compress& c, std::istream& input);
|
||||
/// Throws away the ZipEntry
|
||||
|
||||
private:
|
||||
const ZipLocalFileHeader _hdr;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Zip
|
||||
|
||||
|
||||
#endif // Zip_Delete_INCLUDED
|
49
vendor/POCO/Zip/include/Poco/Zip/Keep.h
vendored
Normal file
49
vendor/POCO/Zip/include/Poco/Zip/Keep.h
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
//
|
||||
// Keep.h
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Manipulation
|
||||
// Module: Keep
|
||||
//
|
||||
// Definition of the Keep class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Zip_Keep_INCLUDED
|
||||
#define Zip_Keep_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Zip/Zip.h"
|
||||
#include "Poco/Zip/ZipOperation.h"
|
||||
#include "Poco/Zip/ZipLocalFileHeader.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Zip {
|
||||
|
||||
|
||||
class Zip_API Keep: public ZipOperation
|
||||
/// Keep simply forwards the compressed data stream from the input ZipArchive
|
||||
/// to the output zip archive
|
||||
{
|
||||
public:
|
||||
Keep(const ZipLocalFileHeader& hdr);
|
||||
/// Creates the Keep object.
|
||||
|
||||
void execute(Compress& c, std::istream& input);
|
||||
///Adds a copy of the compressed input file to the ZipArchive
|
||||
|
||||
private:
|
||||
const ZipLocalFileHeader _hdr;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Zip
|
||||
|
||||
|
||||
#endif // Zip_Keep_INCLUDED
|
54
vendor/POCO/Zip/include/Poco/Zip/ParseCallback.h
vendored
Normal file
54
vendor/POCO/Zip/include/Poco/Zip/ParseCallback.h
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
//
|
||||
// ParseCallback.h
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Zip
|
||||
// Module: ParseCallback
|
||||
//
|
||||
// Definition of the ParseCallback class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Zip_ParseCallback_INCLUDED
|
||||
#define Zip_ParseCallback_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Zip/Zip.h"
|
||||
#include <istream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Zip {
|
||||
|
||||
|
||||
class ZipLocalFileHeader;
|
||||
|
||||
|
||||
class Zip_API ParseCallback
|
||||
/// Interface for callbacks to handle ZipData
|
||||
{
|
||||
public:
|
||||
ParseCallback();
|
||||
/// Creates the ParseCallback.
|
||||
|
||||
virtual ~ParseCallback();
|
||||
/// Destroys the ParseCallback.
|
||||
|
||||
virtual bool handleZipEntry(std::istream& zipStream, const ZipLocalFileHeader& hdr) = 0;
|
||||
/// Handles parsing of the data of a single Zip Entry. zipStream is guaranteed to be at the very first data byte.
|
||||
/// Note that a callback class SHOULD consume all data inside a zip file, ie. after
|
||||
/// processing the next 4 bytes point the next ZipLocalFileHeader or the ZipDirectory.
|
||||
/// If it fails to do so, it must return false, otherwise true.
|
||||
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Zip
|
||||
|
||||
|
||||
#endif // Zip_ParseCallback_INCLUDED
|
187
vendor/POCO/Zip/include/Poco/Zip/PartialStream.h
vendored
Normal file
187
vendor/POCO/Zip/include/Poco/Zip/PartialStream.h
vendored
Normal file
@ -0,0 +1,187 @@
|
||||
//
|
||||
// PartialStream.h
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Zip
|
||||
// Module: PartialStream
|
||||
//
|
||||
// Definition of the PartialStream class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Zip_PartialStream_INCLUDED
|
||||
#define Zip_PartialStream_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Zip/Zip.h"
|
||||
#include "Poco/BufferedStreamBuf.h"
|
||||
#include "Poco/Buffer.h"
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Zip {
|
||||
|
||||
|
||||
class Zip_API PartialStreamBuf: public Poco::BufferedStreamBuf
|
||||
/// A PartialStreamBuf is a class that limits one view on an inputstream to a selected view range
|
||||
{
|
||||
public:
|
||||
PartialStreamBuf(std::istream& in, std::ios::pos_type start, std::ios::pos_type end, const std::string& prefix, const std::string& postfix, bool initStream);
|
||||
/// Creates the PartialStream.
|
||||
/// If initStream is true the status of the stream will be cleared on the first access, and the stream will be repositioned
|
||||
/// to position start
|
||||
|
||||
PartialStreamBuf(std::ostream& out, std::size_t start, std::size_t end, bool initStream);
|
||||
/// Creates the PartialStream.
|
||||
/// If initStream is true the status of the stream will be cleared on the first access.
|
||||
/// start and end acts as offset values for the written content. A start value greater than zero,
|
||||
/// means that the first bytes are not written but discarded instead,
|
||||
/// an end value not equal to zero means that the last end bytes are not written!
|
||||
/// Examples:
|
||||
/// start = 3; end = 1
|
||||
/// write("hello", 5) -> "l"
|
||||
|
||||
~PartialStreamBuf();
|
||||
/// Destroys the PartialStream.
|
||||
|
||||
void close();
|
||||
/// Flushes a writing streambuf
|
||||
|
||||
Poco::UInt64 bytesWritten() const;
|
||||
|
||||
protected:
|
||||
int readFromDevice(char* buffer, std::streamsize length);
|
||||
|
||||
int writeToDevice(const char* buffer, std::streamsize length);
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
STREAM_BUFFER_SIZE = 1024
|
||||
};
|
||||
|
||||
bool _initialized;
|
||||
std::ios::pos_type _start;
|
||||
Poco::UInt64 _numBytes;
|
||||
Poco::UInt64 _bytesWritten;
|
||||
std::istream* _pIstr;
|
||||
std::ostream* _pOstr;
|
||||
std::string _prefix;
|
||||
std::string _postfix;
|
||||
std::size_t _ignoreStart;
|
||||
Poco::Buffer<char> _buffer;
|
||||
Poco::UInt32 _bufferOffset;
|
||||
};
|
||||
|
||||
|
||||
inline Poco::UInt64 PartialStreamBuf::bytesWritten() const
|
||||
{
|
||||
return _bytesWritten;
|
||||
}
|
||||
|
||||
|
||||
class Zip_API PartialIOS: public virtual std::ios
|
||||
/// The base class for PartialInputStream and PartialOutputStream.
|
||||
///
|
||||
/// This class is needed to ensure the correct initialization
|
||||
/// order of the stream buffer and base classes.
|
||||
{
|
||||
public:
|
||||
PartialIOS(std::istream& istr, std::ios::pos_type start, std::ios::pos_type end, const std::string& prefix, const std::string& postfix, bool initStream);
|
||||
/// Creates the basic stream and connects it
|
||||
/// to the given input stream.
|
||||
/// If initStream is true the status of the stream will be cleared on the first access, and the stream will be repositioned
|
||||
/// to position start
|
||||
|
||||
PartialIOS(std::ostream& ostr, std::size_t start, std::size_t end, bool initStream);
|
||||
/// Creates the basic stream and connects it
|
||||
/// to the given output stream.
|
||||
/// If initStream is true the status of the stream will be cleared on the first access.
|
||||
/// start and end acts as offset values for the written content. A start value greater than zero,
|
||||
/// means that the first bytes are not written but discarded instead,
|
||||
/// an end value not equal to zero means that the last end bytes are not written!
|
||||
/// Examples:
|
||||
/// start = 3; end = 1
|
||||
/// write("hello", 5) -> "l"
|
||||
|
||||
~PartialIOS();
|
||||
/// Destroys the stream.
|
||||
|
||||
PartialStreamBuf* rdbuf();
|
||||
/// Returns a pointer to the underlying streambuf.
|
||||
|
||||
protected:
|
||||
PartialStreamBuf _buf;
|
||||
};
|
||||
|
||||
|
||||
class Zip_API PartialInputStream: public PartialIOS, public std::istream
|
||||
/// This stream copies all characters read through it
|
||||
/// to one or multiple output streams.
|
||||
{
|
||||
public:
|
||||
PartialInputStream(std::istream& istr, std::ios::pos_type start, std::ios::pos_type end, bool initStream = true, const std::string& prefix = std::string(), const std::string& postfix = std::string());
|
||||
/// Creates the PartialInputStream and connects it
|
||||
/// to the given input stream. Bytes read are guaranteed to be in the range [start, end-1]
|
||||
/// If initStream is true the status of the stream will be cleared on the first access, and the stream will be repositioned
|
||||
/// to position start
|
||||
|
||||
~PartialInputStream();
|
||||
/// Destroys the PartialInputStream.
|
||||
};
|
||||
|
||||
|
||||
class Zip_API PartialOutputStream: public PartialIOS, public std::ostream
|
||||
/// This stream copies all characters written to it
|
||||
/// to one or multiple output streams.
|
||||
{
|
||||
public:
|
||||
PartialOutputStream(std::ostream& ostr, std::size_t start, std::size_t end, bool initStream = true);
|
||||
/// Creates the PartialOutputStream and connects it
|
||||
/// to the given output stream. Bytes written are guaranteed to be in the range [start, realEnd - end].
|
||||
/// If initStream is true the status of the stream will be cleared on the first access.
|
||||
/// start and end acts as offset values for the written content. A start value greater than zero,
|
||||
/// means that the first bytes are not written but discarded instead,
|
||||
/// an end value not equal to zero means that the last end bytes are not written!
|
||||
/// Examples:
|
||||
/// start = 3; end = 1
|
||||
/// write("hello", 5) -> "l"
|
||||
///
|
||||
/// start = 3; end = 0
|
||||
/// write("hello", 5) -> "lo"
|
||||
|
||||
~PartialOutputStream();
|
||||
/// Destroys the PartialOutputStream.
|
||||
|
||||
void close();
|
||||
/// must be called for the stream to properly terminate it
|
||||
|
||||
Poco::UInt64 bytesWritten() const;
|
||||
/// Returns the number of bytes actually forwarded to the inner ostream
|
||||
};
|
||||
|
||||
|
||||
inline void PartialOutputStream::close()
|
||||
{
|
||||
flush();
|
||||
_buf.close();
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt64 PartialOutputStream::bytesWritten() const
|
||||
{
|
||||
return _buf.bytesWritten();
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Zip
|
||||
|
||||
|
||||
#endif // Zip_PartialStream_INCLUDED
|
49
vendor/POCO/Zip/include/Poco/Zip/Rename.h
vendored
Normal file
49
vendor/POCO/Zip/include/Poco/Zip/Rename.h
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
//
|
||||
// Rename.h
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Manipulation
|
||||
// Module: Rename
|
||||
//
|
||||
// Definition of the Rename class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Zip_Rename_INCLUDED
|
||||
#define Zip_Rename_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Zip/Zip.h"
|
||||
#include "Poco/Zip/ZipOperation.h"
|
||||
#include "Poco/Zip/ZipLocalFileHeader.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Zip {
|
||||
|
||||
|
||||
class Zip_API Rename: public ZipOperation
|
||||
/// Renames an existing Zip Entry
|
||||
{
|
||||
public:
|
||||
Rename(const ZipLocalFileHeader& hdr, const std::string& newZipEntryName);
|
||||
/// Creates the Rename.
|
||||
|
||||
void execute(Compress& c, std::istream& input);
|
||||
/// Performs the rename operation
|
||||
|
||||
private:
|
||||
const ZipLocalFileHeader _hdr;
|
||||
const std::string _newZipEntryName;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Zip
|
||||
|
||||
|
||||
#endif // Zip_Rename_INCLUDED
|
50
vendor/POCO/Zip/include/Poco/Zip/Replace.h
vendored
Normal file
50
vendor/POCO/Zip/include/Poco/Zip/Replace.h
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
//
|
||||
// Replace.h
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Manipulation
|
||||
// Module: Replace
|
||||
//
|
||||
// Definition of the Replace class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Zip_Replace_INCLUDED
|
||||
#define Zip_Replace_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Zip/Zip.h"
|
||||
#include "Poco/Zip/Add.h"
|
||||
#include "Poco/Zip/Delete.h"
|
||||
#include "Poco/Zip/ZipOperation.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Zip {
|
||||
|
||||
|
||||
class Zip_API Replace: public ZipOperation
|
||||
/// Operation Replace replaces the content of an existing entry with a new one
|
||||
{
|
||||
public:
|
||||
Replace(const ZipLocalFileHeader& hdr, const std::string& localPath);
|
||||
/// Creates the Replace.
|
||||
|
||||
void execute(Compress& c, std::istream& input);
|
||||
/// Performs the replace operation
|
||||
|
||||
private:
|
||||
Delete _del;
|
||||
Add _add;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Zip
|
||||
|
||||
|
||||
#endif // Zip_Replace_INCLUDED
|
46
vendor/POCO/Zip/include/Poco/Zip/SkipCallback.h
vendored
Normal file
46
vendor/POCO/Zip/include/Poco/Zip/SkipCallback.h
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
//
|
||||
// SkipCallback.h
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Zip
|
||||
// Module: SkipCallback
|
||||
//
|
||||
// Definition of the SkipCallback class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Zip_SkipCallback_INCLUDED
|
||||
#define Zip_SkipCallback_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Zip/Zip.h"
|
||||
#include "Poco/Zip/ParseCallback.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Zip {
|
||||
|
||||
|
||||
class Zip_API SkipCallback: public ParseCallback
|
||||
/// A SkipCallback simply skips over the data
|
||||
{
|
||||
public:
|
||||
SkipCallback();
|
||||
/// Creates the SkipCallback.
|
||||
|
||||
virtual ~SkipCallback();
|
||||
/// Destroys the SkipCallback.
|
||||
|
||||
bool handleZipEntry(std::istream& zipStream, const ZipLocalFileHeader& hdr);
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Zip
|
||||
|
||||
|
||||
#endif // Zip_SkipCallback_INCLUDED
|
62
vendor/POCO/Zip/include/Poco/Zip/Zip.h
vendored
Normal file
62
vendor/POCO/Zip/include/Poco/Zip/Zip.h
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
//
|
||||
// Zip.h
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Zip
|
||||
// Module: Zip
|
||||
//
|
||||
// Basic definitions for the Poco Zip library.
|
||||
// This file must be the first file included by every other Zip
|
||||
// header file.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Zip_Zip_INCLUDED
|
||||
#define Zip_Zip_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
|
||||
|
||||
//
|
||||
// The following block is the standard way of creating macros which make exporting
|
||||
// from a DLL simpler. All files within this DLL are compiled with the Zip_EXPORTS
|
||||
// symbol defined on the command line. this symbol should not be defined on any project
|
||||
// that uses this DLL. This way any other project whose source files include this file see
|
||||
// Zip_API functions as being imported from a DLL, whereas this DLL sees symbols
|
||||
// defined with this macro as being exported.
|
||||
//
|
||||
#if defined(_WIN32) && defined(POCO_DLL)
|
||||
#if defined(Zip_EXPORTS)
|
||||
#define Zip_API __declspec(dllexport)
|
||||
#else
|
||||
#define Zip_API __declspec(dllimport)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(Zip_API)
|
||||
#if !defined(POCO_NO_GCC_API_ATTRIBUTE) && defined (__GNUC__) && (__GNUC__ >= 4)
|
||||
#define Zip_API __attribute__ ((visibility ("default")))
|
||||
#else
|
||||
#define Zip_API
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
//
|
||||
// Automatically link Zip library.
|
||||
//
|
||||
#if defined(_MSC_VER)
|
||||
#if !defined(POCO_NO_AUTOMATIC_LIBS) && !defined(Zip_EXPORTS)
|
||||
#pragma comment(lib, "PocoZip" POCO_LIB_SUFFIX)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#endif // Zip_Zip_INCLUDED
|
121
vendor/POCO/Zip/include/Poco/Zip/ZipArchive.h
vendored
Normal file
121
vendor/POCO/Zip/include/Poco/Zip/ZipArchive.h
vendored
Normal file
@ -0,0 +1,121 @@
|
||||
//
|
||||
// ZipArchive.h
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Zip
|
||||
// Module: ZipArchive
|
||||
//
|
||||
// Definition of the ZipArchive class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Zip_ZipArchive_INCLUDED
|
||||
#define Zip_ZipArchive_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Zip/Zip.h"
|
||||
#include "Poco/Zip/ZipLocalFileHeader.h"
|
||||
#include "Poco/Zip/ZipFileInfo.h"
|
||||
#include "Poco/Zip/ZipArchiveInfo.h"
|
||||
#include <istream>
|
||||
#include <map>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Zip {
|
||||
|
||||
|
||||
class ParseCallback;
|
||||
class Compress;
|
||||
|
||||
|
||||
class Zip_API ZipArchive
|
||||
/// A ZipArchive contains information on the content of a zip file
|
||||
{
|
||||
public:
|
||||
using FileHeaders = std::map<std::string, ZipLocalFileHeader>;
|
||||
using FileInfos = std::map<std::string, ZipFileInfo>;
|
||||
using DirectoryInfos = std::map<Poco::UInt16, ZipArchiveInfo>;
|
||||
using DirectoryInfos64 = std::map<Poco::UInt32, ZipArchiveInfo64>;
|
||||
|
||||
ZipArchive(std::istream& in);
|
||||
/// Creates the ZipArchive from a file. Note that the in stream will be in state failed after the constructor is finished
|
||||
|
||||
ZipArchive(std::istream& in, ParseCallback& callback);
|
||||
/// Creates the ZipArchive from a file or network stream. Note that the in stream will be in state failed after the constructor is finished
|
||||
|
||||
~ZipArchive();
|
||||
/// Destroys the ZipArchive.
|
||||
|
||||
FileInfos::const_iterator fileInfoBegin() const;
|
||||
|
||||
FileInfos::const_iterator fileInfoEnd() const;
|
||||
|
||||
FileHeaders::const_iterator findHeader(const std::string& fileName) const;
|
||||
|
||||
FileHeaders::const_iterator headerBegin() const;
|
||||
|
||||
FileHeaders::const_iterator headerEnd() const;
|
||||
|
||||
const std::string& getZipComment() const;
|
||||
|
||||
private:
|
||||
void parse(std::istream& in, ParseCallback& pc);
|
||||
|
||||
ZipArchive(const FileHeaders& entries, const FileInfos& infos, const DirectoryInfos& dirs, const DirectoryInfos64& dirs64 );
|
||||
|
||||
private:
|
||||
FileHeaders _entries;
|
||||
/// Info generated by parsing the data block of the zip file
|
||||
FileInfos _infos;
|
||||
/// Info generated by parsing the directory block of the zip file
|
||||
DirectoryInfos _disks;
|
||||
/// Stores directory info for all found disks
|
||||
DirectoryInfos64 _disks64;
|
||||
/// Stores directory info for all found disks
|
||||
|
||||
static const std::string EMPTY_COMMENT;
|
||||
|
||||
friend class Compress;
|
||||
};
|
||||
|
||||
|
||||
inline ZipArchive::FileInfos::const_iterator ZipArchive::fileInfoBegin() const
|
||||
{
|
||||
return _infos.begin();
|
||||
}
|
||||
|
||||
|
||||
inline ZipArchive::FileInfos::const_iterator ZipArchive::fileInfoEnd() const
|
||||
{
|
||||
return _infos.end();
|
||||
}
|
||||
|
||||
|
||||
inline ZipArchive::FileHeaders::const_iterator ZipArchive::findHeader(const std::string& fileName) const
|
||||
{
|
||||
return _entries.find(fileName);
|
||||
}
|
||||
|
||||
|
||||
inline ZipArchive::FileHeaders::const_iterator ZipArchive::headerBegin() const
|
||||
{
|
||||
return _entries.begin();
|
||||
}
|
||||
|
||||
|
||||
inline ZipArchive::FileHeaders::const_iterator ZipArchive::headerEnd() const
|
||||
{
|
||||
return _entries.end();
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Zip
|
||||
|
||||
|
||||
#endif // Zip_ZipArchive_INCLUDED
|
405
vendor/POCO/Zip/include/Poco/Zip/ZipArchiveInfo.h
vendored
Normal file
405
vendor/POCO/Zip/include/Poco/Zip/ZipArchiveInfo.h
vendored
Normal file
@ -0,0 +1,405 @@
|
||||
//
|
||||
// ZipArchiveInfo.h
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Zip
|
||||
// Module: ZipArchiveInfo
|
||||
//
|
||||
// Definition of the ZipArchiveInfo class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Zip_ZipArchiveInfo_INCLUDED
|
||||
#define Zip_ZipArchiveInfo_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Zip/Zip.h"
|
||||
#include "Poco/Zip/ZipCommon.h"
|
||||
#include "Poco/Zip/ZipUtil.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Zip {
|
||||
|
||||
|
||||
class Zip_API ZipArchiveInfo
|
||||
/// A ZipArchiveInfo stores central directory info
|
||||
{
|
||||
public:
|
||||
static const char HEADER[ZipCommon::HEADER_SIZE];
|
||||
|
||||
ZipArchiveInfo();
|
||||
/// Default constructor, everything set to zero or empty
|
||||
|
||||
ZipArchiveInfo(std::istream& in, bool assumeHeaderRead);
|
||||
/// Creates the ZipArchiveInfo by parsing the input stream.
|
||||
/// If assumeHeaderRead is true we assume that the first 4 bytes were already read outside.
|
||||
|
||||
~ZipArchiveInfo();
|
||||
/// Destroys the ZipArchiveInfo.
|
||||
|
||||
Poco::UInt16 getDiskNumber() const;
|
||||
/// Get the number of the disk where this header can be found
|
||||
|
||||
Poco::UInt16 getFirstDiskForDirectoryHeader() const;
|
||||
/// Returns the number of the disk that contains the start of the directory header
|
||||
|
||||
Poco::UInt16 getNumberOfEntries() const;
|
||||
/// Returns the number of entries on this disk
|
||||
|
||||
Poco::UInt16 getTotalNumberOfEntries() const;
|
||||
/// Returns the total number of entries on all disks
|
||||
|
||||
Poco::UInt32 getCentralDirectorySize() const;
|
||||
/// Returns the size of the central directory in bytes
|
||||
|
||||
std::streamoff getHeaderOffset() const;
|
||||
/// Returns the offset of the header in relation to the begin of this disk
|
||||
|
||||
const std::string& getZipComment() const;
|
||||
/// Returns the (optional) Zip Comment
|
||||
|
||||
void setZipComment(const std::string& comment);
|
||||
/// Sets the optional Zip comment.
|
||||
|
||||
void setNumberOfEntries(Poco::UInt16 val);
|
||||
/// Sets the number of entries on this disk
|
||||
|
||||
void setTotalNumberOfEntries(Poco::UInt16 val);
|
||||
/// Sets the total number of entries on all disks
|
||||
|
||||
void setCentralDirectorySize(Poco::UInt32 val);
|
||||
/// Sets the size of the central directory in bytes
|
||||
|
||||
void setCentralDirectoryOffset(Poco::UInt32 val);
|
||||
/// Sets the offset of the central directory from beginning of first disk
|
||||
|
||||
void setHeaderOffset(std::streamoff val);
|
||||
/// Sets the offset of the header in relation to the begin of this disk
|
||||
|
||||
std::string createHeader() const;
|
||||
/// Creates a header
|
||||
|
||||
private:
|
||||
void parse(std::istream& inp, bool assumeHeaderRead);
|
||||
|
||||
Poco::UInt16 getZipCommentSize() const;
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
HEADER_POS = 0,
|
||||
NUMBEROFTHISDISK_POS = HEADER_POS + ZipCommon::HEADER_SIZE,
|
||||
NUMBEROFTHISDISK_SIZE = 2,
|
||||
NUMBEROFCENTRALDIRDISK_POS = NUMBEROFTHISDISK_POS + NUMBEROFTHISDISK_SIZE,
|
||||
NUMBEROFCENTRALDIRDISK_SIZE = 2,
|
||||
NUMENTRIESTHISDISK_POS = NUMBEROFCENTRALDIRDISK_POS + NUMBEROFCENTRALDIRDISK_SIZE,
|
||||
NUMENTRIESTHISDISK_SIZE = 2,
|
||||
TOTALNUMENTRIES_POS = NUMENTRIESTHISDISK_POS + NUMENTRIESTHISDISK_SIZE,
|
||||
TOTALNUMENTRIES_SIZE = 2,
|
||||
CENTRALDIRSIZE_POS = TOTALNUMENTRIES_POS + TOTALNUMENTRIES_SIZE,
|
||||
CENTRALDIRSIZE_SIZE = 4,
|
||||
CENTRALDIRSTARTOFFSET_POS = CENTRALDIRSIZE_POS + CENTRALDIRSIZE_SIZE,
|
||||
CENTRALDIRSTARTOFFSET_SIZE = 4,
|
||||
ZIPCOMMENT_LENGTH_POS = CENTRALDIRSTARTOFFSET_POS + CENTRALDIRSTARTOFFSET_SIZE,
|
||||
ZIPCOMMENT_LENGTH_SIZE = 2,
|
||||
FULLHEADER_SIZE = 22
|
||||
};
|
||||
|
||||
char _rawInfo[FULLHEADER_SIZE];
|
||||
std::streamoff _startPos;
|
||||
std::string _comment;
|
||||
};
|
||||
|
||||
|
||||
class Zip_API ZipArchiveInfo64
|
||||
/// A ZipArchiveInfo64 stores central directory info
|
||||
{
|
||||
public:
|
||||
static const char HEADER[ZipCommon::HEADER_SIZE];
|
||||
static const char LOCATOR_HEADER[ZipCommon::HEADER_SIZE];
|
||||
|
||||
ZipArchiveInfo64();
|
||||
/// Default constructor, everything set to zero or empty
|
||||
|
||||
ZipArchiveInfo64(std::istream& in, bool assumeHeaderRead);
|
||||
/// Creates the ZipArchiveInfo64 by parsing the input stream.
|
||||
/// If assumeHeaderRead is true we assume that the first 4 bytes were already read outside.
|
||||
|
||||
~ZipArchiveInfo64();
|
||||
/// Destroys the ZipArchiveInfo64.
|
||||
|
||||
void getVersionMadeBy(int& major, int& minor);
|
||||
/// The ZIP version used to create the file
|
||||
|
||||
void getRequiredVersion(int& major, int& minor);
|
||||
/// The minimum version required to extract the data
|
||||
|
||||
Poco::UInt32 getDiskNumber() const;
|
||||
/// Get the number of the disk where this header can be found
|
||||
|
||||
Poco::UInt32 getFirstDiskForDirectoryHeader() const;
|
||||
/// Returns the number of the disk that contains the start of the directory header
|
||||
|
||||
Poco::UInt64 getNumberOfEntries() const;
|
||||
/// Returns the number of entries on this disk
|
||||
|
||||
Poco::UInt64 getTotalNumberOfEntries() const;
|
||||
/// Returns the total number of entries on all disks
|
||||
|
||||
Poco::UInt64 getCentralDirectorySize() const;
|
||||
/// Returns the size of the central directory in bytes
|
||||
|
||||
std::streamoff getCentralDirectoryOffset() const;
|
||||
/// Returns the offset of the central directory from beginning of first disk
|
||||
|
||||
std::streamoff getHeaderOffset() const;
|
||||
/// Returns the offset of the header in relation to the begin of this disk
|
||||
|
||||
void setNumberOfEntries(Poco::UInt64 val);
|
||||
/// Sets the number of entries on this disk
|
||||
|
||||
void setTotalNumberOfEntries(Poco::UInt64 val);
|
||||
/// Sets the total number of entries on all disks
|
||||
|
||||
void setCentralDirectorySize(Poco::UInt64 val);
|
||||
/// Set the size of the central directory in bytes
|
||||
|
||||
void setCentralDirectoryOffset(Poco::UInt64 val);
|
||||
/// Returns the offset of the central directory from beginning of first disk
|
||||
|
||||
void setHeaderOffset(std::streamoff val);
|
||||
/// Sets the offset of the header in relation to the begin of this disk
|
||||
|
||||
void setTotalNumberOfDisks(Poco::UInt32 val);
|
||||
/// Sets the offset of the central directory from beginning of first disk
|
||||
|
||||
std::string createHeader() const;
|
||||
/// Creates a header
|
||||
|
||||
private:
|
||||
void parse(std::istream& inp, bool assumeHeaderRead);
|
||||
void setRequiredVersion(int major, int minor);
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
HEADER_POS = 0,
|
||||
RECORDSIZE_POS = HEADER_POS + ZipCommon::HEADER_SIZE,
|
||||
RECORDSIZE_SIZE = 8,
|
||||
VERSIONMADEBY_POS = RECORDSIZE_POS + RECORDSIZE_SIZE,
|
||||
VERSIONMADEBY_SIZE = 2,
|
||||
VERSION_NEEDED_POS = VERSIONMADEBY_POS + VERSIONMADEBY_SIZE,
|
||||
VERSION_NEEDED_SIZE = 2,
|
||||
NUMBEROFTHISDISK_POS = VERSION_NEEDED_POS + VERSION_NEEDED_SIZE,
|
||||
NUMBEROFTHISDISK_SIZE = 4,
|
||||
NUMBEROFCENTRALDIRDISK_POS = NUMBEROFTHISDISK_POS + NUMBEROFTHISDISK_SIZE,
|
||||
NUMBEROFCENTRALDIRDISK_SIZE = 4,
|
||||
NUMENTRIESTHISDISK_POS = NUMBEROFCENTRALDIRDISK_POS + NUMBEROFCENTRALDIRDISK_SIZE,
|
||||
NUMENTRIESTHISDISK_SIZE = 8,
|
||||
TOTALNUMENTRIES_POS = NUMENTRIESTHISDISK_POS + NUMENTRIESTHISDISK_SIZE,
|
||||
TOTALNUMENTRIES_SIZE = 8,
|
||||
CENTRALDIRSIZE_POS = TOTALNUMENTRIES_POS + TOTALNUMENTRIES_SIZE,
|
||||
CENTRALDIRSIZE_SIZE = 8,
|
||||
CENTRALDIRSTARTOFFSET_POS = CENTRALDIRSIZE_POS + CENTRALDIRSIZE_SIZE,
|
||||
CENTRALDIRSTARTOFFSET_SIZE = 8,
|
||||
FULL_HEADER_SIZE = 56,
|
||||
|
||||
LOCATOR_HEADER_POS = 0,
|
||||
NUMBEROFENDOFCENTRALDIRDISK_POS = LOCATOR_HEADER_POS + ZipCommon::HEADER_SIZE,
|
||||
NUMBEROFENDOFCENTRALDIRDISK_SIZE = 4,
|
||||
ENDOFCENTRALDIROFFSET_POS = NUMBEROFENDOFCENTRALDIRDISK_POS + NUMBEROFENDOFCENTRALDIRDISK_SIZE,
|
||||
ENDOFCENTRALDIROFFSET_SIZE = 8,
|
||||
TOTALNUMBEROFENDDISKS_POS = ENDOFCENTRALDIROFFSET_POS + ENDOFCENTRALDIROFFSET_SIZE,
|
||||
TOTALNUMBEROFENDDISKS_SIZE = 4,
|
||||
|
||||
FULL_LOCATOR_SIZE = 20
|
||||
};
|
||||
|
||||
char _rawInfo[FULL_HEADER_SIZE];
|
||||
std::string _extraField;
|
||||
char _locInfo[FULL_LOCATOR_SIZE];
|
||||
std::streamoff _startPos;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
|
||||
|
||||
inline Poco::UInt16 ZipArchiveInfo::getDiskNumber() const
|
||||
{
|
||||
return ZipUtil::get16BitValue(_rawInfo, NUMBEROFTHISDISK_POS);
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt16 ZipArchiveInfo::getFirstDiskForDirectoryHeader() const
|
||||
{
|
||||
return ZipUtil::get16BitValue(_rawInfo, NUMBEROFCENTRALDIRDISK_POS);
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt16 ZipArchiveInfo::getNumberOfEntries() const
|
||||
{
|
||||
return ZipUtil::get16BitValue(_rawInfo, NUMENTRIESTHISDISK_POS);
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt16 ZipArchiveInfo::getTotalNumberOfEntries() const
|
||||
{
|
||||
return ZipUtil::get16BitValue(_rawInfo, TOTALNUMENTRIES_POS);
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt32 ZipArchiveInfo::getCentralDirectorySize() const
|
||||
{
|
||||
return ZipUtil::get32BitValue(_rawInfo, CENTRALDIRSIZE_POS);
|
||||
}
|
||||
|
||||
|
||||
inline std::streamoff ZipArchiveInfo::getHeaderOffset() const
|
||||
{
|
||||
return _startPos;
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt16 ZipArchiveInfo::getZipCommentSize() const
|
||||
{
|
||||
return ZipUtil::get16BitValue(_rawInfo, ZIPCOMMENT_LENGTH_POS);
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& ZipArchiveInfo::getZipComment() const
|
||||
{
|
||||
return _comment;
|
||||
}
|
||||
|
||||
|
||||
inline void ZipArchiveInfo::setNumberOfEntries(Poco::UInt16 val)
|
||||
{
|
||||
ZipUtil::set16BitValue(val, _rawInfo, NUMENTRIESTHISDISK_POS);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipArchiveInfo::setTotalNumberOfEntries(Poco::UInt16 val)
|
||||
{
|
||||
ZipUtil::set16BitValue(val, _rawInfo, TOTALNUMENTRIES_POS);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipArchiveInfo::setCentralDirectorySize(Poco::UInt32 val)
|
||||
{
|
||||
ZipUtil::set32BitValue(val, _rawInfo, CENTRALDIRSIZE_POS);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipArchiveInfo::setCentralDirectoryOffset(Poco::UInt32 val)
|
||||
{
|
||||
ZipUtil::set32BitValue(val, _rawInfo, CENTRALDIRSTARTOFFSET_POS);
|
||||
}
|
||||
|
||||
inline void ZipArchiveInfo::setHeaderOffset(std::streamoff val)
|
||||
{
|
||||
_startPos = val;
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt32 ZipArchiveInfo64::getDiskNumber() const
|
||||
{
|
||||
return ZipUtil::get32BitValue(_rawInfo, NUMBEROFTHISDISK_POS);
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt32 ZipArchiveInfo64::getFirstDiskForDirectoryHeader() const
|
||||
{
|
||||
return ZipUtil::get32BitValue(_rawInfo, NUMBEROFCENTRALDIRDISK_POS);
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt64 ZipArchiveInfo64::getNumberOfEntries() const
|
||||
{
|
||||
return ZipUtil::get64BitValue(_rawInfo, NUMENTRIESTHISDISK_POS);
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt64 ZipArchiveInfo64::getTotalNumberOfEntries() const
|
||||
{
|
||||
return ZipUtil::get64BitValue(_rawInfo, TOTALNUMENTRIES_POS);
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt64 ZipArchiveInfo64::getCentralDirectorySize() const
|
||||
{
|
||||
return ZipUtil::get64BitValue(_rawInfo, CENTRALDIRSIZE_POS);
|
||||
}
|
||||
|
||||
|
||||
inline std::streamoff ZipArchiveInfo64::getCentralDirectoryOffset() const
|
||||
{
|
||||
return _startPos;
|
||||
}
|
||||
|
||||
|
||||
inline std::streamoff ZipArchiveInfo64::getHeaderOffset() const
|
||||
{
|
||||
return _startPos;
|
||||
}
|
||||
|
||||
|
||||
inline void ZipArchiveInfo64::setRequiredVersion(int major, int minor)
|
||||
{
|
||||
poco_assert (minor < 10);
|
||||
poco_assert (major < 24);
|
||||
Poco::UInt8 val = static_cast<unsigned char>(major)*10+static_cast<unsigned char>(minor);
|
||||
_rawInfo[VERSIONMADEBY_POS] = static_cast<char>(val);
|
||||
_rawInfo[VERSION_NEEDED_POS] = static_cast<char>(val);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipArchiveInfo64::setNumberOfEntries(Poco::UInt64 val)
|
||||
{
|
||||
ZipUtil::set64BitValue(val, _rawInfo, NUMENTRIESTHISDISK_POS);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipArchiveInfo64::setTotalNumberOfEntries(Poco::UInt64 val)
|
||||
{
|
||||
ZipUtil::set64BitValue(val, _rawInfo, TOTALNUMENTRIES_POS);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipArchiveInfo64::setCentralDirectorySize(Poco::UInt64 val)
|
||||
{
|
||||
ZipUtil::set64BitValue(val, _rawInfo, CENTRALDIRSIZE_POS);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipArchiveInfo64::setCentralDirectoryOffset(Poco::UInt64 val)
|
||||
{
|
||||
ZipUtil::set64BitValue(val, _rawInfo, CENTRALDIRSTARTOFFSET_POS);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipArchiveInfo64::setHeaderOffset(std::streamoff val)
|
||||
{
|
||||
_startPos = val;
|
||||
ZipUtil::set64BitValue(val, _locInfo, ENDOFCENTRALDIROFFSET_POS);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipArchiveInfo64::setTotalNumberOfDisks(Poco::UInt32 val)
|
||||
{
|
||||
ZipUtil::set32BitValue(val, _locInfo, TOTALNUMBEROFENDDISKS_POS);
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Zip
|
||||
|
||||
|
||||
#endif // Zip_ZipArchiveInfo_INCLUDED
|
104
vendor/POCO/Zip/include/Poco/Zip/ZipCommon.h
vendored
Normal file
104
vendor/POCO/Zip/include/Poco/Zip/ZipCommon.h
vendored
Normal file
@ -0,0 +1,104 @@
|
||||
//
|
||||
// ZipCommon.h
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Zip
|
||||
// Module: ZipCommon
|
||||
//
|
||||
// Definition of the ZipCommon class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Zip_ZipCommon_INCLUDED
|
||||
#define Zip_ZipCommon_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Zip/Zip.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Zip {
|
||||
|
||||
|
||||
class Zip_API ZipCommon
|
||||
/// Common enums used in the Zip project
|
||||
{
|
||||
public:
|
||||
enum
|
||||
{
|
||||
HEADER_SIZE = 4
|
||||
};
|
||||
|
||||
static const Poco::UInt16 ZIP64_EXTRA_ID = 0x1; // Extra data id tag for Zip64 data (in extension for ZipLocalFileHeader and ZipFileInfo)
|
||||
static const Poco::UInt16 ZIP64_MAGIC_SHORT = 0xFFFF;
|
||||
static const Poco::UInt32 ZIP64_MAGIC = 0xFFFFFFFF;
|
||||
|
||||
enum CompressionMethod
|
||||
{
|
||||
CM_STORE = 0,
|
||||
CM_SHRUNK = 1,
|
||||
CM_FACTOR1 = 2,
|
||||
CM_FACTOR2 = 3,
|
||||
CM_FACTOR3 = 4,
|
||||
CM_FACTOR4 = 5,
|
||||
CM_IMPLODE = 6,
|
||||
CM_TOKENIZE= 7,
|
||||
CM_DEFLATE = 8,
|
||||
CM_ENHANCEDDEFLATE = 9,
|
||||
CM_DATECOMPRIMPLODING = 10,
|
||||
CM_UNUSED = 11,
|
||||
CM_AUTO = 255 /// automatically select DM_DEFLATE or CM_STORE based on file type (extension)
|
||||
};
|
||||
|
||||
enum CompressionLevel
|
||||
{
|
||||
CL_NORMAL = 0,
|
||||
CL_MAXIMUM = 1,
|
||||
CL_FAST = 2,
|
||||
CL_SUPERFAST = 3
|
||||
};
|
||||
|
||||
enum HostSystem
|
||||
{
|
||||
HS_FAT = 0, // + PKZIPW 2.50 VFAT, NTFS
|
||||
HS_AMIGA = 1,
|
||||
HS_VMS = 2,
|
||||
HS_UNIX = 3,
|
||||
HS_VM_CMS = 4,
|
||||
HS_ATARI = 5,
|
||||
HS_HPFS = 6,
|
||||
HS_MACINTOSH = 7,
|
||||
HS_ZSYSTEM = 8,
|
||||
HS_CP_M = 9,
|
||||
HS_TOPS20 = 10, // used by pkzip2.5 to indicate ntfs
|
||||
HS_NTFS = 11,
|
||||
HS_SMS_QDOS = 12,
|
||||
HS_ACORN = 13,
|
||||
HS_VFAT = 14,
|
||||
HS_MVS = 15,
|
||||
HS_BEOS = 16,
|
||||
HS_TANDEM = 17,
|
||||
HS_UNUSED = 18
|
||||
};
|
||||
|
||||
enum FileType
|
||||
{
|
||||
FT_BINARY= 0,
|
||||
FT_ASCII = 1
|
||||
};
|
||||
|
||||
static bool isValidPath(const std::string& path);
|
||||
/// Checks whether the given path is valid (does
|
||||
/// not contain ".." path segments).
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Zip
|
||||
|
||||
|
||||
#endif // Zip_ZipCommon_INCLUDED
|
248
vendor/POCO/Zip/include/Poco/Zip/ZipDataInfo.h
vendored
Normal file
248
vendor/POCO/Zip/include/Poco/Zip/ZipDataInfo.h
vendored
Normal file
@ -0,0 +1,248 @@
|
||||
//
|
||||
// ZipDataInfo.h
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Zip
|
||||
// Module: ZipDataInfo
|
||||
//
|
||||
// Definition of the ZipDataInfo class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Zip_ZipDataInfo_INCLUDED
|
||||
#define Zip_ZipDataInfo_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Zip/Zip.h"
|
||||
#include "Poco/Zip/ZipCommon.h"
|
||||
#include "Poco/Zip/ZipUtil.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Zip {
|
||||
|
||||
|
||||
class Zip_API ZipDataInfo
|
||||
/// A ZipDataInfo stores a Zip data descriptor
|
||||
{
|
||||
public:
|
||||
static const char HEADER[ZipCommon::HEADER_SIZE];
|
||||
|
||||
ZipDataInfo();
|
||||
/// Creates a header with all fields (except the header field) set to 0
|
||||
|
||||
ZipDataInfo(std::istream& in, bool assumeHeaderRead);
|
||||
/// Creates the ZipDataInfo.
|
||||
|
||||
~ZipDataInfo();
|
||||
/// Destroys the ZipDataInfo.
|
||||
|
||||
bool isValid() const;
|
||||
|
||||
Poco::UInt32 getCRC32() const;
|
||||
|
||||
void setCRC32(Poco::UInt32 crc);
|
||||
|
||||
Poco::UInt32 getCompressedSize() const;
|
||||
|
||||
void setCompressedSize(Poco::UInt32 size);
|
||||
|
||||
Poco::UInt32 getUncompressedSize() const;
|
||||
|
||||
void setUncompressedSize(Poco::UInt32 size);
|
||||
|
||||
static Poco::UInt32 getFullHeaderSize();
|
||||
|
||||
const char* getRawHeader() const;
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
HEADER_POS = 0,
|
||||
CRC32_POS = HEADER_POS + ZipCommon::HEADER_SIZE,
|
||||
CRC32_SIZE = 4,
|
||||
COMPRESSED_POS = CRC32_POS + CRC32_SIZE,
|
||||
COMPRESSED_SIZE = 4,
|
||||
UNCOMPRESSED_POS = COMPRESSED_POS + COMPRESSED_SIZE,
|
||||
UNCOMPRESSED_SIZE = 4,
|
||||
FULLHEADER_SIZE = UNCOMPRESSED_POS + UNCOMPRESSED_SIZE
|
||||
};
|
||||
|
||||
char _rawInfo[FULLHEADER_SIZE];
|
||||
bool _valid;
|
||||
};
|
||||
|
||||
|
||||
class Zip_API ZipDataInfo64
|
||||
/// A ZipDataInfo64 stores a Zip data descriptor for a Zip64 file
|
||||
{
|
||||
public:
|
||||
static const char HEADER[ZipCommon::HEADER_SIZE];
|
||||
|
||||
ZipDataInfo64();
|
||||
/// Creates a header with all fields (except the header field) set to 0
|
||||
|
||||
ZipDataInfo64(std::istream& in, bool assumeHeaderRead);
|
||||
/// Creates the ZipDataInfo64.
|
||||
|
||||
~ZipDataInfo64();
|
||||
/// Destroys the ZipDataInfo64.
|
||||
|
||||
bool isValid() const;
|
||||
|
||||
Poco::UInt32 getCRC32() const;
|
||||
|
||||
void setCRC32(Poco::UInt32 crc);
|
||||
|
||||
Poco::UInt64 getCompressedSize() const;
|
||||
|
||||
void setCompressedSize(Poco::UInt64 size);
|
||||
|
||||
Poco::UInt64 getUncompressedSize() const;
|
||||
|
||||
void setUncompressedSize(Poco::UInt64 size);
|
||||
|
||||
static Poco::UInt32 getFullHeaderSize();
|
||||
|
||||
const char* getRawHeader() const;
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
HEADER_POS = 0,
|
||||
CRC32_POS = HEADER_POS + ZipCommon::HEADER_SIZE,
|
||||
CRC32_SIZE = 4,
|
||||
COMPRESSED_POS = CRC32_POS + CRC32_SIZE,
|
||||
COMPRESSED_SIZE = 8,
|
||||
UNCOMPRESSED_POS = COMPRESSED_POS + COMPRESSED_SIZE,
|
||||
UNCOMPRESSED_SIZE = 8,
|
||||
FULLHEADER_SIZE = UNCOMPRESSED_POS + UNCOMPRESSED_SIZE
|
||||
};
|
||||
|
||||
char _rawInfo[FULLHEADER_SIZE];
|
||||
bool _valid;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
|
||||
|
||||
inline const char* ZipDataInfo::getRawHeader() const
|
||||
{
|
||||
return _rawInfo;
|
||||
}
|
||||
|
||||
|
||||
inline bool ZipDataInfo::isValid() const
|
||||
{
|
||||
return _valid;
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt32 ZipDataInfo::getCRC32() const
|
||||
{
|
||||
return ZipUtil::get32BitValue(_rawInfo, CRC32_POS);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipDataInfo::setCRC32(Poco::UInt32 crc)
|
||||
{
|
||||
return ZipUtil::set32BitValue(crc, _rawInfo, CRC32_POS);
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt32 ZipDataInfo::getCompressedSize() const
|
||||
{
|
||||
return ZipUtil::get32BitValue(_rawInfo, COMPRESSED_POS);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipDataInfo::setCompressedSize(Poco::UInt32 size)
|
||||
{
|
||||
return ZipUtil::set32BitValue(size, _rawInfo, COMPRESSED_POS);
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt32 ZipDataInfo::getUncompressedSize() const
|
||||
{
|
||||
return ZipUtil::get32BitValue(_rawInfo, UNCOMPRESSED_POS);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipDataInfo::setUncompressedSize(Poco::UInt32 size)
|
||||
{
|
||||
return ZipUtil::set32BitValue(size, _rawInfo, UNCOMPRESSED_POS);
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt32 ZipDataInfo::getFullHeaderSize()
|
||||
{
|
||||
return FULLHEADER_SIZE;
|
||||
}
|
||||
|
||||
|
||||
inline const char* ZipDataInfo64::getRawHeader() const
|
||||
{
|
||||
return _rawInfo;
|
||||
}
|
||||
|
||||
|
||||
inline bool ZipDataInfo64::isValid() const
|
||||
{
|
||||
return _valid;
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt32 ZipDataInfo64::getCRC32() const
|
||||
{
|
||||
return ZipUtil::get32BitValue(_rawInfo, CRC32_POS);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipDataInfo64::setCRC32(Poco::UInt32 crc)
|
||||
{
|
||||
return ZipUtil::set32BitValue(crc, _rawInfo, CRC32_POS);
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt64 ZipDataInfo64::getCompressedSize() const
|
||||
{
|
||||
return ZipUtil::get64BitValue(_rawInfo, COMPRESSED_POS);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipDataInfo64::setCompressedSize(Poco::UInt64 size)
|
||||
{
|
||||
return ZipUtil::set64BitValue(size, _rawInfo, COMPRESSED_POS);
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt64 ZipDataInfo64::getUncompressedSize() const
|
||||
{
|
||||
return ZipUtil::get64BitValue(_rawInfo, UNCOMPRESSED_POS);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipDataInfo64::setUncompressedSize(Poco::UInt64 size)
|
||||
{
|
||||
return ZipUtil::set64BitValue(size, _rawInfo, UNCOMPRESSED_POS);
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt32 ZipDataInfo64::getFullHeaderSize()
|
||||
{
|
||||
return FULLHEADER_SIZE;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Zip
|
||||
|
||||
|
||||
#endif // Zip_ZipDataInfo_INCLUDED
|
36
vendor/POCO/Zip/include/Poco/Zip/ZipException.h
vendored
Normal file
36
vendor/POCO/Zip/include/Poco/Zip/ZipException.h
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
//
|
||||
// ZipException.h
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Zip
|
||||
// Module: ZipException
|
||||
//
|
||||
// Definition of the ZipException class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Zip_ZipException_INCLUDED
|
||||
#define Zip_ZipException_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Zip/Zip.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Zip {
|
||||
|
||||
|
||||
POCO_DECLARE_EXCEPTION(Zip_API, ZipException, Poco::RuntimeException)
|
||||
POCO_DECLARE_EXCEPTION(Zip_API, ZipManipulationException, ZipException)
|
||||
|
||||
|
||||
} } // namespace Poco::Zip
|
||||
|
||||
|
||||
#endif // Zip_ZipException_INCLUDED
|
519
vendor/POCO/Zip/include/Poco/Zip/ZipFileInfo.h
vendored
Normal file
519
vendor/POCO/Zip/include/Poco/Zip/ZipFileInfo.h
vendored
Normal file
@ -0,0 +1,519 @@
|
||||
//
|
||||
// ZipFileInfo.h
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Zip
|
||||
// Module: ZipFileInfo
|
||||
//
|
||||
// Definition of the ZipFileInfo class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Zip_ZipFileInfo_INCLUDED
|
||||
#define Zip_ZipFileInfo_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Zip/Zip.h"
|
||||
#include "Poco/Zip/ZipCommon.h"
|
||||
#include "Poco/Zip/ZipUtil.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Zip {
|
||||
|
||||
|
||||
class ZipLocalFileHeader;
|
||||
|
||||
|
||||
class Zip_API ZipFileInfo
|
||||
/// Stores a Zip directory entry of a file
|
||||
{
|
||||
public:
|
||||
static const char HEADER[ZipCommon::HEADER_SIZE];
|
||||
|
||||
ZipFileInfo(const ZipLocalFileHeader& header);
|
||||
/// Creates a ZipFileInfo from a ZipLocalFileHeader
|
||||
|
||||
ZipFileInfo(std::istream& in, bool assumeHeaderRead);
|
||||
/// Creates the ZipFileInfo by parsing the input stream.
|
||||
/// If assumeHeaderRead is true we assume that the first 4 bytes were already read outside.
|
||||
|
||||
~ZipFileInfo();
|
||||
/// Destroys the ZipFileInfo.
|
||||
|
||||
ZipCommon::CompressionMethod getCompressionMethod() const;
|
||||
|
||||
bool isEncrypted() const;
|
||||
|
||||
const Poco::DateTime& lastModifiedAt() const;
|
||||
|
||||
Poco::UInt32 getCRC() const;
|
||||
|
||||
Poco::UInt32 getHeaderSize() const;
|
||||
/// Returns the total size of the header including filename + other additional fields
|
||||
|
||||
Poco::UInt64 getCompressedSize() const;
|
||||
|
||||
Poco::UInt64 getUncompressedSize() const;
|
||||
|
||||
Poco::UInt64 getOffset() const;
|
||||
/// Where on the disk starts the localheader. Combined with the disk number gives the exact location of the header
|
||||
|
||||
const std::string& getFileName() const;
|
||||
|
||||
bool isFile() const;
|
||||
|
||||
bool isDirectory() const;
|
||||
|
||||
bool hasExtraField() const;
|
||||
|
||||
const std::string& getExtraField() const;
|
||||
|
||||
const std::string& getFileComment() const;
|
||||
|
||||
void getVersionMadeBy(int& major, int& minor) const;
|
||||
/// The ZIP version used to create the file
|
||||
|
||||
void getRequiredVersion(int& major, int& minor) const;
|
||||
/// The minimum version required to extract the data
|
||||
|
||||
ZipCommon::HostSystem getHostSystem() const;
|
||||
|
||||
Poco::UInt16 getDiskNumberStart() const;
|
||||
/// The number of the disk on which this file begins (multidisk archives)
|
||||
|
||||
ZipCommon::FileType getFileType() const;
|
||||
/// Binary or ASCII file?
|
||||
|
||||
std::string createHeader() const;
|
||||
|
||||
void setOffset(Poco::UInt64 val);
|
||||
|
||||
bool needsZip64() const;
|
||||
|
||||
void setZip64Data();
|
||||
|
||||
private:
|
||||
|
||||
void setCRC(Poco::UInt32 val);
|
||||
|
||||
void setCompressedSize(Poco::UInt64 val);
|
||||
|
||||
void setUncompressedSize(Poco::UInt64 val);
|
||||
|
||||
void setCompressionMethod(ZipCommon::CompressionMethod cm);
|
||||
|
||||
void setCompressionLevel(ZipCommon::CompressionLevel cl);
|
||||
|
||||
void setRequiredVersion(int major, int minor);
|
||||
|
||||
void setHostSystem(ZipCommon::HostSystem hs);
|
||||
|
||||
void setLastModifiedAt(const Poco::DateTime& dt);
|
||||
|
||||
void setEncryption(bool val);
|
||||
|
||||
void setFileNameLength(Poco::UInt16 size);
|
||||
|
||||
void setFileName(const std::string& str);
|
||||
|
||||
void setExternalFileAttributes(Poco::UInt32 attrs);
|
||||
|
||||
void parse(std::istream& in, bool assumeHeaderRead);
|
||||
|
||||
void parseDateTime();
|
||||
|
||||
Poco::UInt32 getCRCFromHeader() const;
|
||||
|
||||
Poco::UInt32 getCompressedSizeFromHeader() const;
|
||||
|
||||
Poco::UInt32 getUncompressedSizeFromHeader() const;
|
||||
|
||||
Poco::UInt32 getOffsetFromHeader() const;
|
||||
|
||||
Poco::UInt16 getFileNameLength() const;
|
||||
|
||||
Poco::UInt16 getExtraFieldLength() const;
|
||||
|
||||
Poco::UInt16 getFileCommentLength() const;
|
||||
|
||||
Poco::UInt32 getExternalFileAttributes() const;
|
||||
|
||||
void setUnixAttributes();
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
HEADER_POS = 0,
|
||||
VERSIONMADEBY_POS = HEADER_POS + ZipCommon::HEADER_SIZE,
|
||||
VERSIONMADEBY_SIZE = 2,
|
||||
VERSION_NEEDED_POS = VERSIONMADEBY_POS + VERSIONMADEBY_SIZE,
|
||||
VERSION_NEEDED_SIZE = 2,
|
||||
GENERAL_PURPOSE_POS = VERSION_NEEDED_POS + VERSION_NEEDED_SIZE,
|
||||
GENERAL_PURPOSE_SIZE = 2,
|
||||
COMPR_METHOD_POS = GENERAL_PURPOSE_POS + GENERAL_PURPOSE_SIZE,
|
||||
COMPR_METHOD_SIZE = 2,
|
||||
LASTMODFILETIME_POS = COMPR_METHOD_POS + COMPR_METHOD_SIZE,
|
||||
LASTMODFILETIME_SIZE = 2,
|
||||
LASTMODFILEDATE_POS = LASTMODFILETIME_POS + LASTMODFILETIME_SIZE,
|
||||
LASTMODFILEDATE_SIZE = 2,
|
||||
CRC32_POS = LASTMODFILEDATE_POS + LASTMODFILEDATE_SIZE,
|
||||
CRC32_SIZE = 4,
|
||||
COMPRESSED_SIZE_POS = CRC32_POS + CRC32_SIZE,
|
||||
COMPRESSED_SIZE_SIZE = 4,
|
||||
UNCOMPRESSED_SIZE_POS = COMPRESSED_SIZE_POS + COMPRESSED_SIZE_SIZE,
|
||||
UNCOMPRESSED_SIZE_SIZE = 4,
|
||||
FILENAME_LENGTH_POS = UNCOMPRESSED_SIZE_POS + UNCOMPRESSED_SIZE_SIZE,
|
||||
FILENAME_LENGTH_SIZE = 2,
|
||||
EXTRAFIELD_LENGTH_POS = FILENAME_LENGTH_POS + FILENAME_LENGTH_SIZE,
|
||||
EXTRAFIELD_LENGTH_SIZE = 2,
|
||||
FILECOMMENT_LENGTH_POS = EXTRAFIELD_LENGTH_POS + EXTRAFIELD_LENGTH_SIZE,
|
||||
FILECOMMENT_LENGTH_SIZE = 2,
|
||||
DISKNUMBERSTART_POS = FILECOMMENT_LENGTH_POS + FILECOMMENT_LENGTH_SIZE,
|
||||
DISKNUMBERSTART_SIZE = 2,
|
||||
INTERNALFILE_ATTR_POS = DISKNUMBERSTART_POS + DISKNUMBERSTART_SIZE,
|
||||
INTERNALFILE_ATTR_SIZE = 2,
|
||||
EXTERNALFILE_ATTR_POS = INTERNALFILE_ATTR_POS + INTERNALFILE_ATTR_SIZE,
|
||||
EXTERNALFILE_ATTR_SIZE = 4,
|
||||
RELATIVEOFFSETLOCALHEADER_POS = EXTERNALFILE_ATTR_POS + EXTERNALFILE_ATTR_SIZE,
|
||||
RELATIVEOFFSETLOCALHEADER_SIZE = 4,
|
||||
FULLHEADER_SIZE = 46,
|
||||
|
||||
EXTRA_DATA_TAG_SIZE = 2,
|
||||
EXTRA_DATA_TAG_POS = 0,
|
||||
EXTRA_DATA_SIZE_SIZE = 2,
|
||||
EXTRA_DATA_SIZE_POS = EXTRA_DATA_TAG_POS + EXTRA_DATA_TAG_SIZE,
|
||||
EXTRA_DATA_POS = EXTRA_DATA_SIZE_POS + EXTRA_DATA_SIZE_SIZE,
|
||||
EXTRA_DATA_UNCOMPRESSED_SIZE_SIZE = 8,
|
||||
EXTRA_DATA_COMPRESSED_SIZE_SIZE = 8,
|
||||
EXTRA_DATA_OFFSET_SIZE = 8,
|
||||
FULLEXTRA_DATA_SIZE = 28
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
DEFAULT_UNIX_FILE_MODE = 0640,
|
||||
DEFAULT_UNIX_DIR_MODE = 0755
|
||||
};
|
||||
|
||||
char _rawInfo[FULLHEADER_SIZE];
|
||||
Poco::UInt32 _crc32;
|
||||
Poco::UInt64 _compressedSize;
|
||||
Poco::UInt64 _uncompressedSize;
|
||||
Poco::UInt64 _localHeaderOffset;
|
||||
std::string _fileName;
|
||||
Poco::DateTime _lastModifiedAt;
|
||||
std::string _extraField;
|
||||
std::string _fileComment;
|
||||
};
|
||||
|
||||
|
||||
inline Poco::UInt32 ZipFileInfo::getCRCFromHeader() const
|
||||
{
|
||||
return ZipUtil::get32BitValue(_rawInfo, CRC32_POS);
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt32 ZipFileInfo::getCompressedSizeFromHeader() const
|
||||
{
|
||||
return ZipUtil::get32BitValue(_rawInfo, COMPRESSED_SIZE_POS);
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt32 ZipFileInfo::getUncompressedSizeFromHeader() const
|
||||
{
|
||||
return ZipUtil::get32BitValue(_rawInfo, UNCOMPRESSED_SIZE_POS);
|
||||
}
|
||||
|
||||
inline Poco::UInt32 ZipFileInfo::getOffsetFromHeader() const
|
||||
{
|
||||
return ZipUtil::get32BitValue(_rawInfo, RELATIVEOFFSETLOCALHEADER_POS);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipFileInfo::parseDateTime()
|
||||
{
|
||||
_lastModifiedAt = ZipUtil::parseDateTime(_rawInfo, LASTMODFILETIME_POS, LASTMODFILEDATE_POS);
|
||||
}
|
||||
|
||||
|
||||
inline ZipCommon::CompressionMethod ZipFileInfo::getCompressionMethod() const
|
||||
{
|
||||
return static_cast<ZipCommon::CompressionMethod>(ZipUtil::get16BitValue(_rawInfo, COMPR_METHOD_POS));
|
||||
}
|
||||
|
||||
|
||||
inline bool ZipFileInfo::isEncrypted() const
|
||||
{
|
||||
// bit 0 indicates encryption
|
||||
return ((ZipUtil::get16BitValue(_rawInfo, GENERAL_PURPOSE_POS) & 0x0001) != 0);
|
||||
}
|
||||
|
||||
|
||||
inline const Poco::DateTime& ZipFileInfo::lastModifiedAt() const
|
||||
{
|
||||
return _lastModifiedAt;
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt64 ZipFileInfo::getOffset() const
|
||||
{
|
||||
return _localHeaderOffset;
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt32 ZipFileInfo::getCRC() const
|
||||
{
|
||||
return _crc32;
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt64 ZipFileInfo::getCompressedSize() const
|
||||
{
|
||||
return _compressedSize;
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt64 ZipFileInfo::getUncompressedSize() const
|
||||
{
|
||||
return _uncompressedSize;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& ZipFileInfo::getFileName() const
|
||||
{
|
||||
return _fileName;
|
||||
}
|
||||
|
||||
|
||||
inline bool ZipFileInfo::isFile() const
|
||||
{
|
||||
return !isDirectory();
|
||||
}
|
||||
|
||||
|
||||
inline bool ZipFileInfo::isDirectory() const
|
||||
{
|
||||
poco_assert_dbg(!_fileName.empty());
|
||||
return getUncompressedSize() == 0 && _fileName[_fileName.length()-1] == '/';
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt16 ZipFileInfo::getFileNameLength() const
|
||||
{
|
||||
return ZipUtil::get16BitValue(_rawInfo, FILENAME_LENGTH_POS);
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt16 ZipFileInfo::getExtraFieldLength() const
|
||||
{
|
||||
return ZipUtil::get16BitValue(_rawInfo, EXTRAFIELD_LENGTH_POS);
|
||||
}
|
||||
|
||||
|
||||
inline bool ZipFileInfo::hasExtraField() const
|
||||
{
|
||||
return getExtraFieldLength() > 0;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& ZipFileInfo::getExtraField() const
|
||||
{
|
||||
return _extraField;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& ZipFileInfo::getFileComment() const
|
||||
{
|
||||
return _fileComment;
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt16 ZipFileInfo::getFileCommentLength() const
|
||||
{
|
||||
return ZipUtil::get16BitValue(_rawInfo, FILECOMMENT_LENGTH_POS);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipFileInfo::getVersionMadeBy(int& major, int& minor) const
|
||||
{
|
||||
major = (_rawInfo[VERSIONMADEBY_POS]/10);
|
||||
minor = (_rawInfo[VERSIONMADEBY_POS]%10);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipFileInfo::getRequiredVersion(int& major, int& minor) const
|
||||
{
|
||||
major = (_rawInfo[VERSION_NEEDED_POS]/10);
|
||||
minor = (_rawInfo[VERSION_NEEDED_POS]%10);
|
||||
}
|
||||
|
||||
|
||||
inline ZipCommon::HostSystem ZipFileInfo::getHostSystem() const
|
||||
{
|
||||
return static_cast<ZipCommon::HostSystem>(_rawInfo[VERSION_NEEDED_POS + 1]);
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt16 ZipFileInfo::getDiskNumberStart() const
|
||||
{
|
||||
return ZipUtil::get16BitValue(_rawInfo, DISKNUMBERSTART_POS);
|
||||
}
|
||||
|
||||
|
||||
inline ZipCommon::FileType ZipFileInfo::getFileType() const
|
||||
{
|
||||
return static_cast<ZipCommon::FileType>(_rawInfo[INTERNALFILE_ATTR_POS] & 0x01);
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt32 ZipFileInfo::getExternalFileAttributes() const
|
||||
{
|
||||
return ZipUtil::get32BitValue(_rawInfo, EXTERNALFILE_ATTR_POS);
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt32 ZipFileInfo::getHeaderSize() const
|
||||
{
|
||||
return FULLHEADER_SIZE + getFileNameLength() + getExtraFieldLength() + getFileCommentLength();
|
||||
}
|
||||
|
||||
|
||||
inline bool ZipFileInfo::needsZip64() const
|
||||
{
|
||||
return _localHeaderOffset >= ZipCommon::ZIP64_MAGIC || _compressedSize >= ZipCommon::ZIP64_MAGIC || _uncompressedSize >= ZipCommon::ZIP64_MAGIC;
|
||||
}
|
||||
|
||||
|
||||
inline void ZipFileInfo::setZip64Data()
|
||||
{
|
||||
if (needsZip64())
|
||||
{
|
||||
setRequiredVersion(4, 5);
|
||||
char data[FULLEXTRA_DATA_SIZE];
|
||||
ZipUtil::set16BitValue(ZipCommon::ZIP64_EXTRA_ID, data, EXTRA_DATA_TAG_POS);
|
||||
Poco::UInt16 pos = EXTRA_DATA_POS;
|
||||
if (_uncompressedSize >= ZipCommon::ZIP64_MAGIC)
|
||||
{
|
||||
ZipUtil::set64BitValue(_uncompressedSize, data, pos); pos += 8;
|
||||
}
|
||||
if (_compressedSize >= ZipCommon::ZIP64_MAGIC)
|
||||
{
|
||||
ZipUtil::set64BitValue(_compressedSize, data, pos); pos += 8;
|
||||
}
|
||||
if (_localHeaderOffset >= ZipCommon::ZIP64_MAGIC)
|
||||
{
|
||||
ZipUtil::set64BitValue(_localHeaderOffset, data, pos); pos += 8;
|
||||
}
|
||||
ZipUtil::set16BitValue(pos - EXTRA_DATA_POS, data, EXTRA_DATA_SIZE_POS);
|
||||
_extraField = std::string(data, pos);
|
||||
ZipUtil::set16BitValue(pos, _rawInfo, EXTRAFIELD_LENGTH_POS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline void ZipFileInfo::setCRC(Poco::UInt32 val)
|
||||
{
|
||||
_crc32 = val;
|
||||
ZipUtil::set32BitValue(val, _rawInfo, CRC32_POS);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipFileInfo::setOffset(Poco::UInt64 val)
|
||||
{
|
||||
_localHeaderOffset = val;
|
||||
ZipUtil::set32BitValue(val >= ZipCommon::ZIP64_MAGIC ? ZipCommon::ZIP64_MAGIC : static_cast<Poco::UInt32>(val), _rawInfo, RELATIVEOFFSETLOCALHEADER_POS);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipFileInfo::setCompressedSize(Poco::UInt64 val)
|
||||
{
|
||||
_compressedSize = val;
|
||||
ZipUtil::set32BitValue(val >= ZipCommon::ZIP64_MAGIC ? ZipCommon::ZIP64_MAGIC : static_cast<Poco::UInt32>(val), _rawInfo, COMPRESSED_SIZE_POS);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipFileInfo::setUncompressedSize(Poco::UInt64 val)
|
||||
{
|
||||
_uncompressedSize = val;
|
||||
ZipUtil::set32BitValue(val >= ZipCommon::ZIP64_MAGIC ? ZipCommon::ZIP64_MAGIC : static_cast<Poco::UInt32>(val), _rawInfo, UNCOMPRESSED_SIZE_POS);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipFileInfo::setCompressionMethod(ZipCommon::CompressionMethod cm)
|
||||
{
|
||||
ZipUtil::set16BitValue(static_cast<Poco::UInt16>(cm), _rawInfo, COMPR_METHOD_POS);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipFileInfo::setCompressionLevel(ZipCommon::CompressionLevel cl)
|
||||
{
|
||||
// bit 1 and 2 indicate the level
|
||||
Poco::UInt16 val = static_cast<Poco::UInt16>(cl);
|
||||
val <<= 1;
|
||||
Poco::UInt16 mask = 0xfff9;
|
||||
_rawInfo[GENERAL_PURPOSE_POS] = ((_rawInfo[GENERAL_PURPOSE_POS] & mask) | val);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipFileInfo::setFileNameLength(Poco::UInt16 size)
|
||||
{
|
||||
ZipUtil::set16BitValue(size, _rawInfo, FILENAME_LENGTH_POS);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipFileInfo::setHostSystem(ZipCommon::HostSystem hs)
|
||||
{
|
||||
_rawInfo[VERSIONMADEBY_POS + 1] = static_cast<char>(hs);
|
||||
_rawInfo[VERSION_NEEDED_POS + 1] = static_cast<char>(hs);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipFileInfo::setRequiredVersion(int major, int minor)
|
||||
{
|
||||
poco_assert (minor < 10);
|
||||
poco_assert (major < 24);
|
||||
Poco::UInt8 val = static_cast<unsigned char>(major)*10+static_cast<unsigned char>(minor);
|
||||
_rawInfo[VERSIONMADEBY_POS] = static_cast<char>(val);
|
||||
_rawInfo[VERSION_NEEDED_POS] = static_cast<char>(val);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipFileInfo::setLastModifiedAt(const Poco::DateTime& dt)
|
||||
{
|
||||
_lastModifiedAt = dt;
|
||||
ZipUtil::setDateTime(dt, _rawInfo, LASTMODFILETIME_POS, LASTMODFILEDATE_POS);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipFileInfo::setEncryption(bool val)
|
||||
{
|
||||
if (val)
|
||||
_rawInfo[GENERAL_PURPOSE_POS] |= 0x01;
|
||||
else
|
||||
_rawInfo[GENERAL_PURPOSE_POS] &= 0xfe;
|
||||
}
|
||||
|
||||
|
||||
inline void ZipFileInfo::setFileName(const std::string& str)
|
||||
{
|
||||
_fileName = str;
|
||||
setFileNameLength(static_cast<Poco::UInt16>(str.size()));
|
||||
}
|
||||
|
||||
|
||||
inline void ZipFileInfo::setExternalFileAttributes(Poco::UInt32 attrs)
|
||||
{
|
||||
ZipUtil::set32BitValue(attrs, _rawInfo, EXTERNALFILE_ATTR_POS);
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Zip
|
||||
|
||||
|
||||
#endif // Zip_ZipFileInfo_INCLUDED
|
513
vendor/POCO/Zip/include/Poco/Zip/ZipLocalFileHeader.h
vendored
Normal file
513
vendor/POCO/Zip/include/Poco/Zip/ZipLocalFileHeader.h
vendored
Normal file
@ -0,0 +1,513 @@
|
||||
//
|
||||
// ZipLocalFileHeader.h
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Zip
|
||||
// Module: ZipLocalFileHeader
|
||||
//
|
||||
// Definition of the ZipLocalFileHeader class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Zip_ZipLocalFileHeader_INCLUDED
|
||||
#define Zip_ZipLocalFileHeader_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Zip/Zip.h"
|
||||
#include "Poco/Zip/ZipUtil.h"
|
||||
#include "Poco/Zip/ZipCommon.h"
|
||||
#include "Poco/DateTime.h"
|
||||
#include "Poco/Path.h"
|
||||
#include <istream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Zip {
|
||||
|
||||
|
||||
class ParseCallback;
|
||||
|
||||
|
||||
class Zip_API ZipLocalFileHeader
|
||||
/// Stores a Zip local file header
|
||||
{
|
||||
public:
|
||||
static const char HEADER[ZipCommon::HEADER_SIZE];
|
||||
|
||||
ZipLocalFileHeader(const Poco::Path& fileName, const Poco::DateTime& lastModifiedAt, ZipCommon::CompressionMethod cm, ZipCommon::CompressionLevel cl, bool forceZip64 = false);
|
||||
/// Creates a zip file header from an absoluteFile. fileName is the name of the file in the zip, outputIsSeekable determines if we write
|
||||
/// CRC and file sizes to the LocalFileHeader or after data compression into a ZipDataInfo
|
||||
/// If forceZip64 is set true then the file header is allocated with zip64 extension.
|
||||
|
||||
ZipLocalFileHeader(std::istream& inp, bool assumeHeaderRead, ParseCallback& callback);
|
||||
/// Creates the ZipLocalFileHeader by parsing the input stream.
|
||||
/// If assumeHeaderRead is true we assume that the first 4 bytes were already read outside.
|
||||
/// If skipOverDataBlock is true we position the stream after the data block (either at the next FileHeader or the Directory Entry)
|
||||
|
||||
virtual ~ZipLocalFileHeader();
|
||||
/// Destroys the ZipLocalFileHeader.
|
||||
|
||||
ZipCommon::HostSystem getHostSystem() const;
|
||||
|
||||
int getMajorVersionNumber() const;
|
||||
|
||||
int getMinorVersionNumber() const;
|
||||
|
||||
void getRequiredVersion(int& major, int& minor);
|
||||
/// The minimum version required to extract the data
|
||||
|
||||
Poco::UInt32 getHeaderSize() const;
|
||||
/// Returns the total size of the header including filename + extra field size
|
||||
|
||||
void setStartPos(std::streamoff start);
|
||||
/// Sets the start position to start and the end position to start+compressedSize
|
||||
|
||||
std::streamoff getStartPos() const;
|
||||
/// Returns the position of the first byte of the header in the file stream
|
||||
|
||||
std::streamoff getEndPos() const;
|
||||
/// Points past the last byte of the file entry (ie. either the first byte of the next header, or the directory)
|
||||
|
||||
std::streamoff getDataStartPos() const;
|
||||
/// Returns the streamoffset for the very first byte of data. Will be equal to DataEndPos if no data present
|
||||
|
||||
std::streamoff getDataEndPos() const;
|
||||
|
||||
ZipCommon::CompressionMethod getCompressionMethod() const;
|
||||
|
||||
ZipCommon::CompressionLevel getCompressionLevel() const;
|
||||
/// Returns the compression level used. Only valid when the compression method is CM_DEFLATE
|
||||
|
||||
bool isEncrypted() const;
|
||||
|
||||
bool hasSupportedCompressionMethod() const;
|
||||
|
||||
const Poco::DateTime& lastModifiedAt() const;
|
||||
|
||||
Poco::UInt32 getCRC() const;
|
||||
|
||||
Poco::UInt64 getCompressedSize() const;
|
||||
|
||||
Poco::UInt64 getUncompressedSize() const;
|
||||
|
||||
void setCRC(Poco::UInt32 val);
|
||||
|
||||
void setCompressedSize(Poco::UInt64 val);
|
||||
|
||||
void setUncompressedSize(Poco::UInt64 val);
|
||||
|
||||
const std::string& getFileName() const;
|
||||
|
||||
bool isFile() const;
|
||||
|
||||
bool isDirectory() const;
|
||||
|
||||
bool hasExtraField() const;
|
||||
|
||||
const std::string& getExtraField() const;
|
||||
|
||||
bool hasData() const;
|
||||
|
||||
bool searchCRCAndSizesAfterData() const;
|
||||
|
||||
void setSearchCRCAndSizesAfterData(bool val);
|
||||
|
||||
void setFileName(const std::string& fileName, bool isDirectory);
|
||||
|
||||
bool needsZip64() const;
|
||||
|
||||
void setZip64Data();
|
||||
|
||||
std::string createHeader() const;
|
||||
/// Creates a header
|
||||
|
||||
private:
|
||||
void parse(std::istream& inp, bool assumeHeaderRead);
|
||||
|
||||
void parseDateTime();
|
||||
|
||||
void init(const Poco::Path& fileName, ZipCommon::CompressionMethod cm, ZipCommon::CompressionLevel cl);
|
||||
|
||||
Poco::UInt16 getFileNameLength() const;
|
||||
|
||||
Poco::UInt16 getExtraFieldLength() const;
|
||||
|
||||
Poco::UInt32 getCRCFromHeader() const;
|
||||
|
||||
Poco::UInt32 getCompressedSizeFromHeader() const;
|
||||
|
||||
Poco::UInt32 getUncompressedSizeFromHeader() const;
|
||||
|
||||
void setRequiredVersion(int major, int minor);
|
||||
|
||||
void setHostSystem(ZipCommon::HostSystem hs);
|
||||
|
||||
void setLastModifiedAt(const Poco::DateTime& dt);
|
||||
|
||||
void setEncryption(bool val);
|
||||
|
||||
void setFileNameLength(Poco::UInt16 size);
|
||||
|
||||
void setExtraFieldSize(Poco::UInt16 size);
|
||||
|
||||
void setCompressionMethod(ZipCommon::CompressionMethod cm);
|
||||
|
||||
void setCompressionLevel(ZipCommon::CompressionLevel cl);
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
HEADER_POS = 0,
|
||||
VERSION_SIZE = 2,
|
||||
VERSION_POS = HEADER_POS+ZipCommon::HEADER_SIZE,
|
||||
GENERAL_PURPOSE_SIZE = 2,
|
||||
GENERAL_PURPOSE_POS = VERSION_POS + VERSION_SIZE,
|
||||
COMPR_METHOD_SIZE = 2,
|
||||
COMPR_METHOD_POS = GENERAL_PURPOSE_POS + GENERAL_PURPOSE_SIZE,
|
||||
LASTMODEFILETIME_SIZE = 2,
|
||||
LASTMODEFILETIME_POS = COMPR_METHOD_POS + COMPR_METHOD_SIZE,
|
||||
LASTMODEFILEDATE_SIZE = 2,
|
||||
LASTMODEFILEDATE_POS = LASTMODEFILETIME_POS + LASTMODEFILETIME_SIZE,
|
||||
CRC32_SIZE = 4,
|
||||
CRC32_POS = LASTMODEFILEDATE_POS + LASTMODEFILEDATE_SIZE,
|
||||
COMPRESSED_SIZE_SIZE = 4,
|
||||
COMPRESSED_SIZE_POS = CRC32_POS + CRC32_SIZE,
|
||||
UNCOMPRESSED_SIZE_SIZE = 4,
|
||||
UNCOMPRESSED_SIZE_POS = COMPRESSED_SIZE_POS + COMPRESSED_SIZE_SIZE,
|
||||
FILE_LENGTH_SIZE = 2,
|
||||
FILE_LENGTH_POS = UNCOMPRESSED_SIZE_POS + UNCOMPRESSED_SIZE_SIZE,
|
||||
EXTRA_FIELD_LENGTH = 2,
|
||||
EXTRA_FIELD_POS = FILE_LENGTH_POS + FILE_LENGTH_SIZE,
|
||||
FULLHEADER_SIZE = 30,
|
||||
|
||||
EXTRA_DATA_TAG_SIZE = 2,
|
||||
EXTRA_DATA_TAG_POS = 0,
|
||||
EXTRA_DATA_SIZE_SIZE = 2,
|
||||
EXTRA_DATA_SIZE_POS = EXTRA_DATA_TAG_POS + EXTRA_DATA_TAG_SIZE,
|
||||
EXTRA_DATA_POS = EXTRA_DATA_SIZE_POS + EXTRA_DATA_SIZE_SIZE,
|
||||
EXTRA_DATA_UNCOMPRESSED_SIZE_SIZE = 8,
|
||||
EXTRA_DATA_COMPRESSED_SIZE_SIZE = 8,
|
||||
FULLEXTRA_DATA_SIZE = 20
|
||||
};
|
||||
|
||||
bool _forceZip64;
|
||||
char _rawHeader[FULLHEADER_SIZE];
|
||||
std::streamoff _startPos;
|
||||
std::streamoff _endPos;
|
||||
std::string _fileName;
|
||||
Poco::DateTime _lastModifiedAt;
|
||||
std::string _extraField;
|
||||
Poco::UInt32 _crc32;
|
||||
Poco::UInt64 _compressedSize;
|
||||
Poco::UInt64 _uncompressedSize;
|
||||
|
||||
friend class ZipStreamBuf;
|
||||
};
|
||||
|
||||
|
||||
inline void ZipLocalFileHeader::setFileNameLength(Poco::UInt16 size)
|
||||
{
|
||||
ZipUtil::set16BitValue(size, _rawHeader, FILE_LENGTH_POS);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipLocalFileHeader::setExtraFieldSize(Poco::UInt16 size)
|
||||
{
|
||||
ZipUtil::set16BitValue(size, _rawHeader, EXTRA_FIELD_POS);
|
||||
}
|
||||
|
||||
|
||||
inline ZipCommon::HostSystem ZipLocalFileHeader::getHostSystem() const
|
||||
{
|
||||
return static_cast<ZipCommon::HostSystem>(_rawHeader[VERSION_POS + 1]);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipLocalFileHeader::setHostSystem(ZipCommon::HostSystem hs)
|
||||
{
|
||||
_rawHeader[VERSION_POS + 1] = static_cast<char>(hs);
|
||||
}
|
||||
|
||||
|
||||
inline int ZipLocalFileHeader::getMajorVersionNumber() const
|
||||
{
|
||||
return (_rawHeader[VERSION_POS]/10);
|
||||
}
|
||||
|
||||
|
||||
inline int ZipLocalFileHeader::getMinorVersionNumber() const
|
||||
{
|
||||
return (_rawHeader[VERSION_POS]%10);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipLocalFileHeader::getRequiredVersion(int& major, int& minor)
|
||||
{
|
||||
major = getMajorVersionNumber();
|
||||
minor = getMinorVersionNumber();
|
||||
}
|
||||
|
||||
|
||||
inline bool ZipLocalFileHeader::needsZip64() const
|
||||
{
|
||||
return _forceZip64 || _startPos >= ZipCommon::ZIP64_MAGIC || _compressedSize >= ZipCommon::ZIP64_MAGIC || _uncompressedSize >= ZipCommon::ZIP64_MAGIC;
|
||||
}
|
||||
|
||||
|
||||
inline void ZipLocalFileHeader::setZip64Data()
|
||||
{
|
||||
setRequiredVersion(4, 5);
|
||||
char data[FULLEXTRA_DATA_SIZE];
|
||||
ZipUtil::set16BitValue(ZipCommon::ZIP64_EXTRA_ID, data, EXTRA_DATA_TAG_POS);
|
||||
Poco::UInt16 pos = EXTRA_DATA_POS;
|
||||
ZipUtil::set64BitValue(_uncompressedSize, data, pos); pos += 8;
|
||||
ZipUtil::set32BitValue(ZipCommon::ZIP64_MAGIC, _rawHeader, UNCOMPRESSED_SIZE_POS);
|
||||
ZipUtil::set64BitValue(_compressedSize, data, pos); pos += 8;
|
||||
ZipUtil::set32BitValue(ZipCommon::ZIP64_MAGIC, _rawHeader, COMPRESSED_SIZE_POS);
|
||||
ZipUtil::set16BitValue(pos - EXTRA_DATA_POS, data, EXTRA_DATA_SIZE_POS);
|
||||
_extraField = std::string(data, pos);
|
||||
ZipUtil::set16BitValue(pos, _rawHeader, EXTRA_FIELD_POS);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipLocalFileHeader::setRequiredVersion(int major, int minor)
|
||||
{
|
||||
poco_assert (minor < 10);
|
||||
poco_assert (major < 24);
|
||||
_rawHeader[VERSION_POS] = static_cast<char>(static_cast<unsigned char>(major)*10+static_cast<unsigned char>(minor));
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt16 ZipLocalFileHeader::getFileNameLength() const
|
||||
{
|
||||
return ZipUtil::get16BitValue(_rawHeader, FILE_LENGTH_POS);
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt16 ZipLocalFileHeader::getExtraFieldLength() const
|
||||
{
|
||||
return ZipUtil::get16BitValue(_rawHeader, EXTRA_FIELD_POS);
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt32 ZipLocalFileHeader::getHeaderSize() const
|
||||
{
|
||||
return FULLHEADER_SIZE+getExtraFieldLength()+getFileNameLength();
|
||||
}
|
||||
|
||||
|
||||
inline std::streamoff ZipLocalFileHeader::getStartPos() const
|
||||
{
|
||||
return _startPos;
|
||||
}
|
||||
|
||||
|
||||
inline void ZipLocalFileHeader::setStartPos(std::streamoff start)
|
||||
{
|
||||
_startPos = start;
|
||||
_endPos = start + getHeaderSize()+static_cast<std::streamoff>(getCompressedSize());
|
||||
}
|
||||
|
||||
|
||||
inline std::streamoff ZipLocalFileHeader::getEndPos() const
|
||||
{
|
||||
return _endPos;
|
||||
}
|
||||
|
||||
|
||||
inline void ZipLocalFileHeader::parseDateTime()
|
||||
{
|
||||
_lastModifiedAt = ZipUtil::parseDateTime(_rawHeader, LASTMODEFILETIME_POS, LASTMODEFILEDATE_POS);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipLocalFileHeader::setLastModifiedAt(const Poco::DateTime& dt)
|
||||
{
|
||||
_lastModifiedAt = dt;
|
||||
ZipUtil::setDateTime(dt, _rawHeader, LASTMODEFILETIME_POS, LASTMODEFILEDATE_POS);
|
||||
}
|
||||
|
||||
|
||||
inline ZipCommon::CompressionMethod ZipLocalFileHeader::getCompressionMethod() const
|
||||
{
|
||||
return static_cast<ZipCommon::CompressionMethod>(ZipUtil::get16BitValue(_rawHeader, COMPR_METHOD_POS));
|
||||
}
|
||||
|
||||
|
||||
inline ZipCommon::CompressionLevel ZipLocalFileHeader::getCompressionLevel() const
|
||||
{
|
||||
// bit 1 and 2 indicate the level
|
||||
return static_cast<ZipCommon::CompressionLevel>((ZipUtil::get16BitValue(_rawHeader, GENERAL_PURPOSE_POS)>>1) & 0x0003);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipLocalFileHeader::setCompressionMethod(ZipCommon::CompressionMethod cm)
|
||||
{
|
||||
ZipUtil::set16BitValue(static_cast<Poco::UInt16>(cm), _rawHeader, COMPR_METHOD_POS);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipLocalFileHeader::setCompressionLevel(ZipCommon::CompressionLevel cl)
|
||||
{
|
||||
// bit 1 and 2 indicate the level
|
||||
Poco::UInt16 val = static_cast<Poco::UInt16>(cl);
|
||||
val <<= 1;
|
||||
Poco::UInt16 mask = 0xfff9;
|
||||
_rawHeader[GENERAL_PURPOSE_POS] = ((_rawHeader[GENERAL_PURPOSE_POS] & mask) | val);
|
||||
}
|
||||
|
||||
|
||||
inline bool ZipLocalFileHeader::isEncrypted() const
|
||||
{
|
||||
// bit 0 indicates encryption
|
||||
return ((ZipUtil::get16BitValue(_rawHeader, GENERAL_PURPOSE_POS) & 0x0001) != 0);
|
||||
}
|
||||
|
||||
|
||||
inline bool ZipLocalFileHeader::hasSupportedCompressionMethod() const
|
||||
{
|
||||
ZipCommon::CompressionMethod method = getCompressionMethod();
|
||||
return method == ZipCommon::CM_DEFLATE || method == ZipCommon::CM_STORE;
|
||||
}
|
||||
|
||||
|
||||
inline void ZipLocalFileHeader::setEncryption(bool val)
|
||||
{
|
||||
if (val)
|
||||
_rawHeader[GENERAL_PURPOSE_POS] |= 0x01;
|
||||
else
|
||||
_rawHeader[GENERAL_PURPOSE_POS] &= 0xfe;
|
||||
}
|
||||
|
||||
|
||||
inline void ZipLocalFileHeader::setSearchCRCAndSizesAfterData(bool val)
|
||||
{
|
||||
//set bit 3 of general purpose reg
|
||||
if (val)
|
||||
_rawHeader[GENERAL_PURPOSE_POS] |= 0x08;
|
||||
else
|
||||
_rawHeader[GENERAL_PURPOSE_POS] &= 0xf7;
|
||||
}
|
||||
|
||||
|
||||
inline const Poco::DateTime& ZipLocalFileHeader::lastModifiedAt() const
|
||||
{
|
||||
return _lastModifiedAt;
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt32 ZipLocalFileHeader::getCRC() const
|
||||
{
|
||||
return _crc32;
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt64 ZipLocalFileHeader::getCompressedSize() const
|
||||
{
|
||||
return _compressedSize;
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt64 ZipLocalFileHeader::getUncompressedSize() const
|
||||
{
|
||||
return _uncompressedSize;
|
||||
}
|
||||
|
||||
|
||||
inline void ZipLocalFileHeader::setCRC(Poco::UInt32 val)
|
||||
{
|
||||
_crc32 = val;
|
||||
ZipUtil::set32BitValue(val, _rawHeader, CRC32_POS);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipLocalFileHeader::setCompressedSize(Poco::UInt64 val)
|
||||
{
|
||||
_compressedSize = val;
|
||||
ZipUtil::set32BitValue(val >= ZipCommon::ZIP64_MAGIC ? ZipCommon::ZIP64_MAGIC : static_cast<Poco::UInt32>(val), _rawHeader, COMPRESSED_SIZE_POS);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipLocalFileHeader::setUncompressedSize(Poco::UInt64 val)
|
||||
{
|
||||
_uncompressedSize = val;
|
||||
ZipUtil::set32BitValue(val >= ZipCommon::ZIP64_MAGIC ? ZipCommon::ZIP64_MAGIC : static_cast<Poco::UInt32>(val), _rawHeader, UNCOMPRESSED_SIZE_POS);
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt32 ZipLocalFileHeader::getCRCFromHeader() const
|
||||
{
|
||||
return ZipUtil::get32BitValue(_rawHeader, CRC32_POS);
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt32 ZipLocalFileHeader::getCompressedSizeFromHeader() const
|
||||
{
|
||||
return ZipUtil::get32BitValue(_rawHeader, COMPRESSED_SIZE_POS);
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt32 ZipLocalFileHeader::getUncompressedSizeFromHeader() const
|
||||
{
|
||||
return ZipUtil::get32BitValue(_rawHeader, UNCOMPRESSED_SIZE_POS);
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& ZipLocalFileHeader::getFileName() const
|
||||
{
|
||||
return _fileName;
|
||||
}
|
||||
|
||||
|
||||
inline bool ZipLocalFileHeader::isFile() const
|
||||
{
|
||||
return !isDirectory();
|
||||
}
|
||||
|
||||
|
||||
inline bool ZipLocalFileHeader::isDirectory() const
|
||||
{
|
||||
poco_assert_dbg(!_fileName.empty());
|
||||
return getUncompressedSize() == 0 && _fileName[_fileName.length()-1] == '/';
|
||||
}
|
||||
|
||||
|
||||
inline bool ZipLocalFileHeader::hasExtraField() const
|
||||
{
|
||||
return getExtraFieldLength() > 0;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& ZipLocalFileHeader::getExtraField() const
|
||||
{
|
||||
return _extraField;
|
||||
}
|
||||
|
||||
|
||||
inline bool ZipLocalFileHeader::hasData() const
|
||||
{
|
||||
return (getCompressedSize() > 0);
|
||||
}
|
||||
|
||||
|
||||
inline std::streamoff ZipLocalFileHeader::getDataStartPos() const
|
||||
{
|
||||
return getStartPos() + getHeaderSize();
|
||||
}
|
||||
|
||||
|
||||
inline std::streamoff ZipLocalFileHeader::getDataEndPos() const
|
||||
{
|
||||
return getDataStartPos()+static_cast<std::streamoff>(getCompressedSize());
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Zip
|
||||
|
||||
|
||||
#endif // Zip_ZipLocalFileHeader_INCLUDED
|
109
vendor/POCO/Zip/include/Poco/Zip/ZipManipulator.h
vendored
Normal file
109
vendor/POCO/Zip/include/Poco/Zip/ZipManipulator.h
vendored
Normal file
@ -0,0 +1,109 @@
|
||||
//
|
||||
// ZipManipulator.h
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Manipulation
|
||||
// Module: ZipManipulator
|
||||
//
|
||||
// Definition of the ZipManipulator class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Zip_ZipManipulator_INCLUDED
|
||||
#define Zip_ZipManipulator_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Zip/Zip.h"
|
||||
#include "Poco/Zip/ZipArchive.h"
|
||||
#include "Poco/Zip/ZipCommon.h"
|
||||
#include "Poco/Zip/ZipOperation.h"
|
||||
#include "Poco/FIFOEvent.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
#include <map>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Zip {
|
||||
|
||||
|
||||
class ZipArchive;
|
||||
|
||||
|
||||
class Zip_API ZipManipulator
|
||||
/// ZipManipulator allows to add/remove/update files inside zip files
|
||||
{
|
||||
public:
|
||||
Poco::FIFOEvent<const ZipLocalFileHeader> EDone;
|
||||
// Fired for each entry once commit is invoked
|
||||
|
||||
ZipManipulator(const std::string& zipFile, bool backupOriginalFile);
|
||||
/// Creates the ZipManipulator.
|
||||
|
||||
virtual ~ZipManipulator();
|
||||
/// Destroys the ZipManipulator.
|
||||
|
||||
void deleteFile(const std::string& zipPath);
|
||||
/// Removes the given file from the Zip archive.
|
||||
|
||||
void replaceFile(const std::string& zipPath, const std::string& localPath);
|
||||
/// Replaces the contents of the file in the archive with the contents
|
||||
/// from the file given by localPath.
|
||||
|
||||
void renameFile(const std::string& zipPath, const std::string& newZipPath);
|
||||
/// Renames the file in the archive to newZipPath
|
||||
|
||||
void addFile(const std::string& zipPath, const std::string& localPath, ZipCommon::CompressionMethod cm = ZipCommon::CM_DEFLATE, ZipCommon::CompressionLevel cl = ZipCommon::CL_MAXIMUM);
|
||||
/// Adds a file to the zip file.
|
||||
|
||||
ZipArchive commit();
|
||||
/// Commits all changes and re-creates the Zip File with the changes applied.
|
||||
/// Returns the ZipArchive for the newly created archive
|
||||
///
|
||||
/// Changes will be first written to a temporary file,
|
||||
/// then the originalfile will be either deleted or renamed to .bak,
|
||||
/// then, the temp file will be renamed to the original zip file name.
|
||||
|
||||
const ZipArchive& originalArchive() const;
|
||||
/// Returns the original archive information
|
||||
|
||||
private:
|
||||
const ZipLocalFileHeader& getForChange(const std::string& zipPath) const;
|
||||
/// Searches for the entry given by the zipPath.
|
||||
/// Throws an exception if the entry does not exist
|
||||
/// or if an entry already exists in the Changeslist
|
||||
|
||||
void addOperation(const std::string& zipPath, ZipOperation::Ptr ptrOp);
|
||||
/// Adds the operation to the changes list. Throws an exception if an
|
||||
/// entry for the zipPath already exists
|
||||
|
||||
void onEDone(const void* pSender, const ZipLocalFileHeader& hdr);
|
||||
/// Forwards the event to the EDone event
|
||||
|
||||
ZipArchive compress(const std::string& outFile);
|
||||
/// Compresses the new file to outFile
|
||||
|
||||
private:
|
||||
using Changes = std::map<std::string, ZipOperation::Ptr>;
|
||||
|
||||
const std::string _zipFile;
|
||||
bool _backupOriginalFile;
|
||||
Changes _changes;
|
||||
Poco::SharedPtr<ZipArchive> _in;
|
||||
};
|
||||
|
||||
|
||||
inline const ZipArchive& ZipManipulator::originalArchive() const
|
||||
{
|
||||
return *_in;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Zip
|
||||
|
||||
|
||||
#endif // Zip_ZipManipulator_INCLUDED
|
56
vendor/POCO/Zip/include/Poco/Zip/ZipOperation.h
vendored
Normal file
56
vendor/POCO/Zip/include/Poco/Zip/ZipOperation.h
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
//
|
||||
// ZipOperation.h
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Manipulation
|
||||
// Module: ZipOperation
|
||||
//
|
||||
// Definition of the ZipOperation class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Zip_ZipOperation_INCLUDED
|
||||
#define Zip_ZipOperation_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Zip/Zip.h"
|
||||
#include "Poco/RefCountedObject.h"
|
||||
#include "Poco/AutoPtr.h"
|
||||
#include <ostream>
|
||||
#include <istream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Zip {
|
||||
|
||||
|
||||
class Compress;
|
||||
|
||||
|
||||
class Zip_API ZipOperation: public Poco::RefCountedObject
|
||||
/// Abstract super class for operations on individual zip entries
|
||||
{
|
||||
public:
|
||||
using Ptr = Poco::AutoPtr<ZipOperation>;
|
||||
|
||||
ZipOperation();
|
||||
/// Creates the ZipOperation.
|
||||
|
||||
virtual void execute(Compress& c, std::istream& input) = 0;
|
||||
/// Executes the operation
|
||||
|
||||
protected:
|
||||
virtual ~ZipOperation();
|
||||
/// Destroys the ZipOperation.
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Zip
|
||||
|
||||
|
||||
#endif // Zip_ZipOperation_INCLUDED
|
150
vendor/POCO/Zip/include/Poco/Zip/ZipStream.h
vendored
Normal file
150
vendor/POCO/Zip/include/Poco/Zip/ZipStream.h
vendored
Normal file
@ -0,0 +1,150 @@
|
||||
//
|
||||
// ZipStream.h
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Zip
|
||||
// Module: ZipStream
|
||||
//
|
||||
// Definition of the ZipStream class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Zip_ZipStream_INCLUDED
|
||||
#define Zip_ZipStream_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Zip/Zip.h"
|
||||
#include "Poco/Zip/PartialStream.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
#include "Poco/BufferedStreamBuf.h"
|
||||
#include "Poco/Checksum.h"
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Zip {
|
||||
|
||||
|
||||
class ZipArchive;
|
||||
class ZipLocalFileHeader;
|
||||
|
||||
|
||||
class Zip_API ZipStreamBuf: public Poco::BufferedStreamBuf
|
||||
/// ZipStreamBuf is used to decompress single files from a Zip file.
|
||||
{
|
||||
public:
|
||||
ZipStreamBuf(std::istream& istr, const ZipLocalFileHeader& fileEntry, bool reposition);
|
||||
/// Creates the ZipStreamBuf. Set reposition to false, if you do on-the-fly decompression.
|
||||
|
||||
ZipStreamBuf(std::ostream& ostr, ZipLocalFileHeader& fileEntry, bool reposition);
|
||||
/// Creates the ZipStreamBuf. Set reposition to false, if you do on-the-fly compression.
|
||||
|
||||
virtual ~ZipStreamBuf();
|
||||
/// Destroys the ZipStreamBuf.
|
||||
|
||||
void close(Poco::UInt64& extraDataSize);
|
||||
/// Informs a writing outputstream that writing is done for this stream
|
||||
|
||||
bool crcValid() const;
|
||||
/// Call this method once all bytes were read from the input stream to determine if the CRC is valid
|
||||
|
||||
protected:
|
||||
int readFromDevice(char* buffer, std::streamsize length);
|
||||
|
||||
int writeToDevice(const char* buffer, std::streamsize length);
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
STREAM_BUFFER_SIZE = 1024
|
||||
};
|
||||
|
||||
using PtrIStream = Poco::SharedPtr<std::istream>;
|
||||
using PtrOStream = Poco::SharedPtr<std::ostream>;
|
||||
|
||||
std::istream* _pIstr;
|
||||
std::ostream* _pOstr;
|
||||
PtrIStream _ptrBuf;
|
||||
PtrOStream _ptrOBuf;
|
||||
PtrIStream _ptrHelper;
|
||||
Poco::SharedPtr<PartialOutputStream> _ptrOHelper;
|
||||
Poco::Checksum _crc32;
|
||||
Poco::UInt32 _expectedCrc32;
|
||||
bool _checkCRC;
|
||||
/// Note: we do not check crc if we decompress a streaming zip file and the crc is stored in the directory header
|
||||
Poco::UInt64 _bytesWritten;
|
||||
ZipLocalFileHeader* _pHeader;
|
||||
};
|
||||
|
||||
|
||||
class Zip_API ZipIOS: public virtual std::ios
|
||||
/// The base class for ZipInputStream and ZipOutputStream.
|
||||
///
|
||||
/// This class is needed to ensure the correct initialization
|
||||
/// order of the stream buffer and base classes.
|
||||
{
|
||||
public:
|
||||
ZipIOS(std::istream& istr, const ZipLocalFileHeader& fileEntry, bool reposition);
|
||||
/// Creates the basic stream and connects it
|
||||
/// to the given input stream.
|
||||
|
||||
ZipIOS(std::ostream& ostr, ZipLocalFileHeader& fileEntry, bool reposition);
|
||||
/// Creates the basic stream and connects it
|
||||
/// to the given output stream.
|
||||
|
||||
~ZipIOS();
|
||||
/// Destroys the stream.
|
||||
|
||||
ZipStreamBuf* rdbuf();
|
||||
/// Returns a pointer to the underlying streambuf.
|
||||
|
||||
protected:
|
||||
ZipStreamBuf _buf;
|
||||
};
|
||||
|
||||
|
||||
class Zip_API ZipInputStream: public ZipIOS, public std::istream
|
||||
/// This stream copies all characters read through it
|
||||
/// to one or multiple output streams.
|
||||
{
|
||||
public:
|
||||
ZipInputStream(std::istream& istr, const ZipLocalFileHeader& fileEntry, bool reposition = true);
|
||||
/// Creates the ZipInputStream and connects it
|
||||
/// to the given input stream.
|
||||
|
||||
~ZipInputStream();
|
||||
/// Destroys the ZipInputStream.
|
||||
|
||||
bool crcValid() const;
|
||||
/// Call this method once all bytes were read from the input stream to determine if the CRC is valid
|
||||
};
|
||||
|
||||
|
||||
|
||||
class Zip_API ZipOutputStream: public ZipIOS, public std::ostream
|
||||
/// This stream compresses all characters written through it
|
||||
/// to one output stream.
|
||||
{
|
||||
public:
|
||||
ZipOutputStream(std::ostream& ostr, ZipLocalFileHeader& fileEntry, bool seekableOutput);
|
||||
/// Creates the ZipOutputStream and connects it
|
||||
/// to the given output stream.
|
||||
|
||||
~ZipOutputStream();
|
||||
/// Destroys the ZipOutputStream.
|
||||
|
||||
void close(Poco::UInt64& extraDataSize);
|
||||
/// Must be called for ZipOutputStreams!
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Zip
|
||||
|
||||
|
||||
#endif // Zip_ZipStream_INCLUDED
|
126
vendor/POCO/Zip/include/Poco/Zip/ZipUtil.h
vendored
Normal file
126
vendor/POCO/Zip/include/Poco/Zip/ZipUtil.h
vendored
Normal file
@ -0,0 +1,126 @@
|
||||
//
|
||||
// ZipUtil.h
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Zip
|
||||
// Module: ZipUtil
|
||||
//
|
||||
// Definition of the ZipUtil class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Zip_ZipUtil_INCLUDED
|
||||
#define Zip_ZipUtil_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Zip/Zip.h"
|
||||
#include "Poco/Zip/ZipCommon.h"
|
||||
#include "Poco/DateTime.h"
|
||||
#include "Poco/Path.h"
|
||||
#include <istream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Zip {
|
||||
|
||||
|
||||
class Zip_API ZipUtil
|
||||
/// A utility class used for parsing header information inside of zip files
|
||||
{
|
||||
public:
|
||||
static Poco::UInt16 get16BitValue(const char* pVal, const Poco::UInt32 pos);
|
||||
|
||||
static Poco::UInt32 get32BitValue(const char* pVal, const Poco::UInt32 pos);
|
||||
|
||||
static Poco::UInt64 get64BitValue(const char* pVal, const Poco::UInt32 pos);
|
||||
|
||||
static void set16BitValue(const Poco::UInt16 val, char* pVal, const Poco::UInt32 pos);
|
||||
|
||||
static void set32BitValue(const Poco::UInt32 val, char* pVal, const Poco::UInt32 pos);
|
||||
|
||||
static void set64BitValue(const Poco::UInt64 val, char* pVal, const Poco::UInt32 pos);
|
||||
|
||||
static Poco::DateTime parseDateTime(const char* pVal, const Poco::UInt32 timePos, const Poco::UInt32 datePos);
|
||||
|
||||
static void setDateTime(const Poco::DateTime& dt, char* pVal, const Poco::UInt32 timePos, const Poco::UInt32 datePos);
|
||||
|
||||
static std::string fakeZLibInitString(ZipCommon::CompressionLevel cl);
|
||||
|
||||
static void sync(std::istream& in);
|
||||
/// Searches the next valid header in the input stream, stops right before it
|
||||
|
||||
static void syncDataDescriptor(std::istream& in, bool force64);
|
||||
/// Searches the next data descriptor
|
||||
|
||||
static void verifyZipEntryFileName(const std::string& zipPath);
|
||||
/// Verifies that the name of the ZipEntry is a valid path
|
||||
|
||||
static std::string validZipEntryFileName(const Poco::Path& entry);
|
||||
|
||||
private:
|
||||
ZipUtil();
|
||||
~ZipUtil();
|
||||
ZipUtil(const ZipUtil&);
|
||||
ZipUtil& operator=(const ZipUtil&);
|
||||
};
|
||||
|
||||
|
||||
inline Poco::UInt16 ZipUtil::get16BitValue(const char* pVal, const Poco::UInt32 pos)
|
||||
{
|
||||
return static_cast<Poco::UInt16>((unsigned char)pVal[pos])+ (static_cast<Poco::UInt16>((unsigned char)pVal[pos+1]) << 8);
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt32 ZipUtil::get32BitValue(const char* pVal, const Poco::UInt32 pos)
|
||||
{
|
||||
return static_cast<Poco::UInt32>((unsigned char)pVal[pos])+ (static_cast<Poco::UInt32>((unsigned char)pVal[pos+1]) << 8)+
|
||||
(static_cast<Poco::UInt32>((unsigned char)pVal[pos+2]) << 16) + (static_cast<Poco::UInt32>((unsigned char)pVal[pos+3]) << 24);
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt64 ZipUtil::get64BitValue(const char* pVal, const Poco::UInt32 pos)
|
||||
{
|
||||
Poco::UInt64 val = ZipUtil::get32BitValue(pVal, pos+4);
|
||||
val = (val << 32) | ZipUtil::get32BitValue(pVal, pos);
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
inline void ZipUtil::set16BitValue(const Poco::UInt16 val, char* pVal, const Poco::UInt32 pos)
|
||||
{
|
||||
pVal[pos] = static_cast<char>(val);
|
||||
pVal[pos+1] = static_cast<char>(val>>8);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipUtil::set32BitValue(const Poco::UInt32 val, char* pVal, const Poco::UInt32 pos)
|
||||
{
|
||||
pVal[pos] = static_cast<char>(val);
|
||||
pVal[pos+1] = static_cast<char>(val>>8);
|
||||
pVal[pos+2] = static_cast<char>(val>>16);
|
||||
pVal[pos+3] = static_cast<char>(val>>24);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipUtil::set64BitValue(const Poco::UInt64 val, char* pVal, const Poco::UInt32 pos)
|
||||
{
|
||||
pVal[pos] = static_cast<char>(val);
|
||||
pVal[pos+1] = static_cast<char>(val>>8);
|
||||
pVal[pos+2] = static_cast<char>(val>>16);
|
||||
pVal[pos+3] = static_cast<char>(val>>24);
|
||||
pVal[pos+4] = static_cast<char>(val>>32);
|
||||
pVal[pos+5] = static_cast<char>(val>>40);
|
||||
pVal[pos+6] = static_cast<char>(val>>48);
|
||||
pVal[pos+7] = static_cast<char>(val>>56);
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Zip
|
||||
|
||||
|
||||
#endif // Zip_ZipUtil_INCLUDED
|
Reference in New Issue
Block a user