bit7z 4.1.0
A C++ library for interfacing with the 7-zip shared libs.
Loading...
Searching...
No Matches
bitarchiveeditor.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 BITARCHIVEEDITOR_HPP
11#define BITARCHIVEEDITOR_HPP
12
13#include "bit7zlibrary.hpp"
14#include "bitabstractarchivecreator.hpp"
15#include "bitarchivewriter.hpp"
16#include "bitdefines.hpp"
17#include "bitformat.hpp"
18#include "bititemsvector.hpp"
19#include "bitpropvariant.hpp"
20#include "bitoutputarchive.hpp"
21#include "bittypes.hpp"
22#include "bitwindows.hpp"
23
24#include <cstdint>
25#include <istream>
26#include <unordered_map>
27
28namespace bit7z {
29
30using EditedItems = std::unordered_map< std::uint32_t, BitItemsVector::value_type >;
31
39
47class BIT7Z_MAYBE_UNUSED BitArchiveEditor final : public BitArchiveWriter {
48 public:
58 const Bit7zLibrary& lib,
59 const tstring& inFile,
61 const tstring& password = {}
62 );
63
64 BitArchiveEditor( const BitArchiveEditor& ) = delete;
65
67
68 auto operator=( const BitArchiveEditor& ) -> BitArchiveEditor& = delete;
69
70 auto operator=( BitArchiveEditor&& ) -> BitArchiveEditor& = delete;
71
72 ~BitArchiveEditor() override;
73
81 void setUpdateMode( UpdateMode mode ) override;
82
89 void renameItem( std::uint32_t index, const tstring& newPath );
90
97 void renameItem( const tstring& oldPath, const tstring& newPath );
98
106 void updateItem( std::uint32_t index, const tstring& inFile );
107
115 void updateItem( std::uint32_t index, const buffer_t& inBuffer );
116
123 void updateItem( std::uint32_t index, buffer_t&& inBuffer ) = delete;
124
132 void updateItem( std::uint32_t index, std::istream& inStream );
133
141 void updateItem( const tstring& itemPath, const tstring& inFile );
142
150 void updateItem( const tstring& itemPath, const buffer_t& inBuffer );
151
158 void updateItem( const tstring& itemPath, buffer_t&& inBuffer ) = delete;
159
167 void updateItem( const tstring& itemPath, std::istream& inStream );
168
182
203 void deleteItem( const tstring& itemPath, DeletePolicy policy = DeletePolicy::ItemOnly );
204
209
210 private:
211 EditedItems mEditedItems;
212
213 auto findItem( const tstring& itemPath ) const -> std::uint32_t;
214
215 void checkIndex( std::uint32_t index ) const;
216
217 auto itemProperty( InputIndex index, BitProperty property ) const -> BitPropVariant override;
218
219 auto itemStream( InputIndex index, ISequentialInStream** inStream ) const -> HRESULT override;
220
221 auto hasNewData( std::uint32_t index ) const noexcept -> bool override;
222
223 auto hasNewProperties( std::uint32_t index ) const noexcept -> bool override;
224
225 void markItemAsDeleted( std::uint32_t index );
226
227 void setEditedItem( std::uint32_t index, BitInputItem&& item );
228};
229
230} // namespace bit7z
231
232#endif //BITARCHIVEEDITOR_HPP
The Bit7zLibrary class allows accessing the basic functionalities provided by the 7z DLLs.
Definition bit7zlibrary.hpp:55
auto format() const noexcept -> const BitInFormat &override
auto password() const -> const tstring &
The BitArchiveEditor class allows creating new file archives or updating old ones.
Definition bitarchiveeditor.hpp:47
void updateItem(std::uint32_t index, const buffer_t &inBuffer)
Requests to update the content of the item at the specified index with the data from the given buffer...
void updateItem(const tstring &itemPath, const buffer_t &inBuffer)
Requests to update the content of the item at the specified path with the data from the given buffer.
void deleteItem(std::uint32_t index, DeletePolicy policy=DeletePolicy::ItemOnly)
Marks as deleted the item at the given index.
void updateItem(std::uint32_t index, buffer_t &&inBuffer)=delete
Deleted overload preventing the update from a temporary buffer.
void applyChanges()
Applies the requested changes (i.e., rename/update/delete operations) to the input archive.
void renameItem(const tstring &oldPath, const tstring &newPath)
Requests to change the path of the item from oldPath to the newPath.
void deleteItem(const tstring &itemPath, DeletePolicy policy=DeletePolicy::ItemOnly)
Marks as deleted the archive's item(s) with the specified path.
void setUpdateMode(UpdateMode mode) override
Sets how the editor performs the update of the items in the archive.
void renameItem(std::uint32_t index, const tstring &newPath)
Requests to change the path of the item at the specified index with the given one.
void updateItem(const tstring &itemPath, std::istream &inStream)
Requests to update the content of the item at the specified path with the data from the given stream.
void updateItem(const tstring &itemPath, const tstring &inFile)
Requests to update the content of the item at the specified path with the data from the given file.
BitArchiveEditor(const Bit7zLibrary &lib, const tstring &inFile, const BitInOutFormat &format, const tstring &password={})
Constructs a BitArchiveEditor object, reading the given archive file path.
void updateItem(std::uint32_t index, std::istream &inStream)
Requests to update the content of the item at the specified index with the data from the given stream...
void updateItem(std::uint32_t index, const tstring &inFile)
Requests to update the content of the item at the specified index with the data from the given file.
void updateItem(const tstring &itemPath, buffer_t &&inBuffer)=delete
Deleted overload preventing the update from a temporary buffer.
BitArchiveWriter(const Bit7zLibrary &lib, const BitInOutFormat &format)
Constructs an empty BitArchiveWriter object that can write archives of the specified format.
The BitInOutFormat class specifies a format available for creating new archives and extract old ones.
Definition bitformat.hpp:115
A generic input item for compression operations.
Definition bitinputitem.hpp:70
The main namespace of the bit7z library.
Definition bit7zlibrary.hpp:29
DeletePolicy
Enumeration representing how the deletion of an item from an archive should be handled.
Definition bitarchiveeditor.hpp:35
@ ItemOnly
Delete only the item itself; if it is a folder, its contents are kept.
Definition bitarchiveeditor.hpp:36
@ RecurseDirs
Delete the item; if it is a folder, its contents are recursively deleted too.
Definition bitarchiveeditor.hpp:37
BitProperty
The BitProperty enum represents the archive/item properties that 7-zip can read or write.
Definition bitpropvariant.hpp:32
UpdateMode
Enumeration representing how an archive creator should deal when the output archive already exists.
Definition bitabstractarchivecreator.hpp:39
std::basic_string< tchar > tstring
Definition bittypes.hpp:104
The BitPropVariant struct is a light extension to the WinAPI PROPVARIANT struct providing useful gett...
Definition bitpropvariant.hpp:161