bit7z 4.1.0
A C++ library for interfacing with the 7-zip shared libs.
Loading...
Searching...
No Matches
bitinputitem.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 BITINPUTITEM_HPP
11#define BITINPUTITEM_HPP
12
13#include "bitfs.hpp"
14#include "bitinputarchive.hpp"
15
16#include <cstdint>
17#include <functional>
18
19struct ISequentialInStream;
20
21namespace bit7z {
22
30
32namespace detail {
33
34struct FilesystemInputItem final {
35 SymlinkPolicy symlinkPolicy = SymlinkPolicy::Follow;
36#if defined( _MSC_VER ) && _MSC_VER <= 1900
37 explicit FilesystemInputItem( SymlinkPolicy policy ) : symlinkPolicy{ policy } {}
38#endif
39};
40
41using BufferInputItem = std::reference_wrapper< const buffer_t >;
42
43using StdInputItem = std::reference_wrapper< std::istream >;
44
45struct RenamedInputItemInitTag final {};
46
47struct RenamedInputItem final {
48 explicit RenamedInputItem( RenamedInputItemInitTag /* initTag */ ) {}
49};
50
51enum struct InputItemType : std::uint8_t {
52 Filesystem, Buffer, StdStream, RenamedItem
53};
54
55struct InputItemProperties final {
56 std::uint64_t size;
57 FILETIME lastWriteTime;
58 FILETIME lastAccessTime;
59 FILETIME creationTime;
60 std::uint32_t attributes;
61 InputItemType inputType;
62};
63
64} // namespace detail
66
70class BitInputItem final {
71 public:
72 explicit BitInputItem( const bit7zfs::path& itemPath, SymlinkPolicy symlinkPolicy = SymlinkPolicy::Follow );
73
74 BitInputItem(
75 const bit7zfs::path& itemPath,
76 const bit7zfs::path& inArchivePath,
78 );
79
80 BitInputItem( const bit7zfs::path& searchPath, const bit7zfs::directory_entry& entry, SymlinkPolicy symlinkPolicy );
81
82 BitInputItem( const buffer_t& buffer, const tstring& path );
83
84 BitInputItem( std::istream& stream, const tstring& path );
85
86 BitInputItem( const BitInputArchive& inputArchive, std::uint32_t index, const tstring& newPath );
87
91 BIT7Z_NODISCARD
92 auto isDir() const noexcept -> bool;
93
97 BIT7Z_NODISCARD
98 auto isSymLink() const noexcept -> bool;
99
103 BIT7Z_NODISCARD
104 auto size() const noexcept -> std::uint64_t;
105
109 BIT7Z_NODISCARD
110 auto path() const -> const native_string&;
111
115 BIT7Z_NODISCARD
116 auto attributes() const noexcept -> std::uint32_t;
117
121 BIT7Z_NODISCARD
122 auto inArchivePath() const -> const sevenzip_string&;
123
129 BIT7Z_NODISCARD
130 auto itemProperty( BitProperty property ) const -> BitPropVariant;
131
136 BIT7Z_NODISCARD
137 auto hasNewData() const noexcept -> bool;
138
144 void setCreationTime( time_type creationTime ) noexcept;
145
151 void setLastWriteTime( time_type lastWriteTime ) noexcept;
152
158 void setLastAccessTime( time_type lastAccessTime ) noexcept;
159
160 private:
161 friend class BitOutputArchive;
162 friend class BitArchiveEditor;
163
164 // For internal use only: provides the input stream for this item to be used during compression.
165 // On Windows, storeOpenFiles requests shared read/write access, allowing the compression of files
166 // locked by other processes. Returns S_OK on success, or an error HRESULT otherwise.
167 BIT7Z_NODISCARD
168 auto getStream( ISequentialInStream** inStream, bool storeOpenFiles ) const -> HRESULT;
169
170 detail::InputItemProperties mProperties;
171 // Note: we need to store paths as strings rather than bit7zfs::path as the public API is in C++14.
172 native_string mPath; // std::wstring on Windows, std::string elsewhere.
173 sevenzip_string mInArchivePath; // std::wstring on every OS, used by 7-Zip.
174
175 // Unfortunately, we cannot use std::variant as we need to support C++11/C++14 in the public API.
176 union {
177 detail::FilesystemInputItem mFilesystemItem;
178 detail::BufferInputItem mBufferItem;
179 detail::StdInputItem mStdItem;
180 detail::RenamedInputItem mRenamedItem;
181 };
182};
183
184} // namespace bit7z
185
186#endif //BITINPUTITEM_HPP
The BitInputArchive class, given a handler object, allows reading/extracting the content of archives.
Definition bitinputarchive.hpp:64
auto isSymLink() const noexcept -> bool
void setLastWriteTime(time_type lastWriteTime) noexcept
Sets the last write time of the item.
auto path() const -> const native_string &
void setLastAccessTime(time_type lastAccessTime) noexcept
Sets the last access time of the item.
auto itemProperty(BitProperty property) const -> BitPropVariant
auto isDir() const noexcept -> bool
void setCreationTime(time_type creationTime) noexcept
Sets the creation time of the item.
auto size() const noexcept -> std::uint64_t
auto hasNewData() const noexcept -> bool
auto inArchivePath() const -> const sevenzip_string &
auto attributes() const noexcept -> std::uint32_t
The main namespace of the bit7z library.
Definition bit7zlibrary.hpp:29
SymlinkPolicy
Enumeration representing how an input item should deal with symbolic links.
Definition bitinputitem.hpp:26
@ DoNotFollow
Do not follow symbolic links, storing the link itself.
Definition bitinputitem.hpp:28
@ Follow
Follow symbolic links, storing the content of the pointed-to file.
Definition bitinputitem.hpp:27
BitProperty
The BitProperty enum represents the archive/item properties that 7-zip can read or write.
Definition bitpropvariant.hpp:32
std::wstring sevenzip_string
The string type used internally by 7-Zip.
Definition bittypes.hpp:69
std::basic_string< tchar > tstring
Definition bittypes.hpp:104
std::chrono::time_point< std::chrono::system_clock > time_type
A type representing a time point measured using the system clock.
Definition bitpropvariant.hpp:27
std::string native_string
Native string type of the system.
Definition bittypes.hpp:80
The BitPropVariant struct is a light extension to the WinAPI PROPVARIANT struct providing useful gett...
Definition bitpropvariant.hpp:161