├── .gitignore
├── LICENSE
├── README.md
├── Samples
├── Bin
│ └── Win32
│ │ ├── Unicode Debug
│ │ └── 7zd.dll
│ │ └── Unicode Release
│ │ └── 7z.dll
└── Simple
│ ├── SevenZip
│ └── include
│ │ ├── 7zString.h
│ │ ├── 7zpp.h
│ │ ├── CompressionFormat.h
│ │ ├── CompressionLevel.h
│ │ ├── Enum.h
│ │ ├── FileInfo.h
│ │ ├── NonCopyable.h
│ │ ├── SevenCryptLibrary.h
│ │ ├── SevenZipCompressor.h
│ │ ├── SevenZipException.h
│ │ ├── SevenZipExtractor.h
│ │ ├── SevenZipHasher.h
│ │ └── SevenZipLibrary.h
│ ├── Simple.cpp
│ ├── Simple.vcxproj
│ ├── Simple.vcxproj.filters
│ └── Simple.vcxproj.user
├── SevenZip++.sln
└── SevenZip++
├── 7zString.h
├── 7zpp.h
├── ArchiveExtractCallback.cpp
├── ArchiveExtractCallback.h
├── ArchiveOpenCallback.cpp
├── ArchiveOpenCallback.h
├── ArchiveUpdateCallback.cpp
├── ArchiveUpdateCallback.h
├── CompressionFormat.h
├── CompressionLevel.h
├── Enum.h
├── FileInfo.h
├── FileSys.cpp
├── FileSys.h
├── GUIDs.cpp
├── GUIDs.h
├── InStreamWrapper.cpp
├── InStreamWrapper.h
├── NonCopyable.h
├── OutStreamWrapper.cpp
├── OutStreamWrapper.h
├── PathScanner.cpp
├── PathScanner.h
├── PropVariant.cpp
├── PropVariant.h
├── SevenCryptLibrary.cpp
├── SevenCryptLibrary.h
├── SevenTask.h
├── SevenThread.cpp
├── SevenThread.h
├── SevenWorkerPool.cpp
├── SevenWorkerPool.h
├── SevenZip++.vcxproj
├── SevenZip++.vcxproj.filters
├── SevenZip++.vcxproj.user
├── SevenZip++2008.vcproj
├── SevenZip++2013.vcxproj
├── SevenZipCompressor.cpp
├── SevenZipCompressor.h
├── SevenZipException.cpp
├── SevenZipException.h
├── SevenZipExtractor.cpp
├── SevenZipExtractor.h
├── SevenZipHasher.cpp
├── SevenZipHasher.h
├── SevenZipLibrary.cpp
├── SevenZipLibrary.h
├── stdafx.cpp
├── stdafx.h
└── targetver.h
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled Object files
2 | *.slo
3 | *.lo
4 | *.o
5 | *.obj
6 |
7 | # Precompiled Headers
8 | *.gch
9 | *.pch
10 |
11 | # Compiled Dynamic libraries
12 | *.so
13 | *.dylib
14 | #*.dll
15 |
16 | # Fortran module files
17 | *.mod
18 |
19 | # Compiled Static libraries
20 | *.lai
21 | *.la
22 | *.a
23 | *.lib
24 |
25 | # Executables
26 | *.exe
27 | *.out
28 | *.app
29 |
30 | # debug infomations
31 | *.pdb
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 | {description}
294 | Copyright (C) {year} {fullname}
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | {signature of Ty Coon}, 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
341 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SevenZip
2 | ## The project is based on [cmcnab](https://bitbucket.org/cmcnab/sevenzip)
3 |
4 | ## 项目简介
5 | 本项目主要是7z sdk的C++封装,方便使用,另外也提供了一些常用的工具函数。
6 |
7 | ## 功能简介
8 | * 对7z sdk的一层C++封装,方便使用
9 | * 文件校验,支持CRC32, CRC64, SHA1, SHA256, MD5等
10 | * 文件(夹)压缩、解压,支持7z, zip, gz等常见格式,具体可参照http://www.7-zip.org/sdk.html
11 |
12 | ## 说明
13 | * 再次感谢[`cmcnab`](https://bitbucket.org/cmcnab/sevenzip)
14 | * 关于7z的编译请参考作者博客http://blog.csdn.net/blueln/article/details/49148669
15 | * 有任何问题可以提issue或者给作者发邮件[lniwn#126.com](mailto:lniwn@126.com)
--------------------------------------------------------------------------------
/Samples/Bin/Win32/Unicode Debug/7zd.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lniwn/SevenZip/edbd25b0dc9aca47cd7bbb4183d16292d64f7d3a/Samples/Bin/Win32/Unicode Debug/7zd.dll
--------------------------------------------------------------------------------
/Samples/Bin/Win32/Unicode Release/7z.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lniwn/SevenZip/edbd25b0dc9aca47cd7bbb4183d16292d64f7d3a/Samples/Bin/Win32/Unicode Release/7z.dll
--------------------------------------------------------------------------------
/Samples/Simple/SevenZip/include/7zString.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 |
4 | #include
5 | #include
6 |
7 |
8 | namespace SevenZip
9 | {
10 | #ifdef _UNICODE
11 | typedef std::wstring TString;
12 | #else
13 | typedef std::string TString;
14 | #endif
15 | }
16 |
--------------------------------------------------------------------------------
/Samples/Simple/SevenZip/include/7zpp.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 |
4 | #include "SevenZipCompressor.h"
5 | #include "SevenZipExtractor.h"
6 | #include "SevenZipHasher.h"
7 |
8 | #ifdef _DEBUG
9 | #ifdef _UNICODE
10 | #pragma comment ( lib, "7zpp_ud.lib" )
11 | #else
12 | #pragma comment ( lib, "7zpp_ad.lib" )
13 | #endif
14 | #else
15 | #ifdef _UNICODE
16 | #pragma comment ( lib, "7zpp_u.lib" )
17 | #else
18 | #pragma comment ( lib, "7zpp_a.lib" )
19 | #endif
20 | #endif
21 |
--------------------------------------------------------------------------------
/Samples/Simple/SevenZip/include/CompressionFormat.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 |
4 | #include "Enum.h"
5 |
6 |
7 | namespace SevenZip
8 | {
9 | struct CompressionFormat
10 | {
11 | enum _Enum
12 | {
13 | Unknown,
14 | SevenZip,
15 | Zip,
16 | GZip,
17 | BZip2,
18 | Rar,
19 | Tar,
20 | Iso,
21 | Cab,
22 | Lzma,
23 | Lzma86
24 | };
25 |
26 | typedef intl::EnumerationDefinitionNoStrings _Definition;
27 | typedef intl::EnumerationValue< _Enum, _Definition, Unknown > _Value;
28 | };
29 |
30 | typedef CompressionFormat::_Value CompressionFormatEnum;
31 | }
32 |
--------------------------------------------------------------------------------
/Samples/Simple/SevenZip/include/CompressionLevel.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 |
4 | #include "Enum.h"
5 |
6 |
7 | namespace SevenZip
8 | {
9 | struct CompressionLevel
10 | {
11 | enum _Enum
12 | {
13 | None,
14 | Fast,
15 | Normal
16 | };
17 |
18 | typedef intl::EnumerationDefinitionNoStrings _Definition;
19 | typedef intl::EnumerationValue< _Enum, _Definition, Normal > _Value;
20 | };
21 |
22 | typedef CompressionLevel::_Value CompressionLevelEnum;
23 | }
24 |
--------------------------------------------------------------------------------
/Samples/Simple/SevenZip/include/Enum.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 |
4 | //
5 | // ###### To create an enum call MyType with string support: ######
6 | //
7 | //// MyType.h
8 | //struct MyType
9 | //{
10 | // enum _Enum
11 | // {
12 | // Unknown,
13 | // Foo,
14 | // Bar
15 | // };
16 | //
17 | // struct _Definition : public EnumerationDefinition< _Enum, _Definition > { static StringValue Strings[]; };
18 | // typedef EnumerationValue< _Enum, _Definition, Unknown > _Value;
19 | //};
20 | //
21 | //typedef MyType::_Value MyTypeEnum;
22 | //
23 | //
24 | //// MyType.cpp
25 | //#include "MyType.h"
26 | //
27 | //MyType::_Definition::StringValue MyType::_Definition::Strings[] =
28 | //{
29 | // { MyType::Foo, _T( "Foo" ) },
30 | // { MyType::Bar, _T( "Bar" ) },
31 | // { MyType::Unknown, NULL }
32 | //};
33 | //
34 | //
35 | // ###### To create an enum call MyType without string support: ######
36 | //
37 | //// MyType.h
38 | //struct MyType
39 | //{
40 | // enum _Enum
41 | // {
42 | // Unknown,
43 | // Foo,
44 | // Bar
45 | // };
46 | //
47 | // typedef EnumerationDefinitionNoStrings _Definition;
48 | // typedef EnumerationValue< _Enum, _Definition, Unknown > _Value;
49 | //};
50 | //
51 | //typedef MyType::_Value MyTypeEnum;
52 | //
53 |
54 |
55 | namespace SevenZip
56 | {
57 | namespace intl
58 | {
59 | template < typename TEnum, class DerivedDef >
60 | struct EnumerationDefinition
61 | {
62 | struct StringValue
63 | {
64 | TEnum value;
65 | const TCHAR* string;
66 | };
67 |
68 | static TEnum Parse( const TString& string, const TEnum defaultValue )
69 | {
70 | const StringValue* it = DerivedDef::Strings;
71 | for (; it->string != NULL; ++it )
72 | {
73 | if ( string.Compare( it->string ) == 0 )
74 | {
75 | return it->value;
76 | }
77 | }
78 | return defaultValue;
79 | }
80 |
81 | static TString Format( const TEnum& value )
82 | {
83 | const StringValue* it = DerivedDef::Strings;
84 | for (; it->string != NULL; ++it )
85 | {
86 | if ( value == it->value )
87 | {
88 | return it->string;
89 | }
90 | }
91 | return TString();
92 | }
93 | };
94 |
95 |
96 | struct EnumerationDefinitionNoStrings {};
97 |
98 |
99 | template < typename TEnum, class TEnumClass, TEnum DefaultValue >
100 | class EnumerationValue
101 | {
102 | private:
103 |
104 | typedef typename EnumerationValue< TEnum, TEnumClass, DefaultValue > ThisClass;
105 |
106 | TEnum m_value;
107 |
108 | public:
109 |
110 | typedef typename TEnum Enum;
111 |
112 | EnumerationValue():
113 | m_value( DefaultValue )
114 | {}
115 |
116 | EnumerationValue( const TEnum& value ):
117 | m_value( value )
118 | {}
119 |
120 | static ThisClass Parse( const TString& string )
121 | {
122 | return ThisClass( TEnumClass::Parse( string, DefaultValue ) );
123 | }
124 |
125 | const TEnum& GetValue() const
126 | {
127 | return m_value;
128 | }
129 |
130 | TString GetString() const
131 | {
132 | return TEnumClass::Format( m_value );
133 | }
134 |
135 | operator TEnum() const
136 | {
137 | return m_value;
138 | }
139 |
140 | ThisClass& operator=( const TEnum& value )
141 | {
142 | m_value = value;
143 | return *this;
144 | }
145 |
146 | bool operator==( const ThisClass& that ) const
147 | {
148 | return that.m_value == m_value;
149 | }
150 |
151 | bool operator!=( const ThisClass& that ) const
152 | {
153 | return !operator==( that );
154 | }
155 |
156 | bool operator==( const TEnum& value ) const
157 | {
158 | return value == m_value;
159 | }
160 |
161 | bool operator!=( const TEnum& value ) const
162 | {
163 | return !operator==( value );
164 | }
165 |
166 | bool operator< ( const ThisClass& that ) const
167 | {
168 | return m_value < that.m_value;
169 | }
170 |
171 | // Bit field members
172 | void AddFlag( const TEnum& value )
173 | {
174 | *reinterpret_cast< int* >( &m_value ) |= static_cast< int >( value );
175 | }
176 |
177 | void RemoveFlag( const TEnum& value )
178 | {
179 | *reinterpret_cast< int* >( &m_value ) &= ~static_cast< int >( value );
180 | }
181 |
182 | bool HasFlag( const TEnum& value ) const
183 | {
184 | return ( m_value & value ) == value;
185 | }
186 |
187 | bool HasAnyFlag( const TEnum& valueCombo ) const
188 | {
189 | return ( m_value & valueCombo ) != 0;
190 | }
191 | };
192 | }
193 | }
194 |
--------------------------------------------------------------------------------
/Samples/Simple/SevenZip/include/FileInfo.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 |
4 | namespace SevenZip
5 | {
6 | namespace intl
7 | {
8 | struct FileInfo
9 | {
10 | TString FileName;
11 | FILETIME LastWriteTime;
12 | FILETIME CreationTime;
13 | FILETIME LastAccessTime;
14 | ULONGLONG Size;
15 | UINT Attributes;
16 | bool IsDirectory;
17 | };
18 |
19 | struct FilePathInfo : public FileInfo
20 | {
21 | TString FilePath;
22 | };
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Samples/Simple/SevenZip/include/NonCopyable.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | namespace SevenZip
4 | {
5 |
6 | class NonCopyable
7 | {
8 | protected:
9 | NonCopyable(){}
10 | ~NonCopyable(){}
11 |
12 | private:
13 | NonCopyable(const NonCopyable&);
14 | NonCopyable(NonCopyable&&);
15 | NonCopyable& operator=(const NonCopyable&);
16 | NonCopyable& operator=(NonCopyable&&);
17 | };
18 | }
--------------------------------------------------------------------------------
/Samples/Simple/SevenZip/include/SevenCryptLibrary.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "SevenZipException.h"
3 |
4 | namespace SevenZip
5 | {
6 | typedef struct
7 | {
8 | ULONG i[2];
9 | ULONG buf[4];
10 | unsigned char in[64];
11 | unsigned char digest[16];
12 | }MD5_CTX;
13 |
14 | class SevenCryptLibrary
15 | {
16 | private:
17 | typedef void (WINAPI *TMD5Init)(MD5_CTX*);
18 | typedef void (WINAPI *TMD5Update)(MD5_CTX*, const void*, unsigned int);
19 | typedef void (WINAPI *TMD5Final)(MD5_CTX*);
20 |
21 | SevenCryptLibrary(const SevenCryptLibrary&);
22 | SevenCryptLibrary& operator=(const SevenCryptLibrary&);
23 |
24 | public:
25 | SevenCryptLibrary(void);
26 | ~SevenCryptLibrary(void);
27 |
28 | void Load();
29 | void Load( const TString& libraryPath );
30 | void Free();
31 |
32 | void MD5Init(MD5_CTX*) const;
33 | void MD5Update(MD5_CTX*, const void*, unsigned int) const;
34 | void MD5Final(MD5_CTX*) const;
35 |
36 | private:
37 | HMODULE m_dll;
38 | TMD5Init m_md5Init;
39 | TMD5Update m_md5Update;
40 | TMD5Final m_md5Final;
41 | };
42 |
43 | }
--------------------------------------------------------------------------------
/Samples/Simple/SevenZip/include/SevenZipCompressor.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 |
4 | #include
5 | #include
6 | #include "SevenZipLibrary.h"
7 | #include "FileInfo.h"
8 | #include "CompressionFormat.h"
9 | #include "CompressionLevel.h"
10 |
11 |
12 | namespace SevenZip
13 | {
14 | class SevenZipCompressor
15 | {
16 | private:
17 |
18 | const SevenZipLibrary& m_library;
19 | TString m_archivePath;
20 | CompressionFormatEnum m_compressionFormat;
21 | CompressionLevelEnum m_compressionLevel;
22 |
23 | public:
24 |
25 | SevenZipCompressor( const SevenZipLibrary& library, const TString& archivePath );
26 | virtual ~SevenZipCompressor();
27 |
28 | void SetCompressionFormat( const CompressionFormatEnum& format );
29 | void SetCompressionLevel( const CompressionLevelEnum& level );
30 |
31 | // Includes the last directory as the root in the archive, e.g. specifying "C:\Temp\MyFolder"
32 | // makes "MyFolder" the single root item in archive with the files within it included.
33 | virtual void CompressDirectory( const TString& directory, bool includeSubdirs = true );
34 |
35 | // Excludes the last directory as the root in the archive, its contents are at root instead. E.g.
36 | // specifying "C:\Temp\MyFolder" make the files in "MyFolder" the root items in the archive.
37 | virtual void CompressFiles( const TString& directory, const TString& searchFilter, bool includeSubdirs = true );
38 | virtual void CompressAllFiles( const TString& directory, bool includeSubdirs = true );
39 |
40 | // Compress just this single file as the root item in the archive.
41 | virtual void CompressFile( const TString& filePath );
42 |
43 | private:
44 |
45 | CComPtr< IStream > OpenArchiveStream();
46 | void FindAndCompressFiles( const TString& directory, const TString& searchPattern, const TString& pathPrefix, bool recursion );
47 | void CompressFilesToArchive( const TString& pathPrefix, const std::vector< intl::FilePathInfo >& filePaths );
48 | void SetCompressionProperties( IUnknown* outArchive );
49 | };
50 | }
51 |
--------------------------------------------------------------------------------
/Samples/Simple/SevenZip/include/SevenZipException.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 |
4 | #include
5 | #include "7zString.h"
6 |
7 |
8 | namespace SevenZip
9 | {
10 | TString StrFmt( const TCHAR* format, ... );
11 | TString GetWinErrMsg( const TString& contextMessage, DWORD lastError );
12 | TString GetCOMErrMsg( const TString& contextMessage, HRESULT lastError );
13 |
14 |
15 | class SevenZipException
16 | {
17 | protected:
18 |
19 | TString m_message;
20 |
21 | public:
22 |
23 | SevenZipException();
24 | SevenZipException( const TString& message );
25 | virtual ~SevenZipException();
26 |
27 | const TString& GetMessage() const;
28 | };
29 | }
30 |
--------------------------------------------------------------------------------
/Samples/Simple/SevenZip/include/SevenZipExtractor.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 |
4 | #include "SevenZipLibrary.h"
5 | #include "CompressionFormat.h"
6 |
7 |
8 | namespace SevenZip
9 | {
10 | class SevenZipExtractor
11 | {
12 | private:
13 |
14 | const SevenZipLibrary& m_library;
15 | TString m_archivePath;
16 | CompressionFormatEnum m_format;
17 |
18 | public:
19 |
20 | SevenZipExtractor( const SevenZipLibrary& library, const TString& archivePath );
21 | virtual ~SevenZipExtractor();
22 |
23 | void SetCompressionFormat( const CompressionFormatEnum& format );
24 |
25 | virtual void ExtractArchive( const TString& directory );
26 |
27 | private:
28 |
29 | void ExtractArchive( const CComPtr< IStream >& archiveStream, const TString& directory );
30 | };
31 | }
32 |
--------------------------------------------------------------------------------
/Samples/Simple/SevenZip/include/SevenZipHasher.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lniwn/SevenZip/edbd25b0dc9aca47cd7bbb4183d16292d64f7d3a/Samples/Simple/SevenZip/include/SevenZipHasher.h
--------------------------------------------------------------------------------
/Samples/Simple/SevenZip/include/SevenZipLibrary.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "SevenZipException.h"
4 |
5 | struct IHashers;
6 | namespace SevenZip
7 | {
8 | class SevenZipLibrary
9 | {
10 | private:
11 | SevenZipLibrary(const SevenZipLibrary&);
12 | SevenZipLibrary& operator=(const SevenZipLibrary&);
13 |
14 | public:
15 | SevenZipLibrary();
16 | ~SevenZipLibrary();
17 |
18 | void Load();
19 | void Load( const TString& libraryPath );
20 | void Free();
21 |
22 | void CreateObject( const GUID& clsID, const GUID& interfaceID, void** outObject ) const;
23 | void GetHashers(IHashers **) const;
24 |
25 | private:
26 |
27 | typedef UINT32 (WINAPI * TCreateObject)( const GUID* clsID, const GUID* interfaceID, void** outObject );
28 | typedef HRESULT (WINAPI *TGetHashers)(IHashers **);
29 |
30 | HMODULE m_dll;
31 | TCreateObject m_func;
32 | TGetHashers m_hashers;
33 | };
34 | }
35 |
--------------------------------------------------------------------------------
/Samples/Simple/Simple.cpp:
--------------------------------------------------------------------------------
1 | #define WIN32_LEAN_AND_MEAN
2 | #include
3 | #include
4 | #include
5 | #include "../../SevenZip++/7zpp.h"
6 | #include
7 |
8 | int PrintUsage()
9 | {
10 | _tprintf(_T("Simple.exe [cx] ...\n"));
11 | _tprintf(_T(" c -- Creates an archive.\n"));
12 | _tprintf(_T(" x -- Extracts an archive.\n"));
13 | _tprintf(_T(" h -- Hashes files in directory.\n\n"));
14 | return 0;
15 | }
16 |
17 |
18 | int CreateArchive(int argc, TCHAR** argv)
19 | {
20 | if (argc < 4)
21 | {
22 | return PrintUsage();
23 | }
24 |
25 | const TCHAR* archiveName = argv[2];
26 | const TCHAR* targetDir = argv[3];
27 |
28 | // Note I'm lazily assuming the target is a directory rather than a file.
29 |
30 | SevenZip::SevenZipLibrary lib;
31 | #ifdef _DEBUG
32 | lib.Load(_T("7zd.dll"));
33 | #else
34 | lib.Load(_T("7z.dll"));
35 | #endif // _DEBUG
36 |
37 | SevenZip::SevenZipCompressor compressor(lib, archiveName);
38 | compressor.CompressDirectory(targetDir);
39 |
40 | return 0;
41 | }
42 |
43 | void PrintFileHash(const SevenZip::TString& file_path, const std::string& hash_value)
44 | {
45 | _tprintf(_T("%s --> %S\n"), file_path.c_str(), hash_value.c_str());
46 | }
47 |
48 | int HashFiles(int argc, TCHAR** argv)
49 | {
50 | if (argc < 4)
51 | {
52 | return PrintUsage();
53 | }
54 | const TCHAR* targetDir = argv[2];
55 | const TCHAR* pattern = argv[3];
56 |
57 | SevenZip::SevenZipLibrary lib;
58 | #ifdef _DEBUG
59 | lib.Load(_T("7zd.dll"));
60 | #else
61 | lib.Load(_T("7z.dll"));
62 | #endif // _DEBUG
63 |
64 | SevenZip::SevenCryptLibrary crypt_lib;
65 | crypt_lib.Load();
66 | SevenZip::SevenZipHasher hasherlib(lib, crypt_lib);
67 |
68 | hasherlib.FilesMd5(targetDir, pattern, PrintFileHash);
69 | system("pause");
70 | _tprintf(_T("\n"));
71 |
72 | return 0;
73 | }
74 |
75 | int ExtractArchive(int argc, TCHAR** argv)
76 | {
77 | if (argc < 4)
78 | {
79 | return PrintUsage();
80 | }
81 |
82 | const TCHAR* archiveName = argv[2];
83 | const TCHAR* destination = argv[3];
84 |
85 | SevenZip::SevenZipLibrary lib;
86 | #ifdef _DEBUG
87 | lib.Load(_T("7zd.dll"));
88 | #else
89 | lib.Load(_T("7z.dll"));
90 | #endif // _DEBUG
91 |
92 | SevenZip::SevenZipExtractor extractor(lib, archiveName);
93 | extractor.ExtractArchive(destination);
94 | return 0;
95 | }
96 |
97 | int _tmain(int argc, _TCHAR* argv[])
98 | {
99 | if (argc < 4)
100 | {
101 | return PrintUsage();
102 | }
103 |
104 | try
105 | {
106 | switch (argv[1][0])
107 | {
108 | case _T('c'):
109 | return CreateArchive(argc, argv);
110 | case _T('x'):
111 | return ExtractArchive(argc, argv);
112 | case _T('h'):
113 | return HashFiles(argc, argv);
114 | default:
115 | break;
116 | }
117 | }
118 | catch (SevenZip::SevenZipException& ex)
119 | {
120 | _tprintf(_T("Error: %s\n"), ex.GetMessage().c_str());
121 | }
122 |
123 | return PrintUsage();
124 | }
125 |
--------------------------------------------------------------------------------
/Samples/Simple/Simple.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | MBCS Debug
6 | Win32
7 |
8 |
9 | MBCS Debug
10 | x64
11 |
12 |
13 | MBCS Release
14 | Win32
15 |
16 |
17 | MBCS Release
18 | x64
19 |
20 |
21 | Unicode Debug
22 | Win32
23 |
24 |
25 | Unicode Debug
26 | x64
27 |
28 |
29 | Unicode Release
30 | Win32
31 |
32 |
33 | Unicode Release
34 | x64
35 |
36 |
37 |
38 | {6D212837-5A8C-4139-A1F2-BD62B1523F08}
39 | Win32Proj
40 | Simple
41 |
42 |
43 |
44 | Application
45 | true
46 | Unicode
47 | v100
48 |
49 |
50 | Application
51 | true
52 | MultiByte
53 | v140
54 |
55 |
56 | Application
57 | true
58 | Unicode
59 | v140
60 |
61 |
62 | Application
63 | true
64 | MultiByte
65 | v140
66 |
67 |
68 | Application
69 | false
70 | true
71 | Unicode
72 | v100
73 |
74 |
75 | Application
76 | false
77 | true
78 | MultiByte
79 | v140
80 |
81 |
82 | Application
83 | false
84 | true
85 | Unicode
86 | v140
87 |
88 |
89 | Application
90 | false
91 | true
92 | MultiByte
93 | v140
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 | true
125 | $(SolutionDir)Samples\Bin\$(Platform)\$(Configuration)\
126 | $(Platform)\$(Configuration)\
127 | D:\sdk\7z1506-src\CPP;$(IncludePath)
128 | ..\Build\Win32\Lib;$(VCInstallDir)lib;$(VCInstallDir)atlmfc\lib;$(WindowsSdkDir)lib;$(FrameworkSDKDir)\lib
129 |
130 |
131 | true
132 | $(SolutionDir)Samples\Bin\$(Platform)\$(Configuration)\
133 | $(Platform)\$(Configuration)\
134 |
135 |
136 | true
137 | $(SolutionDir)Samples\Bin\$(Platform)\$(Configuration)\
138 |
139 |
140 | true
141 | $(SolutionDir)Samples\Bin\$(Platform)\$(Configuration)\
142 |
143 |
144 | false
145 | $(SolutionDir)Samples\Bin\$(Platform)\$(Configuration)\
146 | $(Platform)\$(Configuration)\
147 | D:\sdk\7z1506-src\CPP;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSdkDir)include;$(FrameworkSDKDir)\include;
148 | ..\Build\Win32\Lib;$(VCInstallDir)lib;$(VCInstallDir)atlmfc\lib;$(WindowsSdkDir)lib;$(FrameworkSDKDir)\lib
149 |
150 |
151 | false
152 | $(SolutionDir)Samples\Bin\$(Platform)\$(Configuration)\
153 | $(Platform)\$(Configuration)\
154 |
155 |
156 | false
157 | $(SolutionDir)Samples\Bin\$(Platform)\$(Configuration)\
158 |
159 |
160 | false
161 | $(SolutionDir)Samples\Bin\$(Platform)\$(Configuration)\
162 |
163 |
164 |
165 | NotUsing
166 | Level3
167 | Disabled
168 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
169 |
170 |
171 | Console
172 | true
173 | %(AdditionalDependencies)
174 | ..\..\Build\$(Platform)\Lib;%(AdditionalLibraryDirectories)
175 |
176 |
177 |
178 |
179 | NotUsing
180 | Level3
181 | Disabled
182 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
183 |
184 |
185 | Console
186 | true
187 | %(AdditionalDependencies)
188 | ..\..\Build\$(Platform)\Lib;%(AdditionalLibraryDirectories)
189 |
190 |
191 |
192 |
193 | NotUsing
194 | Level3
195 | Disabled
196 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
197 |
198 |
199 | Console
200 | true
201 | %(AdditionalDependencies)
202 | ..\..\Build\$(Platform)\Lib;%(AdditionalLibraryDirectories)
203 |
204 |
205 |
206 |
207 | NotUsing
208 | Level3
209 | Disabled
210 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
211 |
212 |
213 | Console
214 | true
215 | %(AdditionalDependencies)
216 | ..\..\Build\$(Platform)\Lib;%(AdditionalLibraryDirectories)
217 |
218 |
219 |
220 |
221 | Level3
222 | NotUsing
223 | MaxSpeed
224 | true
225 | true
226 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
227 |
228 |
229 | Console
230 | true
231 | true
232 | true
233 | %(AdditionalDependencies)
234 | ..\..\Build\$(Platform)\Lib;%(AdditionalLibraryDirectories)
235 |
236 |
237 |
238 |
239 | Level3
240 | NotUsing
241 | MaxSpeed
242 | true
243 | true
244 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
245 |
246 |
247 | Console
248 | true
249 | true
250 | true
251 | %(AdditionalDependencies)
252 | ..\..\Build\$(Platform)\Lib;%(AdditionalLibraryDirectories)
253 |
254 |
255 |
256 |
257 | Level3
258 | NotUsing
259 | MaxSpeed
260 | true
261 | true
262 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
263 |
264 |
265 | Console
266 | true
267 | true
268 | true
269 | %(AdditionalDependencies)
270 | ..\..\Build\$(Platform)\Lib;%(AdditionalLibraryDirectories)
271 |
272 |
273 |
274 |
275 | Level3
276 | NotUsing
277 | MaxSpeed
278 | true
279 | true
280 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
281 |
282 |
283 | Console
284 | true
285 | true
286 | true
287 | %(AdditionalDependencies)
288 | ..\..\Build\$(Platform)\Lib;%(AdditionalLibraryDirectories)
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
--------------------------------------------------------------------------------
/Samples/Simple/Simple.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Samples/Simple/Simple.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ..\Bin\Win32\Unicode Debug
5 | WindowsLocalDebugger
6 | h "E:\git\explorerplusplus\Explorer++" *.*
7 |
8 |
9 | ..\Bin\Win32\Unicode Release
10 | WindowsLocalDebugger
11 | h D:\test\gshx *.*
12 |
13 |
--------------------------------------------------------------------------------
/SevenZip++.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 11.00
3 | # Visual Studio 2010
4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SevenZip++", "SevenZip++\SevenZip++.vcxproj", "{F7380108-3CF4-427B-A89F-9CD64BB7836A}"
5 | EndProject
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Simple", "Samples\Simple\Simple.vcxproj", "{6D212837-5A8C-4139-A1F2-BD62B1523F08}"
7 | ProjectSection(ProjectDependencies) = postProject
8 | {F7380108-3CF4-427B-A89F-9CD64BB7836A} = {F7380108-3CF4-427B-A89F-9CD64BB7836A}
9 | EndProjectSection
10 | EndProject
11 | Global
12 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
13 | MBCS Debug|Win32 = MBCS Debug|Win32
14 | MBCS Debug|x64 = MBCS Debug|x64
15 | MBCS Release|Win32 = MBCS Release|Win32
16 | MBCS Release|x64 = MBCS Release|x64
17 | Unicode Debug|Win32 = Unicode Debug|Win32
18 | Unicode Debug|x64 = Unicode Debug|x64
19 | Unicode Release|Win32 = Unicode Release|Win32
20 | Unicode Release|x64 = Unicode Release|x64
21 | EndGlobalSection
22 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
23 | {F7380108-3CF4-427B-A89F-9CD64BB7836A}.MBCS Debug|Win32.ActiveCfg = MBCS Debug|Win32
24 | {F7380108-3CF4-427B-A89F-9CD64BB7836A}.MBCS Debug|Win32.Build.0 = MBCS Debug|Win32
25 | {F7380108-3CF4-427B-A89F-9CD64BB7836A}.MBCS Debug|x64.ActiveCfg = MBCS Debug|x64
26 | {F7380108-3CF4-427B-A89F-9CD64BB7836A}.MBCS Debug|x64.Build.0 = MBCS Debug|x64
27 | {F7380108-3CF4-427B-A89F-9CD64BB7836A}.MBCS Release|Win32.ActiveCfg = MBCS Release|Win32
28 | {F7380108-3CF4-427B-A89F-9CD64BB7836A}.MBCS Release|Win32.Build.0 = MBCS Release|Win32
29 | {F7380108-3CF4-427B-A89F-9CD64BB7836A}.MBCS Release|x64.ActiveCfg = MBCS Release|x64
30 | {F7380108-3CF4-427B-A89F-9CD64BB7836A}.MBCS Release|x64.Build.0 = MBCS Release|x64
31 | {F7380108-3CF4-427B-A89F-9CD64BB7836A}.Unicode Debug|Win32.ActiveCfg = Unicode Debug|Win32
32 | {F7380108-3CF4-427B-A89F-9CD64BB7836A}.Unicode Debug|Win32.Build.0 = Unicode Debug|Win32
33 | {F7380108-3CF4-427B-A89F-9CD64BB7836A}.Unicode Debug|x64.ActiveCfg = Unicode Debug|x64
34 | {F7380108-3CF4-427B-A89F-9CD64BB7836A}.Unicode Debug|x64.Build.0 = Unicode Debug|x64
35 | {F7380108-3CF4-427B-A89F-9CD64BB7836A}.Unicode Release|Win32.ActiveCfg = Unicode Release|Win32
36 | {F7380108-3CF4-427B-A89F-9CD64BB7836A}.Unicode Release|Win32.Build.0 = Unicode Release|Win32
37 | {F7380108-3CF4-427B-A89F-9CD64BB7836A}.Unicode Release|x64.ActiveCfg = Unicode Release|x64
38 | {F7380108-3CF4-427B-A89F-9CD64BB7836A}.Unicode Release|x64.Build.0 = Unicode Release|x64
39 | {6D212837-5A8C-4139-A1F2-BD62B1523F08}.MBCS Debug|Win32.ActiveCfg = MBCS Debug|Win32
40 | {6D212837-5A8C-4139-A1F2-BD62B1523F08}.MBCS Debug|Win32.Build.0 = MBCS Debug|Win32
41 | {6D212837-5A8C-4139-A1F2-BD62B1523F08}.MBCS Debug|x64.ActiveCfg = MBCS Debug|x64
42 | {6D212837-5A8C-4139-A1F2-BD62B1523F08}.MBCS Debug|x64.Build.0 = MBCS Debug|x64
43 | {6D212837-5A8C-4139-A1F2-BD62B1523F08}.MBCS Release|Win32.ActiveCfg = MBCS Release|Win32
44 | {6D212837-5A8C-4139-A1F2-BD62B1523F08}.MBCS Release|Win32.Build.0 = MBCS Release|Win32
45 | {6D212837-5A8C-4139-A1F2-BD62B1523F08}.MBCS Release|x64.ActiveCfg = MBCS Release|x64
46 | {6D212837-5A8C-4139-A1F2-BD62B1523F08}.MBCS Release|x64.Build.0 = MBCS Release|x64
47 | {6D212837-5A8C-4139-A1F2-BD62B1523F08}.Unicode Debug|Win32.ActiveCfg = Unicode Debug|Win32
48 | {6D212837-5A8C-4139-A1F2-BD62B1523F08}.Unicode Debug|Win32.Build.0 = Unicode Debug|Win32
49 | {6D212837-5A8C-4139-A1F2-BD62B1523F08}.Unicode Debug|x64.ActiveCfg = Unicode Debug|x64
50 | {6D212837-5A8C-4139-A1F2-BD62B1523F08}.Unicode Debug|x64.Build.0 = Unicode Debug|x64
51 | {6D212837-5A8C-4139-A1F2-BD62B1523F08}.Unicode Release|Win32.ActiveCfg = Unicode Release|Win32
52 | {6D212837-5A8C-4139-A1F2-BD62B1523F08}.Unicode Release|Win32.Build.0 = Unicode Release|Win32
53 | {6D212837-5A8C-4139-A1F2-BD62B1523F08}.Unicode Release|x64.ActiveCfg = Unicode Release|x64
54 | {6D212837-5A8C-4139-A1F2-BD62B1523F08}.Unicode Release|x64.Build.0 = Unicode Release|x64
55 | EndGlobalSection
56 | GlobalSection(SolutionProperties) = preSolution
57 | HideSolutionNode = FALSE
58 | EndGlobalSection
59 | EndGlobal
60 |
--------------------------------------------------------------------------------
/SevenZip++/7zString.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 |
4 | #include
5 | #include
6 |
7 |
8 | namespace SevenZip
9 | {
10 | #ifdef _UNICODE
11 | typedef std::wstring TString;
12 | #else
13 | typedef std::string TString;
14 | #endif
15 | }
16 |
--------------------------------------------------------------------------------
/SevenZip++/7zpp.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 |
4 | #include "SevenZipCompressor.h"
5 | #include "SevenZipExtractor.h"
6 | #include "SevenZipHasher.h"
7 |
8 | #ifdef _DEBUG
9 | #ifdef _UNICODE
10 | #pragma comment ( lib, "7zpp_ud.lib" )
11 | #else
12 | #pragma comment ( lib, "7zpp_ad.lib" )
13 | #endif
14 | #else
15 | #ifdef _UNICODE
16 | #pragma comment ( lib, "7zpp_u.lib" )
17 | #else
18 | #pragma comment ( lib, "7zpp_a.lib" )
19 | #endif
20 | #endif
21 |
--------------------------------------------------------------------------------
/SevenZip++/ArchiveExtractCallback.cpp:
--------------------------------------------------------------------------------
1 | // This file is based on the following file from the LZMA SDK (http://www.7-zip.org/sdk.html):
2 | // ./CPP/7zip/UI/Client7z/Client7z.cpp
3 | #include "StdAfx.h"
4 | #include "ArchiveExtractCallback.h"
5 | #include "PropVariant.h"
6 | #include "FileSys.h"
7 | #include "OutStreamWrapper.h"
8 | #include
9 |
10 |
11 | namespace SevenZip
12 | {
13 | namespace intl
14 | {
15 |
16 | const TString EmptyFileAlias = _T( "[Content]" );
17 |
18 |
19 | ArchiveExtractCallback::ArchiveExtractCallback( const CComPtr< IInArchive >& archiveHandler, const TString& directory )
20 | : m_refCount( 0 )
21 | , m_archiveHandler( archiveHandler )
22 | , m_directory( directory )
23 | {
24 | }
25 |
26 | ArchiveExtractCallback::~ArchiveExtractCallback()
27 | {
28 | }
29 |
30 | STDMETHODIMP ArchiveExtractCallback::QueryInterface( REFIID iid, void** ppvObject )
31 | {
32 | if ( iid == __uuidof( IUnknown ) )
33 | {
34 | *ppvObject = reinterpret_cast< IUnknown* >( this );
35 | AddRef();
36 | return S_OK;
37 | }
38 |
39 | if ( iid == IID_IArchiveExtractCallback )
40 | {
41 | *ppvObject = static_cast< IArchiveExtractCallback* >( this );
42 | AddRef();
43 | return S_OK;
44 | }
45 |
46 | if ( iid == IID_ICryptoGetTextPassword )
47 | {
48 | *ppvObject = static_cast< ICryptoGetTextPassword* >( this );
49 | AddRef();
50 | return S_OK;
51 | }
52 |
53 | return E_NOINTERFACE;
54 | }
55 |
56 | STDMETHODIMP_(ULONG) ArchiveExtractCallback::AddRef()
57 | {
58 | return static_cast< ULONG >( InterlockedIncrement( &m_refCount ) );
59 | }
60 |
61 | STDMETHODIMP_(ULONG) ArchiveExtractCallback::Release()
62 | {
63 | ULONG res = static_cast< ULONG >( InterlockedDecrement( &m_refCount ) );
64 | if ( res == 0 )
65 | {
66 | delete this;
67 | }
68 | return res;
69 | }
70 |
71 | STDMETHODIMP ArchiveExtractCallback::SetTotal( UInt64 size )
72 | {
73 | return S_OK;
74 | }
75 |
76 | STDMETHODIMP ArchiveExtractCallback::SetCompleted( const UInt64* completeValue )
77 | {
78 | return S_OK;
79 | }
80 |
81 | STDMETHODIMP ArchiveExtractCallback::GetStream( UInt32 index, ISequentialOutStream** outStream, Int32 askExtractMode )
82 | {
83 | try
84 | {
85 | // Retrieve all the various properties for the file at this index.
86 | GetPropertyFilePath( index );
87 | if ( askExtractMode != NArchive::NExtract::NAskMode::kExtract )
88 | {
89 | return S_OK;
90 | }
91 |
92 | GetPropertyAttributes( index );
93 | GetPropertyIsDir( index );
94 | GetPropertyModifiedTime( index );
95 | GetPropertySize( index );
96 | }
97 | catch ( _com_error& ex )
98 | {
99 | return ex.Error();
100 | }
101 |
102 | // TODO: m_directory could be a relative path
103 | m_absPath = FileSys::AppendPath( m_directory, m_relPath );
104 |
105 | if ( m_isDir )
106 | {
107 | // Creating the directory here supports having empty directories.
108 | FileSys::CreateDirectoryTree( m_absPath );
109 | *outStream = NULL;
110 | return S_OK;
111 | }
112 |
113 | TString absDir = FileSys::GetPath( m_absPath );
114 | FileSys::CreateDirectoryTree( absDir );
115 |
116 | CComPtr< IStream > fileStream = FileSys::OpenFileToWrite( m_absPath );
117 | if ( fileStream == NULL )
118 | {
119 | m_absPath.clear();
120 | return HRESULT_FROM_WIN32( GetLastError() );
121 | }
122 |
123 | CComPtr< OutStreamWrapper > wrapperStream = new OutStreamWrapper( fileStream );
124 | *outStream = wrapperStream.Detach();
125 |
126 | return S_OK;
127 | }
128 |
129 | STDMETHODIMP ArchiveExtractCallback::PrepareOperation( Int32 askExtractMode )
130 | {
131 | return S_OK;
132 | }
133 |
134 | STDMETHODIMP ArchiveExtractCallback::SetOperationResult( Int32 operationResult )
135 | {
136 | if ( m_absPath.empty() )
137 | {
138 | return S_OK;
139 | }
140 |
141 | if ( m_hasModifiedTime )
142 | {
143 | HANDLE fileHandle = CreateFile( m_absPath.c_str(), GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
144 | if ( fileHandle != INVALID_HANDLE_VALUE )
145 | {
146 | SetFileTime( fileHandle, NULL, NULL, &m_modifiedTime );
147 | CloseHandle( fileHandle );
148 | }
149 | }
150 |
151 | if ( m_hasAttrib )
152 | {
153 | SetFileAttributes( m_absPath.c_str(), m_attrib );
154 | }
155 |
156 | return S_OK;
157 | }
158 |
159 | STDMETHODIMP ArchiveExtractCallback::CryptoGetTextPassword( BSTR* password )
160 | {
161 | // TODO: support passwords
162 | return E_ABORT;
163 | }
164 |
165 | void ArchiveExtractCallback::GetPropertyFilePath( UInt32 index )
166 | {
167 | CPropVariant prop;
168 | HRESULT hr = m_archiveHandler->GetProperty( index, kpidPath, &prop );
169 | if ( hr != S_OK )
170 | {
171 | _com_issue_error( hr );
172 | }
173 |
174 | if ( prop.vt == VT_EMPTY )
175 | {
176 | m_relPath = EmptyFileAlias;
177 | }
178 | else if ( prop.vt != VT_BSTR )
179 | {
180 | _com_issue_error( E_FAIL );
181 | }
182 | else
183 | {
184 | _bstr_t bstr = prop.bstrVal;
185 | #ifdef _UNICODE
186 | m_relPath = bstr;
187 | #else
188 | char relPath[MAX_PATH];
189 | int size = WideCharToMultiByte( CP_UTF8, 0, bstr, bstr.length(), relPath, MAX_PATH, NULL, NULL );
190 | m_relPath.assign( relPath, size );
191 | #endif
192 | }
193 | }
194 |
195 | void ArchiveExtractCallback::GetPropertyAttributes( UInt32 index )
196 | {
197 | CPropVariant prop;
198 | HRESULT hr = m_archiveHandler->GetProperty( index, kpidAttrib, &prop );
199 | if ( hr != S_OK )
200 | {
201 | _com_issue_error( hr );
202 | }
203 |
204 | if ( prop.vt == VT_EMPTY )
205 | {
206 | m_attrib = 0;
207 | m_hasAttrib = false;
208 | }
209 | else if ( prop.vt != VT_UI4 )
210 | {
211 | _com_issue_error( E_FAIL );
212 | }
213 | else
214 | {
215 | m_attrib = prop.ulVal;
216 | m_hasAttrib = true;
217 | }
218 | }
219 |
220 | void ArchiveExtractCallback::GetPropertyIsDir( UInt32 index )
221 | {
222 | CPropVariant prop;
223 | HRESULT hr = m_archiveHandler->GetProperty( index, kpidIsDir, &prop );
224 | if ( hr != S_OK )
225 | {
226 | _com_issue_error( hr );
227 | }
228 |
229 | if ( prop.vt == VT_EMPTY )
230 | {
231 | m_isDir = false;
232 | }
233 | else if ( prop.vt != VT_BOOL )
234 | {
235 | _com_issue_error( E_FAIL );
236 | }
237 | else
238 | {
239 | m_isDir = prop.boolVal != VARIANT_FALSE;
240 | }
241 | }
242 |
243 | void ArchiveExtractCallback::GetPropertyModifiedTime( UInt32 index )
244 | {
245 | CPropVariant prop;
246 | HRESULT hr = m_archiveHandler->GetProperty( index, kpidMTime, &prop );
247 | if ( hr != S_OK )
248 | {
249 | _com_issue_error( hr );
250 | }
251 |
252 | if ( prop.vt == VT_EMPTY )
253 | {
254 | m_hasModifiedTime = false;
255 | }
256 | else if ( prop.vt != VT_FILETIME )
257 | {
258 | _com_issue_error( E_FAIL );
259 | }
260 | else
261 | {
262 | m_modifiedTime = prop.filetime;
263 | m_hasModifiedTime = true;
264 | }
265 | }
266 |
267 | void ArchiveExtractCallback::GetPropertySize( UInt32 index )
268 | {
269 | CPropVariant prop;
270 | HRESULT hr = m_archiveHandler->GetProperty( index, kpidSize, &prop );
271 | if ( hr != S_OK )
272 | {
273 | _com_issue_error( hr );
274 | }
275 |
276 | switch ( prop.vt )
277 | {
278 | case VT_EMPTY:
279 | m_hasNewFileSize = false;
280 | return;
281 | case VT_UI1:
282 | m_newFileSize = prop.bVal;
283 | break;
284 | case VT_UI2:
285 | m_newFileSize = prop.uiVal;
286 | break;
287 | case VT_UI4:
288 | m_newFileSize = prop.ulVal;
289 | break;
290 | case VT_UI8:
291 | m_newFileSize = (UInt64)prop.uhVal.QuadPart;
292 | break;
293 | default:
294 | _com_issue_error( E_FAIL );
295 | }
296 |
297 | m_hasNewFileSize = true;
298 | }
299 |
300 | }
301 | }
302 |
--------------------------------------------------------------------------------
/SevenZip++/ArchiveExtractCallback.h:
--------------------------------------------------------------------------------
1 | // This file is based on the following file from the LZMA SDK (http://www.7-zip.org/sdk.html):
2 | // ./CPP/7zip/UI/Client7z/Client7z.cpp
3 | #pragma once
4 |
5 |
6 | #include <7zip/Archive/IArchive.h>
7 | #include <7zip/IPassword.h>
8 |
9 |
10 | namespace SevenZip
11 | {
12 | namespace intl
13 | {
14 | class ArchiveExtractCallback : public IArchiveExtractCallback, public ICryptoGetTextPassword
15 | {
16 | private:
17 |
18 | long m_refCount;
19 | CComPtr< IInArchive > m_archiveHandler;
20 | TString m_directory;
21 |
22 | TString m_relPath;
23 | TString m_absPath;
24 | bool m_isDir;
25 |
26 | bool m_hasAttrib;
27 | UInt32 m_attrib;
28 |
29 | bool m_hasModifiedTime;
30 | FILETIME m_modifiedTime;
31 |
32 | bool m_hasNewFileSize;
33 | UInt64 m_newFileSize;
34 |
35 | public:
36 |
37 | ArchiveExtractCallback( const CComPtr< IInArchive >& archiveHandler, const TString& directory );
38 | virtual ~ArchiveExtractCallback();
39 |
40 | STDMETHOD(QueryInterface)( REFIID iid, void** ppvObject );
41 | STDMETHOD_(ULONG, AddRef)();
42 | STDMETHOD_(ULONG, Release)();
43 |
44 | // IProgress
45 | STDMETHOD(SetTotal)( UInt64 size );
46 | STDMETHOD(SetCompleted)( const UInt64* completeValue );
47 |
48 | // IArchiveExtractCallback
49 | STDMETHOD(GetStream)( UInt32 index, ISequentialOutStream** outStream, Int32 askExtractMode );
50 | STDMETHOD(PrepareOperation)( Int32 askExtractMode );
51 | STDMETHOD(SetOperationResult)( Int32 resultEOperationResult );
52 |
53 | // ICryptoGetTextPassword
54 | STDMETHOD(CryptoGetTextPassword)( BSTR* password );
55 |
56 | private:
57 |
58 | void GetPropertyFilePath( UInt32 index );
59 | void GetPropertyAttributes( UInt32 index );
60 | void GetPropertyIsDir( UInt32 index );
61 | void GetPropertyModifiedTime( UInt32 index );
62 | void GetPropertySize( UInt32 index );
63 | };
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/SevenZip++/ArchiveOpenCallback.cpp:
--------------------------------------------------------------------------------
1 | // This file is based on the following file from the LZMA SDK (http://www.7-zip.org/sdk.html):
2 | // ./CPP/7zip/UI/Client7z/Client7z.cpp
3 | #include "StdAfx.h"
4 | #include "ArchiveOpenCallback.h"
5 |
6 |
7 | namespace SevenZip
8 | {
9 | namespace intl
10 | {
11 |
12 | ArchiveOpenCallback::ArchiveOpenCallback()
13 | : m_refCount( 0 )
14 | {
15 | }
16 |
17 | ArchiveOpenCallback::~ArchiveOpenCallback()
18 | {
19 | }
20 |
21 | STDMETHODIMP ArchiveOpenCallback::QueryInterface( REFIID iid, void** ppvObject )
22 | {
23 | if ( iid == __uuidof( IUnknown ) )
24 | {
25 | *ppvObject = reinterpret_cast< IUnknown* >( this );
26 | AddRef();
27 | return S_OK;
28 | }
29 |
30 | if ( iid == IID_IArchiveOpenCallback )
31 | {
32 | *ppvObject = static_cast< IArchiveOpenCallback* >( this );
33 | AddRef();
34 | return S_OK;
35 | }
36 |
37 | if ( iid == IID_ICryptoGetTextPassword )
38 | {
39 | *ppvObject = static_cast< ICryptoGetTextPassword* >( this );
40 | AddRef();
41 | return S_OK;
42 | }
43 |
44 | return E_NOINTERFACE;
45 | }
46 |
47 | STDMETHODIMP_(ULONG) ArchiveOpenCallback::AddRef()
48 | {
49 | return static_cast< ULONG >( InterlockedIncrement( &m_refCount ) );
50 | }
51 |
52 | STDMETHODIMP_(ULONG) ArchiveOpenCallback::Release()
53 | {
54 | ULONG res = static_cast< ULONG >( InterlockedDecrement( &m_refCount ) );
55 | if ( res == 0 )
56 | {
57 | delete this;
58 | }
59 | return res;
60 | }
61 |
62 | STDMETHODIMP ArchiveOpenCallback::SetTotal( const UInt64* files, const UInt64* bytes )
63 | {
64 | return S_OK;
65 | }
66 |
67 | STDMETHODIMP ArchiveOpenCallback::SetCompleted( const UInt64* files, const UInt64* bytes )
68 | {
69 | return S_OK;
70 | }
71 |
72 | STDMETHODIMP ArchiveOpenCallback::CryptoGetTextPassword( BSTR* password )
73 | {
74 | // TODO: support passwords
75 | return E_ABORT;
76 | }
77 |
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/SevenZip++/ArchiveOpenCallback.h:
--------------------------------------------------------------------------------
1 | // This file is based on the following file from the LZMA SDK (http://www.7-zip.org/sdk.html):
2 | // ./CPP/7zip/UI/Client7z/Client7z.cpp
3 | #pragma once
4 |
5 |
6 | #include <7zip/Archive/IArchive.h>
7 | #include <7zip/IPassword.h>
8 |
9 |
10 | namespace SevenZip
11 | {
12 | namespace intl
13 | {
14 | class ArchiveOpenCallback : public IArchiveOpenCallback, public ICryptoGetTextPassword
15 | {
16 | private:
17 |
18 | long m_refCount;
19 |
20 | public:
21 |
22 | ArchiveOpenCallback();
23 | virtual ~ArchiveOpenCallback();
24 |
25 | STDMETHOD(QueryInterface)( REFIID iid, void** ppvObject );
26 | STDMETHOD_(ULONG, AddRef)();
27 | STDMETHOD_(ULONG, Release)();
28 |
29 | // IArchiveOpenCallback
30 | STDMETHOD(SetTotal)( const UInt64* files, const UInt64* bytes );
31 | STDMETHOD(SetCompleted)( const UInt64* files, const UInt64* bytes );
32 |
33 | // ICryptoGetTextPassword
34 | STDMETHOD(CryptoGetTextPassword)( BSTR* password );
35 | };
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/SevenZip++/ArchiveUpdateCallback.cpp:
--------------------------------------------------------------------------------
1 | // This file is based on the following file from the LZMA SDK (http://www.7-zip.org/sdk.html):
2 | // ./CPP/7zip/UI/Client7z/Client7z.cpp
3 | #include "StdAfx.h"
4 | #include "ArchiveUpdateCallback.h"
5 | #include "PropVariant.h"
6 | #include "FileSys.h"
7 | #include "InStreamWrapper.h"
8 |
9 |
10 | namespace SevenZip
11 | {
12 | namespace intl
13 | {
14 |
15 | ArchiveUpdateCallback::ArchiveUpdateCallback( const TString& dirPrefix, const std::vector< FilePathInfo >& filePaths )
16 | : m_refCount( 0 )
17 | , m_dirPrefix( dirPrefix )
18 | , m_filePaths( filePaths )
19 | {
20 | }
21 |
22 | ArchiveUpdateCallback::~ArchiveUpdateCallback()
23 | {
24 | }
25 |
26 | STDMETHODIMP ArchiveUpdateCallback::QueryInterface( REFIID iid, void** ppvObject )
27 | {
28 | if ( iid == __uuidof( IUnknown ) )
29 | {
30 | *ppvObject = reinterpret_cast< IUnknown* >( this );
31 | AddRef();
32 | return S_OK;
33 | }
34 |
35 | if ( iid == IID_IArchiveUpdateCallback )
36 | {
37 | *ppvObject = static_cast< IArchiveUpdateCallback* >( this );
38 | AddRef();
39 | return S_OK;
40 | }
41 |
42 | if ( iid == IID_ICryptoGetTextPassword2 )
43 | {
44 | *ppvObject = static_cast< ICryptoGetTextPassword2* >( this );
45 | AddRef();
46 | return S_OK;
47 | }
48 |
49 | if ( iid == IID_ICompressProgressInfo )
50 | {
51 | *ppvObject = static_cast< ICompressProgressInfo* >( this );
52 | AddRef();
53 | return S_OK;
54 | }
55 |
56 | return E_NOINTERFACE;
57 | }
58 |
59 | STDMETHODIMP_(ULONG) ArchiveUpdateCallback::AddRef()
60 | {
61 | return static_cast< ULONG >( InterlockedIncrement( &m_refCount ) );
62 | }
63 |
64 | STDMETHODIMP_(ULONG) ArchiveUpdateCallback::Release()
65 | {
66 | ULONG res = static_cast< ULONG >( InterlockedDecrement( &m_refCount ) );
67 | if ( res == 0 )
68 | {
69 | delete this;
70 | }
71 | return res;
72 | }
73 |
74 | STDMETHODIMP ArchiveUpdateCallback::SetTotal( UInt64 size )
75 | {
76 | return S_OK;
77 | }
78 |
79 | STDMETHODIMP ArchiveUpdateCallback::SetCompleted( const UInt64* completeValue )
80 | {
81 | return S_OK;
82 | }
83 |
84 | STDMETHODIMP ArchiveUpdateCallback::GetUpdateItemInfo( UInt32 index, Int32* newData, Int32* newProperties, UInt32* indexInArchive )
85 | {
86 | // Setting info for Create mode (vs. Append mode).
87 | // TODO: support append mode
88 | if ( newData != NULL )
89 | {
90 | *newData = 1;
91 | }
92 |
93 | if ( newProperties != NULL )
94 | {
95 | *newProperties = 1;
96 | }
97 |
98 | if ( indexInArchive != NULL )
99 | {
100 | *indexInArchive = static_cast< UInt32 >( -1 ); // TODO: UInt32.Max
101 | }
102 |
103 | return S_OK;
104 | }
105 |
106 | STDMETHODIMP ArchiveUpdateCallback::GetProperty( UInt32 index, PROPID propID, PROPVARIANT* value )
107 | {
108 | CPropVariant prop;
109 |
110 | if ( propID == kpidIsAnti )
111 | {
112 | prop = false;
113 | prop.Detach( value );
114 | return S_OK;
115 | }
116 |
117 | if ( index >= m_filePaths.size() )
118 | {
119 | return E_INVALIDARG;
120 | }
121 |
122 | const FilePathInfo& fileInfo = m_filePaths.at( index );
123 | switch ( propID )
124 | {
125 | case kpidPath: prop = FileSys::ExtractRelativePath( m_dirPrefix, fileInfo.FilePath ).c_str(); break;
126 | case kpidIsDir: prop = fileInfo.IsDirectory; break;
127 | case kpidSize: prop = fileInfo.Size; break;
128 | case kpidAttrib: prop = fileInfo.Attributes; break;
129 | case kpidCTime: prop = fileInfo.CreationTime; break;
130 | case kpidATime: prop = fileInfo.LastAccessTime; break;
131 | case kpidMTime: prop = fileInfo.LastWriteTime; break;
132 | }
133 |
134 | prop.Detach( value );
135 | return S_OK;
136 | }
137 |
138 | STDMETHODIMP ArchiveUpdateCallback::GetStream( UInt32 index, ISequentialInStream** inStream )
139 | {
140 | if ( index >= m_filePaths.size() )
141 | {
142 | return E_INVALIDARG;
143 | }
144 |
145 | const FilePathInfo& fileInfo = m_filePaths.at( index );
146 | if ( fileInfo.IsDirectory )
147 | {
148 | return S_OK;
149 | }
150 |
151 | CComPtr< IStream > fileStream = FileSys::OpenFileToRead( fileInfo.FilePath );
152 | if ( fileStream == NULL )
153 | {
154 | return HRESULT_FROM_WIN32( GetLastError() );
155 | }
156 |
157 | CComPtr< InStreamWrapper > wrapperStream = new InStreamWrapper( fileStream );
158 | *inStream = wrapperStream.Detach();
159 |
160 | return S_OK;
161 | }
162 |
163 | STDMETHODIMP ArchiveUpdateCallback::SetOperationResult( Int32 operationResult )
164 | {
165 | return S_OK;
166 | }
167 |
168 | STDMETHODIMP ArchiveUpdateCallback::CryptoGetTextPassword2( Int32* passwordIsDefined, BSTR* password )
169 | {
170 | // TODO: support passwords
171 | *passwordIsDefined = 0;
172 | *password = SysAllocString( L"" );
173 | return *password != 0 ? S_OK : E_OUTOFMEMORY;
174 | }
175 |
176 | STDMETHODIMP ArchiveUpdateCallback::SetRatioInfo( const UInt64* inSize, const UInt64* outSize )
177 | {
178 | return S_OK;
179 | }
180 |
181 | }
182 | }
183 |
--------------------------------------------------------------------------------
/SevenZip++/ArchiveUpdateCallback.h:
--------------------------------------------------------------------------------
1 | // This file is based on the following file from the LZMA SDK (http://www.7-zip.org/sdk.html):
2 | // ./CPP/7zip/UI/Client7z/Client7z.cpp
3 | #pragma once
4 |
5 |
6 | #include <7zip/Archive/IArchive.h>
7 | #include <7zip/ICoder.h>
8 | #include <7zip/IPassword.h>
9 | #include
10 | #include "FileInfo.h"
11 |
12 |
13 | namespace SevenZip
14 | {
15 | namespace intl
16 | {
17 | class ArchiveUpdateCallback : public IArchiveUpdateCallback, public ICryptoGetTextPassword2, public ICompressProgressInfo
18 | {
19 | private:
20 |
21 | long m_refCount;
22 | TString m_dirPrefix;
23 | const std::vector< FilePathInfo >& m_filePaths;
24 |
25 | public:
26 |
27 | ArchiveUpdateCallback( const TString& dirPrefix, const std::vector< FilePathInfo >& filePaths );
28 | virtual ~ArchiveUpdateCallback();
29 |
30 | STDMETHOD(QueryInterface)( REFIID iid, void** ppvObject );
31 | STDMETHOD_(ULONG, AddRef)();
32 | STDMETHOD_(ULONG, Release)();
33 |
34 | // IProgress
35 | STDMETHOD(SetTotal)( UInt64 size );
36 | STDMETHOD(SetCompleted)( const UInt64* completeValue );
37 |
38 | // IArchiveUpdateCallback
39 | STDMETHOD(GetUpdateItemInfo)( UInt32 index, Int32* newData, Int32* newProperties, UInt32* indexInArchive );
40 | STDMETHOD(GetProperty)( UInt32 index, PROPID propID, PROPVARIANT* value );
41 | STDMETHOD(GetStream)( UInt32 index, ISequentialInStream** inStream );
42 | STDMETHOD(SetOperationResult)( Int32 operationResult );
43 |
44 | // ICryptoGetTextPassword2
45 | STDMETHOD(CryptoGetTextPassword2)( Int32* passwordIsDefined, BSTR* password );
46 |
47 | // ICompressProgressInfo
48 | STDMETHOD(SetRatioInfo)( const UInt64* inSize, const UInt64* outSize );
49 | };
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/SevenZip++/CompressionFormat.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 |
4 | #include "Enum.h"
5 |
6 |
7 | namespace SevenZip
8 | {
9 | struct CompressionFormat
10 | {
11 | enum _Enum
12 | {
13 | Unknown,
14 | SevenZip,
15 | Zip,
16 | GZip,
17 | BZip2,
18 | Rar,
19 | Tar,
20 | Iso,
21 | Cab,
22 | Lzma,
23 | Lzma86
24 | };
25 |
26 | typedef intl::EnumerationDefinitionNoStrings _Definition;
27 | typedef intl::EnumerationValue< _Enum, _Definition, Unknown > _Value;
28 | };
29 |
30 | typedef CompressionFormat::_Value CompressionFormatEnum;
31 | }
32 |
--------------------------------------------------------------------------------
/SevenZip++/CompressionLevel.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 |
4 | #include "Enum.h"
5 |
6 |
7 | namespace SevenZip
8 | {
9 | struct CompressionLevel
10 | {
11 | enum _Enum
12 | {
13 | None,
14 | Fast,
15 | Normal
16 | };
17 |
18 | typedef intl::EnumerationDefinitionNoStrings _Definition;
19 | typedef intl::EnumerationValue< _Enum, _Definition, Normal > _Value;
20 | };
21 |
22 | typedef CompressionLevel::_Value CompressionLevelEnum;
23 | }
24 |
--------------------------------------------------------------------------------
/SevenZip++/Enum.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 |
4 | //
5 | // ###### To create an enum call MyType with string support: ######
6 | //
7 | //// MyType.h
8 | //struct MyType
9 | //{
10 | // enum _Enum
11 | // {
12 | // Unknown,
13 | // Foo,
14 | // Bar
15 | // };
16 | //
17 | // struct _Definition : public EnumerationDefinition< _Enum, _Definition > { static StringValue Strings[]; };
18 | // typedef EnumerationValue< _Enum, _Definition, Unknown > _Value;
19 | //};
20 | //
21 | //typedef MyType::_Value MyTypeEnum;
22 | //
23 | //
24 | //// MyType.cpp
25 | //#include "MyType.h"
26 | //
27 | //MyType::_Definition::StringValue MyType::_Definition::Strings[] =
28 | //{
29 | // { MyType::Foo, _T( "Foo" ) },
30 | // { MyType::Bar, _T( "Bar" ) },
31 | // { MyType::Unknown, NULL }
32 | //};
33 | //
34 | //
35 | // ###### To create an enum call MyType without string support: ######
36 | //
37 | //// MyType.h
38 | //struct MyType
39 | //{
40 | // enum _Enum
41 | // {
42 | // Unknown,
43 | // Foo,
44 | // Bar
45 | // };
46 | //
47 | // typedef EnumerationDefinitionNoStrings _Definition;
48 | // typedef EnumerationValue< _Enum, _Definition, Unknown > _Value;
49 | //};
50 | //
51 | //typedef MyType::_Value MyTypeEnum;
52 | //
53 |
54 |
55 | namespace SevenZip
56 | {
57 | namespace intl
58 | {
59 | template < typename TEnum, class DerivedDef >
60 | struct EnumerationDefinition
61 | {
62 | struct StringValue
63 | {
64 | TEnum value;
65 | const TCHAR* string;
66 | };
67 |
68 | static TEnum Parse( const TString& string, const TEnum defaultValue )
69 | {
70 | const StringValue* it = DerivedDef::Strings;
71 | for (; it->string != NULL; ++it )
72 | {
73 | if ( string.Compare( it->string ) == 0 )
74 | {
75 | return it->value;
76 | }
77 | }
78 | return defaultValue;
79 | }
80 |
81 | static TString Format( const TEnum& value )
82 | {
83 | const StringValue* it = DerivedDef::Strings;
84 | for (; it->string != NULL; ++it )
85 | {
86 | if ( value == it->value )
87 | {
88 | return it->string;
89 | }
90 | }
91 | return TString();
92 | }
93 | };
94 |
95 |
96 | struct EnumerationDefinitionNoStrings {};
97 |
98 |
99 | template < typename TEnum, class TEnumClass, TEnum DefaultValue >
100 | class EnumerationValue
101 | {
102 | private:
103 |
104 | typedef typename EnumerationValue< TEnum, TEnumClass, DefaultValue > ThisClass;
105 |
106 | TEnum m_value;
107 |
108 | public:
109 |
110 | typedef typename TEnum Enum;
111 |
112 | EnumerationValue():
113 | m_value( DefaultValue )
114 | {}
115 |
116 | EnumerationValue( const TEnum& value ):
117 | m_value( value )
118 | {}
119 |
120 | static ThisClass Parse( const TString& string )
121 | {
122 | return ThisClass( TEnumClass::Parse( string, DefaultValue ) );
123 | }
124 |
125 | const TEnum& GetValue() const
126 | {
127 | return m_value;
128 | }
129 |
130 | TString GetString() const
131 | {
132 | return TEnumClass::Format( m_value );
133 | }
134 |
135 | operator TEnum() const
136 | {
137 | return m_value;
138 | }
139 |
140 | ThisClass& operator=( const TEnum& value )
141 | {
142 | m_value = value;
143 | return *this;
144 | }
145 |
146 | bool operator==( const ThisClass& that ) const
147 | {
148 | return that.m_value == m_value;
149 | }
150 |
151 | bool operator!=( const ThisClass& that ) const
152 | {
153 | return !operator==( that );
154 | }
155 |
156 | bool operator==( const TEnum& value ) const
157 | {
158 | return value == m_value;
159 | }
160 |
161 | bool operator!=( const TEnum& value ) const
162 | {
163 | return !operator==( value );
164 | }
165 |
166 | bool operator< ( const ThisClass& that ) const
167 | {
168 | return m_value < that.m_value;
169 | }
170 |
171 | // Bit field members
172 | void AddFlag( const TEnum& value )
173 | {
174 | *reinterpret_cast< int* >( &m_value ) |= static_cast< int >( value );
175 | }
176 |
177 | void RemoveFlag( const TEnum& value )
178 | {
179 | *reinterpret_cast< int* >( &m_value ) &= ~static_cast< int >( value );
180 | }
181 |
182 | bool HasFlag( const TEnum& value ) const
183 | {
184 | return ( m_value & value ) == value;
185 | }
186 |
187 | bool HasAnyFlag( const TEnum& valueCombo ) const
188 | {
189 | return ( m_value & valueCombo ) != 0;
190 | }
191 | };
192 | }
193 | }
194 |
--------------------------------------------------------------------------------
/SevenZip++/FileInfo.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 |
4 | namespace SevenZip
5 | {
6 | namespace intl
7 | {
8 | struct FileInfo
9 | {
10 | TString FileName;
11 | FILETIME LastWriteTime;
12 | FILETIME CreationTime;
13 | FILETIME LastAccessTime;
14 | ULONGLONG Size;
15 | UINT Attributes;
16 | bool IsDirectory;
17 | };
18 |
19 | struct FilePathInfo : public FileInfo
20 | {
21 | TString FilePath;
22 | };
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/SevenZip++/FileSys.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "FileSys.h"
3 | #include "PathScanner.h"
4 | #include
5 |
6 |
7 | namespace SevenZip
8 | {
9 | namespace intl
10 | {
11 |
12 | class ScannerCallback : public PathScanner::Callback
13 | {
14 | private:
15 |
16 | std::vector< FilePathInfo > m_files;
17 | bool m_recursive;
18 | bool m_onlyFirst;
19 |
20 | public:
21 |
22 | ScannerCallback( bool recursive, bool onlyFirst = false ) : m_recursive( recursive ), m_onlyFirst( onlyFirst ) {}
23 | const std::vector< FilePathInfo >& GetFiles() { return m_files; }
24 |
25 | virtual bool ShouldDescend( const FilePathInfo& directory ) { return m_recursive; }
26 | virtual void ExamineFile( const FilePathInfo& file, bool& exit )
27 | {
28 | m_files.push_back( file );
29 | if ( m_onlyFirst )
30 | {
31 | exit = true;
32 | }
33 | }
34 | };
35 |
36 |
37 | class IsEmptyCallback : public PathScanner::Callback
38 | {
39 | private:
40 |
41 | bool m_isEmpty;
42 |
43 | public:
44 |
45 | IsEmptyCallback() : m_isEmpty( true ) {}
46 | bool IsEmpty() const { return m_isEmpty; }
47 |
48 | virtual bool ShouldDescend( const FilePathInfo& directory ) { return true; }
49 | virtual void ExamineFile( const FilePathInfo& file, bool& exit ) { m_isEmpty = false; exit = true; }
50 | };
51 |
52 |
53 | TString FileSys::GetPath( const TString& filePath )
54 | {
55 | // Find the last "\" or "/" in the string and return it and everything before it.
56 | size_t index = filePath.rfind( _T( '\\' ) );
57 | size_t index2 = filePath.rfind( _T( '/' ) );
58 |
59 | if ( index2 != std::string::npos && index2 > index )
60 | {
61 | index = index2;
62 | }
63 |
64 | if ( index == std::string::npos )
65 | {
66 | // No path sep.
67 | return TString();
68 | }
69 | else if ( index + 1 >= filePath.size() )
70 | {
71 | // Last char is path sep, the whole thing is a path.
72 | return filePath;
73 | }
74 | else
75 | {
76 | return filePath.substr( 0, index + 1 );
77 | }
78 | }
79 |
80 | TString FileSys::GetFileName( const TString& filePathOrName )
81 | {
82 | // Find the last "\" or "/" in the string and return everything after it.
83 | size_t index = filePathOrName.rfind( _T( '\\' ) );
84 | size_t index2 = filePathOrName.rfind( _T( '/' ) );
85 |
86 | if ( index2 != std::string::npos && index2 > index )
87 | {
88 | index = index2;
89 | }
90 |
91 | if ( index == std::string::npos )
92 | {
93 | // No path sep, return the whole thing.
94 | return filePathOrName;
95 | }
96 | else if ( index + 1 >= filePathOrName.size() )
97 | {
98 | // Last char is path sep, no filename.
99 | return TString();
100 | }
101 | else
102 | {
103 | return filePathOrName.substr( index + 1, filePathOrName.size() - ( index + 1 ) );
104 | }
105 | }
106 |
107 | TString FileSys::AppendPath( const TString& left, const TString& right )
108 | {
109 | if ( left.empty() )
110 | {
111 | return right;
112 | }
113 |
114 | TCHAR lastChar = left[ left.size() - 1 ];
115 | if ( lastChar == _T( '\\' ) || lastChar == _T( '/' ) )
116 | {
117 | return left + right;
118 | }
119 | else
120 | {
121 | return left + _T( "\\" ) + right;
122 | }
123 | }
124 |
125 | TString FileSys::ExtractRelativePath( const TString& basePath, const TString& fullPath )
126 | {
127 | if ( basePath.size() >= fullPath.size() )
128 | {
129 | return TString();
130 | }
131 |
132 | if ( basePath != fullPath.substr( 0, basePath.size() ) )
133 | {
134 | return TString();
135 | }
136 |
137 | return fullPath.substr( basePath.size(), fullPath.size() - basePath.size() );
138 | }
139 |
140 | bool FileSys::DirectoryExists( const TString& path )
141 | {
142 | DWORD attributes = GetFileAttributes( path.c_str() );
143 |
144 | if ( attributes == INVALID_FILE_ATTRIBUTES )
145 | {
146 | return false;
147 | }
148 | else
149 | {
150 | return ( attributes & FILE_ATTRIBUTE_DIRECTORY ) != 0;
151 | }
152 | }
153 |
154 | bool FileSys::IsDirectoryEmptyRecursive( const TString& path )
155 | {
156 | IsEmptyCallback cb;
157 | PathScanner::Scan( path, cb );
158 | return cb.IsEmpty();
159 | }
160 |
161 | bool FileSys::CreateDirectoryTree( const TString& path )
162 | {
163 | int ret = SHCreateDirectoryEx( NULL, path.c_str(), NULL );
164 | return ret == ERROR_SUCCESS;
165 | }
166 |
167 | std::vector< FilePathInfo > FileSys::GetFile( const TString& filePathOrName )
168 | {
169 | TString path = FileSys::GetPath( filePathOrName );
170 | TString name = FileSys::GetFileName( filePathOrName );
171 |
172 | ScannerCallback cb( false, true );
173 | PathScanner::Scan( path, name, cb );
174 | return cb.GetFiles();
175 | }
176 |
177 | std::vector< FilePathInfo > FileSys::GetFilesInDirectory( const TString& directory, const TString& searchPattern, bool recursive )
178 | {
179 | ScannerCallback cb( recursive );
180 | PathScanner::Scan( directory, searchPattern, cb );
181 | return cb.GetFiles();
182 | }
183 |
184 | CComPtr< IStream > FileSys::OpenFileToRead( const TString& filePath )
185 | {
186 | CComPtr< IStream > fileStream;
187 |
188 | #ifdef _UNICODE
189 | const WCHAR* filePathStr = filePath.c_str();
190 | #else
191 | WCHAR filePathStr[MAX_PATH];
192 | MultiByteToWideChar( CP_UTF8, 0, filePath.c_str(), filePath.length() + 1, filePathStr, MAX_PATH );
193 | #endif
194 | if ( FAILED( SHCreateStreamOnFileEx( filePathStr, STGM_READ, FILE_ATTRIBUTE_NORMAL, FALSE, NULL, &fileStream ) ) )
195 | {
196 | return NULL;
197 | }
198 |
199 | return fileStream;
200 | }
201 |
202 | CComPtr< IStream > FileSys::OpenFileToWrite( const TString& filePath )
203 | {
204 | CComPtr< IStream > fileStream;
205 |
206 | #ifdef _UNICODE
207 | const WCHAR* filePathStr = filePath.c_str();
208 | #else
209 | WCHAR filePathStr[MAX_PATH];
210 | MultiByteToWideChar( CP_UTF8, 0, filePath.c_str(), filePath.length() + 1, filePathStr, MAX_PATH );
211 | #endif
212 | if ( FAILED( SHCreateStreamOnFileEx( filePathStr, STGM_CREATE | STGM_WRITE, FILE_ATTRIBUTE_NORMAL, TRUE, NULL, &fileStream ) ) )
213 | {
214 | return NULL;
215 | }
216 |
217 | return fileStream;
218 | }
219 |
220 | }
221 | }
222 |
--------------------------------------------------------------------------------
/SevenZip++/FileSys.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 |
4 | #include
5 | #include "FileInfo.h"
6 |
7 |
8 | namespace SevenZip
9 | {
10 | namespace intl
11 | {
12 | class FileSys
13 | {
14 | public:
15 |
16 | static TString GetPath( const TString& filePath );
17 | static TString GetFileName( const TString& filePathOrName );
18 | static TString AppendPath( const TString& left, const TString& right );
19 | static TString ExtractRelativePath( const TString& basePath, const TString& fullPath );
20 |
21 | static bool DirectoryExists( const TString& path );
22 | static bool IsDirectoryEmptyRecursive( const TString& path );
23 |
24 | static bool CreateDirectoryTree( const TString& path );
25 |
26 | static std::vector< FilePathInfo > GetFile( const TString& filePathOrName );
27 | static std::vector< FilePathInfo > GetFilesInDirectory( const TString& directory, const TString& searchPattern, bool recursive );
28 |
29 | static CComPtr< IStream > OpenFileToRead( const TString& filePath );
30 | static CComPtr< IStream > OpenFileToWrite( const TString& filePath );
31 | };
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/SevenZip++/GUIDs.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include
3 | #include "GUIDs.h"
4 |
--------------------------------------------------------------------------------
/SevenZip++/GUIDs.h:
--------------------------------------------------------------------------------
1 | // This file is based on the following file from the LZMA SDK (http://www.7-zip.org/sdk.html):
2 | // ./CPP/7zip/Guid.txt
3 | #pragma once
4 |
5 |
6 | namespace SevenZip
7 | {
8 | namespace intl
9 | {
10 | // IStream.h
11 |
12 | // {23170F69-40C1-278A-0000-000300010000}
13 | DEFINE_GUID(IID_ISequentialInStream,
14 | 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00);
15 |
16 | // {23170F69-40C1-278A-0000-000300010000}
17 | DEFINE_GUID(IID_ISequentialOutStream,
18 | 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x03, 0x00, 0x02, 0x00, 0x00);
19 |
20 | // {23170F69-40C1-278A-0000-000300030000}
21 | DEFINE_GUID(IID_IInStream,
22 | 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00);
23 |
24 | // {23170F69-40C1-278A-0000-000300040000}
25 | DEFINE_GUID(IID_IOutStream,
26 | 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00);
27 |
28 | // {23170F69-40C1-278A-0000-000300060000}
29 | DEFINE_GUID(IID_IStreamGetSize,
30 | 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00);
31 |
32 | // ICoder.h
33 | // {23170F69-40C1-278A-0000-000400040000}
34 | DEFINE_GUID(IID_ICompressProgressInfo,
35 | 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00);
36 |
37 | // IPassword.h
38 |
39 | // {23170F69-40C1-278A-0000-000500100000}
40 | DEFINE_GUID(IID_ICryptoGetTextPassword,
41 | 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x05, 0x00, 0x10, 0x00, 0x00);
42 |
43 | // {23170F69-40C1-278A-0000-000500110000}
44 | DEFINE_GUID(IID_ICryptoGetTextPassword2,
45 | 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x05, 0x00, 0x11, 0x00, 0x00);
46 |
47 | // IArchive.h
48 |
49 | // {23170F69-40C1-278A-0000-000600030000}
50 | DEFINE_GUID(IID_ISetProperties,
51 | 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x06, 0x00, 0x03, 0x00, 0x00);
52 |
53 | // {23170F69-40C1-278A-0000-000600100000}
54 | DEFINE_GUID(IID_IArchiveOpenCallback,
55 | 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x06, 0x00, 0x10, 0x00, 0x00);
56 |
57 | // {23170F69-40C1-278A-0000-000600200000}
58 | DEFINE_GUID(IID_IArchiveExtractCallback,
59 | 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x06, 0x00, 0x20, 0x00, 0x00);
60 |
61 | // {23170F69-40C1-278A-0000-000600600000}
62 | DEFINE_GUID(IID_IInArchive,
63 | 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x06, 0x00, 0x60, 0x00, 0x00);
64 |
65 | // {23170F69-40C1-278A-0000-000600800000}
66 | DEFINE_GUID(IID_IArchiveUpdateCallback,
67 | 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x06, 0x00, 0x80, 0x00, 0x00);
68 |
69 | // {23170F69-40C1-278A-0000-000600820000}
70 | DEFINE_GUID(IID_IArchiveUpdateCallback2,
71 | 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x06, 0x00, 0x82, 0x00, 0x00);
72 |
73 | // {23170F69-40C1-278A-0000-000600A00000}
74 | DEFINE_GUID(IID_IOutArchive,
75 | 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x06, 0x00, 0xA0, 0x00, 0x00);
76 |
77 | // Handler GUIDs
78 |
79 | // {23170F69-40C1-278A-1000-000110010000}
80 | DEFINE_GUID(CLSID_CFormatZip,
81 | 0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x01, 0x00, 0x00);
82 |
83 | // {23170F69-40C1-278A-1000-000110020000}
84 | DEFINE_GUID(CLSID_CFormatBZip2,
85 | 0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x02, 0x00, 0x00);
86 |
87 | // {23170F69-40C1-278A-1000-000110030000}
88 | DEFINE_GUID(CLSID_CFormatRar,
89 | 0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x03, 0x00, 0x00);
90 |
91 | // {23170F69-40C1-278A-1000-000110070000}
92 | DEFINE_GUID(CLSID_CFormat7z,
93 | 0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x07, 0x00, 0x00);
94 |
95 | // {23170F69-40C1-278A-1000-000110080000}
96 | DEFINE_GUID(CLSID_CFormatCab,
97 | 0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x08, 0x00, 0x00);
98 |
99 | // {23170F69-40C1-278A-1000-0001100A0000}
100 | DEFINE_GUID(CLSID_CFormatLzma,
101 | 0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x0A, 0x00, 0x00);
102 |
103 | // {23170F69-40C1-278A-1000-0001100B0000}
104 | DEFINE_GUID(CLSID_CFormatLzma86,
105 | 0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x0B, 0x00, 0x00);
106 |
107 | // {23170F69-40C1-278A-1000-000110E70000}
108 | DEFINE_GUID(CLSID_CFormatIso,
109 | 0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0xE7, 0x00, 0x00);
110 |
111 | // {23170F69-40C1-278A-1000-000110EE0000}
112 | DEFINE_GUID(CLSID_CFormatTar,
113 | 0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0xEE, 0x00, 0x00);
114 |
115 | // {23170F69-40C1-278A-1000-000110EF0000}
116 | DEFINE_GUID(CLSID_CFormatGZip,
117 | 0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0xEF, 0x00, 0x00);
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/SevenZip++/InStreamWrapper.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "InStreamWrapper.h"
3 |
4 |
5 | namespace SevenZip
6 | {
7 | namespace intl
8 | {
9 |
10 | InStreamWrapper::InStreamWrapper( const CComPtr< IStream >& baseStream )
11 | : m_refCount( 0 )
12 | , m_baseStream( baseStream )
13 | {
14 | }
15 |
16 | InStreamWrapper::~InStreamWrapper()
17 | {
18 | }
19 |
20 | HRESULT STDMETHODCALLTYPE InStreamWrapper::QueryInterface( REFIID iid, void** ppvObject )
21 | {
22 | if ( iid == __uuidof( IUnknown ) )
23 | {
24 | *ppvObject = reinterpret_cast< IUnknown* >( this );
25 | AddRef();
26 | return S_OK;
27 | }
28 |
29 | if ( iid == IID_ISequentialInStream )
30 | {
31 | *ppvObject = static_cast< ISequentialInStream* >( this );
32 | AddRef();
33 | return S_OK;
34 | }
35 |
36 | if ( iid == IID_IInStream )
37 | {
38 | *ppvObject = static_cast< IInStream* >( this );
39 | AddRef();
40 | return S_OK;
41 | }
42 |
43 | if ( iid == IID_IStreamGetSize )
44 | {
45 | *ppvObject = static_cast< IStreamGetSize* >( this );
46 | AddRef();
47 | return S_OK;
48 | }
49 |
50 | return E_NOINTERFACE;
51 | }
52 |
53 | ULONG STDMETHODCALLTYPE InStreamWrapper::AddRef()
54 | {
55 | return static_cast< ULONG >( InterlockedIncrement( &m_refCount ) );
56 | }
57 |
58 | ULONG STDMETHODCALLTYPE InStreamWrapper::Release()
59 | {
60 | ULONG res = static_cast< ULONG >( InterlockedDecrement( &m_refCount ) );
61 | if ( res == 0 )
62 | {
63 | delete this;
64 | }
65 | return res;
66 | }
67 |
68 | STDMETHODIMP InStreamWrapper::Read( void* data, UInt32 size, UInt32* processedSize )
69 | {
70 | ULONG read = 0;
71 | HRESULT hr = m_baseStream->Read( data, size, &read );
72 | if ( processedSize != NULL )
73 | {
74 | *processedSize = read;
75 | }
76 | // Transform S_FALSE to S_OK
77 | return SUCCEEDED( hr ) ? S_OK : hr;
78 | }
79 |
80 | STDMETHODIMP InStreamWrapper::Seek( Int64 offset, UInt32 seekOrigin, UInt64* newPosition )
81 | {
82 | LARGE_INTEGER move;
83 | ULARGE_INTEGER newPos;
84 |
85 | move.QuadPart = offset;
86 | HRESULT hr = m_baseStream->Seek( move, seekOrigin, &newPos );
87 | if ( newPosition != NULL )
88 | {
89 | *newPosition = newPos.QuadPart;
90 | }
91 | return hr;
92 | }
93 |
94 | STDMETHODIMP InStreamWrapper::GetSize( UInt64* size )
95 | {
96 | STATSTG statInfo;
97 | HRESULT hr = m_baseStream->Stat( &statInfo, STATFLAG_NONAME );
98 | if ( SUCCEEDED( hr ) )
99 | {
100 | *size = statInfo.cbSize.QuadPart;
101 | }
102 | return hr;
103 | }
104 |
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/SevenZip++/InStreamWrapper.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 |
4 | #include <7zip/IStream.h>
5 |
6 |
7 | namespace SevenZip
8 | {
9 | namespace intl
10 | {
11 | class InStreamWrapper : public IInStream, public IStreamGetSize
12 | {
13 | private:
14 |
15 | long m_refCount;
16 | CComPtr< IStream > m_baseStream;
17 |
18 | public:
19 |
20 | InStreamWrapper( const CComPtr< IStream >& baseStream );
21 | virtual ~InStreamWrapper();
22 |
23 | STDMETHOD(QueryInterface)( REFIID iid, void** ppvObject );
24 | STDMETHOD_(ULONG, AddRef)();
25 | STDMETHOD_(ULONG, Release)();
26 |
27 | // ISequentialInStream
28 | STDMETHOD(Read)( void* data, UInt32 size, UInt32* processedSize );
29 |
30 | // IInStream
31 | STDMETHOD(Seek)( Int64 offset, UInt32 seekOrigin, UInt64* newPosition );
32 |
33 | // IStreamGetSize
34 | STDMETHOD(GetSize)( UInt64* size );
35 | };
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/SevenZip++/NonCopyable.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | namespace SevenZip
4 | {
5 |
6 | class NonCopyable
7 | {
8 | protected:
9 | NonCopyable(){}
10 | ~NonCopyable(){}
11 |
12 | private:
13 | NonCopyable(const NonCopyable&);
14 | NonCopyable(NonCopyable&&);
15 | NonCopyable& operator=(const NonCopyable&);
16 | NonCopyable& operator=(NonCopyable&&);
17 | };
18 | }
--------------------------------------------------------------------------------
/SevenZip++/OutStreamWrapper.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "OutStreamWrapper.h"
3 |
4 |
5 | namespace SevenZip
6 | {
7 | namespace intl
8 | {
9 |
10 | OutStreamWrapper::OutStreamWrapper( const CComPtr< IStream >& baseStream )
11 | : m_refCount( 0 )
12 | , m_baseStream( baseStream )
13 | {
14 | }
15 |
16 | OutStreamWrapper::~OutStreamWrapper()
17 | {
18 | }
19 |
20 | HRESULT STDMETHODCALLTYPE OutStreamWrapper::QueryInterface( REFIID iid, void** ppvObject )
21 | {
22 | if ( iid == __uuidof( IUnknown ) )
23 | {
24 | *ppvObject = static_cast< IUnknown* >( this );
25 | AddRef();
26 | return S_OK;
27 | }
28 |
29 | if ( iid == IID_ISequentialOutStream )
30 | {
31 | *ppvObject = static_cast< ISequentialOutStream* >( this );
32 | AddRef();
33 | return S_OK;
34 | }
35 |
36 | if ( iid == IID_IOutStream )
37 | {
38 | *ppvObject = static_cast< IOutStream* >( this );
39 | AddRef();
40 | return S_OK;
41 | }
42 |
43 | return E_NOINTERFACE;
44 | }
45 |
46 | ULONG STDMETHODCALLTYPE OutStreamWrapper::AddRef()
47 | {
48 | return static_cast< ULONG >( InterlockedIncrement( &m_refCount ) );
49 | }
50 |
51 | ULONG STDMETHODCALLTYPE OutStreamWrapper::Release()
52 | {
53 | ULONG res = static_cast< ULONG >( InterlockedDecrement( &m_refCount ) );
54 | if ( res == 0 )
55 | {
56 | delete this;
57 | }
58 | return res;
59 | }
60 |
61 | STDMETHODIMP OutStreamWrapper::Write( const void* data, UInt32 size, UInt32* processedSize )
62 | {
63 | ULONG written = 0;
64 | HRESULT hr = m_baseStream->Write( data, size, &written );
65 | if ( processedSize != NULL )
66 | {
67 | *processedSize = written;
68 | }
69 | return hr;
70 | }
71 |
72 | STDMETHODIMP OutStreamWrapper::Seek( Int64 offset, UInt32 seekOrigin, UInt64* newPosition )
73 | {
74 | LARGE_INTEGER move;
75 | ULARGE_INTEGER newPos;
76 |
77 | move.QuadPart = offset;
78 | HRESULT hr = m_baseStream->Seek( move, seekOrigin, &newPos );
79 | if ( newPosition != NULL )
80 | {
81 | *newPosition = newPos.QuadPart;
82 | }
83 | return hr;
84 | }
85 |
86 | STDMETHODIMP OutStreamWrapper::SetSize( UInt64 newSize )
87 | {
88 | ULARGE_INTEGER size;
89 | size.QuadPart = newSize;
90 | return m_baseStream->SetSize( size );
91 | }
92 |
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/SevenZip++/OutStreamWrapper.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 |
4 | #include <7zip/IStream.h>
5 |
6 |
7 | namespace SevenZip
8 | {
9 | namespace intl
10 | {
11 | class OutStreamWrapper : public IOutStream
12 | {
13 | private:
14 |
15 | long m_refCount;
16 | CComPtr< IStream > m_baseStream;
17 |
18 | public:
19 |
20 | OutStreamWrapper( const CComPtr< IStream >& baseStream );
21 | virtual ~OutStreamWrapper();
22 |
23 | STDMETHOD(QueryInterface)( REFIID iid, void** ppvObject );
24 | STDMETHOD_(ULONG, AddRef)();
25 | STDMETHOD_(ULONG, Release)();
26 |
27 | // ISequentialOutStream
28 | STDMETHOD(Write)( const void* data, UInt32 size, UInt32* processedSize );
29 |
30 | // IOutStream
31 | STDMETHOD(Seek)( Int64 offset, UInt32 seekOrigin, UInt64* newPosition );
32 | STDMETHOD(SetSize)( UInt64 newSize );
33 | };
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/SevenZip++/PathScanner.cpp:
--------------------------------------------------------------------------------
1 | #include "StdAfx.h"
2 | #include "PathScanner.h"
3 | #include "FileSys.h"
4 |
5 |
6 | namespace SevenZip
7 | {
8 | namespace intl
9 | {
10 |
11 | void PathScanner::Scan( const TString& root, Callback& cb )
12 | {
13 | Scan( root, _T( "*" ), cb );
14 | }
15 |
16 | void PathScanner::Scan( const TString& root, const TString& searchPattern, Callback& cb )
17 | {
18 | std::deque< TString > directories;
19 | directories.push_back( root );
20 |
21 | while ( !directories.empty() )
22 | {
23 | TString directory = directories.front();
24 | directories.pop_front();
25 |
26 | if ( ExamineFiles( directory, searchPattern, cb ) )
27 | {
28 | break;
29 | }
30 |
31 | ExamineDirectories( directory, directories, cb );
32 | }
33 | }
34 |
35 | bool PathScanner::ExamineFiles( const TString& directory, const TString& searchPattern, Callback& cb )
36 | {
37 | TString findStr = FileSys::AppendPath( directory, searchPattern );
38 | bool exit = false;
39 |
40 | WIN32_FIND_DATA fdata;
41 | HANDLE hFile = FindFirstFile( findStr.c_str(), &fdata );
42 | if ( hFile == INVALID_HANDLE_VALUE )
43 | {
44 | return exit;
45 | }
46 |
47 | cb.EnterDirectory( directory );
48 |
49 | do
50 | {
51 | FilePathInfo fpInfo = ConvertFindInfo( directory, fdata );
52 | if ( !fpInfo.IsDirectory && !IsSpecialFileName( fpInfo.FileName ) )
53 | {
54 | cb.ExamineFile( fpInfo, exit );
55 | }
56 | }
57 | while ( !exit && FindNextFile( hFile, &fdata ) );
58 |
59 | if ( !exit )
60 | {
61 | cb.LeaveDirectory( directory );
62 | }
63 |
64 | FindClose( hFile );
65 | return exit;
66 | }
67 |
68 | void PathScanner::ExamineDirectories( const TString& directory, std::deque< TString >& subDirs, Callback& cb )
69 | {
70 | TString findStr = FileSys::AppendPath( directory, _T( "*" ) );
71 |
72 | WIN32_FIND_DATA fdata;
73 | HANDLE hFile = FindFirstFile( findStr.c_str(), &fdata );
74 | if ( hFile == INVALID_HANDLE_VALUE )
75 | {
76 | return;
77 | }
78 |
79 | do
80 | {
81 | FilePathInfo fpInfo = ConvertFindInfo( directory, fdata );
82 | if ( fpInfo.IsDirectory && !IsSpecialFileName( fpInfo.FileName ) && cb.ShouldDescend( fpInfo ) )
83 | {
84 | subDirs.push_back( fpInfo.FilePath );
85 | }
86 | }
87 | while ( FindNextFile( hFile, &fdata ) );
88 |
89 | FindClose( hFile );
90 | }
91 |
92 | bool PathScanner::IsAllFilesPattern( const TString& searchPattern )
93 | {
94 | return searchPattern == _T( "*" ) || searchPattern == _T( "*.*" );
95 | }
96 |
97 | bool PathScanner::IsSpecialFileName( const TString& fileName )
98 | {
99 | return fileName == _T( "." ) || fileName == _T( ".." );
100 | }
101 |
102 | bool PathScanner::IsDirectory( const WIN32_FIND_DATA& fdata )
103 | {
104 | return ( fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) != 0;
105 | }
106 |
107 | FilePathInfo PathScanner::ConvertFindInfo( const TString& directory, const WIN32_FIND_DATA& fdata )
108 | {
109 | FilePathInfo file;
110 | file.FileName = fdata.cFileName;
111 | file.FilePath = FileSys::AppendPath( directory, file.FileName );
112 | file.LastWriteTime = fdata.ftLastWriteTime;
113 | file.CreationTime = fdata.ftCreationTime;
114 | file.LastAccessTime = fdata.ftLastAccessTime;
115 | file.Attributes = fdata.dwFileAttributes;
116 | file.IsDirectory = IsDirectory( fdata );
117 |
118 | ULARGE_INTEGER size;
119 | size.LowPart = fdata.nFileSizeLow;
120 | size.HighPart = fdata.nFileSizeHigh;
121 | file.Size = size.QuadPart;
122 |
123 | return file;
124 | }
125 |
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/SevenZip++/PathScanner.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 |
4 | #include
5 | #include "FileInfo.h"
6 |
7 |
8 | namespace SevenZip
9 | {
10 | namespace intl
11 | {
12 | class PathScanner
13 | {
14 | public:
15 |
16 | class Callback
17 | {
18 | public:
19 |
20 | virtual ~Callback() {}
21 |
22 | virtual void BeginScan() {}
23 | virtual void EndScan() {}
24 | virtual bool ShouldDescend( const FilePathInfo& directory ) = 0;
25 | virtual void EnterDirectory( const TString& path ) {}
26 | virtual void LeaveDirectory( const TString& path ) {}
27 | virtual void ExamineFile( const FilePathInfo& file, bool& exit ) = 0;
28 | };
29 |
30 | public:
31 |
32 | static void Scan( const TString& root, Callback& cb );
33 | static void Scan( const TString& root, const TString& searchPattern, Callback& cb );
34 |
35 | private:
36 |
37 | static bool ExamineFiles( const TString& directory, const TString& searchPattern, Callback& cb );
38 | static void ExamineDirectories( const TString& directory, std::deque< TString >& subDirs, Callback& cb );
39 |
40 | static bool IsAllFilesPattern( const TString& searchPattern );
41 | static bool IsSpecialFileName( const TString& fileName );
42 | static bool IsDirectory( const WIN32_FIND_DATA& fdata );
43 | static FilePathInfo ConvertFindInfo( const TString& directory, const WIN32_FIND_DATA& fdata );
44 | };
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/SevenZip++/PropVariant.cpp:
--------------------------------------------------------------------------------
1 | // This file is based on the following file from the LZMA SDK (http://www.7-zip.org/sdk.html):
2 | // ./CPP/Windows/PropVariant.cpp
3 | #include "stdafx.h"
4 | #include "PropVariant.h"
5 | #include
6 |
7 |
8 | namespace SevenZip
9 | {
10 | namespace intl
11 | {
12 |
13 | CPropVariant::CPropVariant(const PROPVARIANT &varSrc)
14 | {
15 | vt = VT_EMPTY;
16 | InternalCopy(&varSrc);
17 | }
18 |
19 | CPropVariant::CPropVariant(const CPropVariant &varSrc)
20 | {
21 | vt = VT_EMPTY;
22 | InternalCopy(&varSrc);
23 | }
24 |
25 | CPropVariant::CPropVariant(BSTR bstrSrc)
26 | {
27 | vt = VT_EMPTY;
28 | *this = bstrSrc;
29 | }
30 |
31 | CPropVariant::CPropVariant(LPCOLESTR lpszSrc)
32 | {
33 | vt = VT_EMPTY;
34 | *this = lpszSrc;
35 | }
36 |
37 | CPropVariant& CPropVariant::operator=(const CPropVariant &varSrc)
38 | {
39 | InternalCopy(&varSrc);
40 | return *this;
41 | }
42 | CPropVariant& CPropVariant::operator=(const PROPVARIANT &varSrc)
43 | {
44 | InternalCopy(&varSrc);
45 | return *this;
46 | }
47 |
48 | CPropVariant& CPropVariant::operator=(BSTR bstrSrc)
49 | {
50 | *this = (LPCOLESTR)bstrSrc;
51 | return *this;
52 | }
53 |
54 | static const char *kMemException = "out of memory";
55 |
56 | CPropVariant& CPropVariant::operator=(LPCOLESTR lpszSrc)
57 | {
58 | InternalClear();
59 | vt = VT_BSTR;
60 | wReserved1 = 0;
61 | bstrVal = ::SysAllocString(lpszSrc);
62 | if (bstrVal == NULL && lpszSrc != NULL)
63 | {
64 | throw kMemException;
65 | // vt = VT_ERROR;
66 | // scode = E_OUTOFMEMORY;
67 | }
68 | return *this;
69 | }
70 |
71 |
72 | CPropVariant& CPropVariant::operator=(const char *s)
73 | {
74 | InternalClear();
75 | vt = VT_BSTR;
76 | wReserved1 = 0;
77 | UINT len = (UINT)strlen(s);
78 | bstrVal = ::SysAllocStringByteLen(0, (UINT)len * sizeof(OLECHAR));
79 | if (bstrVal == NULL)
80 | {
81 | throw kMemException;
82 | // vt = VT_ERROR;
83 | // scode = E_OUTOFMEMORY;
84 | }
85 | else
86 | {
87 | for (UINT i = 0; i <= len; i++)
88 | bstrVal[i] = s[i];
89 | }
90 | return *this;
91 | }
92 |
93 | CPropVariant& CPropVariant::operator=(bool bSrc)
94 | {
95 | if (vt != VT_BOOL)
96 | {
97 | InternalClear();
98 | vt = VT_BOOL;
99 | }
100 | boolVal = bSrc ? VARIANT_TRUE : VARIANT_FALSE;
101 | return *this;
102 | }
103 |
104 | #define SET_PROP_FUNC(type, id, dest) \
105 | CPropVariant& CPropVariant::operator=(type value) \
106 | { if (vt != id) { InternalClear(); vt = id; } \
107 | dest = value; return *this; }
108 |
109 | SET_PROP_FUNC(Byte, VT_UI1, bVal)
110 | SET_PROP_FUNC(Int16, VT_I2, iVal)
111 | SET_PROP_FUNC(Int32, VT_I4, lVal)
112 | SET_PROP_FUNC(UInt32, VT_UI4, ulVal)
113 | SET_PROP_FUNC(UInt64, VT_UI8, uhVal.QuadPart)
114 | SET_PROP_FUNC(const FILETIME &, VT_FILETIME, filetime)
115 |
116 | static HRESULT MyPropVariantClear(PROPVARIANT *prop)
117 | {
118 | switch(prop->vt)
119 | {
120 | case VT_UI1:
121 | case VT_I1:
122 | case VT_I2:
123 | case VT_UI2:
124 | case VT_BOOL:
125 | case VT_I4:
126 | case VT_UI4:
127 | case VT_R4:
128 | case VT_INT:
129 | case VT_UINT:
130 | case VT_ERROR:
131 | case VT_FILETIME:
132 | case VT_UI8:
133 | case VT_R8:
134 | case VT_CY:
135 | case VT_DATE:
136 | prop->vt = VT_EMPTY;
137 | prop->wReserved1 = 0;
138 | return S_OK;
139 | }
140 | return ::VariantClear((VARIANTARG *)prop);
141 | }
142 |
143 | HRESULT CPropVariant::Clear()
144 | {
145 | return MyPropVariantClear(this);
146 | }
147 |
148 | HRESULT CPropVariant::Copy(const PROPVARIANT* pSrc)
149 | {
150 | ::VariantClear((tagVARIANT *)this);
151 | switch(pSrc->vt)
152 | {
153 | case VT_UI1:
154 | case VT_I1:
155 | case VT_I2:
156 | case VT_UI2:
157 | case VT_BOOL:
158 | case VT_I4:
159 | case VT_UI4:
160 | case VT_R4:
161 | case VT_INT:
162 | case VT_UINT:
163 | case VT_ERROR:
164 | case VT_FILETIME:
165 | case VT_UI8:
166 | case VT_R8:
167 | case VT_CY:
168 | case VT_DATE:
169 | memmove((PROPVARIANT*)this, pSrc, sizeof(PROPVARIANT));
170 | return S_OK;
171 | }
172 | return ::VariantCopy((tagVARIANT *)this, (tagVARIANT *)const_cast(pSrc));
173 | }
174 |
175 |
176 | HRESULT CPropVariant::Attach(PROPVARIANT *pSrc)
177 | {
178 | HRESULT hr = Clear();
179 | if (FAILED(hr))
180 | return hr;
181 | memcpy(this, pSrc, sizeof(PROPVARIANT));
182 | pSrc->vt = VT_EMPTY;
183 | return S_OK;
184 | }
185 |
186 | HRESULT CPropVariant::Detach(PROPVARIANT *pDest)
187 | {
188 | HRESULT hr = MyPropVariantClear(pDest);
189 | if (FAILED(hr))
190 | return hr;
191 | memcpy(pDest, this, sizeof(PROPVARIANT));
192 | vt = VT_EMPTY;
193 | return S_OK;
194 | }
195 |
196 | HRESULT CPropVariant::InternalClear()
197 | {
198 | HRESULT hr = Clear();
199 | if (FAILED(hr))
200 | {
201 | vt = VT_ERROR;
202 | scode = hr;
203 | }
204 | return hr;
205 | }
206 |
207 | void CPropVariant::InternalCopy(const PROPVARIANT *pSrc)
208 | {
209 | HRESULT hr = Copy(pSrc);
210 | if (FAILED(hr))
211 | {
212 | if (hr == E_OUTOFMEMORY)
213 | throw kMemException;
214 | vt = VT_ERROR;
215 | scode = hr;
216 | }
217 | }
218 |
219 | int CPropVariant::Compare(const CPropVariant &a)
220 | {
221 | if (vt != a.vt)
222 | return MyCompare(vt, a.vt);
223 | switch (vt)
224 | {
225 | case VT_EMPTY: return 0;
226 | // case VT_I1: return MyCompare(cVal, a.cVal);
227 | case VT_UI1: return MyCompare(bVal, a.bVal);
228 | case VT_I2: return MyCompare(iVal, a.iVal);
229 | case VT_UI2: return MyCompare(uiVal, a.uiVal);
230 | case VT_I4: return MyCompare(lVal, a.lVal);
231 | case VT_UI4: return MyCompare(ulVal, a.ulVal);
232 | // case VT_UINT: return MyCompare(uintVal, a.uintVal);
233 | case VT_I8: return MyCompare(hVal.QuadPart, a.hVal.QuadPart);
234 | case VT_UI8: return MyCompare(uhVal.QuadPart, a.uhVal.QuadPart);
235 | case VT_BOOL: return -MyCompare(boolVal, a.boolVal);
236 | case VT_FILETIME: return ::CompareFileTime(&filetime, &a.filetime);
237 | case VT_BSTR:
238 | return 0; // Not implemented
239 | // return MyCompare(aPropVarint.cVal);
240 | default: return 0;
241 | }
242 | }
243 |
244 | }
245 | }
246 |
--------------------------------------------------------------------------------
/SevenZip++/PropVariant.h:
--------------------------------------------------------------------------------
1 | // This file is based on the following file from the LZMA SDK (http://www.7-zip.org/sdk.html):
2 | // ./CPP/Windows/PropVariant.h
3 |
4 | #pragma once
5 |
6 |
7 | #include
8 |
9 |
10 | namespace SevenZip
11 | {
12 | namespace intl
13 | {
14 | class CPropVariant : public PROPVARIANT
15 | {
16 | public:
17 |
18 | CPropVariant() { vt = VT_EMPTY; wReserved1 = 0; }
19 | ~CPropVariant() { Clear(); }
20 | CPropVariant(const PROPVARIANT &varSrc);
21 | CPropVariant(const CPropVariant &varSrc);
22 | CPropVariant(BSTR bstrSrc);
23 | CPropVariant(LPCOLESTR lpszSrc);
24 | CPropVariant(bool bSrc) { vt = VT_BOOL; wReserved1 = 0; boolVal = (bSrc ? VARIANT_TRUE : VARIANT_FALSE); };
25 | CPropVariant(Byte value) { vt = VT_UI1; wReserved1 = 0; bVal = value; }
26 | CPropVariant(Int16 value) { vt = VT_I2; wReserved1 = 0; iVal = value; }
27 | CPropVariant(Int32 value) { vt = VT_I4; wReserved1 = 0; lVal = value; }
28 | CPropVariant(UInt32 value) { vt = VT_UI4; wReserved1 = 0; ulVal = value; }
29 | CPropVariant(UInt64 value) { vt = VT_UI8; wReserved1 = 0; uhVal.QuadPart = value; }
30 | CPropVariant(const FILETIME &value) { vt = VT_FILETIME; wReserved1 = 0; filetime = value; }
31 |
32 | CPropVariant& operator=(const CPropVariant &varSrc);
33 | CPropVariant& operator=(const PROPVARIANT &varSrc);
34 | CPropVariant& operator=(BSTR bstrSrc);
35 | CPropVariant& operator=(LPCOLESTR lpszSrc);
36 | CPropVariant& operator=(const char *s);
37 | CPropVariant& operator=(bool bSrc);
38 | CPropVariant& operator=(Byte value);
39 | CPropVariant& operator=(Int16 value);
40 | CPropVariant& operator=(Int32 value);
41 | CPropVariant& operator=(UInt32 value);
42 | CPropVariant& operator=(Int64 value);
43 | CPropVariant& operator=(UInt64 value);
44 | CPropVariant& operator=(const FILETIME &value);
45 |
46 | HRESULT Clear();
47 | HRESULT Copy(const PROPVARIANT *pSrc);
48 | HRESULT Attach(PROPVARIANT *pSrc);
49 | HRESULT Detach(PROPVARIANT *pDest);
50 |
51 | HRESULT InternalClear();
52 | void InternalCopy(const PROPVARIANT *pSrc);
53 |
54 | int Compare(const CPropVariant &a1);
55 | };
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/SevenZip++/SevenCryptLibrary.cpp:
--------------------------------------------------------------------------------
1 | #include "StdAfx.h"
2 | #include "SevenCryptLibrary.h"
3 |
4 | namespace SevenZip
5 | {
6 | const TString DefaultCryptLibrary = _T( "Cryptdll.dll" );
7 |
8 | SevenCryptLibrary::SevenCryptLibrary(void)
9 | :m_dll(nullptr),
10 | m_md5Init(nullptr),
11 | m_md5Update(nullptr),
12 | m_md5Final(nullptr)
13 | {
14 | }
15 |
16 |
17 | SevenCryptLibrary::~SevenCryptLibrary(void)
18 | {
19 | Free();
20 | }
21 |
22 | void SevenCryptLibrary::Load()
23 | {
24 | Load(DefaultCryptLibrary);
25 | }
26 |
27 |
28 | void SevenCryptLibrary::Load( const TString& libraryPath )
29 | {
30 | Free();
31 | m_dll = ::LoadLibrary( libraryPath.c_str() );
32 | if ( m_dll == NULL )
33 | {
34 | throw SevenZipException( GetWinErrMsg( _T( "LoadLibrary" ), GetLastError() ) );
35 | }
36 |
37 | m_md5Init = reinterpret_cast< TMD5Init >( ::GetProcAddress( m_dll, "MD5Init" ) );
38 | if ( m_md5Init == NULL )
39 | {
40 | Free();
41 | throw SevenZipException( _T( "Loaded library is missing required MD5Init function" ) );
42 | }
43 |
44 | m_md5Update = reinterpret_cast< TMD5Update >( ::GetProcAddress( m_dll, "MD5Update" ) );
45 | if ( m_md5Update == NULL )
46 | {
47 | Free();
48 | throw SevenZipException( _T( "Loaded library is missing required MD5Update function" ) );
49 | }
50 |
51 | m_md5Final = reinterpret_cast< TMD5Final >( ::GetProcAddress( m_dll, "MD5Final" ) );
52 | if ( m_md5Final == NULL )
53 | {
54 | Free();
55 | throw SevenZipException( _T( "Loaded library is missing required MD5Final function" ) );
56 | }
57 |
58 | }
59 |
60 |
61 | void SevenCryptLibrary::Free()
62 | {
63 | if ( m_dll != nullptr )
64 | {
65 | ::FreeLibrary( m_dll );
66 | m_dll = nullptr;
67 | m_md5Init = nullptr;
68 | m_md5Update = nullptr;
69 | m_md5Final = nullptr;
70 | }
71 | }
72 |
73 |
74 | void SevenCryptLibrary::MD5Init(MD5_CTX* ctx) const
75 | {
76 | if (m_md5Init)
77 | {
78 | m_md5Init(ctx);
79 | }
80 | else
81 | {
82 | throw SevenZipException( DefaultCryptLibrary + _T( " is not loaded" ) );
83 | }
84 | }
85 |
86 |
87 | void SevenCryptLibrary::MD5Update(MD5_CTX* ctx, const void* data, unsigned int length) const
88 | {
89 | if (m_md5Update)
90 | {
91 | m_md5Update(ctx, data, length);
92 | }
93 | else
94 | {
95 | throw SevenZipException( DefaultCryptLibrary + _T( " is not loaded" ) );
96 | }
97 | }
98 |
99 |
100 | void SevenCryptLibrary::MD5Final(MD5_CTX* ctx) const
101 | {
102 | if (m_md5Final)
103 | {
104 | m_md5Final(ctx);
105 | }
106 | else
107 | {
108 | throw SevenZipException( DefaultCryptLibrary + _T( " is not loaded" ) );
109 | }
110 | }
111 |
112 | }
--------------------------------------------------------------------------------
/SevenZip++/SevenCryptLibrary.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "SevenZipException.h"
3 |
4 | namespace SevenZip
5 | {
6 | typedef struct
7 | {
8 | ULONG i[2];
9 | ULONG buf[4];
10 | unsigned char in[64];
11 | unsigned char digest[16];
12 | }MD5_CTX;
13 |
14 | class SevenCryptLibrary
15 | {
16 | private:
17 | typedef void (WINAPI *TMD5Init)(MD5_CTX*);
18 | typedef void (WINAPI *TMD5Update)(MD5_CTX*, const void*, unsigned int);
19 | typedef void (WINAPI *TMD5Final)(MD5_CTX*);
20 |
21 | SevenCryptLibrary(const SevenCryptLibrary&);
22 | SevenCryptLibrary& operator=(const SevenCryptLibrary&);
23 |
24 | public:
25 | SevenCryptLibrary(void);
26 | ~SevenCryptLibrary(void);
27 |
28 | void Load();
29 | void Load( const TString& libraryPath );
30 | void Free();
31 |
32 | void MD5Init(MD5_CTX*) const;
33 | void MD5Update(MD5_CTX*, const void*, unsigned int) const;
34 | void MD5Final(MD5_CTX*) const;
35 |
36 | private:
37 | HMODULE m_dll;
38 | TMD5Init m_md5Init;
39 | TMD5Update m_md5Update;
40 | TMD5Final m_md5Final;
41 | };
42 |
43 | }
--------------------------------------------------------------------------------
/SevenZip++/SevenTask.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 |
4 | namespace SevenZip {
5 | class SevenTask
6 | {
7 | public:
8 | SevenTask()
9 | {
10 | }
11 |
12 | explicit SevenTask(const std::function& task)
13 | {
14 | Task = task;
15 | }
16 |
17 | SevenTask(const std::function& task, const std::function& notify)
18 | {
19 | Task = task;
20 | Notify = notify;
21 | }
22 |
23 | operator bool() const
24 | {
25 | return static_cast(Task);
26 | }
27 |
28 | void operator()()
29 | {
30 | Task();
31 | }
32 |
33 | std::function Task;
34 | std::function Notify;
35 | };
36 |
37 | } // namespace SevenZip
--------------------------------------------------------------------------------
/SevenZip++/SevenThread.cpp:
--------------------------------------------------------------------------------
1 | #include "StdAfx.h"
2 | #include "SevenWorkerPool.h"
3 | #include "SevenThread.h"
4 |
5 |
6 | namespace SevenZip
7 | {
8 | SevenThread::SevenThread(SevenWorkerPool* pool)
9 | {
10 | m_hthread = ::CreateThread(nullptr, 0, ThreadProc, this, 0, &m_id);
11 | m_state = THREAD_CREATE;
12 | m_pool = pool;
13 | }
14 |
15 |
16 | SevenThread::~SevenThread(void)
17 | {
18 | Destroy();
19 | }
20 |
21 | DWORD WINAPI SevenThread::ThreadProc(_In_ LPVOID lpParameter)
22 | {
23 | SevenThread* pthis = reinterpret_cast(lpParameter);
24 | ::InterlockedExchange(&pthis->m_state, THREAD_RUNNING);
25 | pthis->run();
26 | ::InterlockedExchange(&pthis->m_state, THREAD_DEAD);
27 | return 0;
28 | }
29 |
30 |
31 | void SevenThread::Join()
32 | {
33 | ::WaitForSingleObject(m_hthread, INFINITE);
34 | }
35 |
36 | void SevenThread::Destroy(DWORD timeout)
37 | {
38 | if (m_hthread)
39 | {
40 | timeout = timeout>0 ? timeout : INFINITE;
41 | if (WAIT_TIMEOUT == ::WaitForSingleObject(m_hthread, timeout))
42 | {
43 | ::SuspendThread(m_hthread);
44 | ::InterlockedExchange(&m_state, THREAD_SUSPEND);
45 | ::TerminateThread(m_hthread, -1);
46 | }
47 | ::CloseHandle(m_hthread);
48 | m_hthread = nullptr;
49 | ::InterlockedExchange(&m_state, THREAD_DEAD);
50 | }
51 | }
52 |
53 |
54 | void SevenThread::run()
55 | {
56 | while (m_pool->runTask()){}
57 | }
58 |
59 | }
--------------------------------------------------------------------------------
/SevenZip++/SevenThread.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lniwn/SevenZip/edbd25b0dc9aca47cd7bbb4183d16292d64f7d3a/SevenZip++/SevenThread.h
--------------------------------------------------------------------------------
/SevenZip++/SevenWorkerPool.cpp:
--------------------------------------------------------------------------------
1 | #include "StdAfx.h"
2 | #include "SevenThread.h"
3 | #include "SevenWorkerPool.h"
4 | #include
5 |
6 |
7 | namespace SevenZip
8 | {
9 |
10 | #define FOR_EACH_THREAD0(method) for (unsigned int _ = 0; _ < m_pool_size_; ++_)\
11 | {auto beg = m_workList.begin(); std::advance(beg, _); (*beg)->##method();}
12 |
13 | SevenWorkerPool::~SevenWorkerPool(void)
14 | {
15 | Uninit();
16 | }
17 |
18 | SevenWorkerPool::SevenWorkerPool(void)
19 | {
20 | }
21 |
22 | bool SevenWorkerPool::Init(unsigned int size)
23 | {
24 | ::InitializeCriticalSectionAndSpinCount(&m_csObj, 4000);
25 | SYSTEM_INFO si;
26 | ::GetSystemInfo(&si);
27 | m_pool_size_ = si.dwNumberOfProcessors > 0 ? si.dwNumberOfProcessors : 2;
28 |
29 | m_hWorkingEvt = ::CreateEvent(NULL, FALSE, FALSE, NULL);
30 | m_hIdleEvt = ::CreateEvent(NULL, TRUE, FALSE, NULL);
31 | setTerminate(false);
32 |
33 | if (size > 0)
34 | {
35 | m_pool_size_ = size;
36 | }
37 |
38 | for (unsigned int i = 0; i < m_pool_size_; ++i)
39 | {
40 | auto task = std::make_shared(this);
41 | m_workList.push_back(task);
42 | }
43 |
44 | return true;
45 | }
46 |
47 | void SevenWorkerPool::Uninit()
48 | {
49 | Terminate();
50 | FOR_EACH_THREAD0(Join);
51 | ::CloseHandle(m_hWorkingEvt);
52 | ::CloseHandle(m_hIdleEvt);
53 | ::DeleteCriticalSection(&m_csObj);
54 | }
55 |
56 |
57 | void SevenWorkerPool::Terminate()
58 | {
59 | {
60 | AUTO_SCOPE_LOCK();
61 | while(!m_taskList.empty())
62 | {
63 | m_taskList.pop();
64 | }
65 | }
66 | setTerminate(true);
67 | ::SetEvent(m_hIdleEvt);
68 | ::SetEvent(m_hWorkingEvt);
69 | }
70 |
71 |
72 | bool SevenWorkerPool::runTask()
73 | {
74 | SevenTask task;
75 | {
76 | AUTO_SCOPE_LOCK();
77 |
78 | if (!m_taskList.empty())
79 | {
80 | task = m_taskList.front();
81 | m_taskList.pop();
82 | }
83 | }
84 | if (task)
85 | {
86 | task();
87 | if (task.Notify)
88 | {
89 | task.Notify();
90 | }
91 | }
92 | else
93 | {
94 | ::SignalObjectAndWait(m_hIdleEvt, m_hWorkingEvt, INFINITE, FALSE);
95 | }
96 |
97 | return !needTerminate();
98 | }
99 |
100 | //void SevenWorkerPool::SetPoolSize(unsigned int size)
101 | //{
102 | // m_poolSize = size;
103 | //}
104 |
105 | void SevenWorkerPool::SubmitTask(const std::function& task, const std::function& notify)
106 | {
107 | AUTO_SCOPE_LOCK();
108 | m_taskList.push(SevenTask(task, notify));
109 | ::SetEvent(m_hWorkingEvt);
110 | }
111 |
112 | unsigned int SevenWorkerPool::GetPoolSize() const
113 | {
114 | return m_pool_size_;
115 | }
116 |
117 | bool SevenWorkerPool::IsWorking()
118 | {
119 | {
120 | AUTO_SCOPE_LOCK();
121 | if (!m_taskList.empty())
122 | {
123 | return true;
124 | }
125 | }
126 |
127 | for (auto itFind = m_workList.begin(); itFind != m_workList.end(); ++itFind)
128 | {
129 | if ((*itFind)->GetThreadState() == SevenThread::THREAD_RUNNING)
130 | {
131 | return true;
132 | }
133 | }
134 | return false;
135 | }
136 |
137 |
138 | bool SevenWorkerPool::needTerminate()
139 | {
140 | return 1 == ::InterlockedCompareExchange(&m_lTerminate, 1, 1);
141 | }
142 |
143 | void SevenWorkerPool::setTerminate(bool yes)
144 | {
145 | ::InterlockedExchange(&m_lTerminate, static_cast(yes));
146 | }
147 |
148 | SimpleMemoryPool::SimpleMemoryPool()
149 | {
150 | ::InitializeCriticalSectionAndSpinCount(&m_csObj, 5000);
151 | const size_t memsize = 1024;
152 | for (unsigned int i = 0; i < 5; ++i)
153 | {
154 | put(memsize);
155 | }
156 | }
157 |
158 | SimpleMemoryPool::~SimpleMemoryPool()
159 | {
160 | ::DeleteCriticalSection(&m_csObj);
161 | }
162 |
163 | SimpleMemoryPool::MemTuple* SimpleMemoryPool::put(size_t size)
164 | {
165 | AUTO_SCOPE_LOCK();
166 | m_pool.push_back(std::make_tuple(size,
167 | std::shared_ptr(new byte[size], std::default_delete()), FALSE));
168 | return &m_pool.back();
169 | }
170 |
171 | void* SimpleMemoryPool::Get(size_t size)
172 | {
173 | AUTO_SCOPE_LOCK();
174 | const auto& find_item = std::find_if(m_pool.begin(), m_pool.end(),
175 | [&size](const std::tuple< size_t, std::shared_ptr, BOOL >& value)->bool
176 | {
177 | return !std::get<2>(value) && std::get<0>(value) >= size;
178 | });
179 | MemTuple* _item = nullptr;
180 | if (find_item == m_pool.end())
181 | {
182 | _item = put(size);
183 | }
184 | else
185 | {
186 | _item = &*find_item;
187 | }
188 | std::get<2>(*_item) = TRUE;
189 | return std::get<1>(*_item).get();
190 | }
191 |
192 | bool SimpleMemoryPool::Done(void* baseaddr)
193 | {
194 | AUTO_SCOPE_LOCK();
195 | const auto& find_item = std::find_if(m_pool.begin(), m_pool.end(),
196 | [&baseaddr](const std::tuple< size_t, std::shared_ptr, BOOL >& value)->bool
197 | {
198 | return std::get<1>(value).get() == baseaddr;
199 | });
200 | if (find_item != m_pool.end())
201 | {
202 | std::get<2>(*find_item) = FALSE;
203 | return true;
204 | }
205 | return false;
206 | }
207 |
208 | void SimpleMemoryPool::Shrink_to_fit()
209 | {
210 | AUTO_SCOPE_LOCK();
211 | m_pool.remove_if([](const MemTuple& value)->bool
212 | {
213 | return !std::get<2>(value);
214 | });
215 | }
216 |
217 | } // namespace SevenZip
--------------------------------------------------------------------------------
/SevenZip++/SevenWorkerPool.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lniwn/SevenZip/edbd25b0dc9aca47cd7bbb4183d16292d64f7d3a/SevenZip++/SevenWorkerPool.h
--------------------------------------------------------------------------------
/SevenZip++/SevenZip++.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | MBCS Debug
6 | Win32
7 |
8 |
9 | MBCS Debug
10 | x64
11 |
12 |
13 | MBCS Release
14 | Win32
15 |
16 |
17 | MBCS Release
18 | x64
19 |
20 |
21 | Unicode Debug
22 | Win32
23 |
24 |
25 | Unicode Debug
26 | x64
27 |
28 |
29 | Unicode Release
30 | Win32
31 |
32 |
33 | Unicode Release
34 | x64
35 |
36 |
37 |
38 | {F7380108-3CF4-427B-A89F-9CD64BB7836A}
39 | Win32Proj
40 | SevenZip
41 |
42 |
43 |
44 | StaticLibrary
45 | true
46 | Unicode
47 | v100
48 |
49 |
50 | StaticLibrary
51 | true
52 | MultiByte
53 | v100
54 |
55 |
56 | StaticLibrary
57 | true
58 | Unicode
59 | v140
60 |
61 |
62 | StaticLibrary
63 | true
64 | MultiByte
65 | v140
66 |
67 |
68 | StaticLibrary
69 | false
70 | true
71 | Unicode
72 | v100
73 |
74 |
75 | StaticLibrary
76 | false
77 | true
78 | MultiByte
79 | v100
80 |
81 |
82 | StaticLibrary
83 | false
84 | true
85 | Unicode
86 | v140
87 |
88 |
89 | StaticLibrary
90 | false
91 | true
92 | MultiByte
93 | v140
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 | $(SolutionDir)Build\$(Platform)\Lib\
125 | 7zpp_ud
126 | $(Platform)\$(Configuration)\
127 | F:\work\code\open source\7z1506-src\CPP;$(IncludePath)
128 |
129 |
130 | $(SolutionDir)Build\$(Platform)\Lib\
131 | 7zpp_ad
132 | $(Platform)\$(Configuration)\
133 | F:\work\code\open source\7z1506-src\CPP;$(IncludePath)
134 |
135 |
136 | $(SolutionDir)Build\$(Platform)\Lib\
137 | 7zpp_ud
138 |
139 |
140 | $(SolutionDir)Build\$(Platform)\Lib\
141 | 7zpp_ad
142 |
143 |
144 | $(SolutionDir)Build\$(Platform)\Lib\
145 | 7zpp_u
146 | $(Platform)\$(Configuration)\
147 | F:\work\code\open source\7z1506-src\CPP;$(IncludePath)
148 |
149 |
150 | $(SolutionDir)Build\$(Platform)\Lib\
151 | 7zpp_a
152 | $(Platform)\$(Configuration)\
153 | F:\work\code\open source\7z1506-src\CPP;$(IncludePath)
154 |
155 |
156 | $(SolutionDir)Build\$(Platform)\Lib\
157 | 7zpp_u
158 |
159 |
160 | $(SolutionDir)Build\$(Platform)\Lib\
161 | 7zpp_a
162 |
163 |
164 | 7zpp
165 |
166 |
167 |
168 | Use
169 | Level3
170 | Disabled
171 | WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)
172 | ..\..\..\External\lzma\CPP;..\7zip\CPP;%(AdditionalIncludeDirectories)
173 | $(OutDir)$(TargetName).pdb
174 |
175 |
176 | Windows
177 | true
178 |
179 |
180 | $(OutDir)$(TargetName)$(TargetExt)
181 |
182 |
183 |
184 |
185 | Use
186 | Level3
187 | Disabled
188 | WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)
189 | ..\..\..\External\lzma\CPP;..\7zip\CPP;%(AdditionalIncludeDirectories)
190 | $(OutDir)$(TargetName).pdb
191 |
192 |
193 | Windows
194 | true
195 |
196 |
197 | $(OutDir)$(TargetName)$(TargetExt)
198 |
199 |
200 |
201 |
202 | Use
203 | Level3
204 | Disabled
205 | WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)
206 | ..\..\..\External\lzma\CPP;..\7zip\CPP;%(AdditionalIncludeDirectories)
207 | $(OutDir)$(TargetName).pdb
208 |
209 |
210 | Windows
211 | true
212 |
213 |
214 |
215 |
216 | Use
217 | Level3
218 | Disabled
219 | WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)
220 | ..\..\..\External\lzma\CPP;..\7zip\CPP;%(AdditionalIncludeDirectories)
221 | $(OutDir)$(TargetName).pdb
222 |
223 |
224 | Windows
225 | true
226 |
227 |
228 |
229 |
230 | Level3
231 | Use
232 | MaxSpeed
233 | true
234 | true
235 | WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)
236 | ..\..\..\External\lzma\CPP;..\7zip\CPP;%(AdditionalIncludeDirectories)
237 | $(OutDir)$(TargetName).pdb
238 |
239 |
240 | Windows
241 | true
242 | true
243 | true
244 |
245 |
246 | $(OutDir)$(TargetName)$(TargetExt)
247 |
248 |
249 | xcopy $(OutDir)*.lib ..\Samples\Simple\SevenZip\lib /R /Y /I
250 | xcopy $(OutDir)*.pdb ..\Samples\Simple\SevenZip\lib /R /Y /I
251 | xcopy $(ProjectDir)7zpp.h ..\Samples\Simple\SevenZip\include /R /Y /I
252 | xcopy $(ProjectDir)7zString.h ..\Samples\Simple\SevenZip\include /R /Y /I
253 | xcopy $(ProjectDir)CompressionFormat.h ..\Samples\Simple\SevenZip\include /R /Y /I
254 | xcopy $(ProjectDir)CompressionLevel.h ..\Samples\Simple\SevenZip\include /R /Y /I
255 | xcopy $(ProjectDir)Enum.h ..\Samples\Simple\SevenZip\include /R /Y /I
256 | xcopy $(ProjectDir)FileInfo.h ..\Samples\Simple\SevenZip\include /R /Y /I
257 | xcopy $(ProjectDir)SevenCryptLibrary.h ..\Samples\Simple\SevenZip\include /R /Y /I
258 | xcopy $(ProjectDir)SevenZipCompressor.h ..\Samples\Simple\SevenZip\include /R /Y /I
259 | xcopy $(ProjectDir)SevenZipException.h ..\Samples\Simple\SevenZip\include /R /Y /I
260 | xcopy $(ProjectDir)SevenZipExtractor.h ..\Samples\Simple\SevenZip\include /R /Y /I
261 | xcopy $(ProjectDir)SevenZipHasher.h ..\Samples\Simple\SevenZip\include /R /Y /I
262 | xcopy $(ProjectDir)SevenZipLibrary.h ..\Samples\Simple\SevenZip\include /R /Y /I
263 | xcopy $(ProjectDir)NonCopyable.h ..\Samples\Simple\SevenZip\include /R /Y /I
264 |
265 |
266 | 拷贝生成的lib文件
267 |
268 |
269 |
270 |
271 | Level3
272 | Use
273 | MaxSpeed
274 | true
275 | true
276 | WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)
277 | ..\..\..\External\lzma\CPP;..\7zip\CPP;%(AdditionalIncludeDirectories)
278 | $(OutDir)$(TargetName).pdb
279 |
280 |
281 | Windows
282 | true
283 | true
284 | true
285 |
286 |
287 | $(OutDir)$(TargetName)$(TargetExt)
288 |
289 |
290 |
291 |
292 | Level3
293 | Use
294 | MaxSpeed
295 | true
296 | true
297 | WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)
298 | ..\..\..\External\lzma\CPP;..\7zip\CPP;%(AdditionalIncludeDirectories)
299 | $(OutDir)$(TargetName).pdb
300 |
301 |
302 | Windows
303 | true
304 | true
305 | true
306 |
307 |
308 |
309 |
310 | Level3
311 | Use
312 | MaxSpeed
313 | true
314 | true
315 | WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)
316 | ..\..\..\External\lzma\CPP;..\7zip\CPP;%(AdditionalIncludeDirectories)
317 | $(OutDir)$(TargetName).pdb
318 |
319 |
320 | Windows
321 | true
322 | true
323 | true
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 | Create
375 | Create
376 | Create
377 | Create
378 | Create
379 | Create
380 | Create
381 | Create
382 |
383 |
384 |
385 |
386 |
387 |
--------------------------------------------------------------------------------
/SevenZip++/SevenZip++.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Header Files
20 |
21 |
22 | Header Files
23 |
24 |
25 | Header Files
26 |
27 |
28 | Header Files
29 |
30 |
31 | Header Files
32 |
33 |
34 | Header Files
35 |
36 |
37 | Header Files
38 |
39 |
40 | Header Files
41 |
42 |
43 | Header Files
44 |
45 |
46 | Header Files
47 |
48 |
49 | Header Files
50 |
51 |
52 | Header Files
53 |
54 |
55 | Header Files
56 |
57 |
58 | Header Files
59 |
60 |
61 | Header Files
62 |
63 |
64 | Header Files
65 |
66 |
67 | Header Files
68 |
69 |
70 | Header Files
71 |
72 |
73 | Header Files
74 |
75 |
76 | Header Files
77 |
78 |
79 | Header Files
80 |
81 |
82 | Header Files
83 |
84 |
85 | Header Files
86 |
87 |
88 | Header Files
89 |
90 |
91 | Header Files
92 |
93 |
94 | Header Files
95 |
96 |
97 | Header Files
98 |
99 |
100 |
101 |
102 | Source Files
103 |
104 |
105 | Source Files
106 |
107 |
108 | Source Files
109 |
110 |
111 | Source Files
112 |
113 |
114 | Source Files
115 |
116 |
117 | Source Files
118 |
119 |
120 | Source Files
121 |
122 |
123 | Source Files
124 |
125 |
126 | Source Files
127 |
128 |
129 | Source Files
130 |
131 |
132 | Source Files
133 |
134 |
135 | Source Files
136 |
137 |
138 | Source Files
139 |
140 |
141 | Source Files
142 |
143 |
144 | Source Files
145 |
146 |
147 | Source Files
148 |
149 |
150 | Source Files
151 |
152 |
153 | Source Files
154 |
155 |
156 |
--------------------------------------------------------------------------------
/SevenZip++/SevenZip++.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | false
5 |
6 |
--------------------------------------------------------------------------------
/SevenZip++/SevenZip++2008.vcproj:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
15 |
18 |
19 |
20 |
21 |
22 |
29 |
32 |
35 |
38 |
41 |
44 |
57 |
60 |
63 |
66 |
70 |
73 |
76 |
79 |
82 |
85 |
86 |
93 |
96 |
99 |
102 |
105 |
109 |
122 |
125 |
128 |
131 |
135 |
138 |
141 |
144 |
147 |
150 |
151 |
159 |
162 |
165 |
168 |
171 |
174 |
187 |
190 |
193 |
196 |
200 |
203 |
206 |
209 |
212 |
215 |
216 |
224 |
227 |
230 |
233 |
236 |
240 |
253 |
256 |
259 |
262 |
266 |
269 |
272 |
275 |
278 |
281 |
282 |
289 |
292 |
295 |
298 |
301 |
304 |
317 |
320 |
323 |
326 |
330 |
333 |
336 |
339 |
342 |
345 |
346 |
353 |
356 |
359 |
362 |
365 |
369 |
382 |
385 |
388 |
391 |
395 |
398 |
401 |
404 |
407 |
410 |
411 |
419 |
422 |
425 |
428 |
431 |
434 |
447 |
450 |
453 |
456 |
460 |
463 |
466 |
469 |
472 |
475 |
476 |
484 |
487 |
490 |
493 |
496 |
500 |
513 |
516 |
519 |
522 |
526 |
529 |
532 |
535 |
538 |
541 |
542 |
543 |
544 |
545 |
546 |
551 |
554 |
555 |
558 |
559 |
562 |
563 |
566 |
567 |
570 |
571 |
574 |
575 |
578 |
579 |
582 |
583 |
586 |
587 |
590 |
591 |
594 |
595 |
598 |
599 |
602 |
603 |
606 |
609 |
613 |
614 |
617 |
621 |
622 |
625 |
629 |
630 |
633 |
637 |
638 |
641 |
645 |
646 |
649 |
653 |
654 |
657 |
661 |
662 |
665 |
669 |
670 |
671 |
672 |
677 |
680 |
681 |
684 |
685 |
688 |
689 |
692 |
693 |
696 |
697 |
700 |
701 |
704 |
705 |
708 |
709 |
712 |
713 |
716 |
717 |
720 |
721 |
724 |
725 |
728 |
729 |
732 |
733 |
736 |
737 |
740 |
741 |
744 |
745 |
748 |
749 |
752 |
753 |
756 |
757 |
760 |
761 |
762 |
767 |
768 |
771 |
772 |
773 |
774 |
775 |
776 |
--------------------------------------------------------------------------------
/SevenZip++/SevenZip++2013.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | MBCS Debug
6 | Win32
7 |
8 |
9 | MBCS Debug
10 | x64
11 |
12 |
13 | MBCS Release
14 | Win32
15 |
16 |
17 | MBCS Release
18 | x64
19 |
20 |
21 | Unicode Debug
22 | Win32
23 |
24 |
25 | Unicode Debug
26 | x64
27 |
28 |
29 | Unicode Release
30 | Win32
31 |
32 |
33 | Unicode Release
34 | x64
35 |
36 |
37 |
38 | SevenZip++
39 | {87675A89-D1C2-4C3D-ABA6-497E75A89962}
40 | SevenZip
41 | Win32Proj
42 |
43 |
44 |
45 | StaticLibrary
46 | v120
47 | Unicode
48 | true
49 |
50 |
51 | StaticLibrary
52 | v120
53 | Unicode
54 |
55 |
56 | StaticLibrary
57 | v120
58 | MultiByte
59 | true
60 |
61 |
62 | StaticLibrary
63 | v120
64 | MultiByte
65 |
66 |
67 | StaticLibrary
68 | v120
69 | Unicode
70 | true
71 |
72 |
73 | StaticLibrary
74 | v120
75 | Unicode
76 |
77 |
78 | StaticLibrary
79 | v120
80 | Unicode
81 | true
82 |
83 |
84 | StaticLibrary
85 | v120
86 | Unicode
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 | <_ProjectFileVersion>12.0.30501.0
118 |
119 |
120 | $(SolutionDir)Lib\
121 | $(Configuration)\
122 | .lib
123 | 7zpp_ad
124 |
125 |
126 | $(SolutionDir)$(Platform)\$(Configuration)\
127 | $(Platform)\$(Configuration)\
128 | 7zpp_ad
129 |
130 |
131 | $(SolutionDir)Lib\
132 | $(Configuration)\
133 | .lib
134 | 7zpp_a
135 |
136 |
137 | $(SolutionDir)$(Platform)\$(Configuration)\
138 | $(Platform)\$(Configuration)\
139 | 7zpp_a
140 |
141 |
142 | $(SolutionDir)Lib\
143 | $(Configuration)\
144 | 7zpp_ud
145 |
146 |
147 | $(SolutionDir)$(Platform)\$(Configuration)\
148 | $(Platform)\$(Configuration)\
149 | 7zpp_ud
150 |
151 |
152 | $(SolutionDir)Lib\
153 | $(Configuration)\
154 | 7zpp_u
155 |
156 |
157 | $(SolutionDir)$(Platform)\$(Configuration)\
158 | $(Platform)\$(Configuration)\
159 | 7zpp_u
160 |
161 |
162 |
163 | Disabled
164 | ..\..\..\External\lzma\CPP;..\7zip\CPP;%(AdditionalIncludeDirectories)
165 | WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)
166 | true
167 | EnableFastChecks
168 | MultiThreadedDebugDLL
169 | Use
170 | $(OutDir)7zpp_ad.pdb
171 | Level3
172 | EditAndContinue
173 |
174 |
175 | $(OutDir)7zpp_ad.lib
176 |
177 |
178 |
179 |
180 | X64
181 |
182 |
183 | Disabled
184 | ..\..\..\External\lzma\CPP;%(AdditionalIncludeDirectories)
185 | WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)
186 | true
187 | EnableFastChecks
188 | MultiThreadedDebugDLL
189 | Use
190 | $(OutDir)7zpp_ad.pdb
191 | Level3
192 | ProgramDatabase
193 |
194 |
195 | $(OutDir)7zpp_ad.lib
196 |
197 |
198 |
199 |
200 | MaxSpeed
201 | true
202 | ..\..\..\External\lzma\CPP;..\7zip\CPP;%(AdditionalIncludeDirectories)
203 | WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)
204 | MultiThreadedDLL
205 | true
206 | Use
207 | $(OutDir)7zpp_a.pdb
208 | Level3
209 | ProgramDatabase
210 |
211 |
212 | $(OutDir)7zpp_a.lib
213 |
214 |
215 |
216 |
217 | X64
218 |
219 |
220 | MaxSpeed
221 | true
222 | ..\..\..\External\lzma\CPP;%(AdditionalIncludeDirectories)
223 | WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)
224 | MultiThreadedDLL
225 | true
226 | Use
227 | $(OutDir)7zpp_a.pdb
228 | Level3
229 | ProgramDatabase
230 |
231 |
232 | $(OutDir)7zpp_a.lib
233 |
234 |
235 |
236 |
237 | Disabled
238 | ..\..\..\External\lzma\CPP;..\7zip\CPP;%(AdditionalIncludeDirectories)
239 | WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)
240 | true
241 | EnableFastChecks
242 | MultiThreadedDebugDLL
243 | Use
244 | $(OutDir)7zpp_ud.pdb
245 | Level3
246 | EditAndContinue
247 |
248 |
249 | $(OutDir)7zpp_ud.lib
250 |
251 |
252 |
253 |
254 | X64
255 |
256 |
257 | Disabled
258 | ..\..\..\External\lzma\CPP;%(AdditionalIncludeDirectories)
259 | WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)
260 | true
261 | EnableFastChecks
262 | MultiThreadedDebugDLL
263 | Use
264 | $(OutDir)7zpp_ud.pdb
265 | Level3
266 | ProgramDatabase
267 |
268 |
269 | $(OutDir)7zpp_ud.lib
270 |
271 |
272 |
273 |
274 | MaxSpeed
275 | true
276 | ..\..\..\External\lzma\CPP;..\7zip\CPP;%(AdditionalIncludeDirectories)
277 | WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)
278 | MultiThreadedDLL
279 | true
280 | Use
281 | $(OutDir)7zpp_u.pdb
282 | Level3
283 | ProgramDatabase
284 |
285 |
286 | $(OutDir)7zpp_u.lib
287 |
288 |
289 |
290 |
291 | X64
292 |
293 |
294 | MaxSpeed
295 | true
296 | ..\..\..\External\lzma\CPP;%(AdditionalIncludeDirectories)
297 | WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)
298 | MultiThreadedDLL
299 | true
300 | Use
301 | $(OutDir)7zpp_u.pdb
302 | Level3
303 | ProgramDatabase
304 |
305 |
306 | $(OutDir)7zpp_u.lib
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 | Create
325 | Create
326 | Create
327 | Create
328 | Create
329 | Create
330 | Create
331 | Create
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
--------------------------------------------------------------------------------
/SevenZip++/SevenZipCompressor.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "SevenZipCompressor.h"
3 | #include "GUIDs.h"
4 | #include "FileSys.h"
5 | #include "ArchiveUpdateCallback.h"
6 | #include "OutStreamWrapper.h"
7 | #include "PropVariant.h"
8 |
9 | namespace SevenZip
10 | {
11 |
12 | using namespace intl;
13 |
14 |
15 | const TString SearchPatternAllFiles = _T( "*" );
16 |
17 | CComPtr< IOutArchive > GetArchiveWriter(const SevenZipLibrary& library, const CompressionFormatEnum& format)
18 | {
19 | const GUID* guid = NULL;
20 |
21 | switch (format)
22 | {
23 | case CompressionFormat::Zip:
24 | guid = &CLSID_CFormatZip;
25 | break;
26 |
27 | case CompressionFormat::GZip:
28 | guid = &CLSID_CFormatGZip;
29 | break;
30 |
31 | case CompressionFormat::BZip2:
32 | guid = &CLSID_CFormatBZip2;
33 | break;
34 |
35 | case CompressionFormat::Rar:
36 | guid = &CLSID_CFormatRar;
37 | break;
38 |
39 | case CompressionFormat::Tar:
40 | guid = &CLSID_CFormatTar;
41 | break;
42 |
43 | case CompressionFormat::Iso:
44 | guid = &CLSID_CFormatIso;
45 | break;
46 |
47 | case CompressionFormat::Cab:
48 | guid = &CLSID_CFormatCab;
49 | break;
50 |
51 | case CompressionFormat::Lzma:
52 | guid = &CLSID_CFormatLzma;
53 | break;
54 |
55 | case CompressionFormat::Lzma86:
56 | guid = &CLSID_CFormatLzma86;
57 | break;
58 |
59 | default:
60 | guid = &CLSID_CFormat7z;
61 | break;
62 | }
63 |
64 |
65 |
66 | CComPtr< IOutArchive > archive;
67 | library.CreateObject(*guid, IID_IOutArchive, reinterpret_cast< void** >(&archive));
68 |
69 | return archive;
70 | }
71 |
72 | SevenZipCompressor::SevenZipCompressor( const SevenZipLibrary& library, const TString& archivePath )
73 | : m_library( library )
74 | , m_archivePath( archivePath )
75 | {
76 | }
77 |
78 | SevenZipCompressor::~SevenZipCompressor()
79 | {
80 | }
81 |
82 | void SevenZipCompressor::SetCompressionFormat(const CompressionFormatEnum& format)
83 | {
84 | m_compressionFormat = format;
85 | }
86 |
87 | void SevenZipCompressor::SetCompressionLevel( const CompressionLevelEnum& level )
88 | {
89 | m_compressionLevel = level;
90 | }
91 |
92 | void SevenZipCompressor::CompressDirectory( const TString& directory, bool includeSubdirs )
93 | {
94 | FindAndCompressFiles(
95 | directory,
96 | SearchPatternAllFiles,
97 | FileSys::GetPath( directory ),
98 | includeSubdirs );
99 | }
100 |
101 | void SevenZipCompressor::CompressFiles( const TString& directory, const TString& searchFilter, bool includeSubdirs )
102 | {
103 | FindAndCompressFiles(
104 | directory,
105 | searchFilter,
106 | directory,
107 | includeSubdirs );
108 | }
109 |
110 | void SevenZipCompressor::CompressAllFiles( const TString& directory, bool includeSubdirs )
111 | {
112 | FindAndCompressFiles(
113 | directory,
114 | SearchPatternAllFiles,
115 | directory,
116 | includeSubdirs );
117 | }
118 |
119 | void SevenZipCompressor::CompressFile( const TString& filePath )
120 | {
121 | std::vector< FilePathInfo > files = FileSys::GetFile( filePath );
122 |
123 | if ( files.empty() )
124 | {
125 | throw SevenZipException( StrFmt( _T( "File \"%s\" does not exist" ), filePath.c_str() ) );
126 | }
127 |
128 | CompressFilesToArchive( TString(), files );
129 | }
130 |
131 | CComPtr< IStream > SevenZipCompressor::OpenArchiveStream()
132 | {
133 | CComPtr< IStream > fileStream = FileSys::OpenFileToWrite( m_archivePath );
134 | if ( fileStream == NULL )
135 | {
136 | throw SevenZipException( StrFmt( _T( "Could not create archive \"%s\"" ), m_archivePath.c_str() ) );
137 | }
138 | return fileStream;
139 | }
140 |
141 | void SevenZipCompressor::FindAndCompressFiles( const TString& directory, const TString& searchPattern, const TString& pathPrefix, bool recursion )
142 | {
143 | if ( !FileSys::DirectoryExists( directory ) )
144 | {
145 | throw SevenZipException( StrFmt( _T( "Directory \"%s\" does not exist" ), directory.c_str() ) );
146 | }
147 |
148 | if ( FileSys::IsDirectoryEmptyRecursive( directory ) )
149 | {
150 | throw SevenZipException( StrFmt( _T( "Directory \"%s\" is empty" ), directory.c_str() ) );
151 | }
152 |
153 | std::vector< FilePathInfo > files = FileSys::GetFilesInDirectory( directory, searchPattern, recursion );
154 | CompressFilesToArchive( pathPrefix, files );
155 | }
156 |
157 | void SevenZipCompressor::CompressFilesToArchive( const TString& pathPrefix, const std::vector< FilePathInfo >& filePaths )
158 | {
159 | CComPtr< IOutArchive > archiver = GetArchiveWriter(m_library, m_compressionFormat);
160 |
161 | SetCompressionProperties( archiver );
162 |
163 | CComPtr< OutStreamWrapper > outFile = new OutStreamWrapper( OpenArchiveStream() );
164 | CComPtr< ArchiveUpdateCallback > callback = new ArchiveUpdateCallback( pathPrefix, filePaths );
165 |
166 | HRESULT hr = archiver->UpdateItems( outFile, (UInt32) filePaths.size(), callback );
167 | if ( hr != S_OK ) // returning S_FALSE also indicates error
168 | {
169 | throw SevenZipException( GetCOMErrMsg( _T( "Create archive" ), hr ) );
170 | }
171 | }
172 |
173 | void SevenZipCompressor::SetCompressionProperties( IUnknown* outArchive )
174 | {
175 | const size_t numProps = 1;
176 | const wchar_t* names[numProps] = { L"x" };
177 | CPropVariant values[numProps] = { static_cast< UInt32 >( m_compressionLevel.GetValue() ) };
178 |
179 | CComPtr< ISetProperties > setter;
180 | outArchive->QueryInterface( IID_ISetProperties, reinterpret_cast< void** >( &setter ) );
181 | if ( setter == NULL )
182 | {
183 | throw SevenZipException( _T( "Archive does not support setting compression properties" ) );
184 | }
185 |
186 | HRESULT hr = setter->SetProperties( names, values, numProps );
187 | if ( hr != S_OK )
188 | {
189 | throw SevenZipException( GetCOMErrMsg( _T( "Setting compression properties" ), hr ) );
190 | }
191 | }
192 |
193 | }
194 |
--------------------------------------------------------------------------------
/SevenZip++/SevenZipCompressor.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 |
4 | #include
5 | #include
6 | #include "SevenZipLibrary.h"
7 | #include "FileInfo.h"
8 | #include "CompressionFormat.h"
9 | #include "CompressionLevel.h"
10 |
11 |
12 | namespace SevenZip
13 | {
14 | class SevenZipCompressor
15 | {
16 | private:
17 |
18 | const SevenZipLibrary& m_library;
19 | TString m_archivePath;
20 | CompressionFormatEnum m_compressionFormat;
21 | CompressionLevelEnum m_compressionLevel;
22 |
23 | public:
24 |
25 | SevenZipCompressor( const SevenZipLibrary& library, const TString& archivePath );
26 | virtual ~SevenZipCompressor();
27 |
28 | void SetCompressionFormat( const CompressionFormatEnum& format );
29 | void SetCompressionLevel( const CompressionLevelEnum& level );
30 |
31 | // Includes the last directory as the root in the archive, e.g. specifying "C:\Temp\MyFolder"
32 | // makes "MyFolder" the single root item in archive with the files within it included.
33 | virtual void CompressDirectory( const TString& directory, bool includeSubdirs = true );
34 |
35 | // Excludes the last directory as the root in the archive, its contents are at root instead. E.g.
36 | // specifying "C:\Temp\MyFolder" make the files in "MyFolder" the root items in the archive.
37 | virtual void CompressFiles( const TString& directory, const TString& searchFilter, bool includeSubdirs = true );
38 | virtual void CompressAllFiles( const TString& directory, bool includeSubdirs = true );
39 |
40 | // Compress just this single file as the root item in the archive.
41 | virtual void CompressFile( const TString& filePath );
42 |
43 | private:
44 |
45 | CComPtr< IStream > OpenArchiveStream();
46 | void FindAndCompressFiles( const TString& directory, const TString& searchPattern, const TString& pathPrefix, bool recursion );
47 | void CompressFilesToArchive( const TString& pathPrefix, const std::vector< intl::FilePathInfo >& filePaths );
48 | void SetCompressionProperties( IUnknown* outArchive );
49 | };
50 | }
51 |
--------------------------------------------------------------------------------
/SevenZip++/SevenZipException.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "SevenZipException.h"
3 |
4 |
5 | namespace SevenZip
6 | {
7 |
8 | TString StrFmt( const TCHAR* format, ... )
9 | {
10 | TString result;
11 | TCHAR* buffer;
12 | int sz;
13 | va_list args;
14 |
15 | va_start( args, format );
16 |
17 | sz = _vsctprintf( format, args ) + 1;
18 | buffer = new TCHAR[sz];
19 | _vsntprintf_s( buffer, sz, _TRUNCATE, format, args );
20 | result = buffer;
21 | delete [] buffer;
22 |
23 | va_end( args );
24 |
25 | return result;
26 | }
27 |
28 | TString GetWinErrMsg( const TString& contextMessage, DWORD lastError )
29 | {
30 | // TODO: use FormatMessage to get the appropriate message from the
31 | return StrFmt( _T( "%s: GetLastError = %lu" ), contextMessage.c_str(), lastError );
32 | }
33 |
34 | TString GetCOMErrMsg( const TString& contextMessage, HRESULT lastError )
35 | {
36 | // TODO: use FormatMessage to get the appropriate message from the
37 | return StrFmt( _T( "%s: HRESULT = 0x%08X" ), contextMessage.c_str(), lastError );
38 | }
39 |
40 | SevenZipException::SevenZipException()
41 | {
42 | }
43 |
44 | SevenZipException::SevenZipException( const TString& message )
45 | : m_message( message )
46 | {
47 | }
48 |
49 | SevenZipException::~SevenZipException()
50 | {
51 | }
52 |
53 | const TString& SevenZipException::GetMessage() const
54 | {
55 | return m_message;
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/SevenZip++/SevenZipException.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 |
4 | #include
5 | #include "7zString.h"
6 |
7 |
8 | namespace SevenZip
9 | {
10 | TString StrFmt( const TCHAR* format, ... );
11 | TString GetWinErrMsg( const TString& contextMessage, DWORD lastError );
12 | TString GetCOMErrMsg( const TString& contextMessage, HRESULT lastError );
13 |
14 |
15 | class SevenZipException
16 | {
17 | protected:
18 |
19 | TString m_message;
20 |
21 | public:
22 |
23 | SevenZipException();
24 | SevenZipException( const TString& message );
25 | virtual ~SevenZipException();
26 |
27 | const TString& GetMessage() const;
28 | };
29 | }
30 |
--------------------------------------------------------------------------------
/SevenZip++/SevenZipExtractor.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "SevenZipExtractor.h"
3 | #include "GUIDs.h"
4 | #include "FileSys.h"
5 | #include "ArchiveOpenCallback.h"
6 | #include "ArchiveExtractCallback.h"
7 | #include "InStreamWrapper.h"
8 |
9 |
10 | namespace SevenZip
11 | {
12 |
13 | using namespace intl;
14 |
15 |
16 | CComPtr< IInArchive > GetArchiveReader( const SevenZipLibrary& library, const CompressionFormatEnum& format )
17 | {
18 | const GUID* guid = NULL;
19 |
20 | switch ( format )
21 | {
22 | case CompressionFormat::Zip:
23 | guid = &CLSID_CFormatZip;
24 | break;
25 |
26 | case CompressionFormat::GZip:
27 | guid = &CLSID_CFormatGZip;
28 | break;
29 |
30 | case CompressionFormat::BZip2:
31 | guid = &CLSID_CFormatBZip2;
32 | break;
33 |
34 | case CompressionFormat::Rar:
35 | guid = &CLSID_CFormatRar;
36 | break;
37 |
38 | case CompressionFormat::Tar:
39 | guid = &CLSID_CFormatTar;
40 | break;
41 |
42 | case CompressionFormat::Iso:
43 | guid = &CLSID_CFormatIso;
44 | break;
45 |
46 | case CompressionFormat::Cab:
47 | guid = &CLSID_CFormatCab;
48 | break;
49 |
50 | case CompressionFormat::Lzma:
51 | guid = &CLSID_CFormatLzma;
52 | break;
53 |
54 | case CompressionFormat::Lzma86:
55 | guid = &CLSID_CFormatLzma86;
56 | break;
57 |
58 | default:
59 | guid = &CLSID_CFormat7z;
60 | break;
61 | }
62 |
63 | CComPtr< IInArchive > archive;
64 | library.CreateObject( *guid, IID_IInArchive, reinterpret_cast< void** >( &archive ) );
65 | return archive;
66 | }
67 |
68 |
69 | SevenZipExtractor::SevenZipExtractor( const SevenZipLibrary& library, const TString& archivePath )
70 | : m_library( library )
71 | , m_archivePath( archivePath )
72 | , m_format( CompressionFormat::SevenZip )
73 | {
74 | }
75 |
76 | SevenZipExtractor::~SevenZipExtractor()
77 | {
78 | }
79 |
80 | void SevenZipExtractor::SetCompressionFormat( const CompressionFormatEnum& format )
81 | {
82 | m_format = format;
83 | }
84 |
85 | void SevenZipExtractor::ExtractArchive( const TString& destDirectory )
86 | {
87 | CComPtr< IStream > fileStream = FileSys::OpenFileToRead( m_archivePath );
88 | if ( fileStream == NULL )
89 | {
90 | throw SevenZipException( StrFmt( _T( "Could not open archive \"%s\"" ), m_archivePath.c_str() ) );
91 | }
92 |
93 | ExtractArchive( fileStream, destDirectory );
94 | }
95 |
96 | void SevenZipExtractor::ExtractArchive( const CComPtr< IStream >& archiveStream, const TString& destDirectory )
97 | {
98 | CComPtr< IInArchive > archive = GetArchiveReader( m_library, m_format );
99 | CComPtr< InStreamWrapper > inFile = new InStreamWrapper( archiveStream );
100 | CComPtr< ArchiveOpenCallback > openCallback = new ArchiveOpenCallback();
101 |
102 | HRESULT hr = archive->Open( inFile, 0, openCallback );
103 | if ( hr != S_OK )
104 | {
105 | throw SevenZipException( GetCOMErrMsg( _T( "Open archive" ), hr ) );
106 | }
107 |
108 | CComPtr< ArchiveExtractCallback > extractCallback = new ArchiveExtractCallback( archive, destDirectory );
109 |
110 | hr = archive->Extract( NULL, -1, false, extractCallback );
111 | if ( hr != S_OK ) // returning S_FALSE also indicates error
112 | {
113 | throw SevenZipException( GetCOMErrMsg( _T( "Extract archive" ), hr ) );
114 | }
115 | }
116 |
117 | }
118 |
--------------------------------------------------------------------------------
/SevenZip++/SevenZipExtractor.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 |
4 | #include "SevenZipLibrary.h"
5 | #include "CompressionFormat.h"
6 |
7 |
8 | namespace SevenZip
9 | {
10 | class SevenZipExtractor
11 | {
12 | private:
13 |
14 | const SevenZipLibrary& m_library;
15 | TString m_archivePath;
16 | CompressionFormatEnum m_format;
17 |
18 | public:
19 |
20 | SevenZipExtractor( const SevenZipLibrary& library, const TString& archivePath );
21 | virtual ~SevenZipExtractor();
22 |
23 | void SetCompressionFormat( const CompressionFormatEnum& format );
24 |
25 | virtual void ExtractArchive( const TString& directory );
26 |
27 | private:
28 |
29 | void ExtractArchive( const CComPtr< IStream >& archiveStream, const TString& directory );
30 | };
31 | }
32 |
--------------------------------------------------------------------------------
/SevenZip++/SevenZipHasher.cpp:
--------------------------------------------------------------------------------
1 | #include "StdAfx.h"
2 | #include <7zip/ICoder.h>
3 | #include "SevenZipHasher.h"
4 | #include
5 | #include "FileSys.h"
6 | #include
7 | #include "SevenWorkerPool.h"
8 |
9 | namespace SevenZip
10 | {
11 | static union { char c[4]; unsigned long mylong; } endian_test = {{ 'l', '?', '?', 'b' } };
12 | #define ENDIANNESS ((char)endian_test.mylong)
13 |
14 | SevenZipHasher::SevenZipHasher(const SevenZipLibrary& seven, const SevenCryptLibrary& crypt)
15 | :m_seven(seven), m_crypt(crypt)
16 | {
17 | m_threadpool = new SevenWorkerPool;
18 | m_mempool = new SimpleMemoryPool;
19 |
20 | m_threadpool->Init();
21 | ::InitializeCriticalSectionAndSpinCount(&m_csObj, 5000);
22 | }
23 |
24 |
25 | SevenZipHasher::~SevenZipHasher(void)
26 | {
27 | m_threadpool->Uninit();
28 | delete m_threadpool;
29 | delete m_mempool;
30 | ::DeleteCriticalSection(&m_csObj);
31 | }
32 |
33 |
34 | void SevenZipHasher::readFile(std::ifstream* _file, const TCHAR* file_path)
35 | {
36 | _file->open(file_path, std::ios::binary);
37 | if (!_file->good())
38 | {
39 | throw SevenZipException(StrFmt(_T("Open %s failed"), file_path));
40 | }
41 | //std::ios::pos_type file_length = 0;
42 | //_file->seekg(0, _file->end);
43 | //file_length = _file->tellg();
44 | //_file->seekg(0, _file->beg);
45 | }
46 |
47 | void SevenZipHasher::submitTask(NHasherCate::HasherCate c, const TString& file_path, const std::function& result_call)
48 | {
49 | auto task = std::bind(&SevenZipHasher::fileHashTask, this, c, file_path);
50 | m_threadpool->SubmitTask(task, std::bind(result_call, file_path));
51 | }
52 |
53 |
54 | void SevenZipHasher::filesHash(NHasherCate::HasherCate c, const TCHAR* direct, const TCHAR* pattern, const std::function& result_call)
55 | {
56 | {
57 | AUTO_SCOPE_LOCK();
58 | m_filesHash.clear();
59 | }
60 | auto files = intl::FileSys::GetFilesInDirectory(direct, pattern, true);
61 |
62 | for (auto it = files.begin(); it != files.end(); ++it)
63 | {
64 | submitTask(c, it->FilePath, result_call);
65 | }
66 | }
67 |
68 |
69 | void SevenZipHasher::filesHash(NHasherCate::HasherCate c, const std::vector& files, const std::function& result_call)
70 | {
71 | {
72 | AUTO_SCOPE_LOCK();
73 | m_filesHash.clear();
74 | }
75 |
76 | for (auto it = files.begin(); it != files.end(); ++it)
77 | {
78 | submitTask(c, *it, result_call);
79 | }
80 | }
81 |
82 |
83 | void SevenZipHasher::fileHashTask(NHasherCate::HasherCate c, TString file_path)
84 | {
85 | auto hash = fileHash(c, file_path.c_str());
86 | {
87 | AUTO_SCOPE_LOCK();
88 | //m_filesHash.push_back(std::make_tuple(hash, file_path));
89 | m_filesHash[file_path] = hash;
90 | }
91 | }
92 |
93 | void SevenZipHasher::onTaskCallback(const UserTaskCallback& user_func, const TString& file_path)
94 | {
95 | std::string hash_value;
96 | {
97 | AUTO_SCOPE_LOCK();
98 | auto itFind = m_filesHash.find(file_path);
99 | if (itFind != m_filesHash.end())
100 | {
101 | hash_value = itFind->second;
102 | }
103 | }
104 | user_func(file_path, hash_value);
105 | }
106 |
107 | std::string SevenZipHasher::fileHash(NHasherCate::HasherCate c, const TCHAR* file_path)
108 | {
109 | std::string dst_buf;
110 | std::ifstream _file;
111 | readFile(&_file, file_path);
112 | switch(c)
113 | {
114 | case NHasherCate::CRC32:
115 | case NHasherCate::SHA1:
116 | case NHasherCate::SHA256:
117 | case NHasherCate::CRC64:
118 | case NHasherCate::BLAKE2sp:
119 | {
120 | auto read_buf = reinterpret_cast(m_mempool->Get(INNER_MEM_SIZE));
121 |
122 | IHasher* pHasher = getHasher(c);
123 | pHasher->Init();
124 |
125 | _file.read(read_buf, INNER_MEM_SIZE);
126 | std::streamsize readed = 0;
127 | while (0 != (readed = _file.gcount()))
128 | {
129 | pHasher->Update(read_buf, static_cast(readed));
130 | _file.read(read_buf, INNER_MEM_SIZE);
131 | }
132 | m_mempool->Done(read_buf);
133 |
134 | //auto digest_buf = std::unique_ptr(new byte[pHasher->GetDigestSize()], std::default_delete());
135 | auto digest_buf = reinterpret_cast(m_mempool->Get(pHasher->GetDigestSize()));
136 | pHasher->Final(digest_buf);
137 | dst_buf = byteHex(digest_buf, pHasher->GetDigestSize());
138 | pHasher->Release();
139 | m_mempool->Done(digest_buf);
140 | }
141 | break;
142 | case NHasherCate::MD5:
143 | {
144 | return fileMd5(&_file);
145 | }
146 | break;
147 | }
148 | return dst_buf;
149 | }
150 |
151 |
152 | std::string SevenZipHasher::fileMd5(std::ifstream* _file)
153 | {
154 | std::string dst_buf;
155 | //auto read_buf = std::unique_ptr(new byte[INNER_MEM_SIZE], std::default_delete());
156 | auto read_buf = reinterpret_cast(m_mempool->Get(INNER_MEM_SIZE));
157 | MD5_CTX ctx;
158 | m_crypt.MD5Init(&ctx);
159 |
160 | _file->read(read_buf, INNER_MEM_SIZE);
161 | std::streamsize readed = 0;
162 | while (readed = _file->gcount())
163 | {
164 | m_crypt.MD5Update(&ctx, read_buf, static_cast(readed));
165 | _file->read(read_buf, INNER_MEM_SIZE);
166 | }
167 | m_mempool->Done(read_buf);
168 |
169 | m_crypt.MD5Final(&ctx);
170 | const unsigned int md5_length = 16;
171 |
172 | return byteHex(ctx.digest, md5_length);
173 | }
174 |
175 | std::string SevenZipHasher::memoryHash(NHasherCate::HasherCate c, const void* data, unsigned int length)
176 | {
177 | std::string dst_buf;
178 | switch(c)
179 | {
180 | case NHasherCate::CRC32:
181 | case NHasherCate::SHA1:
182 | case NHasherCate::SHA256:
183 | case NHasherCate::CRC64:
184 | case NHasherCate::BLAKE2sp:
185 | {
186 | IHasher* pHasher = getHasher(c);
187 |
188 | pHasher->Init();
189 | pHasher->Update(data, length);
190 | auto digest_len = pHasher->GetDigestSize();
191 |
192 | //auto _inner_buf = std::unique_ptr(new byte[digest_len], std::default_delete());
193 | auto _inner_buf = reinterpret_cast(m_mempool->Get(digest_len));
194 | pHasher->Final(_inner_buf);
195 | dst_buf = byteHex(_inner_buf, digest_len);
196 | pHasher->Release();
197 | m_mempool->Done(_inner_buf);
198 | }
199 | break;
200 | case NHasherCate::MD5:
201 | {
202 | return memoryMd5(data, length);
203 | }
204 | break;
205 | }
206 | return dst_buf;
207 | }
208 |
209 |
210 | IHasher* SevenZipHasher::getHasher(NHasherCate::HasherCate c)
211 | {
212 | IHashers* pHashers;
213 | m_seven.GetHashers(&pHashers);
214 |
215 | IHasher* pHasher = nullptr;
216 | PROPVARIANT prop_id;
217 | auto hr = pHashers->GetHasherProp(c, NMethodPropID::kID, &prop_id);
218 | if (FAILED(hr))
219 | {
220 | pHashers->Release();
221 | throw SevenZipException(GetCOMErrMsg(_T("memoryHash"), hr));
222 | }
223 | PROPVARIANT prop_name;
224 | hr = pHashers->GetHasherProp(c, NMethodPropID::kName, &prop_name);
225 | if (FAILED(hr))
226 | {
227 | pHashers->Release();
228 | throw SevenZipException(GetCOMErrMsg(_T("memoryHash"), hr));
229 | }
230 |
231 | auto _id = hashToId(c);
232 | auto _name = hashToName(c);
233 | if (_id != prop_id.uiVal || _name.compare(prop_name.bstrVal) != 0)
234 | {
235 | pHashers->Release();
236 | throw SevenZipException(StrFmt(_T("Hasher id %d name %s is mismatching"), _id, _name.c_str()));
237 | }
238 |
239 | hr = pHashers->CreateHasher(c, &pHasher);
240 | if (FAILED(hr))
241 | {
242 | pHashers->Release();
243 | throw SevenZipException(GetCOMErrMsg(_T("memoryHash"), hr));
244 | }
245 | pHashers->Release();
246 | return pHasher;
247 | }
248 |
249 |
250 | std::string SevenZipHasher::memoryMd5(const void* data, unsigned int length)
251 | {
252 | MD5_CTX ctx;
253 | m_crypt.MD5Init(&ctx);
254 | m_crypt.MD5Update(&ctx, data, length);
255 | m_crypt.MD5Final(&ctx);
256 | const unsigned int md5_length = 16;
257 |
258 | return byteHex(ctx.digest, md5_length);
259 | }
260 |
261 |
262 | unsigned short SevenZipHasher::hashToId(NHasherCate::HasherCate c)
263 | {
264 | unsigned short id = -1;
265 | switch(c)
266 | {
267 | case NHasherCate::CRC32:
268 | id = 1;
269 | break;
270 | case NHasherCate::SHA1:
271 | id = 513;
272 | break;
273 | case NHasherCate::SHA256:
274 | id = 10;
275 | break;
276 | case NHasherCate::CRC64:
277 | id = 4;
278 | break;
279 | case NHasherCate::BLAKE2sp:
280 | id = 514;
281 | break;
282 | case NHasherCate::MD5:
283 | id = -1;
284 | break;
285 | }
286 | return id;
287 | }
288 |
289 |
290 | std::wstring SevenZipHasher::hashToName(NHasherCate::HasherCate c)
291 | {
292 | switch(c)
293 | {
294 | case NHasherCate::CRC32:
295 | return L"CRC32";
296 | break;
297 | case NHasherCate::SHA1:
298 | return L"SHA1";
299 | break;
300 | case NHasherCate::SHA256:
301 | return L"SHA256";
302 | break;
303 | case NHasherCate::CRC64:
304 | return L"CRC64";
305 | break;
306 | case NHasherCate::BLAKE2sp:
307 | return L"BLAKE2sp";
308 | break;
309 | case NHasherCate::MD5:
310 | return L"MD5";
311 | break;
312 | }
313 | return L"";
314 | }
315 |
316 |
317 | std::string SevenZipHasher::byteHex(const byte* src, unsigned int src_len)
318 | {
319 | std::string hexstr;
320 |
321 | auto innerMem = reinterpret_cast(m_mempool->Get(INNER_MEM_SIZE));
322 | switch (src_len)
323 | {
324 | case sizeof(UInt32):
325 | {
326 | auto result = *reinterpret_cast(src);
327 | sprintf_s (innerMem, INNER_MEM_SIZE, "%08X", result);
328 | }
329 |
330 | break;
331 | case sizeof(UInt64):
332 | {
333 | auto result = *reinterpret_cast(src);
334 | sprintf_s (innerMem, INNER_MEM_SIZE, "%016I64X", result);
335 | }
336 |
337 | break;
338 | default:
339 | for (unsigned int i = 0; i < src_len; ++i)
340 | {
341 | sprintf_s (&(innerMem[i << 1]), 3, "%02X", src[i]);
342 | }
343 | break;
344 | }
345 |
346 | hexstr = reinterpret_cast(innerMem);
347 | m_mempool->Done(innerMem);
348 | return hexstr;
349 | }
350 |
351 |
352 | TString SevenZipHasher::strTotstr(const std::string& _src)
353 | {
354 |
355 | #ifdef _UNICODE
356 | auto dst_buf = reinterpret_cast(m_mempool->Get(INNER_MEM_SIZE));
357 | size_t converted;
358 | mbstowcs_s(&converted, dst_buf, INNER_MEM_SIZE>>1, _src.c_str(), _src.length());
359 | m_mempool->Done(dst_buf);
360 | return dst_buf;
361 | #else
362 | return _src;
363 | #endif
364 |
365 |
366 | }
367 |
368 |
369 | } // namespace SevenZip
--------------------------------------------------------------------------------
/SevenZip++/SevenZipHasher.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lniwn/SevenZip/edbd25b0dc9aca47cd7bbb4183d16292d64f7d3a/SevenZip++/SevenZipHasher.h
--------------------------------------------------------------------------------
/SevenZip++/SevenZipLibrary.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include <7zip/ICoder.h>
3 | #include "SevenZipLibrary.h"
4 |
5 |
6 | namespace SevenZip
7 | {
8 |
9 | const TString DefaultSevenZipLibrary = _T( "7z.dll" );
10 |
11 | SevenZipLibrary::SevenZipLibrary()
12 | : m_dll( NULL )
13 | , m_func( NULL )
14 | {
15 | }
16 |
17 | SevenZipLibrary::~SevenZipLibrary()
18 | {
19 | Free();
20 | }
21 |
22 | void SevenZipLibrary::Load()
23 | {
24 | Load( DefaultSevenZipLibrary );
25 | }
26 |
27 | void SevenZipLibrary::Load( const TString& libraryPath )
28 | {
29 | Free();
30 | m_dll = LoadLibrary( libraryPath.c_str() );
31 | if ( m_dll == NULL )
32 | {
33 | throw SevenZipException( GetWinErrMsg( _T( "LoadLibrary" ), GetLastError() ) );
34 | }
35 |
36 | m_func = reinterpret_cast< TCreateObject >( GetProcAddress( m_dll, "CreateObject" ) );
37 | if ( m_func == NULL )
38 | {
39 | Free();
40 | throw SevenZipException( _T( "Loaded library is missing required CreateObject function" ) );
41 | }
42 |
43 | m_hashers = reinterpret_cast< TGetHashers >( GetProcAddress( m_dll, "GetHashers" ) );
44 | if ( m_hashers == NULL )
45 | {
46 | Free();
47 | throw SevenZipException( _T( "Loaded library is missing required GetHashers function" ) );
48 | }
49 | }
50 |
51 | void SevenZipLibrary::Free()
52 | {
53 | if ( m_dll != NULL )
54 | {
55 | FreeLibrary( m_dll );
56 | m_dll = NULL;
57 | m_func = NULL;
58 | }
59 | }
60 |
61 | void SevenZipLibrary::CreateObject( const GUID& clsID, const GUID& interfaceID, void** outObject ) const
62 | {
63 | if ( m_func == NULL )
64 | {
65 | throw SevenZipException( DefaultSevenZipLibrary + _T( " is not loaded" ) );
66 | }
67 |
68 | HRESULT hr = m_func( &clsID, &interfaceID, outObject );
69 | if ( FAILED( hr ) )
70 | {
71 | throw SevenZipException( GetCOMErrMsg( _T( "CreateObject" ), hr ) );
72 | }
73 | }
74 |
75 | void SevenZipLibrary::GetHashers(IHashers **hashers) const
76 | {
77 | if ( m_hashers == NULL )
78 | {
79 | throw SevenZipException( DefaultSevenZipLibrary + _T( " is not loaded" ) );
80 | }
81 |
82 | auto hr = m_hashers(hashers);
83 | if ( FAILED( hr ) )
84 | {
85 | throw SevenZipException( GetCOMErrMsg( _T( "GetHashers" ), hr ) );
86 | }
87 | }
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/SevenZip++/SevenZipLibrary.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "SevenZipException.h"
4 |
5 | struct IHashers;
6 | namespace SevenZip
7 | {
8 | class SevenZipLibrary
9 | {
10 | private:
11 | SevenZipLibrary(const SevenZipLibrary&);
12 | SevenZipLibrary& operator=(const SevenZipLibrary&);
13 |
14 | public:
15 | SevenZipLibrary();
16 | ~SevenZipLibrary();
17 |
18 | void Load();
19 | void Load( const TString& libraryPath );
20 | void Free();
21 |
22 | void CreateObject( const GUID& clsID, const GUID& interfaceID, void** outObject ) const;
23 | void GetHashers(IHashers **) const;
24 |
25 | private:
26 |
27 | typedef UINT32 (WINAPI * TCreateObject)( const GUID* clsID, const GUID* interfaceID, void** outObject );
28 | typedef HRESULT (WINAPI *TGetHashers)(IHashers **);
29 |
30 | HMODULE m_dll;
31 | TCreateObject m_func;
32 | TGetHashers m_hashers;
33 | };
34 | }
35 |
--------------------------------------------------------------------------------
/SevenZip++/stdafx.cpp:
--------------------------------------------------------------------------------
1 | // stdafx.cpp : source file that includes just the standard includes
2 | // SevenZip++.pch will be the pre-compiled header
3 | // stdafx.obj will contain the pre-compiled type information
4 |
5 | #include "stdafx.h"
6 |
7 | // TODO: reference any additional headers you need in STDAFX.H
8 | // and not in this file
9 |
--------------------------------------------------------------------------------
/SevenZip++/stdafx.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 |
4 | #include "targetver.h"
5 | #define WIN32_LEAN_AND_MEAN
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include "7zString.h"
11 | #include "NonCopyable.h"
--------------------------------------------------------------------------------
/SevenZip++/targetver.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | // Including SDKDDKVer.h defines the highest available Windows platform.
4 |
5 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
6 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
7 |
8 | #include
9 |
--------------------------------------------------------------------------------