bit7z 4.0.9
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) 2014-2023 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 <unordered_map>
14
15#include "bitarchivewriter.hpp"
16
17namespace bit7z {
18
19using std::vector;
20
22
23enum struct DeletePolicy : std::uint8_t {
24 ItemOnly,
25 RecurseDirs
26};
27
35class BIT7Z_MAYBE_UNUSED BitArchiveEditor final : public BitArchiveWriter {
36 public:
46 const tstring& inFile,
47 const BitInOutFormat& format,
48 const tstring& password = {} );
49
50 BitArchiveEditor( const BitArchiveEditor& ) = delete;
51
53
54 auto operator=( const BitArchiveEditor& ) -> BitArchiveEditor& = delete;
55
56 auto operator=( BitArchiveEditor&& ) -> BitArchiveEditor& = delete;
57
58 ~BitArchiveEditor() override;
59
67 void setUpdateMode( UpdateMode mode ) override;
68
75 void renameItem( uint32_t index, const tstring& newPath );
76
83 void renameItem( const tstring& oldPath, const tstring& newPath );
84
92 void updateItem( uint32_t index, const tstring& inFile );
93
101 void updateItem( uint32_t index, const std::vector< byte_t >& inBuffer );
102
110 void updateItem( uint32_t index, std::istream& inStream );
111
119 void updateItem( const tstring& itemPath, const tstring& inFile );
120
128 void updateItem( const tstring& itemPath, const std::vector< byte_t >& inBuffer );
129
137 void updateItem( const tstring& itemPath, istream& inStream );
138
151 void deleteItem( uint32_t index, DeletePolicy policy = DeletePolicy::ItemOnly );
152
173 void deleteItem( const tstring& itemPath, DeletePolicy policy = DeletePolicy::ItemOnly );
174
179
180 private:
181 EditedItems mEditedItems;
182
183 auto findItem( const tstring& itemPath ) -> uint32_t;
184
185 void checkIndex( uint32_t index );
186
187 auto itemProperty( InputIndex index, BitProperty property ) const -> BitPropVariant override;
188
189 auto itemStream( InputIndex index, ISequentialInStream** inStream ) const -> HRESULT override;
190
191 auto hasNewData( uint32_t index ) const noexcept -> bool override;
192
193 auto hasNewProperties( uint32_t index ) const noexcept -> bool override;
194
195 void markItemAsDeleted( uint32_t index );
196};
197
198} // namespace bit7z
199
200#endif //BITARCHIVEEDITOR_HPP
The Bit7zLibrary class allows accessing the basic functionalities provided by the 7z DLLs.
Definition bit7zlibrary.hpp:56
The BitArchiveEditor class allows creating new file archives or updating old ones.
Definition bitarchiveeditor.hpp:35
void deleteItem(uint32_t index, DeletePolicy policy=DeletePolicy::ItemOnly)
Marks as deleted the item at the given index.
void updateItem(const tstring &itemPath, istream &inStream)
Requests to update the content of the item at the specified path with the data from the given stream.
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 updateItem(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, const std::vector< byte_t > &inBuffer)
Requests to update the content of the item at the specified path with the data from the given buffer.
void updateItem(uint32_t index, const std::vector< byte_t > &inBuffer)
Requests to update the content of the item at the specified index with the data from the given buffer...
void renameItem(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, const tstring &inFile)
Requests to update the content of the item at the specified path with the data from the given file.
void updateItem(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...
BitArchiveEditor(const Bit7zLibrary &lib, const tstring &inFile, const BitInOutFormat &format, const tstring &password={})
Constructs a BitArchiveEditor object, reading the given archive file path.
The BitArchiveWriter class allows creating new archives or updating old ones with new items.
Definition bitarchivewriter.hpp:20
The BitInOutFormat class specifies a format available for creating new archives and extract old ones.
Definition bitformat.hpp:105
The main namespace of the bit7z library.
Definition bit7zlibrary.hpp:30
BitProperty
The BitProperty enum represents the archive/item properties that 7-zip can read or write.
Definition bitpropvariant.hpp:30
UpdateMode
Enumeration representing how an archive creator should deal when the output archive already exists.
Definition bitabstractarchivecreator.hpp:34
The BitPropVariant struct is a light extension to the WinAPI PROPVARIANT struct providing useful gett...
Definition bitpropvariant.hpp:150