bit7z 4.1.0
A C++ library for interfacing with the 7-zip shared libs.
Loading...
Searching...
No Matches
bitabstractarchivehandler.hpp
1/*
2 * bit7z - A C++ static library to interface with the 7-zip shared libraries.
3 * Copyright (c) Riccardo Ostani - All Rights Reserved.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
8 */
9
10#ifndef BITABSTRACTARCHIVEHANDLER_HPP
11#define BITABSTRACTARCHIVEHANDLER_HPP
12
13#include "bit7zlibrary.hpp"
14#include "bitdefines.hpp"
15#include "bittypes.hpp"
16
17#include <cstdint>
18#include <functional>
19
20namespace bit7z {
21
22class BitInFormat;
23class BitArchiveItem;
24
29
35
41
46using FileCallback = std::function< void( const tstring& ) >;
47
52
57
66
74
78using BufferCallback = std::function< buffer_t&( std::uint32_t, const tstring& ) >;
79
87 BIT7Z_DEPRECATED_ENUMERATOR( Process, ProcessItem, "Use FilterResult::ProcessItem" ),
88 BIT7Z_DEPRECATED_ENUMERATOR( Skip, SkipItem, "Use FilterResult::SkipItem" ),
89 BIT7Z_DEPRECATED_ENUMERATOR( Abort, AbortOperation, "Use FilterResult::AbortOperation" ),
90};
91
96
101 None = 0,
103 Skip,
104 //TODO: RenameOutput,
105 //TODO: RenameExisting
106};
107
116
120class BitAbstractArchiveHandler {
121 public:
122 BitAbstractArchiveHandler( const BitAbstractArchiveHandler& ) = delete;
123
124 BitAbstractArchiveHandler( BitAbstractArchiveHandler&& ) = delete;
125
126 auto operator=( const BitAbstractArchiveHandler& ) -> BitAbstractArchiveHandler& = delete;
127
128 auto operator=( BitAbstractArchiveHandler&& ) -> BitAbstractArchiveHandler& = delete;
129
130 virtual ~BitAbstractArchiveHandler() = default;
131
135 BIT7Z_NODISCARD auto library() const noexcept -> const Bit7zLibrary&;
136
140 BIT7Z_NODISCARD virtual auto format() const noexcept -> const BitInFormat& = 0;
141
145 BIT7Z_NODISCARD auto password() const -> const tstring&;
146
151 BIT7Z_NODISCARD auto retainDirectories() const noexcept -> bool;
152
156 BIT7Z_NODISCARD auto isPasswordDefined() const noexcept -> bool;
157
161 BIT7Z_NODISCARD auto totalCallback() const -> const TotalCallback&;
162
166 BIT7Z_NODISCARD auto progressCallback() const -> const ProgressCallback&;
167
171 BIT7Z_NODISCARD auto ratioCallback() const -> const RatioCallback&;
172
176 BIT7Z_NODISCARD auto fileCallback() const -> const FileCallback&;
177
181 BIT7Z_NODISCARD auto passwordCallback() const -> const PasswordCallback&;
182
186 BIT7Z_NODISCARD auto overwriteMode() const noexcept -> OverwriteMode;
187
207 virtual void setPassword( const tstring& password );
208
216 void clearPassword() noexcept;
217
223 void setRetainDirectories( bool retain ) noexcept;
224
230 void setTotalCallback( const TotalCallback& callback );
231
240 void setProgressCallback( const ProgressCallback& callback );
241
251 void setRatioCallback( const RatioCallback& callback );
252
258 void setFileCallback( const FileCallback& callback );
259
265 void setPasswordCallback( const PasswordCallback& callback );
266
273
274 protected:
275 explicit BitAbstractArchiveHandler(
276 const Bit7zLibrary& lib,
277 tstring password = {},
279 );
280
281 private:
282 const Bit7zLibrary& mLibrary;
283 tstring mPassword;
284 bool mRetainDirectories;
285 OverwriteMode mOverwriteMode;
286
287 //CALLBACKS
288 TotalCallback mTotalCallback;
289 ProgressCallback mProgressCallback;
290 RatioCallback mRatioCallback;
291 FileCallback mFileCallback;
292 PasswordCallback mPasswordCallback;
293};
294
295} // namespace bit7z
296
297#endif // BITABSTRACTARCHIVEHANDLER_HPP
The Bit7zLibrary class allows accessing the basic functionalities provided by the 7z DLLs.
Definition bit7zlibrary.hpp:55
void clearPassword() noexcept
Clear the current password used by the handler.
auto library() const noexcept -> const Bit7zLibrary &
auto password() const -> const tstring &
auto ratioCallback() const -> const RatioCallback &
auto progressCallback() const -> const ProgressCallback &
void setPasswordCallback(const PasswordCallback &callback)
Sets the function to be called when a password is needed to complete the ongoing operation.
void setFileCallback(const FileCallback &callback)
Sets the function to be called when the current file being processed changes.
void setRatioCallback(const RatioCallback &callback)
Sets the function to be called when the input processed size and current output size of the ongoing o...
virtual void setPassword(const tstring &password)
Sets up a password to be used by the archive handler.
void setProgressCallback(const ProgressCallback &callback)
Sets the function to be called when the processed size of the ongoing operation is updated.
virtual auto format() const noexcept -> const BitInFormat &=0
auto overwriteMode() const noexcept -> OverwriteMode
auto totalCallback() const -> const TotalCallback &
void setTotalCallback(const TotalCallback &callback)
Sets the function to be called when the total size of an operation is available.
auto fileCallback() const -> const FileCallback &
auto isPasswordDefined() const noexcept -> bool
auto retainDirectories() const noexcept -> bool
void setOverwriteMode(OverwriteMode mode)
Sets how the handler should behave when it tries to output to an existing file or buffer.
void setRetainDirectories(bool retain) noexcept
Sets whether the operations' output will preserve the input's directory structure or not.
auto passwordCallback() const -> const PasswordCallback &
The BitArchiveItem class represents a generic item inside an archive.
Definition bitarchiveitem.hpp:25
The BitInFormat class specifies an extractable archive format.
Definition bitformat.hpp:68
The main namespace of the bit7z library.
Definition bit7zlibrary.hpp:29
std::function< tstring(std::uint32_t, const tstring &) > LegacyRenameCallback
The (index, path) form of RenameCallback.
Definition bitabstractarchivehandler.hpp:73
FilterResult
Enumeration representing the result of applying a filter callback on an archive item.
Definition bitabstractarchivehandler.hpp:83
@ AbortOperation
Abort the whole operation.
Definition bitabstractarchivehandler.hpp:86
@ SkipItem
Skip the item (do not process it).
Definition bitabstractarchivehandler.hpp:85
@ ProcessItem
Continue processing the item.
Definition bitabstractarchivehandler.hpp:84
std::function< tstring() > PasswordCallback
A function returning the password to be used to handle an archive.
Definition bitabstractarchivehandler.hpp:51
unsigned char byte_t
A type representing a byte.
Definition bittypes.hpp:38
@ None
The creator will throw an exception (unless the OverwriteMode is not None).
Definition bitabstractarchivecreator.hpp:40
@ Overwrite
Definition bitabstractarchivecreator.hpp:43
std::function< void(const tstring &) > FileCallback
A function whose argument is the path, in the archive, of the file currently being processed by the o...
Definition bitabstractarchivehandler.hpp:46
std::function< bool(std::uint64_t) > ProgressCallback
A function whose argument is the currently processed size of the ongoing operation and returns true o...
Definition bitabstractarchivehandler.hpp:34
std::function< tstring(const BitArchiveItem &) > RenameCallback
A function returning a new name for the item currently being extracted.
Definition bitabstractarchivehandler.hpp:65
std::function< bool(const byte_t *, std::size_t) > RawDataCallback
A function providing the raw extracted data and its size to the user.
Definition bitabstractarchivehandler.hpp:56
std::basic_string< tchar > tstring
Definition bittypes.hpp:104
std::function< void(std::uint64_t, std::uint64_t) > RatioCallback
A function whose arguments are the current processed input size, and the current output size of the o...
Definition bitabstractarchivehandler.hpp:40
std::function< buffer_t &(std::uint32_t, const tstring &) > BufferCallback
A function returning a reference to the buffer where to extract the item at the given index/path.
Definition bitabstractarchivehandler.hpp:78
std::function< void(std::uint64_t) > TotalCallback
A function whose argument is the total size of the ongoing operation.
Definition bitabstractarchivehandler.hpp:28
FilterPolicy
Enumeration representing the policy according to which the archive handler should treat the items tha...
Definition bitabstractarchivehandler.hpp:112
@ Exclude
Do not extract/compress the items that match the pattern.
Definition bitabstractarchivehandler.hpp:114
@ Include
Extract/compress the items that match the pattern.
Definition bitabstractarchivehandler.hpp:113
OverwriteMode
Enumeration representing how a handler should deal when an output file already exists.
Definition bitabstractarchivehandler.hpp:100
@ None
The handler will throw an exception if the output file or buffer already exists.
Definition bitabstractarchivehandler.hpp:101
std::function< FilterResult(const BitArchiveItem &) > FilterCallback
A function returning what to do with the given archive item.
Definition bitabstractarchivehandler.hpp:95