summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/lzma/CPP/7zip/UI/Common
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/lzma/CPP/7zip/UI/Common')
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/ArchiveCommandLine.cpp1017
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/ArchiveCommandLine.h75
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp2293
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/ArchiveExtractCallback.h396
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/ArchiveName.cpp186
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/ArchiveName.h15
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/ArchiveOpenCallback.cpp303
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/ArchiveOpenCallback.h197
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/Bench.cpp3668
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/Bench.h92
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/DefaultName.cpp2
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/DefaultName.h4
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/DirItem.h321
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/EnumDirItems.cpp1166
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/EnumDirItems.h29
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/ExitCode.h4
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/Extract.cpp220
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/Extract.h30
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/ExtractMode.h14
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/ExtractingFilePath.cpp113
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/ExtractingFilePath.h22
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/HashCalc.cpp1883
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/HashCalc.h283
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/IFileExtractCallback.h92
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/LoadCodecs.cpp637
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/LoadCodecs.h236
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/OpenArchive.cpp937
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/OpenArchive.h136
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/PropIDUtils.cpp361
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/PropIDUtils.h10
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/Property.h4
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/SetProperties.cpp38
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/SetProperties.h4
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/SortUtils.h4
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/StdAfx.h7
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/TempFiles.h4
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/Update.cpp1136
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/Update.h108
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/UpdateAction.h4
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/UpdateCallback.cpp519
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/UpdateCallback.h182
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/UpdatePair.cpp162
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/UpdatePair.h4
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/UpdateProduce.cpp8
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/UpdateProduce.h17
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/WorkDir.cpp46
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/WorkDir.h4
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/ZipRegistry.h104
48 files changed, 12791 insertions, 4306 deletions
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveCommandLine.cpp b/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveCommandLine.cpp
index 832ec66d9c5..2bdbc418243 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveCommandLine.cpp
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveCommandLine.cpp
@@ -8,27 +8,53 @@
#ifndef UNDER_CE
#include <io.h>
#endif
+#else
+// for isatty()
+#include <unistd.h>
#endif
+
#include <stdio.h>
+#ifdef Z7_LARGE_PAGES
+#include "../../../../C/Alloc.h"
+#endif
+
+#include "../../../Common/IntToString.h"
#include "../../../Common/ListFileUtils.h"
#include "../../../Common/StringConvert.h"
#include "../../../Common/StringToInt.h"
+#include "../../../Windows/ErrorMsg.h"
#include "../../../Windows/FileDir.h"
#include "../../../Windows/FileName.h"
+#include "../../../Windows/System.h"
#ifdef _WIN32
#include "../../../Windows/FileMapping.h"
+#include "../../../Windows/MemoryLock.h"
#include "../../../Windows/Synchronization.h"
#endif
#include "ArchiveCommandLine.h"
#include "EnumDirItems.h"
-#include "SortUtils.h"
#include "Update.h"
#include "UpdateAction.h"
extern bool g_CaseSensitive;
+extern bool g_PathTrailReplaceMode;
+
+#ifdef Z7_LARGE_PAGES
+extern
+bool g_LargePagesMode;
+bool g_LargePagesMode = false;
+#endif
+
+/*
+#ifdef ENV_HAVE_LSTAT
+EXTERN_C_BEGIN
+extern int global_use_lstat;
+EXTERN_C_END
+#endif
+*/
#ifdef UNDER_CE
@@ -36,13 +62,18 @@ extern bool g_CaseSensitive;
#else
-#if _MSC_VER >= 1400
-#define MY_isatty_fileno(x) _isatty(_fileno(x))
-#else
-#define MY_isatty_fileno(x) isatty(fileno(x))
-#endif
-
-#define MY_IS_TERMINAL(x) (MY_isatty_fileno(x) != 0);
+// #define MY_isatty_fileno(x) (isatty(fileno(x)))
+// #define MY_IS_TERMINAL(x) (MY_isatty_fileno(x) != 0);
+static inline bool MY_IS_TERMINAL(FILE *x)
+{
+ return (
+ #if defined(_MSC_VER) && (_MSC_VER >= 1400)
+ _isatty(_fileno(x))
+ #else
+ isatty(fileno(x))
+ #endif
+ != 0);
+}
#endif
@@ -59,17 +90,6 @@ static bool StringToUInt32(const wchar_t *s, UInt32 &v)
return *end == 0;
}
-CArcCmdLineException::CArcCmdLineException(const char *a, const wchar_t *u)
-{
- (*this) += MultiByteToUnicodeString(a);
- if (u)
- {
- this->Add_LF();
- (*this) += u;
- }
-}
-
-int g_CodePage = -1;
namespace NKey {
enum Enum
@@ -113,6 +133,8 @@ enum Enum
kSfx,
kEmail,
kHash,
+ // kHashGenFile,
+ kHashDir,
kStdIn,
kStdOut,
@@ -121,26 +143,38 @@ enum Enum
kListfileCharSet,
kConsoleCharSet,
kTechMode,
+ kListFields,
+ kPreserveATime,
kShareForWrite,
+ kStopAfterOpenError,
kCaseSensitive,
kArcNameMode,
+ kUseSlashMark,
kDisableWildcardParsing,
kElimDup,
kFullPathMode,
kHardLinks,
+ kSymLinks_AllowDangerous,
kSymLinks,
kNtSecurity,
+
+ kStoreOwnerId,
+ kStoreOwnerName,
+
+ kZoneFile,
kAltStreams,
kReplaceColonForAltStream,
kWriteToAltStreamIfColon,
+ kNameTrailReplace,
+
kDeleteAfterCompressing,
kSetArcMTime
- #ifndef _NO_CRYPTO
+ #ifndef Z7_NO_CRYPTO
, kPassword
#endif
};
@@ -149,13 +183,13 @@ enum Enum
static const wchar_t kRecursedIDChar = 'r';
-static const char *kRecursedPostCharSet = "0-";
+static const char * const kRecursedPostCharSet = "0-";
-static const char *k_ArcNameMode_PostCharSet = "sea";
+static const char * const k_ArcNameMode_PostCharSet = "sea";
-static const char *k_Stream_PostCharSet = "012";
+static const char * const k_Stream_PostCharSet = "012";
-static inline const EArcNameMode ParseArcNameMode(int postCharIndex)
+static inline EArcNameMode ParseArcNameMode(int postCharIndex)
{
switch (postCharIndex)
{
@@ -173,14 +207,17 @@ namespace NRecursedPostCharIndex {
};
}
-static const char kImmediateNameID = '!';
-static const char kMapNameID = '#';
-static const char kFileListID = '@';
+// static const char
+#define kImmediateNameID '!'
+#ifdef _WIN32
+#define kMapNameID '#'
+#endif
+#define kFileListID '@'
-static const char kSomeCludePostStringMinSize = 2; // at least <@|!><N>ame must be
-static const char kSomeCludeAfterRecursedPostStringMinSize = 2; // at least <@|!><N>ame must be
+static const Byte kSomeCludePostStringMinSize = 2; // at least <@|!><N>ame must be
+static const Byte kSomeCludeAfterRecursedPostStringMinSize = 2; // at least <@|!><N>ame must be
-static const char *kOverwritePostCharSet = "asut";
+static const char * const kOverwritePostCharSet = "asut";
static const NExtract::NOverwriteMode::EEnum k_OverwriteModes[] =
{
@@ -190,125 +227,154 @@ static const NExtract::NOverwriteMode::EEnum k_OverwriteModes[] =
NExtract::NOverwriteMode::kRenameExisting
};
+
+
+#define SWFRM_3(t, mu, mi) t, mu, mi, NULL
+
+#define SWFRM_1(t) SWFRM_3(t, false, 0)
+#define SWFRM_SIMPLE SWFRM_1(NSwitchType::kSimple)
+#define SWFRM_MINUS SWFRM_1(NSwitchType::kMinus)
+#define SWFRM_STRING SWFRM_1(NSwitchType::kString)
+
+#define SWFRM_STRING_SINGL(mi) SWFRM_3(NSwitchType::kString, false, mi)
+#define SWFRM_STRING_MULT(mi) SWFRM_3(NSwitchType::kString, true, mi)
+
+
static const CSwitchForm kSwitchForms[] =
{
- { "?" },
- { "h" },
- { "-help" },
+ { "?", SWFRM_SIMPLE },
+ { "h", SWFRM_SIMPLE },
+ { "-help", SWFRM_SIMPLE },
- { "ba" },
- { "bd" },
- { "bt" },
- { "bb", NSwitchType::kString, false, 0 },
+ { "ba", SWFRM_SIMPLE },
+ { "bd", SWFRM_SIMPLE },
+ { "bt", SWFRM_SIMPLE },
+ { "bb", SWFRM_STRING_SINGL(0) },
{ "bso", NSwitchType::kChar, false, 1, k_Stream_PostCharSet },
{ "bse", NSwitchType::kChar, false, 1, k_Stream_PostCharSet },
{ "bsp", NSwitchType::kChar, false, 1, k_Stream_PostCharSet },
- { "y" },
+ { "y", SWFRM_SIMPLE },
- { "ad" },
+ { "ad", SWFRM_SIMPLE },
{ "ao", NSwitchType::kChar, false, 1, kOverwritePostCharSet},
- { "t", NSwitchType::kString, false, 1 },
- { "stx", NSwitchType::kString, true, 1 },
+ { "t", SWFRM_STRING_SINGL(1) },
+ { "stx", SWFRM_STRING_MULT(1) },
- { "m", NSwitchType::kString, true, 1 },
- { "o", NSwitchType::kString, false, 1 },
- { "w", NSwitchType::kString },
-
- { "i", NSwitchType::kString, true, kSomeCludePostStringMinSize},
- { "x", NSwitchType::kString, true, kSomeCludePostStringMinSize},
- { "ai", NSwitchType::kString, true, kSomeCludePostStringMinSize},
- { "ax", NSwitchType::kString, true, kSomeCludePostStringMinSize},
- { "an" },
+ { "m", SWFRM_STRING_MULT(1) },
+ { "o", SWFRM_STRING_SINGL(1) },
+ { "w", SWFRM_STRING },
+
+ { "i", SWFRM_STRING_MULT(kSomeCludePostStringMinSize) },
+ { "x", SWFRM_STRING_MULT(kSomeCludePostStringMinSize) },
+ { "ai", SWFRM_STRING_MULT(kSomeCludePostStringMinSize) },
+ { "ax", SWFRM_STRING_MULT(kSomeCludePostStringMinSize) },
+ { "an", SWFRM_SIMPLE },
- { "u", NSwitchType::kString, true, 1},
- { "v", NSwitchType::kString, true, 1},
+ { "u", SWFRM_STRING_MULT(1) },
+ { "v", SWFRM_STRING_MULT(1) },
{ "r", NSwitchType::kChar, false, 0, kRecursedPostCharSet },
- { "stm", NSwitchType::kString },
- { "sfx", NSwitchType::kString },
- { "seml", NSwitchType::kString, false, 0},
- { "scrc", NSwitchType::kString, true, 0 },
+ { "stm", SWFRM_STRING },
+ { "sfx", SWFRM_STRING },
+ { "seml", SWFRM_STRING_SINGL(0) },
+ { "scrc", SWFRM_STRING_MULT(0) },
+ // { "scrf", SWFRM_STRING_SINGL(1) },
+ { "shd", SWFRM_STRING_SINGL(1) },
- { "si", NSwitchType::kString },
- { "so" },
-
- { "slp", NSwitchType::kMinus },
- { "scs", NSwitchType::kString },
- { "scc", NSwitchType::kString },
- { "slt" },
-
- { "ssw" },
- { "ssc", NSwitchType::kMinus },
+ { "si", SWFRM_STRING },
+ { "so", SWFRM_SIMPLE },
+
+ { "slp", SWFRM_STRING },
+ { "scs", SWFRM_STRING },
+ { "scc", SWFRM_STRING },
+ { "slt", SWFRM_SIMPLE },
+ { "slf", SWFRM_STRING_SINGL(1) },
+
+ { "ssp", SWFRM_SIMPLE },
+ { "ssw", SWFRM_SIMPLE },
+ { "sse", SWFRM_SIMPLE },
+ { "ssc", SWFRM_MINUS },
{ "sa", NSwitchType::kChar, false, 1, k_ArcNameMode_PostCharSet },
- { "spd" },
- { "spe", NSwitchType::kMinus },
- { "spf", NSwitchType::kString, false, 0 },
+ { "spm", SWFRM_STRING_SINGL(0) },
+ { "spd", SWFRM_SIMPLE },
+ { "spe", SWFRM_MINUS },
+ { "spf", SWFRM_STRING_SINGL(0) },
- { "snh", NSwitchType::kMinus },
- { "snl", NSwitchType::kMinus },
- { "sni" },
- { "sns", NSwitchType::kMinus },
- { "snr" },
- { "snc" },
+ { "snh", SWFRM_MINUS },
+ { "snld", SWFRM_MINUS },
+ { "snl", SWFRM_MINUS },
+ { "sni", SWFRM_SIMPLE },
+
+ { "snoi", SWFRM_MINUS },
+ { "snon", SWFRM_MINUS },
- { "sdel" },
- { "stl" }
+ { "snz", SWFRM_STRING_SINGL(0) },
+ { "sns", SWFRM_MINUS },
+ { "snr", SWFRM_SIMPLE },
+ { "snc", SWFRM_SIMPLE },
+
+ { "snt", SWFRM_MINUS },
+
+ { "sdel", SWFRM_SIMPLE },
+ { "stl", SWFRM_SIMPLE }
- #ifndef _NO_CRYPTO
- , { "p", NSwitchType::kString }
+ #ifndef Z7_NO_CRYPTO
+ , { "p", SWFRM_STRING }
#endif
};
-static const wchar_t *kUniversalWildcard = L"*";
+static const char * const kUniversalWildcard = "*";
static const unsigned kMinNonSwitchWords = 1;
static const unsigned kCommandIndex = 0;
-// static const char *kUserErrorMessage = "Incorrect command line";
-static const char *kCannotFindListFile = "Cannot find listfile";
-static const char *kIncorrectListFile = "Incorrect item in listfile.\nCheck charset encoding and -scs switch.";
-static const char *kTerminalOutError = "I won't write compressed data to a terminal";
-static const char *kSameTerminalError = "I won't write data and program's messages to same stream";
-static const char *kEmptyFilePath = "Empty file path";
-static const char *kCannotFindArchive = "Cannot find archive";
+// static const char * const kUserErrorMessage = "Incorrect command line";
+// static const char * const kCannotFindListFile = "Cannot find listfile";
+static const char * const kIncorrectListFile = "Incorrect item in listfile.\nCheck charset encoding and -scs switch.";
+static const char * const kTerminalOutError = "I won't write compressed data to a terminal";
+static const char * const kSameTerminalError = "I won't write data and program's messages to same stream";
+static const char * const kEmptyFilePath = "Empty file path";
bool CArcCommand::IsFromExtractGroup() const
{
- switch (CommandType)
+ switch ((int)CommandType)
{
case NCommandType::kTest:
case NCommandType::kExtract:
case NCommandType::kExtractFull:
return true;
+ default:
+ return false;
}
- return false;
}
NExtract::NPathMode::EEnum CArcCommand::GetPathMode() const
{
- switch (CommandType)
+ switch ((int)CommandType)
{
case NCommandType::kTest:
case NCommandType::kExtractFull:
return NExtract::NPathMode::kFullPaths;
+ default:
+ return NExtract::NPathMode::kNoPaths;
}
- return NExtract::NPathMode::kNoPaths;
}
bool CArcCommand::IsFromUpdateGroup() const
{
- switch (CommandType)
+ switch ((int)CommandType)
{
case NCommandType::kAdd:
case NCommandType::kUpdate:
case NCommandType::kDelete:
case NCommandType::kRename:
return true;
+ default:
+ return false;
}
- return false;
}
static NRecursedType::EEnum GetRecursedTypeFromIndex(int index)
@@ -328,7 +394,7 @@ static const char *g_Commands = "audtexlbih";
static bool ParseArchiveCommand(const UString &commandString, CArcCommand &command)
{
- UString s = commandString;
+ UString s (commandString);
s.MakeLower_Ascii();
if (s.Len() == 1)
{
@@ -351,12 +417,28 @@ static bool ParseArchiveCommand(const UString &commandString, CArcCommand &comma
// ------------------------------------------------------------------
// filenames functions
+struct CNameOption
+{
+ bool Include;
+ bool WildcardMatching;
+ Byte MarkMode;
+ NRecursedType::EEnum RecursedType;
+
+ CNameOption():
+ Include(true),
+ WildcardMatching(true),
+ MarkMode(NWildcard::kMark_FileOrDir),
+ RecursedType(NRecursedType::kNonRecursed)
+ {}
+};
+
+
static void AddNameToCensor(NWildcard::CCensor &censor,
- const UString &name, bool include, NRecursedType::EEnum type, bool wildcardMatching)
+ const CNameOption &nop, const UString &name)
{
bool recursed = false;
- switch (type)
+ switch ((int)nop.RecursedType)
{
case NRecursedType::kWildcardOnlyRecursed:
recursed = DoesNameContainWildcard(name);
@@ -364,8 +446,15 @@ static void AddNameToCensor(NWildcard::CCensor &censor,
case NRecursedType::kRecursed:
recursed = true;
break;
+ default:
+ break;
}
- censor.AddPreItem(include, name, recursed, wildcardMatching);
+
+ NWildcard::CCensorPathProps props;
+ props.Recursive = recursed;
+ props.WildcardMatching = nop.WildcardMatching;
+ props.MarkMode = nop.MarkMode;
+ censor.AddPreItem(nop.Include, name, props);
}
static void AddRenamePair(CObjectVector<CRenamePair> *renamePairs,
@@ -386,9 +475,9 @@ static void AddRenamePair(CObjectVector<CRenamePair> *renamePairs,
val += pair.NewName;
val.Add_LF();
if (type == NRecursedType::kRecursed)
- val.AddAscii("-r");
+ val += "-r";
else if (type == NRecursedType::kWildcardOnlyRecursed)
- val.AddAscii("-r0");
+ val += "-r0";
throw CArcCmdLineException("Unsupported rename command:", val);
}
}
@@ -396,13 +485,26 @@ static void AddRenamePair(CObjectVector<CRenamePair> *renamePairs,
static void AddToCensorFromListFile(
CObjectVector<CRenamePair> *renamePairs,
NWildcard::CCensor &censor,
- LPCWSTR fileName, bool include, NRecursedType::EEnum type, bool wildcardMatching, Int32 codePage)
+ const CNameOption &nop, LPCWSTR fileName, UInt32 codePage)
{
UStringVector names;
- if (!NFind::DoesFileExist(us2fs(fileName)))
+ /*
+ if (!NFind::DoesFileExist_FollowLink(us2fs(fileName)))
throw CArcCmdLineException(kCannotFindListFile, fileName);
- if (!ReadNamesFromListFile(us2fs(fileName), names, codePage))
+ */
+ DWORD lastError = 0;
+ if (!ReadNamesFromListFile2(us2fs(fileName), names, codePage, lastError))
+ {
+ if (lastError != 0)
+ {
+ UString m;
+ m = "The file operation error for listfile";
+ m.Add_LF();
+ m += NError::MyFormatMessage(lastError);
+ throw CArcCmdLineException(m, fileName);
+ }
throw CArcCmdLineException(kIncorrectListFile, fileName);
+ }
if (renamePairs)
{
if ((names.Size() & 1) != 0)
@@ -410,55 +512,73 @@ static void AddToCensorFromListFile(
for (unsigned i = 0; i < names.Size(); i += 2)
{
// change type !!!!
- AddRenamePair(renamePairs, names[i], names[i + 1], type, wildcardMatching);
+ AddRenamePair(renamePairs, names[i], names[i + 1], nop.RecursedType, nop.WildcardMatching);
}
}
else
FOR_VECTOR (i, names)
- AddNameToCensor(censor, names[i], include, type, wildcardMatching);
+ AddNameToCensor(censor, nop, names[i]);
}
static void AddToCensorFromNonSwitchesStrings(
CObjectVector<CRenamePair> *renamePairs,
unsigned startIndex,
NWildcard::CCensor &censor,
- const UStringVector &nonSwitchStrings, NRecursedType::EEnum type,
- bool wildcardMatching,
- bool thereAreSwitchIncludes, Int32 codePage)
+ const UStringVector &nonSwitchStrings,
+ int stopSwitchIndex,
+ const CNameOption &nop,
+ bool thereAreSwitchIncludes, UInt32 codePage)
{
+ // another default
if ((renamePairs || nonSwitchStrings.Size() == startIndex) && !thereAreSwitchIncludes)
- AddNameToCensor(censor, kUniversalWildcard, true, type,
- true // wildcardMatching
- );
+ {
+ /* for rename command: -i switch sets the mask for archive item reading.
+ if (thereAreSwitchIncludes), { we don't use UniversalWildcard. }
+ also for non-rename command: we set UniversalWildcard, only if there are no nonSwitches. */
+ // we use default fileds in (CNameOption) for UniversalWildcard.
+ CNameOption nop2;
+ // recursive mode is not important for UniversalWildcard (*)
+ // nop2.RecursedType = nop.RecursedType; // we don't need it
+ /*
+ nop2.RecursedType = NRecursedType::kNonRecursed;
+ nop2.Include = true;
+ nop2.WildcardMatching = true;
+ nop2.MarkMode = NWildcard::kMark_FileOrDir;
+ */
+ AddNameToCensor(censor, nop2, UString(kUniversalWildcard));
+ }
int oldIndex = -1;
+ if (stopSwitchIndex < 0)
+ stopSwitchIndex = (int)nonSwitchStrings.Size();
+
for (unsigned i = startIndex; i < nonSwitchStrings.Size(); i++)
{
const UString &s = nonSwitchStrings[i];
if (s.IsEmpty())
throw CArcCmdLineException(kEmptyFilePath);
- if (s[0] == kFileListID)
- AddToCensorFromListFile(renamePairs, censor, s.Ptr(1), true, type, wildcardMatching, codePage);
+ if (i < (unsigned)stopSwitchIndex && s[0] == kFileListID)
+ AddToCensorFromListFile(renamePairs, censor, nop, s.Ptr(1), codePage);
else if (renamePairs)
{
if (oldIndex == -1)
- oldIndex = i;
+ oldIndex = (int)i;
else
{
// NRecursedType::EEnum type is used for global wildcard (-i! switches)
- AddRenamePair(renamePairs, nonSwitchStrings[oldIndex], s, NRecursedType::kNonRecursed, wildcardMatching);
+ AddRenamePair(renamePairs, nonSwitchStrings[(unsigned)oldIndex], s, NRecursedType::kNonRecursed, nop.WildcardMatching);
// AddRenamePair(renamePairs, nonSwitchStrings[oldIndex], s, type);
oldIndex = -1;
}
}
else
- AddNameToCensor(censor, s, true, type, wildcardMatching);
+ AddNameToCensor(censor, nop, s);
}
if (oldIndex != -1)
{
- throw CArcCmdLineException("There is no second file name for rename pair:", nonSwitchStrings[oldIndex]);
+ throw CArcCmdLineException("There is no second file name for rename pair:", nonSwitchStrings[(unsigned)oldIndex]);
}
}
@@ -477,35 +597,34 @@ struct CEventSetEnd
}
};
-const char *k_IncorrectMapCommand = "Incorrect Map command";
+static const char * const k_IncorrectMapCommand = "Incorrect Map command";
static const char *ParseMapWithPaths(
NWildcard::CCensor &censor,
- const UString &s2, bool include,
- NRecursedType::EEnum commonRecursedType,
- bool wildcardMatching)
+ const UString &s2,
+ const CNameOption &nop)
{
- UString s = s2;
+ UString s (s2);
int pos = s.Find(L':');
if (pos < 0)
return k_IncorrectMapCommand;
- int pos2 = s.Find(L':', pos + 1);
+ int pos2 = s.Find(L':', (unsigned)(pos + 1));
if (pos2 < 0)
return k_IncorrectMapCommand;
- CEventSetEnd eventSetEnd((const wchar_t *)s + ((unsigned)pos2 + 1));
- s.DeleteFrom(pos2);
+ CEventSetEnd eventSetEnd((const wchar_t *)s + (unsigned)(pos2 + 1));
+ s.DeleteFrom((unsigned)pos2);
UInt32 size;
- if (!StringToUInt32(s.Ptr(pos + 1), size)
+ if (!StringToUInt32(s.Ptr((unsigned)(pos + 1)), size)
|| size < sizeof(wchar_t)
|| size > ((UInt32)1 << 31)
|| size % sizeof(wchar_t) != 0)
return "Unsupported Map data size";
- s.DeleteFrom(pos);
+ s.DeleteFrom((unsigned)pos);
CFileMapping map;
if (map.Open(FILE_MAP_READ, GetSystemString(s)) != 0)
- return "Can not open mapping";
+ return "Cannot open mapping";
LPVOID data = map.Map(FILE_MAP_READ, 0, size);
if (!data)
return "MapViewOfFile error";
@@ -522,7 +641,7 @@ static const char *ParseMapWithPaths(
if (c == 0)
{
// MessageBoxW(0, name, L"7-Zip", 0);
- AddNameToCensor(censor, name, include, commonRecursedType, wildcardMatching);
+ AddNameToCensor(censor, nop, name);
name.Empty();
}
else
@@ -538,17 +657,15 @@ static const char *ParseMapWithPaths(
static void AddSwitchWildcardsToCensor(
NWildcard::CCensor &censor,
- const UStringVector &strings, bool include,
- NRecursedType::EEnum commonRecursedType,
- bool wildcardMatching,
- Int32 codePage)
+ const UStringVector &strings,
+ const CNameOption &nop,
+ UInt32 codePage)
{
const char *errorMessage = NULL;
unsigned i;
for (i = 0; i < strings.Size(); i++)
{
const UString &name = strings[i];
- NRecursedType::EEnum recursedType;
unsigned pos = 0;
if (name.Len() < kSomeCludePostStringMinSize)
@@ -556,37 +673,118 @@ static void AddSwitchWildcardsToCensor(
errorMessage = "Too short switch";
break;
}
-
- if (::MyCharLower_Ascii(name[pos]) == kRecursedIDChar)
+
+ if (!nop.Include)
{
- pos++;
- wchar_t c = name[pos];
- int index = -1;
- if (c <= 0x7F)
- index = FindCharPosInString(kRecursedPostCharSet, (char)c);
- recursedType = GetRecursedTypeFromIndex(index);
- if (index >= 0)
+ if (name.IsEqualTo_Ascii_NoCase("td"))
+ {
+ censor.ExcludeDirItems = true;
+ continue;
+ }
+ if (name.IsEqualTo_Ascii_NoCase("tf"))
+ {
+ censor.ExcludeFileItems = true;
+ continue;
+ }
+ }
+
+ CNameOption nop2 = nop;
+
+ bool type_WasUsed = false;
+ bool recursed_WasUsed = false;
+ bool matching_WasUsed = false;
+ bool error = false;
+
+ for (;;)
+ {
+ wchar_t c = ::MyCharLower_Ascii(name[pos]);
+ if (c == kRecursedIDChar)
+ {
+ if (recursed_WasUsed)
+ {
+ error = true;
+ break;
+ }
+ recursed_WasUsed = true;
+ pos++;
+ c = name[pos];
+ int index = -1;
+ if (c <= 0x7F)
+ index = FindCharPosInString(kRecursedPostCharSet, (char)c);
+ nop2.RecursedType = GetRecursedTypeFromIndex(index);
+ if (index >= 0)
+ {
+ pos++;
+ continue;
+ }
+ }
+
+ if (c == 'w')
+ {
+ if (matching_WasUsed)
+ {
+ error = true;
+ break;
+ }
+ matching_WasUsed = true;
+ nop2.WildcardMatching = true;
pos++;
+ if (name[pos] == '-')
+ {
+ nop2.WildcardMatching = false;
+ pos++;
+ }
+ }
+ else if (c == 'm')
+ {
+ if (type_WasUsed)
+ {
+ error = true;
+ break;
+ }
+ type_WasUsed = true;
+ pos++;
+ nop2.MarkMode = NWildcard::kMark_StrictFile;
+ c = name[pos];
+ if (c == '-')
+ {
+ nop2.MarkMode = NWildcard::kMark_FileOrDir;
+ pos++;
+ }
+ else if (c == '2')
+ {
+ nop2.MarkMode = NWildcard::kMark_StrictFile_IfWildcard;
+ pos++;
+ }
+ }
+ else
+ break;
}
- else
- recursedType = commonRecursedType;
+ if (error)
+ {
+ errorMessage = "inorrect switch";
+ break;
+ }
+
if (name.Len() < pos + kSomeCludeAfterRecursedPostStringMinSize)
{
errorMessage = "Too short switch";
break;
}
- UString tail = name.Ptr(pos + 1);
-
- if (name[pos] == kImmediateNameID)
- AddNameToCensor(censor, tail, include, recursedType, wildcardMatching);
- else if (name[pos] == kFileListID)
- AddToCensorFromListFile(NULL, censor, tail, include, recursedType, wildcardMatching, codePage);
+ const UString tail = name.Ptr(pos + 1);
+
+ const wchar_t c = name[pos];
+
+ if (c == kImmediateNameID)
+ AddNameToCensor(censor, nop2, tail);
+ else if (c == kFileListID)
+ AddToCensorFromListFile(NULL, censor, nop2, tail, codePage);
#ifdef _WIN32
- else if (name[pos] == kMapNameID)
+ else if (c == kMapNameID)
{
- errorMessage = ParseMapWithPaths(censor, tail, include, recursedType, wildcardMatching);
+ errorMessage = ParseMapWithPaths(censor, tail, nop2);
if (errorMessage)
break;
}
@@ -597,88 +795,11 @@ static void AddSwitchWildcardsToCensor(
break;
}
}
+
if (i != strings.Size())
throw CArcCmdLineException(errorMessage, strings[i]);
}
-#ifdef _WIN32
-
-// This code converts all short file names to long file names.
-
-static void ConvertToLongName(const UString &prefix, UString &name)
-{
- if (name.IsEmpty() || DoesNameContainWildcard(name))
- return;
- NFind::CFileInfo fi;
- const FString path = us2fs(prefix + name);
- #ifndef UNDER_CE
- if (NFile::NName::IsDevicePath(path))
- return;
- #endif
- if (fi.Find(path))
- name = fs2us(fi.Name);
-}
-
-static void ConvertToLongNames(const UString &prefix, CObjectVector<NWildcard::CItem> &items)
-{
- FOR_VECTOR (i, items)
- {
- NWildcard::CItem &item = items[i];
- if (item.Recursive || item.PathParts.Size() != 1)
- continue;
- if (prefix.IsEmpty() && item.IsDriveItem())
- continue;
- ConvertToLongName(prefix, item.PathParts.Front());
- }
-}
-
-static void ConvertToLongNames(const UString &prefix, NWildcard::CCensorNode &node)
-{
- ConvertToLongNames(prefix, node.IncludeItems);
- ConvertToLongNames(prefix, node.ExcludeItems);
- unsigned i;
- for (i = 0; i < node.SubNodes.Size(); i++)
- {
- UString &name = node.SubNodes[i].Name;
- if (prefix.IsEmpty() && NWildcard::IsDriveColonName(name))
- continue;
- ConvertToLongName(prefix, name);
- }
- // mix folders with same name
- for (i = 0; i < node.SubNodes.Size(); i++)
- {
- NWildcard::CCensorNode &nextNode1 = node.SubNodes[i];
- for (unsigned j = i + 1; j < node.SubNodes.Size();)
- {
- const NWildcard::CCensorNode &nextNode2 = node.SubNodes[j];
- if (nextNode1.Name.IsEqualTo_NoCase(nextNode2.Name))
- {
- nextNode1.IncludeItems += nextNode2.IncludeItems;
- nextNode1.ExcludeItems += nextNode2.ExcludeItems;
- node.SubNodes.Delete(j);
- }
- else
- j++;
- }
- }
- for (i = 0; i < node.SubNodes.Size(); i++)
- {
- NWildcard::CCensorNode &nextNode = node.SubNodes[i];
- ConvertToLongNames(prefix + nextNode.Name + WCHAR_PATH_SEPARATOR, nextNode);
- }
-}
-
-void ConvertToLongNames(NWildcard::CCensor &censor)
-{
- FOR_VECTOR (i, censor.Pairs)
- {
- NWildcard::CPair &pair = censor.Pairs[i];
- ConvertToLongNames(pair.Prefix, pair.Head);
- }
-}
-
-#endif
-
/*
static NUpdateArchive::NPairAction::EEnum GetUpdatePairActionType(int i)
{
@@ -693,11 +814,11 @@ static NUpdateArchive::NPairAction::EEnum GetUpdatePairActionType(int i)
}
*/
-static const wchar_t *kUpdatePairStateIDSet = L"pqrxyzw";
+static const char * const kUpdatePairStateIDSet = "pqrxyzw";
static const int kUpdatePairStateNotSupportedActions[] = {2, 2, 1, -1, -1, -1, -1};
static const unsigned kNumUpdatePairActions = 4;
-static const char *kUpdateIgnoreItselfPostStringID = "-";
+static const char * const kUpdateIgnoreItselfPostStringID = "-";
static const wchar_t kUpdateNewArchivePostCharID = '!';
@@ -707,8 +828,8 @@ static bool ParseUpdateCommandString2(const UString &command,
for (unsigned i = 0; i < command.Len();)
{
wchar_t c = MyCharLower_Ascii(command[i]);
- int statePos = FindCharPosInString(kUpdatePairStateIDSet, c);
- if (statePos < 0)
+ int statePos = FindCharPosInString(kUpdatePairStateIDSet, (char)c);
+ if (c > 0x7F || statePos < 0)
{
postString = command.Ptr(i);
return true;
@@ -717,9 +838,9 @@ static bool ParseUpdateCommandString2(const UString &command,
if (i >= command.Len())
return false;
c = command[i];
- if (c < '0' || c >= '0' + kNumUpdatePairActions)
+ if (c < '0' || c >= (wchar_t)('0' + kNumUpdatePairActions))
return false;
- unsigned actionPos = c - '0';
+ unsigned actionPos = (unsigned)(c - '0');
actionSet.StateActions[(unsigned)statePos] = (NUpdateArchive::NPairAction::EEnum)(actionPos);
if (kUpdatePairStateNotSupportedActions[(unsigned)statePos] == (int)actionPos)
return false;
@@ -784,7 +905,7 @@ static void SetAddCommandOptions(
CUpdateOptions &options)
{
NUpdateArchive::CActionSet defaultActionSet;
- switch (commandType)
+ switch ((int)commandType)
{
case NCommandType::kAdd:
defaultActionSet = NUpdateArchive::k_ActionSet_Add;
@@ -823,8 +944,10 @@ static void SetAddCommandOptions(
FOR_VECTOR (i, sv)
{
UInt64 size;
- if (!ParseComplexSize(sv[i], size) || size == 0)
+ if (!ParseComplexSize(sv[i], size))
throw CArcCmdLineException("Incorrect volume size:", sv[i]);
+ if (i == sv.Size() - 1 && size == 0)
+ throw CArcCmdLineException("zero size last volume is not allowed");
options.VolumesSizes.Add(size);
}
}
@@ -841,26 +964,37 @@ static void SetMethodOptions(const CParser &parser, CObjectVector<CProperty> &pr
int index = prop.Name.Find(L'=');
if (index >= 0)
{
- prop.Value = prop.Name.Ptr(index + 1);
- prop.Name.DeleteFrom(index);
+ prop.Value = prop.Name.Ptr((unsigned)(index + 1));
+ prop.Name.DeleteFrom((unsigned)index);
}
properties.Add(prop);
}
}
}
-CArcCmdLineParser::CArcCmdLineParser(): parser(ARRAY_SIZE(kSwitchForms)) {}
static inline void SetStreamMode(const CSwitchResult &sw, unsigned &res)
{
if (sw.ThereIs)
- res = sw.PostCharIndex;
+ res = (unsigned)sw.PostCharIndex;
}
+
+#if defined(_WIN32) && !defined(UNDER_CE)
+static void PrintHex(UString &s, UInt64 v)
+{
+ char temp[32];
+ ConvertUInt64ToHex(v, temp);
+ s += temp;
+}
+#endif
+
+
void CArcCmdLineParser::Parse1(const UStringVector &commandStrings,
CArcCmdLineOptions &options)
{
- if (!parser.ParseStrings(kSwitchForms, commandStrings))
+ Parse1Log.Empty();
+ if (!parser.ParseStrings(kSwitchForms, Z7_ARRAY_SIZE(kSwitchForms), commandStrings))
throw CArcCmdLineException(parser.ErrorMessage, parser.ErrorLine);
options.IsInTerminal = MY_IS_TERMINAL(stdin);
@@ -872,6 +1006,11 @@ void CArcCmdLineParser::Parse1(const UStringVector &commandStrings,
options.StdInMode = parser[NKey::kStdIn].ThereIs;
options.StdOutMode = parser[NKey::kStdOut].ThereIs;
options.EnableHeaders = !parser[NKey::kDisableHeaders].ThereIs;
+ if (parser[NKey::kListFields].ThereIs)
+ {
+ const UString &s = parser[NKey::kListFields].PostStrings[0];
+ options.ListFields = GetAnsiString(s);
+ }
options.TechMode = parser[NKey::kTechMode].ThereIs;
options.ShowTime = parser[NKey::kShowTime].ThereIs;
@@ -903,14 +1042,52 @@ void CArcCmdLineParser::Parse1(const UStringVector &commandStrings,
if (parser[NKey::kCaseSensitive].ThereIs)
{
+ options.CaseSensitive =
g_CaseSensitive = !parser[NKey::kCaseSensitive].WithMinus;
- options.CaseSensitiveChange = true;
- options.CaseSensitive = g_CaseSensitive;
+ options.CaseSensitive_Change = true;
}
- options.LargePages = false;
+
+ #if defined(_WIN32) && !defined(UNDER_CE)
+ NSecurity::EnablePrivilege_SymLink();
+ #endif
+
+ // options.LargePages = false;
+
if (parser[NKey::kLargePages].ThereIs)
- options.LargePages = !parser[NKey::kLargePages].WithMinus;
+ {
+ UInt32 slp = 0;
+ const UString &s = parser[NKey::kLargePages].PostStrings[0];
+ if (s.IsEmpty())
+ slp = 1;
+ else if (s != L"-")
+ {
+ if (!StringToUInt32(s, slp))
+ throw CArcCmdLineException("Unsupported switch postfix for -slp", s);
+ }
+
+ #ifdef Z7_LARGE_PAGES
+ if (slp >
+ #if defined(_WIN32) && !defined(UNDER_CE)
+ (unsigned)NSecurity::Get_LargePages_RiskLevel()
+ #else
+ 0
+ #endif
+ )
+ {
+ #ifdef _WIN32 // change it !
+ SetLargePageSize();
+ #endif
+ // note: this process also can inherit that Privilege from parent process
+ g_LargePagesMode =
+ #if defined(_WIN32) && !defined(UNDER_CE)
+ NSecurity::EnablePrivilege_LockMemory();
+ #else
+ true;
+ #endif
+ }
+ #endif
+ }
#ifndef UNDER_CE
@@ -920,32 +1097,83 @@ void CArcCmdLineParser::Parse1(const UStringVector &commandStrings,
const UString &s = parser[NKey::kAffinity].PostStrings[0];
if (!s.IsEmpty())
{
- UInt32 v = 0;
AString a;
a.SetFromWStr_if_Ascii(s);
- if (!a.IsEmpty())
+ Parse1Log += "Set process affinity mask: ";
+
+ #ifdef _WIN32
+
+ UInt64 v = 0;
{
const char *end;
- v = ConvertHexStringToUInt32(a, &end);
+ v = ConvertHexStringToUInt64(a, &end);
if (*end != 0)
a.Empty();
}
if (a.IsEmpty())
throw CArcCmdLineException("Unsupported switch postfix -stm", s);
+
+ {
+ #ifndef _WIN64
+ if (v >= ((UInt64)1 << 32))
+ throw CArcCmdLineException("unsupported value -stm", s);
+ #endif
+ {
+ PrintHex(Parse1Log, v);
+ if (!SetProcessAffinityMask(GetCurrentProcess(), (DWORD_PTR)v))
+ {
+ DWORD lastError = GetLastError();
+ Parse1Log += " : ERROR : ";
+ Parse1Log += NError::MyFormatMessage(lastError);
+ }
+ }
+ }
- #ifdef _WIN32
- SetProcessAffinityMask(GetCurrentProcess(), v);
- #endif
+ #else // _WIN32
+
+ {
+ Parse1Log += a;
+ NSystem::CProcessAffinity aff;
+ aff.CpuZero();
+ for (unsigned i = 0; i < a.Len(); i++)
+ {
+ char c = a[i];
+ unsigned v;
+ if (c >= '0' && c <= '9') v = (unsigned)(c - '0');
+ else if (c >= 'A' && c <= 'F') v = 10 + (unsigned)(c - 'A');
+ else if (c >= 'a' && c <= 'f') v = 10 + (unsigned)(c - 'a');
+ else
+ throw CArcCmdLineException("Unsupported switch postfix -stm", s);
+ for (unsigned k = 0; k < 4; k++)
+ {
+ const unsigned cpu = (a.Len() - 1 - i) * 4 + k;
+ if (v & ((unsigned)1 << k))
+ aff.CpuSet(cpu);
+ }
+ }
+
+ if (!aff.SetProcAffinity())
+ {
+ DWORD lastError = GetLastError();
+ Parse1Log += " : ERROR : ";
+ Parse1Log += NError::MyFormatMessage(lastError);
+ }
+ }
+ #endif // _WIN32
+
+ Parse1Log.Add_LF();
}
}
#endif
}
+
+
struct CCodePagePair
{
const char *Name;
- Int32 CodePage;
+ UInt32 CodePage;
};
static const unsigned kNumByteOnlyCodePages = 3;
@@ -955,8 +1183,8 @@ static const CCodePagePair g_CodePagePairs[] =
{ "utf-8", CP_UTF8 },
{ "win", CP_ACP },
{ "dos", CP_OEMCP },
- { "utf-16le", MY__CP_UTF16 },
- { "utf-16be", MY__CP_UTF16BE }
+ { "utf-16le", Z7_WIN_CP_UTF16 },
+ { "utf-16be", Z7_WIN_CP_UTF16BE }
};
static Int32 FindCharset(const NCommandLineParser::CParser &parser, unsigned keyIndex,
@@ -965,81 +1193,23 @@ static Int32 FindCharset(const NCommandLineParser::CParser &parser, unsigned key
if (!parser[keyIndex].ThereIs)
return defaultVal;
- UString name = parser[keyIndex].PostStrings.Back();
+ UString name (parser[keyIndex].PostStrings.Back());
UInt32 v;
if (StringToUInt32(name, v))
if (v < ((UInt32)1 << 16))
return (Int32)v;
name.MakeLower_Ascii();
- unsigned num = byteOnlyCodePages ? kNumByteOnlyCodePages : ARRAY_SIZE(g_CodePagePairs);
+ const unsigned num = byteOnlyCodePages ? kNumByteOnlyCodePages : Z7_ARRAY_SIZE(g_CodePagePairs);
for (unsigned i = 0;; i++)
{
if (i == num) // to disable warnings from different compilers
throw CArcCmdLineException("Unsupported charset:", name);
const CCodePagePair &pair = g_CodePagePairs[i];
if (name.IsEqualTo(pair.Name))
- return pair.CodePage;
+ return (Int32)pair.CodePage;
}
}
-HRESULT EnumerateDirItemsAndSort(
- NWildcard::CCensor &censor,
- NWildcard::ECensorPathMode censorPathMode,
- const UString &addPathPrefix,
- UStringVector &sortedPaths,
- UStringVector &sortedFullPaths,
- CDirItemsStat &st,
- IDirItemsCallback *callback)
-{
- FStringVector paths;
-
- {
- CDirItems dirItems;
- dirItems.Callback = callback;
- {
- HRESULT res = EnumerateItems(censor, censorPathMode, addPathPrefix, dirItems);
- st = dirItems.Stat;
- RINOK(res);
- }
-
- FOR_VECTOR (i, dirItems.Items)
- {
- const CDirItem &dirItem = dirItems.Items[i];
- if (!dirItem.IsDir())
- paths.Add(dirItems.GetPhyPath(i));
- }
- }
-
- if (paths.Size() == 0)
- throw CArcCmdLineException(kCannotFindArchive);
-
- UStringVector fullPaths;
-
- unsigned i;
-
- for (i = 0; i < paths.Size(); i++)
- {
- FString fullPath;
- NFile::NDir::MyGetFullPathName(paths[i], fullPath);
- fullPaths.Add(fs2us(fullPath));
- }
-
- CUIntVector indices;
- SortFileNames(fullPaths, indices);
- sortedPaths.ClearAndReserve(indices.Size());
- sortedFullPaths.ClearAndReserve(indices.Size());
-
- for (i = 0; i < indices.Size(); i++)
- {
- unsigned index = indices[i];
- sortedPaths.AddInReserved(fs2us(paths[index]));
- sortedFullPaths.AddInReserved(fullPaths[index]);
- if (i > 0 && CompareFileNames(sortedFullPaths[i], sortedFullPaths[i - 1]) == 0)
- throw CArcCmdLineException("Duplicate archive path:", sortedFullPaths[i]);
- }
-
- return S_OK;
-}
static void SetBoolPair(NCommandLineParser::CParser &parser, unsigned switchID, CBoolPair &bp)
{
@@ -1051,7 +1221,7 @@ static void SetBoolPair(NCommandLineParser::CParser &parser, unsigned switchID,
void CArcCmdLineParser::Parse2(CArcCmdLineOptions &options)
{
const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;
- unsigned numNonSwitchStrings = nonSwitchStrings.Size();
+ const unsigned numNonSwitchStrings = nonSwitchStrings.Size();
if (numNonSwitchStrings < kMinNonSwitchWords)
throw CArcCmdLineException("The command must be specified");
@@ -1060,6 +1230,27 @@ void CArcCmdLineParser::Parse2(CArcCmdLineOptions &options)
if (parser[NKey::kHash].ThereIs)
options.HashMethods = parser[NKey::kHash].PostStrings;
+
+ /*
+ if (parser[NKey::kHashGenFile].ThereIs)
+ {
+ const UString &s = parser[NKey::kHashGenFile].PostStrings[0];
+ for (unsigned i = 0 ; i < s.Len();)
+ {
+ const wchar_t c = s[i++];
+ if (!options.HashOptions.ParseFlagCharOption(c, true))
+ {
+ if (c != '=')
+ throw CArcCmdLineException("Unsupported hash mode switch:", s);
+ options.HashOptions.HashFilePath = s.Ptr(i);
+ break;
+ }
+ }
+ }
+ */
+
+ if (parser[NKey::kHashDir].ThereIs)
+ options.ExtractOptions.HashDir = parser[NKey::kHashDir].PostStrings[0];
if (parser[NKey::kElimDup].ThereIs)
{
@@ -1082,31 +1273,51 @@ void CArcCmdLineParser::Parse2(CArcCmdLineOptions &options)
}
}
- NRecursedType::EEnum recursedType;
+ if (parser[NKey::kNameTrailReplace].ThereIs)
+ g_PathTrailReplaceMode = !parser[NKey::kNameTrailReplace].WithMinus;
+
+ CNameOption nop;
+
if (parser[NKey::kRecursed].ThereIs)
- recursedType = GetRecursedTypeFromIndex(parser[NKey::kRecursed].PostCharIndex);
- else
- recursedType = NRecursedType::kNonRecursed;
+ nop.RecursedType = GetRecursedTypeFromIndex(parser[NKey::kRecursed].PostCharIndex);
- bool wildcardMatching = true;
if (parser[NKey::kDisableWildcardParsing].ThereIs)
- wildcardMatching = false;
+ nop.WildcardMatching = false;
+
+ if (parser[NKey::kUseSlashMark].ThereIs)
+ {
+ const UString &s = parser[NKey::kUseSlashMark].PostStrings[0];
+ if (s.IsEmpty())
+ nop.MarkMode = NWildcard::kMark_StrictFile;
+ else if (s.IsEqualTo_Ascii_NoCase("-"))
+ nop.MarkMode = NWildcard::kMark_FileOrDir;
+ else if (s.IsEqualTo_Ascii_NoCase("2"))
+ nop.MarkMode = NWildcard::kMark_StrictFile_IfWildcard;
+ else
+ throw CArcCmdLineException("Unsupported -spm:", s);
+ }
- g_CodePage = FindCharset(parser, NKey::kConsoleCharSet, true, -1);
- Int32 codePage = FindCharset(parser, NKey::kListfileCharSet, false, CP_UTF8);
+
+ options.ConsoleCodePage = FindCharset(parser, NKey::kConsoleCharSet, true, -1);
+
+ UInt32 codePage = (UInt32)FindCharset(parser, NKey::kListfileCharSet, false, CP_UTF8);
bool thereAreSwitchIncludes = false;
-
+
if (parser[NKey::kInclude].ThereIs)
{
thereAreSwitchIncludes = true;
+ nop.Include = true;
AddSwitchWildcardsToCensor(options.Censor,
- parser[NKey::kInclude].PostStrings, true, recursedType, wildcardMatching, codePage);
+ parser[NKey::kInclude].PostStrings, nop, codePage);
}
if (parser[NKey::kExclude].ThereIs)
+ {
+ nop.Include = false;
AddSwitchWildcardsToCensor(options.Censor,
- parser[NKey::kExclude].PostStrings, false, recursedType, wildcardMatching, codePage);
+ parser[NKey::kExclude].PostStrings, nop, codePage);
+ }
unsigned curCommandIndex = kCommandIndex + 1;
bool thereIsArchiveName = !parser[NKey::kNoArName].ThereIs &&
@@ -1114,9 +1325,9 @@ void CArcCmdLineParser::Parse2(CArcCmdLineOptions &options)
options.Command.CommandType != NCommandType::kInfo &&
options.Command.CommandType != NCommandType::kHash;
- bool isExtractGroupCommand = options.Command.IsFromExtractGroup();
- bool isExtractOrList = isExtractGroupCommand || options.Command.CommandType == NCommandType::kList;
- bool isRename = options.Command.CommandType == NCommandType::kRename;
+ const bool isExtractGroupCommand = options.Command.IsFromExtractGroup();
+ const bool isExtractOrList = isExtractGroupCommand || options.Command.CommandType == NCommandType::kList;
+ const bool isRename = options.Command.CommandType == NCommandType::kRename;
if ((isExtractOrList || isRename) && options.StdInMode)
thereIsArchiveName = false;
@@ -1136,15 +1347,17 @@ void CArcCmdLineParser::Parse2(CArcCmdLineOptions &options)
#endif
}
+ nop.Include = true;
AddToCensorFromNonSwitchesStrings(isRename ? &options.UpdateOptions.RenamePairs : NULL,
curCommandIndex, options.Censor,
- nonSwitchStrings, recursedType, wildcardMatching,
+ nonSwitchStrings, parser.StopSwitchIndex,
+ nop,
thereAreSwitchIncludes, codePage);
options.YesToAll = parser[NKey::kYes].ThereIs;
- #ifndef _NO_CRYPTO
+ #ifndef Z7_NO_CRYPTO
options.PasswordEnabled = parser[NKey::kPassword].ThereIs;
if (options.PasswordEnabled)
options.Password = parser[NKey::kPassword].PostStrings[0];
@@ -1164,11 +1377,41 @@ void CArcCmdLineParser::Parse2(CArcCmdLineOptions &options)
SetBoolPair(parser, NKey::kAltStreams, options.AltStreams);
SetBoolPair(parser, NKey::kHardLinks, options.HardLinks);
SetBoolPair(parser, NKey::kSymLinks, options.SymLinks);
+
+ SetBoolPair(parser, NKey::kStoreOwnerId, options.StoreOwnerId);
+ SetBoolPair(parser, NKey::kStoreOwnerName, options.StoreOwnerName);
+
+ CBoolPair symLinks_AllowDangerous;
+ SetBoolPair(parser, NKey::kSymLinks_AllowDangerous, symLinks_AllowDangerous);
+
+
+ /*
+ bool supportSymLink = options.SymLinks.Val;
+
+ if (!options.SymLinks.Def)
+ {
+ if (isExtractOrList)
+ supportSymLink = true;
+ else
+ supportSymLink = false;
+ }
+
+ #ifdef ENV_HAVE_LSTAT
+ if (supportSymLink)
+ global_use_lstat = 1;
+ else
+ global_use_lstat = 0;
+ #endif
+ */
+
if (isExtractOrList)
{
CExtractOptionsBase &eo = options.ExtractOptions;
+ eo.ExcludeDirItems = options.Censor.ExcludeDirItems;
+ eo.ExcludeFileItems = options.Censor.ExcludeFileItems;
+
{
CExtractNtOptions &nt = eo.NtOptions;
nt.NtSecurity = options.NtSecurity;
@@ -1185,10 +1428,33 @@ void CArcCmdLineParser::Parse2(CArcCmdLineOptions &options)
if (!options.SymLinks.Def)
nt.SymLinks.Val = true;
+ nt.SymLinks_AllowDangerous = symLinks_AllowDangerous;
+
nt.ReplaceColonForAltStream = parser[NKey::kReplaceColonForAltStream].ThereIs;
nt.WriteToAltStreamIfColon = parser[NKey::kWriteToAltStreamIfColon].ThereIs;
+
+ nt.ExtractOwner = options.StoreOwnerId.Val; // StoreOwnerName
+
+ if (parser[NKey::kPreserveATime].ThereIs)
+ nt.PreserveATime = true;
+ if (parser[NKey::kShareForWrite].ThereIs)
+ nt.OpenShareForWrite = true;
}
-
+
+ if (parser[NKey::kZoneFile].ThereIs)
+ {
+ eo.ZoneMode = NExtract::NZoneIdMode::kAll;
+ const UString &s = parser[NKey::kZoneFile].PostStrings[0];
+ if (!s.IsEmpty())
+ {
+ if (s == L"0") eo.ZoneMode = NExtract::NZoneIdMode::kNone;
+ else if (s == L"1") eo.ZoneMode = NExtract::NZoneIdMode::kAll;
+ else if (s == L"2") eo.ZoneMode = NExtract::NZoneIdMode::kOffice;
+ else
+ throw CArcCmdLineException("Unsupported -snz:", s);
+ }
+ }
+
options.Censor.AddPathsToCensor(NWildcard::k_AbsPath);
options.Censor.ExtendExclude();
@@ -1198,13 +1464,28 @@ void CArcCmdLineParser::Parse2(CArcCmdLineOptions &options)
NWildcard::CCensor &arcCensor = options.arcCensor;
+ CNameOption nopArc;
+ // nopArc.RecursedType = NRecursedType::kNonRecursed; // default: we don't want recursing for archives, if -r specified
+ // is it OK, external switches can disable WildcardMatching and MarcMode for arc.
+ nopArc.WildcardMatching = nop.WildcardMatching;
+ nopArc.MarkMode = nop.MarkMode;
+
if (parser[NKey::kArInclude].ThereIs)
- AddSwitchWildcardsToCensor(arcCensor, parser[NKey::kArInclude].PostStrings, true, NRecursedType::kNonRecursed, wildcardMatching, codePage);
+ {
+ nopArc.Include = true;
+ AddSwitchWildcardsToCensor(arcCensor, parser[NKey::kArInclude].PostStrings, nopArc, codePage);
+ }
if (parser[NKey::kArExclude].ThereIs)
- AddSwitchWildcardsToCensor(arcCensor, parser[NKey::kArExclude].PostStrings, false, NRecursedType::kNonRecursed, wildcardMatching, codePage);
+ {
+ nopArc.Include = false;
+ AddSwitchWildcardsToCensor(arcCensor, parser[NKey::kArExclude].PostStrings, nopArc, codePage);
+ }
if (thereIsArchiveName)
- AddNameToCensor(arcCensor, options.ArchiveName, true, NRecursedType::kNonRecursed, wildcardMatching);
+ {
+ nopArc.Include = true;
+ AddNameToCensor(arcCensor, nopArc, options.ArchiveName);
+ }
arcCensor.AddPathsToCensor(NWildcard::k_RelatPath);
@@ -1242,6 +1523,9 @@ void CArcCmdLineParser::Parse2(CArcCmdLineOptions &options)
if (parser[NKey::kOutputDir].ThereIs)
{
eo.OutputDir = us2fs(parser[NKey::kOutputDir].PostStrings[0]);
+ #ifdef _WIN32
+ NFile::NName::NormalizeDirSeparators(eo.OutputDir);
+ #endif
NFile::NName::NormalizeDirPathPrefix(eo.OutputDir);
}
@@ -1281,8 +1565,12 @@ void CArcCmdLineParser::Parse2(CArcCmdLineOptions &options)
updateOptions.MethodMode.Properties = options.Properties;
+ if (parser[NKey::kPreserveATime].ThereIs)
+ updateOptions.PreserveATime = true;
if (parser[NKey::kShareForWrite].ThereIs)
updateOptions.OpenShareForWrite = true;
+ if (parser[NKey::kStopAfterOpenError].ThereIs)
+ updateOptions.StopAfterOpenError = true;
updateOptions.PathMode = censorPathMode;
@@ -1290,6 +1578,9 @@ void CArcCmdLineParser::Parse2(CArcCmdLineOptions &options)
updateOptions.NtSecurity = options.NtSecurity;
updateOptions.HardLinks = options.HardLinks;
updateOptions.SymLinks = options.SymLinks;
+
+ updateOptions.StoreOwnerId = options.StoreOwnerId;
+ updateOptions.StoreOwnerName = options.StoreOwnerName;
updateOptions.EMailMode = parser[NKey::kEmail].ThereIs;
if (updateOptions.EMailMode)
@@ -1333,11 +1624,13 @@ void CArcCmdLineParser::Parse2(CArcCmdLineOptions &options)
else if (options.Command.CommandType == NCommandType::kBenchmark)
{
options.NumIterations = 1;
+ options.NumIterations_Defined = false;
if (curCommandIndex < numNonSwitchStrings)
{
if (!StringToUInt32(nonSwitchStrings[curCommandIndex], options.NumIterations))
- throw CArcCmdLineException("Incorrect Number of benmchmark iterations", nonSwitchStrings[curCommandIndex]);
+ throw CArcCmdLineException("Incorrect number of benchmark iterations", nonSwitchStrings[curCommandIndex]);
curCommandIndex++;
+ options.NumIterations_Defined = true;
}
}
else if (options.Command.CommandType == NCommandType::kHash)
@@ -1348,10 +1641,14 @@ void CArcCmdLineParser::Parse2(CArcCmdLineOptions &options)
CHashOptions &hashOptions = options.HashOptions;
hashOptions.PathMode = censorPathMode;
hashOptions.Methods = options.HashMethods;
+ // hashOptions.HashFilePath = options.HashFilePath;
+ if (parser[NKey::kPreserveATime].ThereIs)
+ hashOptions.PreserveATime = true;
if (parser[NKey::kShareForWrite].ThereIs)
hashOptions.OpenShareForWrite = true;
hashOptions.StdInMode = options.StdInMode;
hashOptions.AltStreamsMode = options.AltStreams.Val;
+ hashOptions.SymLinks = options.SymLinks;
}
else if (options.Command.CommandType == NCommandType::kInfo)
{
@@ -1359,3 +1656,45 @@ void CArcCmdLineParser::Parse2(CArcCmdLineOptions &options)
else
throw 20150919;
}
+
+
+
+#ifndef _WIN32
+
+static AString g_ModuleDirPrefix;
+
+void Set_ModuleDirPrefix_From_ProgArg0(const char *s);
+void Set_ModuleDirPrefix_From_ProgArg0(const char *s)
+{
+ AString a (s);
+ int sep = a.ReverseFind_PathSepar();
+ a.DeleteFrom((unsigned)(sep + 1));
+ g_ModuleDirPrefix = a;
+}
+
+namespace NWindows {
+namespace NDLL {
+
+FString GetModuleDirPrefix();
+FString GetModuleDirPrefix()
+{
+ FString s;
+
+ s = fas2fs(g_ModuleDirPrefix);
+ if (s.IsEmpty())
+ s = FTEXT(".") FSTRING_PATH_SEPARATOR;
+ return s;
+ /*
+ setenv("_7ZIP_HOME_DIR", "/test/", 0);
+ const char *home = getenv("_7ZIP_HOME_DIR");
+ if (home)
+ s = home;
+ else
+ s = FTEXT(".") FSTRING_PATH_SEPARATOR;
+ return s;
+ */
+}
+
+}}
+
+#endif // ! _WIN32
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveCommandLine.h b/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveCommandLine.h
index a345505cb84..9e375b55aba 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveCommandLine.h
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveCommandLine.h
@@ -1,19 +1,18 @@
// ArchiveCommandLine.h
-#ifndef __ARCHIVE_COMMAND_LINE_H
-#define __ARCHIVE_COMMAND_LINE_H
+#ifndef ZIP7_INC_ARCHIVE_COMMAND_LINE_H
+#define ZIP7_INC_ARCHIVE_COMMAND_LINE_H
#include "../../../Common/CommandLineParser.h"
#include "../../../Common/Wildcard.h"
+#include "EnumDirItems.h"
+
#include "Extract.h"
#include "HashCalc.h"
#include "Update.h"
-struct CArcCmdLineException: public UString
-{
- CArcCmdLineException(const char *a, const wchar_t *u = NULL);
-};
+typedef CMessagePathException CArcCmdLineException;
namespace NCommandType { enum EEnum
{
@@ -51,8 +50,8 @@ struct CArcCmdLineOptions
{
bool HelpMode;
- bool LargePages;
- bool CaseSensitiveChange;
+ // bool LargePages;
+ bool CaseSensitive_Change;
bool CaseSensitive;
bool IsInTerminal;
@@ -64,22 +63,35 @@ struct CArcCmdLineOptions
bool YesToAll;
bool ShowDialog;
+ bool TechMode;
+ bool ShowTime;
+
+ CBoolPair NtSecurity;
+ CBoolPair AltStreams;
+ CBoolPair HardLinks;
+ CBoolPair SymLinks;
+
+ CBoolPair StoreOwnerId;
+ CBoolPair StoreOwnerName;
+
+ AString ListFields;
+
+ int ConsoleCodePage;
+
NWildcard::CCensor Censor;
CArcCommand Command;
UString ArchiveName;
- #ifndef _NO_CRYPTO
+ #ifndef Z7_NO_CRYPTO
bool PasswordEnabled;
UString Password;
#endif
- bool TechMode;
- bool ShowTime;
-
UStringVector HashMethods;
+ // UString HashFilePath;
- bool AppendName;
+ // bool AppendName;
// UStringVector ArchivePathsSorted;
// UStringVector ArchivePathsFullSorted;
NWildcard::CCensor arcCensor;
@@ -89,11 +101,6 @@ struct CArcCmdLineOptions
CExtractOptionsBase ExtractOptions;
- CBoolPair NtSecurity;
- CBoolPair AltStreams;
- CBoolPair HardLinks;
- CBoolPair SymLinks;
-
CUpdateOptions UpdateOptions;
CHashOptions HashOptions;
UString ArcType;
@@ -108,40 +115,46 @@ struct CArcCmdLineOptions
// Benchmark
UInt32 NumIterations;
+ bool NumIterations_Defined;
CArcCmdLineOptions():
- LargePages(false),
- CaseSensitiveChange(false),
+ HelpMode(false),
+ // LargePages(false),
+ CaseSensitive_Change(false),
CaseSensitive(false),
+ IsInTerminal(false),
+ IsStdOutTerminal(false),
+ IsStdErrTerminal(false),
+
StdInMode(false),
StdOutMode(false),
+ EnableHeaders(false),
+
+ YesToAll(false),
+ ShowDialog(false),
+ TechMode(false),
+ ShowTime(false),
+
+ ConsoleCodePage(-1),
+
Number_for_Out(k_OutStream_stdout),
Number_for_Errors(k_OutStream_stderr),
Number_for_Percents(k_OutStream_stdout),
LogLevel(0)
{
- };
+ }
};
class CArcCmdLineParser
{
NCommandLineParser::CParser parser;
public:
- CArcCmdLineParser();
+ UString Parse1Log;
void Parse1(const UStringVector &commandStrings, CArcCmdLineOptions &options);
void Parse2(CArcCmdLineOptions &options);
};
-HRESULT EnumerateDirItemsAndSort(
- NWildcard::CCensor &censor,
- NWildcard::ECensorPathMode pathMode,
- const UString &addPathPrefix,
- UStringVector &sortedPaths,
- UStringVector &sortedFullPaths,
- CDirItemsStat &st,
- IDirItemsCallback *callback);
-
#endif
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp b/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp
index bc116c93d66..4b0cbedad31 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp
@@ -5,11 +5,17 @@
#undef sprintf
#undef printf
+// #include <stdio.h>
+// #include "../../../../C/CpuTicks.h"
+
#include "../../../../C/Alloc.h"
+#include "../../../../C/CpuArch.h"
+
#include "../../../Common/ComTry.h"
#include "../../../Common/IntToString.h"
#include "../../../Common/StringConvert.h"
+#include "../../../Common/UTFConvert.h"
#include "../../../Common/Wildcard.h"
#include "../../../Windows/ErrorMsg.h"
@@ -19,13 +25,13 @@
#include "../../../Windows/PropVariant.h"
#include "../../../Windows/PropVariantConv.h"
-#if defined(_WIN32) && !defined(UNDER_CE) && !defined(_SFX)
-#define _USE_SECURITY_CODE
+#if defined(_WIN32) && !defined(UNDER_CE) && !defined(Z7_SFX)
+#define Z7_USE_SECURITY_CODE
#include "../../../Windows/SecurityUtils.h"
#endif
#include "../../Common/FilePathAutoRename.h"
-// #include "../../Common/StreamUtils.h"
+#include "../../Common/StreamUtils.h"
#include "../Common/ExtractingFilePath.h"
#include "../Common/PropIDUtils.h"
@@ -36,15 +42,21 @@ using namespace NWindows;
using namespace NFile;
using namespace NDir;
-static const char *kCantAutoRename = "Can not create file with auto name";
-static const char *kCantRenameFile = "Can not rename existing file";
-static const char *kCantDeleteOutputFile = "Can not delete output file";
-static const char *kCantDeleteOutputDir = "Can not delete output folder";
-
+static const char * const kCantAutoRename = "Cannot create file with auto name";
+static const char * const kCantRenameFile = "Cannot rename existing file";
+static const char * const kCantDeleteOutputFile = "Cannot delete output file";
+static const char * const kCantDeleteOutputDir = "Cannot delete output folder";
+static const char * const kCantOpenOutFile = "Cannot open output file";
+static const char * const kCantOpenInFile = "Cannot open input file";
+static const char * const kCantSetFileLen = "Cannot set length for output file";
+#ifdef SUPPORT_LINKS
+static const char * const kCantCreateHardLink = "Cannot create hard link";
+static const char * const kCantCreateSymLink = "Cannot create symbolic link";
+#endif
-#ifndef _SFX
+#ifndef Z7_SFX
-STDMETHODIMP COutStreamWithHash::Write(const void *data, UInt32 size, UInt32 *processedSize)
+Z7_COM7F_IMF(COutStreamWithHash::Write(const void *data, UInt32 size, UInt32 *processedSize))
{
HRESULT result = S_OK;
if (_stream)
@@ -57,9 +69,11 @@ STDMETHODIMP COutStreamWithHash::Write(const void *data, UInt32 size, UInt32 *pr
return result;
}
-#endif
+#endif // Z7_SFX
-#ifdef _USE_SECURITY_CODE
+
+#ifdef Z7_USE_SECURITY_CODE
+bool InitLocalPrivileges();
bool InitLocalPrivileges()
{
NSecurity::CAccessToken token;
@@ -78,8 +92,86 @@ bool InitLocalPrivileges()
return false;
return (GetLastError() == ERROR_SUCCESS);
}
+#endif // Z7_USE_SECURITY_CODE
+
+
+
+#if defined(_WIN32) && !defined(UNDER_CE) && !defined(Z7_SFX)
+
+static const char * const kOfficeExtensions =
+ " doc dot wbk"
+ " docx docm dotx dotm docb wll wwl"
+ " xls xlt xlm"
+ " xlsx xlsm xltx xltm xlsb xla xlam"
+ " ppt pot pps ppa ppam"
+ " pptx pptm potx potm ppam ppsx ppsm sldx sldm"
+ " ";
+
+static bool FindExt2(const char *p, const UString &name)
+{
+ const int pathPos = name.ReverseFind_PathSepar();
+ const int dotPos = name.ReverseFind_Dot();
+ if (dotPos < 0
+ || dotPos < pathPos
+ || dotPos == (int)name.Len() - 1)
+ return false;
+
+ AString s;
+ for (unsigned pos = (unsigned)(dotPos + 1);; pos++)
+ {
+ const wchar_t c = name[pos];
+ if (c <= 0)
+ break;
+ if (c >= 0x80)
+ return false;
+ s += (char)MyCharLower_Ascii((char)c);
+ }
+ for (unsigned i = 0; p[i] != 0;)
+ {
+ unsigned j;
+ for (j = i; p[j] != ' '; j++);
+ if (s.Len() == j - i && memcmp(p + i, (const char *)s, s.Len()) == 0)
+ return true;
+ i = j + 1;
+ }
+ return false;
+}
+
+
+static const FChar * const k_ZoneId_StreamName = FTEXT(":Zone.Identifier");
+
+void ReadZoneFile_Of_BaseFile(CFSTR fileName2, CByteBuffer &buf)
+{
+ FString fileName (fileName2);
+ fileName += k_ZoneId_StreamName;
+
+ buf.Free();
+ NIO::CInFile file;
+ if (!file.Open(fileName))
+ return;
+ UInt64 fileSize;
+ if (!file.GetLength(fileSize))
+ return;
+ if (fileSize == 0 || fileSize >= ((UInt32)1 << 16))
+ return;
+ buf.Alloc((size_t)fileSize);
+ size_t processed;
+ if (file.ReadFull(buf, (size_t)fileSize, processed) && processed == fileSize)
+ return;
+ buf.Free();
+}
+
+static bool WriteZoneFile(CFSTR fileName, const CByteBuffer &buf)
+{
+ NIO::COutFile file;
+ if (!file.Create(fileName, true))
+ return false;
+ return file.WriteFull(buf, buf.Size());
+}
+
#endif
+
#ifdef SUPPORT_LINKS
int CHardLinkNode::Compare(const CHardLinkNode &a) const
@@ -96,13 +188,13 @@ static HRESULT Archive_Get_HardLinkNode(IInArchive *archive, UInt32 index, CHard
defined = false;
{
NCOM::CPropVariant prop;
- RINOK(archive->GetProperty(index, kpidINode, &prop));
+ RINOK(archive->GetProperty(index, kpidINode, &prop))
if (!ConvertPropVariantToUInt64(prop, h.INode))
return S_OK;
}
{
NCOM::CPropVariant prop;
- RINOK(archive->GetProperty(index, kpidStreamId, &prop));
+ RINOK(archive->GetProperty(index, kpidStreamId, &prop))
ConvertPropVariantToUInt64(prop, h.StreamId);
}
defined = true;
@@ -126,22 +218,27 @@ HRESULT CArchiveExtractCallback::PrepareHardLinks(const CRecordVector<UInt32> *r
numItems = realIndices->Size();
else
{
- RINOK(archive->GetNumberOfItems(&numItems));
+ RINOK(archive->GetNumberOfItems(&numItems))
}
for (UInt32 i = 0; i < numItems; i++)
{
CHardLinkNode h;
bool defined;
- UInt32 realIndex = realIndices ? (*realIndices)[i] : i;
+ const UInt32 realIndex = realIndices ? (*realIndices)[i] : i;
- RINOK(Archive_Get_HardLinkNode(archive, realIndex, h, defined));
+ RINOK(Archive_Get_HardLinkNode(archive, realIndex, h, defined))
if (defined)
{
bool isAltStream = false;
- RINOK(Archive_IsItem_AltStream(archive, realIndex, isAltStream));
+ RINOK(Archive_IsItem_AltStream(archive, realIndex, isAltStream))
if (!isAltStream)
- hardIDs.Add(h);
+ {
+ bool isDir = false;
+ RINOK(Archive_IsItem_Dir(archive, realIndex, isDir))
+ if (!isDir)
+ hardIDs.Add(h);
+ }
}
}
}
@@ -149,7 +246,7 @@ HRESULT CArchiveExtractCallback::PrepareHardLinks(const CRecordVector<UInt32> *r
hardIDs.Sort2();
{
- // wee keep only items that have 2 or more items
+ // we keep only items that have 2 or more items
unsigned k = 0;
unsigned numSame = 1;
for (unsigned i = 1; i < hardIDs.Size(); i++)
@@ -170,22 +267,32 @@ HRESULT CArchiveExtractCallback::PrepareHardLinks(const CRecordVector<UInt32> *r
return S_OK;
}
-#endif
+#endif // SUPPORT_LINKS
+
CArchiveExtractCallback::CArchiveExtractCallback():
- WriteCTime(true),
- WriteATime(true),
- WriteMTime(true),
+ _arc(NULL),
+ Write_CTime(true),
+ Write_ATime(true),
+ Write_MTime(true),
_multiArchives(false)
{
LocalProgressSpec = new CLocalProgress();
_localProgress = LocalProgressSpec;
- #ifdef _USE_SECURITY_CODE
+ #ifdef Z7_USE_SECURITY_CODE
_saclEnabled = InitLocalPrivileges();
#endif
}
+
+void CArchiveExtractCallback::InitBeforeNewArchive()
+{
+ #if defined(_WIN32) && !defined(UNDER_CE)
+ ZoneBuf.Free();
+ #endif
+}
+
void CArchiveExtractCallback::Init(
const CExtractNtOptions &ntOptions,
const NWildcard::CCensorNode *wildcardCensor,
@@ -196,8 +303,9 @@ void CArchiveExtractCallback::Init(
const UStringVector &removePathParts, bool removePartsForAltStreams,
UInt64 packSize)
{
- _extractedFolderPaths.Clear();
- _extractedFolderIndices.Clear();
+ ClearExtractedDirsInfo();
+ _outFileStream.Release();
+ _bufPtrSeqOutStream.Release();
#ifdef SUPPORT_LINKS
_hardLinks.Clear();
@@ -221,13 +329,21 @@ void CArchiveExtractCallback::Init(
_progressTotal_Defined = true;
_extractCallback2 = extractCallback2;
+
+ /*
_compressProgress.Release();
_extractCallback2.QueryInterface(IID_ICompressProgressInfo, &_compressProgress);
- _extractCallback2.QueryInterface(IID_IArchiveExtractCallbackMessage, &_callbackMessage);
+
+ _callbackMessage.Release();
+ _extractCallback2.QueryInterface(IID_IArchiveExtractCallbackMessage2, &_callbackMessage);
+ */
+
+ _folderArchiveExtractCallback2.Release();
_extractCallback2.QueryInterface(IID_IFolderArchiveExtractCallback2, &_folderArchiveExtractCallback2);
- #ifndef _SFX
+ #ifndef Z7_SFX
+ ExtractToStreamCallback.Release();
_extractCallback2.QueryInterface(IID_IFolderExtractToStreamCallback, &ExtractToStreamCallback);
if (ExtractToStreamCallback)
{
@@ -246,7 +362,7 @@ void CArchiveExtractCallback::Init(
_removePathParts = removePathParts;
_removePartsForAltStreams = removePartsForAltStreams;
- #ifndef _SFX
+ #ifndef Z7_SFX
_baseParentFolder = (UInt32)(Int32)-1;
_use_baseParentFolder_mode = false;
#endif
@@ -264,7 +380,8 @@ void CArchiveExtractCallback::Init(
}
}
-STDMETHODIMP CArchiveExtractCallback::SetTotal(UInt64 size)
+
+Z7_COM7F_IMF(CArchiveExtractCallback::SetTotal(UInt64 size))
{
COM_TRY_BEGIN
_progressTotal = size;
@@ -275,6 +392,7 @@ STDMETHODIMP CArchiveExtractCallback::SetTotal(UInt64 size)
COM_TRY_END
}
+
static void NormalizeVals(UInt64 &v1, UInt64 &v2)
{
const UInt64 kMax = (UInt64)1 << 31;
@@ -285,6 +403,7 @@ static void NormalizeVals(UInt64 &v1, UInt64 &v2)
}
}
+
static UInt64 MyMultDiv64(UInt64 unpCur, UInt64 unpTotal, UInt64 packTotal)
{
NormalizeVals(packTotal, unpTotal);
@@ -294,7 +413,8 @@ static UInt64 MyMultDiv64(UInt64 unpCur, UInt64 unpTotal, UInt64 packTotal)
return unpCur * packTotal / unpTotal;
}
-STDMETHODIMP CArchiveExtractCallback::SetCompleted(const UInt64 *completeValue)
+
+Z7_COM7F_IMF(CArchiveExtractCallback::SetCompleted(const UInt64 *completeValue))
{
COM_TRY_BEGIN
@@ -314,15 +434,19 @@ STDMETHODIMP CArchiveExtractCallback::SetCompleted(const UInt64 *completeValue)
COM_TRY_END
}
-STDMETHODIMP CArchiveExtractCallback::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)
+
+Z7_COM7F_IMF(CArchiveExtractCallback::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize))
{
COM_TRY_BEGIN
return _localProgress->SetRatioInfo(inSize, outSize);
COM_TRY_END
}
+
void CArchiveExtractCallback::CreateComplexDirectory(const UStringVector &dirPathParts, FString &fullPath)
{
+ // we use (_item.IsDir) in this function
+
bool isAbsPath = false;
if (!dirPathParts.IsEmpty())
@@ -350,45 +474,72 @@ void CArchiveExtractCallback::CreateComplexDirectory(const UStringVector &dirPat
fullPath.Add_PathSepar();
const UString &s = dirPathParts[i];
fullPath += us2fs(s);
+
+ const bool isFinalDir = (i == dirPathParts.Size() - 1 && _item.IsDir);
+
+ if (fullPath.IsEmpty())
+ {
+ if (isFinalDir)
+ _itemFailure = true;
+ continue;
+ }
+
#if defined(_WIN32) && !defined(UNDER_CE)
if (_pathMode == NExtract::NPathMode::kAbsPaths)
if (i == 0 && s.Len() == 2 && NName::IsDrivePath2(s))
+ {
+ if (isFinalDir)
+ {
+ // we don't want to call SetAttrib() for root drive path
+ _itemFailure = true;
+ }
continue;
+ }
#endif
+
+ // bool res =
CreateDir(fullPath);
+ // if (!res)
+ if (isFinalDir)
+ {
+ if (!NFile::NFind::DoesDirExist(fullPath))
+ {
+ _itemFailure = true;
+ SendMessageError("Cannot create folder", fullPath);
+ // SendMessageError_with_LastError()
+ }
+ }
}
}
-HRESULT CArchiveExtractCallback::GetTime(int index, PROPID propID, FILETIME &filetime, bool &filetimeIsDefined)
+
+HRESULT CArchiveExtractCallback::GetTime(UInt32 index, PROPID propID, CArcTime &ft)
{
- filetimeIsDefined = false;
+ ft.Clear();
NCOM::CPropVariant prop;
- RINOK(_arc->Archive->GetProperty(index, propID, &prop));
+ RINOK(_arc->Archive->GetProperty(index, propID, &prop))
if (prop.vt == VT_FILETIME)
- {
- filetime = prop.filetime;
- filetimeIsDefined = (filetime.dwHighDateTime != 0 || filetime.dwLowDateTime != 0);
- }
+ ft.Set_From_Prop(prop);
else if (prop.vt != VT_EMPTY)
return E_FAIL;
return S_OK;
}
+
HRESULT CArchiveExtractCallback::GetUnpackSize()
{
- return _arc->GetItemSize(_index, _curSize, _curSizeDefined);
+ return _arc->GetItem_Size(_index, _curSize, _curSize_Defined);
}
static void AddPathToMessage(UString &s, const FString &path)
{
- s.AddAscii(" : ");
+ s += " : ";
s += fs2us(path);
}
HRESULT CArchiveExtractCallback::SendMessageError(const char *message, const FString &path)
{
- UString s;
- s.AddAscii(message);
+ UString s (message);
AddPathToMessage(s, path);
return _extractCallback2->MessageError(s);
}
@@ -396,29 +547,33 @@ HRESULT CArchiveExtractCallback::SendMessageError(const char *message, const FSt
HRESULT CArchiveExtractCallback::SendMessageError_with_LastError(const char *message, const FString &path)
{
DWORD errorCode = GetLastError();
- UString s;
- s.AddAscii(message);
- if (errorCode != 0)
+ if (errorCode == 0)
+ errorCode = (DWORD)E_FAIL;
+ UString s (message);
{
- s.AddAscii(" : ");
+ s += " : ";
s += NError::MyFormatMessage(errorCode);
}
AddPathToMessage(s, path);
return _extractCallback2->MessageError(s);
}
-HRESULT CArchiveExtractCallback::SendMessageError2(const char *message, const FString &path1, const FString &path2)
+HRESULT CArchiveExtractCallback::SendMessageError2(HRESULT errorCode, const char *message, const FString &path1, const FString &path2)
{
- UString s;
- s.AddAscii(message);
+ UString s (message);
+ if (errorCode != 0)
+ {
+ s += " : ";
+ s += NError::MyFormatMessage(errorCode);
+ }
AddPathToMessage(s, path1);
AddPathToMessage(s, path2);
return _extractCallback2->MessageError(s);
}
-#ifndef _SFX
+#ifndef Z7_SFX
-STDMETHODIMP CGetProp::GetProp(PROPID propID, PROPVARIANT *value)
+Z7_COM7F_IMF(CGetProp::GetProp(PROPID propID, PROPVARIANT *value))
{
/*
if (propID == kpidName)
@@ -433,35 +588,45 @@ STDMETHODIMP CGetProp::GetProp(PROPID propID, PROPVARIANT *value)
return Arc->Archive->GetProperty(IndexInArc, propID, value);
}
-#endif
+#endif // Z7_SFX
#ifdef SUPPORT_LINKS
static UString GetDirPrefixOf(const UString &src)
{
- UString s = src;
+ UString s (src);
if (!s.IsEmpty())
{
if (IsPathSepar(s.Back()))
s.DeleteBack();
int pos = s.ReverseFind_PathSepar();
- s.DeleteFrom(pos + 1);
+ s.DeleteFrom((unsigned)(pos + 1));
}
return s;
}
-#endif
+#endif // SUPPORT_LINKS
+struct CLinkLevelsInfo
+{
+ bool IsAbsolute;
+ int LowLevel;
+ int FinalLevel;
-bool IsSafePath(const UString &path)
+ void Parse(const UString &path);
+};
+
+void CLinkLevelsInfo::Parse(const UString &path)
{
- if (NName::IsAbsolutePath(path))
- return false;
+ IsAbsolute = NName::IsAbsolutePath(path);
+
+ LowLevel = 0;
+ FinalLevel = 0;
UStringVector parts;
SplitPathToParts(path, parts);
- unsigned level = 0;
+ int level = 0;
FOR_VECTOR (i, parts)
{
@@ -469,29 +634,42 @@ bool IsSafePath(const UString &path)
if (s.IsEmpty())
{
if (i == 0)
- return false;
+ IsAbsolute = true;
continue;
}
if (s == L".")
continue;
if (s == L"..")
{
- if (level == 0)
- return false;
level--;
+ if (LowLevel > level)
+ LowLevel = level;
}
else
level++;
}
- return level > 0;
+ FinalLevel = level;
+}
+
+
+bool IsSafePath(const UString &path);
+bool IsSafePath(const UString &path)
+{
+ CLinkLevelsInfo levelsInfo;
+ levelsInfo.Parse(path);
+ return !levelsInfo.IsAbsolute
+ && levelsInfo.LowLevel >= 0
+ && levelsInfo.FinalLevel > 0;
}
+bool CensorNode_CheckPath2(const NWildcard::CCensorNode &node, const CReadArcItem &item, bool &include);
bool CensorNode_CheckPath2(const NWildcard::CCensorNode &node, const CReadArcItem &item, bool &include)
{
bool found = false;
-
+
+ // CheckPathVect() doesn't check path to Parent nodes
if (node.CheckPathVect(item.PathParts, !item.MainIsDir, include))
{
if (!include)
@@ -514,7 +692,7 @@ bool CensorNode_CheckPath2(const NWildcard::CCensorNode &node, const CReadArcIte
if (pathParts2.IsEmpty())
pathParts2.AddNew();
UString &back = pathParts2.Back();
- back += L':';
+ back += ':';
back += item.AltStreamName;
bool include2;
@@ -526,11 +704,12 @@ bool CensorNode_CheckPath2(const NWildcard::CCensorNode &node, const CReadArcIte
return true;
}
- #endif
+ #endif // SUPPORT_ALT_STREAMS
return found;
}
+
bool CensorNode_CheckPath(const NWildcard::CCensorNode &node, const CReadArcItem &item)
{
bool include;
@@ -539,9 +718,10 @@ bool CensorNode_CheckPath(const NWildcard::CCensorNode &node, const CReadArcItem
return false;
}
+
static FString MakePath_from_2_Parts(const FString &prefix, const FString &path)
{
- FString s = prefix;
+ FString s (prefix);
#if defined(_WIN32) && !defined(UNDER_CE)
if (!path.IsEmpty() && path[0] == ':' && !prefix.IsEmpty() && IsPathSepar(prefix.Back()))
{
@@ -554,9 +734,10 @@ static FString MakePath_from_2_Parts(const FString &prefix, const FString &path)
}
-/*
+
#ifdef SUPPORT_LINKS
+/*
struct CTempMidBuffer
{
void *Buf;
@@ -575,15 +756,15 @@ HRESULT CArchiveExtractCallback::MyCopyFile(ISequentialOutStream *outStream)
NIO::CInFile inFile;
NIO::COutFile outFile;
- if (!inFile.Open(_CopyFile_Path))
- return SendMessageError_with_LastError("Open error", _CopyFile_Path);
+ if (!inFile.Open(_copyFile_Path))
+ return SendMessageError_with_LastError("Open error", _copyFile_Path);
for (;;)
{
UInt32 num;
if (!inFile.Read(buf.Buf, kBufSize, num))
- return SendMessageError_with_LastError("Read error", _CopyFile_Path);
+ return SendMessageError_with_LastError("Read error", _copyFile_Path);
if (num == 0)
return S_OK;
@@ -592,88 +773,24 @@ HRESULT CArchiveExtractCallback::MyCopyFile(ISequentialOutStream *outStream)
RINOK(WriteStream(outStream, buf.Buf, num));
}
}
-
-#endif
*/
-STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode)
-{
- COM_TRY_BEGIN
-
- *outStream = NULL;
-
- #ifndef _SFX
- if (_hashStream)
- _hashStreamSpec->ReleaseStream();
- _hashStreamWasUsed = false;
- #endif
-
- _outFileStream.Release();
-
- _encrypted = false;
- _position = 0;
- _isSplit = false;
-
- _curSize = 0;
- _curSizeDefined = false;
- _index = index;
-
- _diskFilePath.Empty();
-
- // _fi.Clear();
-
- #ifdef SUPPORT_LINKS
- // _CopyFile_Path.Empty();
- linkPath.Empty();
- #endif
+HRESULT CArchiveExtractCallback::ReadLink()
+{
IInArchive *archive = _arc->Archive;
-
- #ifndef _SFX
- _item._use_baseParentFolder_mode = _use_baseParentFolder_mode;
- if (_use_baseParentFolder_mode)
- {
- _item._baseParentFolder = _baseParentFolder;
- if (_pathMode == NExtract::NPathMode::kFullPaths ||
- _pathMode == NExtract::NPathMode::kAbsPaths)
- _item._baseParentFolder = -1;
- }
- #endif
-
- #ifdef SUPPORT_ALT_STREAMS
- _item.WriteToAltStreamIfColon = _ntOptions.WriteToAltStreamIfColon;
- #endif
-
- RINOK(_arc->GetItem(index, _item));
+ const UInt32 index = _index;
+ _link.Clear();
{
NCOM::CPropVariant prop;
- RINOK(archive->GetProperty(index, kpidPosition, &prop));
- if (prop.vt != VT_EMPTY)
- {
- if (prop.vt != VT_UI8)
- return E_FAIL;
- _position = prop.uhVal.QuadPart;
- _isSplit = true;
- }
- }
-
- #ifdef SUPPORT_LINKS
-
- // bool isCopyLink = false;
- bool isHardLink = false;
- bool isJunction = false;
- bool isRelative = false;
-
- {
- NCOM::CPropVariant prop;
- RINOK(archive->GetProperty(index, kpidHardLink, &prop));
+ RINOK(archive->GetProperty(index, kpidHardLink, &prop))
if (prop.vt == VT_BSTR)
{
- isHardLink = true;
- // isCopyLink = false;
- isRelative = false; // RAR5, TAR: hard links are from root folder of archive
- linkPath.SetFromBstr(prop.bstrVal);
+ _link.isHardLink = true;
+ // _link.isCopyLink = false;
+ _link.isRelative = false; // RAR5, TAR: hard links are from root folder of archive
+ _link.linkPath.SetFromBstr(prop.bstrVal);
}
else if (prop.vt != VT_EMPTY)
return E_FAIL;
@@ -685,10 +802,10 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStre
RINOK(archive->GetProperty(index, kpidCopyLink, &prop));
if (prop.vt == VT_BSTR)
{
- isHardLink = false;
- isCopyLink = true;
- isRelative = false; // RAR5: copy links are from root folder of archive
- linkPath.SetFromBstr(prop.bstrVal);
+ _link.isHardLink = false;
+ _link.isCopyLink = true;
+ _link.isRelative = false; // RAR5: copy links are from root folder of archive
+ _link.linkPath.SetFromBstr(prop.bstrVal);
}
else if (prop.vt != VT_EMPTY)
return E_FAIL;
@@ -697,22 +814,22 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStre
{
NCOM::CPropVariant prop;
- RINOK(archive->GetProperty(index, kpidSymLink, &prop));
+ RINOK(archive->GetProperty(index, kpidSymLink, &prop))
if (prop.vt == VT_BSTR)
{
- isHardLink = false;
- // isCopyLink = false;
- isRelative = true; // RAR5, TAR: symbolic links can be relative
- linkPath.SetFromBstr(prop.bstrVal);
+ _link.isHardLink = false;
+ // _link.isCopyLink = false;
+ _link.isRelative = true; // RAR5, TAR: symbolic links can be relative
+ _link.linkPath.SetFromBstr(prop.bstrVal);
}
else if (prop.vt != VT_EMPTY)
return E_FAIL;
}
+ NtReparse_Data = NULL;
+ NtReparse_Size = 0;
- bool isOkReparse = false;
-
- if (linkPath.IsEmpty() && _arc->GetRawProps)
+ if (_link.linkPath.IsEmpty() && _arc->GetRawProps)
{
const void *data;
UInt32 dataSize;
@@ -720,55 +837,79 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStre
_arc->GetRawProps->GetRawProp(_index, kpidNtReparse, &data, &dataSize, &propType);
+ // if (dataSize == 1234567) // for debug: unpacking without reparse
if (dataSize != 0)
{
if (propType != NPropDataType::kRaw)
return E_FAIL;
- UString s;
+
+ // 21.06: we need kpidNtReparse in linux for wim archives created in Windows
+ // #ifdef _WIN32
+
+ NtReparse_Data = data;
+ NtReparse_Size = dataSize;
+
CReparseAttr reparse;
- isOkReparse = reparse.Parse((const Byte *)data, dataSize);
+ bool isOkReparse = reparse.Parse((const Byte *)data, dataSize);
if (isOkReparse)
{
- isHardLink = false;
- // isCopyLink = false;
- linkPath = reparse.GetPath();
- isJunction = reparse.IsMountPoint();
- isRelative = reparse.IsRelative();
+ _link.isHardLink = false;
+ // _link.isCopyLink = false;
+ _link.linkPath = reparse.GetPath();
+ _link.isJunction = reparse.IsMountPoint();
+
+ if (reparse.IsSymLink_WSL())
+ {
+ _link.isWSL = true;
+ _link.isRelative = reparse.IsRelative_WSL();
+ }
+ else
+ _link.isRelative = reparse.IsRelative_Win();
+
+ // const AString s = GetAnsiString(_link.linkPath);
+ // printf("\n_link.linkPath: %s\n", s.Ptr());
+
#ifndef _WIN32
- linkPath.Replace(L'\\', WCHAR_PATH_SEPARATOR);
+ _link.linkPath.Replace(L'\\', WCHAR_PATH_SEPARATOR);
#endif
}
+ // #endif
}
}
- if (!linkPath.IsEmpty())
+ if (_link.linkPath.IsEmpty())
+ return S_OK;
+
{
#ifdef _WIN32
- linkPath.Replace(L'/', WCHAR_PATH_SEPARATOR);
+ _link.linkPath.Replace(L'/', WCHAR_PATH_SEPARATOR);
#endif
// rar5 uses "\??\" prefix for absolute links
- if (linkPath.IsPrefixedBy(WSTRING_PATH_SEPARATOR L"??" WSTRING_PATH_SEPARATOR))
+ if (_link.linkPath.IsPrefixedBy(WSTRING_PATH_SEPARATOR L"??" WSTRING_PATH_SEPARATOR))
{
- isRelative = false;
- linkPath.DeleteFrontal(4);
+ _link.isRelative = false;
+ _link.linkPath.DeleteFrontal(4);
}
for (;;)
// while (NName::IsAbsolutePath(linkPath))
{
- unsigned n = NName::GetRootPrefixSize(linkPath);
+ unsigned n = NName::GetRootPrefixSize(_link.linkPath);
if (n == 0)
break;
- isRelative = false;
- linkPath.DeleteFrontal(n);
+ _link.isRelative = false;
+ _link.linkPath.DeleteFrontal(n);
}
}
- if (!linkPath.IsEmpty() && !isRelative && _removePathParts.Size() != 0)
+ if (_link.linkPath.IsEmpty())
+ return S_OK;
+
+ if (!_link.isRelative && _removePathParts.Size() != 0)
{
UStringVector pathParts;
- SplitPathToParts(linkPath, pathParts);
+ SplitPathToParts(_link.linkPath, pathParts);
bool badPrefix = false;
FOR_VECTOR (i, _removePathParts)
{
@@ -780,23 +921,726 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStre
}
if (!badPrefix)
pathParts.DeleteFrontal(_removePathParts.Size());
- linkPath = MakePathFromParts(pathParts);
+ _link.linkPath = MakePathFromParts(pathParts);
+ }
+
+ /*
+ if (!_link.linkPath.IsEmpty())
+ {
+ printf("\n_link %s to -> %s\n", GetOemString(_item.Path).Ptr(), GetOemString(_link.linkPath).Ptr());
+ }
+ */
+
+ return S_OK;
+}
+
+#endif // SUPPORT_LINKS
+
+
+#ifndef _WIN32
+
+static HRESULT GetOwner(IInArchive *archive,
+ UInt32 index, UInt32 pidName, UInt32 pidId, COwnerInfo &res)
+{
+ {
+ NWindows::NCOM::CPropVariant prop;
+ RINOK(archive->GetProperty(index, pidId, &prop))
+ if (prop.vt == VT_UI4)
+ {
+ res.Id_Defined = true;
+ res.Id = prop.ulVal; // for debug
+ // res.Id++; // for debug
+ // if (pidId == kpidGroupId) res.Id += 7; // for debug
+ // res.Id = 0; // for debug
+ }
+ else if (prop.vt != VT_EMPTY)
+ return E_INVALIDARG;
+ }
+ {
+ NWindows::NCOM::CPropVariant prop;
+ RINOK(archive->GetProperty(index, pidName, &prop))
+ if (prop.vt == VT_BSTR)
+ {
+ const UString s = prop.bstrVal;
+ ConvertUnicodeToUTF8(s, res.Name);
+ }
+ else if (prop.vt == VT_UI4)
+ {
+ res.Id_Defined = true;
+ res.Id = prop.ulVal;
+ }
+ else if (prop.vt != VT_EMPTY)
+ return E_INVALIDARG;
}
+ return S_OK;
+}
+#endif
+
+
+HRESULT CArchiveExtractCallback::Read_fi_Props()
+{
+ IInArchive *archive = _arc->Archive;
+ const UInt32 index = _index;
+
+ _fi.Attrib_Defined = false;
+
+ #ifndef _WIN32
+ _fi.Owner.Clear();
+ _fi.Group.Clear();
+ #endif
+
+ {
+ NCOM::CPropVariant prop;
+ RINOK(archive->GetProperty(index, kpidPosixAttrib, &prop))
+ if (prop.vt == VT_UI4)
+ {
+ _fi.SetFromPosixAttrib(prop.ulVal);
+ }
+ else if (prop.vt != VT_EMPTY)
+ return E_FAIL;
+ }
+
+ {
+ NCOM::CPropVariant prop;
+ RINOK(archive->GetProperty(index, kpidAttrib, &prop))
+ if (prop.vt == VT_UI4)
+ {
+ _fi.Attrib = prop.ulVal;
+ _fi.Attrib_Defined = true;
+ }
+ else if (prop.vt != VT_EMPTY)
+ return E_FAIL;
+ }
+
+ RINOK(GetTime(index, kpidCTime, _fi.CTime))
+ RINOK(GetTime(index, kpidATime, _fi.ATime))
+ RINOK(GetTime(index, kpidMTime, _fi.MTime))
+
+ #ifndef _WIN32
+ if (_ntOptions.ExtractOwner)
+ {
+ // SendMessageError_with_LastError("_ntOptions.ExtractOwner", _diskFilePath);
+ GetOwner(archive, index, kpidUser, kpidUserId, _fi.Owner);
+ GetOwner(archive, index, kpidGroup, kpidGroupId, _fi.Group);
+ }
+ #endif
+
+ return S_OK;
+}
+
+
+
+void CArchiveExtractCallback::CorrectPathParts()
+{
+ UStringVector &pathParts = _item.PathParts;
+
+ #ifdef SUPPORT_ALT_STREAMS
+ if (!_item.IsAltStream
+ || !pathParts.IsEmpty()
+ || !(_removePartsForAltStreams || _pathMode == NExtract::NPathMode::kNoPathsAlt))
#endif
+ Correct_FsPath(_pathMode == NExtract::NPathMode::kAbsPaths, _keepAndReplaceEmptyDirPrefixes, pathParts, _item.MainIsDir);
+
+ #ifdef SUPPORT_ALT_STREAMS
+
+ if (_item.IsAltStream)
+ {
+ UString s (_item.AltStreamName);
+ Correct_AltStream_Name(s);
+ bool needColon = true;
+
+ if (pathParts.IsEmpty())
+ {
+ pathParts.AddNew();
+ if (_removePartsForAltStreams || _pathMode == NExtract::NPathMode::kNoPathsAlt)
+ needColon = false;
+ }
+ #ifdef _WIN32
+ else if (_pathMode == NExtract::NPathMode::kAbsPaths &&
+ NWildcard::GetNumPrefixParts_if_DrivePath(pathParts) == pathParts.Size())
+ pathParts.AddNew();
+ #endif
+
+ UString &name = pathParts.Back();
+ if (needColon)
+ name += (char)(_ntOptions.ReplaceColonForAltStream ? '_' : ':');
+ name += s;
+ }
+
+ #endif // SUPPORT_ALT_STREAMS
+}
+
+
+void CArchiveExtractCallback::GetFiTimesCAM(CFiTimesCAM &pt)
+{
+ pt.CTime_Defined = false;
+ pt.ATime_Defined = false;
+ pt.MTime_Defined = false;
+
+ if (Write_MTime)
+ {
+ if (_fi.MTime.Def)
+ {
+ _fi.MTime.Write_To_FiTime(pt.MTime);
+ pt.MTime_Defined = true;
+ }
+ else if (_arc->MTime.Def)
+ {
+ _arc->MTime.Write_To_FiTime(pt.MTime);
+ pt.MTime_Defined = true;
+ }
+ }
+
+ if (Write_CTime && _fi.CTime.Def)
+ {
+ _fi.CTime.Write_To_FiTime(pt.CTime);
+ pt.CTime_Defined = true;
+ }
+
+ if (Write_ATime && _fi.ATime.Def)
+ {
+ _fi.ATime.Write_To_FiTime(pt.ATime);
+ pt.ATime_Defined = true;
+ }
+}
+
+
+void CArchiveExtractCallback::CreateFolders()
+{
+ // 21.04 : we don't change original (_item.PathParts) here
+ UStringVector pathParts = _item.PathParts;
+
+ if (!pathParts.IsEmpty())
+ {
+ /* v23: if we extract symlink, and we know that it links to dir:
+ Linux: we don't create dir item (symlink_from_path) here.
+ Windows: SetReparseData() will create dir item, if it doesn't exist,
+ but if we create dir item here, it's not problem. */
+ if (!_item.IsDir
+ #ifdef SUPPORT_LINKS
+ #ifndef WIN32
+ || !_link.linkPath.IsEmpty()
+ #endif
+ #endif
+ )
+ pathParts.DeleteBack();
+ }
+
+ if (pathParts.IsEmpty())
+ return;
+
+ FString fullPathNew;
+ CreateComplexDirectory(pathParts, fullPathNew);
+
+ if (!_item.IsDir)
+ return;
+
+ if (_itemFailure)
+ return;
+
+ CDirPathTime pt;
+ GetFiTimesCAM(pt);
+
+ if (pt.IsSomeTimeDefined())
+ {
+ pt.Path = fullPathNew;
+ pt.SetDirTime();
+ _extractedFolders.Add(pt);
+ }
+}
+
+
+
+/*
+ CheckExistFile(fullProcessedPath)
+ it can change: fullProcessedPath, _isRenamed, _overwriteMode
+ (needExit = true) means that we must exit GetStream() even for S_OK result.
+*/
+
+HRESULT CArchiveExtractCallback::CheckExistFile(FString &fullProcessedPath, bool &needExit)
+{
+ needExit = true; // it was set already before
+
+ NFind::CFileInfo fileInfo;
+
+ if (fileInfo.Find(fullProcessedPath))
+ {
+ if (_overwriteMode == NExtract::NOverwriteMode::kSkip)
+ return S_OK;
+
+ if (_overwriteMode == NExtract::NOverwriteMode::kAsk)
+ {
+ const int slashPos = fullProcessedPath.ReverseFind_PathSepar();
+ const FString realFullProcessedPath = fullProcessedPath.Left((unsigned)(slashPos + 1)) + fileInfo.Name;
+
+ /* (fileInfo) can be symbolic link.
+ we can show final file properties here. */
+
+ FILETIME ft1;
+ FiTime_To_FILETIME(fileInfo.MTime, ft1);
+
+ Int32 overwriteResult;
+ RINOK(_extractCallback2->AskOverwrite(
+ fs2us(realFullProcessedPath), &ft1, &fileInfo.Size, _item.Path,
+ _fi.MTime.Def ? &_fi.MTime.FT : NULL,
+ _curSize_Defined ? &_curSize : NULL,
+ &overwriteResult))
+
+ switch (overwriteResult)
+ {
+ case NOverwriteAnswer::kCancel:
+ return E_ABORT;
+ case NOverwriteAnswer::kNo:
+ return S_OK;
+ case NOverwriteAnswer::kNoToAll:
+ _overwriteMode = NExtract::NOverwriteMode::kSkip;
+ return S_OK;
+
+ case NOverwriteAnswer::kYes:
+ break;
+ case NOverwriteAnswer::kYesToAll:
+ _overwriteMode = NExtract::NOverwriteMode::kOverwrite;
+ break;
+ case NOverwriteAnswer::kAutoRename:
+ _overwriteMode = NExtract::NOverwriteMode::kRename;
+ break;
+ default:
+ return E_FAIL;
+ }
+ } // NExtract::NOverwriteMode::kAsk
+
+ if (_overwriteMode == NExtract::NOverwriteMode::kRename)
+ {
+ if (!AutoRenamePath(fullProcessedPath))
+ {
+ RINOK(SendMessageError(kCantAutoRename, fullProcessedPath))
+ return E_FAIL;
+ }
+ _isRenamed = true;
+ }
+ else if (_overwriteMode == NExtract::NOverwriteMode::kRenameExisting)
+ {
+ FString existPath (fullProcessedPath);
+ if (!AutoRenamePath(existPath))
+ {
+ RINOK(SendMessageError(kCantAutoRename, fullProcessedPath))
+ return E_FAIL;
+ }
+ // MyMoveFile can rename folders. So it's OK to use it for folders too
+ if (!MyMoveFile(fullProcessedPath, existPath))
+ {
+ HRESULT errorCode = GetLastError_noZero_HRESULT();
+ RINOK(SendMessageError2(errorCode, kCantRenameFile, existPath, fullProcessedPath))
+ return E_FAIL;
+ }
+ }
+ else // not Rename*
+ {
+ if (fileInfo.IsDir())
+ {
+ // do we need to delete all files in folder?
+ if (!RemoveDir(fullProcessedPath))
+ {
+ RINOK(SendMessageError_with_LastError(kCantDeleteOutputDir, fullProcessedPath))
+ return S_OK;
+ }
+ }
+ else // fileInfo is not Dir
+ {
+ if (NFind::DoesFileExist_Raw(fullProcessedPath))
+ if (!DeleteFileAlways(fullProcessedPath))
+ if (GetLastError() != ERROR_FILE_NOT_FOUND) // check it in linux
+ {
+ RINOK(SendMessageError_with_LastError(kCantDeleteOutputFile, fullProcessedPath))
+ return S_OK;
+ // return E_FAIL;
+ }
+ } // fileInfo is not Dir
+ } // not Rename*
+ }
+ else // not Find(fullProcessedPath)
+ {
+ #if defined(_WIN32) && !defined(UNDER_CE)
+ // we need to clear READ-ONLY of parent before creating alt stream
+ int colonPos = NName::FindAltStreamColon(fullProcessedPath);
+ if (colonPos >= 0 && fullProcessedPath[(unsigned)colonPos + 1] != 0)
+ {
+ FString parentFsPath (fullProcessedPath);
+ parentFsPath.DeleteFrom((unsigned)colonPos);
+ NFind::CFileInfo parentFi;
+ if (parentFi.Find(parentFsPath))
+ {
+ if (parentFi.IsReadOnly())
+ SetFileAttrib(parentFsPath, parentFi.Attrib & ~(DWORD)FILE_ATTRIBUTE_READONLY);
+ }
+ }
+ #endif // defined(_WIN32) && !defined(UNDER_CE)
+ }
- RINOK(Archive_GetItemBoolProp(archive, index, kpidEncrypted, _encrypted));
+ needExit = false;
+ return S_OK;
+}
+
+
+
+
+
+
+HRESULT CArchiveExtractCallback::GetExtractStream(CMyComPtr<ISequentialOutStream> &outStreamLoc, bool &needExit)
+{
+ needExit = true;
+
+ RINOK(Read_fi_Props())
+
+ #ifdef SUPPORT_LINKS
+ IInArchive *archive = _arc->Archive;
+ #endif
+
+ const UInt32 index = _index;
- RINOK(GetUnpackSize());
+ bool isAnti = false;
+ RINOK(_arc->IsItem_Anti(index, isAnti))
+
+ CorrectPathParts();
+ UString processedPath (MakePathFromParts(_item.PathParts));
+
+ if (!isAnti)
+ {
+ // 21.04: CreateFolders doesn't change (_item.PathParts)
+ CreateFolders();
+ }
+
+ FString fullProcessedPath (us2fs(processedPath));
+ if (_pathMode != NExtract::NPathMode::kAbsPaths
+ || !NName::IsAbsolutePath(processedPath))
+ {
+ fullProcessedPath = MakePath_from_2_Parts(_dirPathPrefix, fullProcessedPath);
+ }
#ifdef SUPPORT_ALT_STREAMS
+ if (_item.IsAltStream && _item.ParentIndex != (UInt32)(Int32)-1)
+ {
+ const int renIndex = _renamedFiles.FindInSorted(CIndexToPathPair(_item.ParentIndex));
+ if (renIndex != -1)
+ {
+ const CIndexToPathPair &pair = _renamedFiles[(unsigned)renIndex];
+ fullProcessedPath = pair.Path;
+ fullProcessedPath += ':';
+ UString s (_item.AltStreamName);
+ Correct_AltStream_Name(s);
+ fullProcessedPath += us2fs(s);
+ }
+ }
+ #endif // SUPPORT_ALT_STREAMS
+
+ if (_item.IsDir)
+ {
+ _diskFilePath = fullProcessedPath;
+ if (isAnti)
+ RemoveDir(_diskFilePath);
+ #ifdef SUPPORT_LINKS
+ if (_link.linkPath.IsEmpty())
+ #endif
+ {
+ if (!isAnti)
+ SetAttrib();
+ return S_OK;
+ }
+ }
+ else if (!_isSplit)
+ {
+ RINOK(CheckExistFile(fullProcessedPath, needExit))
+ if (needExit)
+ return S_OK;
+ needExit = true;
+ }
- if (!_ntOptions.AltStreams.Val && _item.IsAltStream)
+ _diskFilePath = fullProcessedPath;
+
+
+ if (isAnti)
+ {
+ needExit = false;
return S_OK;
+ }
+
+ // not anti
+
+ #ifdef SUPPORT_LINKS
+
+ if (!_link.linkPath.IsEmpty())
+ {
+ #ifndef UNDER_CE
+ {
+ bool linkWasSet = false;
+ RINOK(SetFromLinkPath(fullProcessedPath, _link, linkWasSet))
+ if (linkWasSet)
+ {
+ _isSymLinkCreated = _link.IsSymLink();
+ SetAttrib();
+ // printf("\nlinkWasSet %s\n", GetAnsiString(_diskFilePath));
+ }
+ }
+ #endif // UNDER_CE
+
+ // if (_copyFile_Path.IsEmpty())
+ {
+ needExit = false;
+ return S_OK;
+ }
+ }
+
+ if (!_hardLinks.IDs.IsEmpty() && !_item.IsAltStream && !_item.IsDir)
+ {
+ CHardLinkNode h;
+ bool defined;
+ RINOK(Archive_Get_HardLinkNode(archive, index, h, defined))
+ if (defined)
+ {
+ const int linkIndex = _hardLinks.IDs.FindInSorted2(h);
+ if (linkIndex != -1)
+ {
+ FString &hl = _hardLinks.Links[(unsigned)linkIndex];
+ if (hl.IsEmpty())
+ hl = fullProcessedPath;
+ else
+ {
+ if (!MyCreateHardLink(fullProcessedPath, hl))
+ {
+ HRESULT errorCode = GetLastError_noZero_HRESULT();
+ RINOK(SendMessageError2(errorCode, kCantCreateHardLink, fullProcessedPath, hl))
+ return S_OK;
+ }
+
+ // printf("\nHard linkWasSet Archive_Get_HardLinkNode %s\n", GetAnsiString(_diskFilePath));
+ // _needSetAttrib = true; // do we need to set attribute ?
+ SetAttrib();
+ needExit = false;
+ return S_OK;
+ }
+ }
+ }
+ }
+
+ #endif // SUPPORT_LINKS
+
+
+ // ---------- CREATE WRITE FILE -----
+
+ _outFileStreamSpec = new COutFileStream;
+ CMyComPtr<IOutStream> outFileStream_Loc(_outFileStreamSpec);
+
+ if (!_outFileStreamSpec->Open(fullProcessedPath, _isSplit ? OPEN_ALWAYS: CREATE_ALWAYS))
+ {
+ // if (::GetLastError() != ERROR_FILE_EXISTS || !isSplit)
+ {
+ RINOK(SendMessageError_with_LastError(kCantOpenOutFile, fullProcessedPath))
+ return S_OK;
+ }
+ }
+
+ _needSetAttrib = true;
+ bool is_SymLink_in_Data = false;
+
+ if (_curSize_Defined && _curSize > 0 && _curSize < (1 << 12))
+ {
+ if (_fi.IsLinuxSymLink())
+ {
+ is_SymLink_in_Data = true;
+ _is_SymLink_in_Data_Linux = true;
+ }
+ else if (_fi.IsReparse())
+ {
+ is_SymLink_in_Data = true;
+ _is_SymLink_in_Data_Linux = false;
+ }
+ }
+
+ if (is_SymLink_in_Data)
+ {
+ _outMemBuf.Alloc((size_t)_curSize);
+ _bufPtrSeqOutStream_Spec = new CBufPtrSeqOutStream;
+ _bufPtrSeqOutStream = _bufPtrSeqOutStream_Spec;
+ _bufPtrSeqOutStream_Spec->Init(_outMemBuf, _outMemBuf.Size());
+ outStreamLoc = _bufPtrSeqOutStream;
+ }
+ else // not reprase
+ {
+ if (_ntOptions.PreAllocateOutFile && !_isSplit && _curSize_Defined && _curSize > (1 << 12))
+ {
+ // UInt64 ticks = GetCpuTicks();
+ _fileLength_that_WasSet = _curSize;
+ bool res = _outFileStreamSpec->File.SetLength(_curSize);
+ _fileLength_WasSet = res;
+
+ // ticks = GetCpuTicks() - ticks;
+ // printf("\nticks = %10d\n", (unsigned)ticks);
+ if (!res)
+ {
+ RINOK(SendMessageError_with_LastError(kCantSetFileLen, fullProcessedPath))
+ }
+
+ /*
+ _outFileStreamSpec->File.Close();
+ ticks = GetCpuTicks() - ticks;
+ printf("\nticks = %10d\n", (unsigned)ticks);
+ return S_FALSE;
+ */
+
+ /*
+ File.SetLength() on FAT (xp64): is fast, but then File.Close() can be slow,
+ if we don't write any data.
+ File.SetLength() for remote share file (exFAT) can be slow in some cases,
+ and the Windows can return "network error" after 1 minute,
+ while remote file still can grow.
+ We need some way to detect such bad cases and disable PreAllocateOutFile mode.
+ */
+
+ res = _outFileStreamSpec->SeekToBegin_bool();
+ if (!res)
+ {
+ RINOK(SendMessageError_with_LastError("Cannot seek to begin of file", fullProcessedPath))
+ }
+ } // PreAllocateOutFile
+
+ #ifdef SUPPORT_ALT_STREAMS
+ if (_isRenamed && !_item.IsAltStream)
+ {
+ CIndexToPathPair pair(index, fullProcessedPath);
+ unsigned oldSize = _renamedFiles.Size();
+ unsigned insertIndex = _renamedFiles.AddToUniqueSorted(pair);
+ if (oldSize == _renamedFiles.Size())
+ _renamedFiles[insertIndex].Path = fullProcessedPath;
+ }
+ #endif // SUPPORT_ALT_STREAMS
+
+ if (_isSplit)
+ {
+ RINOK(outFileStream_Loc->Seek((Int64)_position, STREAM_SEEK_SET, NULL))
+ }
+ outStreamLoc = outFileStream_Loc;
+ } // if not reprase
+
+ _outFileStream = outFileStream_Loc;
+
+ needExit = false;
+ return S_OK;
+}
+
+
+
+HRESULT CArchiveExtractCallback::GetItem(UInt32 index)
+{
+ #ifndef Z7_SFX
+ _item._use_baseParentFolder_mode = _use_baseParentFolder_mode;
+ if (_use_baseParentFolder_mode)
+ {
+ _item._baseParentFolder = (int)_baseParentFolder;
+ if (_pathMode == NExtract::NPathMode::kFullPaths ||
+ _pathMode == NExtract::NPathMode::kAbsPaths)
+ _item._baseParentFolder = -1;
+ }
+ #endif // Z7_SFX
+
+ #ifdef SUPPORT_ALT_STREAMS
+ _item.WriteToAltStreamIfColon = _ntOptions.WriteToAltStreamIfColon;
#endif
+ return _arc->GetItem(index, _item);
+}
+
+
+Z7_COM7F_IMF(CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode))
+{
+ COM_TRY_BEGIN
+
+ *outStream = NULL;
+
+ #ifndef Z7_SFX
+ if (_hashStream)
+ _hashStreamSpec->ReleaseStream();
+ _hashStreamWasUsed = false;
+ #endif
+ _outFileStream.Release();
+ _bufPtrSeqOutStream.Release();
+
+ _encrypted = false;
+ _position = 0;
+ _isSplit = false;
+
+ _curSize = 0;
+ _curSize_Defined = false;
+ _fileLength_WasSet = false;
+ _fileLength_that_WasSet = 0;
+ _index = index;
+
+ _diskFilePath.Empty();
+
+ _isRenamed = false;
+
+ // _fi.Clear();
+
+ // _is_SymLink_in_Data = false;
+ _is_SymLink_in_Data_Linux = false;
+
+ _needSetAttrib = false;
+ _isSymLinkCreated = false;
+ _itemFailure = false;
+
+ #ifdef SUPPORT_LINKS
+ // _copyFile_Path.Empty();
+ _link.Clear();
+ #endif
+
+ _extractMode = false;
+
+ switch (askExtractMode)
+ {
+ case NArchive::NExtract::NAskMode::kExtract:
+ if (_testMode)
+ {
+ // askExtractMode = NArchive::NExtract::NAskMode::kTest;
+ }
+ else
+ _extractMode = true;
+ break;
+ }
+
+
+ IInArchive *archive = _arc->Archive;
+
+ RINOK(GetItem(index))
+
+ {
+ NCOM::CPropVariant prop;
+ RINOK(archive->GetProperty(index, kpidPosition, &prop))
+ if (prop.vt != VT_EMPTY)
+ {
+ if (prop.vt != VT_UI8)
+ return E_FAIL;
+ _position = prop.uhVal.QuadPart;
+ _isSplit = true;
+ }
+ }
+
+ #ifdef SUPPORT_LINKS
+ RINOK(ReadLink())
+ #endif // SUPPORT_LINKS
+
+
+ RINOK(Archive_GetItemBoolProp(archive, index, kpidEncrypted, _encrypted))
+
+ RINOK(GetUnpackSize())
+
+ #ifdef SUPPORT_ALT_STREAMS
+ if (!_ntOptions.AltStreams.Val && _item.IsAltStream)
+ return S_OK;
+ #endif // SUPPORT_ALT_STREAMS
+
+ // we can change (_item.PathParts) in this function
UStringVector &pathParts = _item.PathParts;
if (_wildcardCensor)
@@ -805,7 +1649,7 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStre
return S_OK;
}
- #ifndef _SFX
+ #ifndef Z7_SFX
if (_use_baseParentFolder_mode)
{
if (!pathParts.IsEmpty())
@@ -824,7 +1668,7 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStre
}
}
else
- #endif
+ #endif // Z7_SFX
{
if (pathParts.IsEmpty())
{
@@ -907,17 +1751,16 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStre
numRemovePathParts = pathParts.Size() - 1;
break;
}
- /*
- case NExtract::NPathMode::kFullPaths:
case NExtract::NPathMode::kAbsPaths:
+ // default:
break;
- */
}
pathParts.DeleteFrontal(numRemovePathParts);
}
- #ifndef _SFX
+
+ #ifndef Z7_SFX
if (ExtractToStreamCallback)
{
@@ -928,13 +1771,13 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStre
}
GetProp_Spec->Arc = _arc;
GetProp_Spec->IndexInArc = index;
- UString name = MakePathFromParts(pathParts);
+ UString name (MakePathFromParts(pathParts));
#ifdef SUPPORT_ALT_STREAMS
if (_item.IsAltStream)
{
if (!pathParts.IsEmpty() || (!_removePartsForAltStreams && _pathMode != NExtract::NPathMode::kNoPathsAlt))
- name += L':';
+ name += ':';
name += _item.AltStreamName;
}
#endif
@@ -942,500 +1785,531 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStre
return ExtractToStreamCallback->GetStream7(name, BoolToInt(_item.IsDir), outStream, askExtractMode, GetProp);
}
- #endif
+ #endif // Z7_SFX
+
CMyComPtr<ISequentialOutStream> outStreamLoc;
-if (askExtractMode == NArchive::NExtract::NAskMode::kExtract && !_testMode)
-{
- if (_stdOutMode)
+ if (askExtractMode == NArchive::NExtract::NAskMode::kExtract && !_testMode)
{
- outStreamLoc = new CStdOutFileStream;
+ if (_stdOutMode)
+ outStreamLoc = new CStdOutFileStream;
+ else
+ {
+ bool needExit = true;
+ RINOK(GetExtractStream(outStreamLoc, needExit))
+ if (needExit)
+ return S_OK;
+ }
}
- else
+
+ #ifndef Z7_SFX
+ if (_hashStream)
{
+ if (askExtractMode == NArchive::NExtract::NAskMode::kExtract ||
+ askExtractMode == NArchive::NExtract::NAskMode::kTest)
{
- NCOM::CPropVariant prop;
- RINOK(archive->GetProperty(index, kpidAttrib, &prop));
- if (prop.vt == VT_UI4)
- {
- _fi.Attrib = prop.ulVal;
- _fi.AttribDefined = true;
- }
- else if (prop.vt == VT_EMPTY)
- _fi.AttribDefined = false;
- else
- return E_FAIL;
+ _hashStreamSpec->SetStream(outStreamLoc);
+ outStreamLoc = _hashStream;
+ _hashStreamSpec->Init(true);
+ _hashStreamWasUsed = true;
}
+ }
+ #endif // Z7_SFX
- RINOK(GetTime(index, kpidCTime, _fi.CTime, _fi.CTimeDefined));
- RINOK(GetTime(index, kpidATime, _fi.ATime, _fi.ATimeDefined));
- RINOK(GetTime(index, kpidMTime, _fi.MTime, _fi.MTimeDefined));
+ if (outStreamLoc)
+ {
+ /*
+ #ifdef SUPPORT_LINKS
+ if (!_copyFile_Path.IsEmpty())
+ {
+ RINOK(PrepareOperation(askExtractMode));
+ RINOK(MyCopyFile(outStreamLoc));
+ return SetOperationResult(NArchive::NExtract::NOperationResult::kOK);
+ }
+ if (_link.isCopyLink && _testMode)
+ return S_OK;
+ #endif
+ */
+ *outStream = outStreamLoc.Detach();
+ }
+
+ return S_OK;
- bool isAnti = false;
- RINOK(_arc->IsItemAnti(index, isAnti));
+ COM_TRY_END
+}
- #ifdef SUPPORT_ALT_STREAMS
- if (!_item.IsAltStream
- || !pathParts.IsEmpty()
- || !(_removePartsForAltStreams || _pathMode == NExtract::NPathMode::kNoPathsAlt))
- #endif
- Correct_FsPath(_pathMode == NExtract::NPathMode::kAbsPaths, pathParts, _item.MainIsDir);
- #ifdef SUPPORT_ALT_STREAMS
-
- if (_item.IsAltStream)
- {
- UString s = _item.AltStreamName;
- Correct_AltStream_Name(s);
- bool needColon = true;
- if (pathParts.IsEmpty())
- {
- pathParts.AddNew();
- if (_removePartsForAltStreams || _pathMode == NExtract::NPathMode::kNoPathsAlt)
- needColon = false;
- }
- else if (_pathMode == NExtract::NPathMode::kAbsPaths &&
- NWildcard::GetNumPrefixParts_if_DrivePath(pathParts) == pathParts.Size())
- pathParts.AddNew();
-
- UString &name = pathParts.Back();
- if (needColon)
- name += (wchar_t)(_ntOptions.ReplaceColonForAltStream ? L'_' : L':');
- name += s;
- }
-
- #endif
- UString processedPath = MakePathFromParts(pathParts);
-
- if (!isAnti)
- {
- if (!_item.IsDir)
- {
- if (!pathParts.IsEmpty())
- pathParts.DeleteBack();
- }
-
- if (!pathParts.IsEmpty())
- {
- FString fullPathNew;
- CreateComplexDirectory(pathParts, fullPathNew);
- if (_item.IsDir)
- {
- _extractedFolderPaths.Add(fullPathNew);
- _extractedFolderIndices.Add(index);
- SetDirTime(fullPathNew,
- (WriteCTime && _fi.CTimeDefined) ? &_fi.CTime : NULL,
- (WriteATime && _fi.ATimeDefined) ? &_fi.ATime : NULL,
- (WriteMTime && _fi.MTimeDefined) ? &_fi.MTime : (_arc->MTimeDefined ? &_arc->MTime : NULL));
- }
- }
- }
- FString fullProcessedPath = us2fs(processedPath);
- if (_pathMode != NExtract::NPathMode::kAbsPaths
- || !NName::IsAbsolutePath(processedPath))
+
+
+
+
+
+Z7_COM7F_IMF(CArchiveExtractCallback::PrepareOperation(Int32 askExtractMode))
+{
+ COM_TRY_BEGIN
+
+ #ifndef Z7_SFX
+ if (ExtractToStreamCallback)
+ return ExtractToStreamCallback->PrepareOperation7(askExtractMode);
+ #endif
+
+ _extractMode = false;
+
+ switch (askExtractMode)
+ {
+ case NArchive::NExtract::NAskMode::kExtract:
+ if (_testMode)
+ askExtractMode = NArchive::NExtract::NAskMode::kTest;
+ else
+ _extractMode = true;
+ break;
+ }
+
+ return _extractCallback2->PrepareOperation(_item.Path, BoolToInt(_item.IsDir),
+ askExtractMode, _isSplit ? &_position: NULL);
+
+ COM_TRY_END
+}
+
+
+
+
+
+HRESULT CArchiveExtractCallback::CloseFile()
+{
+ if (!_outFileStream)
+ return S_OK;
+
+ HRESULT hres = S_OK;
+
+ const UInt64 processedSize = _outFileStreamSpec->ProcessedSize;
+ if (_fileLength_WasSet && _fileLength_that_WasSet > processedSize)
+ {
+ const bool res = _outFileStreamSpec->File.SetLength(processedSize);
+ _fileLength_WasSet = res;
+ if (!res)
{
- fullProcessedPath = MakePath_from_2_Parts(_dirPathPrefix, fullProcessedPath);
+ const HRESULT hres2 = SendMessageError_with_LastError(kCantSetFileLen, us2fs(_item.Path));
+ if (hres == S_OK)
+ hres = hres2;
}
+ }
- #ifdef SUPPORT_ALT_STREAMS
-
- if (_item.IsAltStream && _item.ParentIndex != (UInt32)(Int32)-1)
+ _curSize = processedSize;
+ _curSize_Defined = true;
+
+ #if defined(_WIN32) && !defined(UNDER_CE) && !defined(Z7_SFX)
+ if (ZoneBuf.Size() != 0
+ && !_item.IsAltStream)
+ {
+ // if (NFind::DoesFileExist_Raw(tempFilePath))
+ if (ZoneMode != NExtract::NZoneIdMode::kOffice ||
+ FindExt2(kOfficeExtensions, fs2us(_diskFilePath)))
{
- int renIndex = _renamedFiles.FindInSorted(CIndexToPathPair(_item.ParentIndex));
- if (renIndex >= 0)
+ // we must write zone file before setting of timestamps
+ const FString path = _diskFilePath + k_ZoneId_StreamName;
+ if (!WriteZoneFile(path, ZoneBuf))
{
- const CIndexToPathPair &pair = _renamedFiles[renIndex];
- fullProcessedPath = pair.Path;
- fullProcessedPath += (FChar)':';
- UString s = _item.AltStreamName;
- Correct_AltStream_Name(s);
- fullProcessedPath += us2fs(s);
+ // we can't write it in FAT
+ // SendMessageError_with_LastError("Can't write Zone.Identifier stream", path);
}
}
-
- #endif
+ }
+ #endif
- bool isRenamed = false;
+ CFiTimesCAM t;
+ GetFiTimesCAM(t);
- if (_item.IsDir)
+ // #ifdef _WIN32
+ if (t.IsSomeTimeDefined())
+ _outFileStreamSpec->SetTime(
+ t.CTime_Defined ? &t.CTime : NULL,
+ t.ATime_Defined ? &t.ATime : NULL,
+ t.MTime_Defined ? &t.MTime : NULL);
+ // #endif
+
+ RINOK(_outFileStreamSpec->Close())
+ _outFileStream.Release();
+ return hres;
+}
+
+
+#ifdef SUPPORT_LINKS
+
+
+HRESULT CArchiveExtractCallback::SetFromLinkPath(
+ const FString &fullProcessedPath,
+ const CLinkInfo &linkInfo,
+ bool &linkWasSet)
+{
+ linkWasSet = false;
+ if (!_ntOptions.SymLinks.Val && !linkInfo.isHardLink)
+ return S_OK;
+
+ UString relatPath;
+
+ /* if (linkInfo.isRelative)
+ linkInfo.linkPath is final link path that must be stored to file link field
+ else
+ linkInfo.linkPath is path from root of archive. So we must add _dirPathPrefix_Full before linkPath.
+ */
+
+ if (linkInfo.isRelative)
+ relatPath = GetDirPrefixOf(_item.Path);
+ relatPath += linkInfo.linkPath;
+
+ if (!IsSafePath(relatPath))
+ {
+ return SendMessageError2(
+ 0, // errorCode
+ "Dangerous link path was ignored",
+ us2fs(_item.Path),
+ us2fs(linkInfo.linkPath)); // us2fs(relatPath)
+ }
+
+ FString existPath;
+ if (linkInfo.isHardLink /* || linkInfo.IsCopyLink */ || !linkInfo.isRelative)
+ {
+ if (!NName::GetFullPath(_dirPathPrefix_Full, us2fs(relatPath), existPath))
{
- _diskFilePath = fullProcessedPath;
- if (isAnti)
- RemoveDir(_diskFilePath);
- #ifdef SUPPORT_LINKS
- if (linkPath.IsEmpty())
- #endif
- return S_OK;
+ RINOK(SendMessageError("Incorrect path", us2fs(relatPath)))
}
- else if (!_isSplit)
- {
+ }
+ else
+ {
+ existPath = us2fs(linkInfo.linkPath);
+ // printf("\nlinkPath = : %s\n", GetOemString(linkInfo.linkPath).Ptr());
+ }
- // ----- Is file (not split) -----
- NFind::CFileInfo fileInfo;
- if (fileInfo.Find(fullProcessedPath))
+ if (existPath.IsEmpty())
+ return SendMessageError("Empty link", fullProcessedPath);
+
+ if (linkInfo.isHardLink /* || linkInfo.IsCopyLink */)
+ {
+ // if (linkInfo.isHardLink)
{
- switch (_overwriteMode)
+ if (!MyCreateHardLink(fullProcessedPath, existPath))
{
- case NExtract::NOverwriteMode::kSkip:
- return S_OK;
- case NExtract::NOverwriteMode::kAsk:
- {
- int slashPos = fullProcessedPath.ReverseFind_PathSepar();
- FString realFullProcessedPath = fullProcessedPath.Left(slashPos + 1) + fileInfo.Name;
-
- Int32 overwriteResult;
- RINOK(_extractCallback2->AskOverwrite(
- fs2us(realFullProcessedPath), &fileInfo.MTime, &fileInfo.Size, _item.Path,
- _fi.MTimeDefined ? &_fi.MTime : NULL,
- _curSizeDefined ? &_curSize : NULL,
- &overwriteResult))
-
- switch (overwriteResult)
- {
- case NOverwriteAnswer::kCancel: return E_ABORT;
- case NOverwriteAnswer::kNo: return S_OK;
- case NOverwriteAnswer::kNoToAll: _overwriteMode = NExtract::NOverwriteMode::kSkip; return S_OK;
- case NOverwriteAnswer::kYes: break;
- case NOverwriteAnswer::kYesToAll: _overwriteMode = NExtract::NOverwriteMode::kOverwrite; break;
- case NOverwriteAnswer::kAutoRename: _overwriteMode = NExtract::NOverwriteMode::kRename; break;
- default:
- return E_FAIL;
- }
- }
+ const HRESULT errorCode = GetLastError_noZero_HRESULT();
+ RINOK(SendMessageError2(errorCode, kCantCreateHardLink, fullProcessedPath, existPath))
}
- if (_overwriteMode == NExtract::NOverwriteMode::kRename)
+ linkWasSet = true;
+ return S_OK;
+ }
+ /*
+ // IsCopyLink
+ {
+ NFind::CFileInfo fi;
+ if (!fi.Find(existPath))
{
- if (!AutoRenamePath(fullProcessedPath))
- {
- RINOK(SendMessageError(kCantAutoRename, fullProcessedPath));
- return E_FAIL;
- }
- isRenamed = true;
- }
- else if (_overwriteMode == NExtract::NOverwriteMode::kRenameExisting)
- {
- FString existPath = fullProcessedPath;
- if (!AutoRenamePath(existPath))
- {
- RINOK(SendMessageError(kCantAutoRename, fullProcessedPath));
- return E_FAIL;
- }
- // MyMoveFile can raname folders. So it's OK to use it for folders too
- if (!MyMoveFile(fullProcessedPath, existPath))
- {
- RINOK(SendMessageError2(kCantRenameFile, existPath, fullProcessedPath));
- return E_FAIL;
- }
+ RINOK(SendMessageError2("Cannot find the file for copying", existPath, fullProcessedPath));
}
else
{
- if (fileInfo.IsDir())
- {
- // do we need to delete all files in folder?
- if (!RemoveDir(fullProcessedPath))
- {
- RINOK(SendMessageError_with_LastError(kCantDeleteOutputDir, fullProcessedPath));
- return S_OK;
- }
- }
+ if (_curSize_Defined && _curSize == fi.Size)
+ _copyFile_Path = existPath;
else
{
- bool needDelete = true;
- if (needDelete)
- {
- if (!DeleteFileAlways(fullProcessedPath))
- {
- RINOK(SendMessageError_with_LastError(kCantDeleteOutputFile, fullProcessedPath));
- return S_OK;
- // return E_FAIL;
- }
- }
+ RINOK(SendMessageError2("File size collision for file copying", existPath, fullProcessedPath));
}
+ // RINOK(MyCopyFile(existPath, fullProcessedPath));
}
}
- else // not Find(fullProcessedPath)
- {
- // we need to clear READ-ONLY of parent before creating alt stream
- #if defined(_WIN32) && !defined(UNDER_CE)
- int colonPos = NName::FindAltStreamColon(fullProcessedPath);
- if (colonPos >= 0 && fullProcessedPath[(unsigned)colonPos + 1] != 0)
+ */
+ }
+
+ // is Symbolic link
+
+ /*
+ if (_item.IsDir && !isRelative)
+ {
+ // Windows before Vista doesn't support symbolic links.
+ // we could convert such symbolic links to Junction Points
+ // isJunction = true;
+ // convertToAbs = true;
+ }
+ */
+
+ if (!_ntOptions.SymLinks_AllowDangerous.Val)
+ {
+ #ifdef _WIN32
+ if (_item.IsDir)
+ #endif
+ if (linkInfo.isRelative)
{
- FString parentFsPath = fullProcessedPath;
- parentFsPath.DeleteFrom(colonPos);
- NFind::CFileInfo parentFi;
- if (parentFi.Find(parentFsPath))
+ CLinkLevelsInfo levelsInfo;
+ levelsInfo.Parse(linkInfo.linkPath);
+ if (levelsInfo.FinalLevel < 1 || levelsInfo.IsAbsolute)
{
- if (parentFi.IsReadOnly())
- SetFileAttrib(parentFsPath, parentFi.Attrib & ~FILE_ATTRIBUTE_READONLY);
+ return SendMessageError2(
+ 0, // errorCode
+ "Dangerous symbolic link path was ignored",
+ us2fs(_item.Path),
+ us2fs(linkInfo.linkPath));
}
}
- #endif
- }
- // ----- END of code for Is file (not split) -----
+ }
- }
- _diskFilePath = fullProcessedPath;
-
+
+ #ifdef _WIN32
+
+ CByteBuffer data;
+ // printf("\nFillLinkData(): %s\n", GetOemString(existPath).Ptr());
+ if (!FillLinkData(data, fs2us(existPath), !linkInfo.isJunction, linkInfo.isWSL))
+ return SendMessageError("Cannot fill link data", us2fs(_item.Path));
- if (!isAnti)
- {
- #ifdef SUPPORT_LINKS
+ /*
+ if (NtReparse_Size != data.Size() || memcmp(NtReparse_Data, data, data.Size()) != 0)
+ {
+ SendMessageError("reconstructed Reparse is different", fs2us(existPath));
+ }
+ */
+
+ CReparseAttr attr;
+ if (!attr.Parse(data, data.Size()))
+ {
+ RINOK(SendMessageError("Internal error for symbolic link file", us2fs(_item.Path)))
+ return S_OK;
+ }
+ if (!NFile::NIO::SetReparseData(fullProcessedPath, _item.IsDir, data, (DWORD)data.Size()))
+ {
+ RINOK(SendMessageError_with_LastError(kCantCreateSymLink, fullProcessedPath))
+ return S_OK;
+ }
+ linkWasSet = true;
- if (!linkPath.IsEmpty())
- {
- #ifndef UNDER_CE
+ return S_OK;
+
+
+ #else // ! _WIN32
- UString relatPath;
- if (isRelative)
- relatPath = GetDirPrefixOf(_item.Path);
- relatPath += linkPath;
-
- if (!IsSafePath(relatPath))
- {
- RINOK(SendMessageError("Dangerous link path was ignored", us2fs(relatPath)));
- }
- else
- {
- FString existPath;
- if (isHardLink /* || isCopyLink */ || !isRelative)
- {
- if (!NName::GetFullPath(_dirPathPrefix_Full, us2fs(relatPath), existPath))
- {
- RINOK(SendMessageError("Incorrect path", us2fs(relatPath)));
- }
- }
- else
- {
- existPath = us2fs(linkPath);
- }
-
- if (!existPath.IsEmpty())
- {
- if (isHardLink /* || isCopyLink */)
- {
- // if (isHardLink)
- {
- if (!MyCreateHardLink(fullProcessedPath, existPath))
- {
- RINOK(SendMessageError2("Can not create hard link", fullProcessedPath, existPath));
- // return S_OK;
- }
- }
- /*
- else
- {
- NFind::CFileInfo fi;
- if (!fi.Find(existPath))
- {
- RINOK(SendMessageError2("Can not find the file for copying", existPath, fullProcessedPath));
- }
- else
- {
- if (_curSizeDefined && _curSize == fi.Size)
- _CopyFile_Path = existPath;
- else
- {
- RINOK(SendMessageError2("File size collision for file copying", existPath, fullProcessedPath));
- }
-
- // RINOK(MyCopyFile(existPath, fullProcessedPath));
- }
- }
- */
- }
- else if (_ntOptions.SymLinks.Val)
- {
- // bool isSymLink = true; // = false for junction
- if (_item.IsDir && !isRelative)
- {
- // if it's before Vista we use Junction Point
- // isJunction = true;
- // convertToAbs = true;
- }
-
- CByteBuffer data;
- if (FillLinkData(data, fs2us(existPath), !isJunction))
- {
- CReparseAttr attr;
- if (!attr.Parse(data, data.Size()))
- {
- RINOK(SendMessageError("Internal error for symbolic link file", us2fs(_item.Path)));
- // return E_FAIL;
- }
- else
- if (!NFile::NIO::SetReparseData(fullProcessedPath, _item.IsDir, data, (DWORD)data.Size()))
- {
- RINOK(SendMessageError_with_LastError("Can not create symbolic link", fullProcessedPath));
- }
- }
- }
- }
- }
-
- #endif
- }
-
- if (linkPath.IsEmpty() /* || !_CopyFile_Path.IsEmpty() */)
- #endif // SUPPORT_LINKS
- {
- bool needWriteFile = true;
-
- #ifdef SUPPORT_LINKS
- if (!_hardLinks.IDs.IsEmpty() && !_item.IsAltStream)
- {
- CHardLinkNode h;
- bool defined;
- RINOK(Archive_Get_HardLinkNode(archive, index, h, defined));
- if (defined)
- {
- {
- int linkIndex = _hardLinks.IDs.FindInSorted2(h);
- if (linkIndex >= 0)
- {
- FString &hl = _hardLinks.Links[linkIndex];
- if (hl.IsEmpty())
- hl = fullProcessedPath;
- else
- {
- if (!MyCreateHardLink(fullProcessedPath, hl))
- {
- RINOK(SendMessageError2("Can not create hard link", fullProcessedPath, hl));
- return S_OK;
- }
- needWriteFile = false;
- }
- }
- }
- }
- }
- #endif
-
- if (needWriteFile)
- {
- _outFileStreamSpec = new COutFileStream;
- CMyComPtr<ISequentialOutStream> outStreamLoc2(_outFileStreamSpec);
- if (!_outFileStreamSpec->Open(fullProcessedPath, _isSplit ? OPEN_ALWAYS: CREATE_ALWAYS))
- {
- // if (::GetLastError() != ERROR_FILE_EXISTS || !isSplit)
- {
- RINOK(SendMessageError_with_LastError("Can not open output file", fullProcessedPath));
- return S_OK;
- }
- }
+ if (!NFile::NIO::SetSymLink(fullProcessedPath, existPath))
+ {
+ RINOK(SendMessageError_with_LastError(kCantCreateSymLink, fullProcessedPath))
+ return S_OK;
+ }
+ linkWasSet = true;
+ return S_OK;
- #ifdef SUPPORT_ALT_STREAMS
- if (isRenamed && !_item.IsAltStream)
- {
- CIndexToPathPair pair(index, fullProcessedPath);
- unsigned oldSize = _renamedFiles.Size();
- unsigned insertIndex = _renamedFiles.AddToUniqueSorted(pair);
- if (oldSize == _renamedFiles.Size())
- _renamedFiles[insertIndex].Path = fullProcessedPath;
- }
- #endif
+ #endif // ! _WIN32
+}
- if (_isSplit)
- {
- RINOK(_outFileStreamSpec->Seek(_position, STREAM_SEEK_SET, NULL));
- }
-
- _outFileStream = outStreamLoc2;
- }
- }
- }
+
+bool CLinkInfo::Parse(const Byte *data, size_t dataSize, bool isLinuxData)
+{
+ Clear();
+ // this->isLinux = isLinuxData;
+
+ if (isLinuxData)
+ {
+ isJunction = false;
+ isHardLink = false;
+ AString utf;
+ if (dataSize >= (1 << 12))
+ return false;
+ utf.SetFrom_CalcLen((const char *)data, (unsigned)dataSize);
+ UString u;
+ if (!ConvertUTF8ToUnicode(utf, u))
+ return false;
+ linkPath = u;
- outStreamLoc = _outFileStream;
+ // in linux symbolic data: we expect that linux separator '/' is used
+ // if windows link was created, then we also must use linux separator
+ if (u.IsEmpty())
+ return false;
+ const wchar_t c = u[0];
+ isRelative = !IS_PATH_SEPAR(c);
+ return true;
}
+
+ CReparseAttr reparse;
+ if (!reparse.Parse(data, dataSize))
+ return false;
+ isHardLink = false;
+ // isCopyLink = false;
+ linkPath = reparse.GetPath();
+ isJunction = reparse.IsMountPoint();
+
+ if (reparse.IsSymLink_WSL())
+ {
+ isWSL = true;
+ isRelative = reparse.IsRelative_WSL();
+ }
+ else
+ isRelative = reparse.IsRelative_Win();
+
+ // FIXME !!!
+ #ifndef _WIN32
+ linkPath.Replace(L'\\', WCHAR_PATH_SEPARATOR);
+ #endif
+
+ return true;
}
+
+#endif // SUPPORT_LINKS
- #ifndef _SFX
- if (_hashStream)
+HRESULT CArchiveExtractCallback::CloseReparseAndFile()
+{
+ HRESULT res = S_OK;
+
+ #ifdef SUPPORT_LINKS
+
+ size_t reparseSize = 0;
+ bool repraseMode = false;
+ bool needSetReparse = false;
+ CLinkInfo linkInfo;
+
+ if (_bufPtrSeqOutStream)
{
- if (askExtractMode == NArchive::NExtract::NAskMode::kExtract ||
- askExtractMode == NArchive::NExtract::NAskMode::kTest)
+ repraseMode = true;
+ reparseSize = _bufPtrSeqOutStream_Spec->GetPos();
+ if (_curSize_Defined && reparseSize == _outMemBuf.Size())
{
- _hashStreamSpec->SetStream(outStreamLoc);
- outStreamLoc = _hashStream;
- _hashStreamSpec->Init(true);
- _hashStreamWasUsed = true;
+ /*
+ CReparseAttr reparse;
+ DWORD errorCode = 0;
+ needSetReparse = reparse.Parse(_outMemBuf, reparseSize, errorCode);
+ if (needSetReparse)
+ {
+ UString linkPath = reparse.GetPath();
+ #ifndef _WIN32
+ linkPath.Replace(L'\\', WCHAR_PATH_SEPARATOR);
+ #endif
+ }
+ */
+ needSetReparse = linkInfo.Parse(_outMemBuf, reparseSize, _is_SymLink_in_Data_Linux);
+ if (!needSetReparse)
+ res = SendMessageError_with_LastError("Incorrect reparse stream", us2fs(_item.Path));
+ }
+ else
+ {
+ res = SendMessageError_with_LastError("Unknown reparse stream", us2fs(_item.Path));
}
+ if (!needSetReparse && _outFileStream)
+ {
+ const HRESULT res2 = WriteStream(_outFileStream, _outMemBuf, reparseSize);
+ if (res == S_OK)
+ res = res2;
+ }
+ _bufPtrSeqOutStream.Release();
}
- #endif
+ #endif // SUPPORT_LINKS
-
- if (outStreamLoc)
+
+ const HRESULT res2 = CloseFile();
+
+ if (res == S_OK)
+ res = res2;
+
+ RINOK(res)
+
+ #ifdef SUPPORT_LINKS
+ if (repraseMode)
{
- /*
- #ifdef SUPPORT_LINKS
+ _curSize = reparseSize;
+ _curSize_Defined = true;
- if (!_CopyFile_Path.IsEmpty())
+ #ifdef SUPPORT_LINKS
+ if (needSetReparse)
{
- RINOK(PrepareOperation(askExtractMode));
- RINOK(MyCopyFile(outStreamLoc));
- return SetOperationResult(NArchive::NExtract::NOperationResult::kOK);
+ // in Linux : we must delete empty file before symbolic link creation
+ // in Windows : we can create symbolic link even without file deleting
+ if (!DeleteFileAlways(_diskFilePath))
+ {
+ RINOK(SendMessageError_with_LastError("can't delete file", _diskFilePath))
+ }
+ {
+ /*
+ // for DEBUG ONLY: we can extract sym links as WSL links
+ // to eliminate (non-admin) errors for sym links.
+ #ifdef _WIN32
+ if (!linkInfo.isHardLink && !linkInfo.isJunction)
+ linkInfo.isWSL = true;
+ #endif
+ */
+ bool linkWasSet = false;
+ RINOK(SetFromLinkPath(_diskFilePath, linkInfo, linkWasSet))
+ if (linkWasSet)
+ _isSymLinkCreated = linkInfo.IsSymLink();
+ else
+ _needSetAttrib = false;
+ }
+ /*
+ if (!NFile::NIO::SetReparseData(_diskFilePath, _item.IsDir, ))
+ {
+ res = SendMessageError_with_LastError(kCantCreateSymLink, _diskFilePath);
+ }
+ */
}
-
- if (isCopyLink && _testMode)
- return S_OK;
-
#endif
- */
-
- *outStream = outStreamLoc.Detach();
}
-
- return S_OK;
-
- COM_TRY_END
+ #endif
+ return res;
}
-STDMETHODIMP CArchiveExtractCallback::PrepareOperation(Int32 askExtractMode)
+void CArchiveExtractCallback::SetAttrib()
{
- COM_TRY_BEGIN
+ #ifndef _WIN32
+ // Linux now doesn't support permissions for symlinks
+ if (_isSymLinkCreated)
+ return;
+ #endif
+
+ if (_itemFailure
+ || _diskFilePath.IsEmpty()
+ || _stdOutMode
+ || !_extractMode)
+ return;
+
+ #ifndef _WIN32
+ if (_fi.Owner.Id_Defined &&
+ _fi.Group.Id_Defined)
+ {
+ if (my_chown(_diskFilePath, _fi.Owner.Id, _fi.Group.Id) != 0)
+ {
+ SendMessageError_with_LastError("Cannot set owner", _diskFilePath);
+ }
+ }
+ #endif
- #ifndef _SFX
- if (ExtractToStreamCallback)
- return ExtractToStreamCallback->PrepareOperation7(askExtractMode);
- #endif
-
- _extractMode = false;
-
- switch (askExtractMode)
+ if (_fi.Attrib_Defined)
{
- case NArchive::NExtract::NAskMode::kExtract:
- if (_testMode)
- askExtractMode = NArchive::NExtract::NAskMode::kTest;
- else
- _extractMode = true;
- break;
- };
-
- return _extractCallback2->PrepareOperation(_item.Path, BoolToInt(_item.IsDir),
- askExtractMode, _isSplit ? &_position: 0);
-
- COM_TRY_END
+ // const AString s = GetAnsiString(_diskFilePath);
+ // printf("\nSetFileAttrib_PosixHighDetect: %s: hex:%x\n", s.Ptr(), _fi.Attrib);
+ bool res = SetFileAttrib_PosixHighDetect(_diskFilePath, _fi.Attrib);
+ if (!res)
+ {
+ // do we need error message here in Windows and in posix?
+ SendMessageError_with_LastError("Cannot set file attribute", _diskFilePath);
+ }
+ }
}
-STDMETHODIMP CArchiveExtractCallback::SetOperationResult(Int32 opRes)
+Z7_COM7F_IMF(CArchiveExtractCallback::SetOperationResult(Int32 opRes))
{
COM_TRY_BEGIN
- #ifndef _SFX
+ // printf("\nCArchiveExtractCallback::SetOperationResult: %d %s\n", opRes, GetAnsiString(_diskFilePath));
+
+ #ifndef Z7_SFX
if (ExtractToStreamCallback)
- return ExtractToStreamCallback->SetOperationResult7(opRes, BoolToInt(_encrypted));
+ {
+ GetUnpackSize();
+ return ExtractToStreamCallback->SetOperationResult8(opRes, BoolToInt(_encrypted), _curSize);
+ }
#endif
- #ifndef _SFX
+ #ifndef Z7_SFX
if (_hashStreamWasUsed)
{
@@ -1447,26 +2321,16 @@ STDMETHODIMP CArchiveExtractCallback::SetOperationResult(Int32 opRes)
#endif
, _item.Path);
_curSize = _hashStreamSpec->GetSize();
- _curSizeDefined = true;
+ _curSize_Defined = true;
_hashStreamSpec->ReleaseStream();
_hashStreamWasUsed = false;
}
- #endif
+ #endif // Z7_SFX
- if (_outFileStream)
- {
- _outFileStreamSpec->SetTime(
- (WriteCTime && _fi.CTimeDefined) ? &_fi.CTime : NULL,
- (WriteATime && _fi.ATimeDefined) ? &_fi.ATime : NULL,
- (WriteMTime && _fi.MTimeDefined) ? &_fi.MTime : (_arc->MTimeDefined ? &_arc->MTime : NULL));
- _curSize = _outFileStreamSpec->ProcessedSize;
- _curSizeDefined = true;
- RINOK(_outFileStreamSpec->Close());
- _outFileStream.Release();
- }
+ RINOK(CloseReparseAndFile())
- #ifdef _USE_SECURITY_CODE
+ #ifdef Z7_USE_SECURITY_CODE
if (!_stdOutMode && _extractMode && _ntOptions.NtSecurity.Val && _arc->GetRawProps)
{
const void *data;
@@ -1482,16 +2346,16 @@ STDMETHODIMP CArchiveExtractCallback::SetOperationResult(Int32 opRes)
SECURITY_INFORMATION securInfo = DACL_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | OWNER_SECURITY_INFORMATION;
if (_saclEnabled)
securInfo |= SACL_SECURITY_INFORMATION;
- ::SetFileSecurityW(fs2us(_diskFilePath), securInfo, (PSECURITY_DESCRIPTOR)(void *)data);
+ ::SetFileSecurityW(fs2us(_diskFilePath), securInfo, (PSECURITY_DESCRIPTOR)(void *)(const Byte *)(data));
}
}
}
- #endif
+ #endif // Z7_USE_SECURITY_CODE
- if (!_curSizeDefined)
+ if (!_curSize_Defined)
GetUnpackSize();
- if (_curSizeDefined)
+ if (_curSize_Defined)
{
#ifdef SUPPORT_ALT_STREAMS
if (_item.IsAltStream)
@@ -1510,38 +2374,36 @@ STDMETHODIMP CArchiveExtractCallback::SetOperationResult(Int32 opRes)
else
NumFiles++;
- if (!_stdOutMode && _extractMode && _fi.AttribDefined)
- SetFileAttrib(_diskFilePath, _fi.Attrib);
+ if (_needSetAttrib)
+ SetAttrib();
- RINOK(_extractCallback2->SetOperationResult(opRes, BoolToInt(_encrypted)));
+ RINOK(_extractCallback2->SetOperationResult(opRes, BoolToInt(_encrypted)))
return S_OK;
COM_TRY_END
}
-STDMETHODIMP CArchiveExtractCallback::ReportExtractResult(UInt32 indexType, UInt32 index, Int32 opRes)
+
+
+Z7_COM7F_IMF(CArchiveExtractCallback::ReportExtractResult(UInt32 indexType, UInt32 index, Int32 opRes))
{
if (_folderArchiveExtractCallback2)
{
bool isEncrypted = false;
- wchar_t temp[16];
- UString s2;
- const wchar_t *s = NULL;
+ UString s;
if (indexType == NArchive::NEventIndexType::kInArcIndex && index != (UInt32)(Int32)-1)
{
CReadArcItem item;
- RINOK(_arc->GetItem(index, item));
- s2 = item.Path;
- s = s2;
- RINOK(Archive_GetItemBoolProp(_arc->Archive, index, kpidEncrypted, isEncrypted));
+ RINOK(_arc->GetItem(index, item))
+ s = item.Path;
+ RINOK(Archive_GetItemBoolProp(_arc->Archive, index, kpidEncrypted, isEncrypted))
}
else
{
- temp[0] = '#';
- ConvertUInt32ToString(index, temp + 1);
- s = temp;
+ s = '#';
+ s.Add_UInt32(index);
// if (indexType == NArchive::NEventIndexType::kBlockIndex) {}
}
@@ -1552,84 +2414,179 @@ STDMETHODIMP CArchiveExtractCallback::ReportExtractResult(UInt32 indexType, UInt
}
-STDMETHODIMP CArchiveExtractCallback::CryptoGetTextPassword(BSTR *password)
+Z7_COM7F_IMF(CArchiveExtractCallback::CryptoGetTextPassword(BSTR *password))
{
COM_TRY_BEGIN
if (!_cryptoGetTextPassword)
{
RINOK(_extractCallback2.QueryInterface(IID_ICryptoGetTextPassword,
- &_cryptoGetTextPassword));
+ &_cryptoGetTextPassword))
}
return _cryptoGetTextPassword->CryptoGetTextPassword(password);
COM_TRY_END
}
-struct CExtrRefSortPair
+// ---------- HASH functions ----------
+
+FString CArchiveExtractCallback::Hash_GetFullFilePath()
{
- unsigned Len;
- unsigned Index;
+ // this function changes _item.PathParts.
+ CorrectPathParts();
+ const UStringVector &pathParts = _item.PathParts;
+ const UString processedPath (MakePathFromParts(pathParts));
+ FString fullProcessedPath (us2fs(processedPath));
+ if (_pathMode != NExtract::NPathMode::kAbsPaths
+ || !NName::IsAbsolutePath(processedPath))
+ {
+ fullProcessedPath = MakePath_from_2_Parts(
+ DirPathPrefix_for_HashFiles,
+ // _dirPathPrefix,
+ fullProcessedPath);
+ }
+ return fullProcessedPath;
+}
- int Compare(const CExtrRefSortPair &a) const;
-};
-#define RINOZ(x) { int __tt = (x); if (__tt != 0) return __tt; }
+Z7_COM7F_IMF(CArchiveExtractCallback::GetDiskProperty(UInt32 index, PROPID propID, PROPVARIANT *value))
+{
+ COM_TRY_BEGIN
+ NCOM::CPropVariant prop;
+ if (propID == kpidSize)
+ {
+ RINOK(GetItem(index))
+ const FString fullProcessedPath = Hash_GetFullFilePath();
+ NFile::NFind::CFileInfo fi;
+ if (fi.Find_FollowLink(fullProcessedPath))
+ if (!fi.IsDir())
+ prop = (UInt64)fi.Size;
+ }
+ prop.Detach(value);
+ return S_OK;
+ COM_TRY_END
+}
+
+
+Z7_COM7F_IMF(CArchiveExtractCallback::GetStream2(UInt32 index, ISequentialInStream **inStream, UInt32 mode))
+{
+ COM_TRY_BEGIN
+ *inStream = NULL;
+ // if (index != _index) return E_FAIL;
+ if (mode != NUpdateNotifyOp::kHashRead)
+ return E_FAIL;
+
+ RINOK(GetItem(index))
+ const FString fullProcessedPath = Hash_GetFullFilePath();
+
+ CInFileStream *inStreamSpec = new CInFileStream;
+ CMyComPtr<ISequentialInStream> inStreamRef = inStreamSpec;
+ inStreamSpec->Set_PreserveATime(_ntOptions.PreserveATime);
+ if (!inStreamSpec->OpenShared(fullProcessedPath, _ntOptions.OpenShareForWrite))
+ {
+ RINOK(SendMessageError_with_LastError(kCantOpenInFile, fullProcessedPath))
+ return S_OK;
+ }
+ *inStream = inStreamRef.Detach();
+ return S_OK;
+ COM_TRY_END
+}
+
-int CExtrRefSortPair::Compare(const CExtrRefSortPair &a) const
+Z7_COM7F_IMF(CArchiveExtractCallback::ReportOperation(
+ UInt32 /* indexType */, UInt32 /* index */, UInt32 /* op */))
{
- RINOZ(-MyCompare(Len, a.Len));
- return MyCompare(Index, a.Index);
+ // COM_TRY_BEGIN
+ return S_OK;
+ // COM_TRY_END
}
-static unsigned GetNumSlashes(const FChar *s)
+
+// ------------ After Extracting functions ------------
+
+void CDirPathSortPair::SetNumSlashes(const FChar *s)
{
for (unsigned numSlashes = 0;;)
{
FChar c = *s++;
if (c == 0)
- return numSlashes;
+ {
+ Len = numSlashes;
+ return;
+ }
if (IS_PATH_SEPAR(c))
numSlashes++;
}
}
+
+bool CDirPathTime::SetDirTime() const
+{
+ return NDir::SetDirTime(Path,
+ CTime_Defined ? &CTime : NULL,
+ ATime_Defined ? &ATime : NULL,
+ MTime_Defined ? &MTime : NULL);
+}
+
+
HRESULT CArchiveExtractCallback::SetDirsTimes()
{
- CRecordVector<CExtrRefSortPair> pairs;
- pairs.ClearAndSetSize(_extractedFolderPaths.Size());
+ if (!_arc)
+ return S_OK;
+
+ CRecordVector<CDirPathSortPair> pairs;
+ pairs.ClearAndSetSize(_extractedFolders.Size());
unsigned i;
- for (i = 0; i < _extractedFolderPaths.Size(); i++)
+ for (i = 0; i < _extractedFolders.Size(); i++)
{
- CExtrRefSortPair &pair = pairs[i];
+ CDirPathSortPair &pair = pairs[i];
pair.Index = i;
- pair.Len = GetNumSlashes(_extractedFolderPaths[i]);
+ pair.SetNumSlashes(_extractedFolders[i].Path);
}
pairs.Sort2();
+ HRESULT res = S_OK;
+
for (i = 0; i < pairs.Size(); i++)
{
- int pairIndex = pairs[i].Index;
- int index = _extractedFolderIndices[pairIndex];
+ const CDirPathTime &dpt = _extractedFolders[pairs[i].Index];
+ if (!dpt.SetDirTime())
+ {
+ // result = E_FAIL;
+ // do we need error message here in Windows and in posix?
+ // SendMessageError_with_LastError("Cannot set directory time", dpt.Path);
+ }
+ }
- FILETIME CTime;
- FILETIME ATime;
- FILETIME MTime;
-
- bool CTimeDefined;
- bool ATimeDefined;
- bool MTimeDefined;
+ /*
+ #ifndef _WIN32
+ for (i = 0; i < _delayedSymLinks.Size(); i++)
+ {
+ const CDelayedSymLink &link = _delayedSymLinks[i];
+ if (!link.Create())
+ {
+ if (res == S_OK)
+ res = GetLastError_noZero_HRESULT();
+ // res = E_FAIL;
+ // do we need error message here in Windows and in posix?
+ SendMessageError_with_LastError("Cannot create Symbolic Link", link._source);
+ }
+ }
+ #endif // _WIN32
+ */
- RINOK(GetTime(index, kpidCTime, CTime, CTimeDefined));
- RINOK(GetTime(index, kpidATime, ATime, ATimeDefined));
- RINOK(GetTime(index, kpidMTime, MTime, MTimeDefined));
+ ClearExtractedDirsInfo();
+ return res;
+}
- // printf("\n%S", _extractedFolderPaths[pairIndex]);
- SetDirTime(_extractedFolderPaths[pairIndex],
- (WriteCTime && CTimeDefined) ? &CTime : NULL,
- (WriteATime && ATimeDefined) ? &ATime : NULL,
- (WriteMTime && MTimeDefined) ? &MTime : (_arc->MTimeDefined ? &_arc->MTime : NULL));
- }
- return S_OK;
+
+HRESULT CArchiveExtractCallback::CloseArc()
+{
+ HRESULT res = CloseReparseAndFile();
+ const HRESULT res2 = SetDirsTimes();
+ if (res == S_OK)
+ res = res2;
+ _arc = NULL;
+ return res;
}
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveExtractCallback.h b/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveExtractCallback.h
index 7d4155fe2e7..5ed20f3f0a8 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveExtractCallback.h
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveExtractCallback.h
@@ -1,15 +1,17 @@
// ArchiveExtractCallback.h
-#ifndef __ARCHIVE_EXTRACT_CALLBACK_H
-#define __ARCHIVE_EXTRACT_CALLBACK_H
+#ifndef ZIP7_INC_ARCHIVE_EXTRACT_CALLBACK_H
+#define ZIP7_INC_ARCHIVE_EXTRACT_CALLBACK_H
#include "../../../Common/MyCom.h"
+#include "../../../Common/MyLinux.h"
#include "../../../Common/Wildcard.h"
#include "../../IPassword.h"
#include "../../Common/FileStreams.h"
#include "../../Common/ProgressUtils.h"
+#include "../../Common/StreamObjects.h"
#include "../../Archive/IArchive.h"
@@ -19,20 +21,18 @@
#include "HashCalc.h"
-#ifndef _SFX
+#ifndef Z7_SFX
-class COutStreamWithHash:
- public ISequentialOutStream,
- public CMyUnknownImp
-{
+Z7_CLASS_IMP_NOQIB_1(
+ COutStreamWithHash
+ , ISequentialOutStream
+)
CMyComPtr<ISequentialOutStream> _stream;
UInt64 _size;
bool _calculate;
public:
IHashCalc *_hash;
- MY_UNKNOWN_IMP
- STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
void SetStream(ISequentialOutStream *stream) { _stream = stream; }
void ReleaseStream() { _stream.Release(); }
void Init(bool calculate = true)
@@ -52,39 +52,56 @@ struct CExtractNtOptions
{
CBoolPair NtSecurity;
CBoolPair SymLinks;
+ CBoolPair SymLinks_AllowDangerous;
CBoolPair HardLinks;
CBoolPair AltStreams;
bool ReplaceColonForAltStream;
bool WriteToAltStreamIfColon;
+ bool ExtractOwner;
+
+ bool PreAllocateOutFile;
+
+ // used for hash arcs only, when we open external files
+ bool PreserveATime;
+ bool OpenShareForWrite;
+
CExtractNtOptions():
ReplaceColonForAltStream(false),
- WriteToAltStreamIfColon(false)
+ WriteToAltStreamIfColon(false),
+ ExtractOwner(false),
+ PreserveATime(false),
+ OpenShareForWrite(false)
{
SymLinks.Val = true;
+ SymLinks_AllowDangerous.Val = false;
HardLinks.Val = true;
AltStreams.Val = true;
+
+ PreAllocateOutFile =
+ #ifdef _WIN32
+ true;
+ #else
+ false;
+ #endif
}
};
-#ifndef _SFX
+#ifndef Z7_SFX
-class CGetProp:
- public IGetProp,
- public CMyUnknownImp
-{
+Z7_CLASS_IMP_COM_1(
+ CGetProp
+ , IGetProp
+)
public:
- const CArc *Arc;
UInt32 IndexInArc;
+ const CArc *Arc;
// UString Name; // relative path
-
- MY_UNKNOWN_IMP1(IGetProp)
- INTERFACE_IGetProp(;)
};
#endif
-#ifndef _SFX
+#ifndef Z7_SFX
#ifndef UNDER_CE
#define SUPPORT_LINKS
@@ -142,29 +159,160 @@ struct CIndexToPathPair
#endif
-class CArchiveExtractCallback:
+
+
+struct CFiTimesCAM
+{
+ CFiTime CTime;
+ CFiTime ATime;
+ CFiTime MTime;
+
+ bool CTime_Defined;
+ bool ATime_Defined;
+ bool MTime_Defined;
+
+ bool IsSomeTimeDefined() const
+ {
+ return
+ CTime_Defined |
+ ATime_Defined |
+ MTime_Defined;
+ }
+};
+
+struct CDirPathTime: public CFiTimesCAM
+{
+ FString Path;
+
+ bool SetDirTime() const;
+};
+
+
+#ifdef SUPPORT_LINKS
+
+struct CLinkInfo
+{
+ // bool isCopyLink;
+ bool isHardLink;
+ bool isJunction;
+ bool isRelative;
+ bool isWSL;
+ UString linkPath;
+
+ bool IsSymLink() const { return !isHardLink; }
+
+ CLinkInfo():
+ // IsCopyLink(false),
+ isHardLink(false),
+ isJunction(false),
+ isRelative(false),
+ isWSL(false)
+ {}
+
+ void Clear()
+ {
+ // IsCopyLink = false;
+ isHardLink = false;
+ isJunction = false;
+ isRelative = false;
+ isWSL = false;
+ linkPath.Empty();
+ }
+
+ bool Parse(const Byte *data, size_t dataSize, bool isLinuxData);
+};
+
+#endif // SUPPORT_LINKS
+
+
+#ifndef _WIN32
+
+struct COwnerInfo
+{
+ bool Id_Defined;
+ UInt32 Id;
+ AString Name;
+
+ void Clear()
+ {
+ Id_Defined = false;
+ Id = 0;
+ Name.Empty();
+ }
+};
+
+#endif
+
+
+class CArchiveExtractCallback Z7_final:
public IArchiveExtractCallback,
- public IArchiveExtractCallbackMessage,
+ public IArchiveExtractCallbackMessage2,
public ICryptoGetTextPassword,
public ICompressProgressInfo,
+ public IArchiveUpdateCallbackFile,
+ public IArchiveGetDiskProperty,
public CMyUnknownImp
{
+ Z7_COM_UNKNOWN_IMP_5(
+ /* IArchiveExtractCallback, */
+ IArchiveExtractCallbackMessage2,
+ ICryptoGetTextPassword,
+ ICompressProgressInfo,
+ IArchiveUpdateCallbackFile,
+ IArchiveGetDiskProperty)
+
+ Z7_IFACE_COM7_IMP(IProgress)
+ Z7_IFACE_COM7_IMP(IArchiveExtractCallback)
+ Z7_IFACE_COM7_IMP(IArchiveExtractCallbackMessage2)
+ Z7_IFACE_COM7_IMP(ICryptoGetTextPassword)
+ Z7_IFACE_COM7_IMP(ICompressProgressInfo)
+ Z7_IFACE_COM7_IMP(IArchiveUpdateCallbackFile)
+ Z7_IFACE_COM7_IMP(IArchiveGetDiskProperty)
+
const CArc *_arc;
CExtractNtOptions _ntOptions;
+ bool _isSplit;
+
+ bool _extractMode;
+
+ bool Write_CTime;
+ bool Write_ATime;
+ bool Write_MTime;
+ bool _keepAndReplaceEmptyDirPrefixes; // replace them to "_";
+
+ bool _encrypted;
+
+ // bool _is_SymLink_in_Data;
+ bool _is_SymLink_in_Data_Linux; // false = WIN32, true = LINUX
+
+ bool _needSetAttrib;
+ bool _isSymLinkCreated;
+ bool _itemFailure;
+
+ bool _curSize_Defined;
+ bool _fileLength_WasSet;
+
+ bool _removePartsForAltStreams;
+
+ bool _stdOutMode;
+ bool _testMode;
+ bool _multiArchives;
+
+ NExtract::NPathMode::EEnum _pathMode;
+ NExtract::NOverwriteMode::EEnum _overwriteMode;
+
const NWildcard::CCensorNode *_wildcardCensor; // we need wildcard for single pass mode (stdin)
CMyComPtr<IFolderArchiveExtractCallback> _extractCallback2;
- CMyComPtr<ICompressProgressInfo> _compressProgress;
- CMyComPtr<ICryptoGetTextPassword> _cryptoGetTextPassword;
- CMyComPtr<IArchiveExtractCallbackMessage> _callbackMessage;
+ // CMyComPtr<ICompressProgressInfo> _compressProgress;
+ // CMyComPtr<IArchiveExtractCallbackMessage2> _callbackMessage;
CMyComPtr<IFolderArchiveExtractCallback2> _folderArchiveExtractCallback2;
+ CMyComPtr<ICryptoGetTextPassword> _cryptoGetTextPassword;
FString _dirPathPrefix;
FString _dirPathPrefix_Full;
- NExtract::NPathMode::EEnum _pathMode;
- NExtract::NOverwriteMode::EEnum _overwriteMode;
- #ifndef _SFX
+ #ifndef Z7_SFX
CMyComPtr<IFolderExtractToStreamCallback> ExtractToStreamCallback;
CGetProp *GetProp_Spec;
@@ -175,54 +323,74 @@ class CArchiveExtractCallback:
CReadArcItem _item;
FString _diskFilePath;
UInt64 _position;
- bool _isSplit;
-
- bool _extractMode;
-
- bool WriteCTime;
- bool WriteATime;
- bool WriteMTime;
-
- bool _encrypted;
struct CProcessedFileInfo
{
- FILETIME CTime;
- FILETIME ATime;
- FILETIME MTime;
+ CArcTime CTime;
+ CArcTime ATime;
+ CArcTime MTime;
UInt32 Attrib;
-
- bool CTimeDefined;
- bool ATimeDefined;
- bool MTimeDefined;
- bool AttribDefined;
+ bool Attrib_Defined;
+
+ #ifndef _WIN32
+ COwnerInfo Owner;
+ COwnerInfo Group;
+ #endif
+
+ bool IsReparse() const
+ {
+ return (Attrib_Defined && (Attrib & FILE_ATTRIBUTE_REPARSE_POINT) != 0);
+ }
+
+ bool IsLinuxSymLink() const
+ {
+ return (Attrib_Defined && MY_LIN_S_ISLNK(Attrib >> 16));
+ }
+
+ void SetFromPosixAttrib(UInt32 a)
+ {
+ // here we set only part of combined attribute required by SetFileAttrib() call
+ #ifdef _WIN32
+ // Windows sets FILE_ATTRIBUTE_NORMAL, if we try to set 0 as attribute.
+ Attrib = MY_LIN_S_ISDIR(a) ?
+ FILE_ATTRIBUTE_DIRECTORY :
+ FILE_ATTRIBUTE_ARCHIVE;
+ if ((a & 0222) == 0) // (& S_IWUSR) in p7zip
+ Attrib |= FILE_ATTRIBUTE_READONLY;
+ // 22.00 : we need type bits for (MY_LIN_S_IFLNK) for IsLinuxSymLink()
+ a &= MY_LIN_S_IFMT;
+ if (a == MY_LIN_S_IFLNK)
+ Attrib |= (a << 16);
+ #else
+ Attrib = (a << 16) | FILE_ATTRIBUTE_UNIX_EXTENSION;
+ #endif
+ Attrib_Defined = true;
+ }
} _fi;
UInt32 _index;
UInt64 _curSize;
- bool _curSizeDefined;
+ UInt64 _fileLength_that_WasSet;
+
COutFileStream *_outFileStreamSpec;
CMyComPtr<ISequentialOutStream> _outFileStream;
- #ifndef _SFX
+ CByteBuffer _outMemBuf;
+ CBufPtrSeqOutStream *_bufPtrSeqOutStream_Spec;
+ CMyComPtr<ISequentialOutStream> _bufPtrSeqOutStream;
+
+
+ #ifndef Z7_SFX
COutStreamWithHash *_hashStreamSpec;
CMyComPtr<ISequentialOutStream> _hashStream;
bool _hashStreamWasUsed;
- #endif
-
- bool _removePartsForAltStreams;
- UStringVector _removePathParts;
-
- #ifndef _SFX
bool _use_baseParentFolder_mode;
UInt32 _baseParentFolder;
- #endif
+ #endif
- bool _stdOutMode;
- bool _testMode;
- bool _multiArchives;
+ UStringVector _removePathParts;
CMyComPtr<ICompressProgressInfo> _localProgress;
UInt64 _packTotal;
@@ -230,22 +398,34 @@ class CArchiveExtractCallback:
UInt64 _progressTotal;
bool _progressTotal_Defined;
- FStringVector _extractedFolderPaths;
- CRecordVector<UInt32> _extractedFolderIndices;
+ CObjectVector<CDirPathTime> _extractedFolders;
+
+ #ifndef _WIN32
+ // CObjectVector<NWindows::NFile::NDir::CDelayedSymLink> _delayedSymLinks;
+ #endif
- #if defined(_WIN32) && !defined(UNDER_CE) && !defined(_SFX)
+ #if defined(_WIN32) && !defined(UNDER_CE) && !defined(Z7_SFX)
bool _saclEnabled;
#endif
void CreateComplexDirectory(const UStringVector &dirPathParts, FString &fullPath);
- HRESULT GetTime(int index, PROPID propID, FILETIME &filetime, bool &filetimeIsDefined);
+ HRESULT GetTime(UInt32 index, PROPID propID, CArcTime &ft);
HRESULT GetUnpackSize();
+ FString Hash_GetFullFilePath();
+
+ void SetAttrib();
+
+public:
HRESULT SendMessageError(const char *message, const FString &path);
HRESULT SendMessageError_with_LastError(const char *message, const FString &path);
- HRESULT SendMessageError2(const char *message, const FString &path1, const FString &path2);
+ HRESULT SendMessageError2(HRESULT errorCode, const char *message, const FString &path1, const FString &path2);
public:
+ #if defined(_WIN32) && !defined(UNDER_CE)
+ NExtract::NZoneIdMode::EEnum ZoneMode;
+ CByteBuffer ZoneBuf;
+ #endif
CLocalProgress *LocalProgressSpec;
@@ -255,28 +435,29 @@ public:
UInt64 UnpackSize;
UInt64 AltStreams_UnpackSize;
- MY_UNKNOWN_IMP3(IArchiveExtractCallbackMessage, ICryptoGetTextPassword, ICompressProgressInfo)
-
- INTERFACE_IArchiveExtractCallback(;)
- INTERFACE_IArchiveExtractCallbackMessage(;)
-
- STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);
-
- STDMETHOD(CryptoGetTextPassword)(BSTR *password);
+ FString DirPathPrefix_for_HashFiles;
CArchiveExtractCallback();
void InitForMulti(bool multiArchives,
NExtract::NPathMode::EEnum pathMode,
- NExtract::NOverwriteMode::EEnum overwriteMode)
+ NExtract::NOverwriteMode::EEnum overwriteMode,
+ NExtract::NZoneIdMode::EEnum zoneMode,
+ bool keepAndReplaceEmptyDirPrefixes)
{
_multiArchives = multiArchives;
_pathMode = pathMode;
_overwriteMode = overwriteMode;
+ #if defined(_WIN32) && !defined(UNDER_CE)
+ ZoneMode = zoneMode;
+ #else
+ UNUSED_VAR(zoneMode)
+ #endif
+ _keepAndReplaceEmptyDirPrefixes = keepAndReplaceEmptyDirPrefixes;
NumFolders = NumFiles = NumAltStreams = UnpackSize = AltStreams_UnpackSize = 0;
}
- #ifndef _SFX
+ #ifndef Z7_SFX
void SetHashMethods(IHashCalc *hash)
{
@@ -289,6 +470,8 @@ public:
#endif
+ void InitBeforeNewArchive();
+
void Init(
const CExtractNtOptions &ntOptions,
const NWildcard::CCensorNode *wildcardCensor,
@@ -304,10 +487,12 @@ public:
private:
CHardLinks _hardLinks;
- UString linkPath;
+ CLinkInfo _link;
- // FString _CopyFile_Path;
+ // FString _copyFile_Path;
// HRESULT MyCopyFile(ISequentialOutStream *outStream);
+ HRESULT Link(const FString &fullProcessedPath);
+ HRESULT ReadLink();
public:
// call PrepareHardLinks() after Init()
@@ -322,7 +507,7 @@ public:
// call it after Init()
- #ifndef _SFX
+ #ifndef Z7_SFX
void SetBaseParentFolderIndex(UInt32 indexInArc)
{
_baseParentFolder = indexInArc;
@@ -330,9 +515,70 @@ public:
}
#endif
+ HRESULT CloseArc();
+
+private:
+ void ClearExtractedDirsInfo()
+ {
+ _extractedFolders.Clear();
+ #ifndef _WIN32
+ // _delayedSymLinks.Clear();
+ #endif
+ }
+
+ HRESULT Read_fi_Props();
+ void CorrectPathParts();
+ void GetFiTimesCAM(CFiTimesCAM &pt);
+ void CreateFolders();
+
+ bool _isRenamed;
+ HRESULT CheckExistFile(FString &fullProcessedPath, bool &needExit);
+ HRESULT GetExtractStream(CMyComPtr<ISequentialOutStream> &outStreamLoc, bool &needExit);
+ HRESULT GetItem(UInt32 index);
+
+ HRESULT CloseFile();
+ HRESULT CloseReparseAndFile();
+ HRESULT CloseReparseAndFile2();
HRESULT SetDirsTimes();
+
+ const void *NtReparse_Data;
+ UInt32 NtReparse_Size;
+
+ #ifdef SUPPORT_LINKS
+ HRESULT SetFromLinkPath(
+ const FString &fullProcessedPath,
+ const CLinkInfo &linkInfo,
+ bool &linkWasSet);
+ #endif
+};
+
+
+struct CArchiveExtractCallback_Closer
+{
+ CArchiveExtractCallback *_ref;
+
+ CArchiveExtractCallback_Closer(CArchiveExtractCallback *ref): _ref(ref) {}
+
+ HRESULT Close()
+ {
+ HRESULT res = S_OK;
+ if (_ref)
+ {
+ res = _ref->CloseArc();
+ _ref = NULL;
+ }
+ return res;
+ }
+
+ ~CArchiveExtractCallback_Closer()
+ {
+ Close();
+ }
};
+
bool CensorNode_CheckPath(const NWildcard::CCensorNode &node, const CReadArcItem &item);
+void ReadZoneFile_Of_BaseFile(CFSTR fileName2, CByteBuffer &buf);
+
#endif
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveName.cpp b/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveName.cpp
index 06d2ab80895..1c0c3a821b1 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveName.cpp
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveName.cpp
@@ -2,77 +2,175 @@
#include "StdAfx.h"
+#include "../../../../C/Sort.h"
+
+#include "../../../Common/Wildcard.h"
+#include "../../../Common/StringToInt.h"
+
#include "../../../Windows/FileDir.h"
#include "../../../Windows/FileName.h"
-#include "ExtractingFilePath.h"
#include "ArchiveName.h"
+#include "ExtractingFilePath.h"
using namespace NWindows;
using namespace NFile;
-UString CreateArchiveName(const NFind::CFileInfo &fi, bool keepName)
+
+static const char *g_ArcExts =
+ "7z"
+ "\0" "zip"
+ "\0" "tar"
+ "\0" "wim"
+ "\0";
+
+static const char *g_HashExts =
+ "sha256"
+ "\0";
+
+
+UString CreateArchiveName(
+ const UStringVector &paths,
+ bool isHash,
+ const NFind::CFileInfo *fi,
+ UString &baseName)
{
- FString resultName = fi.Name;
- if (!fi.IsDir() && !keepName)
+ bool keepName = isHash;
+ /*
+ if (paths.Size() == 1)
{
- int dotPos = resultName.ReverseFind_Dot();
- if (dotPos > 0)
- {
- FString archiveName2 = resultName.Left(dotPos);
- if (archiveName2.ReverseFind_Dot() < 0)
- resultName = archiveName2;
- }
+ const UString &name = paths[0];
+ if (name.Len() > 4)
+ if (CompareFileNames(name.RightPtr(4), L".tar") == 0)
+ keepName = true;
}
- return Get_Correct_FsFile_Name(fs2us(resultName));
-}
+ */
-static FString CreateArchiveName2(const FString &path, bool fromPrev, bool keepName)
-{
- FString resultName = FTEXT("Archive");
- if (fromPrev)
+ UString name ("Archive");
+ NFind::CFileInfo fi3;
+ if (paths.Size() > 1)
+ fi = NULL;
+ if (!fi && paths.Size() != 0)
{
- FString dirPrefix;
- if (NDir::GetOnlyDirPrefix(path, dirPrefix))
+ const UString &path = paths.Front();
+ if (paths.Size() == 1)
+ {
+ if (fi3.Find(us2fs(path)))
+ fi = &fi3;
+ }
+ else
{
- if (!dirPrefix.IsEmpty() && IsPathSepar(dirPrefix.Back()))
+ // we try to use name of parent folder
+ FString dirPrefix;
+ if (NDir::GetOnlyDirPrefix(us2fs(path), dirPrefix))
{
- #if defined(_WIN32) && !defined(UNDER_CE)
- if (NName::IsDriveRootPath_SuperAllowed(dirPrefix))
- resultName = dirPrefix[dirPrefix.Len() - 3]; // only letter
- else
- #endif
+ if (!dirPrefix.IsEmpty() && IsPathSepar(dirPrefix.Back()))
{
- dirPrefix.DeleteBack();
- NFind::CFileInfo fi;
- if (fi.Find(dirPrefix))
- resultName = fi.Name;
+ #if defined(_WIN32) && !defined(UNDER_CE)
+ if (NName::IsDriveRootPath_SuperAllowed(dirPrefix))
+ {
+ if (path != fs2us(dirPrefix))
+ name = dirPrefix[dirPrefix.Len() - 3]; // only letter
+ }
+ else
+ #endif
+ {
+ dirPrefix.DeleteBack();
+ if (!dirPrefix.IsEmpty())
+ {
+ const int slash = dirPrefix.ReverseFind_PathSepar();
+ if (slash >= 0 && slash != (int)dirPrefix.Len() - 1)
+ name = dirPrefix.Ptr(slash + 1);
+ else if (fi3.Find(dirPrefix))
+ name = fs2us(fi3.Name);
+ }
+ }
}
}
}
}
- else
+
+ if (fi)
{
- NFind::CFileInfo fi;
- if (fi.Find(path))
+ name = fs2us(fi->Name);
+ if (!fi->IsDir() && !keepName)
+ {
+ const int dotPos = name.Find(L'.');
+ if (dotPos > 0 && name.Find(L'.', (unsigned)dotPos + 1) < 0)
+ name.DeleteFrom((unsigned)dotPos);
+ }
+ }
+ name = Get_Correct_FsFile_Name(name);
+
+ CRecordVector<UInt32> ids;
+ bool simple_IsAllowed = true;
+ // for (int y = 0; y < 10000; y++) // for debug
+ {
+ // ids.Clear();
+ UString n;
+
+ FOR_VECTOR (i, paths)
{
- resultName = fi.Name;
- if (!fi.IsDir() && !keepName)
+ const UString &a = paths[i];
+ const int slash = a.ReverseFind_PathSepar();
+ // if (name.Len() >= a.Len() - slash + 1) continue;
+ const wchar_t *s = a.Ptr(slash + 1);
+ if (!IsPath1PrefixedByPath2(s, name))
+ continue;
+ s += name.Len();
+ const char *exts = isHash ? g_HashExts : g_ArcExts;
+
+ for (;;)
{
- int dotPos = resultName.ReverseFind_Dot();
- if (dotPos > 0)
+ const char *ext = exts;
+ const unsigned len = MyStringLen(ext);
+ if (len == 0)
+ break;
+ exts += len + 1;
+ n = s;
+ if (n.Len() <= len)
+ continue;
+ if (!StringsAreEqualNoCase_Ascii(n.RightPtr(len), ext))
+ continue;
+ n.DeleteFrom(n.Len() - len);
+ if (n.Back() != '.')
+ continue;
+ n.DeleteBack();
+ if (n.IsEmpty())
{
- FString name2 = resultName.Left(dotPos);
- if (name2.ReverseFind_Dot() < 0)
- resultName = name2;
+ simple_IsAllowed = false;
+ break;
}
+ if (n.Len() < 2)
+ continue;
+ if (n[0] != '_')
+ continue;
+ const wchar_t *end;
+ const UInt32 v = ConvertStringToUInt32(n.Ptr(1), &end);
+ if (*end != 0)
+ continue;
+ ids.Add(v);
+ break;
}
}
}
- return resultName;
-}
-UString CreateArchiveName(const UString &path, bool fromPrev, bool keepName)
-{
- return Get_Correct_FsFile_Name(fs2us(CreateArchiveName2(us2fs(path), fromPrev, keepName)));
+ baseName = name;
+ if (!simple_IsAllowed)
+ {
+ HeapSort(&ids.Front(), ids.Size());
+ UInt32 v = 2;
+ const unsigned num = ids.Size();
+ for (unsigned i = 0; i < num; i++)
+ {
+ const UInt32 id = ids[i];
+ if (id > v)
+ break;
+ if (id == v)
+ v = id + 1;
+ }
+ name += '_';
+ name.Add_UInt32(v);
+ }
+ return name;
}
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveName.h b/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveName.h
index ec2f1e8d1d9..9b6b7fe9d38 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveName.h
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveName.h
@@ -1,13 +1,16 @@
// ArchiveName.h
-#ifndef __ARCHIVE_NAME_H
-#define __ARCHIVE_NAME_H
-
-#include "../../../Common/MyString.h"
+#ifndef ZIP7_INC_ARCHIVE_NAME_H
+#define ZIP7_INC_ARCHIVE_NAME_H
#include "../../../Windows/FileFind.h"
-UString CreateArchiveName(const UString &path, bool fromPrev, bool keepName);
-UString CreateArchiveName(const NWindows::NFile::NFind::CFileInfo &fileInfo, bool keepName);
+/* (fi != NULL) only if (paths.Size() == 1) */
+
+UString CreateArchiveName(
+ const UStringVector &paths,
+ bool isHash,
+ const NWindows::NFile::NFind::CFileInfo *fi,
+ UString &baseName);
#endif
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveOpenCallback.cpp b/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveOpenCallback.cpp
index fd2807ac149..4e5f1f56041 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveOpenCallback.cpp
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveOpenCallback.cpp
@@ -6,14 +6,54 @@
#include "../../../Windows/FileName.h"
#include "../../../Windows/PropVariant.h"
+#include "../../../Windows/System.h"
-#include "../../Common/FileStreams.h"
+#include "../../Common/StreamUtils.h"
#include "ArchiveOpenCallback.h"
+// #define DEBUG_VOLUMES
+
+#ifdef DEBUG_VOLUMES
+#include <stdio.h>
+#endif
+
+
+#ifdef DEBUG_VOLUMES
+ #define PRF(x) x
+#else
+ #define PRF(x)
+#endif
+
using namespace NWindows;
-STDMETHODIMP COpenCallbackImp::SetTotal(const UInt64 *files, const UInt64 *bytes)
+HRESULT COpenCallbackImp::Init2(const FString &folderPrefix, const FString &fileName)
+{
+ Volumes.Init();
+ FileNames.Clear();
+ FileNames_WasUsed.Clear();
+ FileSizes.Clear();
+ _subArchiveMode = false;
+ // TotalSize = 0;
+ PasswordWasAsked = false;
+ _folderPrefix = folderPrefix;
+ if (!_fileInfo.Find_FollowLink(_folderPrefix + fileName))
+ {
+ // throw 20121118;
+ return GetLastError_noZero_HRESULT();
+ }
+ return S_OK;
+}
+
+Z7_COM7F_IMF(COpenCallbackImp::SetSubArchiveName(const wchar_t *name))
+{
+ _subArchiveMode = true;
+ _subArchiveName = name;
+ // TotalSize = 0;
+ return S_OK;
+}
+
+Z7_COM7F_IMF(COpenCallbackImp::SetTotal(const UInt64 *files, const UInt64 *bytes))
{
COM_TRY_BEGIN
if (ReOpenCallback)
@@ -24,7 +64,7 @@ STDMETHODIMP COpenCallbackImp::SetTotal(const UInt64 *files, const UInt64 *bytes
COM_TRY_END
}
-STDMETHODIMP COpenCallbackImp::SetCompleted(const UInt64 *files, const UInt64 *bytes)
+Z7_COM7F_IMF(COpenCallbackImp::SetCompleted(const UInt64 *files, const UInt64 *bytes))
{
COM_TRY_BEGIN
if (ReOpenCallback)
@@ -34,8 +74,9 @@ STDMETHODIMP COpenCallbackImp::SetCompleted(const UInt64 *files, const UInt64 *b
return Callback->Open_SetCompleted(files, bytes);
COM_TRY_END
}
-
-STDMETHODIMP COpenCallbackImp::GetProperty(PROPID propID, PROPVARIANT *value)
+
+
+Z7_COM7F_IMF(COpenCallbackImp::GetProperty(PROPID propID, PROPVARIANT *value))
{
COM_TRY_BEGIN
NCOM::CPropVariant prop;
@@ -48,37 +89,194 @@ STDMETHODIMP COpenCallbackImp::GetProperty(PROPID propID, PROPVARIANT *value)
else
switch (propID)
{
- case kpidName: prop = _fileInfo.Name; break;
+ case kpidName: prop = fs2us(_fileInfo.Name); break;
case kpidIsDir: prop = _fileInfo.IsDir(); break;
case kpidSize: prop = _fileInfo.Size; break;
- case kpidAttrib: prop = (UInt32)_fileInfo.Attrib; break;
- case kpidCTime: prop = _fileInfo.CTime; break;
- case kpidATime: prop = _fileInfo.ATime; break;
- case kpidMTime: prop = _fileInfo.MTime; break;
+ case kpidAttrib: prop = (UInt32)_fileInfo.GetWinAttrib(); break;
+ case kpidPosixAttrib: prop = (UInt32)_fileInfo.GetPosixAttrib(); break;
+ case kpidCTime: PropVariant_SetFrom_FiTime(prop, _fileInfo.CTime); break;
+ case kpidATime: PropVariant_SetFrom_FiTime(prop, _fileInfo.ATime); break;
+ case kpidMTime: PropVariant_SetFrom_FiTime(prop, _fileInfo.MTime); break;
}
prop.Detach(value);
return S_OK;
COM_TRY_END
}
-struct CInFileStreamVol: public CInFileStream
-{
- int FileNameIndex;
+
+// ---------- CInFileStreamVol ----------
+
+Z7_CLASS_IMP_COM_2(
+ CInFileStreamVol
+ , IInStream
+ , IStreamGetSize
+)
+ Z7_IFACE_COM7_IMP(ISequentialInStream)
+public:
+ unsigned FileIndex;
COpenCallbackImp *OpenCallbackImp;
CMyComPtr<IArchiveOpenCallback> OpenCallbackRef;
-
+
+ HRESULT EnsureOpen()
+ {
+ return OpenCallbackImp->Volumes.EnsureOpen(FileIndex);
+ }
+
~CInFileStreamVol()
{
if (OpenCallbackRef)
- OpenCallbackImp->FileNames_WasUsed[FileNameIndex] = false;
+ OpenCallbackImp->AtCloseFile(FileIndex);
}
};
+void CMultiStreams::InsertToList(unsigned index)
+{
+ {
+ CSubStream &s = Streams[index];
+ s.Next = Head;
+ s.Prev = -1;
+ }
+ if (Head != -1)
+ Streams[(unsigned)Head].Prev = (int)index;
+ else
+ {
+ // if (Tail != -1) throw 1;
+ Tail = (int)index;
+ }
+ Head = (int)index;
+ NumListItems++;
+}
+
+// s must bee in List
+void CMultiStreams::RemoveFromList(CSubStream &s)
+{
+ if (s.Next != -1) Streams[(unsigned)s.Next].Prev = s.Prev; else Tail = s.Prev;
+ if (s.Prev != -1) Streams[(unsigned)s.Prev].Next = s.Next; else Head = s.Next;
+ s.Next = -1; // optional
+ s.Prev = -1; // optional
+ NumListItems--;
+}
+
+void CMultiStreams::CloseFile(unsigned index)
+{
+ CSubStream &s = Streams[index];
+ if (s.Stream)
+ {
+ s.Stream.Release();
+ RemoveFromList(s);
+ // s.InFile->Close();
+ // s.IsOpen = false;
+ #ifdef DEBUG_VOLUMES
+ static int numClosing = 0;
+ numClosing++;
+ printf("\nCloseFile %u, total_closes = %u, num_open_files = %u\n", index, numClosing, NumListItems);
+ #endif
+ }
+}
+
+void CMultiStreams::Init()
+{
+ Head = -1;
+ Tail = -1;
+ NumListItems = 0;
+ Streams.Clear();
+}
+
+CMultiStreams::CMultiStreams():
+ Head(-1),
+ Tail(-1),
+ NumListItems(0)
+{
+ NumOpenFiles_AllowedMax = NSystem::Get_File_OPEN_MAX_Reduced_for_3_tasks();
+ PRF(printf("\nNumOpenFiles_Limit = %u\n", NumOpenFiles_AllowedMax));
+}
+
+
+HRESULT CMultiStreams::PrepareToOpenNew()
+{
+ if (NumListItems < NumOpenFiles_AllowedMax)
+ return S_OK;
+ if (Tail == -1)
+ return E_FAIL;
+ CMultiStreams::CSubStream &tailStream = Streams[(unsigned)Tail];
+ RINOK(InStream_GetPos(tailStream.Stream, tailStream.LocalPos))
+ CloseFile((unsigned)Tail);
+ return S_OK;
+}
+
+
+HRESULT CMultiStreams::EnsureOpen(unsigned index)
+{
+ CMultiStreams::CSubStream &s = Streams[index];
+ if (s.Stream)
+ {
+ if ((int)index != Head)
+ {
+ RemoveFromList(s);
+ InsertToList(index);
+ }
+ }
+ else
+ {
+ RINOK(PrepareToOpenNew())
+ {
+ CInFileStream *inFile = new CInFileStream;
+ CMyComPtr<IInStream> inStreamTemp = inFile;
+ if (!inFile->Open(s.Path))
+ return GetLastError_noZero_HRESULT();
+ s.FileSpec = inFile;
+ s.Stream = s.FileSpec;
+ InsertToList(index);
+ }
+ // s.IsOpen = true;
+ if (s.LocalPos != 0)
+ {
+ RINOK(s.Stream->Seek((Int64)s.LocalPos, STREAM_SEEK_SET, &s.LocalPos))
+ }
+ #ifdef DEBUG_VOLUMES
+ static int numOpens = 0;
+ numOpens++;
+ printf("\n-- %u, ReOpen, total_reopens = %u, num_open_files = %u\n", index, numOpens, NumListItems);
+ #endif
+ }
+ return S_OK;
+}
+
+
+Z7_COM7F_IMF(CInFileStreamVol::Read(void *data, UInt32 size, UInt32 *processedSize))
+{
+ if (processedSize)
+ *processedSize = 0;
+ if (size == 0)
+ return S_OK;
+ RINOK(EnsureOpen())
+ CMultiStreams::CSubStream &s = OpenCallbackImp->Volumes.Streams[FileIndex];
+ PRF(printf("\n== %u, Read =%u \n", FileIndex, size));
+ return s.Stream->Read(data, size, processedSize);
+}
+
+Z7_COM7F_IMF(CInFileStreamVol::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition))
+{
+ // if (seekOrigin >= 3) return STG_E_INVALIDFUNCTION;
+ RINOK(EnsureOpen())
+ CMultiStreams::CSubStream &s = OpenCallbackImp->Volumes.Streams[FileIndex];
+ PRF(printf("\n-- %u, Seek seekOrigin=%u Seek =%u\n", FileIndex, seekOrigin, (unsigned)offset));
+ return s.Stream->Seek(offset, seekOrigin, newPosition);
+}
+
+Z7_COM7F_IMF(CInFileStreamVol::GetSize(UInt64 *size))
+{
+ RINOK(EnsureOpen())
+ CMultiStreams::CSubStream &s = OpenCallbackImp->Volumes.Streams[FileIndex];
+ return s.FileSpec->GetSize(size);
+}
+
+
// from ArchiveExtractCallback.cpp
bool IsSafePath(const UString &path);
-STDMETHODIMP COpenCallbackImp::GetStream(const wchar_t *name, IInStream **inStream)
+Z7_COM7F_IMF(COpenCallbackImp::GetStream(const wchar_t *name, IInStream **inStream))
{
COM_TRY_BEGIN
*inStream = NULL;
@@ -87,13 +285,13 @@ STDMETHODIMP COpenCallbackImp::GetStream(const wchar_t *name, IInStream **inStre
return S_FALSE;
if (Callback)
{
- RINOK(Callback->Open_CheckBreak());
+ RINOK(Callback->Open_CheckBreak())
}
UString name2 = name;
- #ifndef _SFX
+ #ifndef Z7_SFX
#ifdef _WIN32
name2.Replace(L'/', WCHAR_PATH_SEPARATOR);
@@ -102,30 +300,58 @@ STDMETHODIMP COpenCallbackImp::GetStream(const wchar_t *name, IInStream **inStre
// if (!allowAbsVolPaths)
if (!IsSafePath(name2))
return S_FALSE;
-
+
+ #ifdef _WIN32
+ /* WIN32 allows wildcards in Find() function
+ and doesn't allow wildcard in File.Open()
+ so we can work without the following wildcard check here */
+ if (name2.Find(L'*') >= 0)
+ return S_FALSE;
+ {
+ unsigned startPos = 0;
+ if (name2.IsPrefixedBy_Ascii_NoCase("\\\\?\\"))
+ startPos = 3;
+ if (name2.Find(L'?', startPos) >= 0)
+ return S_FALSE;
+ }
+ #endif
+
#endif
FString fullPath;
if (!NFile::NName::GetFullPath(_folderPrefix, us2fs(name2), fullPath))
return S_FALSE;
- if (!_fileInfo.Find(fullPath))
+ if (!_fileInfo.Find_FollowLink(fullPath))
return S_FALSE;
if (_fileInfo.IsDir())
return S_FALSE;
- CInFileStreamVol *inFile = new CInFileStreamVol;
- CMyComPtr<IInStream> inStreamTemp = inFile;
- if (!inFile->Open(fullPath))
+
+ CMultiStreams::CSubStream s;
+
{
- DWORD lastError = ::GetLastError();
- if (lastError == 0)
- return E_FAIL;
- return HRESULT_FROM_WIN32(lastError);
+ CInFileStream *inFile = new CInFileStream;
+ CMyComPtr<IInStream> inStreamTemp = inFile;
+ if (!inFile->Open(fullPath))
+ return GetLastError_noZero_HRESULT();
+ RINOK(Volumes.PrepareToOpenNew())
+ s.FileSpec = inFile;
+ s.Stream = s.FileSpec;
+ s.Path = fullPath;
+ // s.Size = _fileInfo.Size;
+ // s.IsOpen = true;
}
+ const unsigned fileIndex = Volumes.Streams.Add(s);
+ Volumes.InsertToList(fileIndex);
+
FileSizes.Add(_fileInfo.Size);
FileNames.Add(name2);
- inFile->FileNameIndex = FileNames_WasUsed.Add(true);
+ FileNames_WasUsed.Add(true);
+
+ CInFileStreamVol *inFile = new CInFileStreamVol;
+ CMyComPtr<IInStream> inStreamTemp = inFile;
+ inFile->FileIndex = fileIndex;
inFile->OpenCallbackImp = this;
inFile->OpenCallbackRef = this;
// TotalSize += _fileInfo.Size;
@@ -134,14 +360,16 @@ STDMETHODIMP COpenCallbackImp::GetStream(const wchar_t *name, IInStream **inStre
COM_TRY_END
}
-#ifndef _NO_CRYPTO
-STDMETHODIMP COpenCallbackImp::CryptoGetTextPassword(BSTR *password)
+
+#ifndef Z7_NO_CRYPTO
+Z7_COM7F_IMF(COpenCallbackImp::CryptoGetTextPassword(BSTR *password))
{
COM_TRY_BEGIN
if (ReOpenCallback)
{
- CMyComPtr<ICryptoGetTextPassword> getTextPassword;
- ReOpenCallback.QueryInterface(IID_ICryptoGetTextPassword, &getTextPassword);
+ Z7_DECL_CMyComPtr_QI_FROM(
+ ICryptoGetTextPassword,
+ getTextPassword, ReOpenCallback)
if (getTextPassword)
return getTextPassword->CryptoGetTextPassword(password);
}
@@ -152,3 +380,14 @@ STDMETHODIMP COpenCallbackImp::CryptoGetTextPassword(BSTR *password)
COM_TRY_END
}
#endif
+
+// IProgress
+Z7_COM7F_IMF(COpenCallbackImp::SetTotal(const UInt64 /* total */))
+{
+ return S_OK;
+}
+
+Z7_COM7F_IMF(COpenCallbackImp::SetCompleted(const UInt64 * /* completed */))
+{
+ return S_OK;
+}
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveOpenCallback.h b/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveOpenCallback.h
index e9575f56123..4e44c9dde21 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveOpenCallback.h
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveOpenCallback.h
@@ -1,111 +1,180 @@
// ArchiveOpenCallback.h
-#ifndef __ARCHIVE_OPEN_CALLBACK_H
-#define __ARCHIVE_OPEN_CALLBACK_H
+#ifndef ZIP7_INC_ARCHIVE_OPEN_CALLBACK_H
+#define ZIP7_INC_ARCHIVE_OPEN_CALLBACK_H
#include "../../../Common/MyCom.h"
#include "../../../Windows/FileFind.h"
-#ifndef _NO_CRYPTO
+#include "../../Common/FileStreams.h"
+
+#ifndef Z7_NO_CRYPTO
#include "../../IPassword.h"
#endif
#include "../../Archive/IArchive.h"
-#ifdef _NO_CRYPTO
+Z7_PURE_INTERFACES_BEGIN
+
+#ifdef Z7_NO_CRYPTO
-#define INTERFACE_IOpenCallbackUI_Crypto(x)
+#define Z7_IFACEM_IOpenCallbackUI_Crypto(x)
#else
-#define INTERFACE_IOpenCallbackUI_Crypto(x) \
- virtual HRESULT Open_CryptoGetTextPassword(BSTR *password) x; \
- /* virtual HRESULT Open_GetPasswordIfAny(bool &passwordIsDefined, UString &password) x; */ \
- /* virtual bool Open_WasPasswordAsked() x; */ \
- /* virtual void Open_Clear_PasswordWasAsked_Flag() x; */ \
+#define Z7_IFACEM_IOpenCallbackUI_Crypto(x) \
+ virtual HRESULT Open_CryptoGetTextPassword(BSTR *password) x \
+ /* virtual HRESULT Open_GetPasswordIfAny(bool &passwordIsDefined, UString &password) x */ \
+ /* virtual bool Open_WasPasswordAsked() x */ \
+ /* virtual void Open_Clear_PasswordWasAsked_Flag() x */ \
#endif
-#define INTERFACE_IOpenCallbackUI(x) \
- virtual HRESULT Open_CheckBreak() x; \
- virtual HRESULT Open_SetTotal(const UInt64 *files, const UInt64 *bytes) x; \
- virtual HRESULT Open_SetCompleted(const UInt64 *files, const UInt64 *bytes) x; \
- virtual HRESULT Open_Finished() x; \
- INTERFACE_IOpenCallbackUI_Crypto(x)
+#define Z7_IFACEN_IOpenCallbackUI(x) \
+ virtual HRESULT Open_CheckBreak() x \
+ virtual HRESULT Open_SetTotal(const UInt64 *files, const UInt64 *bytes) x \
+ virtual HRESULT Open_SetCompleted(const UInt64 *files, const UInt64 *bytes) x \
+ virtual HRESULT Open_Finished() x \
+ Z7_IFACEM_IOpenCallbackUI_Crypto(x)
+
+Z7_IFACE_DECL_PURE(IOpenCallbackUI)
+
+Z7_PURE_INTERFACES_END
+
-struct IOpenCallbackUI
+class CMultiStreams Z7_final
{
- INTERFACE_IOpenCallbackUI(=0)
+public:
+ struct CSubStream
+ {
+ CMyComPtr<IInStream> Stream;
+ CInFileStream *FileSpec;
+ FString Path;
+ // UInt64 Size;
+ UInt64 LocalPos;
+ int Next; // next older
+ int Prev; // prev newer
+ // bool IsOpen;
+
+ CSubStream():
+ FileSpec(NULL),
+ // Size(0),
+ LocalPos(0),
+ Next(-1),
+ Prev(-1)
+ // IsOpen(false)
+ {}
+ };
+
+ CObjectVector<CSubStream> Streams;
+private:
+ // we must use critical section here, if we want to access from different volumnes simultaneously
+ int Head; // newest
+ int Tail; // oldest
+ unsigned NumListItems;
+ unsigned NumOpenFiles_AllowedMax;
+public:
+
+ CMultiStreams();
+ void Init();
+ HRESULT PrepareToOpenNew();
+ void InsertToList(unsigned index);
+ void RemoveFromList(CSubStream &s);
+ void CloseFile(unsigned index);
+ HRESULT EnsureOpen(unsigned index);
};
-class COpenCallbackImp:
+
+/*
+ We need COpenCallbackImp class for multivolume processing.
+ Also we use it as proxy from COM interfaces (IArchiveOpenCallback) to internal (IOpenCallbackUI) interfaces.
+ If archive is multivolume:
+ COpenCallbackImp object will exist after Open stage.
+ COpenCallbackImp object will be deleted when last reference
+ from each volume object (CInFileStreamVol) will be closed (when archive will be closed).
+*/
+
+class COpenCallbackImp Z7_final:
public IArchiveOpenCallback,
public IArchiveOpenVolumeCallback,
public IArchiveOpenSetSubArchiveName,
- #ifndef _NO_CRYPTO
+ #ifndef Z7_NO_CRYPTO
public ICryptoGetTextPassword,
- #endif
+ #endif
+ public IProgress, // IProgress is used for 7zFM
public CMyUnknownImp
{
+ Z7_COM_QI_BEGIN2(IArchiveOpenCallback)
+ Z7_COM_QI_ENTRY(IArchiveOpenVolumeCallback)
+ Z7_COM_QI_ENTRY(IArchiveOpenSetSubArchiveName)
+ #ifndef Z7_NO_CRYPTO
+ Z7_COM_QI_ENTRY(ICryptoGetTextPassword)
+ #endif
+ // Z7_COM_QI_ENTRY(IProgress) // the code doesn't require it
+ Z7_COM_QI_END
+ Z7_COM_ADDREF_RELEASE
+
+ Z7_IFACE_COM7_IMP(IArchiveOpenCallback)
+ Z7_IFACE_COM7_IMP(IArchiveOpenVolumeCallback)
+ Z7_IFACE_COM7_IMP(IProgress)
public:
- MY_QUERYINTERFACE_BEGIN2(IArchiveOpenVolumeCallback)
- MY_QUERYINTERFACE_ENTRY(IArchiveOpenSetSubArchiveName)
- #ifndef _NO_CRYPTO
- MY_QUERYINTERFACE_ENTRY(ICryptoGetTextPassword)
- #endif
- MY_QUERYINTERFACE_END
- MY_ADDREF_RELEASE
-
- INTERFACE_IArchiveOpenCallback(;)
- INTERFACE_IArchiveOpenVolumeCallback(;)
-
- #ifndef _NO_CRYPTO
- STDMETHOD(CryptoGetTextPassword)(BSTR *password);
- #endif
-
- STDMETHOD(SetSubArchiveName(const wchar_t *name))
- {
- _subArchiveMode = true;
- _subArchiveName = name;
- // TotalSize = 0;
- return S_OK;
- }
-
+ Z7_IFACE_COM7_IMP(IArchiveOpenSetSubArchiveName)
private:
- FString _folderPrefix;
- NWindows::NFile::NFind::CFileInfo _fileInfo;
+ #ifndef Z7_NO_CRYPTO
+ Z7_IFACE_COM7_IMP(ICryptoGetTextPassword)
+ #endif
+
bool _subArchiveMode;
- UString _subArchiveName;
public:
+ bool PasswordWasAsked;
UStringVector FileNames;
CBoolVector FileNames_WasUsed;
CRecordVector<UInt64> FileSizes;
-
- bool PasswordWasAsked;
+ void AtCloseFile(unsigned fileIndex)
+ {
+ FileNames_WasUsed[fileIndex] = false;
+ Volumes.CloseFile(fileIndex);
+ }
+
+ /* we have two ways to Callback from this object
+ 1) IArchiveOpenCallback * ReOpenCallback - for ReOpen function, when IOpenCallbackUI is not available
+ 2) IOpenCallbackUI *Callback - for usual callback
+ we can't transfer IOpenCallbackUI pointer via internal interface,
+ so we use ReOpenCallback to callback without IOpenCallbackUI.
+ */
+
+ /* we use Callback/ReOpenCallback only at Open stage.
+ So the CMyComPtr reference counter is not required,
+ and we don't want additional reference to unused object,
+ if COpenCallbackImp is not closed
+ */
+ IArchiveOpenCallback *ReOpenCallback;
+ // CMyComPtr<IArchiveOpenCallback> ReOpenCallback;
IOpenCallbackUI *Callback;
- CMyComPtr<IArchiveOpenCallback> ReOpenCallback;
+ // CMyComPtr<IUnknown> Callback_Ref;
+
+private:
+ FString _folderPrefix;
+ UString _subArchiveName;
+ NWindows::NFile::NFind::CFileInfo _fileInfo;
+
+public:
+ CMultiStreams Volumes;
+
// UInt64 TotalSize;
- COpenCallbackImp(): Callback(NULL), _subArchiveMode(false) {}
+ COpenCallbackImp():
+ _subArchiveMode(false),
+ ReOpenCallback(NULL),
+ Callback(NULL) {}
- void Init(const FString &folderPrefix, const FString &fileName)
- {
- _folderPrefix = folderPrefix;
- if (!_fileInfo.Find(_folderPrefix + fileName))
- throw 20121118;
- FileNames.Clear();
- FileNames_WasUsed.Clear();
- FileSizes.Clear();
- _subArchiveMode = false;
- // TotalSize = 0;
- PasswordWasAsked = false;
- }
+ HRESULT Init2(const FString &folderPrefix, const FString &fileName);
bool SetSecondFileInfo(CFSTR newName)
{
- return _fileInfo.Find(newName) && !_fileInfo.IsDir();
+ return _fileInfo.Find_FollowLink(newName) && !_fileInfo.IsDir();
}
};
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/Bench.cpp b/3rdparty/lzma/CPP/7zip/UI/Common/Bench.cpp
index ecbacbc9c8e..5da9783d4e1 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/Bench.cpp
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/Bench.cpp
@@ -2,19 +2,24 @@
#include "StdAfx.h"
-#include <stdio.h>
+#include "../../../../C/CpuArch.h"
+
+// #include <stdio.h>
#ifndef _WIN32
+
#define USE_POSIX_TIME
#define USE_POSIX_TIME2
-#endif
+#endif // _WIN32
#ifdef USE_POSIX_TIME
#include <time.h>
+#include <unistd.h>
#ifdef USE_POSIX_TIME2
#include <sys/time.h>
+#include <sys/times.h>
#endif
-#endif
+#endif // USE_POSIX_TIME
#ifdef _WIN32
#define USE_ALLOCA
@@ -29,37 +34,34 @@
#endif
#include "../../../../C/7zCrc.h"
-#include "../../../../C/Alloc.h"
-#include "../../../../C/CpuArch.h"
-
-#include "../../../Windows/System.h"
+#include "../../../../C/RotateDefs.h"
-#ifndef _7ZIP_ST
+#ifndef Z7_ST
#include "../../../Windows/Synchronization.h"
#include "../../../Windows/Thread.h"
#endif
-#if defined(_WIN32) || defined(UNIX_USE_WIN_FILE)
-#define USE_WIN_FILE
-#endif
-
-#ifdef USE_WIN_FILE
+#include "../../../Windows/FileFind.h"
#include "../../../Windows/FileIO.h"
-#endif
-
+#include "../../../Windows/SystemInfo.h"
+#include "../../../Common/MyBuffer2.h"
#include "../../../Common/IntToString.h"
#include "../../../Common/StringConvert.h"
#include "../../../Common/StringToInt.h"
+#include "../../../Common/Wildcard.h"
#include "../../Common/MethodProps.h"
+#include "../../Common/StreamObjects.h"
#include "../../Common/StreamUtils.h"
#include "Bench.h"
using namespace NWindows;
+#ifndef Z7_ST
static const UInt32 k_LZMA = 0x030101;
+#endif
static const UInt64 kComplexInCommands = (UInt64)1 <<
#ifdef UNDER_CE
@@ -68,9 +70,9 @@ static const UInt64 kComplexInCommands = (UInt64)1 <<
34;
#endif
-static const UInt32 kComplexInSeconds = 4;
+static const UInt32 kComplexInMs = 4000;
-static void SetComplexCommands(UInt32 complexInSeconds,
+static void SetComplexCommandsMs(UInt32 complexInMs,
bool isSpecifiedFreq, UInt64 cpuFreq, UInt64 &complexInCommands)
{
complexInCommands = kComplexInCommands;
@@ -80,96 +82,80 @@ static void SetComplexCommands(UInt32 complexInSeconds,
cpuFreq = kMinFreq;
if (cpuFreq < kMaxFreq || isSpecifiedFreq)
{
- if (complexInSeconds != 0)
- complexInCommands = complexInSeconds * cpuFreq;
+ if (complexInMs != 0)
+ complexInCommands = complexInMs * cpuFreq / 1000;
else
complexInCommands = cpuFreq >> 2;
}
}
+// const UInt64 kBenchmarkUsageMult = 1000000; // for debug
+static const unsigned kBenchmarkUsageMultBits = 16;
+static const UInt64 kBenchmarkUsageMult = 1 << kBenchmarkUsageMultBits;
+
+UInt64 Benchmark_GetUsage_Percents(UInt64 usage)
+{
+ return (100 * usage + kBenchmarkUsageMult / 2) / kBenchmarkUsageMult;
+}
+
static const unsigned kNumHashDictBits = 17;
-static const UInt32 kFilterUnpackSize = (48 << 10);
+static const UInt32 kFilterUnpackSize = (47 << 10); // + 5; // for test
-static const unsigned kOldLzmaDictBits = 30;
+static const unsigned kOldLzmaDictBits = 32;
-static const UInt32 kAdditionalSize = (1 << 16);
+// static const size_t kAdditionalSize = (size_t)1 << 32; // for debug
+static const size_t kAdditionalSize = (size_t)1 << 16;
static const UInt32 kCompressedAdditionalSize = (1 << 10);
-static const UInt32 kMaxLzmaPropSize = 5;
+
+static const UInt32 kMaxMethodPropSize = (1 << 6);
+
+
+#define ALLOC_WITH_HRESULT(_buffer_, _size_) \
+ { (_buffer_)->Alloc(_size_); \
+ if (_size_ && !(_buffer_)->IsAllocated()) return E_OUTOFMEMORY; }
+
class CBaseRandomGenerator
{
UInt32 A1;
UInt32 A2;
+ UInt32 Salt;
public:
- CBaseRandomGenerator() { Init(); }
+ CBaseRandomGenerator(UInt32 salt = 0): Salt(salt) { Init(); }
void Init() { A1 = 362436069; A2 = 521288629;}
+ Z7_FORCE_INLINE
UInt32 GetRnd()
{
- return
+ return Salt ^
+ (
((A1 = 36969 * (A1 & 0xffff) + (A1 >> 16)) << 16) +
- ((A2 = 18000 * (A2 & 0xffff) + (A2 >> 16)) );
+ ((A2 = 18000 * (A2 & 0xffff) + (A2 >> 16)) )
+ );
}
};
-static const unsigned kBufferAlignment = 1 << 4;
-
-struct CBenchBuffer
+Z7_NO_INLINE
+static void RandGen(Byte *buf, size_t size)
{
- size_t BufferSize;
-
- #ifdef _WIN32
-
- Byte *Buffer;
-
- CBenchBuffer(): BufferSize(0), Buffer(NULL) {}
- ~CBenchBuffer() { ::MidFree(Buffer); }
-
- void AllocAlignedMask(size_t size, size_t)
- {
- ::MidFree(Buffer);
- BufferSize = 0;
- Buffer = (Byte *)::MidAlloc(size);
- if (Buffer)
- BufferSize = size;
- }
-
- #else
-
- Byte *Buffer;
- Byte *_bufBase;
-
- CBenchBuffer(): BufferSize(0), Buffer(NULL), _bufBase(NULL){}
- ~CBenchBuffer() { ::MidFree(_bufBase); }
-
- void AllocAlignedMask(size_t size, size_t alignMask)
+ CBaseRandomGenerator RG;
+ const size_t size4 = size & ~((size_t)3);
+ size_t i;
+ for (i = 0; i < size4; i += 4)
{
- ::MidFree(_bufBase);
- Buffer = NULL;
- BufferSize = 0;
- _bufBase = (Byte *)::MidAlloc(size + alignMask);
-
- if (_bufBase)
- {
- // Buffer = (Byte *)(((uintptr_t)_bufBase + alignMask) & ~(uintptr_t)alignMask);
- Buffer = (Byte *)(((ptrdiff_t)_bufBase + alignMask) & ~(ptrdiff_t)alignMask);
- BufferSize = size;
- }
+ const UInt32 v = RG.GetRnd();
+ SetUi32(buf + i, v)
}
-
- #endif
-
- bool Alloc(size_t size)
+ UInt32 v = RG.GetRnd();
+ for (; i < size; i++)
{
- if (Buffer && BufferSize == size)
- return true;
- AllocAlignedMask(size, kBufferAlignment - 1);
- return (Buffer != NULL || size == 0);
+ buf[i] = (Byte)v;
+ v >>= 8;
}
-};
+}
-class CBenchRandomGenerator: public CBenchBuffer
+class CBenchRandomGenerator: public CMidAlignedBuffer
{
static UInt32 GetVal(UInt32 &res, unsigned numBits)
{
@@ -186,27 +172,33 @@ class CBenchRandomGenerator: public CBenchBuffer
public:
- void GenerateSimpleRandom(CBaseRandomGenerator *_RG_)
+ void GenerateSimpleRandom(UInt32 salt)
{
- CBaseRandomGenerator rg = *_RG_;
- const size_t bufSize = BufferSize;
- Byte *buf = Buffer;
+ CBaseRandomGenerator rg(salt);
+ const size_t bufSize = Size();
+ Byte *buf = (Byte *)*this;
for (size_t i = 0; i < bufSize; i++)
buf[i] = (Byte)rg.GetRnd();
- *_RG_ = rg;
}
- void GenerateLz(unsigned dictBits, CBaseRandomGenerator *_RG_)
+ void GenerateLz(unsigned dictBits, UInt32 salt)
{
- CBaseRandomGenerator rg = *_RG_;
- UInt32 pos = 0;
- UInt32 rep0 = 1;
- const size_t bufSize = BufferSize;
- Byte *buf = Buffer;
+ CBaseRandomGenerator rg(salt);
+ size_t pos = 0;
+ size_t rep0 = 1;
+ const size_t bufSize = Size();
+ Byte *buf = (Byte *)*this;
unsigned posBits = 1;
+
+ // printf("\n dictBits = %d\n", (UInt32)dictBits);
+ // printf("\n bufSize = 0x%p\n", (const void *)bufSize);
while (pos < bufSize)
{
+ /*
+ if (pos >= ((UInt32)1 << 31))
+ printf(" %x\n", pos);
+ */
UInt32 r = rg.GetRnd();
if (GetVal(r, 1) == 0 || pos < 1024)
buf[pos++] = (Byte)(r & 0xFF);
@@ -219,7 +211,7 @@ public:
{
len += GetLen(r);
- while (((UInt32)1 << posBits) < pos)
+ while (((size_t)1 << posBits) < pos)
posBits++;
unsigned numBitsMax = dictBits;
@@ -233,11 +225,12 @@ public:
for (;;)
{
- UInt32 ppp = GetVal(r, numLogBits) + kAddBits;
+ const UInt32 ppp = GetVal(r, numLogBits) + kAddBits;
r = rg.GetRnd();
if (ppp > numBitsMax)
continue;
- rep0 = GetVal(r, ppp);
+ // rep0 = GetVal(r, ppp);
+ rep0 = r & (((size_t)1 << ppp) - 1);
if (rep0 < pos)
break;
r = rg.GetRnd();
@@ -245,10 +238,11 @@ public:
rep0++;
}
+ // len *= 300; // for debug
{
- UInt32 rem = (UInt32)bufSize - pos;
+ const size_t rem = bufSize - pos;
if (len > rem)
- len = rem;
+ len = (UInt32)rem;
}
Byte *dest = buf + pos;
const Byte *src = dest - rep0;
@@ -257,51 +251,54 @@ public:
*dest++ = *src++;
}
}
-
- *_RG_ = rg;
+ // printf("\n CRC = %x\n", CrcCalc(buf, bufSize));
}
};
-class CBenchmarkInStream:
- public ISequentialInStream,
- public CMyUnknownImp
-{
+Z7_CLASS_IMP_NOQIB_1(
+ CBenchmarkInStream
+ , ISequentialInStream
+)
const Byte *Data;
size_t Pos;
size_t Size;
public:
- MY_UNKNOWN_IMP
void Init(const Byte *data, size_t size)
{
Data = data;
Size = size;
Pos = 0;
}
- STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
+ bool WasFinished() const { return Pos == Size; }
};
-STDMETHODIMP CBenchmarkInStream::Read(void *data, UInt32 size, UInt32 *processedSize)
+Z7_COM7F_IMF(CBenchmarkInStream::Read(void *data, UInt32 size, UInt32 *processedSize))
{
- size_t remain = Size - Pos;
- UInt32 kMaxBlockSize = (1 << 20);
+ const UInt32 kMaxBlockSize = (1 << 20);
if (size > kMaxBlockSize)
size = kMaxBlockSize;
+ const size_t remain = Size - Pos;
if (size > remain)
size = (UInt32)remain;
- for (UInt32 i = 0; i < size; i++)
- ((Byte *)data)[i] = Data[Pos + i];
+
+ if (size != 0)
+ memcpy(data, Data + Pos, size);
+
Pos += size;
if (processedSize)
*processedSize = size;
return S_OK;
}
-class CBenchmarkOutStream:
+
+class CBenchmarkOutStream Z7_final:
public ISequentialOutStream,
- public CBenchBuffer,
- public CMyUnknownImp
+ public CMyUnknownImp,
+ public CMidAlignedBuffer
{
+ Z7_COM_UNKNOWN_IMP_0
+ Z7_IFACE_COM7_IMP(ISequentialOutStream)
// bool _overflow;
public:
size_t Pos;
@@ -319,23 +316,32 @@ public:
Pos = 0;
}
- // void Print() { printf("\n%8d %8d\n", (unsigned)BufferSize, (unsigned)Pos); }
+ void InitCrc()
+ {
+ Crc = CRC_INIT_VAL;
+ }
- MY_UNKNOWN_IMP
- STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
+ void Calc(const void *data, size_t size)
+ {
+ Crc = CrcUpdate(Crc, data, size);
+ }
+
+ size_t GetPos() const { return Pos; }
+
+ // void Print() { printf("\n%8d %8d\n", (unsigned)BufferSize, (unsigned)Pos); }
};
-STDMETHODIMP CBenchmarkOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
+Z7_COM7F_IMF(CBenchmarkOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize))
{
- size_t curSize = BufferSize - Pos;
+ size_t curSize = Size() - Pos;
if (curSize > size)
curSize = size;
if (curSize != 0)
{
if (RealCopy)
- memcpy(Buffer + Pos, data, curSize);
+ memcpy(((Byte *)*this) + Pos, data, curSize);
if (CalcCrc)
- Crc = CrcUpdate(Crc, data, curSize);
+ Calc(data, curSize);
Pos += curSize;
}
if (processedSize)
@@ -348,46 +354,51 @@ STDMETHODIMP CBenchmarkOutStream::Write(const void *data, UInt32 size, UInt32 *p
return S_OK;
}
-class CCrcOutStream:
- public ISequentialOutStream,
- public CMyUnknownImp
-{
+
+Z7_CLASS_IMP_NOQIB_1(
+ CCrcOutStream
+ , ISequentialOutStream
+)
public:
bool CalcCrc;
UInt32 Crc;
- MY_UNKNOWN_IMP
-
- CCrcOutStream(): CalcCrc(true) {};
- void Init() { Crc = CRC_INIT_VAL; }
- STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
+ UInt64 Pos;
+
+ CCrcOutStream(): CalcCrc(true) {}
+ void Init() { Crc = CRC_INIT_VAL; Pos = 0; }
+ void Calc(const void *data, size_t size)
+ {
+ Crc = CrcUpdate(Crc, data, size);
+ }
};
-STDMETHODIMP CCrcOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
+Z7_COM7F_IMF(CCrcOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize))
{
if (CalcCrc)
- Crc = CrcUpdate(Crc, data, size);
+ Calc(data, size);
+ Pos += size;
if (processedSize)
*processedSize = size;
return S_OK;
}
+// #include "../../../../C/My_sys_time.h"
+
static UInt64 GetTimeCount()
{
#ifdef USE_POSIX_TIME
#ifdef USE_POSIX_TIME2
timeval v;
- if (gettimeofday(&v, 0) == 0)
- return (UInt64)(v.tv_sec) * 1000000 + v.tv_usec;
+ if (gettimeofday(&v, NULL) == 0)
+ return (UInt64)(v.tv_sec) * 1000000 + (UInt64)v.tv_usec;
return (UInt64)time(NULL) * 1000000;
#else
return time(NULL);
#endif
#else
- /*
LARGE_INTEGER value;
if (::QueryPerformanceCounter(&value))
- return value.QuadPart;
- */
+ return (UInt64)value.QuadPart;
return GetTickCount();
#endif
}
@@ -401,15 +412,14 @@ static UInt64 GetFreq()
return 1;
#endif
#else
- /*
LARGE_INTEGER value;
if (::QueryPerformanceFrequency(&value))
- return value.QuadPart;
- */
+ return (UInt64)value.QuadPart;
return 1000;
#endif
}
+
#ifdef USE_POSIX_TIME
struct CUserTime
@@ -419,58 +429,106 @@ struct CUserTime
void Init()
{
- Prev = clock();
+ // Prev = clock();
+ Sum = 0;
+ Prev = 0;
+ Update();
Sum = 0;
}
- UInt64 GetUserTime()
+ void Update()
{
+ tms t;
+ /* clock_t res = */ times(&t);
+ clock_t newVal = t.tms_utime + t.tms_stime;
+ Sum += (UInt64)(newVal - Prev);
+ Prev = newVal;
+
+ /*
clock_t v = clock();
- Sum += v - Prev;
- Prev = v;
+ if (v != -1)
+ {
+ Sum += v - Prev;
+ Prev = v;
+ }
+ */
+ }
+ UInt64 GetUserTime()
+ {
+ Update();
return Sum;
}
};
#else
-static inline UInt64 GetTime64(const FILETIME &t) { return ((UInt64)t.dwHighDateTime << 32) | t.dwLowDateTime; }
-UInt64 GetWinUserTime()
-{
- FILETIME creationTime, exitTime, kernelTime, userTime;
- if (
- #ifdef UNDER_CE
- ::GetThreadTimes(::GetCurrentThread()
- #else
- ::GetProcessTimes(::GetCurrentProcess()
- #endif
- , &creationTime, &exitTime, &kernelTime, &userTime) != 0)
- return GetTime64(userTime) + GetTime64(kernelTime);
- return (UInt64)GetTickCount() * 10000;
-}
struct CUserTime
{
- UInt64 StartTime;
+ bool UseTick;
+ DWORD Prev_Tick;
+ UInt64 Prev;
+ UInt64 Sum;
- void Init() { StartTime = GetWinUserTime(); }
- UInt64 GetUserTime() { return GetWinUserTime() - StartTime; }
+ void Init()
+ {
+ UseTick = false;
+ Prev_Tick = 0;
+ Prev = 0;
+ Sum = 0;
+ Update();
+ Sum = 0;
+ }
+ UInt64 GetUserTime()
+ {
+ Update();
+ return Sum;
+ }
+ void Update();
};
+static inline UInt64 GetTime64(const FILETIME &t) { return ((UInt64)t.dwHighDateTime << 32) | t.dwLowDateTime; }
+
+void CUserTime::Update()
+{
+ DWORD new_Tick = GetTickCount();
+ FILETIME creationTime, exitTime, kernelTime, userTime;
+ if (!UseTick &&
+ #ifdef UNDER_CE
+ ::GetThreadTimes(::GetCurrentThread()
+ #else
+ ::GetProcessTimes(::GetCurrentProcess()
+ #endif
+ , &creationTime, &exitTime, &kernelTime, &userTime))
+ {
+ UInt64 newVal = GetTime64(userTime) + GetTime64(kernelTime);
+ Sum += newVal - Prev;
+ Prev = newVal;
+ }
+ else
+ {
+ UseTick = true;
+ Sum += (UInt64)(new_Tick - (DWORD)Prev_Tick) * 10000;
+ }
+ Prev_Tick = new_Tick;
+}
+
+
#endif
static UInt64 GetUserFreq()
{
#ifdef USE_POSIX_TIME
- return CLOCKS_PER_SEC;
+ // return CLOCKS_PER_SEC;
+ return (UInt64)sysconf(_SC_CLK_TCK);
#else
return 10000000;
#endif
}
-class CBenchProgressStatus
+class CBenchProgressStatus Z7_final
{
- #ifndef _7ZIP_ST
+ #ifndef Z7_ST
NSynchronization::CCriticalSection CS;
#endif
public:
@@ -478,14 +536,14 @@ public:
bool EncodeMode;
void SetResult(HRESULT res)
{
- #ifndef _7ZIP_ST
+ #ifndef Z7_ST
NSynchronization::CCriticalSectionLock lock(CS);
#endif
Res = res;
}
HRESULT GetResult()
{
- #ifndef _7ZIP_ST
+ #ifndef Z7_ST
NSynchronization::CCriticalSectionLock lock(CS);
#endif
return Res;
@@ -517,28 +575,44 @@ void CBenchInfoCalc::SetFinishTime(CBenchInfo &dest)
dest.UserTime = UserTime.GetUserTime();
}
-class CBenchProgressInfo:
+class CBenchProgressInfo Z7_final:
public ICompressProgressInfo,
public CMyUnknownImp,
public CBenchInfoCalc
{
+ Z7_COM_UNKNOWN_IMP_0
+ Z7_IFACE_COM7_IMP(ICompressProgressInfo)
public:
CBenchProgressStatus *Status;
- HRESULT Res;
IBenchCallback *Callback;
- CBenchProgressInfo(): Callback(0) {}
- MY_UNKNOWN_IMP
- STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);
+ CBenchProgressInfo(): Callback(NULL) {}
};
-STDMETHODIMP CBenchProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)
+
+Z7_COM7F_IMF(CBenchProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize))
{
HRESULT res = Status->GetResult();
if (res != S_OK)
return res;
if (!Callback)
return res;
+
+ /*
+ static UInt64 inSizePrev = 0;
+ static UInt64 outSizePrev = 0;
+ UInt64 delta1 = 0, delta2 = 0, val1 = 0, val2 = 0;
+ if (inSize) { val1 = *inSize; delta1 = val1 - inSizePrev; inSizePrev = val1; }
+ if (outSize) { val2 = *outSize; delta2 = val2 - outSizePrev; outSizePrev = val2; }
+ UInt64 percents = delta2 * 1000;
+ if (delta1 != 0)
+ percents /= delta1;
+ printf("=== %7d %7d %7d %7d ratio = %4d\n",
+ (unsigned)(val1 >> 10), (unsigned)(delta1 >> 10),
+ (unsigned)(val2 >> 10), (unsigned)(delta2 >> 10),
+ (unsigned)percents);
+ */
+
CBenchInfo info;
SetFinishTime(info);
if (Status->EncodeMode)
@@ -560,91 +634,168 @@ STDMETHODIMP CBenchProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64
static const unsigned kSubBits = 8;
-static UInt32 GetLogSize(UInt32 size)
+static unsigned GetLogSize(UInt64 size)
+{
+ unsigned i = 0;
+ for (;;)
+ {
+ i++; size >>= 1; if (size == 0) break;
+ }
+ return i;
+}
+
+
+static UInt32 GetLogSize_Sub(UInt64 size)
+{
+ if (size <= 1)
+ return 0;
+ const unsigned i = GetLogSize(size) - 1;
+ UInt32 v;
+ if (i <= kSubBits)
+ v = (UInt32)(size) << (kSubBits - i);
+ else
+ v = (UInt32)(size >> (i - kSubBits));
+ return ((UInt32)i << kSubBits) + (v & (((UInt32)1 << kSubBits) - 1));
+}
+
+
+static UInt64 Get_UInt64_from_double(double v)
{
- for (unsigned i = kSubBits; i < 32; i++)
- for (UInt32 j = 0; j < (1 << kSubBits); j++)
- if (size <= (((UInt32)1) << i) + (j << (i - kSubBits)))
- return (i << kSubBits) + j;
- return (32 << kSubBits);
+ const UInt64 kMaxVal = (UInt64)1 << 62;
+ if (v > (double)(Int64)kMaxVal)
+ return kMaxVal;
+ return (UInt64)v;
}
-static void NormalizeVals(UInt64 &v1, UInt64 &v2)
+static UInt64 MyMultDiv64(UInt64 m1, UInt64 m2, UInt64 d)
{
- while (v1 > 1000000)
+ if (d == 0)
+ d = 1;
+ const double v =
+ (double)(Int64)m1 *
+ (double)(Int64)m2 /
+ (double)(Int64)d;
+ return Get_UInt64_from_double(v);
+ /*
+ unsigned n1 = GetLogSize(m1);
+ unsigned n2 = GetLogSize(m2);
+ while (n1 + n2 > 64)
{
- v1 >>= 1;
- v2 >>= 1;
+ if (n1 >= n2)
+ {
+ m1 >>= 1;
+ n1--;
+ }
+ else
+ {
+ m2 >>= 1;
+ n2--;
+ }
+ d >>= 1;
}
+
+ if (d == 0)
+ d = 1;
+ return m1 * m2 / d;
+ */
}
+
UInt64 CBenchInfo::GetUsage() const
{
UInt64 userTime = UserTime;
UInt64 userFreq = UserFreq;
UInt64 globalTime = GlobalTime;
UInt64 globalFreq = GlobalFreq;
- NormalizeVals(userTime, userFreq);
- NormalizeVals(globalFreq, globalTime);
+
if (userFreq == 0)
userFreq = 1;
if (globalTime == 0)
globalTime = 1;
- return userTime * globalFreq * 1000000 / userFreq / globalTime;
+
+ const double v =
+ ((double)(Int64)userTime / (double)(Int64)userFreq)
+ * ((double)(Int64)globalFreq / (double)(Int64)globalTime)
+ * (double)(Int64)kBenchmarkUsageMult;
+ return Get_UInt64_from_double(v);
+ /*
+ return MyMultDiv64(
+ MyMultDiv64(kBenchmarkUsageMult, userTime, userFreq),
+ globalFreq, globalTime);
+ */
}
+
UInt64 CBenchInfo::GetRatingPerUsage(UInt64 rating) const
{
- UInt64 userTime = UserTime;
- UInt64 userFreq = UserFreq;
- UInt64 globalTime = GlobalTime;
+ if (UserTime == 0)
+ {
+ return 0;
+ // userTime = 1;
+ }
UInt64 globalFreq = GlobalFreq;
- NormalizeVals(userFreq, userTime);
- NormalizeVals(globalTime, globalFreq);
if (globalFreq == 0)
globalFreq = 1;
- if (userTime == 0)
- userTime = 1;
- return userFreq * globalTime / globalFreq * rating / userTime;
+
+ const double v =
+ ((double)(Int64)GlobalTime / (double)(Int64)globalFreq)
+ * ((double)(Int64)UserFreq / (double)(Int64)UserTime)
+ * (double)(Int64)rating;
+ return Get_UInt64_from_double(v);
+ /*
+ return MyMultDiv64(
+ MyMultDiv64(rating, UserFreq, UserTime),
+ GlobalTime, globalFreq);
+ */
}
-static UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime, UInt64 freq)
+
+UInt64 CBenchInfo::GetSpeed(UInt64 numUnits) const
{
- UInt64 elTime = elapsedTime;
- NormalizeVals(freq, elTime);
- if (elTime == 0)
- elTime = 1;
- return value * freq / elTime;
+ return MyMultDiv64(numUnits, GlobalFreq, GlobalTime);
}
-UInt64 CBenchInfo::GetSpeed(UInt64 numCommands) const
+static UInt64 GetNumCommands_from_Size_and_Complexity(UInt64 size, Int32 complexity)
{
- return MyMultDiv64(numCommands, GlobalTime, GlobalFreq);
+ return complexity >= 0 ?
+ size * (UInt32)complexity :
+ size / (UInt32)(-complexity);
}
struct CBenchProps
{
bool LzmaRatingMode;
- UInt32 EncComplex;
- UInt32 DecComplexCompr;
- UInt32 DecComplexUnc;
+ Int32 EncComplex;
+ Int32 DecComplexCompr;
+ Int32 DecComplexUnc;
+
+ unsigned KeySize;
+
+ CBenchProps():
+ LzmaRatingMode(false),
+ KeySize(0)
+ {}
- CBenchProps(): LzmaRatingMode(false) {}
void SetLzmaCompexity();
- UInt64 GeComprCommands(UInt64 unpackSize)
+ UInt64 GetNumCommands_Enc(UInt64 unpackSize) const
{
- return unpackSize * EncComplex;
+ const UInt32 kMinSize = 100;
+ if (unpackSize < kMinSize)
+ unpackSize = kMinSize;
+ return GetNumCommands_from_Size_and_Complexity(unpackSize, EncComplex);
}
- UInt64 GeDecomprCommands(UInt64 packSize, UInt64 unpackSize)
+ UInt64 GetNumCommands_Dec(UInt64 packSize, UInt64 unpackSize) const
{
- return (packSize * DecComplexCompr + unpackSize * DecComplexUnc);
+ return
+ GetNumCommands_from_Size_and_Complexity(packSize, DecComplexCompr) +
+ GetNumCommands_from_Size_and_Complexity(unpackSize, DecComplexUnc);
}
- UInt64 GetCompressRating(UInt32 dictSize, UInt64 elapsedTime, UInt64 freq, UInt64 size);
- UInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt64 inSize, UInt64 numIterations);
+ UInt64 GetRating_Enc(UInt64 dictSize, UInt64 elapsedTime, UInt64 freq, UInt64 size) const;
+ UInt64 GetRating_Dec(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt64 inSize, UInt64 numIterations) const;
};
void CBenchProps::SetLzmaCompexity()
@@ -655,63 +806,247 @@ void CBenchProps::SetLzmaCompexity()
LzmaRatingMode = true;
}
-UInt64 CBenchProps::GetCompressRating(UInt32 dictSize, UInt64 elapsedTime, UInt64 freq, UInt64 size)
+UInt64 CBenchProps::GetRating_Enc(UInt64 dictSize, UInt64 elapsedTime, UInt64 freq, UInt64 size) const
{
if (dictSize < (1 << kBenchMinDicLogSize))
dictSize = (1 << kBenchMinDicLogSize);
- UInt64 encComplex = EncComplex;
+ Int32 encComplex = EncComplex;
if (LzmaRatingMode)
{
- UInt64 t = GetLogSize(dictSize) - (kBenchMinDicLogSize << kSubBits);
+ /*
+ for (UInt64 uu = 0; uu < (UInt64)0xf << 60;)
+ {
+ unsigned rr = GetLogSize_Sub(uu);
+ printf("\n%16I64x , log = %4x", uu, rr);
+ uu += 1;
+ uu += uu / 50;
+ }
+ */
+ // throw 1;
+ const UInt32 t = GetLogSize_Sub(dictSize) - (kBenchMinDicLogSize << kSubBits);
encComplex = 870 + ((t * t * 5) >> (2 * kSubBits));
}
- UInt64 numCommands = (UInt64)size * encComplex;
- return MyMultDiv64(numCommands, elapsedTime, freq);
+ const UInt64 numCommands = GetNumCommands_from_Size_and_Complexity(size, encComplex);
+ return MyMultDiv64(numCommands, freq, elapsedTime);
}
-UInt64 CBenchProps::GetDecompressRating(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt64 inSize, UInt64 numIterations)
+UInt64 CBenchProps::GetRating_Dec(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt64 inSize, UInt64 numIterations) const
{
- UInt64 numCommands = (inSize * DecComplexCompr + outSize * DecComplexUnc) * numIterations;
- return MyMultDiv64(numCommands, elapsedTime, freq);
+ const UInt64 numCommands = GetNumCommands_Dec(inSize, outSize) * numIterations;
+ return MyMultDiv64(numCommands, freq, elapsedTime);
}
-UInt64 GetCompressRating(UInt32 dictSize, UInt64 elapsedTime, UInt64 freq, UInt64 size)
+
+
+UInt64 CBenchInfo::GetRating_LzmaEnc(UInt64 dictSize) const
{
CBenchProps props;
props.SetLzmaCompexity();
- return props.GetCompressRating(dictSize, elapsedTime, freq, size);
+ return props.GetRating_Enc(dictSize, GlobalTime, GlobalFreq, UnpackSize * NumIterations);
}
-UInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt64 inSize, UInt64 numIterations)
+UInt64 CBenchInfo::GetRating_LzmaDec() const
{
CBenchProps props;
props.SetLzmaCompexity();
- return props.GetDecompressRating(elapsedTime, freq, outSize, inSize, numIterations);
+ return props.GetRating_Dec(GlobalTime, GlobalFreq, UnpackSize, PackSize, NumIterations);
+}
+
+
+#ifndef Z7_ST
+
+#define NUM_CPU_LEVELS_MAX 3
+
+struct CAffinityMode
+{
+ unsigned NumBundleThreads;
+ unsigned NumLevels;
+ unsigned NumCoreThreads;
+ unsigned NumCores;
+ // unsigned DivideNum;
+ UInt32 Sizes[NUM_CPU_LEVELS_MAX];
+
+ void SetLevels(unsigned numCores, unsigned numCoreThreads);
+ DWORD_PTR GetAffinityMask(UInt32 bundleIndex, CCpuSet *cpuSet) const;
+ bool NeedAffinity() const { return NumBundleThreads != 0; }
+
+ WRes CreateThread_WithAffinity(NWindows::CThread &thread, THREAD_FUNC_TYPE startAddress, LPVOID parameter, UInt32 bundleIndex) const
+ {
+ if (NeedAffinity())
+ {
+ CCpuSet cpuSet;
+ GetAffinityMask(bundleIndex, &cpuSet);
+ return thread.Create_With_CpuSet(startAddress, parameter, &cpuSet);
+ }
+ return thread.Create(startAddress, parameter);
+ }
+
+ CAffinityMode():
+ NumBundleThreads(0),
+ NumLevels(0),
+ NumCoreThreads(1)
+ // DivideNum(1)
+ {}
+};
+
+void CAffinityMode::SetLevels(unsigned numCores, unsigned numCoreThreads)
+{
+ NumCores = numCores;
+ NumCoreThreads = numCoreThreads;
+ NumLevels = 0;
+ if (numCoreThreads == 0 || numCores == 0 || numCores % numCoreThreads != 0)
+ return;
+ UInt32 c = numCores / numCoreThreads;
+ UInt32 c2 = 1;
+ while ((c & 1) == 0)
+ {
+ c >>= 1;
+ c2 <<= 1;
+ }
+ if (c2 != 1)
+ Sizes[NumLevels++] = c2;
+ if (c != 1)
+ Sizes[NumLevels++] = c;
+ if (numCoreThreads != 1)
+ Sizes[NumLevels++] = numCoreThreads;
+ if (NumLevels == 0)
+ Sizes[NumLevels++] = 1;
+
+ /*
+ printf("\n Cores:");
+ for (unsigned i = 0; i < NumLevels; i++)
+ {
+ printf(" %d", Sizes[i]);
+ }
+ printf("\n");
+ */
+}
+
+
+DWORD_PTR CAffinityMode::GetAffinityMask(UInt32 bundleIndex, CCpuSet *cpuSet) const
+{
+ CpuSet_Zero(cpuSet);
+
+ if (NumLevels == 0)
+ return 0;
+
+ // printf("\n%2d", bundleIndex);
+
+ /*
+ UInt32 low = 0;
+ if (DivideNum != 1)
+ {
+ low = bundleIndex % DivideNum;
+ bundleIndex /= DivideNum;
+ }
+ */
+
+ UInt32 numGroups = NumCores / NumBundleThreads;
+ UInt32 m = bundleIndex % numGroups;
+ UInt32 v = 0;
+ for (unsigned i = 0; i < NumLevels; i++)
+ {
+ UInt32 size = Sizes[i];
+ while ((size & 1) == 0)
+ {
+ v *= 2;
+ v |= (m & 1);
+ m >>= 1;
+ size >>= 1;
+ }
+ v *= size;
+ v += m % size;
+ m /= size;
+ }
+
+ // UInt32 nb = NumBundleThreads / DivideNum;
+ UInt32 nb = NumBundleThreads;
+
+ DWORD_PTR mask = ((DWORD_PTR)1 << nb) - 1;
+ // v += low;
+ mask <<= v;
+
+ // printf(" %2d %8x \n ", v, (unsigned)mask);
+ #ifdef _WIN32
+ *cpuSet = mask;
+ #else
+ {
+ for (unsigned k = 0; k < nb; k++)
+ CpuSet_Set(cpuSet, v + k);
+ }
+ #endif
+
+ return mask;
}
-struct CEncoderInfo;
-struct CEncoderInfo
+struct CBenchSyncCommon
+{
+ bool ExitMode;
+ NSynchronization::CManualResetEvent StartEvent;
+
+ CBenchSyncCommon(): ExitMode(false) {}
+};
+
+#endif
+
+
+
+enum E_CheckCrcMode
{
- #ifndef _7ZIP_ST
+ k_CheckCrcMode_Never = 0,
+ k_CheckCrcMode_Always = 1,
+ k_CheckCrcMode_FirstPass = 2
+};
+
+class CEncoderInfo;
+
+class CEncoderInfo Z7_final
+{
+ Z7_CLASS_NO_COPY(CEncoderInfo)
+
+public:
+
+ #ifndef Z7_ST
NWindows::CThread thread[2];
+ NSynchronization::CManualResetEvent ReadyEvent;
UInt32 NumDecoderSubThreads;
+ CBenchSyncCommon *Common;
+ UInt32 EncoderIndex;
+ UInt32 NumEncoderInternalThreads;
+ CAffinityMode AffinityMode;
+ bool IsGlobalMtMode; // if more than one benchmark encoder threads
#endif
+
CMyComPtr<ICompressCoder> _encoder;
CMyComPtr<ICompressFilter> _encoderFilter;
CBenchProgressInfo *progressInfoSpec[2];
CMyComPtr<ICompressProgressInfo> progressInfo[2];
UInt64 NumIterations;
+ UInt32 Salt;
+
#ifdef USE_ALLOCA
size_t AllocaSize;
#endif
+ unsigned KeySize;
Byte _key[32];
Byte _iv[16];
+
+ HRESULT Set_Key_and_IV(ICryptoProperties *cp)
+ {
+ RINOK(cp->SetKey(_key, KeySize))
+ return cp->SetInitVector(_iv, sizeof(_iv));
+ }
+
Byte _psw[16];
- bool CheckCrc_Enc;
- bool CheckCrc_Dec;
+
+ bool CheckCrc_Enc; /* = 1, if we want to check packed data crcs after each pass
+ used for filter and usual coders */
+ bool UseRealData_Enc; /* = 1, if we want to use only original data for each pass
+ used only for filter */
+ E_CheckCrcMode CheckCrcMode_Dec;
struct CDecoderInfo
{
@@ -741,28 +1076,41 @@ struct CEncoderInfo
const Byte *fileData;
CBenchRandomGenerator rg;
- CBenchBuffer rgCopy; // it must be 16-byte aligned !!!
- CBenchmarkOutStream *propStreamSpec;
+ CMidAlignedBuffer rgCopy; // it must be 16-byte aligned !!!
+
+ // CBenchmarkOutStream *propStreamSpec;
+ Byte propsData[kMaxMethodPropSize];
+ CBufPtrSeqOutStream *propStreamSpec;
CMyComPtr<ISequentialOutStream> propStream;
- // for decode
+ unsigned generateDictBits;
COneMethodInfo _method;
+
+ // for decode
size_t _uncompressedDataSize;
- HRESULT Init(
- const COneMethodInfo &method,
- unsigned generateDictBits,
- CBaseRandomGenerator *rg);
+ HRESULT Generate();
HRESULT Encode();
HRESULT Decode(UInt32 decoderIndex);
CEncoderInfo():
- fileData(NULL),
+ #ifndef Z7_ST
+ Common(NULL),
+ IsGlobalMtMode(true),
+ #endif
+ Salt(0),
+ KeySize(0),
CheckCrc_Enc(true),
- CheckCrc_Dec(true),
- outStreamSpec(0), callback(0), printCallback(0), propStreamSpec(0) {}
+ UseRealData_Enc(true),
+ CheckCrcMode_Dec(k_CheckCrcMode_Always),
+ outStreamSpec(NULL),
+ callback(NULL),
+ printCallback(NULL),
+ fileData(NULL),
+ propStreamSpec(NULL)
+ {}
- #ifndef _7ZIP_ST
+ #ifndef Z7_ST
static THREAD_FUNC_DECL EncodeThreadFunction(void *param)
{
@@ -775,15 +1123,16 @@ struct CEncoderInfo
#endif
res = encoder->Encode();
- encoder->Results[0] = res;
}
catch(...)
{
res = E_FAIL;
}
+ encoder->Results[0] = res;
if (res != S_OK)
encoder->progressInfoSpec[0]->Status->SetResult(res);
- return 0;
+ encoder->ReadyEvent.Set();
+ return THREAD_FUNC_RET_ZERO;
}
static THREAD_FUNC_DECL DecodeThreadFunction(void *param)
@@ -796,12 +1145,18 @@ struct CEncoderInfo
CEncoderInfo *encoder = decoder->Encoder;
encoder->Results[decoder->DecoderIndex] = encoder->Decode(decoder->DecoderIndex);
- return 0;
+ return THREAD_FUNC_RET_ZERO;
}
HRESULT CreateEncoderThread()
{
- return thread[0].Create(EncodeThreadFunction, this);
+ WRes res = 0;
+ if (!ReadyEvent.IsCreated())
+ res = ReadyEvent.Create();
+ if (res == 0)
+ res = AffinityMode.CreateThread_WithAffinity(thread[0], EncodeThreadFunction, this,
+ EncoderIndex);
+ return HRESULT_FROM_WIN32(res);
}
HRESULT CreateDecoderThread(unsigned index, bool callbackMode
@@ -819,66 +1174,99 @@ struct CEncoderInfo
#endif
decoder.CallbackMode = callbackMode;
- return thread[index].Create(DecodeThreadFunction, &decoder);
+
+ WRes res = AffinityMode.CreateThread_WithAffinity(thread[index], DecodeThreadFunction, &decoder,
+ // EncoderIndex * NumEncoderInternalThreads + index
+ EncoderIndex
+ );
+
+ return HRESULT_FROM_WIN32(res);
}
#endif
};
-HRESULT CEncoderInfo::Init(
- const COneMethodInfo &method,
- unsigned generateDictBits,
- CBaseRandomGenerator *rgLoc)
+
+
+static size_t GetBenchCompressedSize(size_t bufferSize)
+{
+ return kCompressedAdditionalSize + bufferSize + bufferSize / 16;
+ // kBufferSize / 2;
+}
+
+
+HRESULT CEncoderInfo::Generate()
{
+ const COneMethodInfo &method = _method;
+
// we need extra space, if input data is already compressed
- const size_t kCompressedBufferSize =
- kCompressedAdditionalSize +
- kBufferSize + kBufferSize / 16;
- // kBufferSize / 2;
+ const size_t kCompressedBufferSize = _encoderFilter ?
+ kBufferSize :
+ GetBenchCompressedSize(kBufferSize);
if (kCompressedBufferSize < kBufferSize)
return E_FAIL;
uncompressedDataPtr = fileData;
-
- if (!fileData)
+ if (fileData)
{
- if (!rg.Alloc(kBufferSize))
- return E_OUTOFMEMORY;
-
+ #if !defined(Z7_ST)
+ if (IsGlobalMtMode)
+ {
+ /* we copy the data to local buffer of thread to eliminate
+ using of shared buffer by different threads */
+ ALLOC_WITH_HRESULT(&rg, kBufferSize)
+ memcpy((Byte *)rg, fileData, kBufferSize);
+ uncompressedDataPtr = (const Byte *)rg;
+ }
+ #endif
+ }
+ else
+ {
+ ALLOC_WITH_HRESULT(&rg, kBufferSize)
// DWORD ttt = GetTickCount();
if (generateDictBits == 0)
- rg.GenerateSimpleRandom(rgLoc);
+ rg.GenerateSimpleRandom(Salt);
else
- rg.GenerateLz(generateDictBits, rgLoc);
+ {
+ if (generateDictBits >= sizeof(size_t) * 8
+ && kBufferSize > ((size_t)1 << (sizeof(size_t) * 8 - 1)))
+ return E_INVALIDARG;
+ rg.GenerateLz(generateDictBits, Salt);
+ // return E_ABORT; // for debug
+ }
// printf("\n%d\n ", GetTickCount() - ttt);
- crc = CrcCalc(rg.Buffer, rg.BufferSize);
- uncompressedDataPtr = rg.Buffer;
+ crc = CrcCalc((const Byte *)rg, rg.Size());
+ uncompressedDataPtr = (const Byte *)rg;
}
-
- if (_encoderFilter)
+
+ if (!outStream)
{
- if (!rgCopy.Alloc(kBufferSize))
- return E_OUTOFMEMORY;
+ outStreamSpec = new CBenchmarkOutStream;
+ outStream = outStreamSpec;
}
+ ALLOC_WITH_HRESULT(outStreamSpec, kCompressedBufferSize)
- outStreamSpec = new CBenchmarkOutStream;
- outStream = outStreamSpec;
- if (!outStreamSpec->Alloc(kCompressedBufferSize))
- return E_OUTOFMEMORY;
+ if (_encoderFilter)
+ {
+ /* we try to reduce the number of memcpy() in main encoding loop.
+ so we copy data to temp buffers here */
+ ALLOC_WITH_HRESULT(&rgCopy, kBufferSize)
+ memcpy((Byte *)*outStreamSpec, uncompressedDataPtr, kBufferSize);
+ memcpy((Byte *)rgCopy, uncompressedDataPtr, kBufferSize);
+ }
- propStreamSpec = 0;
if (!propStream)
{
- propStreamSpec = new CBenchmarkOutStream;
+ propStreamSpec = new CBufPtrSeqOutStream; // CBenchmarkOutStream;
propStream = propStreamSpec;
}
- if (!propStreamSpec->Alloc(kMaxLzmaPropSize))
- return E_OUTOFMEMORY;
- propStreamSpec->Init(true, false);
+ // ALLOC_WITH_HRESULT_2(propStreamSpec, kMaxMethodPropSize);
+ // propStreamSpec->Init(true, false);
+ propStreamSpec->Init(propsData, sizeof(propsData));
CMyComPtr<IUnknown> coder;
@@ -891,8 +1279,23 @@ HRESULT CEncoderInfo::Init(
coder.QueryInterface(IID_ICompressSetCoderProperties, &scp);
if (scp)
{
- UInt64 reduceSize = kBufferSize;
- RINOK(method.SetCoderProps(scp, &reduceSize));
+ const UInt64 reduceSize = kBufferSize;
+
+ /* in posix new thread uses same affinity as parent thread,
+ so we don't need to send affinity to coder in posix */
+ UInt64 affMask;
+ #if !defined(Z7_ST) && defined(_WIN32)
+ {
+ CCpuSet cpuSet;
+ affMask = AffinityMode.GetAffinityMask(EncoderIndex, &cpuSet);
+ }
+ #else
+ affMask = 0;
+ #endif
+ // affMask <<= 3; // debug line: to test no affinity in coder;
+ // affMask = 0;
+
+ RINOK(method.SetCoderProps_DSReduce_Aff(scp, &reduceSize, (affMask != 0 ? &affMask : NULL)))
}
else
{
@@ -904,7 +1307,7 @@ HRESULT CEncoderInfo::Init(
coder.QueryInterface(IID_ICompressWriteCoderProperties, &writeCoderProps);
if (writeCoderProps)
{
- RINOK(writeCoderProps->WriteCoderProperties(propStream));
+ RINOK(writeCoderProps->WriteCoderProperties(propStream))
}
{
@@ -912,7 +1315,7 @@ HRESULT CEncoderInfo::Init(
coder.QueryInterface(IID_ICryptoSetPassword, &sp);
if (sp)
{
- RINOK(sp->CryptoSetPassword(_psw, sizeof(_psw)));
+ RINOK(sp->CryptoSetPassword(_psw, sizeof(_psw)))
// we must call encoding one time to calculate password key for key cache.
// it must be after WriteCoderProperties!
@@ -934,7 +1337,7 @@ HRESULT CEncoderInfo::Init(
CMyComPtr<ISequentialOutStream> crcStream = crcStreamSpec;
crcStreamSpec->Init();
- RINOK(_encoder->Code(inStream, crcStream, 0, 0, NULL));
+ RINOK(_encoder->Code(inStream, crcStream, NULL, NULL, NULL))
}
}
}
@@ -944,19 +1347,22 @@ HRESULT CEncoderInfo::Init(
}
-static void My_FilterBench(ICompressFilter *filter, Byte *data, size_t size)
+static void My_FilterBench(ICompressFilter *filter, Byte *data, size_t size, UInt32 *crc)
{
while (size != 0)
{
- UInt32 cur = (UInt32)1 << 31;
+ UInt32 cur = crc ? 1 << 17 : 1 << 24;
if (cur > size)
cur = (UInt32)size;
UInt32 processed = filter->Filter(data, cur);
- data += processed;
- // if (processed > size) (in AES filter), we must fill last block with zeros.
- // but it is not important for benchmark. So we just copy that data without filtering.
+ /* if (processed > size) (in AES filter), we must fill last block with zeros.
+ but it is not important for benchmark. So we just copy that data without filtering.
+ if (processed == 0) then filter can't process more */
if (processed > size || processed == 0)
- break;
+ processed = (UInt32)size;
+ if (crc)
+ *crc = CrcUpdate(*crc, data, processed);
+ data += processed;
size -= processed;
}
}
@@ -964,6 +1370,32 @@ static void My_FilterBench(ICompressFilter *filter, Byte *data, size_t size)
HRESULT CEncoderInfo::Encode()
{
+ // printf("\nCEncoderInfo::Generate\n");
+
+ RINOK(Generate())
+
+ // printf("\n2222\n");
+
+ #ifndef Z7_ST
+ if (Common)
+ {
+ Results[0] = S_OK;
+ WRes wres = ReadyEvent.Set();
+ if (wres == 0)
+ wres = Common->StartEvent.Lock();
+ if (wres != 0)
+ return HRESULT_FROM_WIN32(wres);
+ if (Common->ExitMode)
+ return S_OK;
+ }
+ else
+ #endif
+ {
+ CBenchProgressInfo *bpi = progressInfoSpec[0];
+ bpi->SetStartTime();
+ }
+
+
CBenchInfo &bi = progressInfoSpec[0]->BenchInfo;
bi.UnpackSize = 0;
bi.PackSize = 0;
@@ -976,52 +1408,116 @@ HRESULT CEncoderInfo::Encode()
coder.QueryInterface(IID_ICryptoProperties, &cp);
CBenchmarkInStream *inStreamSpec = new CBenchmarkInStream;
CMyComPtr<ISequentialInStream> inStream = inStreamSpec;
- UInt64 prev = 0;
-
- UInt32 crcPrev = 0;
if (cp)
{
- RINOK(cp->SetKey(_key, sizeof(_key)));
- RINOK(cp->SetInitVector(_iv, sizeof(_iv)));
+ RINOK(Set_Key_and_IV(cp))
+ }
+
+ compressedSize = 0;
+ if (_encoderFilter)
+ compressedSize = kBufferSize;
+
+ // CBenchmarkOutStream *outStreamSpec = this->outStreamSpec;
+ UInt64 prev = 0;
+
+ const UInt32 mask = (CheckCrc_Enc ? 0 : 0xFFFF);
+ const bool useCrc = (mask < NumIterations);
+ bool crcPrev_defined = false;
+ UInt32 crcPrev = 0;
+
+ bool useRealData_Enc = UseRealData_Enc;
+ bool data_Was_Changed = false;
+ if (useRealData_Enc)
+ {
+ /* we want memcpy() for each iteration including first iteration.
+ So results will be equal for different number of iterations */
+ data_Was_Changed = true;
}
- for (UInt64 i = 0; i < NumIterations; i++)
+ const UInt64 numIterations = NumIterations;
+ UInt64 i = numIterations;
+ // printCallback->NewLine();
+
+ while (i != 0)
{
- if (printCallback && bi.UnpackSize - prev > (1 << 20))
+ i--;
+ if (printCallback && bi.UnpackSize - prev >= (1 << 26))
{
- RINOK(printCallback->CheckBreak());
prev = bi.UnpackSize;
+ RINOK(printCallback->CheckBreak())
}
+
+ /*
+ CBenchInfo info;
+ progressInfoSpec[0]->SetStartTime();
+ */
- bool isLast = (i == NumIterations - 1);
- bool calcCrc = ((isLast || (i & 0x7F) == 0 || CheckCrc_Enc) && NumIterations != 1);
- outStreamSpec->Init(isLast, calcCrc);
-
+ bool calcCrc = false;
+ if (useCrc)
+ calcCrc = (((UInt32)i & mask) == 0);
+
if (_encoderFilter)
{
- memcpy(rgCopy.Buffer, uncompressedDataPtr, kBufferSize);
+ Byte *filterData = rgCopy;
+ if (i == numIterations - 1 || calcCrc || useRealData_Enc)
+ {
+ filterData = (Byte *)*outStreamSpec;
+ if (data_Was_Changed)
+ memcpy(filterData, uncompressedDataPtr, kBufferSize);
+ data_Was_Changed = true;
+ }
_encoderFilter->Init();
- My_FilterBench(_encoderFilter, rgCopy.Buffer, kBufferSize);
- RINOK(WriteStream(outStream, rgCopy.Buffer, kBufferSize));
+ if (calcCrc)
+ outStreamSpec->InitCrc();
+ My_FilterBench(_encoderFilter, filterData, kBufferSize,
+ calcCrc ? &outStreamSpec->Crc : NULL);
}
else
{
+ outStreamSpec->Init(true, calcCrc); // write real data for speed consistency at any number of iterations
inStreamSpec->Init(uncompressedDataPtr, kBufferSize);
- RINOK(_encoder->Code(inStream, outStream, NULL, NULL, progressInfo[0]));
+ RINOK(_encoder->Code(inStream, outStream, NULL, NULL, progressInfo[0]))
+ if (!inStreamSpec->WasFinished())
+ return E_FAIL;
+ if (compressedSize != outStreamSpec->Pos)
+ {
+ if (compressedSize != 0)
+ return E_FAIL;
+ compressedSize = outStreamSpec->Pos;
+ }
}
// outStreamSpec->Print();
- UInt32 crcNew = CRC_GET_DIGEST(outStreamSpec->Crc);
- if (i == 0)
- crcPrev = crcNew;
- else if (calcCrc && crcPrev != crcNew)
- return E_FAIL;
+ if (calcCrc)
+ {
+ const UInt32 crc2 = CRC_GET_DIGEST(outStreamSpec->Crc);
+ if (crcPrev_defined && crcPrev != crc2)
+ return E_FAIL;
+ crcPrev = crc2;
+ crcPrev_defined = true;
+ }
- compressedSize = outStreamSpec->Pos;
bi.UnpackSize += kBufferSize;
bi.PackSize += compressedSize;
+
+ /*
+ {
+ progressInfoSpec[0]->SetFinishTime(info);
+ info.UnpackSize = 0;
+ info.PackSize = 0;
+ info.NumIterations = 1;
+
+ info.UnpackSize = kBufferSize;
+ info.PackSize = compressedSize;
+ // printf("\n%7d\n", encoder.compressedSize);
+
+ RINOK(callback->SetEncodeResult(info, true))
+ printCallback->NewLine();
+ }
+ */
+
}
_encoder.Release();
@@ -1047,7 +1543,7 @@ HRESULT CEncoderInfo::Decode(UInt32 decoderIndex)
CMyComPtr<ICompressSetDecoderProperties2> setDecProps;
coder.QueryInterface(IID_ICompressSetDecoderProperties2, &setDecProps);
- if (!setDecProps && propStreamSpec->Pos != 0)
+ if (!setDecProps && propStreamSpec->GetPos() != 0)
return E_FAIL;
CCrcOutStream *crcOutStreamSpec = new CCrcOutStream;
@@ -1057,13 +1553,13 @@ HRESULT CEncoderInfo::Decode(UInt32 decoderIndex)
pi->BenchInfo.UnpackSize = 0;
pi->BenchInfo.PackSize = 0;
- #ifndef _7ZIP_ST
+ #ifndef Z7_ST
{
CMyComPtr<ICompressSetCoderMt> setCoderMt;
coder.QueryInterface(IID_ICompressSetCoderMt, &setCoderMt);
if (setCoderMt)
{
- RINOK(setCoderMt->SetNumberOfThreads(NumDecoderSubThreads));
+ RINOK(setCoderMt->SetNumberOfThreads(NumDecoderSubThreads))
}
}
#endif
@@ -1072,8 +1568,8 @@ HRESULT CEncoderInfo::Decode(UInt32 decoderIndex)
coder.QueryInterface(IID_ICompressSetCoderProperties, &scp);
if (scp)
{
- UInt64 reduceSize = _uncompressedDataSize;
- RINOK(_method.SetCoderProps(scp, &reduceSize));
+ const UInt64 reduceSize = _uncompressedDataSize;
+ RINOK(_method.SetCoderProps(scp, &reduceSize))
}
CMyComPtr<ICryptoProperties> cp;
@@ -1081,7 +1577,10 @@ HRESULT CEncoderInfo::Decode(UInt32 decoderIndex)
if (setDecProps)
{
- RINOK(setDecProps->SetDecoderProperties2(propStreamSpec->Buffer, (UInt32)propStreamSpec->Pos));
+ RINOK(setDecProps->SetDecoderProperties2(
+ /* (const Byte *)*propStreamSpec, */
+ propsData,
+ (UInt32)propStreamSpec->GetPos()))
}
{
@@ -1089,7 +1588,7 @@ HRESULT CEncoderInfo::Decode(UInt32 decoderIndex)
coder.QueryInterface(IID_ICryptoSetPassword, &sp);
if (sp)
{
- RINOK(sp->CryptoSetPassword(_psw, sizeof(_psw)));
+ RINOK(sp->CryptoSetPassword(_psw, sizeof(_psw)))
}
}
@@ -1097,40 +1596,90 @@ HRESULT CEncoderInfo::Decode(UInt32 decoderIndex)
if (cp)
{
- RINOK(cp->SetKey(_key, sizeof(_key)));
- RINOK(cp->SetInitVector(_iv, sizeof(_iv)));
+ RINOK(Set_Key_and_IV(cp))
}
- for (UInt64 i = 0; i < NumIterations; i++)
+ CMyComPtr<ICompressSetFinishMode> setFinishMode;
+
+ if (_decoderFilter)
{
- if (printCallback && pi->BenchInfo.UnpackSize - prev > (1 << 20))
+ if (compressedSize > rgCopy.Size())
+ return E_FAIL;
+ }
+ else
+ {
+ decoder->QueryInterface(IID_ICompressSetFinishMode, (void **)&setFinishMode);
+ }
+
+ const UInt64 numIterations = NumIterations;
+ const E_CheckCrcMode checkCrcMode = CheckCrcMode_Dec;
+
+ for (UInt64 i = 0; i < numIterations; i++)
+ {
+ if (printCallback && pi->BenchInfo.UnpackSize - prev >= (1 << 26))
{
- RINOK(printCallback->CheckBreak());
+ RINOK(printCallback->CheckBreak())
prev = pi->BenchInfo.UnpackSize;
}
- inStreamSpec->Init(outStreamSpec->Buffer, compressedSize);
+ const UInt64 outSize = kBufferSize;
+ bool calcCrc = (checkCrcMode != k_CheckCrcMode_Never);
+
crcOutStreamSpec->Init();
-
- UInt64 outSize = kBufferSize;
- crcOutStreamSpec->CalcCrc = ((i & 0x7F) == 0 || CheckCrc_Dec);
-
+
if (_decoderFilter)
{
- if (compressedSize > rgCopy.BufferSize)
- return E_FAIL;
- memcpy(rgCopy.Buffer, outStreamSpec->Buffer, compressedSize);
+ Byte *filterData = (Byte *)*outStreamSpec;
+ if (calcCrc)
+ {
+ calcCrc = (i == 0);
+ if (checkCrcMode == k_CheckCrcMode_Always)
+ {
+ calcCrc = true;
+ memcpy((Byte *)rgCopy, (const Byte *)*outStreamSpec, compressedSize);
+ filterData = rgCopy;
+ }
+ }
_decoderFilter->Init();
- My_FilterBench(_decoderFilter, rgCopy.Buffer, compressedSize);
- RINOK(WriteStream(crcOutStream, rgCopy.Buffer, compressedSize));
+ My_FilterBench(_decoderFilter, filterData, compressedSize,
+ calcCrc ? &crcOutStreamSpec->Crc : NULL);
}
else
{
- RINOK(decoder->Code(inStream, crcOutStream, 0, &outSize, progressInfo[decoderIndex]));
+ crcOutStreamSpec->CalcCrc = calcCrc;
+ inStreamSpec->Init((const Byte *)*outStreamSpec, compressedSize);
+
+ if (setFinishMode)
+ {
+ RINOK(setFinishMode->SetFinishMode(BoolToUInt(true)))
+ }
+
+ RINOK(decoder->Code(inStream, crcOutStream, NULL, &outSize, progressInfo[decoderIndex]))
+
+ if (setFinishMode)
+ {
+ if (!inStreamSpec->WasFinished())
+ return S_FALSE;
+
+ CMyComPtr<ICompressGetInStreamProcessedSize> getInStreamProcessedSize;
+ decoder.QueryInterface(IID_ICompressGetInStreamProcessedSize, (void **)&getInStreamProcessedSize);
+
+ if (getInStreamProcessedSize)
+ {
+ UInt64 processed;
+ RINOK(getInStreamProcessedSize->GetInStreamProcessedSize(&processed))
+ if (processed != compressedSize)
+ return S_FALSE;
+ }
+ }
+
+ if (crcOutStreamSpec->Pos != outSize)
+ return S_FALSE;
}
- if (crcOutStreamSpec->CalcCrc && CRC_GET_DIGEST(crcOutStreamSpec->Crc) != crc)
+ if (calcCrc && CRC_GET_DIGEST(crcOutStreamSpec->Crc) != crc)
return S_FALSE;
+
pi->BenchInfo.UnpackSize += kBufferSize;
pi->BenchInfo.PackSize += compressedSize;
}
@@ -1146,7 +1695,7 @@ static const UInt32 kNumThreadsMax = (1 << 12);
struct CBenchEncoders
{
CEncoderInfo *encoders;
- CBenchEncoders(UInt32 num): encoders(0) { encoders = new CEncoderInfo[num]; }
+ CBenchEncoders(UInt32 num): encoders(NULL) { encoders = new CEncoderInfo[num]; }
~CBenchEncoders() { delete []encoders; }
};
@@ -1160,19 +1709,74 @@ static UInt64 GetNumIterations(UInt64 numCommands, UInt64 complexInCommands)
}
+
+#ifndef Z7_ST
+
+// ---------- CBenchThreadsFlusher ----------
+
+struct CBenchThreadsFlusher
+{
+ CBenchEncoders *EncodersSpec;
+ CBenchSyncCommon Common;
+ unsigned NumThreads;
+ bool NeedClose;
+
+ CBenchThreadsFlusher(): NumThreads(0), NeedClose(false) {}
+
+ ~CBenchThreadsFlusher()
+ {
+ StartAndWait(true);
+ }
+
+ WRes StartAndWait(bool exitMode = false);
+};
+
+
+WRes CBenchThreadsFlusher::StartAndWait(bool exitMode)
+{
+ if (!NeedClose)
+ return 0;
+
+ Common.ExitMode = exitMode;
+ WRes res = Common.StartEvent.Set();
+
+ for (unsigned i = 0; i < NumThreads; i++)
+ {
+ NWindows::CThread &t = EncodersSpec->encoders[i].thread[0];
+ if (t.IsCreated())
+ {
+ WRes res2 = t.Wait_Close();
+ if (res == 0)
+ res = res2;
+ }
+ }
+ NeedClose = false;
+ return res;
+}
+
+#endif // Z7_ST
+
+
+
+static void SetPseudoRand(Byte *data, size_t size, UInt32 startValue)
+{
+ for (size_t i = 0; i < size; i++)
+ {
+ data[i] = (Byte)startValue;
+ startValue++;
+ }
+}
+
+
+
static HRESULT MethodBench(
DECL_EXTERNAL_CODECS_LOC_VARS
UInt64 complexInCommands,
- bool
- #ifndef _7ZIP_ST
- oldLzmaBenchMode
- #endif
- ,
- UInt32
- #ifndef _7ZIP_ST
- numThreads
- #endif
- ,
+ #ifndef Z7_ST
+ bool oldLzmaBenchMode,
+ UInt32 numThreads,
+ const CAffinityMode *affinityMode,
+ #endif
const COneMethodInfo &method2,
size_t uncompressedDataSize,
const Byte *fileData,
@@ -1185,9 +1789,12 @@ static HRESULT MethodBench(
COneMethodInfo method = method2;
UInt64 methodId;
UInt32 numStreams;
- if (!FindMethod(
+ bool isFilter;
+ const int codecIndex = FindMethod_Index(
EXTERNAL_CODECS_LOC_VARS
- method.MethodName, methodId, numStreams))
+ method.MethodName, true,
+ methodId, numStreams, isFilter);
+ if (codecIndex < 0)
return E_NOTIMPL;
if (numStreams != 1)
return E_INVALIDARG;
@@ -1195,21 +1802,24 @@ static HRESULT MethodBench(
UInt32 numEncoderThreads = 1;
UInt32 numSubDecoderThreads = 1;
- #ifndef _7ZIP_ST
+ #ifndef Z7_ST
numEncoderThreads = numThreads;
- if (oldLzmaBenchMode && methodId == k_LZMA)
+ if (oldLzmaBenchMode)
+ if (methodId == k_LZMA)
{
- bool fixedNumber;
- UInt32 numLzmaThreads = method.Get_Lzma_NumThreads(fixedNumber);
- if (!fixedNumber && numThreads == 1)
+ if (numThreads == 1 && method.Get_NumThreads() < 0)
method.AddProp_NumThreads(1);
+ const UInt32 numLzmaThreads = method.Get_Lzma_NumThreads();
if (numThreads > 1 && numLzmaThreads > 1)
{
- numEncoderThreads = numThreads / 2;
+ numEncoderThreads = (numThreads + 1) / 2; // 20.03
numSubDecoderThreads = 2;
}
}
+
+ const bool mtEncMode = (numEncoderThreads > 1) || affinityMode->NeedAffinity();
+
#endif
CBenchEncoders encodersSpec(numEncoderThreads);
@@ -1220,37 +1830,65 @@ static HRESULT MethodBench(
for (i = 0; i < numEncoderThreads; i++)
{
CEncoderInfo &encoder = encoders[i];
- encoder.callback = (i == 0) ? callback : 0;
+ encoder.callback = (i == 0) ? callback : NULL;
encoder.printCallback = printCallback;
+ #ifndef Z7_ST
+ encoder.EncoderIndex = i;
+ encoder.NumEncoderInternalThreads = numSubDecoderThreads;
+ encoder.AffinityMode = *affinityMode;
+
+ /*
+ if (numSubDecoderThreads > 1)
+ if (encoder.AffinityMode.NeedAffinity()
+ && encoder.AffinityMode.NumBundleThreads == 1)
+ {
+ // if old LZMA benchmark uses two threads in coder, we increase (NumBundleThreads) for old LZMA benchmark uses two threads instead of one
+ if (encoder.AffinityMode.NumBundleThreads * 2 <= encoder.AffinityMode.NumCores)
+ encoder.AffinityMode.NumBundleThreads *= 2;
+ }
+ */
+
+ #endif
+
{
CCreatedCoder cod;
- RINOK(CreateCoder(EXTERNAL_CODECS_LOC_VARS methodId, true, encoder._encoderFilter, cod));
+ RINOK(CreateCoder_Index(EXTERNAL_CODECS_LOC_VARS (unsigned)codecIndex, true, encoder._encoderFilter, cod))
encoder._encoder = cod.Coder;
if (!encoder._encoder && !encoder._encoderFilter)
return E_NOTIMPL;
}
- encoder.CheckCrc_Enc = (benchProps->EncComplex) > 30 ;
- encoder.CheckCrc_Dec = (benchProps->DecComplexCompr + benchProps->DecComplexUnc) > 30 ;
-
- memset(encoder._iv, 0, sizeof(encoder._iv));
- memset(encoder._key, 0, sizeof(encoder._key));
- memset(encoder._psw, 0, sizeof(encoder._psw));
+ SetPseudoRand(encoder._iv, sizeof(encoder._iv), 17);
+ SetPseudoRand(encoder._key, sizeof(encoder._key), 51);
+ SetPseudoRand(encoder._psw, sizeof(encoder._psw), 123);
for (UInt32 j = 0; j < numSubDecoderThreads; j++)
{
CCreatedCoder cod;
CMyComPtr<ICompressCoder> &decoder = encoder._decoders[j];
- RINOK(CreateCoder(EXTERNAL_CODECS_LOC_VARS methodId, false, encoder._decoderFilter, cod));
+ RINOK(CreateCoder_Id(EXTERNAL_CODECS_LOC_VARS methodId, false, encoder._decoderFilter, cod))
decoder = cod.Coder;
if (!encoder._decoderFilter && !decoder)
return E_NOTIMPL;
}
- }
- CBaseRandomGenerator rg;
- rg.Init();
+ encoder.UseRealData_Enc =
+ encoder.CheckCrc_Enc = (benchProps->EncComplex) > 30;
+
+ encoder.CheckCrcMode_Dec = k_CheckCrcMode_Always;
+ if (benchProps->DecComplexCompr +
+ benchProps->DecComplexUnc <= 30)
+ encoder.CheckCrcMode_Dec =
+ k_CheckCrcMode_FirstPass; // for filters
+ // k_CheckCrcMode_Never; // for debug
+ // k_CheckCrcMode_Always; // for debug
+ if (fileData)
+ {
+ encoder.UseRealData_Enc = true;
+ encoder.CheckCrcMode_Dec = k_CheckCrcMode_Always;
+ }
+ }
UInt32 crc = 0;
if (fileData)
@@ -1260,22 +1898,41 @@ static HRESULT MethodBench(
{
CEncoderInfo &encoder = encoders[i];
encoder._method = method;
+ encoder.generateDictBits = generateDictBits;
encoder._uncompressedDataSize = uncompressedDataSize;
encoder.kBufferSize = uncompressedDataSize;
encoder.fileData = fileData;
encoder.crc = crc;
-
- RINOK(encoders[i].Init(method, generateDictBits, &rg));
}
CBenchProgressStatus status;
status.Res = S_OK;
status.EncodeMode = true;
+ #ifndef Z7_ST
+ CBenchThreadsFlusher encoderFlusher;
+ if (mtEncMode)
+ {
+ WRes wres = encoderFlusher.Common.StartEvent.Create();
+ if (wres != 0)
+ return HRESULT_FROM_WIN32(wres);
+ encoderFlusher.NumThreads = numEncoderThreads;
+ encoderFlusher.EncodersSpec = &encodersSpec;
+ encoderFlusher.NeedClose = true;
+ }
+ #endif
+
for (i = 0; i < numEncoderThreads; i++)
{
CEncoderInfo &encoder = encoders[i];
- encoder.NumIterations = GetNumIterations(benchProps->GeComprCommands(uncompressedDataSize), complexInCommands);
+ encoder.NumIterations = GetNumIterations(benchProps->GetNumCommands_Enc(uncompressedDataSize), complexInCommands);
+ // encoder.NumIterations = 3;
+ encoder.Salt = g_CrcTable[i & 0xFF];
+ encoder.Salt ^= (g_CrcTable[(i >> 8) & 0xFF] << 3);
+ // (g_CrcTable[0] == 0), and (encoder.Salt == 0) for first thread
+ // printf(" %8x", encoder.Salt);
+
+ encoder.KeySize = benchProps->KeySize;
for (int j = 0; j < 2; j++)
{
@@ -1290,32 +1947,53 @@ static HRESULT MethodBench(
CBenchProgressInfo *bpi = encoder.progressInfoSpec[0];
bpi->Callback = callback;
bpi->BenchInfo.NumIterations = numEncoderThreads;
- bpi->SetStartTime();
}
- #ifndef _7ZIP_ST
- if (numEncoderThreads > 1)
+ #ifndef Z7_ST
+ if (mtEncMode)
{
#ifdef USE_ALLOCA
encoder.AllocaSize = (i * 16 * 21) & 0x7FF;
#endif
+ encoder.Common = &encoderFlusher.Common;
+ encoder.IsGlobalMtMode = numEncoderThreads > 1;
RINOK(encoder.CreateEncoderThread())
}
- else
#endif
+ }
+
+ if (printCallback)
+ {
+ RINOK(printCallback->CheckBreak())
+ }
+
+ #ifndef Z7_ST
+ if (mtEncMode)
+ {
+ for (i = 0; i < numEncoderThreads; i++)
{
- RINOK(encoder.Encode());
+ CEncoderInfo &encoder = encoders[i];
+ const WRes wres = encoder.ReadyEvent.Lock();
+ if (wres != 0)
+ return HRESULT_FROM_WIN32(wres);
+ RINOK(encoder.Results[0])
}
+
+ CBenchProgressInfo *bpi = encoders[0].progressInfoSpec[0];
+ bpi->SetStartTime();
+
+ const WRes wres = encoderFlusher.StartAndWait();
+ if (status.Res == 0 && wres != 0)
+ return HRESULT_FROM_WIN32(wres);
}
-
- #ifndef _7ZIP_ST
- if (numEncoderThreads > 1)
- for (i = 0; i < numEncoderThreads; i++)
- encoders[i].thread[0].Wait();
+ else
#endif
+ {
+ RINOK(encoders[0].Encode())
+ }
- RINOK(status.Res);
+ RINOK(status.Res)
CBenchInfo info;
@@ -1326,26 +2004,47 @@ static HRESULT MethodBench(
for (i = 0; i < numEncoderThreads; i++)
{
- CEncoderInfo &encoder = encoders[i];
+ const CEncoderInfo &encoder = encoders[i];
info.UnpackSize += encoder.kBufferSize;
info.PackSize += encoder.compressedSize;
+ // printf("\n%7d\n", encoder.compressedSize);
}
- RINOK(callback->SetEncodeResult(info, true));
+ RINOK(callback->SetEncodeResult(info, true))
+
+
+ // ---------- Decode ----------
+
status.Res = S_OK;
status.EncodeMode = false;
- UInt32 numDecoderThreads = numEncoderThreads * numSubDecoderThreads;
+ const UInt32 numDecoderThreads = numEncoderThreads * numSubDecoderThreads;
+ #ifndef Z7_ST
+ const bool mtDecoderMode = (numDecoderThreads > 1) || affinityMode->NeedAffinity();
+ #endif
for (i = 0; i < numEncoderThreads; i++)
{
CEncoderInfo &encoder = encoders[i];
+ /*
+ #ifndef Z7_ST
+ // encoder.affinityMode = *affinityMode;
+ if (encoder.NumEncoderInternalThreads != 1)
+ encoder.AffinityMode.DivideNum = encoder.NumEncoderInternalThreads;
+ #endif
+ */
+
+
if (i == 0)
{
- encoder.NumIterations = GetNumIterations(benchProps->GeDecomprCommands(encoder.compressedSize, encoder.kBufferSize), complexInCommands);
+ encoder.NumIterations = GetNumIterations(
+ benchProps->GetNumCommands_Dec(
+ encoder.compressedSize,
+ encoder.kBufferSize),
+ complexInCommands);
CBenchProgressInfo *bpi = encoder.progressInfoSpec[0];
bpi->Callback = callback;
bpi->BenchInfo.NumIterations = numDecoderThreads;
@@ -1354,50 +2053,61 @@ static HRESULT MethodBench(
else
encoder.NumIterations = encoders[0].NumIterations;
- #ifndef _7ZIP_ST
+ #ifndef Z7_ST
{
int numSubThreads = method.Get_NumThreads();
- encoder.NumDecoderSubThreads = (numSubThreads <= 0) ? 1 : numSubThreads;
+ encoder.NumDecoderSubThreads = (numSubThreads <= 0) ? 1 : (unsigned)numSubThreads;
}
- if (numDecoderThreads > 1)
+ if (mtDecoderMode)
{
for (UInt32 j = 0; j < numSubDecoderThreads; j++)
{
- HRESULT res = encoder.CreateDecoderThread(j, (i == 0 && j == 0)
+ const HRESULT res = encoder.CreateDecoderThread(j, (i == 0 && j == 0)
#ifdef USE_ALLOCA
, ((i * numSubDecoderThreads + j) * 16 * 21) & 0x7FF
#endif
);
- RINOK(res);
+ RINOK(res)
}
}
else
#endif
{
- RINOK(encoder.Decode(0));
+ RINOK(encoder.Decode(0))
}
}
- #ifndef _7ZIP_ST
- HRESULT res = S_OK;
- if (numDecoderThreads > 1)
+ #ifndef Z7_ST
+ if (mtDecoderMode)
+ {
+ WRes wres = 0;
+ HRESULT res = S_OK;
for (i = 0; i < numEncoderThreads; i++)
for (UInt32 j = 0; j < numSubDecoderThreads; j++)
{
CEncoderInfo &encoder = encoders[i];
- encoder.thread[j].Wait();
- if (encoder.Results[j] != S_OK)
- res = encoder.Results[j];
+ const WRes wres2 = encoder.thread[j].
+ // Wait(); // later we can get thread times from thread in UNDER_CE
+ Wait_Close();
+ if (wres == 0 && wres2 != 0)
+ wres = wres2;
+ const HRESULT res2 = encoder.Results[j];
+ if (res == 0 && res2 != 0)
+ res = res2;
}
- RINOK(res);
- #endif
-
- RINOK(status.Res);
+ if (wres != 0)
+ return HRESULT_FROM_WIN32(wres);
+ RINOK(res)
+ }
+ #endif // Z7_ST
+
+ RINOK(status.Res)
encoders[0].progressInfoSpec[0]->SetFinishTime(info);
-
- #ifndef _7ZIP_ST
+
+ /*
+ #ifndef Z7_ST
#ifdef UNDER_CE
- if (numDecoderThreads > 1)
+ if (mtDecoderMode)
for (i = 0; i < numEncoderThreads; i++)
for (UInt32 j = 0; j < numSubDecoderThreads; j++)
{
@@ -1407,6 +2117,7 @@ static HRESULT MethodBench(
}
#endif
#endif
+ */
info.UnpackSize = 0;
info.PackSize = 0;
@@ -1414,21 +2125,41 @@ static HRESULT MethodBench(
for (i = 0; i < numEncoderThreads; i++)
{
- CEncoderInfo &encoder = encoders[i];
+ const CEncoderInfo &encoder = encoders[i];
info.UnpackSize += encoder.kBufferSize;
info.PackSize += encoder.compressedSize;
}
- RINOK(callback->SetDecodeResult(info, false));
- RINOK(callback->SetDecodeResult(info, true));
+ // RINOK(callback->SetDecodeResult(info, false)) // why we called before 21.03 ??
+ RINOK(callback->SetDecodeResult(info, true))
return S_OK;
}
-static inline UInt64 GetLZMAUsage(bool multiThread, UInt32 dictionary)
+
+static inline UInt64 GetDictSizeFromLog(unsigned dictSizeLog)
+{
+ /*
+ if (dictSizeLog < 32)
+ return (UInt32)1 << dictSizeLog;
+ else
+ return (UInt32)(Int32)-1;
+ */
+ return (UInt64)1 << dictSizeLog;
+}
+
+
+// it's limit of current LZMA implementation that can be changed later
+#define kLzmaMaxDictSize ((UInt32)15 << 28)
+
+static inline UInt64 GetLZMAUsage(bool multiThread, int btMode, UInt64 dict)
{
- UInt32 hs = dictionary - 1;
+ if (dict == 0)
+ dict = 1;
+ if (dict > kLzmaMaxDictSize)
+ dict = kLzmaMaxDictSize;
+ UInt32 hs = (UInt32)dict - 1;
hs |= (hs >> 1);
hs |= (hs >> 2);
hs |= (hs >> 4);
@@ -1438,53 +2169,158 @@ static inline UInt64 GetLZMAUsage(bool multiThread, UInt32 dictionary)
if (hs > (1 << 24))
hs >>= 1;
hs++;
- return ((hs + (1 << 16)) + (UInt64)dictionary * 2) * 4 + (UInt64)dictionary * 3 / 2 +
+ hs += (1 << 16);
+
+ const UInt32 kBlockSizeMax = (UInt32)0 - (UInt32)(1 << 16);
+ UInt64 blockSize = (UInt64)dict + (1 << 16)
+ + (multiThread ? (1 << 20) : 0);
+ blockSize += (blockSize >> (blockSize < ((UInt32)1 << 30) ? 1 : 2));
+ if (blockSize >= kBlockSizeMax)
+ blockSize = kBlockSizeMax;
+
+ UInt64 son = (UInt64)dict;
+ if (btMode)
+ son *= 2;
+ const UInt64 v = (hs + son) * 4 + blockSize +
(1 << 20) + (multiThread ? (6 << 20) : 0);
+
+ // printf("\nGetLZMAUsage = %d\n", (UInt32)(v >> 20));
+ // printf("\nblockSize = %d\n", (UInt32)(blockSize >> 20));
+ return v;
}
-UInt64 GetBenchMemoryUsage(UInt32 numThreads, UInt32 dictionary, bool totalBench)
+
+UInt64 GetBenchMemoryUsage(UInt32 numThreads, int level, UInt64 dictionary, bool totalBench)
{
- const UInt32 kBufferSize = dictionary;
- const UInt32 kCompressedBufferSize = kBufferSize; // / 2;
- bool lzmaMt = (totalBench || numThreads > 1);
+ const size_t kBufferSize = (size_t)dictionary + kAdditionalSize;
+ const UInt64 kCompressedBufferSize = GetBenchCompressedSize(kBufferSize); // / 2;
+ if (level < 0)
+ level = 5;
+ const int algo = (level < 5 ? 0 : 1);
+ const int btMode = (algo == 0 ? 0 : 1);
+
UInt32 numBigThreads = numThreads;
- if (!totalBench && lzmaMt)
- numBigThreads /= 2;
+ bool lzmaMt = (totalBench || (numThreads > 1 && btMode));
+ if (btMode)
+ {
+ if (!totalBench && lzmaMt)
+ numBigThreads /= 2;
+ }
return ((UInt64)kBufferSize + kCompressedBufferSize +
- GetLZMAUsage(lzmaMt, dictionary) + (2 << 20)) * numBigThreads;
+ GetLZMAUsage(lzmaMt, btMode, dictionary) + (2 << 20)) * numBigThreads;
}
-static HRESULT CrcBig(const void *data, UInt32 size, UInt64 numIterations,
+static UInt64 GetBenchMemoryUsage_Hash(UInt32 numThreads, UInt64 dictionary)
+{
+ // dictionary += (dictionary >> 9); // for page tables (virtual memory)
+ return (UInt64)(dictionary + (1 << 15)) * numThreads + (2 << 20);
+}
+
+
+// ---------- CRC and HASH ----------
+
+struct CCrcInfo_Base
+{
+ CMidAlignedBuffer Buffer;
+ const Byte *Data;
+ size_t Size;
+ bool CreateLocalBuf;
+ UInt32 CheckSum_Res;
+
+ CCrcInfo_Base(): CreateLocalBuf(true), CheckSum_Res(0) {}
+
+ HRESULT Generate(const Byte *data, size_t size);
+ HRESULT CrcProcess(UInt64 numIterations,
+ const UInt32 *checkSum, IHasher *hf,
+ IBenchPrintCallback *callback);
+};
+
+
+HRESULT CCrcInfo_Base::Generate(const Byte *data, size_t size)
+{
+ Size = size;
+ Data = data;
+ if (!data || CreateLocalBuf)
+ {
+ ALLOC_WITH_HRESULT(&Buffer, size)
+ Data = Buffer;
+ }
+ if (!data)
+ RandGen(Buffer, size);
+ else if (CreateLocalBuf && size != 0)
+ memcpy(Buffer, data, size);
+ return S_OK;
+}
+
+
+HRESULT CCrcInfo_Base::CrcProcess(UInt64 numIterations,
const UInt32 *checkSum, IHasher *hf,
IBenchPrintCallback *callback)
{
+ MY_ALIGN(16)
Byte hash[64];
- UInt64 i;
- for (i = 0; i < sizeof(hash); i++)
- hash[i] = 0;
- for (i = 0; i < numIterations; i++)
+ memset(hash, 0, sizeof(hash));
+
+ CheckSum_Res = 0;
+
+ const UInt32 hashSize = hf->GetDigestSize();
+ if (hashSize > sizeof(hash))
+ return S_FALSE;
+
+ const Byte *buf = Data;
+ const size_t size = Size;
+ UInt32 checkSum_Prev = 0;
+
+ UInt64 prev = 0;
+ UInt64 cur = 0;
+
+ for (UInt64 i = 0; i < numIterations; i++)
{
- if (callback && (i & 0xFF) == 0)
+ hf->Init();
+ size_t pos = 0;
+ do
{
- RINOK(callback->CheckBreak());
+ const size_t rem = size - pos;
+ const UInt32 kStep = ((UInt32)1 << 31);
+ const UInt32 curSize = (rem < kStep) ? (UInt32)rem : kStep;
+ hf->Update(buf + pos, curSize);
+ pos += curSize;
}
- hf->Init();
- hf->Update(data, size);
+ while (pos != size);
+
hf->Final(hash);
- UInt32 hashSize = hf->GetDigestSize();
- if (hashSize > sizeof(hash))
- return S_FALSE;
UInt32 sum = 0;
for (UInt32 j = 0; j < hashSize; j += 4)
- sum ^= GetUi32(hash + j);
- if (checkSum && sum != *checkSum)
{
- return S_FALSE;
+ sum = rotlFixed(sum, 11);
+ sum += GetUi32(hash + j);
+ }
+ if (checkSum)
+ {
+ if (sum != *checkSum)
+ return S_FALSE;
+ }
+ else
+ {
+ checkSum_Prev = sum;
+ checkSum = &checkSum_Prev;
+ }
+ if (callback)
+ {
+ cur += size;
+ if (cur - prev >= ((UInt32)1 << 30))
+ {
+ prev = cur;
+ RINOK(callback->CheckBreak())
+ }
}
}
+ CheckSum_Res = checkSum_Prev;
return S_OK;
}
+extern
+UInt32 g_BenchCpuFreqTemp; // we need non-static variavble to disable compiler optimization
UInt32 g_BenchCpuFreqTemp = 1;
#define YY1 sum += val; sum ^= val;
@@ -1507,24 +2343,29 @@ static UInt32 CountCpuFreq(UInt32 sum, UInt32 num, UInt32 val)
EXTERN_C_END
-#ifndef _7ZIP_ST
+#ifndef Z7_ST
-struct CFreqInfo
+struct CBaseThreadInfo
{
NWindows::CThread Thread;
IBenchPrintCallback *Callback;
HRESULT CallbackRes;
- UInt32 ValRes;
- UInt32 Size;
- UInt64 NumIterations;
- void Wait()
+ WRes Wait_If_Created()
{
- Thread.Wait();
- Thread.Close();
+ if (!Thread.IsCreated())
+ return 0;
+ return Thread.Wait_Close();
}
};
+struct CFreqInfo: public CBaseThreadInfo
+{
+ UInt32 ValRes;
+ UInt32 Size;
+ UInt64 NumIterations;
+};
+
static THREAD_FUNC_DECL FreqThreadFunction(void *param)
{
CFreqInfo *p = (CFreqInfo *)param;
@@ -1532,13 +2373,16 @@ static THREAD_FUNC_DECL FreqThreadFunction(void *param)
UInt32 sum = g_BenchCpuFreqTemp;
for (UInt64 k = p->NumIterations; k > 0; k--)
{
- p->CallbackRes = p->Callback->CheckBreak();
- if (p->CallbackRes != S_OK)
- return 0;
+ if (p->Callback)
+ {
+ p->CallbackRes = p->Callback->CheckBreak();
+ if (p->CallbackRes != S_OK)
+ break;
+ }
sum = CountCpuFreq(sum, p->Size, g_BenchCpuFreqTemp);
}
p->ValRes = sum;
- return 0;
+ return THREAD_FUNC_RET_ZERO;
}
struct CFreqThreads
@@ -1546,13 +2390,21 @@ struct CFreqThreads
CFreqInfo *Items;
UInt32 NumThreads;
- CFreqThreads(): Items(0), NumThreads(0) {}
- void WaitAll()
+ CFreqThreads(): Items(NULL), NumThreads(0) {}
+
+ WRes WaitAll()
{
+ WRes wres = 0;
for (UInt32 i = 0; i < NumThreads; i++)
- Items[i].Wait();
+ {
+ WRes wres2 = Items[i].Wait_If_Created();
+ if (wres == 0 && wres2 != 0)
+ wres = wres2;
+ }
NumThreads = 0;
+ return wres;
}
+
~CFreqThreads()
{
WaitAll();
@@ -1560,30 +2412,95 @@ struct CFreqThreads
}
};
-struct CCrcInfo
-{
- NWindows::CThread Thread;
- IBenchPrintCallback *Callback;
- HRESULT CallbackRes;
+static THREAD_FUNC_DECL CrcThreadFunction(void *param);
+
+struct CCrcInfo: public CBaseThreadInfo
+{
const Byte *Data;
- UInt32 Size;
+ size_t Size;
UInt64 NumIterations;
bool CheckSumDefined;
UInt32 CheckSum;
CMyComPtr<IHasher> Hasher;
HRESULT Res;
+ UInt32 CheckSum_Res;
+
+ #ifndef Z7_ST
+ NSynchronization::CManualResetEvent ReadyEvent;
+ UInt32 ThreadIndex;
+ CBenchSyncCommon *Common;
+ CAffinityMode AffinityMode;
+ #endif
+
+ // we want to call CCrcInfo_Base::Buffer.Free() in main thread.
+ // so we uses non-local CCrcInfo_Base.
+ CCrcInfo_Base crcib;
+
+ HRESULT CreateThread()
+ {
+ WRes res = 0;
+ if (!ReadyEvent.IsCreated())
+ res = ReadyEvent.Create();
+ if (res == 0)
+ res = AffinityMode.CreateThread_WithAffinity(Thread, CrcThreadFunction, this,
+ ThreadIndex);
+ return HRESULT_FROM_WIN32(res);
+ }
#ifdef USE_ALLOCA
size_t AllocaSize;
#endif
- void Wait()
+ void Process();
+
+ CCrcInfo(): Res(E_FAIL) {}
+};
+
+static const bool k_Crc_CreateLocalBuf_For_File = true; // for total BW test
+// static const bool k_Crc_CreateLocalBuf_For_File = false; // for shared memory read test
+
+void CCrcInfo::Process()
+{
+ crcib.CreateLocalBuf = k_Crc_CreateLocalBuf_For_File;
+ // we can use additional Generate() passes to reduce some time effects for new page allocation
+ // for (unsigned y = 0; y < 10; y++)
+ Res = crcib.Generate(Data, Size);
+
+ // if (Common)
{
- Thread.Wait();
- Thread.Close();
+ WRes wres = ReadyEvent.Set();
+ if (wres != 0)
+ {
+ if (Res == 0)
+ Res = HRESULT_FROM_WIN32(wres);
+ return;
+ }
+ if (Res != 0)
+ return;
+
+ wres = Common->StartEvent.Lock();
+
+ if (wres != 0)
+ {
+ Res = HRESULT_FROM_WIN32(wres);
+ return;
+ }
+ if (Common->ExitMode)
+ return;
}
-};
+
+ Res = crcib.CrcProcess(NumIterations,
+ CheckSumDefined ? &CheckSum : NULL, Hasher,
+ Callback);
+ CheckSum_Res = crcib.CheckSum_Res;
+ /*
+ We don't want to include the time of slow CCrcInfo_Base::Buffer.Free()
+ to time of benchmark. So we don't free Buffer here
+ */
+ // crcib.Buffer.Free();
+}
+
static THREAD_FUNC_DECL CrcThreadFunction(void *param)
{
@@ -1592,73 +2509,87 @@ static THREAD_FUNC_DECL CrcThreadFunction(void *param)
#ifdef USE_ALLOCA
alloca(p->AllocaSize);
#endif
-
- p->Res = CrcBig(p->Data, p->Size, p->NumIterations,
- p->CheckSumDefined ? &p->CheckSum : NULL, p->Hasher,
- p->Callback);
- return 0;
+ p->Process();
+ return THREAD_FUNC_RET_ZERO;
}
+
struct CCrcThreads
{
CCrcInfo *Items;
- UInt32 NumThreads;
+ unsigned NumThreads;
+ CBenchSyncCommon Common;
+ bool NeedClose;
+
+ CCrcThreads(): Items(NULL), NumThreads(0), NeedClose(false) {}
+
+ WRes StartAndWait(bool exitMode = false);
- CCrcThreads(): Items(0), NumThreads(0) {}
- void WaitAll()
- {
- for (UInt32 i = 0; i < NumThreads; i++)
- Items[i].Wait();
- NumThreads = 0;
- }
~CCrcThreads()
{
- WaitAll();
+ StartAndWait(true);
delete []Items;
}
};
-#endif
-static UInt32 CrcCalc1(const Byte *buf, UInt32 size)
+WRes CCrcThreads::StartAndWait(bool exitMode)
{
- UInt32 crc = CRC_INIT_VAL;;
- for (UInt32 i = 0; i < size; i++)
- crc = CRC_UPDATE_BYTE(crc, buf[i]);
- return CRC_GET_DIGEST(crc);
+ if (!NeedClose)
+ return 0;
+
+ Common.ExitMode = exitMode;
+ WRes wres = Common.StartEvent.Set();
+
+ for (unsigned i = 0; i < NumThreads; i++)
+ {
+ WRes wres2 = Items[i].Wait_If_Created();
+ if (wres == 0 && wres2 != 0)
+ wres = wres2;
+ }
+ NumThreads = 0;
+ NeedClose = false;
+ return wres;
}
-static void RandGen(Byte *buf, UInt32 size, CBaseRandomGenerator &RG)
+#endif
+
+
+static UInt32 CrcCalc1(const Byte *buf, size_t size)
{
- for (UInt32 i = 0; i < size; i++)
- buf[i] = (Byte)RG.GetRnd();
+ UInt32 crc = CRC_INIT_VAL;
+ for (size_t i = 0; i < size; i++)
+ crc = CRC_UPDATE_BYTE(crc, buf[i]);
+ return CRC_GET_DIGEST(crc);
}
-static UInt32 RandGenCrc(Byte *buf, UInt32 size, CBaseRandomGenerator &RG)
+/*
+static UInt32 RandGenCrc(Byte *buf, size_t size, CBaseRandomGenerator &RG)
{
RandGen(buf, size, RG);
return CrcCalc1(buf, size);
}
+*/
-bool CrcInternalTest()
+static bool CrcInternalTest()
{
- CBenchBuffer buffer;
- const UInt32 kBufferSize0 = (1 << 8);
- const UInt32 kBufferSize1 = (1 << 10);
- const UInt32 kCheckSize = (1 << 5);
- if (!buffer.Alloc(kBufferSize0 + kBufferSize1))
+ CAlignedBuffer buffer;
+ const size_t kBufferSize0 = (1 << 8);
+ const size_t kBufferSize1 = (1 << 10);
+ const unsigned kCheckSize = (1 << 5);
+ buffer.Alloc(kBufferSize0 + kBufferSize1);
+ if (!buffer.IsAllocated())
return false;
- Byte *buf = buffer.Buffer;
- UInt32 i;
+ Byte *buf = (Byte *)buffer;
+ size_t i;
for (i = 0; i < kBufferSize0; i++)
buf[i] = (Byte)i;
UInt32 crc1 = CrcCalc1(buf, kBufferSize0);
if (crc1 != 0x29058C73)
return false;
- CBaseRandomGenerator RG;
- RandGen(buf + kBufferSize0, kBufferSize1, RG);
+ RandGen(buf + kBufferSize0, kBufferSize1);
for (i = 0; i < kBufferSize0 + kBufferSize1 - kCheckSize; i++)
- for (UInt32 j = 0; j < kCheckSize; j++)
+ for (unsigned j = 0; j < kCheckSize; j++)
if (CrcCalc1(buf + i, j) != CrcCalc(buf + i, j))
return false;
return true;
@@ -1668,15 +2599,29 @@ struct CBenchMethod
{
unsigned Weight;
unsigned DictBits;
- UInt32 EncComplex;
- UInt32 DecComplexCompr;
- UInt32 DecComplexUnc;
+ Int32 EncComplex;
+ Int32 DecComplexCompr;
+ Int32 DecComplexUnc;
const char *Name;
+ // unsigned KeySize;
};
+// #define USE_SW_CMPLX
+
+#ifdef USE_SW_CMPLX
+#define CMPLX(x) ((x) * 1000)
+#else
+#define CMPLX(x) (x)
+#endif
+
static const CBenchMethod g_Bench[] =
{
- { 40, 17, 357, 145, 20, "LZMA:x1" },
+ // { 40, 17, 357, 145, 20, "LZMA:x1" },
+ // { 20, 18, 360, 145, 20, "LZMA2:x1:mt2" },
+
+ { 20, 18, 360, 145, 20, "LZMA:x1" },
+ { 20, 22, 600, 145, 20, "LZMA:x3" },
+
{ 80, 24, 1220, 145, 20, "LZMA:x5:mt1" },
{ 80, 24, 1220, 145, 20, "LZMA:x5:mt2" },
@@ -1690,14 +2635,46 @@ static const CBenchMethod g_Bench[] =
{ 10, 19, 815, 122, 122, "BZip2:x5:mt2" },
{ 10, 19, 2530, 122, 122, "BZip2:x7" },
+ // { 10, 18, 1010, 0, 1150, "PPMDZip:x1" },
{ 10, 18, 1010, 0, 1150, "PPMD:x1" },
+ // { 10, 22, 1655, 0, 1830, "PPMDZip:x5" },
{ 10, 22, 1655, 0, 1830, "PPMD:x5" },
- { 2, 0, 6, 0, 6, "Delta:4" },
- { 2, 0, 4, 0, 4, "BCJ" },
+ // { 2, 0, -16, 0, -16, "Swap2" },
+ { 2, 0, -16, 0, -16, "Swap4" },
+ // { 2, 0, 3, 0, 4, "Delta:1" },
+ // { 2, 0, 3, 0, 4, "Delta:2" },
+ // { 2, 0, 3, 0, 4, "Delta:3" },
+ { 2, 0, 3, 0, 4, "Delta:4" },
+ // { 2, 0, 3, 0, 4, "Delta:8" },
+ // { 2, 0, 3, 0, 4, "Delta:32" },
+
+ { 2, 0, 2, 0, 2, "BCJ" },
+ { 2, 0, 1, 0, 1, "ARM64" },
+
+ // { 10, 0, 18, 0, 18, "AES128CBC:1" },
+ // { 10, 0, 21, 0, 21, "AES192CBC:1" },
{ 10, 0, 24, 0, 24, "AES256CBC:1" },
- { 2, 0, 8, 0, 2, "AES256CBC:2" }
+
+ // { 10, 0, 18, 0, 18, "AES128CTR:1" },
+ // { 10, 0, 21, 0, 21, "AES192CTR:1" },
+ // { 10, 0, 24, 0, 24, "AES256CTR:1" },
+ // { 2, 0, CMPLX(6), 0, CMPLX(1), "AES128CBC:2" },
+ // { 2, 0, CMPLX(7), 0, CMPLX(1), "AES192CBC:2" },
+ { 2, 0, CMPLX(8), 0, CMPLX(1), "AES256CBC:2" },
+
+ // { 2, 0, CMPLX(1), 0, CMPLX(1), "AES128CTR:2" },
+ // { 2, 0, CMPLX(1), 0, CMPLX(1), "AES192CTR:2" },
+ // { 2, 0, CMPLX(1), 0, CMPLX(1), "AES256CTR:2" },
+
+ // { 1, 0, CMPLX(6), 0, CMPLX(1), "AES128CBC:3" },
+ // { 1, 0, CMPLX(7), 0, CMPLX(1), "AES192CBC:3" },
+ { 1, 0, CMPLX(8), 0, CMPLX(1), "AES256CBC:3" }
+
+ // { 1, 0, CMPLX(1), 0, CMPLX(1), "AES128CTR:3" },
+ // { 1, 0, CMPLX(1), 0, CMPLX(1), "AES192CTR:3" },
+ // { 1, 0, CMPLX(1), 0, CMPLX(1), "AES256CTR:3" },
};
struct CBenchHash
@@ -1708,36 +2685,27 @@ struct CBenchHash
const char *Name;
};
-static const CBenchHash g_Hash[] =
-{
- { 1, 1820, 0x8F8FEDAB, "CRC32:1" },
- { 10, 558, 0x8F8FEDAB, "CRC32:4" },
- { 10, 339, 0x8F8FEDAB, "CRC32:8" },
- { 10, 512, 0xDF1C17CC, "CRC64" },
- { 10, 5100, 0x2D79FF2E, "SHA256" },
- { 10, 2340, 0x4C25132B, "SHA1" },
- { 2, 5500, 0xE084E913, "BLAKE2sp" }
-};
+// #define ARM_CRC_MUL 100
+#define ARM_CRC_MUL 1
-struct CTotalBenchRes
-{
- // UInt64 NumIterations1; // for Usage
- UInt64 NumIterations2; // for Rating / RPU
+#define k_Hash_Complex_Mult 256
- UInt64 Rating;
- UInt64 Usage;
- UInt64 RPU;
+static const CBenchHash g_Hash[] =
+{
+ // { 1, 1820, 0x21e207bb, "CRC32:1" },
+ // { 10, 558, 0x21e207bb, "CRC32:4" },
+ { 20, 339, 0x21e207bb, "CRC32:8" } ,
+ { 2, 128 *ARM_CRC_MUL, 0x21e207bb, "CRC32:32" },
+ { 2, 64 *ARM_CRC_MUL, 0x21e207bb, "CRC32:64" },
+ { 10, 512, 0x41b901d1, "CRC64" },
- void Init() { /* NumIterations1 = 0; */ NumIterations2 = 0; Rating = 0; Usage = 0; RPU = 0; }
-
- void SetSum(const CTotalBenchRes &r1, const CTotalBenchRes &r2)
- {
- Rating = (r1.Rating + r2.Rating);
- Usage = (r1.Usage + r2.Usage);
- RPU = (r1.RPU + r2.RPU);
- // NumIterations1 = (r1.NumIterations1 + r2.NumIterations1);
- NumIterations2 = (r1.NumIterations2 + r2.NumIterations2);
- }
+ { 10, 5100, 0x7913ba03, "SHA256:1" },
+ { 2, CMPLX((32 * 4 + 1) * 4 + 4), 0x7913ba03, "SHA256:2" },
+
+ { 10, 2340, 0xff769021, "SHA1:1" },
+ { 2, CMPLX((20 * 6 + 1) * 4 + 4), 0xff769021, "SHA1:2" },
+
+ { 2, 5500, 0x85189d02, "BLAKE2sp" }
};
static void PrintNumber(IBenchPrintCallback &f, UInt64 value, unsigned size)
@@ -1754,9 +2722,11 @@ static void PrintNumber(IBenchPrintCallback &f, UInt64 value, unsigned size)
unsigned len = (unsigned)strlen(s + startPos);
if (size > len)
{
- startPos -= (size - len);
- if (startPos < 0)
+ size -= len;
+ if (startPos < size)
startPos = 0;
+ else
+ startPos -= size;
}
f.Print(s + startPos);
}
@@ -1769,6 +2739,8 @@ static const unsigned kFieldSize_RU = 6;
static const unsigned kFieldSize_Rating = 6;
static const unsigned kFieldSize_EU = 5;
static const unsigned kFieldSize_Effec = 5;
+static const unsigned kFieldSize_CrcSpeed = 8;
+
static const unsigned kFieldSize_TotalSize = 4 + kFieldSize_Speed + kFieldSize_Usage + kFieldSize_RU + kFieldSize_Rating;
static const unsigned kFieldSize_EUAndEffec = 2 + kFieldSize_EU + kFieldSize_Effec;
@@ -1782,7 +2754,10 @@ static void PrintRating(IBenchPrintCallback &f, UInt64 rating, unsigned size)
static void PrintPercents(IBenchPrintCallback &f, UInt64 val, UInt64 divider, unsigned size)
{
- PrintNumber(f, (val * 100 + divider / 2) / divider, size);
+ UInt64 v = 0;
+ if (divider != 0)
+ v = (val * 100 + divider / 2) / divider;
+ PrintNumber(f, v, size);
}
static void PrintChars(IBenchPrintCallback &f, char c, unsigned size)
@@ -1798,9 +2773,14 @@ static void PrintSpaces(IBenchPrintCallback &f, unsigned size)
PrintChars(f, ' ', size);
}
+static void PrintUsage(IBenchPrintCallback &f, UInt64 usage, unsigned size)
+{
+ PrintNumber(f, Benchmark_GetUsage_Percents(usage), size);
+}
+
static void PrintResults(IBenchPrintCallback &f, UInt64 usage, UInt64 rpu, UInt64 rating, bool showFreq, UInt64 cpuFreq)
{
- PrintNumber(f, (usage + 5000) / 10000, kFieldSize_Usage);
+ PrintUsage(f, usage, kFieldSize_Usage);
PrintRating(f, rpu, kFieldSize_RU);
PrintRating(f, rating, kFieldSize_Rating);
if (showFreq)
@@ -1809,15 +2789,39 @@ static void PrintResults(IBenchPrintCallback &f, UInt64 usage, UInt64 rpu, UInt6
PrintSpaces(f, kFieldSize_EUAndEffec);
else
{
- UInt64 ddd = cpuFreq * usage / 100;
- if (ddd == 0)
- ddd = 1;
- PrintPercents(f, (rating * 10000), ddd, kFieldSize_EU);
+ PrintPercents(f, rating, cpuFreq * usage / kBenchmarkUsageMult, kFieldSize_EU);
PrintPercents(f, rating, cpuFreq, kFieldSize_Effec);
}
}
}
+
+void CTotalBenchRes::Generate_From_BenchInfo(const CBenchInfo &info)
+{
+ Speed = info.GetUnpackSizeSpeed();
+ Usage = info.GetUsage();
+ RPU = info.GetRatingPerUsage(Rating);
+}
+
+void CTotalBenchRes::Mult_For_Weight(unsigned weight)
+{
+ NumIterations2 *= weight;
+ RPU *= weight;
+ Rating *= weight;
+ Usage *= weight;
+ Speed *= weight;
+}
+
+void CTotalBenchRes::Update_With_Res(const CTotalBenchRes &r)
+{
+ Rating += r.Rating;
+ Usage += r.Usage;
+ RPU += r.RPU;
+ Speed += r.Speed;
+ // NumIterations1 = (r1.NumIterations1 + r2.NumIterations1);
+ NumIterations2 += r.NumIterations2;
+}
+
static void PrintResults(IBenchPrintCallback *f,
const CBenchInfo &info,
unsigned weight,
@@ -1825,39 +2829,126 @@ static void PrintResults(IBenchPrintCallback *f,
bool showFreq, UInt64 cpuFreq,
CTotalBenchRes *res)
{
- UInt64 speed = info.GetSpeed(info.UnpackSize * info.NumIterations);
+ CTotalBenchRes t;
+ t.Rating = rating;
+ t.NumIterations2 = 1;
+ t.Generate_From_BenchInfo(info);
+
if (f)
{
- if (speed != 0)
- PrintNumber(*f, speed / 1024, kFieldSize_Speed);
+ if (t.Speed != 0)
+ PrintNumber(*f, t.Speed / 1024, kFieldSize_Speed);
else
PrintSpaces(*f, 1 + kFieldSize_Speed);
}
- UInt64 usage = info.GetUsage();
- UInt64 rpu = info.GetRatingPerUsage(rating);
if (f)
{
- PrintResults(*f, usage, rpu, rating, showFreq, cpuFreq);
+ PrintResults(*f, t.Usage, t.RPU, rating, showFreq, cpuFreq);
}
if (res)
{
// res->NumIterations1++;
- res->NumIterations2 += weight;
- res->RPU += (rpu * weight);
- res->Rating += (rating * weight);
- res->Usage += (usage * weight);
+ t.Mult_For_Weight(weight);
+ res->Update_With_Res(t);
}
}
-static void PrintTotals(IBenchPrintCallback &f, bool showFreq, UInt64 cpuFreq, const CTotalBenchRes &res)
+static void PrintTotals(IBenchPrintCallback &f,
+ bool showFreq, UInt64 cpuFreq, bool showSpeed, const CTotalBenchRes &res)
{
- PrintSpaces(f, 1 + kFieldSize_Speed);
+ const UInt64 numIterations2 = res.NumIterations2 ? res.NumIterations2 : 1;
+ const UInt64 speed = res.Speed / numIterations2;
+ if (showSpeed && speed != 0)
+ PrintNumber(f, speed / 1024, kFieldSize_Speed);
+ else
+ PrintSpaces(f, 1 + kFieldSize_Speed);
+
+ // PrintSpaces(f, 1 + kFieldSize_Speed);
// UInt64 numIterations1 = res.NumIterations1; if (numIterations1 == 0) numIterations1 = 1;
- UInt64 numIterations2 = res.NumIterations2; if (numIterations2 == 0) numIterations2 = 1;
PrintResults(f, res.Usage / numIterations2, res.RPU / numIterations2, res.Rating / numIterations2, showFreq, cpuFreq);
}
+
+static void PrintHex(AString &s, UInt64 v)
+{
+ char temp[32];
+ ConvertUInt64ToHex(v, temp);
+ s += temp;
+}
+
+AString GetProcessThreadsInfo(const NSystem::CProcessAffinity &ti)
+{
+ AString s;
+ // s.Add_UInt32(ti.numProcessThreads);
+ unsigned numSysThreads = ti.GetNumSystemThreads();
+ if (ti.GetNumProcessThreads() != numSysThreads)
+ {
+ // if (ti.numProcessThreads != ti.numSysThreads)
+ {
+ s += " / ";
+ s.Add_UInt32(numSysThreads);
+ }
+ s += " : ";
+ #ifdef _WIN32
+ PrintHex(s, ti.processAffinityMask);
+ s += " / ";
+ PrintHex(s, ti.systemAffinityMask);
+ #else
+ unsigned i = (numSysThreads + 3) & ~(unsigned)3;
+ if (i == 0)
+ i = 4;
+ for (; i >= 4; )
+ {
+ i -= 4;
+ unsigned val = 0;
+ for (unsigned k = 0; k < 4; k++)
+ {
+ const unsigned bit = (ti.IsCpuSet(i + k) ? 1 : 0);
+ val += (bit << k);
+ }
+ PrintHex(s, val);
+ }
+ #endif
+ }
+ return s;
+}
+
+
+#ifdef Z7_LARGE_PAGES
+
+#ifdef _WIN32
+extern bool g_LargePagesMode;
+extern "C"
+{
+ extern SIZE_T g_LargePageSize;
+}
+#endif
+
+void Add_LargePages_String(AString &s)
+{
+ #ifdef _WIN32
+ if (g_LargePagesMode || g_LargePageSize != 0)
+ {
+ s.Add_OptSpaced("(LP-");
+ PrintSize_KMGT_Or_Hex(s, g_LargePageSize);
+ #ifdef MY_CPU_X86_OR_AMD64
+ if (CPU_IsSupported_PageGB())
+ s += "-1G";
+ #endif
+ if (!g_LargePagesMode)
+ s += "-NA";
+ s += ")";
+ }
+ #else
+ s += "";
+ #endif
+}
+
+#endif
+
+
+
static void PrintRequirements(IBenchPrintCallback &f, const char *sizeString,
bool size_Defined, UInt64 size, const char *threadsString, UInt32 numThreads)
{
@@ -1867,36 +2958,51 @@ static void PrintRequirements(IBenchPrintCallback &f, const char *sizeString,
PrintNumber(f, (size >> 20), 6);
else
f.Print(" ?");
- f.Print(" MB, # ");
+ f.Print(" MB");
+
+ #ifdef Z7_LARGE_PAGES
+ {
+ AString s;
+ Add_LargePages_String(s);
+ f.Print(s);
+ }
+ #endif
+
+ f.Print(", # ");
f.Print(threadsString);
PrintNumber(f, numThreads, 3);
- f.NewLine();
}
-struct CBenchCallbackToPrint: public IBenchCallback
-{
- CBenchProps BenchProps;
- CTotalBenchRes EncodeRes;
- CTotalBenchRes DecodeRes;
- IBenchPrintCallback *_file;
- UInt32 DictSize;
- bool Use2Columns;
- unsigned NameFieldSize;
+struct CBenchCallbackToPrint Z7_final: public IBenchCallback
+{
+ bool NeedPrint;
+ bool Use2Columns;
bool ShowFreq;
- UInt64 CpuFreq;
+ unsigned NameFieldSize;
unsigned EncodeWeight;
unsigned DecodeWeight;
+ UInt64 CpuFreq;
+ UInt64 DictSize;
+
+ IBenchPrintCallback *_file;
+ CBenchProps BenchProps;
+ CTotalBenchRes EncodeRes;
+ CTotalBenchRes DecodeRes;
+
+ CBenchInfo BenchInfo_Results[2];
+
CBenchCallbackToPrint():
+ NeedPrint(true),
Use2Columns(false),
- NameFieldSize(0),
ShowFreq(false),
- CpuFreq(0),
+ NameFieldSize(0),
EncodeWeight(1),
- DecodeWeight(1)
+ DecodeWeight(1),
+ CpuFreq(0)
{}
void Init() { EncodeRes.Init(); DecodeRes.Init(); }
@@ -1904,8 +3010,8 @@ struct CBenchCallbackToPrint: public IBenchCallback
void NewLine();
HRESULT SetFreq(bool showFreq, UInt64 cpuFreq);
- HRESULT SetEncodeResult(const CBenchInfo &info, bool final);
- HRESULT SetDecodeResult(const CBenchInfo &info, bool final);
+ HRESULT SetEncodeResult(const CBenchInfo &info, bool final) Z7_override;
+ HRESULT SetDecodeResult(const CBenchInfo &info, bool final) Z7_override;
};
HRESULT CBenchCallbackToPrint::SetFreq(bool showFreq, UInt64 cpuFreq)
@@ -1917,10 +3023,13 @@ HRESULT CBenchCallbackToPrint::SetFreq(bool showFreq, UInt64 cpuFreq)
HRESULT CBenchCallbackToPrint::SetEncodeResult(const CBenchInfo &info, bool final)
{
- RINOK(_file->CheckBreak());
+ RINOK(_file->CheckBreak())
+ if (final)
+ BenchInfo_Results[0] = info;
if (final)
+ if (NeedPrint)
{
- UInt64 rating = BenchProps.GetCompressRating(DictSize, info.GlobalTime, info.GlobalFreq, info.UnpackSize * info.NumIterations);
+ const UInt64 rating = BenchProps.GetRating_Enc(DictSize, info.GlobalTime, info.GlobalFreq, info.UnpackSize * info.NumIterations);
PrintResults(_file, info,
EncodeWeight, rating,
ShowFreq, CpuFreq, &EncodeRes);
@@ -1930,14 +3039,17 @@ HRESULT CBenchCallbackToPrint::SetEncodeResult(const CBenchInfo &info, bool fina
return S_OK;
}
-static const char *kSep = " | ";
+static const char * const kSep = " | ";
HRESULT CBenchCallbackToPrint::SetDecodeResult(const CBenchInfo &info, bool final)
{
- RINOK(_file->CheckBreak());
+ RINOK(_file->CheckBreak())
if (final)
+ BenchInfo_Results[1] = info;
+ if (final)
+ if (NeedPrint)
{
- UInt64 rating = BenchProps.GetDecompressRating(info.GlobalTime, info.GlobalFreq, info.UnpackSize, info.PackSize, info.NumIterations);
+ const UInt64 rating = BenchProps.GetRating_Dec(info.GlobalTime, info.GlobalFreq, info.UnpackSize, info.PackSize, info.NumIterations);
if (Use2Columns)
_file->Print(kSep);
else
@@ -1963,35 +3075,58 @@ void CBenchCallbackToPrint::NewLine()
_file->NewLine();
}
-void PrintLeft(IBenchPrintCallback &f, const char *s, unsigned size)
+static void PrintLeft(IBenchPrintCallback &f, const char *s, unsigned size)
{
f.Print(s);
- int numSpaces = size - MyStringLen(s);
+ int numSpaces = (int)size - (int)MyStringLen(s);
if (numSpaces > 0)
- PrintSpaces(f, numSpaces);
+ PrintSpaces(f, (unsigned)numSpaces);
}
-void PrintRight(IBenchPrintCallback &f, const char *s, unsigned size)
+static void PrintRight(IBenchPrintCallback &f, const char *s, unsigned size)
{
- int numSpaces = size - MyStringLen(s);
+ int numSpaces = (int)size - (int)MyStringLen(s);
if (numSpaces > 0)
- PrintSpaces(f, numSpaces);
+ PrintSpaces(f, (unsigned)numSpaces);
f.Print(s);
}
+
+static bool DoesWildcardMatchName_NoCase(const AString &mask, const char *name)
+{
+ UString wildc = GetUnicodeString(mask);
+ UString bname = GetUnicodeString(name);
+ wildc.MakeLower_Ascii();
+ bname.MakeLower_Ascii();
+ return DoesWildcardMatchName(wildc, bname);
+}
+
+
static HRESULT TotalBench(
DECL_EXTERNAL_CODECS_LOC_VARS
+ const COneMethodInfo &methodMask,
UInt64 complexInCommands,
+ #ifndef Z7_ST
UInt32 numThreads,
+ const CAffinityMode *affinityMode,
+ #endif
bool forceUnpackSize,
size_t unpackSize,
const Byte *fileData,
IBenchPrintCallback *printCallback, CBenchCallbackToPrint *callback)
{
- for (unsigned i = 0; i < ARRAY_SIZE(g_Bench); i++)
+ for (unsigned i = 0; i < Z7_ARRAY_SIZE(g_Bench); i++)
{
const CBenchMethod &bench = g_Bench[i];
+ if (!DoesWildcardMatchName_NoCase(methodMask.MethodName, bench.Name))
+ continue;
PrintLeft(*callback->_file, bench.Name, kFieldSize_Name);
+ {
+ unsigned keySize = 32;
+ if (IsString1PrefixedByString2(bench.Name, "AES128")) keySize = 16;
+ else if (IsString1PrefixedByString2(bench.Name, "AES192")) keySize = 24;
+ callback->BenchProps.KeySize = keySize;
+ }
callback->BenchProps.DecComplexUnc = bench.DecComplexUnc;
callback->BenchProps.DecComplexCompr = bench.DecComplexCompr;
callback->BenchProps.EncComplex = bench.EncComplex;
@@ -1999,7 +3134,7 @@ static HRESULT TotalBench(
COneMethodInfo method;
NCOM::CPropVariant propVariant;
propVariant = bench.Name;
- RINOK(method.ParseMethodFromPROPVARIANT(UString(), propVariant));
+ RINOK(method.ParseMethodFromPROPVARIANT(UString(), propVariant))
size_t unpackSize2 = unpackSize;
if (!forceUnpackSize && bench.DictBits == 0)
@@ -2008,10 +3143,13 @@ static HRESULT TotalBench(
callback->EncodeWeight = bench.Weight;
callback->DecodeWeight = bench.Weight;
- HRESULT res = MethodBench(
+ const HRESULT res = MethodBench(
EXTERNAL_CODECS_LOC_VARS
complexInCommands,
- false, numThreads, method,
+ #ifndef Z7_ST
+ false, numThreads, affinityMode,
+ #endif
+ method,
unpackSize2, fileData,
bench.DictBits,
printCallback, callback, &callback->BenchProps);
@@ -2025,7 +3163,7 @@ static HRESULT TotalBench(
}
else
{
- RINOK(res);
+ RINOK(res)
}
callback->NewLine();
@@ -2034,38 +3172,67 @@ static HRESULT TotalBench(
}
-static HRESULT FreqBench(
- UInt64 complexInCommands,
- UInt32 numThreads,
- IBenchPrintCallback *_file,
- bool showFreq,
- UInt64 specifiedFreq,
- UInt64 &cpuFreq,
- UInt32 &res)
+struct CFreqBench
+{
+ // in:
+ UInt64 complexInCommands;
+ UInt32 numThreads;
+ bool showFreq;
+ UInt64 specifiedFreq;
+
+ // out:
+ UInt64 CpuFreqRes;
+ UInt64 UsageRes;
+ UInt32 res;
+
+ CFreqBench()
+ {}
+
+ HRESULT FreqBench(IBenchPrintCallback *_file
+ #ifndef Z7_ST
+ , const CAffinityMode *affinityMode
+ #endif
+ );
+};
+
+
+HRESULT CFreqBench::FreqBench(IBenchPrintCallback *_file
+ #ifndef Z7_ST
+ , const CAffinityMode *affinityMode
+ #endif
+ )
{
res = 0;
- cpuFreq = 0;
+ CpuFreqRes = 0;
+ UsageRes = 0;
- UInt32 bufferSize = 1 << 20;
- UInt32 complexity = kNumFreqCommands;
if (numThreads == 0)
numThreads = 1;
- #ifdef _7ZIP_ST
+ #ifdef Z7_ST
numThreads = 1;
#endif
- UInt32 bsize = (bufferSize == 0 ? 1 : bufferSize);
- UInt64 numIterations = complexInCommands / complexity / bsize;
- if (numIterations == 0)
+ const UInt32 complexity = kNumFreqCommands;
+ UInt64 numIterations = complexInCommands / complexity;
+ UInt32 numIterations2 = 1 << 30;
+ if (numIterations > numIterations2)
+ numIterations /= numIterations2;
+ else
+ {
+ numIterations2 = (UInt32)numIterations;
numIterations = 1;
+ }
CBenchInfoCalc progressInfoSpec;
- #ifndef _7ZIP_ST
- CFreqThreads threads;
- if (numThreads > 1)
+ #ifndef Z7_ST
+
+ bool mtMode = (numThreads > 1) || affinityMode->NeedAffinity();
+
+ if (mtMode)
{
+ CFreqThreads threads;
threads.Items = new CFreqInfo[numThreads];
UInt32 i;
for (i = 0; i < numThreads; i++)
@@ -2074,19 +3241,25 @@ static HRESULT FreqBench(
info.Callback = _file;
info.CallbackRes = S_OK;
info.NumIterations = numIterations;
- info.Size = bufferSize;
+ info.Size = numIterations2;
}
progressInfoSpec.SetStartTime();
for (i = 0; i < numThreads; i++)
{
+ // Sleep(10);
CFreqInfo &info = threads.Items[i];
- RINOK(info.Thread.Create(FreqThreadFunction, &info));
- threads.NumThreads++;
+ WRes wres = affinityMode->CreateThread_WithAffinity(info.Thread, FreqThreadFunction, &info, i);
+ if (info.Thread.IsCreated())
+ threads.NumThreads++;
+ if (wres != 0)
+ return HRESULT_FROM_WIN32(wres);
}
- threads.WaitAll();
+ WRes wres = threads.WaitAll();
+ if (wres != 0)
+ return HRESULT_FROM_WIN32(wres);
for (i = 0; i < numThreads; i++)
{
- RINOK(threads.Items[i].CallbackRes);
+ RINOK(threads.Items[i].CallbackRes)
}
}
else
@@ -2096,11 +3269,20 @@ static HRESULT FreqBench(
UInt32 sum = g_BenchCpuFreqTemp;
for (UInt64 k = numIterations; k > 0; k--)
{
- RINOK(_file->CheckBreak());
- sum = CountCpuFreq(sum, bufferSize, g_BenchCpuFreqTemp);
+ sum = CountCpuFreq(sum, numIterations2, g_BenchCpuFreqTemp);
+ if (_file)
+ {
+ RINOK(_file->CheckBreak())
+ }
}
res += sum;
}
+
+ if (res == 0x12345678)
+ if (_file)
+ {
+ RINOK(_file->CheckBreak())
+ }
CBenchInfo info;
progressInfoSpec.SetFinishTime(info);
@@ -2109,18 +3291,18 @@ static HRESULT FreqBench(
info.PackSize = 0;
info.NumIterations = 1;
+ const UInt64 numCommands = (UInt64)numIterations * numIterations2 * numThreads * complexity;
+ const UInt64 rating = info.GetSpeed(numCommands);
+ CpuFreqRes = rating / numThreads;
+ UsageRes = info.GetUsage();
+
if (_file)
{
- {
- UInt64 numCommands = (UInt64)numIterations * bufferSize * numThreads * complexity;
- UInt64 rating = info.GetSpeed(numCommands);
- cpuFreq = rating / numThreads;
- PrintResults(_file, info,
+ PrintResults(_file, info,
0, // weight
rating,
- showFreq, showFreq ? (specifiedFreq != 0 ? specifiedFreq : cpuFreq) : 0, NULL);
- }
- RINOK(_file->CheckBreak());
+ showFreq, showFreq ? (specifiedFreq != 0 ? specifiedFreq : CpuFreqRes) : 0, NULL);
+ RINOK(_file->CheckBreak())
}
return S_OK;
@@ -2131,23 +3313,32 @@ static HRESULT FreqBench(
static HRESULT CrcBench(
DECL_EXTERNAL_CODECS_LOC_VARS
UInt64 complexInCommands,
- UInt32 numThreads, UInt32 bufferSize,
+ UInt32 numThreads,
+ const size_t bufferSize,
+ const Byte *fileData,
+
UInt64 &speed,
+ UInt64 &usage,
+
UInt32 complexity, unsigned benchWeight,
const UInt32 *checkSum,
const COneMethodInfo &method,
IBenchPrintCallback *_file,
+ #ifndef Z7_ST
+ const CAffinityMode *affinityMode,
+ #endif
+ bool showRating,
CTotalBenchRes *encodeRes,
bool showFreq, UInt64 cpuFreq)
{
if (numThreads == 0)
numThreads = 1;
- #ifdef _7ZIP_ST
+ #ifdef Z7_ST
numThreads = 1;
#endif
- AString methodName = method.MethodName;
+ const AString &methodName = method.MethodName;
// methodName.RemoveChar(L'-');
CMethodId hashID;
if (!FindHashMethod(
@@ -2155,98 +3346,131 @@ static HRESULT CrcBench(
methodName, hashID))
return E_NOTIMPL;
- CBenchBuffer buffer;
- size_t totalSize = (size_t)bufferSize * numThreads;
- if (totalSize / numThreads != bufferSize)
- return E_OUTOFMEMORY;
- if (!buffer.Alloc(totalSize))
- return E_OUTOFMEMORY;
+ /*
+ // if will generate random data in each thread, instead of global data
+ CMidAlignedBuffer buffer;
+ if (!fileData)
+ {
+ ALLOC_WITH_HRESULT(&buffer, bufferSize)
+ RandGen(buffer, bufferSize);
+ fileData = buffer;
+ }
+ */
- Byte *buf = buffer.Buffer;
- CBaseRandomGenerator RG;
- UInt32 bsize = (bufferSize == 0 ? 1 : bufferSize);
- UInt64 numIterations = complexInCommands * 256 / complexity / bsize;
+ const size_t bsize = (bufferSize == 0 ? 1 : bufferSize);
+ UInt64 numIterations = complexInCommands * k_Hash_Complex_Mult / complexity / bsize;
if (numIterations == 0)
numIterations = 1;
CBenchInfoCalc progressInfoSpec;
+ CBenchInfo info;
+
+ #ifndef Z7_ST
+ bool mtEncMode = (numThreads > 1) || affinityMode->NeedAffinity();
- #ifndef _7ZIP_ST
- CCrcThreads threads;
- if (numThreads > 1)
+ if (mtEncMode)
{
+ CCrcThreads threads;
threads.Items = new CCrcInfo[numThreads];
-
+ {
+ WRes wres = threads.Common.StartEvent.Create();
+ if (wres != 0)
+ return HRESULT_FROM_WIN32(wres);
+ threads.NeedClose = true;
+ }
+
UInt32 i;
for (i = 0; i < numThreads; i++)
{
- CCrcInfo &info = threads.Items[i];
+ CCrcInfo &ci = threads.Items[i];
AString name;
- RINOK(CreateHasher(EXTERNAL_CODECS_LOC_VARS hashID, name, info.Hasher));
- if (!info.Hasher)
+ RINOK(CreateHasher(EXTERNAL_CODECS_LOC_VARS hashID, name, ci.Hasher))
+ if (!ci.Hasher)
return E_NOTIMPL;
CMyComPtr<ICompressSetCoderProperties> scp;
- info.Hasher.QueryInterface(IID_ICompressSetCoderProperties, &scp);
+ ci.Hasher.QueryInterface(IID_ICompressSetCoderProperties, &scp);
if (scp)
{
- UInt64 reduceSize = 1;
- RINOK(method.SetCoderProps(scp, &reduceSize));
+ RINOK(method.SetCoderProps(scp))
}
- Byte *data = buf + (size_t)bufferSize * i;
- info.Callback = _file;
- info.Data = data;
- info.NumIterations = numIterations;
- info.Size = bufferSize;
- /* info.Crc = */ RandGenCrc(data, bufferSize, RG);
- info.CheckSumDefined = false;
+ ci.Callback = _file;
+ ci.Data = fileData;
+ ci.NumIterations = numIterations;
+ ci.Size = bufferSize;
+ ci.CheckSumDefined = false;
if (checkSum)
{
- info.CheckSum = *checkSum;
- info.CheckSumDefined = (checkSum && (i == 0));
+ ci.CheckSum = *checkSum;
+ ci.CheckSumDefined = true;
}
#ifdef USE_ALLOCA
- info.AllocaSize = (i * 16 * 21) & 0x7FF;
+ ci.AllocaSize = (i * 16 * 21) & 0x7FF;
#endif
}
- progressInfoSpec.SetStartTime();
+ for (i = 0; i < numThreads; i++)
+ {
+ CCrcInfo &ci = threads.Items[i];
+ ci.ThreadIndex = i;
+ ci.Common = &threads.Common;
+ ci.AffinityMode = *affinityMode;
+ HRESULT hres = ci.CreateThread();
+ if (ci.Thread.IsCreated())
+ threads.NumThreads++;
+ if (hres != 0)
+ return hres;
+ }
for (i = 0; i < numThreads; i++)
{
- CCrcInfo &info = threads.Items[i];
- RINOK(info.Thread.Create(CrcThreadFunction, &info));
- threads.NumThreads++;
+ CCrcInfo &ci = threads.Items[i];
+ WRes wres = ci.ReadyEvent.Lock();
+ if (wres != 0)
+ return HRESULT_FROM_WIN32(wres);
+ RINOK(ci.Res)
}
- threads.WaitAll();
+
+ progressInfoSpec.SetStartTime();
+
+ WRes wres = threads.StartAndWait();
+ if (wres != 0)
+ return HRESULT_FROM_WIN32(wres);
+
+ progressInfoSpec.SetFinishTime(info);
+
for (i = 0; i < numThreads; i++)
{
- RINOK(threads.Items[i].Res);
+ RINOK(threads.Items[i].Res)
+ if (i != 0)
+ if (threads.Items[i].CheckSum_Res !=
+ threads.Items[i - 1].CheckSum_Res)
+ return S_FALSE;
}
}
else
#endif
{
- /* UInt32 crc = */ RandGenCrc(buf, bufferSize, RG);
- progressInfoSpec.SetStartTime();
CMyComPtr<IHasher> hasher;
AString name;
- RINOK(CreateHasher(EXTERNAL_CODECS_LOC_VARS hashID, name, hasher));
+ RINOK(CreateHasher(EXTERNAL_CODECS_LOC_VARS hashID, name, hasher))
if (!hasher)
return E_NOTIMPL;
CMyComPtr<ICompressSetCoderProperties> scp;
hasher.QueryInterface(IID_ICompressSetCoderProperties, &scp);
if (scp)
{
- UInt64 reduceSize = 1;
- RINOK(method.SetCoderProps(scp, &reduceSize));
+ RINOK(method.SetCoderProps(scp))
}
- RINOK(CrcBig(buf, bufferSize, numIterations, checkSum, hasher, _file));
+ CCrcInfo_Base crcib;
+ crcib.CreateLocalBuf = false;
+ RINOK(crcib.Generate(fileData, bufferSize))
+ progressInfoSpec.SetStartTime();
+ RINOK(crcib.CrcProcess(numIterations, checkSum, hasher, _file))
+ progressInfoSpec.SetFinishTime(info);
}
- CBenchInfo info;
- progressInfoSpec.SetFinishTime(info);
UInt64 unpSize = numIterations * bufferSize;
UInt64 unpSizeThreads = unpSize * numThreads;
@@ -2256,32 +3480,47 @@ static HRESULT CrcBench(
if (_file)
{
+ if (showRating)
{
- UInt64 numCommands = unpSizeThreads * complexity / 256;
- UInt64 rating = info.GetSpeed(numCommands);
+ UInt64 unpSizeThreads2 = unpSizeThreads;
+ if (unpSizeThreads2 == 0)
+ unpSizeThreads2 = numIterations * 1 * numThreads;
+ const UInt64 numCommands = unpSizeThreads2 * complexity / 256;
+ const UInt64 rating = info.GetSpeed(numCommands);
PrintResults(_file, info,
benchWeight, rating,
showFreq, cpuFreq, encodeRes);
}
- RINOK(_file->CheckBreak());
+ RINOK(_file->CheckBreak())
}
speed = info.GetSpeed(unpSizeThreads);
+ usage = info.GetUsage();
return S_OK;
}
+
+
static HRESULT TotalBench_Hash(
DECL_EXTERNAL_CODECS_LOC_VARS
+ const COneMethodInfo &methodMask,
UInt64 complexInCommands,
- UInt32 numThreads, UInt32 bufSize,
+ UInt32 numThreads,
+ size_t bufSize,
+ const Byte *fileData,
IBenchPrintCallback *printCallback, CBenchCallbackToPrint *callback,
+ #ifndef Z7_ST
+ const CAffinityMode *affinityMode,
+ #endif
CTotalBenchRes *encodeRes,
bool showFreq, UInt64 cpuFreq)
{
- for (unsigned i = 0; i < ARRAY_SIZE(g_Hash); i++)
+ for (unsigned i = 0; i < Z7_ARRAY_SIZE(g_Hash); i++)
{
const CBenchHash &bench = g_Hash[i];
+ if (!DoesWildcardMatchName_NoCase(methodMask.MethodName, bench.Name))
+ continue;
PrintLeft(*callback->_file, bench.Name, kFieldSize_Name);
// callback->BenchProps.DecComplexUnc = bench.DecComplexUnc;
// callback->BenchProps.DecComplexCompr = bench.DecComplexCompr;
@@ -2290,24 +3529,31 @@ static HRESULT TotalBench_Hash(
COneMethodInfo method;
NCOM::CPropVariant propVariant;
propVariant = bench.Name;
- RINOK(method.ParseMethodFromPROPVARIANT(UString(), propVariant));
+ RINOK(method.ParseMethodFromPROPVARIANT(UString(), propVariant))
- UInt64 speed;
- HRESULT res = CrcBench(
+ UInt64 speed, usage;
+
+ const HRESULT res = CrcBench(
EXTERNAL_CODECS_LOC_VARS
complexInCommands,
- numThreads, bufSize,
- speed,
+ numThreads, bufSize, fileData,
+ speed, usage,
bench.Complex, bench.Weight,
- &bench.CheckSum, method,
- printCallback, encodeRes, showFreq, cpuFreq);
+ (!fileData && bufSize == (1 << kNumHashDictBits)) ? &bench.CheckSum : NULL,
+ method,
+ printCallback,
+ #ifndef Z7_ST
+ affinityMode,
+ #endif
+ true, // showRating
+ encodeRes, showFreq, cpuFreq);
if (res == E_NOTIMPL)
{
// callback->Print(" ---");
}
else
{
- RINOK(res);
+ RINOK(res)
}
callback->NewLine();
}
@@ -2317,7 +3563,8 @@ static HRESULT TotalBench_Hash(
struct CTempValues
{
UInt64 *Values;
- CTempValues(UInt32 num) { Values = new UInt64[num]; }
+ CTempValues(): Values(NULL) {}
+ void Alloc(UInt32 num) { Values = new UInt64[num]; }
~CTempValues() { delete []Values; }
};
@@ -2333,110 +3580,41 @@ static void ParseNumberString(const UString &s, NCOM::CPropVariant &prop)
prop = result;
}
-static UInt32 GetNumThreadsNext(unsigned i, UInt32 numThreads)
-{
- if (i < 2)
- return i + 1;
- i -= 1;
- UInt32 num = (UInt32)(2 + (i & 1)) << (i >> 1);
- return (num <= numThreads) ? num : numThreads;
-}
static bool AreSameMethodNames(const char *fullName, const char *shortName)
{
- for (;;)
- {
- char c2 = *shortName++;
- if (c2 == 0)
- return true;
- char c1 = *fullName++;
- if (MyCharLower_Ascii(c1) != MyCharLower_Ascii(c2))
- return false;
- }
+ return StringsAreEqualNoCase_Ascii(fullName, shortName);
}
-#ifdef MY_CPU_X86_OR_AMD64
-static void PrintCpuChars(AString &s, UInt32 v)
-{
- for (int j = 0; j < 4; j++)
- {
- Byte b = (Byte)(v & 0xFF);
- v >>= 8;
- if (b == 0)
- break;
- s += (char)b;
- }
-}
-static void x86cpuid_to_String(const Cx86cpuid &c, AString &s)
+static void Print_Usage_and_Threads(IBenchPrintCallback &f, UInt64 usage, UInt32 threads)
{
- s.Empty();
-
- UInt32 maxFunc2 = 0;
- UInt32 t[3];
-
- MyCPUID(0x80000000, &maxFunc2, &t[0], &t[1], &t[2]);
-
- bool fullNameIsAvail = (maxFunc2 >= 0x80000004);
-
- if (!fullNameIsAvail)
- {
- for (int i = 0; i < 3; i++)
- PrintCpuChars(s, c.vendor[i]);
- }
- else
- {
- for (int i = 0; i < 3; i++)
- {
- UInt32 d[4] = { 0 };
- MyCPUID(0x80000002 + i, &d[0], &d[1], &d[2], &d[3]);
- for (int j = 0; j < 4; j++)
- PrintCpuChars(s, d[j]);
- }
- }
-
- s.Add_Space_if_NotEmpty();
- {
- char temp[32];
- ConvertUInt32ToHex(c.ver, temp);
- s += '(';
- s += temp;
- s += ')';
- }
+ PrintRequirements(f, "usage:", true, usage, "Benchmark threads: ", threads);
}
-#endif
-
-void GetCpuName(AString &s)
+static void Print_Delimiter(IBenchPrintCallback &f)
{
- s.Empty();
+ f.Print(" |");
+}
- #ifdef MY_CPU_X86_OR_AMD64
- {
- Cx86cpuid cpuid;
- if (x86cpuid_CheckAndRead(&cpuid))
- {
- x86cpuid_to_String(cpuid, s);
- return;
- }
- #ifdef MY_CPU_AMD64
- s = "x64";
- #else
- s = "x86";
- #endif
- }
- #else
-
- #ifdef MY_CPU_LE
- s = "LE";
- #elif defined(MY_CPU_BE)
- s = "BE";
- #endif
+static void Print_Pow(IBenchPrintCallback &f, unsigned pow)
+{
+ char s[16];
+ ConvertUInt32ToString(pow, s);
+ unsigned pos = MyStringLen(s);
+ s[pos++] = ':';
+ s[pos] = 0;
+ PrintLeft(f, s, kFieldSize_SmallName); // 4
+}
- #endif
+static void Bench_BW_Print_Usage_Speed(IBenchPrintCallback &f,
+ UInt64 usage, UInt64 speed)
+{
+ PrintUsage(f, usage, kFieldSize_Usage);
+ PrintNumber(f, speed / 1000000, kFieldSize_CrcSpeed);
}
@@ -2446,38 +3624,87 @@ HRESULT Bench(
IBenchCallback *benchCallback,
const CObjectVector<CProperty> &props,
UInt32 numIterations,
- bool multiDict)
+ bool multiDict,
+ IBenchFreqCallback *freqCallback)
{
if (!CrcInternalTest())
- return S_FALSE;
+ return E_FAIL;
UInt32 numCPUs = 1;
UInt64 ramSize = (UInt64)(sizeof(size_t)) << 29;
- #ifndef _7ZIP_ST
- numCPUs = NSystem::GetNumberOfProcessors();
+ NSystem::CProcessAffinity threadsInfo;
+ threadsInfo.InitST();
+
+ #ifndef Z7_ST
+
+ if (threadsInfo.Get() && threadsInfo.GetNumProcessThreads() != 0)
+ numCPUs = threadsInfo.GetNumProcessThreads();
+ else
+ numCPUs = NSystem::GetNumberOfProcessors();
+
#endif
+
+ // numCPUs = 24;
+ /*
+ {
+ DWORD_PTR mask = (1 << 0);
+ DWORD_PTR old = SetThreadAffinityMask(GetCurrentThread(), mask);
+ old = old;
+ DWORD_PTR old2 = SetThreadAffinityMask(GetCurrentThread(), mask);
+ old2 = old2;
+ return 0;
+ }
+ */
bool ramSize_Defined = NSystem::GetRamSize(ramSize);
UInt32 numThreadsSpecified = numCPUs;
-
- UInt32 testTime = kComplexInSeconds;
-
+ bool needSetComplexity = false;
+ UInt32 testTimeMs = kComplexInMs;
+ UInt32 startDicLog = 22;
+ bool startDicLog_Defined = false;
UInt64 specifiedFreq = 0;
-
bool multiThreadTests = false;
+ UInt64 complexInCommands = kComplexInCommands;
+ UInt32 numThreads_Start = 1;
+
+ #ifndef Z7_ST
+ CAffinityMode affinityMode;
+ #endif
+
COneMethodInfo method;
- CBenchBuffer fileDataBuffer;
+ CMidAlignedBuffer fileDataBuffer;
+ bool use_fileData = false;
+ bool isFixedDict = false;
{
unsigned i;
+
+ if (printCallback)
+ {
+ for (i = 0; i < props.Size(); i++)
+ {
+ const CProperty &property = props[i];
+ printCallback->Print(" ");
+ printCallback->Print(GetAnsiString(property.Name));
+ if (!property.Value.IsEmpty())
+ {
+ printCallback->Print("=");
+ printCallback->Print(GetAnsiString(property.Value));
+ }
+ }
+ if (!props.IsEmpty())
+ printCallback->NewLine();
+ }
+
+
for (i = 0; i < props.Size(); i++)
{
const CProperty &property = props[i];
- UString name = property.Name;
+ UString name (property.Name);
name.MakeLower_Ascii();
if (name.IsEqualTo("file"))
@@ -2485,36 +3712,38 @@ HRESULT Bench(
if (property.Value.IsEmpty())
return E_INVALIDARG;
- #ifdef USE_WIN_FILE
-
NFile::NIO::CInFile file;
if (!file.Open(us2fs(property.Value)))
- return E_INVALIDARG;
- UInt64 len;
- if (!file.GetLength(len))
- return E_FAIL;
- if (len >= ((UInt32)1 << 31) || len == 0)
- return E_INVALIDARG;
- if (!fileDataBuffer.Alloc((size_t)len))
- return E_OUTOFMEMORY;
- UInt32 processedSize;
- file.Read(fileDataBuffer.Buffer, (UInt32)len, processedSize);
- if (processedSize != len)
- return E_FAIL;
- if (printCallback)
+ return GetLastError_noZero_HRESULT();
+ size_t len;
{
- printCallback->Print("file size =");
- // printCallback->Print(GetOemString(property.Value));
- PrintNumber(*printCallback, len, 0);
- printCallback->NewLine();
+ UInt64 len64;
+ if (!file.GetLength(len64))
+ return GetLastError_noZero_HRESULT();
+ if (printCallback)
+ {
+ printCallback->Print("file size =");
+ PrintNumber(*printCallback, len64, 0);
+ printCallback->NewLine();
+ }
+ len = (size_t)len64;
+ if (len != len64)
+ return E_INVALIDARG;
}
- continue;
- #else
+ // (len == 0) is allowed. Also it's allowed if Alloc(0) returns NULL here
- return E_NOTIMPL;
+ ALLOC_WITH_HRESULT(&fileDataBuffer, len)
+ use_fileData = true;
- #endif
+ {
+ size_t processed;
+ if (!file.ReadFull((Byte *)fileDataBuffer, len, processed))
+ return GetLastError_noZero_HRESULT();
+ if (processed != len)
+ return E_FAIL;
+ }
+ continue;
}
NCOM::CPropVariant propVariant;
@@ -2523,14 +3752,65 @@ HRESULT Bench(
if (name.IsEqualTo("time"))
{
- RINOK(ParsePropToUInt32(L"", propVariant, testTime));
+ RINOK(ParsePropToUInt32(UString(), propVariant, testTimeMs))
+ needSetComplexity = true;
+ testTimeMs *= 1000;
continue;
}
-
+
+ if (name.IsEqualTo("timems"))
+ {
+ RINOK(ParsePropToUInt32(UString(), propVariant, testTimeMs))
+ needSetComplexity = true;
+ continue;
+ }
+
+ if (name.IsEqualTo("tic"))
+ {
+ UInt32 v;
+ RINOK(ParsePropToUInt32(UString(), propVariant, v))
+ if (v >= 64)
+ return E_INVALIDARG;
+ complexInCommands = (UInt64)1 << v;
+ continue;
+ }
+
+ const bool isCurrent_fixedDict = name.IsEqualTo("df");
+ if (isCurrent_fixedDict)
+ isFixedDict = true;
+ if (isCurrent_fixedDict || name.IsEqualTo("ds"))
+ {
+ RINOK(ParsePropToUInt32(UString(), propVariant, startDicLog))
+ if (startDicLog > 32)
+ return E_INVALIDARG;
+ startDicLog_Defined = true;
+ continue;
+ }
+
+ if (name.IsEqualTo("mts"))
+ {
+ RINOK(ParsePropToUInt32(UString(), propVariant, numThreads_Start))
+ continue;
+ }
+
+ if (name.IsEqualTo("af"))
+ {
+ UInt32 bundle;
+ RINOK(ParsePropToUInt32(UString(), propVariant, bundle))
+ if (bundle > 0 && bundle < numCPUs)
+ {
+ #ifndef Z7_ST
+ affinityMode.SetLevels(numCPUs, 2);
+ affinityMode.NumBundleThreads = bundle;
+ #endif
+ }
+ continue;
+ }
+
if (name.IsEqualTo("freq"))
{
UInt32 freq32 = 0;
- RINOK(ParsePropToUInt32(L"", propVariant, freq32));
+ RINOK(ParsePropToUInt32(UString(), propVariant, freq32))
if (freq32 == 0)
return E_INVALIDARG;
specifiedFreq = (UInt64)freq32 * 1000000;
@@ -2547,46 +3827,48 @@ HRESULT Bench(
if (name.IsPrefixedBy_Ascii_NoCase("mt"))
{
- UString s = name.Ptr(2);
- if (s == L"*")
+ const UString s = name.Ptr(2);
+ if (s.IsEqualTo("*")
+ || (s.IsEmpty()
+ && propVariant.vt == VT_BSTR
+ && StringsAreEqual_Ascii(propVariant.bstrVal, "*")))
{
multiThreadTests = true;
continue;
}
- if (s.IsEmpty() && propVariant.vt == VT_BSTR)
- {
- if (wcscmp(propVariant.bstrVal, L"*") == 0)
- {
- multiThreadTests = true;
- continue;
- }
- }
- #ifndef _7ZIP_ST
- RINOK(ParseMtProp(s, propVariant, numCPUs, numThreadsSpecified));
+ #ifndef Z7_ST
+ RINOK(ParseMtProp(s, propVariant, numCPUs, numThreadsSpecified))
#endif
continue;
}
- RINOK(method.ParseMethodFromPROPVARIANT(name, propVariant));
+ RINOK(method.ParseMethodFromPROPVARIANT(name, propVariant))
}
}
if (printCallback)
{
AString s;
- GetCpuName(s);
+
+ #ifndef _WIN32
+ s += "Compiler: ";
+ GetCompiler(s);
+ printCallback->Print(s);
+ printCallback->NewLine();
+ s.Empty();
+ #endif
+
+ GetSystemInfoText(s);
printCallback->Print(s);
printCallback->NewLine();
}
if (printCallback)
{
- printCallback->Print("CPU Freq:");
+ printCallback->Print("1T CPU Freq (MHz):");
}
- UInt64 complexInCommands = kComplexInCommands;
-
- if (printCallback /* || benchCallback */)
+ if (printCallback || freqCallback)
{
UInt64 numMilCommands = 1 << 6;
if (specifiedFreq != 0)
@@ -2598,17 +3880,23 @@ HRESULT Bench(
for (int jj = 0;; jj++)
{
if (printCallback)
- RINOK(printCallback->CheckBreak());
+ RINOK(printCallback->CheckBreak())
UInt64 start = ::GetTimeCount();
UInt32 sum = (UInt32)start;
sum = CountCpuFreq(sum, (UInt32)(numMilCommands * 1000000 / kNumFreqCommands), g_BenchCpuFreqTemp);
+ if (sum == 0xF1541213)
+ if (printCallback)
+ printCallback->Print("");
const UInt64 realDelta = ::GetTimeCount() - start;
start = realDelta;
if (start == 0)
start = 1;
- UInt64 freq = GetFreq();
+ if (start > (UInt64)1 << 61)
+ start = 1;
+ const UInt64 freq = GetFreq();
// mips is constant in some compilers
+ const UInt64 hz = MyMultDiv64(numMilCommands * 1000000, freq, start);
const UInt64 mipsVal = numMilCommands * freq / start;
if (printCallback)
{
@@ -2619,172 +3907,570 @@ HRESULT Bench(
else
{
// PrintNumber(*printCallback, start, 0);
- PrintNumber(*printCallback, mipsVal, 5 + ((sum == 0xF1541213) ? 1 : 0));
+ PrintNumber(*printCallback, mipsVal, 5);
}
}
- /*
- if (benchCallback)
- benchCallback->AddCpuFreq(mipsVal);
- */
+ if (freqCallback)
+ {
+ RINOK(freqCallback->AddCpuFreq(1, hz, kBenchmarkUsageMult))
+ }
+
+ if (jj >= 1)
+ {
+ bool needStop = (numMilCommands >= (1 <<
+ #ifdef _DEBUG
+ 7
+ #else
+ 11
+ #endif
+ ));
+ if (start >= freq * 16)
+ {
+ printCallback->Print(" (Cmplx)");
+ if (!freqCallback) // we don't want complexity change for old gui lzma benchmark
+ {
+ needSetComplexity = true;
+ }
+ needStop = true;
+ }
+ if (needSetComplexity)
+ SetComplexCommandsMs(testTimeMs, false, mipsVal * 1000000, complexInCommands);
+ if (needStop)
+ break;
+ numMilCommands <<= 1;
+ }
+ }
+ if (freqCallback)
+ {
+ RINOK(freqCallback->FreqsFinished(1))
+ }
+ }
+
+ if (numThreadsSpecified >= 2)
+ if (printCallback || freqCallback)
+ {
+ if (printCallback)
+ printCallback->NewLine();
- if (jj >= 3)
+ /* it can show incorrect frequency for HT threads.
+ so we reduce freq test to (numCPUs / 2) */
+
+ UInt32 numThreads = numThreadsSpecified >= numCPUs / 2 ? numCPUs / 2: numThreadsSpecified;
+ if (numThreads < 1)
+ numThreads = 1;
+
+ if (printCallback)
+ {
+ char s[128];
+ ConvertUInt64ToString(numThreads, s);
+ printCallback->Print(s);
+ printCallback->Print("T CPU Freq (MHz):");
+ }
+ UInt64 numMilCommands = 1 <<
+ #ifdef _DEBUG
+ 7;
+ #else
+ 10;
+ #endif
+
+ if (specifiedFreq != 0)
+ {
+ while (numMilCommands > 1 && specifiedFreq < (numMilCommands * 1000000))
+ numMilCommands >>= 1;
+ }
+
+ // for (int jj = 0;; jj++)
+ for (;;)
+ {
+ if (printCallback)
+ RINOK(printCallback->CheckBreak())
+
+ {
+ // PrintLeft(f, "CPU", kFieldSize_Name);
+
+ // UInt32 resVal;
+
+ CFreqBench fb;
+ fb.complexInCommands = numMilCommands * 1000000;
+ fb.numThreads = numThreads;
+ // showFreq;
+ // fb.showFreq = (freqTest == kNumCpuTests - 1 || specifiedFreq != 0);
+ fb.showFreq = true;
+ fb.specifiedFreq = 1;
+
+ const HRESULT res = fb.FreqBench(NULL /* printCallback */
+ #ifndef Z7_ST
+ , &affinityMode
+ #endif
+ );
+ RINOK(res)
+
+ if (freqCallback)
+ {
+ RINOK(freqCallback->AddCpuFreq(numThreads, fb.CpuFreqRes, fb.UsageRes))
+ }
+
+ if (printCallback)
+ {
+ /*
+ if (realDelta == 0)
+ {
+ printCallback->Print(" -");
+ }
+ else
+ */
+ {
+ // PrintNumber(*printCallback, start, 0);
+ PrintUsage(*printCallback, fb.UsageRes, 3);
+ printCallback->Print("%");
+ PrintNumber(*printCallback, fb.CpuFreqRes / 1000000, 0);
+ printCallback->Print(" ");
+
+ // PrintNumber(*printCallback, fb.UsageRes, 5);
+ }
+ }
+ }
+ // if (jj >= 1)
{
- SetComplexCommands(testTime, false, mipsVal * 1000000, complexInCommands);
- if (jj >= 8 || start >= freq)
+ const bool needStop = (numMilCommands >= (1 <<
+ #ifdef _DEBUG
+ 7
+ #else
+ 11
+ #endif
+ ));
+ if (needStop)
break;
- // break; // change it
numMilCommands <<= 1;
}
}
+ if (freqCallback)
+ {
+ RINOK(freqCallback->FreqsFinished(numThreads))
+ }
}
+
if (printCallback)
{
printCallback->NewLine();
printCallback->NewLine();
PrintRequirements(*printCallback, "size: ", ramSize_Defined, ramSize, "CPU hardware threads:", numCPUs);
+ printCallback->Print(GetProcessThreadsInfo(threadsInfo));
+ printCallback->NewLine();
}
if (numThreadsSpecified < 1 || numThreadsSpecified > kNumThreadsMax)
return E_INVALIDARG;
- UInt32 dict;
- bool dictIsDefined = method.Get_DicSize(dict);
+ UInt64 dict = (UInt64)1 << startDicLog;
+ const bool dictIsDefined = (isFixedDict || method.Get_DicSize(dict));
+
+ const unsigned level = method.GetLevel();
- if (method.MethodName.IsEmpty())
- method.MethodName = "LZMA";
+ AString &methodName = method.MethodName;
+ const AString original_MethodName = methodName;
+ if (methodName.IsEmpty())
+ methodName = "LZMA";
if (benchCallback)
{
CBenchProps benchProps;
benchProps.SetLzmaCompexity();
- UInt32 dictSize = method.Get_Lzma_DicSize();
- UInt32 uncompressedDataSize = kAdditionalSize + dictSize;
+ const UInt64 dictSize = method.Get_Lzma_DicSize();
+
+ size_t uncompressedDataSize;
+ if (use_fileData)
+ {
+ uncompressedDataSize = fileDataBuffer.Size();
+ }
+ else
+ {
+ uncompressedDataSize = kAdditionalSize + (size_t)dictSize;
+ if (uncompressedDataSize < dictSize)
+ return E_INVALIDARG;
+ }
+
return MethodBench(
EXTERNAL_CODECS_LOC_VARS
complexInCommands,
+ #ifndef Z7_ST
true, numThreadsSpecified,
+ &affinityMode,
+ #endif
method,
- uncompressedDataSize, fileDataBuffer.Buffer,
+ uncompressedDataSize, (const Byte *)fileDataBuffer,
kOldLzmaDictBits, printCallback, benchCallback, &benchProps);
}
- AString methodName = method.MethodName;
if (methodName.IsEqualTo_Ascii_NoCase("CRC"))
methodName = "crc32";
- method.MethodName = methodName;
+
CMethodId hashID;
-
- if (FindHashMethod(EXTERNAL_CODECS_LOC_VARS methodName, hashID))
+ const bool isHashMethod = FindHashMethod(EXTERNAL_CODECS_LOC_VARS methodName, hashID);
+ int codecIndex = -1;
+ bool isFilter = false;
+ if (!isHashMethod)
+ {
+ UInt32 numStreams;
+ codecIndex = FindMethod_Index(EXTERNAL_CODECS_LOC_VARS original_MethodName,
+ true, // encode
+ hashID, numStreams, isFilter);
+ // we can allow non filter for BW tests
+ if (!isFilter) codecIndex = -1;
+ }
+
+ CBenchCallbackToPrint callback;
+ callback.Init();
+ callback._file = printCallback;
+
+ if (isHashMethod || codecIndex != -1)
{
if (!printCallback)
return S_FALSE;
IBenchPrintCallback &f = *printCallback;
+
+ UInt64 dict64 = dict;
if (!dictIsDefined)
- dict = (1 << 24);
+ dict64 = (1 << 27);
+ if (use_fileData)
+ {
+ if (!dictIsDefined)
+ dict64 = fileDataBuffer.Size();
+ else if (dict64 > fileDataBuffer.Size())
+ dict64 = fileDataBuffer.Size();
+ }
+ for (;;)
+ {
+ const int index = method.FindProp(NCoderPropID::kDictionarySize);
+ if (index < 0)
+ break;
+ method.Props.Delete((unsigned)index);
+ }
- // methhodName.RemoveChar(L'-');
- UInt32 complexity = 10000;
+ // methodName.RemoveChar(L'-');
+ Int32 complexity = 16 * k_Hash_Complex_Mult; // for unknown hash method
const UInt32 *checkSum = NULL;
+ int benchIndex = -1;
+
+ if (isHashMethod)
{
- for (unsigned i = 0; i < ARRAY_SIZE(g_Hash); i++)
+ for (unsigned i = 0; i < Z7_ARRAY_SIZE(g_Hash); i++)
{
const CBenchHash &h = g_Hash[i];
- AString s = h.Name;
- AString hProp;
- int propPos = s.Find(':');
+ AString benchMethod (h.Name);
+ AString benchProps;
+ const int propPos = benchMethod.Find(':');
if (propPos >= 0)
{
- hProp = s.Ptr(propPos + 1);
- s.DeleteFrom(propPos);
+ benchProps = benchMethod.Ptr((unsigned)(propPos + 1));
+ benchMethod.DeleteFrom((unsigned)propPos);
}
- if (AreSameMethodNames(s, methodName))
+ if (AreSameMethodNames(benchMethod, methodName))
{
- complexity = h.Complex;
- checkSum = &h.CheckSum;
- if (method.PropsString.IsEqualTo_Ascii_NoCase(hProp))
- break;
+ const bool sameProps = method.PropsString.IsEqualTo_Ascii_NoCase(benchProps);
+ /*
+ bool isMainMethod = method.PropsString.IsEmpty();
+ if (isMainMethod)
+ isMainMethod = !checkSum
+ || (benchMethod.IsEqualTo_Ascii_NoCase("crc32") && benchProps.IsEqualTo_Ascii_NoCase("8"));
+ if (sameProps || isMainMethod)
+ */
+ {
+ complexity = (Int32)h.Complex;
+ checkSum = &h.CheckSum;
+ if (sameProps)
+ break;
+ /*
+ if property. is not specified, we use the complexity
+ for latest fastest method (crc32:64)
+ */
+ }
+ }
+ }
+ // if (!checkSum) return E_NOTIMPL;
+ }
+ else
+ {
+ for (unsigned i = 0; i < Z7_ARRAY_SIZE(g_Bench); i++)
+ {
+ const CBenchMethod &bench = g_Bench[i];
+ AString benchMethod (bench.Name);
+ AString benchProps;
+ const int propPos = benchMethod.Find(':');
+ if (propPos >= 0)
+ {
+ benchProps = benchMethod.Ptr((unsigned)(propPos + 1));
+ benchMethod.DeleteFrom((unsigned)propPos);
+ }
+
+ if (AreSameMethodNames(benchMethod, methodName))
+ {
+ const bool sameProps = method.PropsString.IsEqualTo_Ascii_NoCase(benchProps);
+ // bool isMainMethod = method.PropsString.IsEmpty();
+ // if (sameProps || isMainMethod)
+ {
+ benchIndex = (int)i;
+ if (sameProps)
+ break;
+ }
}
}
+ // if (benchIndex < 0) return E_NOTIMPL;
}
- f.NewLine();
- f.Print("Size");
- const unsigned kFieldSize_CrcSpeed = 6;
- unsigned numThreadsTests = 0;
- for (;;)
{
- UInt32 t = GetNumThreadsNext(numThreadsTests, numThreadsSpecified);
- PrintNumber(f, t, kFieldSize_CrcSpeed);
- numThreadsTests++;
- if (t >= numThreadsSpecified)
- break;
+ /* we count usage only for crc and filter. non-filters are not supported */
+ UInt64 usage = (1 << 20);
+ UInt64 bufSize = dict64;
+ UInt32 numBlocks = isHashMethod ? 1 : 3;
+ if (use_fileData)
+ {
+ usage += fileDataBuffer.Size();
+ if (bufSize > fileDataBuffer.Size())
+ bufSize = fileDataBuffer.Size();
+ if (isHashMethod)
+ {
+ numBlocks = 0;
+ #ifndef Z7_ST
+ if (numThreadsSpecified != 1)
+ numBlocks = (k_Crc_CreateLocalBuf_For_File ? 1 : 0);
+ #endif
+ }
+ }
+ usage += numThreadsSpecified * bufSize * numBlocks;
+ Print_Usage_and_Threads(f, usage, numThreadsSpecified);
}
+
+ CUIntVector numThreadsVector;
+ {
+ unsigned nt = numThreads_Start;
+ for (;;)
+ {
+ if (nt > numThreadsSpecified)
+ break;
+ numThreadsVector.Add(nt);
+ const unsigned next = nt * 2;
+ const UInt32 ntHalf= numThreadsSpecified / 2;
+ if (ntHalf > nt && ntHalf < next)
+ numThreadsVector.Add(ntHalf);
+ if (numThreadsSpecified > nt && numThreadsSpecified < next)
+ numThreadsVector.Add(numThreadsSpecified);
+ nt = next;
+ }
+ }
+
+ unsigned numColumns = isHashMethod ? 1 : 2;
+ CTempValues speedTotals;
+ CTempValues usageTotals;
+ {
+ const unsigned numItems = numThreadsVector.Size() * numColumns;
+ speedTotals.Alloc(numItems);
+ usageTotals.Alloc(numItems);
+ for (unsigned i = 0; i < numItems; i++)
+ {
+ speedTotals.Values[i] = 0;
+ usageTotals.Values[i] = 0;
+ }
+ }
+
f.NewLine();
- f.NewLine();
- CTempValues speedTotals(numThreadsTests);
+ for (unsigned line = 0; line < 3; line++)
{
- for (unsigned ti = 0; ti < numThreadsTests; ti++)
- speedTotals.Values[ti] = 0;
+ f.NewLine();
+ f.Print(line == 0 ? "THRD" : line == 1 ? " " : "Size");
+ FOR_VECTOR (ti, numThreadsVector)
+ {
+ if (ti != 0)
+ Print_Delimiter(f);
+ if (line == 0)
+ {
+ PrintSpaces(f, (kFieldSize_CrcSpeed + kFieldSize_Usage + 2) * (numColumns - 1));
+ PrintNumber(f, numThreadsVector[ti], 1 + kFieldSize_Usage + kFieldSize_CrcSpeed);
+ }
+ else
+ {
+ for (unsigned c = 0; c < numColumns; c++)
+ {
+ PrintRight(f, line == 1 ? "Usage" : "%", kFieldSize_Usage + 1);
+ PrintRight(f, line == 1 ? "BW" : "MB/s", kFieldSize_CrcSpeed + 1);
+ }
+ }
+ }
}
-
+ f.NewLine();
+
UInt64 numSteps = 0;
- for (UInt32 i = 0; i < numIterations; i++)
+
+ // for (UInt32 iter = 0; iter < numIterations; iter++)
+ // {
+ unsigned pow = 10; // kNumHashDictBits
+ if (startDicLog_Defined)
+ pow = startDicLog;
+
+ // #define NUM_SUB_BITS 2
+ // pow <<= NUM_SUB_BITS;
+ for (;; pow++)
{
- for (unsigned pow = 10; pow < 32; pow++)
+ const UInt64 bufSize = (UInt64)1 << pow;
+ // UInt64 bufSize = (UInt64)1 << (pow >> NUM_SUB_BITS);
+ // bufSize += ((UInt64)pow & ((1 << NUM_SUB_BITS) - 1)) << ((pow >> NUM_SUB_BITS) - NUM_SUB_BITS);
+
+ size_t dataSize = fileDataBuffer.Size();
+ if (dataSize > bufSize || !use_fileData)
+ dataSize = (size_t)bufSize;
+
+ for (UInt32 iter = 0; iter < numIterations; iter++)
{
- UInt32 bufSize = (UInt32)1 << pow;
- if (bufSize > dict)
- break;
- char s[16];
- ConvertUInt32ToString(pow, s);
- unsigned pos = MyStringLen(s);
- s[pos++] = ':';
- s[pos++] = ' ';
- s[pos] = 0;
- f.Print(s);
-
- for (unsigned ti = 0; ti < numThreadsTests; ti++)
+ Print_Pow(f, pow);
+ // PrintNumber(f, bufSize >> 10, 4);
+
+ FOR_VECTOR (ti, numThreadsVector)
{
- RINOK(f.CheckBreak());
- UInt32 t = GetNumThreadsNext(ti, numThreadsSpecified);
- UInt64 speed = 0;
- RINOK(CrcBench(EXTERNAL_CODECS_LOC_VARS complexInCommands,
- t, bufSize, speed,
- complexity,
+ RINOK(f.CheckBreak())
+ const UInt32 numThreads = numThreadsVector[ti];
+ if (isHashMethod)
+ {
+ UInt64 speed = 0;
+ UInt64 usage = 0;
+ const HRESULT res = CrcBench(EXTERNAL_CODECS_LOC_VARS complexInCommands,
+ numThreads,
+ dataSize, (const Byte *)fileDataBuffer,
+ speed, usage,
+ (UInt32)complexity,
1, // benchWeight,
- (pow == kNumHashDictBits) ? checkSum : NULL, method, NULL, NULL, false, 0));
- PrintNumber(f, (speed >> 20), kFieldSize_CrcSpeed);
- speedTotals.Values[ti] += speed;
+ (pow == kNumHashDictBits && !use_fileData) ? checkSum : NULL,
+ method,
+ &f,
+ #ifndef Z7_ST
+ &affinityMode,
+ #endif
+ false, // showRating
+ NULL, false, 0);
+ RINOK(res)
+
+ if (ti != 0)
+ Print_Delimiter(f);
+
+ Bench_BW_Print_Usage_Speed(f, usage, speed);
+ speedTotals.Values[ti] += speed;
+ usageTotals.Values[ti] += usage;
+ }
+ else
+ {
+ {
+ unsigned keySize = 32;
+ if (IsString1PrefixedByString2(methodName, "AES128")) keySize = 16;
+ else if (IsString1PrefixedByString2(methodName, "AES192")) keySize = 24;
+ callback.BenchProps.KeySize = keySize;
+ }
+
+ COneMethodInfo method2 = method;
+ unsigned bench_DictBits;
+
+ if (benchIndex >= 0)
+ {
+ const CBenchMethod &bench = g_Bench[benchIndex];
+ callback.BenchProps.EncComplex = bench.EncComplex;
+ callback.BenchProps.DecComplexUnc = bench.DecComplexUnc;
+ callback.BenchProps.DecComplexCompr = bench.DecComplexCompr;
+ bench_DictBits = bench.DictBits;
+ // bench_DictBits = kOldLzmaDictBits; = 32 default : for debug
+ }
+ else
+ {
+ bench_DictBits = kOldLzmaDictBits; // = 32 default
+ if (isFilter)
+ {
+ const unsigned k_UnknownCoderComplexity = 4;
+ callback.BenchProps.EncComplex = k_UnknownCoderComplexity;
+ callback.BenchProps.DecComplexUnc = k_UnknownCoderComplexity;
+ }
+ else
+ {
+ callback.BenchProps.EncComplex = 1 << 10;
+ callback.BenchProps.DecComplexUnc = 1 << 6;
+ }
+ callback.BenchProps.DecComplexCompr = 0;
+ }
+ callback.NeedPrint = false;
+
+ if (StringsAreEqualNoCase_Ascii(method2.MethodName, "LZMA"))
+ {
+ const NCOM::CPropVariant propVariant = (UInt32)pow;
+ RINOK(method2.ParseMethodFromPROPVARIANT((UString)"d", propVariant))
+ }
+
+ const HRESULT res = MethodBench(
+ EXTERNAL_CODECS_LOC_VARS
+ complexInCommands,
+ #ifndef Z7_ST
+ false, // oldLzmaBenchMode
+ numThreadsVector[ti],
+ &affinityMode,
+ #endif
+ method2,
+ dataSize, (const Byte *)fileDataBuffer,
+ bench_DictBits,
+ printCallback,
+ &callback,
+ &callback.BenchProps);
+ RINOK(res)
+
+ if (ti != 0)
+ Print_Delimiter(f);
+
+ for (unsigned i = 0; i < 2; i++)
+ {
+ const CBenchInfo &bi = callback.BenchInfo_Results[i];
+ const UInt64 usage = bi.GetUsage();
+ const UInt64 speed = bi.GetUnpackSizeSpeed();
+ usageTotals.Values[ti * 2 + i] += usage;
+ speedTotals.Values[ti * 2 + i] += speed;
+ Bench_BW_Print_Usage_Speed(f, usage, speed);
+ }
+ }
}
+
f.NewLine();
numSteps++;
}
+ if (dataSize >= dict64)
+ break;
}
+
if (numSteps != 0)
{
- f.NewLine();
f.Print("Avg:");
- for (unsigned ti = 0; ti < numThreadsTests; ti++)
+ for (unsigned ti = 0; ti < numThreadsVector.Size(); ti++)
{
- PrintNumber(f, ((speedTotals.Values[ti] / numSteps) >> 20), kFieldSize_CrcSpeed);
+ if (ti != 0)
+ Print_Delimiter(f);
+ for (unsigned i = 0; i < numColumns; i++)
+ Bench_BW_Print_Usage_Speed(f,
+ usageTotals.Values[ti * numColumns + i] / numSteps,
+ speedTotals.Values[ti * numColumns + i] / numSteps);
}
f.NewLine();
}
+
return S_OK;
}
bool use2Columns = false;
- bool totalBenchMode = (method.MethodName.IsEqualTo_Ascii_NoCase("*"));
+ bool totalBenchMode = false;
bool onlyHashBench = false;
- if (method.MethodName.IsEqualTo_Ascii_NoCase("hash"))
+ if (methodName.IsEqualTo_Ascii_NoCase("hash"))
{
onlyHashBench = true;
+ methodName = "*";
totalBenchMode = true;
}
+ else if (methodName.Find('*') >= 0)
+ totalBenchMode = true;
// ---------- Threads loop ----------
for (unsigned threadsPassIndex = 0; threadsPassIndex < 3; threadsPassIndex++)
@@ -2815,10 +4501,6 @@ HRESULT Bench(
}
}
- CBenchCallbackToPrint callback;
- callback.Init();
- callback._file = printCallback;
-
IBenchPrintCallback &f = *printCallback;
if (threadsPassIndex > 0)
@@ -2827,7 +4509,7 @@ HRESULT Bench(
f.NewLine();
}
- if (!dictIsDefined)
+ if (!dictIsDefined && !onlyHashBench)
{
const unsigned dicSizeLog_Main = (totalBenchMode ? 24 : 25);
unsigned dicSizeLog = dicSizeLog_Main;
@@ -2838,10 +4520,10 @@ HRESULT Bench(
if (ramSize_Defined)
for (; dicSizeLog > kBenchMinDicLogSize; dicSizeLog--)
- if (GetBenchMemoryUsage(numThreads, ((UInt32)1 << dicSizeLog), totalBenchMode) + (8 << 20) <= ramSize)
+ if (GetBenchMemoryUsage(numThreads, (int)level, ((UInt64)1 << dicSizeLog), totalBenchMode) + (8 << 20) <= ramSize)
break;
- dict = (UInt32)1 << dicSizeLog;
+ dict = (UInt64)1 << dicSizeLog;
if (totalBenchMode && dicSizeLog != dicSizeLog_Main)
{
@@ -2851,7 +4533,13 @@ HRESULT Bench(
}
}
- PrintRequirements(f, "usage:", true, GetBenchMemoryUsage(numThreads, dict, totalBenchMode), "Benchmark threads: ", numThreads);
+ Print_Usage_and_Threads(f,
+ onlyHashBench ?
+ GetBenchMemoryUsage_Hash(numThreads, dict) :
+ GetBenchMemoryUsage(numThreads, (int)level, dict, totalBenchMode),
+ numThreads);
+
+ f.NewLine();
f.NewLine();
@@ -2934,6 +4622,7 @@ HRESULT Bench(
if (specifiedFreq != 0)
cpuFreq = specifiedFreq;
+ // bool showTotalSpeed = false;
if (totalBenchMode)
{
@@ -2941,96 +4630,171 @@ HRESULT Bench(
{
if (i != 0)
printCallback->NewLine();
- HRESULT res;
const unsigned kNumCpuTests = 3;
for (unsigned freqTest = 0; freqTest < kNumCpuTests; freqTest++)
{
PrintLeft(f, "CPU", kFieldSize_Name);
- UInt32 resVal;
- RINOK(FreqBench(complexInCommands, numThreads, printCallback,
- (freqTest == kNumCpuTests - 1 || specifiedFreq != 0), // showFreq
- specifiedFreq,
- cpuFreq, resVal));
+
+ // UInt32 resVal;
+
+ CFreqBench fb;
+ fb.complexInCommands = complexInCommands;
+ fb.numThreads = numThreads;
+ // showFreq;
+ fb.showFreq = (freqTest == kNumCpuTests - 1 || specifiedFreq != 0);
+ fb.specifiedFreq = specifiedFreq;
+
+ const HRESULT res = fb.FreqBench(printCallback
+ #ifndef Z7_ST
+ , &affinityMode
+ #endif
+ );
+ RINOK(res)
+
+ cpuFreq = fb.CpuFreqRes;
callback.NewLine();
if (specifiedFreq != 0)
cpuFreq = specifiedFreq;
+ if (testTimeMs >= 1000)
if (freqTest == kNumCpuTests - 1)
- SetComplexCommands(testTime, specifiedFreq != 0, cpuFreq, complexInCommands);
+ {
+ // SetComplexCommandsMs(testTimeMs, specifiedFreq != 0, cpuFreq, complexInCommands);
+ }
}
callback.NewLine();
+ // return S_OK; // change it
+
callback.SetFreq(true, cpuFreq);
if (!onlyHashBench)
{
- res = TotalBench(EXTERNAL_CODECS_LOC_VARS
- complexInCommands, numThreads,
- dictIsDefined || fileDataBuffer.Buffer, // forceUnpackSize
- fileDataBuffer.Buffer ? fileDataBuffer.BufferSize : dict,
- fileDataBuffer.Buffer,
+ size_t dataSize = (size_t)dict;
+ if (use_fileData)
+ {
+ dataSize = fileDataBuffer.Size();
+ if (dictIsDefined && dataSize > dict)
+ dataSize = (size_t)dict;
+ }
+
+ const HRESULT res = TotalBench(EXTERNAL_CODECS_LOC_VARS
+ method, complexInCommands,
+ #ifndef Z7_ST
+ numThreads,
+ &affinityMode,
+ #endif
+ dictIsDefined || use_fileData, // forceUnpackSize
+ dataSize,
+ (const Byte *)fileDataBuffer,
printCallback, &callback);
- RINOK(res);
+ RINOK(res)
}
- res = TotalBench_Hash(EXTERNAL_CODECS_LOC_VARS complexInCommands, numThreads,
- 1 << kNumHashDictBits, printCallback, &callback, &callback.EncodeRes, true, cpuFreq);
- RINOK(res);
+ {
+ size_t dataSize = (size_t)1 << kNumHashDictBits;
+ if (dictIsDefined)
+ {
+ dataSize = (size_t)dict;
+ if (dataSize != dict)
+ return E_OUTOFMEMORY;
+ }
+ if (use_fileData)
+ {
+ dataSize = fileDataBuffer.Size();
+ if (dictIsDefined && dataSize > dict)
+ dataSize = (size_t)dict;
+ }
+
+ const HRESULT res = TotalBench_Hash(EXTERNAL_CODECS_LOC_VARS
+ method, complexInCommands,
+ numThreads,
+ dataSize, (const Byte *)fileDataBuffer,
+ printCallback, &callback,
+ #ifndef Z7_ST
+ &affinityMode,
+ #endif
+ &callback.EncodeRes, true, cpuFreq);
+ RINOK(res)
+ }
callback.NewLine();
{
PrintLeft(f, "CPU", kFieldSize_Name);
- UInt32 resVal;
- UInt64 cpuFreqLastTemp = cpuFreq;
- RINOK(FreqBench(complexInCommands, numThreads, printCallback,
- specifiedFreq != 0, // showFreq
- specifiedFreq,
- cpuFreqLastTemp, resVal));
+
+ CFreqBench fb;
+ fb.complexInCommands = complexInCommands;
+ fb.numThreads = numThreads;
+ // showFreq;
+ fb.showFreq = (specifiedFreq != 0);
+ fb.specifiedFreq = specifiedFreq;
+
+ const HRESULT res = fb.FreqBench(printCallback
+ #ifndef Z7_ST
+ , &affinityMode
+ #endif
+ );
+ RINOK(res)
callback.NewLine();
}
}
}
else
{
- bool needSetComplexity = true;
+ needSetComplexity = true;
if (!methodName.IsEqualTo_Ascii_NoCase("LZMA"))
{
- for (unsigned i = 0; i < ARRAY_SIZE(g_Bench); i++)
+ unsigned i;
+ for (i = 0; i < Z7_ARRAY_SIZE(g_Bench); i++)
{
const CBenchMethod &h = g_Bench[i];
- AString s = h.Name;
- if (AreSameMethodNames(h.Name, methodName))
+ AString benchMethod (h.Name);
+ AString benchProps;
+ const int propPos = benchMethod.Find(':');
+ if (propPos >= 0)
{
- callback.BenchProps.EncComplex = h.EncComplex;
- callback.BenchProps.DecComplexCompr = h.DecComplexCompr;
- callback.BenchProps.DecComplexUnc = h.DecComplexUnc;;
- needSetComplexity = false;
- break;
+ benchProps = benchMethod.Ptr((unsigned)(propPos + 1));
+ benchMethod.DeleteFrom((unsigned)propPos);
+ }
+
+ if (AreSameMethodNames(benchMethod, methodName))
+ {
+ if (benchProps.IsEmpty()
+ || (benchProps == "x5" && method.PropsString.IsEmpty())
+ || method.PropsString.IsPrefixedBy_Ascii_NoCase(benchProps))
+ {
+ callback.BenchProps.EncComplex = h.EncComplex;
+ callback.BenchProps.DecComplexCompr = h.DecComplexCompr;
+ callback.BenchProps.DecComplexUnc = h.DecComplexUnc;
+ needSetComplexity = false;
+ break;
+ }
}
}
+ /*
+ if (i == Z7_ARRAY_SIZE(g_Bench))
+ return E_NOTIMPL;
+ */
}
if (needSetComplexity)
callback.BenchProps.SetLzmaCompexity();
+ if (startDicLog < kBenchMinDicLogSize)
+ startDicLog = kBenchMinDicLogSize;
+
for (unsigned i = 0; i < numIterations; i++)
{
- const unsigned kStartDicLog = 22;
- unsigned pow = (dict < ((UInt32)1 << kStartDicLog)) ? kBenchMinDicLogSize : kStartDicLog;
+ unsigned pow = (dict < GetDictSizeFromLog(startDicLog)) ? kBenchMinDicLogSize : (unsigned)startDicLog;
if (!multiDict)
- pow = 31;
- while (((UInt32)1 << pow) > dict && pow > 0)
+ pow = 32;
+ while (GetDictSizeFromLog(pow) > dict && pow > 0)
pow--;
- for (; ((UInt32)1 << pow) <= dict; pow++)
+ for (; GetDictSizeFromLog(pow) <= dict; pow++)
{
- char s[16];
- ConvertUInt32ToString(pow, s);
- unsigned pos = MyStringLen(s);
- s[pos++] = ':';
- s[pos] = 0;
- PrintLeft(f, s, kFieldSize_SmallName);
- callback.DictSize = (UInt32)1 << pow;
+ Print_Pow(f, pow);
+ callback.DictSize = (UInt64)1 << pow;
COneMethodInfo method2 = method;
@@ -3040,30 +4804,35 @@ HRESULT Bench(
// method2 can have two different dictionary size properties.
// And last property is main.
NCOM::CPropVariant propVariant = (UInt32)pow;
- RINOK(method2.ParseMethodFromPROPVARIANT(L"d", propVariant));
+ RINOK(method2.ParseMethodFromPROPVARIANT((UString)"d", propVariant))
}
size_t uncompressedDataSize;
- if (fileDataBuffer.Buffer)
+ if (use_fileData)
{
- uncompressedDataSize = fileDataBuffer.BufferSize;
+ uncompressedDataSize = fileDataBuffer.Size();
}
else
{
- uncompressedDataSize = callback.DictSize;
+ uncompressedDataSize = (size_t)callback.DictSize;
+ if (uncompressedDataSize != callback.DictSize)
+ return E_OUTOFMEMORY;
if (uncompressedDataSize >= (1 << 18))
uncompressedDataSize += kAdditionalSize;
}
- HRESULT res = MethodBench(
+ const HRESULT res = MethodBench(
EXTERNAL_CODECS_LOC_VARS
complexInCommands,
+ #ifndef Z7_ST
true, numThreads,
+ &affinityMode,
+ #endif
method2,
- uncompressedDataSize, fileDataBuffer.Buffer,
+ uncompressedDataSize, (const Byte *)fileDataBuffer,
kOldLzmaDictBits, printCallback, &callback, &callback.BenchProps);
f.NewLine();
- RINOK(res);
+ RINOK(res)
if (!multiDict)
break;
}
@@ -3083,16 +4852,19 @@ HRESULT Bench(
if (use2Columns)
{
PrintLeft(f, "Avr:", callback.NameFieldSize);
- PrintTotals(f, showFreq, cpuFreq, callback.EncodeRes);
+ PrintTotals(f, showFreq, cpuFreq, !totalBenchMode, callback.EncodeRes);
f.Print(kSep);
- PrintTotals(f, showFreq, cpuFreq, callback.DecodeRes);
+ PrintTotals(f, showFreq, cpuFreq, !totalBenchMode, callback.DecodeRes);
f.NewLine();
}
PrintLeft(f, "Tot:", callback.NameFieldSize);
CTotalBenchRes midRes;
- midRes.SetSum(callback.EncodeRes, callback.DecodeRes);
- PrintTotals(f, showFreq, cpuFreq, midRes);
+ midRes = callback.EncodeRes;
+ midRes.Update_With_Res(callback.DecodeRes);
+
+ // midRes.SetSum(callback.EncodeRes, callback.DecodeRes);
+ PrintTotals(f, showFreq, cpuFreq, false, midRes);
f.NewLine();
}
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/Bench.h b/3rdparty/lzma/CPP/7zip/UI/Common/Bench.h
index 841250ef2cc..313676dd5a1 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/Bench.h
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/Bench.h
@@ -1,11 +1,15 @@
// Bench.h
-#ifndef __7ZIP_BENCH_H
-#define __7ZIP_BENCH_H
+#ifndef ZIP7_INC_7ZIP_BENCH_H
+#define ZIP7_INC_7ZIP_BENCH_H
+
+#include "../../../Windows/System.h"
#include "../../Common/CreateCoder.h"
#include "../../UI/Common/Property.h"
+UInt64 Benchmark_GetUsage_Percents(UInt64 usage);
+
struct CBenchInfo
{
UInt64 GlobalTime;
@@ -15,41 +19,103 @@ struct CBenchInfo
UInt64 UnpackSize;
UInt64 PackSize;
UInt64 NumIterations;
+
+ /*
+ during Code(): we track benchInfo only from one thread (theads with index[0])
+ NumIterations means number of threads
+ UnpackSize and PackSize are total sizes of all iterations of current thread
+ after Code():
+ NumIterations means the number of Iterations
+ UnpackSize and PackSize are total sizes of all threads
+ */
CBenchInfo(): NumIterations(0) {}
+
UInt64 GetUsage() const;
UInt64 GetRatingPerUsage(UInt64 rating) const;
- UInt64 GetSpeed(UInt64 numCommands) const;
+ UInt64 GetSpeed(UInt64 numUnits) const;
+ UInt64 GetUnpackSizeSpeed() const { return GetSpeed(UnpackSize * NumIterations); }
+
+ UInt64 Get_UnpackSize_Full() const { return UnpackSize * NumIterations; }
+
+ UInt64 GetRating_LzmaEnc(UInt64 dictSize) const;
+ UInt64 GetRating_LzmaDec() const;
};
-struct IBenchCallback
+
+struct CTotalBenchRes
{
- virtual HRESULT SetFreq(bool showFreq, UInt64 cpuFreq) = 0;
- virtual HRESULT SetEncodeResult(const CBenchInfo &info, bool final) = 0;
- virtual HRESULT SetDecodeResult(const CBenchInfo &info, bool final) = 0;
+ // UInt64 NumIterations1; // for Usage
+ UInt64 NumIterations2; // for Rating / RPU
+
+ UInt64 Rating;
+ UInt64 Usage;
+ UInt64 RPU;
+ UInt64 Speed;
+
+ void Init() { /* NumIterations1 = 0; */ NumIterations2 = 0; Rating = 0; Usage = 0; RPU = 0; Speed = 0; }
+
+ void SetSum(const CTotalBenchRes &r1, const CTotalBenchRes &r2)
+ {
+ Rating = (r1.Rating + r2.Rating);
+ Usage = (r1.Usage + r2.Usage);
+ RPU = (r1.RPU + r2.RPU);
+ Speed = (r1.Speed + r2.Speed);
+ // NumIterations1 = (r1.NumIterations1 + r2.NumIterations1);
+ NumIterations2 = (r1.NumIterations2 + r2.NumIterations2);
+ }
+
+ void Generate_From_BenchInfo(const CBenchInfo &info);
+ void Mult_For_Weight(unsigned weight);
+ void Update_With_Res(const CTotalBenchRes &r);
};
-UInt64 GetCompressRating(UInt32 dictSize, UInt64 elapsedTime, UInt64 freq, UInt64 size);
-UInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt64 inSize, UInt64 numIterations);
const unsigned kBenchMinDicLogSize = 18;
-UInt64 GetBenchMemoryUsage(UInt32 numThreads, UInt32 dictionary, bool totalBench = false);
+UInt64 GetBenchMemoryUsage(UInt32 numThreads, int level, UInt64 dictionary, bool totalBench);
-struct IBenchPrintCallback
+Z7_PURE_INTERFACES_BEGIN
+DECLARE_INTERFACE(IBenchCallback)
+{
+ // virtual HRESULT SetFreq(bool showFreq, UInt64 cpuFreq) = 0;
+ virtual HRESULT SetEncodeResult(const CBenchInfo &info, bool final) = 0;
+ virtual HRESULT SetDecodeResult(const CBenchInfo &info, bool final) = 0;
+};
+
+DECLARE_INTERFACE(IBenchPrintCallback)
{
virtual void Print(const char *s) = 0;
virtual void NewLine() = 0;
virtual HRESULT CheckBreak() = 0;
};
+DECLARE_INTERFACE(IBenchFreqCallback)
+{
+ virtual HRESULT AddCpuFreq(unsigned numThreads, UInt64 freq, UInt64 usage) = 0;
+ virtual HRESULT FreqsFinished(unsigned numThreads) = 0;
+};
+Z7_PURE_INTERFACES_END
+
HRESULT Bench(
DECL_EXTERNAL_CODECS_LOC_VARS
IBenchPrintCallback *printCallback,
IBenchCallback *benchCallback,
const CObjectVector<CProperty> &props,
UInt32 numIterations,
- bool multiDict
- );
+ bool multiDict,
+ IBenchFreqCallback *freqCallback = NULL);
+
+AString GetProcessThreadsInfo(const NWindows::NSystem::CProcessAffinity &ti);
+
+void GetSysInfo(AString &s1, AString &s2);
+void GetCpuName(AString &s);
+void AddCpuFeatures(AString &s);
+
+#ifdef Z7_LARGE_PAGES
+void Add_LargePages_String(AString &s);
+#else
+// #define Add_LargePages_String
+#endif
#endif
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/DefaultName.cpp b/3rdparty/lzma/CPP/7zip/UI/Common/DefaultName.cpp
index 02f611c3d18..8c34ffc7348 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/DefaultName.cpp
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/DefaultName.cpp
@@ -20,7 +20,7 @@ static UString GetDefaultName3(const UString &fileName,
int dotPos = fileName.ReverseFind_Dot();
if (dotPos > 0)
- return fileName.Left(dotPos) + addSubExtension;
+ return fileName.Left((unsigned)dotPos) + addSubExtension;
if (addSubExtension.IsEmpty())
return fileName + L'~';
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/DefaultName.h b/3rdparty/lzma/CPP/7zip/UI/Common/DefaultName.h
index df164560275..46f6e9e67e2 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/DefaultName.h
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/DefaultName.h
@@ -1,7 +1,7 @@
// DefaultName.h
-#ifndef __DEFAULT_NAME_H
-#define __DEFAULT_NAME_H
+#ifndef ZIP7_INC_DEFAULT_NAME_H
+#define ZIP7_INC_DEFAULT_NAME_H
#include "../../../Common/MyString.h"
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/DirItem.h b/3rdparty/lzma/CPP/7zip/UI/Common/DirItem.h
index 4286b4e8db0..ae8493766fa 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/DirItem.h
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/DirItem.h
@@ -1,11 +1,17 @@
// DirItem.h
-#ifndef __DIR_ITEM_H
-#define __DIR_ITEM_H
+#ifndef ZIP7_INC_DIR_ITEM_H
+#define ZIP7_INC_DIR_ITEM_H
+
+#ifdef _WIN32
+#include "../../../Common/MyLinux.h"
+#endif
#include "../../../Common/MyString.h"
#include "../../../Windows/FileFind.h"
+#include "../../../Windows/PropVariant.h"
+#include "../../../Windows/TimeUtils.h"
#include "../../Common/UniqBlocks.h"
@@ -20,9 +26,18 @@ struct CDirItemsStat
UInt64 AltStreamsSize;
UInt64 NumErrors;
- // UInt64 GetTotalItems() const { return NumDirs + NumFiles + NumAltStreams; }
+ // UInt64 Get_NumItems() const { return NumDirs + NumFiles + NumAltStreams; }
+ UInt64 Get_NumDataItems() const { return NumFiles + NumAltStreams; }
UInt64 GetTotalBytes() const { return FilesSize + AltStreamsSize; }
+
+ bool IsEmpty() const { return
+ 0 == NumDirs
+ && 0 == NumFiles
+ && 0 == NumAltStreams
+ && 0 == FilesSize
+ && 0 == AltStreamsSize
+ && 0 == NumErrors; }
CDirItemsStat():
NumDirs(0),
@@ -34,42 +49,250 @@ struct CDirItemsStat
{}
};
-#define INTERFACE_IDirItemsCallback(x) \
- virtual HRESULT ScanError(const FString &path, DWORD systemError) x; \
- virtual HRESULT ScanProgress(const CDirItemsStat &st, const FString &path, bool isDir) x; \
-struct IDirItemsCallback
+struct CDirItemsStat2: public CDirItemsStat
{
- INTERFACE_IDirItemsCallback(=0)
+ UInt64 Anti_NumDirs;
+ UInt64 Anti_NumFiles;
+ UInt64 Anti_NumAltStreams;
+
+ // UInt64 Get_NumItems() const { return Anti_NumDirs + Anti_NumFiles + Anti_NumAltStreams + CDirItemsStat::Get_NumItems(); }
+ UInt64 Get_NumDataItems2() const { return Anti_NumFiles + Anti_NumAltStreams + CDirItemsStat::Get_NumDataItems(); }
+
+ bool IsEmpty() const { return CDirItemsStat::IsEmpty()
+ && 0 == Anti_NumDirs
+ && 0 == Anti_NumFiles
+ && 0 == Anti_NumAltStreams; }
+
+ CDirItemsStat2():
+ Anti_NumDirs(0),
+ Anti_NumFiles(0),
+ Anti_NumAltStreams(0)
+ {}
};
-struct CDirItem
+
+Z7_PURE_INTERFACES_BEGIN
+
+#define Z7_IFACEN_IDirItemsCallback(x) \
+ virtual HRESULT ScanError(const FString &path, DWORD systemError) x \
+ virtual HRESULT ScanProgress(const CDirItemsStat &st, const FString &path, bool isDir) x \
+
+Z7_IFACE_DECL_PURE(IDirItemsCallback)
+
+Z7_PURE_INTERFACES_END
+
+
+struct CArcTime
+{
+ FILETIME FT;
+ UInt16 Prec;
+ Byte Ns100;
+ bool Def;
+
+ CArcTime()
+ {
+ Clear();
+ }
+
+ void Clear()
+ {
+ FT.dwHighDateTime = FT.dwLowDateTime = 0;
+ Prec = 0;
+ Ns100 = 0;
+ Def = false;
+ }
+
+ bool IsZero() const
+ {
+ return FT.dwLowDateTime == 0 && FT.dwHighDateTime == 0 && Ns100 == 0;
+ }
+
+ int CompareWith(const CArcTime &a) const
+ {
+ const int res = CompareFileTime(&FT, &a.FT);
+ if (res != 0)
+ return res;
+ if (Ns100 < a.Ns100) return -1;
+ if (Ns100 > a.Ns100) return 1;
+ return 0;
+ }
+
+ UInt64 Get_FILETIME_as_UInt64() const
+ {
+ return (((UInt64)FT.dwHighDateTime) << 32) + FT.dwLowDateTime;
+ }
+
+ UInt32 Get_DosTime() const
+ {
+ FILETIME ft2 = FT;
+ if ((Prec == k_PropVar_TimePrec_Base + 8 ||
+ Prec == k_PropVar_TimePrec_Base + 9)
+ && Ns100 != 0)
+ {
+ UInt64 u64 = Get_FILETIME_as_UInt64();
+ // we round up even small (ns < 100ns) as FileTimeToDosTime()
+ if (u64 % 20000000 == 0)
+ {
+ u64++;
+ ft2.dwHighDateTime = (DWORD)(u64 >> 32);
+ ft2.dwHighDateTime = (DWORD)u64;
+ }
+ }
+ // FileTimeToDosTime() is expected to round up in Windows
+ UInt32 dosTime;
+ // we use simplified code with utctime->dos.
+ // do we need local time instead here?
+ NWindows::NTime::FileTime_To_DosTime(ft2, dosTime);
+ return dosTime;
+ }
+
+ int GetNumDigits() const
+ {
+ if (Prec == k_PropVar_TimePrec_Unix ||
+ Prec == k_PropVar_TimePrec_DOS)
+ return 0;
+ if (Prec == k_PropVar_TimePrec_HighPrec)
+ return 9;
+ if (Prec == k_PropVar_TimePrec_0)
+ return 7;
+ int digits = (int)Prec - (int)k_PropVar_TimePrec_Base;
+ if (digits < 0)
+ digits = 0;
+ return digits;
+ }
+
+ void Write_To_FiTime(CFiTime &dest) const
+ {
+ #ifdef _WIN32
+ dest = FT;
+ #else
+ if (FILETIME_To_timespec(FT, dest))
+ if ((Prec == k_PropVar_TimePrec_Base + 8 ||
+ Prec == k_PropVar_TimePrec_Base + 9)
+ && Ns100 != 0)
+ {
+ dest.tv_nsec += Ns100;
+ }
+ #endif
+ }
+
+ // (Def) is not set
+ void Set_From_FILETIME(const FILETIME &ft)
+ {
+ FT = ft;
+ // Prec = k_PropVar_TimePrec_CompatNTFS;
+ Prec = k_PropVar_TimePrec_Base + 7;
+ Ns100 = 0;
+ }
+
+ // (Def) is not set
+ // it set full form precision: k_PropVar_TimePrec_Base + numDigits
+ void Set_From_FiTime(const CFiTime &ts)
+ {
+ #ifdef _WIN32
+ FT = ts;
+ Prec = k_PropVar_TimePrec_Base + 7;
+ // Prec = k_PropVar_TimePrec_Base; // for debug
+ // Prec = 0; // for debug
+ Ns100 = 0;
+ #else
+ unsigned ns100;
+ FiTime_To_FILETIME_ns100(ts, FT, ns100);
+ Ns100 = (Byte)ns100;
+ Prec = k_PropVar_TimePrec_Base + 9;
+ #endif
+ }
+
+ void Set_From_Prop(const PROPVARIANT &prop)
+ {
+ FT = prop.filetime;
+ unsigned prec = 0;
+ unsigned ns100 = 0;
+ const unsigned prec_Temp = prop.wReserved1;
+ if (prec_Temp != 0
+ && prec_Temp <= k_PropVar_TimePrec_1ns
+ && prop.wReserved3 == 0)
+ {
+ const unsigned ns100_Temp = prop.wReserved2;
+ if (ns100_Temp < 100)
+ {
+ ns100 = ns100_Temp;
+ prec = prec_Temp;
+ }
+ }
+ Prec = (UInt16)prec;
+ Ns100 = (Byte)ns100;
+ Def = true;
+ }
+};
+
+
+struct CDirItem: public NWindows::NFile::NFind::CFileInfoBase
{
- UInt64 Size;
- FILETIME CTime;
- FILETIME ATime;
- FILETIME MTime;
UString Name;
- #if defined(_WIN32) && !defined(UNDER_CE)
- // UString ShortName;
+ #ifndef UNDER_CE
CByteBuffer ReparseData;
- CByteBuffer ReparseData2; // fixed (reduced) absolute links
+ #ifdef _WIN32
+ // UString ShortName;
+ CByteBuffer ReparseData2; // fixed (reduced) absolute links for WIM format
bool AreReparseData() const { return ReparseData.Size() != 0 || ReparseData2.Size() != 0; }
- #endif
+ #else
+ bool AreReparseData() const { return ReparseData.Size() != 0; }
+ #endif // _WIN32
+
+ #endif // !UNDER_CE
- UInt32 Attrib;
+ void Copy_From_FileInfoBase(const NWindows::NFile::NFind::CFileInfoBase &fi)
+ {
+ (NWindows::NFile::NFind::CFileInfoBase &)*this = fi;
+ }
+
int PhyParent;
int LogParent;
int SecureIndex;
- bool IsAltStream;
-
- CDirItem(): PhyParent(-1), LogParent(-1), SecureIndex(-1), IsAltStream(false) {}
- bool IsDir() const { return (Attrib & FILE_ATTRIBUTE_DIRECTORY) != 0 ; }
+ #ifdef _WIN32
+ #else
+ int OwnerNameIndex;
+ int OwnerGroupIndex;
+ #endif
+
+ CDirItem():
+ PhyParent(-1)
+ , LogParent(-1)
+ , SecureIndex(-1)
+ #ifdef _WIN32
+ #else
+ , OwnerNameIndex(-1)
+ , OwnerGroupIndex(-1)
+ #endif
+ {
+ }
+
+
+ CDirItem(const NWindows::NFile::NFind::CFileInfo &fi,
+ int phyParent, int logParent, int secureIndex):
+ CFileInfoBase(fi)
+ , Name(fs2us(fi.Name))
+ #if defined(_WIN32) && !defined(UNDER_CE)
+ // , ShortName(fs2us(fi.ShortName))
+ #endif
+ , PhyParent(phyParent)
+ , LogParent(logParent)
+ , SecureIndex(secureIndex)
+ #ifdef _WIN32
+ #else
+ , OwnerNameIndex(-1)
+ , OwnerGroupIndex(-1)
+ #endif
+ {}
};
+
+
class CDirItems
{
UStringVector Prefixes;
@@ -84,18 +307,26 @@ public:
CObjectVector<CDirItem> Items;
bool SymLinks;
-
bool ScanAltStreams;
-
+ bool ExcludeDirItems;
+ bool ExcludeFileItems;
+ bool ShareForWrite;
+
+ /* it must be called after anotrher checks */
+ bool CanIncludeItem(bool isDir) const
+ {
+ return isDir ? !ExcludeDirItems : !ExcludeFileItems;
+ }
+
+
CDirItemsStat Stat;
- #ifndef UNDER_CE
+ #if !defined(UNDER_CE)
HRESULT SetLinkInfo(CDirItem &dirItem, const NWindows::NFile::NFind::CFileInfo &fi,
const FString &phyPrefix);
#endif
-
- #if defined(_WIN32) && !defined(UNDER_CE)
+ #if defined(_WIN32) && !defined(UNDER_CE)
CUniqBlocks SecureBlocks;
CByteBuffer TempSecureBuf;
@@ -103,8 +334,19 @@ public:
bool ReadSecure;
HRESULT AddSecurityItem(const FString &path, int &secureIndex);
+ HRESULT FillFixedReparse();
- #endif
+ #endif
+
+ #ifndef _WIN32
+
+ C_UInt32_UString_Map OwnerNameMap;
+ C_UInt32_UString_Map OwnerGroupMap;
+ bool StoreOwnerName;
+
+ HRESULT FillDeviceSizes();
+
+ #endif
IDirItemsCallback *Callback;
@@ -124,6 +366,9 @@ public:
unsigned AddPrefix(int phyParent, int logParent, const UString &prefix);
void DeleteLastPrefix();
+
+ // HRESULT EnumerateOneDir(const FString &phyPrefix, CObjectVector<NWindows::NFile::NFind::CDirEntry> &files);
+ HRESULT EnumerateOneDir(const FString &phyPrefix, CObjectVector<NWindows::NFile::NFind::CFileInfo> &files);
HRESULT EnumerateItems2(
const FString &phyPrefix,
@@ -131,27 +376,29 @@ public:
const FStringVector &filePaths,
FStringVector *requestedPaths);
- #if defined(_WIN32) && !defined(UNDER_CE)
- void FillFixedReparse();
- #endif
-
void ReserveDown();
};
+
+
+
struct CArcItem
{
UInt64 Size;
- FILETIME MTime;
UString Name;
+ CArcTime MTime; // it can be mtime of archive file, if MTime is not defined for item in archive
bool IsDir;
bool IsAltStream;
- bool SizeDefined;
- bool MTimeDefined;
+ bool Size_Defined;
bool Censored;
UInt32 IndexInServer;
- int TimeType;
- CArcItem(): IsDir(false), IsAltStream(false), SizeDefined(false), MTimeDefined(false), Censored(false), TimeType(-1) {}
+ CArcItem():
+ IsDir(false),
+ IsAltStream(false),
+ Size_Defined(false),
+ Censored(false)
+ {}
};
#endif
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/EnumDirItems.cpp b/3rdparty/lzma/CPP/7zip/UI/Common/EnumDirItems.cpp
index 3ebf25aad8f..d536c4739aa 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/EnumDirItems.cpp
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/EnumDirItems.cpp
@@ -3,6 +3,13 @@
#include "StdAfx.h"
#include <wchar.h>
+// #include <stdio.h>
+
+#ifndef _WIN32
+#include <grp.h>
+#include <pwd.h>
+#include "../../../Common/UTFConvert.h"
+#endif
#include "../../../Common/Wildcard.h"
@@ -11,42 +18,71 @@
#include "../../../Windows/FileName.h"
#if defined(_WIN32) && !defined(UNDER_CE)
-#define _USE_SECURITY_CODE
+#define Z7_USE_SECURITY_CODE
#include "../../../Windows/SecurityUtils.h"
#endif
#include "EnumDirItems.h"
+#include "SortUtils.h"
using namespace NWindows;
using namespace NFile;
using namespace NName;
+
+static bool FindFile_KeepDots(NFile::NFind::CFileInfo &fi, const FString &path, bool followLink)
+{
+ const bool res = fi.Find(path, followLink);
+ if (!res)
+ return res;
+ if (path.IsEmpty())
+ return res;
+ // we keep name "." and "..", if it's without tail slash
+ const FChar *p = path.RightPtr(1);
+ if (*p != '.')
+ return res;
+ if (p != path.Ptr())
+ {
+ FChar c = p[-1];
+ if (!IS_PATH_SEPAR(c))
+ {
+ if (c != '.')
+ return res;
+ p--;
+ if (p != path.Ptr())
+ {
+ c = p[-1];
+ if (!IS_PATH_SEPAR(c))
+ return res;
+ }
+ }
+ }
+ fi.Name = p;
+ return res;
+}
+
+
void CDirItems::AddDirFileInfo(int phyParent, int logParent, int secureIndex,
const NFind::CFileInfo &fi)
{
- CDirItem di;
- di.Size = fi.Size;
- di.CTime = fi.CTime;
- di.ATime = fi.ATime;
- di.MTime = fi.MTime;
- di.Attrib = fi.Attrib;
- di.IsAltStream = fi.IsAltStream;
+ /*
+ CDirItem di(fi);
di.PhyParent = phyParent;
di.LogParent = logParent;
di.SecureIndex = secureIndex;
- di.Name = fs2us(fi.Name);
- #if defined(_WIN32) && !defined(UNDER_CE)
- // di.ShortName = fs2us(fi.ShortName);
- #endif
Items.Add(di);
+ */
+ VECTOR_ADD_NEW_OBJECT (Items, CDirItem(fi, phyParent, logParent, secureIndex))
if (fi.IsDir())
Stat.NumDirs++;
+ #ifdef _WIN32
else if (fi.IsAltStream)
{
Stat.NumAltStreams++;
Stat.AltStreamsSize += fi.Size;
}
+ #endif
else
{
Stat.NumFiles++;
@@ -54,8 +90,13 @@ void CDirItems::AddDirFileInfo(int phyParent, int logParent, int secureIndex,
}
}
+// (DWORD)E_FAIL
+#define DI_DEFAULT_ERROR ERROR_INVALID_FUNCTION
+
HRESULT CDirItems::AddError(const FString &path, DWORD errorCode)
{
+ if (errorCode == 0)
+ errorCode = DI_DEFAULT_ERROR;
Stat.NumErrors++;
if (Callback)
return Callback->ScanError(path, errorCode);
@@ -82,17 +123,17 @@ UString CDirItems::GetPrefixesPath(const CIntVector &parents, int index, const U
unsigned len = name.Len();
int i;
- for (i = index; i >= 0; i = parents[i])
- len += Prefixes[i].Len();
+ for (i = index; i >= 0; i = parents[(unsigned)i])
+ len += Prefixes[(unsigned)i].Len();
wchar_t *p = path.GetBuf_SetEnd(len) + len;
p -= name.Len();
wmemcpy(p, (const wchar_t *)name, name.Len());
- for (i = index; i >= 0; i = parents[i])
+ for (i = index; i >= 0; i = parents[(unsigned)i])
{
- const UString &s = Prefixes[i];
+ const UString &s = Prefixes[(unsigned)i];
p -= s.Len();
wmemcpy(p, (const wchar_t *)s, s.Len());
}
@@ -139,17 +180,24 @@ bool InitLocalPrivileges();
CDirItems::CDirItems():
SymLinks(false),
ScanAltStreams(false)
- #ifdef _USE_SECURITY_CODE
+ , ExcludeDirItems(false)
+ , ExcludeFileItems(false)
+ , ShareForWrite(false)
+ #ifdef Z7_USE_SECURITY_CODE
, ReadSecure(false)
- #endif
+ #endif
+ #ifndef _WIN32
+ , StoreOwnerName(false)
+ #endif
, Callback(NULL)
{
- #ifdef _USE_SECURITY_CODE
+ #ifdef Z7_USE_SECURITY_CODE
_saclEnabled = InitLocalPrivileges();
#endif
}
-#ifdef _USE_SECURITY_CODE
+
+#ifdef Z7_USE_SECURITY_CODE
HRESULT CDirItems::AddSecurityItem(const FString &path, int &secureIndex)
{
@@ -165,7 +213,7 @@ HRESULT CDirItems::AddSecurityItem(const FString &path, int &secureIndex)
DWORD errorCode = 0;
DWORD secureSize;
- BOOL res = ::GetFileSecurityW(fs2us(path), securInfo, (PSECURITY_DESCRIPTOR)(Byte *)TempSecureBuf, (DWORD)TempSecureBuf.Size(), &secureSize);
+ BOOL res = ::GetFileSecurityW(fs2us(path), securInfo, (PSECURITY_DESCRIPTOR)(void *)(Byte *)TempSecureBuf, (DWORD)TempSecureBuf.Size(), &secureSize);
if (res)
{
@@ -184,11 +232,11 @@ HRESULT CDirItems::AddSecurityItem(const FString &path, int &secureIndex)
else
{
TempSecureBuf.Alloc(secureSize);
- res = ::GetFileSecurityW(fs2us(path), securInfo, (PSECURITY_DESCRIPTOR)(Byte *)TempSecureBuf, (DWORD)TempSecureBuf.Size(), &secureSize);
+ res = ::GetFileSecurityW(fs2us(path), securInfo, (PSECURITY_DESCRIPTOR)(void *)(Byte *)TempSecureBuf, (DWORD)TempSecureBuf.Size(), &secureSize);
if (res)
{
if (secureSize != TempSecureBuf.Size())
- errorCode = ERROR_INVALID_FUNCTION;;
+ errorCode = ERROR_INVALID_FUNCTION;
}
else
errorCode = GetLastError();
@@ -198,103 +246,224 @@ HRESULT CDirItems::AddSecurityItem(const FString &path, int &secureIndex)
if (res)
{
- secureIndex = SecureBlocks.AddUniq(TempSecureBuf, secureSize);
+ secureIndex = (int)SecureBlocks.AddUniq(TempSecureBuf, secureSize);
return S_OK;
}
- if (errorCode == 0)
- errorCode = ERROR_INVALID_FUNCTION;
return AddError(path, errorCode);
}
-#endif
+#endif // Z7_USE_SECURITY_CODE
-HRESULT CDirItems::EnumerateDir(int phyParent, int logParent, const FString &phyPrefix)
+
+HRESULT CDirItems::EnumerateOneDir(const FString &phyPrefix, CObjectVector<NFind::CFileInfo> &files)
{
- RINOK(ScanProgress(phyPrefix));
+ NFind::CEnumerator enumerator;
+ // printf("\n enumerator.SetDirPrefix(phyPrefix) \n");
+
+ enumerator.SetDirPrefix(phyPrefix);
+
+ #ifdef _WIN32
+
+ NFind::CFileInfo fi;
- NFind::CEnumerator enumerator(phyPrefix + FCHAR_ANY_MASK);
for (unsigned ttt = 0; ; ttt++)
{
- NFind::CFileInfo fi;
bool found;
if (!enumerator.Next(fi, found))
+ return AddError(phyPrefix);
+ if (!found)
+ return S_OK;
+ files.Add(fi);
+ if (Callback && (ttt & kScanProgressStepMask) == kScanProgressStepMask)
+ {
+ RINOK(ScanProgress(phyPrefix))
+ }
+ }
+
+ #else // _WIN32
+
+ // enumerator.SolveLinks = !SymLinks;
+
+ CObjectVector<NFind::CDirEntry> entries;
+
+ for (unsigned ttt = 0; ; ttt++)
+ {
+ bool found;
+ NFind::CDirEntry de;
+ if (!enumerator.Next(de, found))
{
return AddError(phyPrefix);
}
if (!found)
- return S_OK;
+ break;
+ entries.Add(de);
+ }
+
+ FOR_VECTOR(i, entries)
+ {
+ const NFind::CDirEntry &de = entries[i];
+ NFind::CFileInfo fi;
+ if (!enumerator.Fill_FileInfo(de, fi, !SymLinks))
+ // if (!fi.Find_AfterEnumerator(path))
+ {
+ const FString path = phyPrefix + de.Name;
+ {
+ RINOK(AddError(path))
+ continue;
+ }
+ }
+
+ files.Add(fi);
+
+ if (Callback && (i & kScanProgressStepMask) == kScanProgressStepMask)
+ {
+ RINOK(ScanProgress(phyPrefix))
+ }
+ }
+
+ return S_OK;
+
+ #endif // _WIN32
+}
+
+
+
+
+HRESULT CDirItems::EnumerateDir(int phyParent, int logParent, const FString &phyPrefix)
+{
+ RINOK(ScanProgress(phyPrefix))
+
+ CObjectVector<NFind::CFileInfo> files;
+ RINOK(EnumerateOneDir(phyPrefix, files))
+ FOR_VECTOR (i, files)
+ {
+ #ifdef _WIN32
+ const NFind::CFileInfo &fi = files[i];
+ #else
+ const NFind::CFileInfo &fi = files[i];
+ /*
+ NFind::CFileInfo fi;
+ {
+ const NFind::CDirEntry &di = files[i];
+ const FString path = phyPrefix + di.Name;
+ if (!fi.Find_AfterEnumerator(path))
+ {
+ RINOK(AddError(path));
+ continue;
+ }
+ fi.Name = di.Name;
+ }
+ */
+ #endif
+
+ if (CanIncludeItem(fi.IsDir()))
+ {
int secureIndex = -1;
- #ifdef _USE_SECURITY_CODE
+ #ifdef Z7_USE_SECURITY_CODE
if (ReadSecure)
{
- RINOK(AddSecurityItem(phyPrefix + fi.Name, secureIndex));
+ RINOK(AddSecurityItem(phyPrefix + fi.Name, secureIndex))
}
#endif
-
AddDirFileInfo(phyParent, logParent, secureIndex, fi);
+ }
- if (Callback && (ttt & kScanProgressStepMask) == kScanProgressStepMask)
+ if (Callback && (i & kScanProgressStepMask) == kScanProgressStepMask)
{
- RINOK(ScanProgress(phyPrefix));
+ RINOK(ScanProgress(phyPrefix))
}
if (fi.IsDir())
{
const FString name2 = fi.Name + FCHAR_PATH_SEPARATOR;
unsigned parent = AddPrefix(phyParent, logParent, fs2us(name2));
- RINOK(EnumerateDir(parent, parent, phyPrefix + name2));
+ RINOK(EnumerateDir((int)parent, (int)parent, phyPrefix + name2))
}
}
+ return S_OK;
}
+
+/*
+EnumerateItems2()
+ const FStringVector &filePaths - are path without tail slashes.
+ All dir prefixes of filePaths will be not stores in logical paths
+fix it: we can scan AltStream also.
+*/
+
+#ifdef _WIN32
+// #define FOLLOW_LINK_PARAM
+// #define FOLLOW_LINK_PARAM2
+#define FOLLOW_LINK_PARAM , (!SymLinks)
+#define FOLLOW_LINK_PARAM2 , (!dirItems.SymLinks)
+#else
+#define FOLLOW_LINK_PARAM , (!SymLinks)
+#define FOLLOW_LINK_PARAM2 , (!dirItems.SymLinks)
+#endif
+
HRESULT CDirItems::EnumerateItems2(
const FString &phyPrefix,
const UString &logPrefix,
const FStringVector &filePaths,
FStringVector *requestedPaths)
{
- int phyParent = phyPrefix.IsEmpty() ? -1 : AddPrefix(-1, -1, fs2us(phyPrefix));
- int logParent = logPrefix.IsEmpty() ? -1 : AddPrefix(-1, -1, logPrefix);
+ const int phyParent = phyPrefix.IsEmpty() ? -1 : (int)AddPrefix(-1, -1, fs2us(phyPrefix));
+ const int logParent = logPrefix.IsEmpty() ? -1 : (int)AddPrefix(-1, -1, logPrefix);
+
+ #ifdef _WIN32
+ const bool phyPrefix_isAltStreamPrefix =
+ NFile::NName::IsAltStreamPrefixWithColon(fs2us(phyPrefix));
+ #endif
FOR_VECTOR (i, filePaths)
{
const FString &filePath = filePaths[i];
NFind::CFileInfo fi;
const FString phyPath = phyPrefix + filePath;
- if (!fi.Find(phyPath))
+ if (!FindFile_KeepDots(fi, phyPath FOLLOW_LINK_PARAM))
{
- RINOK(AddError(phyPath));
+ RINOK(AddError(phyPath))
continue;
}
if (requestedPaths)
requestedPaths->Add(phyPath);
- int delimiter = filePath.ReverseFind_PathSepar();
+ const int delimiter = filePath.ReverseFind_PathSepar();
FString phyPrefixCur;
int phyParentCur = phyParent;
if (delimiter >= 0)
{
- phyPrefixCur.SetFrom(filePath, delimiter + 1);
- phyParentCur = AddPrefix(phyParent, logParent, fs2us(phyPrefixCur));
+ phyPrefixCur.SetFrom(filePath, (unsigned)(delimiter + 1));
+ phyParentCur = (int)AddPrefix(phyParent, logParent, fs2us(phyPrefixCur));
}
+ if (CanIncludeItem(fi.IsDir()))
+ {
int secureIndex = -1;
- #ifdef _USE_SECURITY_CODE
+ #ifdef Z7_USE_SECURITY_CODE
if (ReadSecure)
{
- RINOK(AddSecurityItem(phyPath, secureIndex));
+ RINOK(AddSecurityItem(phyPath, secureIndex))
}
#endif
-
+ #ifdef _WIN32
+ if (phyPrefix_isAltStreamPrefix && fi.IsAltStream)
+ {
+ const int pos = fi.Name.Find(FChar(':'));
+ if (pos >= 0)
+ fi.Name.DeleteFrontal((unsigned)pos + 1);
+ }
+ #endif
AddDirFileInfo(phyParentCur, logParent, secureIndex, fi);
+ }
if (fi.IsDir())
{
const FString name2 = fi.Name + FCHAR_PATH_SEPARATOR;
- unsigned parent = AddPrefix(phyParentCur, logParent, fs2us(name2));
- RINOK(EnumerateDir(parent, parent, phyPrefix + phyPrefixCur + name2));
+ const unsigned parent = AddPrefix(phyParentCur, logParent, fs2us(name2));
+ RINOK(EnumerateDir((int)parent, (int)parent, phyPrefix + phyPrefixCur + name2))
}
}
@@ -305,34 +474,46 @@ HRESULT CDirItems::EnumerateItems2(
-
-
static HRESULT EnumerateDirItems(
const NWildcard::CCensorNode &curNode,
- int phyParent, int logParent, const FString &phyPrefix,
- const UStringVector &addArchivePrefix,
+ const int phyParent, const int logParent,
+ const FString &phyPrefix,
+ const UStringVector &addParts, // additional parts from curNode
CDirItems &dirItems,
bool enterToSubFolders);
+
+/* EnumerateDirItems_Spec()
+ adds new Dir item prefix, and enumerates dir items,
+ then it can remove that Dir item prefix, if there are no items in that dir.
+*/
+
+
+/*
+ EnumerateDirItems_Spec()
+ it's similar to EnumerateDirItems, but phyPrefix doesn't include (curFolderName)
+*/
+
static HRESULT EnumerateDirItems_Spec(
const NWildcard::CCensorNode &curNode,
- int phyParent, int logParent, const FString &curFolderName,
- const FString &phyPrefix,
- const UStringVector &addArchivePrefix,
+ const int phyParent, const int logParent, const FString &curFolderName,
+ const FString &phyPrefix, // without (curFolderName)
+ const UStringVector &addParts, // (curNode + addParts) includes (curFolderName)
CDirItems &dirItems,
bool enterToSubFolders)
{
const FString name2 = curFolderName + FCHAR_PATH_SEPARATOR;
- unsigned parent = dirItems.AddPrefix(phyParent, logParent, fs2us(name2));
- unsigned numItems = dirItems.Items.Size();
+ const unsigned parent = dirItems.AddPrefix(phyParent, logParent, fs2us(name2));
+ const unsigned numItems = dirItems.Items.Size();
HRESULT res = EnumerateDirItems(
- curNode, parent, parent, phyPrefix + name2,
- addArchivePrefix, dirItems, enterToSubFolders);
+ curNode, (int)parent, (int)parent, phyPrefix + name2,
+ addParts, dirItems, enterToSubFolders);
if (numItems == dirItems.Items.Size())
dirItems.DeleteLastPrefix();
return res;
}
+
#ifndef UNDER_CE
#ifdef _WIN32
@@ -340,136 +521,222 @@ static HRESULT EnumerateDirItems_Spec(
static HRESULT EnumerateAltStreams(
const NFind::CFileInfo &fi,
const NWildcard::CCensorNode &curNode,
- int phyParent, int logParent, const FString &fullPath,
- const UStringVector &addArchivePrefix, // prefix from curNode
+ const int phyParent, const int logParent,
+ const FString &phyPath, // with (fi.Name), without tail slash for folders
+ const UStringVector &addParts, // with (fi.Name), prefix parts from curNode
+ bool addAllSubStreams,
CDirItems &dirItems)
{
- NFind::CStreamEnumerator enumerator(fullPath);
+ // we don't use (ExcludeFileItems) rules for AltStreams
+ // if (dirItems.ExcludeFileItems) return S_OK;
+
+ NFind::CStreamEnumerator enumerator(phyPath);
for (;;)
{
NFind::CStreamInfo si;
bool found;
if (!enumerator.Next(si, found))
{
- return dirItems.AddError(fullPath + FTEXT(":*")); // , (DWORD)E_FAIL
+ return dirItems.AddError(phyPath + FTEXT(":*")); // , (DWORD)E_FAIL
}
if (!found)
return S_OK;
if (si.IsMainStream())
continue;
- UStringVector addArchivePrefixNew = addArchivePrefix;
- UString reducedName = si.GetReducedName();
- addArchivePrefixNew.Back() += reducedName;
- if (curNode.CheckPathToRoot(false, addArchivePrefixNew, true))
+ UStringVector parts = addParts;
+ const UString reducedName = si.GetReducedName();
+ parts.Back() += reducedName;
+ if (curNode.CheckPathToRoot(false, parts, true))
continue;
+ if (!addAllSubStreams)
+ if (!curNode.CheckPathToRoot(true, parts, true))
+ continue;
+
NFind::CFileInfo fi2 = fi;
fi2.Name += us2fs(reducedName);
fi2.Size = si.Size;
- fi2.Attrib &= ~FILE_ATTRIBUTE_DIRECTORY;
+ fi2.Attrib &= ~(DWORD)(FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_REPARSE_POINT);
fi2.IsAltStream = true;
dirItems.AddDirFileInfo(phyParent, logParent, -1, fi2);
}
}
-#endif
+#endif // _WIN32
+
+
+/* We get Reparse data and parse it.
+ If there is Reparse error, we free dirItem.Reparse data.
+ Do we need to work with empty reparse data?
+*/
HRESULT CDirItems::SetLinkInfo(CDirItem &dirItem, const NFind::CFileInfo &fi,
const FString &phyPrefix)
{
- if (!SymLinks || !fi.HasReparsePoint())
+ if (!SymLinks)
return S_OK;
+
+ #ifdef _WIN32
+ if (!fi.HasReparsePoint() || fi.IsAltStream)
+ #else // _WIN32
+ if (!fi.IsPosixLink())
+ #endif // _WIN32
+ return S_OK;
+
const FString path = phyPrefix + fi.Name;
CByteBuffer &buf = dirItem.ReparseData;
if (NIO::GetReparseData(path, buf))
{
- CReparseAttr attr;
- if (attr.Parse(buf, buf.Size()))
- return S_OK;
+ // if (dirItem.ReparseData.Size() != 0)
+ Stat.FilesSize -= fi.Size;
+ return S_OK;
}
+
DWORD res = ::GetLastError();
buf.Free();
- return AddError(path , res);
+ return AddError(path, res);
}
-#endif
+#endif // UNDER_CE
+
+
static HRESULT EnumerateForItem(
- NFind::CFileInfo &fi,
+ const NFind::CFileInfo &fi,
const NWildcard::CCensorNode &curNode,
- int phyParent, int logParent, const FString &phyPrefix,
- const UStringVector &addArchivePrefix, // prefix from curNode
+ const int phyParent, const int logParent, const FString &phyPrefix,
+ const UStringVector &addParts, // additional parts from curNode, without (fi.Name)
CDirItems &dirItems,
bool enterToSubFolders)
{
const UString name = fs2us(fi.Name);
- bool enterToSubFolders2 = enterToSubFolders;
- UStringVector addArchivePrefixNew = addArchivePrefix;
- addArchivePrefixNew.Add(name);
- {
- UStringVector addArchivePrefixNewTemp(addArchivePrefixNew);
- if (curNode.CheckPathToRoot(false, addArchivePrefixNewTemp, !fi.IsDir()))
- return S_OK;
- }
- int dirItemIndex = -1;
+ UStringVector newParts = addParts;
+ newParts.Add(name);
- if (curNode.CheckPathToRoot(true, addArchivePrefixNew, !fi.IsDir()))
+ // check the path in exclude rules
+ if (curNode.CheckPathToRoot(false, newParts, !fi.IsDir()))
+ return S_OK;
+
+ #if !defined(UNDER_CE)
+ int dirItemIndex = -1;
+ #if defined(_WIN32)
+ bool addAllSubStreams = false;
+ bool needAltStreams = true;
+ #endif // _WIN32
+ #endif // !defined(UNDER_CE)
+
+ // check the path in inlcude rules
+ if (curNode.CheckPathToRoot(true, newParts, !fi.IsDir()))
{
- int secureIndex = -1;
- #ifdef _USE_SECURITY_CODE
- if (dirItems.ReadSecure)
+ #if !defined(UNDER_CE)
+ // dirItemIndex = (int)dirItems.Items.Size();
+ #if defined(_WIN32)
+ // we will not check include rules for substreams.
+ addAllSubStreams = true;
+ #endif // _WIN32
+ #endif // !defined(UNDER_CE)
+
+ if (dirItems.CanIncludeItem(fi.IsDir()))
{
- RINOK(dirItems.AddSecurityItem(phyPrefix + fi.Name, secureIndex));
- }
+ int secureIndex = -1;
+ #ifdef Z7_USE_SECURITY_CODE
+ if (dirItems.ReadSecure)
+ {
+ RINOK(dirItems.AddSecurityItem(phyPrefix + fi.Name, secureIndex))
+ }
#endif
+ #if !defined(UNDER_CE)
+ dirItemIndex = (int)dirItems.Items.Size();
+ #endif // !defined(UNDER_CE)
+ dirItems.AddDirFileInfo(phyParent, logParent, secureIndex, fi);
+ }
+ else
+ {
+ #if defined(_WIN32) && !defined(UNDER_CE)
+ needAltStreams = false;
+ #endif
+ }
- dirItemIndex = dirItems.Items.Size();
- dirItems.AddDirFileInfo(phyParent, logParent, secureIndex, fi);
if (fi.IsDir())
- enterToSubFolders2 = true;
+ enterToSubFolders = true;
}
- #ifndef UNDER_CE
- if (dirItems.ScanAltStreams)
- {
- RINOK(EnumerateAltStreams(fi, curNode, phyParent, logParent,
- phyPrefix + fi.Name,
- addArchivePrefixNew, dirItems));
- }
+ #if !defined(UNDER_CE)
+
+ // we don't scan AltStreams for link files
if (dirItemIndex >= 0)
{
- CDirItem &dirItem = dirItems.Items[dirItemIndex];
- RINOK(dirItems.SetLinkInfo(dirItem, fi, phyPrefix));
+ CDirItem &dirItem = dirItems.Items[(unsigned)dirItemIndex];
+ RINOK(dirItems.SetLinkInfo(dirItem, fi, phyPrefix))
if (dirItem.ReparseData.Size() != 0)
return S_OK;
}
- #endif
+ #if defined(_WIN32)
+ if (needAltStreams && dirItems.ScanAltStreams)
+ {
+ RINOK(EnumerateAltStreams(fi, curNode, phyParent, logParent,
+ phyPrefix + fi.Name, // with (fi.Name)
+ newParts, // with (fi.Name)
+ addAllSubStreams,
+ dirItems))
+ }
+ #endif
+
+ #endif // !defined(UNDER_CE)
+
+
+ #ifndef _WIN32
+ if (!fi.IsPosixLink()) // posix link can follow to dir
+ #endif
if (!fi.IsDir())
return S_OK;
-
- const NWildcard::CCensorNode *nextNode = 0;
- if (addArchivePrefix.IsEmpty())
+
+ const NWildcard::CCensorNode *nextNode = NULL;
+
+ if (addParts.IsEmpty())
{
int index = curNode.FindSubNode(name);
if (index >= 0)
- nextNode = &curNode.SubNodes[index];
+ {
+ nextNode = &curNode.SubNodes[(unsigned)index];
+ newParts.Clear();
+ }
}
- if (!enterToSubFolders2 && nextNode == 0)
- return S_OK;
-
- addArchivePrefixNew = addArchivePrefix;
- if (nextNode == 0)
+
+ if (!nextNode)
{
+ if (!enterToSubFolders)
+ return S_OK;
+
+ #ifndef _WIN32
+ if (fi.IsPosixLink())
+ {
+ // here we can try to resolve posix link
+ // if the link to dir, then can we follow it
+ return S_OK; // we don't follow posix link
+ }
+ #else
+ if (dirItems.SymLinks && fi.HasReparsePoint())
+ {
+ /* 20.03: in SymLinks mode: we don't enter to directory that
+ has reparse point and has no CCensorNode
+ NOTE: (curNode and parent nodes) still can have wildcard rules
+ to include some items of target directory (of reparse point),
+ but we ignore these rules here.
+ */
+ return S_OK;
+ }
+ #endif
nextNode = &curNode;
- addArchivePrefixNew.Add(name);
}
return EnumerateDirItems_Spec(
- *nextNode, phyParent, logParent, fi.Name, phyPrefix,
- addArchivePrefixNew,
+ *nextNode, phyParent, logParent, fi.Name,
+ phyPrefix, // without (fi.Name)
+ newParts, // relative to (*nextNode). (*nextNode + newParts) includes (fi.Name)
dirItems,
- enterToSubFolders2);
+ enterToSubFolders);
}
@@ -488,10 +755,13 @@ static bool CanUseFsDirect(const NWildcard::CCensorNode &curNode)
/* Windows doesn't support file name with wildcard
But if another system supports file name with wildcard,
- and wildcard mode is disabled, we can ignore wildcard in name */
+ and wildcard mode is disabled, we can ignore wildcard in name
+ */
/*
+ #ifndef _WIN32
if (!item.WildcardParsing)
continue;
+ #endif
*/
if (DoesNameContainWildcard(name))
return false;
@@ -507,26 +777,33 @@ static bool IsVirtualFsFolder(const FString &prefix, const UString &name)
UString s = fs2us(prefix);
s += name;
s.Add_PathSepar();
+ // it returns (true) for non real FS folder path like - "\\SERVER\"
return IsPathSepar(s[0]) && GetRootPrefixSize(s) == 0;
}
#endif
+
+
static HRESULT EnumerateDirItems(
const NWildcard::CCensorNode &curNode,
- int phyParent, int logParent, const FString &phyPrefix,
- const UStringVector &addArchivePrefix, // prefix from curNode
+ const int phyParent, const int logParent, const FString &phyPrefix,
+ const UStringVector &addParts, // prefix from curNode including
CDirItems &dirItems,
bool enterToSubFolders)
{
if (!enterToSubFolders)
+ {
+ /* if there are IncludeItems censor rules that affect items in subdirs,
+ then we will enter to all subfolders */
if (curNode.NeedCheckSubDirs())
enterToSubFolders = true;
+ }
- RINOK(dirItems.ScanProgress(phyPrefix));
+ RINOK(dirItems.ScanProgress(phyPrefix))
// try direct_names case at first
- if (addArchivePrefix.IsEmpty() && !enterToSubFolders)
+ if (addParts.IsEmpty() && !enterToSubFolders)
{
if (CanUseFsDirect(curNode))
{
@@ -541,11 +818,20 @@ static HRESULT EnumerateDirItems(
const UString &name = item.PathParts.Front();
FString fullPath = phyPrefix + us2fs(name);
+ /*
+ // not possible now
+ if (!item.ForDir && !item.ForFile)
+ {
+ RINOK(dirItems.AddError(fullPath, ERROR_INVALID_PARAMETER));
+ continue;
+ }
+ */
+
#if defined(_WIN32) && !defined(UNDER_CE)
bool needAltStreams = true;
#endif
- #ifdef _USE_SECURITY_CODE
+ #ifdef Z7_USE_SECURITY_CODE
bool needSecurity = true;
#endif
@@ -565,12 +851,12 @@ static HRESULT EnumerateDirItems(
/*
// do we need to ignore security info for "\\" folder ?
- #ifdef _USE_SECURITY_CODE
+ #ifdef Z7_USE_SECURITY_CODE
needSecurity = false;
#endif
*/
- fullPath = FCHAR_PATH_SEPARATOR;
+ fullPath = CHAR_PATH_SEPARATOR;
}
#if defined(_WIN32) && !defined(UNDER_CE)
else if (item.IsDriveItem())
@@ -591,16 +877,27 @@ static HRESULT EnumerateDirItems(
}
else
#endif
- if (!fi.Find(fullPath))
+ if (!FindFile_KeepDots(fi, fullPath FOLLOW_LINK_PARAM2))
{
- RINOK(dirItems.AddError(fullPath));
+ RINOK(dirItems.AddError(fullPath))
continue;
}
- bool isDir = fi.IsDir();
- if (isDir && !item.ForDir || !isDir && !item.ForFile)
+ /*
+ #ifdef _WIN32
+ #define MY_ERROR_IS_DIR ERROR_FILE_NOT_FOUND
+ #define MY_ERROR_NOT_DIR DI_DEFAULT_ERROR
+ #else
+ #define MY_ERROR_IS_DIR EISDIR
+ #define MY_ERROR_NOT_DIR ENOTDIR
+ #endif
+ */
+
+ const bool isDir = fi.IsDir();
+ if (isDir ? !item.ForDir : !item.ForFile)
{
- RINOK(dirItems.AddError(fullPath, (DWORD)E_FAIL));
+ // RINOK(dirItems.AddError(fullPath, isDir ? MY_ERROR_IS_DIR: MY_ERROR_NOT_DIR));
+ RINOK(dirItems.AddError(fullPath, DI_DEFAULT_ERROR))
continue;
}
{
@@ -610,65 +907,90 @@ static HRESULT EnumerateDirItems(
continue;
}
+
+ if (dirItems.CanIncludeItem(fi.IsDir()))
+ {
int secureIndex = -1;
- #ifdef _USE_SECURITY_CODE
+ #ifdef Z7_USE_SECURITY_CODE
if (needSecurity && dirItems.ReadSecure)
{
- RINOK(dirItems.AddSecurityItem(fullPath, secureIndex));
+ RINOK(dirItems.AddSecurityItem(fullPath, secureIndex))
}
#endif
dirItems.AddDirFileInfo(phyParent, logParent, secureIndex, fi);
- #ifndef UNDER_CE
+ // we don't scan AltStreams for link files
+
+ #if !defined(UNDER_CE)
{
CDirItem &dirItem = dirItems.Items.Back();
- RINOK(dirItems.SetLinkInfo(dirItem, fi, phyPrefix));
+ RINOK(dirItems.SetLinkInfo(dirItem, fi, phyPrefix))
if (dirItem.ReparseData.Size() != 0)
- {
- if (fi.IsAltStream)
- dirItems.Stat.AltStreamsSize -= fi.Size;
- else
- dirItems.Stat.FilesSize -= fi.Size;
continue;
- }
}
- #endif
-
-
- #ifndef UNDER_CE
+
+ #if defined(_WIN32)
if (needAltStreams && dirItems.ScanAltStreams)
{
UStringVector pathParts;
pathParts.Add(fs2us(fi.Name));
RINOK(EnumerateAltStreams(fi, curNode, phyParent, logParent,
- fullPath, pathParts, dirItems));
+ fullPath, // including (name)
+ pathParts, // including (fi.Name)
+ true, /* addAllSubStreams */
+ dirItems))
}
- #endif
+ #endif // defined(_WIN32)
+
+ #endif // !defined(UNDER_CE)
+ }
+
+ #ifndef _WIN32
+ if (!fi.IsPosixLink()) // posix link can follow to dir
+ #endif
if (!isDir)
continue;
-
- UStringVector addArchivePrefixNew;
- const NWildcard::CCensorNode *nextNode = 0;
+
+ UStringVector newParts;
+ const NWildcard::CCensorNode *nextNode = NULL;
int index = curNode.FindSubNode(name);
if (index >= 0)
{
- for (int t = needEnterVector.Size(); t <= index; t++)
+ for (int t = (int)needEnterVector.Size(); t <= index; t++)
needEnterVector.Add(true);
- needEnterVector[index] = false;
- nextNode = &curNode.SubNodes[index];
+ needEnterVector[(unsigned)index] = false;
+ nextNode = &curNode.SubNodes[(unsigned)index];
}
else
{
+ #ifndef _WIN32
+ if (fi.IsPosixLink())
+ {
+ // here we can try to resolve posix link
+ // if the link to dir, then can we follow it
+ continue; // we don't follow posix link
+ }
+ #else
+ if (dirItems.SymLinks)
+ {
+ if (fi.HasReparsePoint())
+ {
+ /* 20.03: in SymLinks mode: we don't enter to directory that
+ has reparse point and has no CCensorNode */
+ continue;
+ }
+ }
+ #endif
nextNode = &curNode;
- addArchivePrefixNew.Add(name); // don't change it to fi.Name. It's for shortnames support
+ newParts.Add(name); // don't change it to fi.Name. It's for shortnames support
}
RINOK(EnumerateDirItems_Spec(*nextNode, phyParent, logParent, fi.Name, phyPrefix,
- addArchivePrefixNew, dirItems, true));
+ newParts, dirItems, true))
}
-
+
for (i = 0; i < curNode.SubNodes.Size(); i++)
{
if (i < needEnterVector.Size())
@@ -678,20 +1000,23 @@ static HRESULT EnumerateDirItems(
FString fullPath = phyPrefix + us2fs(nextNode.Name);
NFind::CFileInfo fi;
- if (phyPrefix.IsEmpty())
+ if (nextNode.Name.IsEmpty())
{
- {
- if (nextNode.Name.IsEmpty())
- fullPath = FCHAR_PATH_SEPARATOR;
- #ifdef _WIN32
- else if (NWildcard::IsDriveColonName(nextNode.Name))
- fullPath.Add_PathSepar();
- #endif
- }
+ if (phyPrefix.IsEmpty())
+ fullPath = CHAR_PATH_SEPARATOR;
}
+ #ifdef _WIN32
+ else if(phyPrefix.IsEmpty()
+ || (phyPrefix.Len() == NName::kSuperPathPrefixSize
+ && IsSuperPath(phyPrefix)))
+ {
+ if (NWildcard::IsDriveColonName(nextNode.Name))
+ fullPath.Add_PathSepar();
+ }
+ #endif
// we don't want to call fi.Find() for root folder or virtual folder
- if (phyPrefix.IsEmpty() && nextNode.Name.IsEmpty()
+ if ((phyPrefix.IsEmpty() && nextNode.Name.IsEmpty())
#if defined(_WIN32) && !defined(UNDER_CE)
|| IsVirtualFsFolder(phyPrefix, nextNode.Name)
#endif
@@ -702,23 +1027,23 @@ static HRESULT EnumerateDirItems(
}
else
{
- if (!fi.Find(fullPath))
+ if (!FindFile_KeepDots(fi, fullPath FOLLOW_LINK_PARAM2))
{
if (!nextNode.AreThereIncludeItems())
continue;
- RINOK(dirItems.AddError(fullPath));
+ RINOK(dirItems.AddError(fullPath))
continue;
}
if (!fi.IsDir())
{
- RINOK(dirItems.AddError(fullPath, (DWORD)E_FAIL));
+ RINOK(dirItems.AddError(fullPath, DI_DEFAULT_ERROR))
continue;
}
}
RINOK(EnumerateDirItems_Spec(nextNode, phyParent, logParent, fi.Name, phyPrefix,
- UStringVector(), dirItems, false));
+ UStringVector(), dirItems, false))
}
return S_OK;
@@ -764,7 +1089,7 @@ static HRESULT EnumerateDirItems(
fi.Name = driveName;
RINOK(EnumerateForItem(fi, curNode, phyParent, logParent, phyPrefix,
- addArchivePrefix, dirItems, enterToSubFolders));
+ addParts, dirItems, enterToSubFolders))
}
return S_OK;
}
@@ -773,41 +1098,81 @@ static HRESULT EnumerateDirItems(
#endif
#endif
- NFind::CEnumerator enumerator(phyPrefix + FCHAR_ANY_MASK);
- for (unsigned ttt = 0; ; ttt++)
+
+ CObjectVector<NFind::CFileInfo> files;
+
+ // for (int y = 0; y < 1; y++)
{
- NFind::CFileInfo fi;
- bool found;
- if (!enumerator.Next(fi, found))
+ // files.Clear();
+ RINOK(dirItems.EnumerateOneDir(phyPrefix, files))
+ /*
+ FOR_VECTOR (i, files)
+ {
+ #ifdef _WIN32
+ // const NFind::CFileInfo &fi = files[i];
+ #else
+ NFind::CFileInfo &fi = files[i];
{
- RINOK(dirItems.AddError(phyPrefix));
- break;
+ const NFind::CFileInfo &di = files[i];
+ const FString path = phyPrefix + di.Name;
+ if (!fi.Find_AfterEnumerator(path))
+ {
+ RINOK(dirItems.AddError(path));
+ continue;
+ }
+ fi.Name = di.Name;
}
- if (!found)
- break;
+ #endif
+
+ }
+ */
+ }
- if (dirItems.Callback && (ttt & kScanProgressStepMask) == kScanProgressStepMask)
+ FOR_VECTOR (i, files)
+ {
+ #ifdef _WIN32
+ const NFind::CFileInfo &fi = files[i];
+ #else
+ const NFind::CFileInfo &fi = files[i];
+ /*
+ NFind::CFileInfo fi;
{
- RINOK(dirItems.ScanProgress(phyPrefix));
+ const NFind::CDirEntry &di = files[i];
+ const FString path = phyPrefix + di.Name;
+ if (!fi.Find_AfterEnumerator(path))
+ {
+ RINOK(dirItems.AddError(path));
+ continue;
+ }
+ fi.Name = di.Name;
}
+ */
+ #endif
RINOK(EnumerateForItem(fi, curNode, phyParent, logParent, phyPrefix,
- addArchivePrefix, dirItems, enterToSubFolders));
+ addParts, dirItems, enterToSubFolders))
+ if (dirItems.Callback && (i & kScanProgressStepMask) == kScanProgressStepMask)
+ {
+ RINOK(dirItems.ScanProgress(phyPrefix))
+ }
}
return S_OK;
}
+
+
+
HRESULT EnumerateItems(
const NWildcard::CCensor &censor,
const NWildcard::ECensorPathMode pathMode,
- const UString &addPathPrefix,
+ const UString &addPathPrefix, // prefix that will be added to Logical Path
CDirItems &dirItems)
{
FOR_VECTOR (i, censor.Pairs)
{
const NWildcard::CPair &pair = censor.Pairs[i];
- int phyParent = pair.Prefix.IsEmpty() ? -1 : dirItems.AddPrefix(-1, -1, pair.Prefix);
+ const int phyParent = pair.Prefix.IsEmpty() ? -1 : (int)dirItems.AddPrefix(-1, -1, pair.Prefix);
int logParent = -1;
if (pathMode == NWildcard::k_AbsPath)
@@ -815,44 +1180,117 @@ HRESULT EnumerateItems(
else
{
if (!addPathPrefix.IsEmpty())
- logParent = dirItems.AddPrefix(-1, -1, addPathPrefix);
+ logParent = (int)dirItems.AddPrefix(-1, -1, addPathPrefix);
}
RINOK(EnumerateDirItems(pair.Head, phyParent, logParent, us2fs(pair.Prefix), UStringVector(),
dirItems,
false // enterToSubFolders
- ));
+ ))
}
dirItems.ReserveDown();
- #if defined(_WIN32) && !defined(UNDER_CE)
- dirItems.FillFixedReparse();
- #endif
+ #if defined(_WIN32) && !defined(UNDER_CE)
+ RINOK(dirItems.FillFixedReparse())
+ #endif
+
+ #ifndef _WIN32
+ RINOK(dirItems.FillDeviceSizes())
+ #endif
return S_OK;
}
+
#if defined(_WIN32) && !defined(UNDER_CE)
-void CDirItems::FillFixedReparse()
+HRESULT CDirItems::FillFixedReparse()
{
- /* imagex/WIM reduces absolute pathes in links (raparse data),
- if we archive non root folder. We do same thing here */
-
- if (!SymLinks)
- return;
-
FOR_VECTOR(i, Items)
{
CDirItem &item = Items[i];
+
+ if (!SymLinks)
+ {
+ // continue; // for debug
+ if (!item.Has_Attrib_ReparsePoint())
+ continue;
+
+ // if (item.IsDir()) continue;
+
+ const FString phyPath = GetPhyPath(i);
+
+ NFind::CFileInfo fi;
+ if (fi.Fill_From_ByHandleFileInfo(phyPath)) // item.IsDir()
+ {
+ item.Size = fi.Size;
+ item.CTime = fi.CTime;
+ item.ATime = fi.ATime;
+ item.MTime = fi.MTime;
+ item.Attrib = fi.Attrib;
+ continue;
+ }
+
+ /*
+ // we request properties of target file instead of properies of symbolic link
+ // here we also can manually parse unsupported links (like WSL links)
+ NIO::CInFile inFile;
+ if (inFile.Open(phyPath))
+ {
+ BY_HANDLE_FILE_INFORMATION info;
+ if (inFile.GetFileInformation(&info))
+ {
+ // Stat.FilesSize doesn't contain item.Size already
+ // Stat.FilesSize -= item.Size;
+ item.Size = (((UInt64)info.nFileSizeHigh) << 32) + info.nFileSizeLow;
+ Stat.FilesSize += item.Size;
+ item.CTime = info.ftCreationTime;
+ item.ATime = info.ftLastAccessTime;
+ item.MTime = info.ftLastWriteTime;
+ item.Attrib = info.dwFileAttributes;
+ continue;
+ }
+ }
+ */
+
+ RINOK(AddError(phyPath))
+ continue;
+ }
+
+ // (SymLinks == true) here
+
if (item.ReparseData.Size() == 0)
continue;
+
+ // if (item.Size == 0)
+ {
+ // 20.03: we use Reparse Data instead of real data
+ item.Size = item.ReparseData.Size();
+ }
CReparseAttr attr;
if (!attr.Parse(item.ReparseData, item.ReparseData.Size()))
+ {
+ const FString phyPath = GetPhyPath(i);
+ AddError(phyPath, attr.ErrorCode);
continue;
- if (attr.IsRelative())
+ }
+
+ /* imagex/WIM reduces absolute paths in links (raparse data),
+ if we archive non root folder. We do same thing here */
+
+ bool isWSL = false;
+ if (attr.IsSymLink_WSL())
+ {
+ // isWSL = true;
+ // we don't change WSL symlinks
continue;
+ }
+ else
+ {
+ if (attr.IsRelative_Win())
+ continue;
+ }
const UString &link = attr.GetPath();
if (!IsDrivePath(link))
@@ -862,7 +1300,7 @@ void CDirItems::FillFixedReparse()
FString fullPathF;
if (!NDir::MyGetFullPathName(GetPhyPath(i), fullPathF))
continue;
- UString fullPath = fs2us(fullPathF);
+ const UString fullPath = fs2us(fullPathF);
const UString logPath = GetLogPath(i);
if (logPath.Len() >= fullPath.Len())
continue;
@@ -873,7 +1311,7 @@ void CDirItems::FillFixedReparse()
if (!IsPathSepar(prefix.Back()))
continue;
- unsigned rootPrefixSize = GetRootPrefixSize(prefix);
+ const unsigned rootPrefixSize = GetRootPrefixSize(prefix);
if (rootPrefixSize == 0)
continue;
if (rootPrefixSize == prefix.Len())
@@ -889,10 +1327,330 @@ void CDirItems::FillFixedReparse()
newLink += link.Ptr(prefix.Len());
CByteBuffer data;
- if (!FillLinkData(data, newLink, attr.IsSymLink()))
+ bool isSymLink = !attr.IsMountPoint();
+ if (!FillLinkData(data, newLink, isSymLink, isWSL))
continue;
item.ReparseData2 = data;
}
+ return S_OK;
}
#endif
+
+
+#ifndef _WIN32
+
+HRESULT CDirItems::FillDeviceSizes()
+{
+ {
+ FOR_VECTOR (i, Items)
+ {
+ CDirItem &item = Items[i];
+
+ if (S_ISBLK(item.mode) && item.Size == 0)
+ {
+ const FString phyPath = GetPhyPath(i);
+ NIO::CInFile inFile;
+ inFile.PreserveATime = true;
+ if (inFile.OpenShared(phyPath, ShareForWrite)) // fixme: OpenShared ??
+ {
+ UInt64 size = 0;
+ if (inFile.GetLength(size))
+ item.Size = size;
+ }
+ }
+ if (StoreOwnerName)
+ {
+ OwnerNameMap.Add_UInt32(item.uid);
+ OwnerGroupMap.Add_UInt32(item.gid);
+ }
+ }
+ }
+
+ if (StoreOwnerName)
+ {
+ UString u;
+ AString a;
+ {
+ FOR_VECTOR (i, OwnerNameMap.Numbers)
+ {
+ // 200K/sec speed
+ u.Empty();
+ const passwd *pw = getpwuid(OwnerNameMap.Numbers[i]);
+ // printf("\ngetpwuid=%s\n", pw->pw_name);
+ if (pw)
+ {
+ a = pw->pw_name;
+ ConvertUTF8ToUnicode(a, u);
+ }
+ OwnerNameMap.Strings.Add(u);
+ }
+ }
+ {
+ FOR_VECTOR (i, OwnerGroupMap.Numbers)
+ {
+ u.Empty();
+ const group *gr = getgrgid(OwnerGroupMap.Numbers[i]);
+ if (gr)
+ {
+ // printf("\ngetgrgid %d %s\n", OwnerGroupMap.Numbers[i], gr->gr_name);
+ a = gr->gr_name;
+ ConvertUTF8ToUnicode(a, u);
+ }
+ OwnerGroupMap.Strings.Add(u);
+ }
+ }
+
+ FOR_VECTOR (i, Items)
+ {
+ CDirItem &item = Items[i];
+ {
+ const int index = OwnerNameMap.Find(item.uid);
+ if (index < 0) throw 1;
+ item.OwnerNameIndex = index;
+ }
+ {
+ const int index = OwnerGroupMap.Find(item.gid);
+ if (index < 0) throw 1;
+ item.OwnerGroupIndex = index;
+ }
+ }
+ }
+
+
+ // if (NeedOwnerNames)
+ {
+ /*
+ {
+ for (unsigned i = 0 ; i < 10000; i++)
+ {
+ const passwd *pw = getpwuid(i);
+ if (pw)
+ {
+ UString u;
+ ConvertUTF8ToUnicode(AString(pw->pw_name), u);
+ OwnerNameMap.Add(i, u);
+ OwnerNameMap.Add(i, u);
+ OwnerNameMap.Add(i, u);
+ }
+ const group *gr = getgrgid(i);
+ if (gr)
+ {
+ // we can use utf-8 here.
+ UString u;
+ ConvertUTF8ToUnicode(AString(gr->gr_name), u);
+ OwnerGroupMap.Add(i, u);
+ }
+ }
+ }
+ */
+ /*
+ {
+ FOR_VECTOR (i, OwnerNameMap.Strings)
+ {
+ AString s;
+ ConvertUnicodeToUTF8(OwnerNameMap.Strings[i], s);
+ printf("\n%5d %s", (unsigned)OwnerNameMap.Numbers[i], s.Ptr());
+ }
+ }
+ {
+ printf("\n\n=========Groups\n");
+ FOR_VECTOR (i, OwnerGroupMap.Strings)
+ {
+ AString s;
+ ConvertUnicodeToUTF8(OwnerGroupMap.Strings[i], s);
+ printf("\n%5d %s", (unsigned)OwnerGroupMap.Numbers[i], s.Ptr());
+ }
+ }
+ */
+ }
+ /*
+ for (unsigned i = 0 ; i < 100000000; i++)
+ {
+ // const passwd *pw = getpwuid(1000);
+ // pw = pw;
+ int pos = OwnerNameMap.Find(1000);
+ if (pos < 0 - (int)i)
+ throw 1;
+ }
+ */
+
+ return S_OK;
+}
+
+#endif
+
+
+
+static const char * const kCannotFindArchive = "Cannot find archive";
+
+HRESULT EnumerateDirItemsAndSort(
+ NWildcard::CCensor &censor,
+ NWildcard::ECensorPathMode censorPathMode,
+ const UString &addPathPrefix,
+ UStringVector &sortedPaths,
+ UStringVector &sortedFullPaths,
+ CDirItemsStat &st,
+ IDirItemsCallback *callback)
+{
+ FStringVector paths;
+
+ {
+ CDirItems dirItems;
+ dirItems.Callback = callback;
+ {
+ HRESULT res = EnumerateItems(censor, censorPathMode, addPathPrefix, dirItems);
+ st = dirItems.Stat;
+ RINOK(res)
+ }
+
+ FOR_VECTOR (i, dirItems.Items)
+ {
+ const CDirItem &dirItem = dirItems.Items[i];
+ if (!dirItem.IsDir())
+ paths.Add(dirItems.GetPhyPath(i));
+ }
+ }
+
+ if (paths.Size() == 0)
+ {
+ // return S_OK;
+ throw CMessagePathException(kCannotFindArchive);
+ }
+
+ UStringVector fullPaths;
+
+ unsigned i;
+
+ for (i = 0; i < paths.Size(); i++)
+ {
+ FString fullPath;
+ NFile::NDir::MyGetFullPathName(paths[i], fullPath);
+ fullPaths.Add(fs2us(fullPath));
+ }
+
+ CUIntVector indices;
+ SortFileNames(fullPaths, indices);
+ sortedPaths.ClearAndReserve(indices.Size());
+ sortedFullPaths.ClearAndReserve(indices.Size());
+
+ for (i = 0; i < indices.Size(); i++)
+ {
+ unsigned index = indices[i];
+ sortedPaths.AddInReserved(fs2us(paths[index]));
+ sortedFullPaths.AddInReserved(fullPaths[index]);
+ if (i > 0 && CompareFileNames(sortedFullPaths[i], sortedFullPaths[i - 1]) == 0)
+ throw CMessagePathException("Duplicate archive path:", sortedFullPaths[i]);
+ }
+
+ return S_OK;
+}
+
+
+
+
+#ifdef _WIN32
+
+static bool IsDotsName(const wchar_t *s)
+{
+ return s[0] == '.' && (s[1] == 0 || (s[1] == '.' && s[2] == 0));
+}
+
+// This code converts all short file names to long file names.
+
+static void ConvertToLongName(const UString &prefix, UString &name)
+{
+ if (name.IsEmpty()
+ || DoesNameContainWildcard(name)
+ || IsDotsName(name))
+ return;
+ NFind::CFileInfo fi;
+ const FString path (us2fs(prefix + name));
+ #ifndef UNDER_CE
+ if (NFile::NName::IsDevicePath(path))
+ return;
+ #endif
+ if (fi.Find(path))
+ name = fs2us(fi.Name);
+}
+
+static void ConvertToLongNames(const UString &prefix, CObjectVector<NWildcard::CItem> &items)
+{
+ FOR_VECTOR (i, items)
+ {
+ NWildcard::CItem &item = items[i];
+ if (item.Recursive || item.PathParts.Size() != 1)
+ continue;
+ if (prefix.IsEmpty() && item.IsDriveItem())
+ continue;
+ ConvertToLongName(prefix, item.PathParts.Front());
+ }
+}
+
+static void ConvertToLongNames(const UString &prefix, NWildcard::CCensorNode &node)
+{
+ ConvertToLongNames(prefix, node.IncludeItems);
+ ConvertToLongNames(prefix, node.ExcludeItems);
+ unsigned i;
+ for (i = 0; i < node.SubNodes.Size(); i++)
+ {
+ UString &name = node.SubNodes[i].Name;
+ if (prefix.IsEmpty() && NWildcard::IsDriveColonName(name))
+ continue;
+ ConvertToLongName(prefix, name);
+ }
+ // mix folders with same name
+ for (i = 0; i < node.SubNodes.Size(); i++)
+ {
+ NWildcard::CCensorNode &nextNode1 = node.SubNodes[i];
+ for (unsigned j = i + 1; j < node.SubNodes.Size();)
+ {
+ const NWildcard::CCensorNode &nextNode2 = node.SubNodes[j];
+ if (nextNode1.Name.IsEqualTo_NoCase(nextNode2.Name))
+ {
+ nextNode1.IncludeItems += nextNode2.IncludeItems;
+ nextNode1.ExcludeItems += nextNode2.ExcludeItems;
+ node.SubNodes.Delete(j);
+ }
+ else
+ j++;
+ }
+ }
+ for (i = 0; i < node.SubNodes.Size(); i++)
+ {
+ NWildcard::CCensorNode &nextNode = node.SubNodes[i];
+ ConvertToLongNames(prefix + nextNode.Name + WCHAR_PATH_SEPARATOR, nextNode);
+ }
+}
+
+void ConvertToLongNames(NWildcard::CCensor &censor)
+{
+ FOR_VECTOR (i, censor.Pairs)
+ {
+ NWildcard::CPair &pair = censor.Pairs[i];
+ ConvertToLongNames(pair.Prefix, pair.Head);
+ }
+}
+
+#endif
+
+
+CMessagePathException::CMessagePathException(const char *a, const wchar_t *u)
+{
+ (*this) += a;
+ if (u)
+ {
+ Add_LF();
+ (*this) += u;
+ }
+}
+
+CMessagePathException::CMessagePathException(const wchar_t *a, const wchar_t *u)
+{
+ (*this) += a;
+ if (u)
+ {
+ Add_LF();
+ (*this) += u;
+ }
+}
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/EnumDirItems.h b/3rdparty/lzma/CPP/7zip/UI/Common/EnumDirItems.h
index 7afb800a033..24f1c8bd548 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/EnumDirItems.h
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/EnumDirItems.h
@@ -1,16 +1,12 @@
// EnumDirItems.h
-#ifndef __ENUM_DIR_ITEMS_H
-#define __ENUM_DIR_ITEMS_H
+#ifndef ZIP7_INC_ENUM_DIR_ITEMS_H
+#define ZIP7_INC_ENUM_DIR_ITEMS_H
#include "../../../Common/Wildcard.h"
-#include "../../../Windows/FileFind.h"
-
#include "DirItem.h"
-void AddDirFileInfo(int phyParent, int logParent, int secureIndex,
- const NWindows::NFile::NFind::CFileInfo &fi, CObjectVector<CDirItem> &dirItems);
HRESULT EnumerateItems(
const NWildcard::CCensor &censor,
@@ -18,4 +14,25 @@ HRESULT EnumerateItems(
const UString &addPathPrefix,
CDirItems &dirItems);
+
+struct CMessagePathException: public UString
+{
+ CMessagePathException(const char *a, const wchar_t *u = NULL);
+ CMessagePathException(const wchar_t *a, const wchar_t *u = NULL);
+};
+
+
+HRESULT EnumerateDirItemsAndSort(
+ NWildcard::CCensor &censor,
+ NWildcard::ECensorPathMode pathMode,
+ const UString &addPathPrefix,
+ UStringVector &sortedPaths,
+ UStringVector &sortedFullPaths,
+ CDirItemsStat &st,
+ IDirItemsCallback *callback);
+
+#ifdef _WIN32
+void ConvertToLongNames(NWildcard::CCensor &censor);
+#endif
+
#endif
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/ExitCode.h b/3rdparty/lzma/CPP/7zip/UI/Common/ExitCode.h
index b6d7d4dfcab..2d7b0293a0f 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/ExitCode.h
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/ExitCode.h
@@ -1,7 +1,7 @@
// ExitCode.h
-#ifndef __EXIT_CODE_H
-#define __EXIT_CODE_H
+#ifndef ZIP7_INC_EXIT_CODE_H
+#define ZIP7_INC_EXIT_CODE_H
namespace NExitCode {
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/Extract.cpp b/3rdparty/lzma/CPP/7zip/UI/Common/Extract.cpp
index 3da0aadb813..34b48719ec6 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/Extract.cpp
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/Extract.cpp
@@ -7,10 +7,13 @@
#include "../../../Common/StringConvert.h"
#include "../../../Windows/FileDir.h"
+#include "../../../Windows/FileName.h"
+#include "../../../Windows/ErrorMsg.h"
#include "../../../Windows/PropVariant.h"
#include "../../../Windows/PropVariantConv.h"
#include "../Common/ExtractingFilePath.h"
+#include "../Common/HashCalc.h"
#include "Extract.h"
#include "SetProperties.h"
@@ -19,6 +22,19 @@ using namespace NWindows;
using namespace NFile;
using namespace NDir;
+
+static void SetErrorMessage(const char *message,
+ const FString &path, HRESULT errorCode,
+ UString &s)
+{
+ s = message;
+ s += " : ";
+ s += NError::MyFormatMessage(errorCode);
+ s += " : ";
+ s += fs2us(path);
+}
+
+
static HRESULT DecompressArchive(
CCodecs *codecs,
const CArchiveLink &arcLink,
@@ -27,6 +43,7 @@ static HRESULT DecompressArchive(
const CExtractOptions &options,
bool calcCrc,
IExtractCallbackUI *callback,
+ IFolderArchiveExtractCallback *callbackFAE,
CArchiveExtractCallback *ecs,
UString &errorMessage,
UInt64 &stdInProcessed)
@@ -47,11 +64,11 @@ static HRESULT DecompressArchive(
// So it extracts different archives to one folder.
// We will use top level archive name
const CArc &arc0 = arcLink.Arcs[0];
- if (StringsAreEqualNoCase_Ascii(codecs->Formats[arc0.FormatIndex].Name, "pe"))
+ if (arc0.FormatIndex >= 0 && StringsAreEqualNoCase_Ascii(codecs->Formats[(unsigned)arc0.FormatIndex].Name, "pe"))
replaceName = arc0.DefaultName;
}
- outDir.Replace(FSTRING_ANY_MASK, us2fs(Get_Correct_FsFile_Name(replaceName)));
+ outDir.Replace(FString("*"), us2fs(Get_Correct_FsFile_Name(replaceName)));
bool elimIsPossible = false;
UString elimPrefix; // only pure name without dir delimiter
@@ -73,20 +90,25 @@ static HRESULT DecompressArchive(
}
}
- bool allFilesAreAllowed = wildcardCensor.AreAllAllowed();
+ const bool allFilesAreAllowed = wildcardCensor.AreAllAllowed();
if (!options.StdInMode)
{
UInt32 numItems;
- RINOK(archive->GetNumberOfItems(&numItems));
+ RINOK(archive->GetNumberOfItems(&numItems))
CReadArcItem item;
for (UInt32 i = 0; i < numItems; i++)
{
- if (elimIsPossible || !allFilesAreAllowed)
+ if (elimIsPossible
+ || !allFilesAreAllowed
+ || options.ExcludeDirItems
+ || options.ExcludeFileItems)
{
- RINOK(arc.GetItem(i, item));
+ RINOK(arc.GetItem(i, item))
+ if (item.IsDir ? options.ExcludeDirItems : options.ExcludeFileItems)
+ continue;
}
else
{
@@ -94,7 +116,7 @@ static HRESULT DecompressArchive(
item.IsAltStream = false;
if (!options.NtOptions.AltStreams.Val && arc.Ask_AltStream)
{
- RINOK(Archive_IsItem_AltStream(arc.Archive, i, item.IsAltStream));
+ RINOK(Archive_IsItem_AltStream(arc.Archive, i, item.IsAltStream))
}
#endif
}
@@ -156,7 +178,7 @@ static HRESULT DecompressArchive(
#endif
if (outDir.IsEmpty())
- outDir = FTEXT(".") FSTRING_PATH_SEPARATOR;
+ outDir = "." STRING_PATH_SEPARATOR;
/*
#ifdef _WIN32
else if (NName::IsAltPathPrefix(outDir)) {}
@@ -164,11 +186,8 @@ static HRESULT DecompressArchive(
*/
else if (!CreateComplexDir(outDir))
{
- HRESULT res = ::GetLastError();
- if (res == S_OK)
- res = E_FAIL;
- errorMessage.SetFromAscii("Can not create output directory: ");
- errorMessage += fs2us(outDir);
+ const HRESULT res = GetLastError_noZero_HRESULT();
+ SetErrorMessage("Cannot create output directory", outDir, res, errorMessage);
return res;
}
@@ -176,7 +195,7 @@ static HRESULT DecompressArchive(
options.NtOptions,
options.StdInMode ? &wildcardCensor : NULL,
&arc,
- callback,
+ callbackFAE,
options.StdOutMode, options.TestMode,
outDir,
removePathParts, false,
@@ -189,14 +208,17 @@ static HRESULT DecompressArchive(
!options.TestMode &&
options.NtOptions.HardLinks.Val)
{
- RINOK(ecs->PrepareHardLinks(&realIndices));
+ RINOK(ecs->PrepareHardLinks(&realIndices))
}
#endif
HRESULT result;
- Int32 testMode = (options.TestMode && !calcCrc) ? 1: 0;
+ const Int32 testMode = (options.TestMode && !calcCrc) ? 1: 0;
+
+ CArchiveExtractCallback_Closer ecsCloser(ecs);
+
if (options.StdInMode)
{
result = archive->Extract(NULL, (UInt32)(Int32)-1, testMode, ecs);
@@ -206,8 +228,11 @@ static HRESULT DecompressArchive(
}
else
result = archive->Extract(&realIndices.Front(), realIndices.Size(), testMode, ecs);
- if (result == S_OK && !options.StdInMode)
- result = ecs->SetDirsTimes();
+
+ const HRESULT res2 = ecsCloser.Close();
+ if (result == S_OK)
+ result = res2;
+
return callback->ExtractResult(result);
}
@@ -215,17 +240,18 @@ static HRESULT DecompressArchive(
Sorted list for file paths was sorted with case insensitive compare function.
But FindInSorted function did binary search via case sensitive compare function */
-int Find_FileName_InSortedVector(const UStringVector &fileName, const UString &name)
+int Find_FileName_InSortedVector(const UStringVector &fileNames, const UString &name);
+int Find_FileName_InSortedVector(const UStringVector &fileNames, const UString &name)
{
- unsigned left = 0, right = fileName.Size();
+ unsigned left = 0, right = fileNames.Size();
while (left != right)
{
- unsigned mid = (left + right) / 2;
- const UString &midValue = fileName[mid];
- int compare = CompareFileNames(name, midValue);
- if (compare == 0)
- return mid;
- if (compare < 0)
+ const unsigned mid = (unsigned)(((size_t)left + (size_t)right) / 2);
+ const UString &midVal = fileNames[mid];
+ const int comp = CompareFileNames(name, midVal);
+ if (comp == 0)
+ return (int)mid;
+ if (comp < 0)
right = mid;
else
left = mid + 1;
@@ -233,7 +259,10 @@ int Find_FileName_InSortedVector(const UStringVector &fileName, const UString &n
return -1;
}
+
+
HRESULT Extract(
+ // DECL_EXTERNAL_CODECS_LOC_VARS
CCodecs *codecs,
const CObjectVector<COpenType> &types,
const CIntVector &excludedFormats,
@@ -242,7 +271,8 @@ HRESULT Extract(
const CExtractOptions &options,
IOpenCallbackUI *openCallback,
IExtractCallbackUI *extractCallback,
- #ifndef _SFX
+ IFolderArchiveExtractCallback *faeCallback,
+ #ifndef Z7_SFX
IHashCalc *hash,
#endif
UString &errorMessage,
@@ -262,11 +292,19 @@ HRESULT Extract(
fi.Size = 0;
if (!options.StdInMode)
{
- const FString &arcPath = us2fs(arcPaths[i]);
- if (!fi.Find(arcPath))
- throw "there is no such archive";
+ const FString arcPath = us2fs(arcPaths[i]);
+ if (!fi.Find_FollowLink(arcPath))
+ {
+ const HRESULT errorCode = GetLastError_noZero_HRESULT();
+ SetErrorMessage("Cannot find archive file", arcPath, errorCode, errorMessage);
+ return errorCode;
+ }
if (fi.IsDir())
- throw "can't decompress folder";
+ {
+ HRESULT errorCode = E_FAIL;
+ SetErrorMessage("The item is a directory", arcPath, errorCode, errorMessage);
+ return errorCode;
+ }
}
arcSizes.Add(fi.Size);
totalPackSize += fi.Size;
@@ -278,15 +316,22 @@ HRESULT Extract(
CArchiveExtractCallback *ecs = new CArchiveExtractCallback;
CMyComPtr<IArchiveExtractCallback> ec(ecs);
- bool multi = (numArcs > 1);
- ecs->InitForMulti(multi, options.PathMode, options.OverwriteMode);
- #ifndef _SFX
+
+ const bool multi = (numArcs > 1);
+
+ ecs->InitForMulti(multi,
+ options.PathMode,
+ options.OverwriteMode,
+ options.ZoneMode,
+ false // keepEmptyDirParts
+ );
+ #ifndef Z7_SFX
ecs->SetHashMethods(hash);
#endif
if (multi)
{
- RINOK(extractCallback->SetTotal(totalPackSize));
+ RINOK(faeCallback->SetTotal(totalPackSize))
}
UInt64 totalPackProcessed = 0;
@@ -297,31 +342,41 @@ HRESULT Extract(
if (skipArcs[i])
continue;
+ ecs->InitBeforeNewArchive();
+
const UString &arcPath = arcPaths[i];
NFind::CFileInfo fi;
if (options.StdInMode)
{
- fi.Size = 0;
- fi.Attrib = 0;
+ // do we need ctime and mtime?
+ fi.ClearBase();
+ fi.Size = 0; // (UInt64)(Int64)-1;
+ fi.SetAsFile();
+ // NTime::GetCurUtc_FiTime(fi.MTime);
+ // fi.CTime = fi.ATime = fi.MTime;
}
else
{
- if (!fi.Find(us2fs(arcPath)) || fi.IsDir())
- throw "there is no such archive";
+ if (!fi.Find_FollowLink(us2fs(arcPath)) || fi.IsDir())
+ {
+ const HRESULT errorCode = GetLastError_noZero_HRESULT();
+ SetErrorMessage("Cannot find archive file", us2fs(arcPath), errorCode, errorMessage);
+ return errorCode;
+ }
}
/*
- #ifndef _NO_CRYPTO
+ #ifndef Z7_NO_CRYPTO
openCallback->Open_Clear_PasswordWasAsked_Flag();
#endif
*/
- RINOK(extractCallback->BeforeOpen(arcPath, options.TestMode));
+ RINOK(extractCallback->BeforeOpen(arcPath, options.TestMode))
CArchiveLink arcLink;
CObjectVector<COpenType> types2 = types;
/*
- #ifndef _SFX
+ #ifndef Z7_SFX
if (types.IsEmpty())
{
int pos = arcPath.ReverseFind(L'.');
@@ -349,7 +404,7 @@ HRESULT Extract(
*/
COpenOptions op;
- #ifndef _SFX
+ #ifndef Z7_SFX
op.props = &options.Properties;
#endif
op.codecs = codecs;
@@ -365,19 +420,54 @@ HRESULT Extract(
return result;
// arcLink.Set_ErrorsText();
- RINOK(extractCallback->OpenResult(codecs, arcLink, arcPath, result));
+ RINOK(extractCallback->OpenResult(codecs, arcLink, arcPath, result))
if (result != S_OK)
{
thereAreNotOpenArcs = true;
if (!options.StdInMode)
+ totalPackProcessed += fi.Size;
+ continue;
+ }
+
+ #if defined(_WIN32) && !defined(UNDER_CE) && !defined(Z7_SFX)
+ if (options.ZoneMode != NExtract::NZoneIdMode::kNone
+ && !options.StdInMode)
+ {
+ ReadZoneFile_Of_BaseFile(us2fs(arcPath), ecs->ZoneBuf);
+ }
+ #endif
+
+
+ if (arcLink.Arcs.Size() != 0)
+ {
+ if (arcLink.GetArc()->IsHashHandler(op))
{
- NFind::CFileInfo fi2;
- if (fi2.Find(us2fs(arcPath)))
- if (!fi2.IsDir())
- totalPackProcessed += fi2.Size;
+ if (!options.TestMode)
+ {
+ /* real Extracting to files is possible.
+ But user can think that hash archive contains real files.
+ So we block extracting here. */
+ // v23.00 : we don't break process.
+ RINOK(extractCallback->OpenResult(codecs, arcLink, arcPath, E_NOTIMPL))
+ thereAreNotOpenArcs = true;
+ if (!options.StdInMode)
+ totalPackProcessed += fi.Size;
+ continue;
+ // return E_NOTIMPL; // before v23
+ }
+ FString dirPrefix = us2fs(options.HashDir);
+ if (dirPrefix.IsEmpty())
+ {
+ if (!NFile::NDir::GetOnlyDirPrefix(us2fs(arcPath), dirPrefix))
+ {
+ // return GetLastError_noZero_HRESULT();
+ }
+ }
+ if (!dirPrefix.IsEmpty())
+ NName::NormalizeDirPathPrefix(dirPrefix);
+ ecs->DirPathPrefix_for_HashFiles = dirPrefix;
}
- continue;
}
if (!options.StdInMode)
@@ -389,7 +479,7 @@ HRESULT Extract(
// numArcs = arcPaths.Size();
if (arcLink.VolumePaths.Size() != 0)
{
- Int64 correctionSize = arcLink.VolumesSize;
+ Int64 correctionSize = (Int64)arcLink.VolumesSize;
FOR_VECTOR (v, arcLink.VolumePaths)
{
int index = Find_FileName_InSortedVector(arcPathsFull, arcLink.VolumePaths[v]);
@@ -407,8 +497,8 @@ HRESULT Extract(
Int64 newPackSize = (Int64)totalPackSize + correctionSize;
if (newPackSize < 0)
newPackSize = 0;
- totalPackSize = newPackSize;
- RINOK(extractCallback->SetTotal(totalPackSize));
+ totalPackSize = (UInt64)newPackSize;
+ RINOK(faeCallback->SetTotal(totalPackSize))
}
}
}
@@ -416,24 +506,29 @@ HRESULT Extract(
/*
// Now openCallback and extractCallback use same object. So we don't need to send password.
- #ifndef _NO_CRYPTO
+ #ifndef Z7_NO_CRYPTO
bool passwordIsDefined;
UString password;
- RINOK(openCallback->Open_GetPasswordIfAny(passwordIsDefined, password));
+ RINOK(openCallback->Open_GetPasswordIfAny(passwordIsDefined, password))
if (passwordIsDefined)
{
- RINOK(extractCallback->SetPassword(password));
+ RINOK(extractCallback->SetPassword(password))
}
#endif
*/
CArc &arc = arcLink.Arcs.Back();
- arc.MTimeDefined = (!options.StdInMode && !fi.IsDevice);
- arc.MTime = fi.MTime;
+ arc.MTime.Def = !options.StdInMode
+ #ifdef _WIN32
+ && !fi.IsDevice
+ #endif
+ ;
+ if (arc.MTime.Def)
+ arc.MTime.Set_From_FiTime(fi.MTime);
UInt64 packProcessed;
- bool calcCrc =
- #ifndef _SFX
+ const bool calcCrc =
+ #ifndef Z7_SFX
(hash != NULL);
#else
false;
@@ -446,7 +541,8 @@ HRESULT Extract(
wildcardCensor,
options,
calcCrc,
- extractCallback, ecs, errorMessage, packProcessed));
+ extractCallback, faeCallback, ecs,
+ errorMessage, packProcessed))
if (!options.StdInMode)
packProcessed = fi.Size + arcLink.VolumesSize;
@@ -459,8 +555,8 @@ HRESULT Extract(
if (multi || thereAreNotOpenArcs)
{
- RINOK(extractCallback->SetTotal(totalPackSize));
- RINOK(extractCallback->SetCompleted(&totalPackProcessed));
+ RINOK(faeCallback->SetTotal(totalPackSize))
+ RINOK(faeCallback->SetCompleted(&totalPackProcessed))
}
st.NumFolders = ecs->NumFolders;
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/Extract.h b/3rdparty/lzma/CPP/7zip/UI/Common/Extract.h
index 03ac74b2d0b..b20f607d6d9 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/Extract.h
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/Extract.h
@@ -1,7 +1,7 @@
// Extract.h
-#ifndef __EXTRACT_H
-#define __EXTRACT_H
+#ifndef ZIP7_INC_EXTRACT_H
+#define ZIP7_INC_EXTRACT_H
#include "../../../Windows/FileFind.h"
@@ -17,20 +17,28 @@
struct CExtractOptionsBase
{
CBoolPair ElimDup;
-
+
+ bool ExcludeDirItems;
+ bool ExcludeFileItems;
+
bool PathMode_Force;
bool OverwriteMode_Force;
NExtract::NPathMode::EEnum PathMode;
NExtract::NOverwriteMode::EEnum OverwriteMode;
+ NExtract::NZoneIdMode::EEnum ZoneMode;
FString OutputDir;
CExtractNtOptions NtOptions;
+ UString HashDir;
CExtractOptionsBase():
+ ExcludeDirItems(false),
+ ExcludeFileItems(false),
PathMode_Force(false),
OverwriteMode_Force(false),
PathMode(NExtract::NPathMode::kFullPaths),
- OverwriteMode(NExtract::NOverwriteMode::kAsk)
+ OverwriteMode(NExtract::NOverwriteMode::kAsk),
+ ZoneMode(NExtract::NZoneIdMode::kNone)
{}
};
@@ -44,19 +52,21 @@ struct CExtractOptions: public CExtractOptionsBase
// bool ShowDialog;
// bool PasswordEnabled;
// UString Password;
- #ifndef _SFX
+ #ifndef Z7_SFX
CObjectVector<CProperty> Properties;
#endif
- #ifdef EXTERNAL_CODECS
+ /*
+ #ifdef Z7_EXTERNAL_CODECS
CCodecs *Codecs;
#endif
+ */
CExtractOptions():
- TestMode(false),
StdInMode(false),
StdOutMode(false),
- YesToAll(false)
+ YesToAll(false),
+ TestMode(false)
{}
};
@@ -77,6 +87,7 @@ struct CDecompressStat
};
HRESULT Extract(
+ // DECL_EXTERNAL_CODECS_LOC_VARS
CCodecs *codecs,
const CObjectVector<COpenType> &types,
const CIntVector &excludedFormats,
@@ -85,7 +96,8 @@ HRESULT Extract(
const CExtractOptions &options,
IOpenCallbackUI *openCallback,
IExtractCallbackUI *extractCallback,
- #ifndef _SFX
+ IFolderArchiveExtractCallback *faeCallback,
+ #ifndef Z7_SFX
IHashCalc *hash,
#endif
UString &errorMessage,
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/ExtractMode.h b/3rdparty/lzma/CPP/7zip/UI/Common/ExtractMode.h
index 3b2b9a02e81..6e38f2601fb 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/ExtractMode.h
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/ExtractMode.h
@@ -1,7 +1,7 @@
// ExtractMode.h
-#ifndef __EXTRACT_MODE_H
-#define __EXTRACT_MODE_H
+#ifndef ZIP7_INC_EXTRACT_MODE_H
+#define ZIP7_INC_EXTRACT_MODE_H
namespace NExtract {
@@ -29,6 +29,16 @@ namespace NOverwriteMode
};
}
+namespace NZoneIdMode
+{
+ enum EEnum
+ {
+ kNone,
+ kAll,
+ kOffice
+ };
+}
+
}
#endif
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/ExtractingFilePath.cpp b/3rdparty/lzma/CPP/7zip/UI/Common/ExtractingFilePath.cpp
index 39e67b7f2ed..88da4ad36c0 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/ExtractingFilePath.cpp
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/ExtractingFilePath.cpp
@@ -8,6 +8,18 @@
#include "ExtractingFilePath.h"
+extern
+bool g_PathTrailReplaceMode;
+bool g_PathTrailReplaceMode =
+ #ifdef _WIN32
+ true
+ #else
+ false
+ #endif
+ ;
+
+
+#ifdef _WIN32
static void ReplaceIncorrectChars(UString &s)
{
{
@@ -22,24 +34,60 @@ static void ReplaceIncorrectChars(UString &s)
||
#endif
c == WCHAR_PATH_SEPARATOR)
- s.ReplaceOneCharAtPos(i, '_');
+ {
+ #if WCHAR_PATH_SEPARATOR != L'/'
+ // 22.00 : WSL replacement for backslash
+ if (c == WCHAR_PATH_SEPARATOR)
+ c = WCHAR_IN_FILE_NAME_BACKSLASH_REPLACEMENT;
+ else
+ #endif
+ c = '_';
+ s.ReplaceOneCharAtPos(i,
+ c
+ // (wchar_t)(0xf000 + c) // 21.02 debug: WSL encoding for unsupported characters
+ );
+ }
}
}
- #ifdef _WIN32
+ if (g_PathTrailReplaceMode)
{
- for (unsigned i = s.Len(); i != 0;)
+ /*
+ // if (g_PathTrailReplaceMode == 1)
{
- wchar_t c = s[--i];
- if (c != '.' && c != ' ')
- break;
- s.ReplaceOneCharAtPos(i, '_');
+ if (!s.IsEmpty())
+ {
+ wchar_t c = s.Back();
+ if (c == '.' || c == ' ')
+ {
+ // s += (wchar_t)(0x9c); // STRING TERMINATOR
+ s += (wchar_t)'_';
+ }
+ }
+ }
+ else
+ */
+ {
+ unsigned i;
+ for (i = s.Len(); i != 0;)
+ {
+ wchar_t c = s[i - 1];
+ if (c != '.' && c != ' ')
+ break;
+ i--;
+ s.ReplaceOneCharAtPos(i, '_');
+ // s.ReplaceOneCharAtPos(i, (c == ' ' ? (wchar_t)(0x2423) : (wchar_t)0x00B7));
+ }
+ /*
+ if (g_PathTrailReplaceMode > 1 && i != s.Len())
+ {
+ s.DeleteFrom(i);
+ }
+ */
}
}
- #endif
}
-
-#ifdef _WIN32
+#endif
/* WinXP-64 doesn't support ':', '\\' and '/' symbols in name of alt stream.
But colon in postfix ":$DATA" is allowed.
@@ -61,9 +109,11 @@ void Correct_AltStream_Name(UString &s)
s.ReplaceOneCharAtPos(i, '_');
}
if (s.IsEmpty())
- s = L'_';
+ s = '_';
}
+#ifdef _WIN32
+
static const unsigned g_ReservedWithNum_Index = 4;
static const char * const g_ReservedNames[] =
@@ -74,7 +124,7 @@ static const char * const g_ReservedNames[] =
static bool IsSupportedName(const UString &name)
{
- for (unsigned i = 0; i < ARRAY_SIZE(g_ReservedNames); i++)
+ for (unsigned i = 0; i < Z7_ARRAY_SIZE(g_ReservedNames); i++)
{
const char *reservedName = g_ReservedNames[i];
unsigned len = MyStringLen(reservedName);
@@ -112,7 +162,10 @@ static void CorrectUnsupportedName(UString &name)
static void Correct_PathPart(UString &s)
{
// "." and ".."
- if (s[0] == '.' && (s[1] == 0 || s[1] == '.' && s[2] == 0))
+ if (s.IsEmpty())
+ return;
+
+ if (s[0] == '.' && (s[1] == 0 || (s[1] == '.' && s[2] == 0)))
s.Empty();
#ifdef _WIN32
else
@@ -120,8 +173,8 @@ static void Correct_PathPart(UString &s)
#endif
}
-// static const wchar_t *k_EmptyReplaceName = L"[]";
-static const wchar_t k_EmptyReplaceName = L'_';
+// static const char * const k_EmptyReplaceName = "[]";
+static const char k_EmptyReplaceName = '_';
UString Get_Correct_FsFile_Name(const UString &name)
{
@@ -138,7 +191,7 @@ UString Get_Correct_FsFile_Name(const UString &name)
}
-void Correct_FsPath(bool absIsAllowed, UStringVector &parts, bool isDir)
+void Correct_FsPath(bool absIsAllowed, bool keepAndReplaceEmptyPrefixes, UStringVector &parts, bool isDir)
{
unsigned i = 0;
@@ -147,6 +200,7 @@ void Correct_FsPath(bool absIsAllowed, UStringVector &parts, bool isDir)
#if defined(_WIN32) && !defined(UNDER_CE)
bool isDrive = false;
#endif
+
if (parts[0].IsEmpty())
{
i = 1;
@@ -157,7 +211,7 @@ void Correct_FsPath(bool absIsAllowed, UStringVector &parts, bool isDir)
if (parts.Size() > 2 && parts[2] == L"?")
{
i = 3;
- if (parts.Size() > 3 && NWindows::NFile::NName::IsDrivePath2(parts[3]))
+ if (parts.Size() > 3 && NWindows::NFile::NName::IsDrivePath2(parts[3]))
{
isDrive = true;
i = 4;
@@ -176,16 +230,19 @@ void Correct_FsPath(bool absIsAllowed, UStringVector &parts, bool isDir)
if (isDrive)
{
// we convert "c:name" to "c:\name", if absIsAllowed path.
- const UString &ds = parts[i - 1];
- if (ds.Len() != 2)
+ UString &ds = parts[i - 1];
+ if (ds.Len() > 2)
{
- UString s = ds.Ptr(2);
- parts.Insert(i, s);
+ parts.Insert(i, ds.Ptr(2));
+ ds.DeleteFrom(2);
}
}
#endif
}
+ if (i != 0)
+ keepAndReplaceEmptyPrefixes = false;
+
for (; i < parts.Size();)
{
UString &s = parts[i];
@@ -194,15 +251,17 @@ void Correct_FsPath(bool absIsAllowed, UStringVector &parts, bool isDir)
if (s.IsEmpty())
{
- if (isDir || i != parts.Size() - 1)
- {
- parts.Delete(i);
- continue;
- }
+ if (!keepAndReplaceEmptyPrefixes)
+ if (isDir || i != parts.Size() - 1)
+ {
+ parts.Delete(i);
+ continue;
+ }
s = k_EmptyReplaceName;
}
else
{
+ keepAndReplaceEmptyPrefixes = false;
#ifdef _WIN32
CorrectUnsupportedName(s);
#endif
@@ -214,7 +273,7 @@ void Correct_FsPath(bool absIsAllowed, UStringVector &parts, bool isDir)
if (!isDir)
{
if (parts.IsEmpty())
- parts.Add(k_EmptyReplaceName);
+ parts.Add((UString)k_EmptyReplaceName);
else
{
UString &s = parts.Back();
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/ExtractingFilePath.h b/3rdparty/lzma/CPP/7zip/UI/Common/ExtractingFilePath.h
index a52a1f4a5b4..bb1732fc8bb 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/ExtractingFilePath.h
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/ExtractingFilePath.h
@@ -1,18 +1,30 @@
// ExtractingFilePath.h
-#ifndef __EXTRACTING_FILE_PATH_H
-#define __EXTRACTING_FILE_PATH_H
+#ifndef ZIP7_INC_EXTRACTING_FILE_PATH_H
+#define ZIP7_INC_EXTRACTING_FILE_PATH_H
#include "../../../Common/MyString.h"
-#ifdef _WIN32
+// #ifdef _WIN32
void Correct_AltStream_Name(UString &s);
-#endif
+// #endif
// replaces unsuported characters, and replaces "." , ".." and "" to "[]"
UString Get_Correct_FsFile_Name(const UString &name);
-void Correct_FsPath(bool absIsAllowed, UStringVector &parts, bool isDir);
+/*
+ Correct_FsPath() corrects path parts to prepare it for File System operations.
+ It also corrects empty path parts like "\\\\":
+ - frontal empty path parts : it removes them or changes them to "_"
+ - another empty path parts : it removes them
+ if (absIsAllowed && path is absolute) : it removes empty path parts after start absolute path prefix marker
+ else
+ {
+ if (!keepAndReplaceEmptyPrefixes) : it removes empty path parts
+ if ( keepAndReplaceEmptyPrefixes) : it changes each empty frontal path part to "_"
+ }
+*/
+void Correct_FsPath(bool absIsAllowed, bool keepAndReplaceEmptyPrefixes, UStringVector &parts, bool isDir);
UString MakePathFromParts(const UStringVector &parts);
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/HashCalc.cpp b/3rdparty/lzma/CPP/7zip/UI/Common/HashCalc.cpp
index 60a747d5590..94c8a06fc8b 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/HashCalc.cpp
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/HashCalc.cpp
@@ -3,44 +3,52 @@
#include "StdAfx.h"
#include "../../../../C/Alloc.h"
+#include "../../../../C/CpuArch.h"
+#include "../../../Common/DynLimBuf.h"
+#include "../../../Common/IntToString.h"
#include "../../../Common/StringToInt.h"
#include "../../Common/FileStreams.h"
+#include "../../Common/ProgressUtils.h"
+#include "../../Common/StreamObjects.h"
#include "../../Common/StreamUtils.h"
+#include "../../Archive/Common/ItemNameUtils.h"
+#include "../../Archive/IArchive.h"
+
#include "EnumDirItems.h"
#include "HashCalc.h"
using namespace NWindows;
+#ifdef Z7_EXTERNAL_CODECS
+extern const CExternalCodecs *g_ExternalCodecs_Ptr;
+#endif
+
class CHashMidBuf
{
void *_data;
public:
- CHashMidBuf(): _data(0) {}
+ CHashMidBuf(): _data(NULL) {}
operator void *() { return _data; }
bool Alloc(size_t size)
{
- if (_data != 0)
+ if (_data)
return false;
_data = ::MidAlloc(size);
- return _data != 0;
+ return _data != NULL;
}
~CHashMidBuf() { ::MidFree(_data); }
};
-static const char *k_DefaultHashMethod = "CRC32";
+static const char * const k_DefaultHashMethod = "CRC32";
HRESULT CHashBundle::SetMethods(DECL_EXTERNAL_CODECS_LOC_VARS const UStringVector &hashMethods)
{
UStringVector names = hashMethods;
if (names.IsEmpty())
- {
- UString s;
- s.SetFromAscii(k_DefaultHashMethod);
- names.Add(s);
- }
+ names.Add(UString(k_DefaultHashMethod));
CRecordVector<CMethodId> ids;
CObjectVector<COneMethodInfo> methods;
@@ -49,7 +57,7 @@ HRESULT CHashBundle::SetMethods(DECL_EXTERNAL_CODECS_LOC_VARS const UStringVecto
for (i = 0; i < names.Size(); i++)
{
COneMethodInfo m;
- RINOK(m.ParseMethodFromString(names[i]));
+ RINOK(m.ParseMethodFromString(names[i]))
if (m.MethodName.IsEmpty())
m.MethodName = k_DefaultHashMethod;
@@ -84,7 +92,7 @@ HRESULT CHashBundle::SetMethods(DECL_EXTERNAL_CODECS_LOC_VARS const UStringVecto
{
CMyComPtr<IHasher> hasher;
AString name;
- RINOK(CreateHasher(EXTERNAL_CODECS_LOC_VARS ids[i], name, hasher));
+ RINOK(CreateHasher(EXTERNAL_CODECS_LOC_VARS ids[i], name, hasher))
if (!hasher)
throw "Can't create hasher";
const COneMethodInfo &m = methods[i];
@@ -92,17 +100,17 @@ HRESULT CHashBundle::SetMethods(DECL_EXTERNAL_CODECS_LOC_VARS const UStringVecto
CMyComPtr<ICompressSetCoderProperties> scp;
hasher.QueryInterface(IID_ICompressSetCoderProperties, &scp);
if (scp)
- RINOK(m.SetCoderProps(scp, NULL));
+ RINOK(m.SetCoderProps(scp, NULL))
}
- UInt32 digestSize = hasher->GetDigestSize();
+ const UInt32 digestSize = hasher->GetDigestSize();
if (digestSize > k_HashCalc_DigestSize_Max)
return E_NOTIMPL;
CHasherState &h = Hashers.AddNew();
+ h.DigestSize = digestSize;
h.Hasher = hasher;
h.Name = name;
- h.DigestSize = digestSize;
for (unsigned k = 0; k < k_HashCalc_NumGroups; k++)
- memset(h.Digests[k], 0, digestSize);
+ h.InitDigestGroup(k);
}
return S_OK;
@@ -115,7 +123,7 @@ void CHashBundle::InitForNewFile()
{
CHasherState &h = Hashers[i];
h.Hasher->Init();
- memset(h.Digests[k_HashCalc_Index_Current], 0, h.DigestSize);
+ h.InitDigestGroup(k_HashCalc_Index_Current);
}
}
@@ -134,14 +142,46 @@ void CHashBundle::SetSize(UInt64 size)
static void AddDigests(Byte *dest, const Byte *src, UInt32 size)
{
unsigned next = 0;
- for (UInt32 i = 0; i < size; i++)
+ /*
+ // we could use big-endian addition for sha-1 and sha-256
+ // but another hashers are little-endian
+ if (size > 8)
+ {
+ for (unsigned i = size; i != 0;)
+ {
+ i--;
+ next += (unsigned)dest[i] + (unsigned)src[i];
+ dest[i] = (Byte)next;
+ next >>= 8;
+ }
+ }
+ else
+ */
{
- next += (unsigned)dest[i] + (unsigned)src[i];
+ for (unsigned i = 0; i < size; i++)
+ {
+ next += (unsigned)dest[i] + (unsigned)src[i];
+ dest[i] = (Byte)next;
+ next >>= 8;
+ }
+ }
+
+ // we use little-endian to store extra bytes
+ dest += k_HashCalc_DigestSize_Max;
+ for (unsigned i = 0; i < k_HashCalc_ExtraSize; i++)
+ {
+ next += (unsigned)dest[i];
dest[i] = (Byte)next;
next >>= 8;
}
}
+void CHasherState::AddDigest(unsigned groupIndex, const Byte *data)
+{
+ NumSums[groupIndex]++;
+ AddDigests(Digests[groupIndex], data, DigestSize);
+}
+
void CHashBundle::Final(bool isDir, bool isAltStream, const UString &path)
{
if (isDir)
@@ -167,9 +207,9 @@ void CHashBundle::Final(bool isDir, bool isAltStream, const UString &path)
CHasherState &h = Hashers[i];
if (!isDir)
{
- h.Hasher->Final(h.Digests[0]);
+ h.Hasher->Final(h.Digests[0]); // k_HashCalc_Index_Current
if (!isAltStream)
- AddDigests(h.Digests[k_HashCalc_Index_DataSum], h.Digests[0], h.DigestSize);
+ h.AddDigest(k_HashCalc_Index_DataSum, h.Digests[0]);
}
h.Hasher->Init();
@@ -179,6 +219,15 @@ void CHashBundle::Final(bool isDir, bool isAltStream, const UString &path)
for (unsigned k = 0; k < path.Len(); k++)
{
wchar_t c = path[k];
+
+ // 21.04: we want same hash for linux and windows paths
+ #if CHAR_PATH_SEPARATOR != '/'
+ if (c == CHAR_PATH_SEPARATOR)
+ c = '/';
+ // if (c == (wchar_t)('\\' + 0xf000)) c = '\\'; // to debug WSL
+ // if (c > 0xf000 && c < 0xf080) c -= 0xf000; // to debug WSL
+ #endif
+
Byte temp[2] = { (Byte)(c & 0xFF), (Byte)((c >> 8) & 0xFF) };
h.Hasher->Update(temp, 2);
}
@@ -186,9 +235,216 @@ void CHashBundle::Final(bool isDir, bool isAltStream, const UString &path)
Byte tempDigest[k_HashCalc_DigestSize_Max];
h.Hasher->Final(tempDigest);
if (!isAltStream)
- AddDigests(h.Digests[k_HashCalc_Index_NamesSum], tempDigest, h.DigestSize);
- AddDigests(h.Digests[k_HashCalc_Index_StreamsSum], tempDigest, h.DigestSize);
+ h.AddDigest(k_HashCalc_Index_NamesSum, tempDigest);
+ h.AddDigest(k_HashCalc_Index_StreamsSum, tempDigest);
+ }
+}
+
+
+static void CSum_Name_OriginalToEscape(const AString &src, AString &dest)
+{
+ dest.Empty();
+ for (unsigned i = 0; i < src.Len();)
+ {
+ char c = src[i++];
+ if (c == '\n')
+ {
+ dest += '\\';
+ c = 'n';
+ }
+ else if (c == '\\')
+ dest += '\\';
+ dest += c;
+ }
+}
+
+
+static bool CSum_Name_EscapeToOriginal(const char *s, AString &dest)
+{
+ bool isOK = true;
+ dest.Empty();
+ for (;;)
+ {
+ char c = *s++;
+ if (c == 0)
+ break;
+ if (c == '\\')
+ {
+ const char c1 = *s;
+ if (c1 == 'n')
+ {
+ c = '\n';
+ s++;
+ }
+ else if (c1 == '\\')
+ {
+ c = c1;
+ s++;
+ }
+ else
+ {
+ // original md5sum returns NULL for such bad strings
+ isOK = false;
+ }
+ }
+ dest += c;
+ }
+ return isOK;
+}
+
+
+
+static void SetSpacesAndNul(char *s, unsigned num)
+{
+ for (unsigned i = 0; i < num; i++)
+ s[i] = ' ';
+ s[num] = 0;
+}
+
+static const unsigned kHashColumnWidth_Min = 4 * 2;
+
+static unsigned GetColumnWidth(unsigned digestSize)
+{
+ const unsigned width = digestSize * 2;
+ return width < kHashColumnWidth_Min ? kHashColumnWidth_Min: width;
+}
+
+
+static void AddHashResultLine(
+ AString &_s,
+ // bool showHash,
+ // UInt64 fileSize, bool showSize,
+ const CObjectVector<CHasherState> &hashers
+ // unsigned digestIndex, = k_HashCalc_Index_Current
+ )
+{
+ FOR_VECTOR (i, hashers)
+ {
+ const CHasherState &h = hashers[i];
+ char s[k_HashCalc_DigestSize_Max * 2 + 64];
+ s[0] = 0;
+ // if (showHash)
+ HashHexToString(s, h.Digests[k_HashCalc_Index_Current], h.DigestSize);
+ const unsigned pos = (unsigned)strlen(s);
+ const int numSpaces = (int)GetColumnWidth(h.DigestSize) - (int)pos;
+ if (numSpaces > 0)
+ SetSpacesAndNul(s + pos, (unsigned)numSpaces);
+ if (i != 0)
+ _s.Add_Space();
+ _s += s;
+ }
+
+ /*
+ if (showSize)
+ {
+ _s.Add_Space();
+ static const unsigned kSizeField_Len = 13; // same as in HashCon.cpp
+ char s[kSizeField_Len + 32];
+ char *p = s;
+ SetSpacesAndNul(s, kSizeField_Len);
+ p = s + kSizeField_Len;
+ ConvertUInt64ToString(fileSize, p);
+ int numSpaces = (int)kSizeField_Len - (int)strlen(p);
+ if (numSpaces > 0)
+ p -= (unsigned)numSpaces;
+ _s += p;
+ }
+ */
+}
+
+
+static void Add_LF(CDynLimBuf &hashFileString, const CHashOptionsLocal &options)
+{
+ hashFileString += (char)(options.HashMode_Zero.Val ? 0 : '\n');
+}
+
+
+
+
+static void WriteLine(CDynLimBuf &hashFileString,
+ const CHashOptionsLocal &options,
+ const UString &path2,
+ bool isDir,
+ const AString &methodName,
+ const AString &hashesString)
+{
+ if (options.HashMode_OnlyHash.Val)
+ {
+ hashFileString += hashesString;
+ Add_LF(hashFileString, options);
+ return;
+ }
+
+ UString path = path2;
+
+ bool isBin = false;
+ const bool zeroMode = options.HashMode_Zero.Val;
+ const bool tagMode = options.HashMode_Tag.Val;
+
+#if CHAR_PATH_SEPARATOR != '/'
+ path.Replace(WCHAR_PATH_SEPARATOR, L'/');
+ // path.Replace((wchar_t)('\\' + 0xf000), L'\\'); // to debug WSL
+#endif
+
+ AString utf8;
+ ConvertUnicodeToUTF8(path, utf8);
+
+ AString esc;
+ CSum_Name_OriginalToEscape(utf8, esc);
+
+ if (!zeroMode)
+ {
+ if (esc != utf8)
+ {
+ /* Original md5sum writes escape in that case.
+ We do same for compatibility with original md5sum. */
+ hashFileString += '\\';
+ }
+ }
+
+ if (isDir && !esc.IsEmpty() && esc.Back() != '/')
+ esc += '/';
+
+ if (tagMode)
+ {
+ if (!methodName.IsEmpty())
+ {
+ hashFileString += methodName;
+ hashFileString += ' ';
+ }
+ hashFileString += '(';
+ hashFileString += esc;
+ hashFileString += ')';
+ hashFileString += " = ";
}
+
+ hashFileString += hashesString;
+
+ if (!tagMode)
+ {
+ hashFileString += ' ';
+ hashFileString += (char)(isBin ? '*' : ' ');
+ hashFileString += esc;
+ }
+
+ Add_LF(hashFileString, options);
+}
+
+
+
+static void WriteLine(CDynLimBuf &hashFileString,
+ const CHashOptionsLocal &options,
+ const UString &path,
+ bool isDir,
+ const CHashBundle &hb)
+{
+ AString methodName;
+ if (!hb.Hashers.IsEmpty())
+ methodName = hb.Hashers[0].Name;
+
+ AString hashesString;
+ AddHashResultLine(hashesString, hb.Hashers);
+ WriteLine(hashFileString, options, path, isDir, methodName, hashesString);
}
@@ -206,16 +462,19 @@ HRESULT HashCalc(
{
CDirItem di;
di.Size = (UInt64)(Int64)-1;
- di.Attrib = 0;
- di.MTime.dwLowDateTime = 0;
- di.MTime.dwHighDateTime = 0;
- di.CTime = di.ATime = di.MTime;
+ di.SetAsFile();
dirItems.Items.Add(di);
}
else
{
- RINOK(callback->StartScanning());
+ RINOK(callback->StartScanning())
+
+ dirItems.SymLinks = options.SymLinks.Val;
dirItems.ScanAltStreams = options.AltStreamsMode;
+ dirItems.ExcludeDirItems = censor.ExcludeDirItems;
+ dirItems.ExcludeFileItems = censor.ExcludeFileItems;
+
+ dirItems.ShareForWrite = options.OpenShareForWrite;
HRESULT res = EnumerateItems(censor,
options.PathMode,
@@ -228,23 +487,25 @@ HRESULT HashCalc(
errorInfo = "Scanning error";
return res;
}
- RINOK(callback->FinishScanning(dirItems.Stat));
+ RINOK(callback->FinishScanning(dirItems.Stat))
}
unsigned i;
CHashBundle hb;
- RINOK(hb.SetMethods(EXTERNAL_CODECS_LOC_VARS options.Methods));
- hb.Init();
+ RINOK(hb.SetMethods(EXTERNAL_CODECS_LOC_VARS options.Methods))
+ // hb.Init();
hb.NumErrors = dirItems.Stat.NumErrors;
-
+
+ UInt64 totalSize = 0;
if (options.StdInMode)
{
- RINOK(callback->SetNumFiles(1));
+ RINOK(callback->SetNumFiles(1))
}
else
{
- RINOK(callback->SetTotal(dirItems.Stat.GetTotalBytes()));
+ totalSize = dirItems.Stat.GetTotalBytes();
+ RINOK(callback->SetTotal(totalSize))
}
const UInt32 kBufSize = 1 << 15;
@@ -254,7 +515,12 @@ HRESULT HashCalc(
UInt64 completeValue = 0;
- RINOK(callback->BeforeFirstFile(hb));
+ RINOK(callback->BeforeFirstFile(hb))
+
+ /*
+ CDynLimBuf hashFileString((size_t)1 << 31);
+ const bool needGenerate = !options.HashFilePath.IsEmpty();
+ */
for (i = 0; i < dirItems.Items.Size(); i++)
{
@@ -262,43 +528,79 @@ HRESULT HashCalc(
UString path;
bool isDir = false;
bool isAltStream = false;
+
if (options.StdInMode)
{
inStream = new CStdInFileStream;
}
else
{
- CInFileStream *inStreamSpec = new CInFileStream;
- inStream = inStreamSpec;
- const CDirItem &dirItem = dirItems.Items[i];
- isDir = dirItem.IsDir();
- isAltStream = dirItem.IsAltStream;
path = dirItems.GetLogPath(i);
- if (!isDir)
+ const CDirItem &di = dirItems.Items[i];
+ #ifdef _WIN32
+ isAltStream = di.IsAltStream;
+ #endif
+
+ #ifndef UNDER_CE
+ // if (di.AreReparseData())
+ if (di.ReparseData.Size() != 0)
+ {
+ CBufInStream *inStreamSpec = new CBufInStream();
+ inStream = inStreamSpec;
+ inStreamSpec->Init(di.ReparseData, di.ReparseData.Size());
+ }
+ else
+ #endif
{
- FString phyPath = dirItems.GetPhyPath(i);
- if (!inStreamSpec->OpenShared(phyPath, options.OpenShareForWrite))
+ CInFileStream *inStreamSpec = new CInFileStream;
+ inStreamSpec->Set_PreserveATime(options.PreserveATime);
+ inStream = inStreamSpec;
+ isDir = di.IsDir();
+ if (!isDir)
{
- HRESULT res = callback->OpenFileError(phyPath, ::GetLastError());
- hb.NumErrors++;
- if (res != S_FALSE)
- return res;
- continue;
+ const FString phyPath = dirItems.GetPhyPath(i);
+ if (!inStreamSpec->OpenShared(phyPath, options.OpenShareForWrite))
+ {
+ HRESULT res = callback->OpenFileError(phyPath, ::GetLastError());
+ hb.NumErrors++;
+ if (res != S_FALSE)
+ return res;
+ continue;
+ }
+ if (!options.StdInMode)
+ {
+ UInt64 curSize = 0;
+ if (inStreamSpec->GetSize(&curSize) == S_OK)
+ {
+ if (curSize > di.Size)
+ {
+ totalSize += curSize - di.Size;
+ RINOK(callback->SetTotal(totalSize))
+ // printf("\ntotal = %d MiB\n", (unsigned)(totalSize >> 20));
+ }
+ }
+ }
+ // inStreamSpec->ReloadProps();
}
}
}
- RINOK(callback->GetStream(path, isDir));
+
+ RINOK(callback->GetStream(path, isDir))
UInt64 fileSize = 0;
hb.InitForNewFile();
+
if (!isDir)
{
for (UInt32 step = 0;; step++)
{
if ((step & 0xFF) == 0)
- RINOK(callback->SetCompleted(&completeValue));
+ {
+ // printf("\ncompl = %d\n", (unsigned)(completeValue >> 20));
+ RINOK(callback->SetCompleted(&completeValue))
+ }
UInt32 size;
- RINOK(inStream->Read(buf, kBufSize, &size));
+ RINOK(inStream->Read(buf, kBufSize, &size))
if (size == 0)
break;
hb.Update(buf, size);
@@ -306,20 +608,54 @@ HRESULT HashCalc(
completeValue += size;
}
}
+
hb.Final(isDir, isAltStream, path);
- RINOK(callback->SetOperationResult(fileSize, hb, !isDir));
- RINOK(callback->SetCompleted(&completeValue));
+
+ /*
+ if (needGenerate
+ && (options.HashMode_Dirs.Val || !isDir))
+ {
+ WriteLine(hashFileString,
+ options,
+ path, // change it
+ isDir,
+ hb);
+
+ if (hashFileString.IsError())
+ return E_OUTOFMEMORY;
+ }
+ */
+
+ RINOK(callback->SetOperationResult(fileSize, hb, !isDir))
+ RINOK(callback->SetCompleted(&completeValue))
+ }
+
+ /*
+ if (needGenerate)
+ {
+ NFile::NIO::COutFile file;
+ if (!file.Create(us2fs(options.HashFilePath), true)) // createAlways
+ return GetLastError_noZero_HRESULT();
+ if (!file.WriteFull(hashFileString, hashFileString.Len()))
+ return GetLastError_noZero_HRESULT();
}
+ */
+
return callback->AfterLastFile(hb);
}
-static inline char GetHex(unsigned v)
+static inline char GetHex_Upper(unsigned v)
{
return (char)((v < 10) ? ('0' + v) : ('A' + (v - 10)));
}
-void AddHashHexToString(char *dest, const Byte *data, UInt32 size)
+static inline char GetHex_Lower(unsigned v)
+{
+ return (char)((v < 10) ? ('0' + v) : ('a' + (v - 10)));
+}
+
+void HashHexToString(char *dest, const Byte *data, UInt32 size)
{
dest[size * 2] = 0;
@@ -334,18 +670,1441 @@ void AddHashHexToString(char *dest, const Byte *data, UInt32 size)
return;
}
- int step = 2;
if (size <= 8)
{
- step = -2;
- dest += size * 2 - 2;
+ dest += size * 2;
+ for (UInt32 i = 0; i < size; i++)
+ {
+ const unsigned b = data[i];
+ dest -= 2;
+ dest[0] = GetHex_Upper((b >> 4) & 0xF);
+ dest[1] = GetHex_Upper(b & 0xF);
+ }
+ }
+ else
+ {
+ for (UInt32 i = 0; i < size; i++)
+ {
+ const unsigned b = data[i];
+ dest[0] = GetHex_Lower((b >> 4) & 0xF);
+ dest[1] = GetHex_Lower(b & 0xF);
+ dest += 2;
+ }
+ }
+}
+
+void CHasherState::WriteToString(unsigned digestIndex, char *s) const
+{
+ HashHexToString(s, Digests[digestIndex], DigestSize);
+
+ if (digestIndex != 0 && NumSums[digestIndex] != 1)
+ {
+ unsigned numExtraBytes = GetNumExtraBytes_for_Group(digestIndex);
+ if (numExtraBytes > 4)
+ numExtraBytes = 8;
+ else // if (numExtraBytes >= 0)
+ numExtraBytes = 4;
+ // if (numExtraBytes != 0)
+ {
+ s += strlen(s);
+ *s++ = '-';
+ // *s = 0;
+ HashHexToString(s, GetExtraData_for_Group(digestIndex), numExtraBytes);
+ }
+ }
+}
+
+
+
+// ---------- Hash Handler ----------
+
+namespace NHash {
+
+static size_t ParseHexString(const char *s, Byte *dest) throw()
+{
+ size_t num;
+ for (num = 0;; num++, s += 2)
+ {
+ unsigned c = (Byte)s[0];
+ unsigned v0;
+ if (c >= '0' && c <= '9') v0 = (c - '0');
+ else if (c >= 'A' && c <= 'F') v0 = 10 + (c - 'A');
+ else if (c >= 'a' && c <= 'f') v0 = 10 + (c - 'a');
+ else
+ return num;
+ c = (Byte)s[1];
+ unsigned v1;
+ if (c >= '0' && c <= '9') v1 = (c - '0');
+ else if (c >= 'A' && c <= 'F') v1 = 10 + (c - 'A');
+ else if (c >= 'a' && c <= 'f') v1 = 10 + (c - 'a');
+ else
+ return num;
+ if (dest)
+ dest[num] = (Byte)(v1 | (v0 << 4));
+ }
+}
+
+
+#define IsWhite(c) ((c) == ' ' || (c) == '\t')
+
+bool CHashPair::IsDir() const
+{
+ if (Name.IsEmpty() || Name.Back() != '/')
+ return false;
+ // here we expect that Dir items contain only zeros or no Hash
+ for (size_t i = 0; i < Hash.Size(); i++)
+ if (Hash[i] != 0)
+ return false;
+ return true;
+}
+
+
+bool CHashPair::ParseCksum(const char *s)
+{
+ const char *end;
+
+ const UInt32 crc = ConvertStringToUInt32(s, &end);
+ if (*end != ' ')
+ return false;
+ end++;
+
+ const UInt64 size = ConvertStringToUInt64(end, &end);
+ if (*end != ' ')
+ return false;
+ end++;
+
+ Name = end;
+
+ Hash.Alloc(4);
+ SetBe32(Hash, crc)
+
+ Size_from_Arc = size;
+ Size_from_Arc_Defined = true;
+
+ return true;
+}
+
+
+
+static const char *SkipWhite(const char *s)
+{
+ while (IsWhite(*s))
+ s++;
+ return s;
+}
+
+static const char * const k_CsumMethodNames[] =
+{
+ "sha256"
+ , "sha224"
+// , "sha512/224"
+// , "sha512/256"
+ , "sha512"
+ , "sha384"
+ , "sha1"
+ , "md5"
+ , "blake2b"
+ , "crc64"
+ , "crc32"
+ , "cksum"
+};
+
+static UString GetMethod_from_FileName(const UString &name)
+{
+ AString s;
+ ConvertUnicodeToUTF8(name, s);
+ const int dotPos = s.ReverseFind_Dot();
+ const char *src = s.Ptr();
+ bool isExtension = false;
+ if (dotPos >= 0)
+ {
+ isExtension = true;
+ src = s.Ptr(dotPos + 1);
+ }
+ const char *m = "";
+ unsigned i;
+ for (i = 0; i < Z7_ARRAY_SIZE(k_CsumMethodNames); i++)
+ {
+ m = k_CsumMethodNames[i];
+ if (isExtension)
+ {
+ if (StringsAreEqual_Ascii(src, m))
+ break;
+ }
+ else if (IsString1PrefixedByString2_NoCase_Ascii(src, m))
+ if (StringsAreEqual_Ascii(src + strlen(m), "sums"))
+ break;
+ }
+ UString res;
+ if (i != Z7_ARRAY_SIZE(k_CsumMethodNames))
+ res = m;
+ return res;
+}
+
+
+bool CHashPair::Parse(const char *s)
+{
+ // here we keep compatibility with original md5sum / shasum
+ bool escape = false;
+
+ s = SkipWhite(s);
+
+ if (*s == '\\')
+ {
+ s++;
+ escape = true;
}
- for (UInt32 i = 0; i < size; i++)
+ // const char *kMethod = GetMethod_from_FileName(s);
+ // if (kMethod)
+ if (ParseHexString(s, NULL) < 4)
+ {
+ // BSD-style checksum line
+ {
+ const char *s2 = s;
+ for (; *s2 != 0; s2++)
+ {
+ const char c = *s2;
+ if (c == 0)
+ return false;
+ if (c == ' ' || c == '(')
+ break;
+ }
+ Method.SetFrom(s, (unsigned)(s2 - s));
+ s = s2;
+ }
+ IsBSD = true;
+ if (*s == ' ')
+ s++;
+ if (*s != '(')
+ return false;
+ s++;
+ {
+ const char *s2 = s;
+ for (; *s2 != 0; s2++)
+ {}
+ for (;;)
+ {
+ s2--;
+ if (s2 < s)
+ return false;
+ if (*s2 == ')')
+ break;
+ }
+ Name.SetFrom(s, (unsigned)(s2 - s));
+ s = s2 + 1;
+ }
+
+ s = SkipWhite(s);
+ if (*s != '=')
+ return false;
+ s++;
+ s = SkipWhite(s);
+ }
+
+ {
+ const size_t num = ParseHexString(s, NULL);
+ Hash.Alloc(num);
+ ParseHexString(s, Hash);
+ const size_t numChars = num * 2;
+ HashString.SetFrom(s, (unsigned)numChars);
+ s += numChars;
+ }
+
+ if (IsBSD)
+ {
+ if (*s != 0)
+ return false;
+ if (escape)
+ {
+ const AString temp (Name);
+ return CSum_Name_EscapeToOriginal(temp, Name);
+ }
+ return true;
+ }
+
+ if (*s == 0)
+ return true;
+
+ if (*s != ' ')
+ return false;
+ s++;
+ const char c = *s;
+ if (c != ' '
+ && c != '*'
+ && c != 'U' // shasum Universal
+ && c != '^' // shasum 0/1
+ )
+ return false;
+ Mode = c;
+ s++;
+ if (escape)
+ return CSum_Name_EscapeToOriginal(s, Name);
+ Name = s;
+ return true;
+}
+
+
+static bool GetLine(CByteBuffer &buf, bool zeroMode, bool cr_lf_Mode, size_t &posCur, AString &s)
+{
+ s.Empty();
+ size_t pos = posCur;
+ const Byte *p = buf;
+ unsigned numDigits = 0;
+ for (; pos < buf.Size(); pos++)
+ {
+ const Byte b = p[pos];
+ if (b == 0)
+ {
+ numDigits = 1;
+ break;
+ }
+ if (zeroMode)
+ continue;
+ if (b == 0x0a)
+ {
+ numDigits = 1;
+ break;
+ }
+ if (!cr_lf_Mode)
+ continue;
+ if (b == 0x0d)
+ {
+ if (pos + 1 >= buf.Size())
+ {
+ numDigits = 1;
+ break;
+ // return false;
+ }
+ if (p[pos + 1] == 0x0a)
+ {
+ numDigits = 2;
+ break;
+ }
+ }
+ }
+ s.SetFrom((const char *)(p + posCur), (unsigned)(pos - posCur));
+ posCur = pos + numDigits;
+ return true;
+}
+
+
+static bool Is_CR_LF_Data(const Byte *buf, size_t size)
+{
+ bool isCrLf = false;
+ for (size_t i = 0; i < size;)
+ {
+ const Byte b = buf[i];
+ if (b == 0x0a)
+ return false;
+ if (b == 0x0d)
+ {
+ if (i == size - 1)
+ return false;
+ if (buf[i + 1] != 0x0a)
+ return false;
+ isCrLf = true;
+ i += 2;
+ }
+ else
+ i++;
+ }
+ return isCrLf;
+}
+
+
+static const Byte kArcProps[] =
+{
+ // kpidComment,
+ kpidCharacts
+};
+
+static const Byte kProps[] =
+{
+ kpidPath,
+ kpidSize,
+ kpidPackSize,
+ kpidMethod
+};
+
+static const Byte kRawProps[] =
+{
+ kpidChecksum
+};
+
+
+Z7_COM7F_IMF(CHandler::GetParent(UInt32 /* index */ , UInt32 *parent, UInt32 *parentType))
+{
+ *parentType = NParentType::kDir;
+ *parent = (UInt32)(Int32)-1;
+ return S_OK;
+}
+
+Z7_COM7F_IMF(CHandler::GetNumRawProps(UInt32 *numProps))
+{
+ *numProps = Z7_ARRAY_SIZE(kRawProps);
+ return S_OK;
+}
+
+Z7_COM7F_IMF(CHandler::GetRawPropInfo(UInt32 index, BSTR *name, PROPID *propID))
+{
+ *propID = kRawProps[index];
+ *name = NULL;
+ return S_OK;
+}
+
+Z7_COM7F_IMF(CHandler::GetRawProp(UInt32 index, PROPID propID, const void **data, UInt32 *dataSize, UInt32 *propType))
+{
+ *data = NULL;
+ *dataSize = 0;
+ *propType = 0;
+
+ if (propID == kpidChecksum)
{
- unsigned b = data[i];
- dest[0] = GetHex((b >> 4) & 0xF);
- dest[1] = GetHex(b & 0xF);
- dest += step;
+ const CHashPair &hp = HashPairs[index];
+ if (hp.Hash.Size() > 0)
+ {
+ *data = hp.Hash;
+ *dataSize = (UInt32)hp.Hash.Size();
+ *propType = NPropDataType::kRaw;
+ }
+ return S_OK;
+ }
+
+ return S_OK;
+}
+
+IMP_IInArchive_Props
+IMP_IInArchive_ArcProps
+
+Z7_COM7F_IMF(CHandler::GetNumberOfItems(UInt32 *numItems))
+{
+ *numItems = HashPairs.Size();
+ return S_OK;
+}
+
+static void Add_OptSpace_String(UString &dest, const char *src)
+{
+ dest.Add_Space_if_NotEmpty();
+ dest += src;
+}
+
+Z7_COM7F_IMF(CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value))
+{
+ NWindows::NCOM::CPropVariant prop;
+ switch (propID)
+ {
+ case kpidPhySize: if (_phySize != 0) prop = _phySize; break;
+ /*
+ case kpidErrorFlags:
+ {
+ UInt32 v = 0;
+ if (!_isArc) v |= kpv_ErrorFlags_IsNotArc;
+ // if (_sres == k_Base64_RES_NeedMoreInput) v |= kpv_ErrorFlags_UnexpectedEnd;
+ if (v != 0)
+ prop = v;
+ break;
+ }
+ */
+ case kpidCharacts:
+ {
+ UString s;
+ if (_hashSize_Defined)
+ {
+ s.Add_Space_if_NotEmpty();
+ s.Add_UInt32(_hashSize * 8);
+ s += "-bit";
+ }
+ if (!_nameExtenstion.IsEmpty())
+ {
+ s.Add_Space_if_NotEmpty();
+ s += _nameExtenstion;
+ }
+ if (_is_PgpMethod)
+ {
+ Add_OptSpace_String(s, "PGP");
+ if (!_pgpMethod.IsEmpty())
+ {
+ s += ":";
+ s += _pgpMethod;
+ }
+ }
+ if (_is_ZeroMode)
+ Add_OptSpace_String(s, "ZERO");
+ if (_are_there_Tags)
+ Add_OptSpace_String(s, "TAG");
+ if (_are_there_Dirs)
+ Add_OptSpace_String(s, "DIRS");
+ prop = s;
+ break;
+ }
+
+ case kpidReadOnly:
+ {
+ if (_isArc)
+ if (!CanUpdate())
+ prop = true;
+ break;
+ }
+ }
+ prop.Detach(value);
+ return S_OK;
+}
+
+
+Z7_COM7F_IMF(CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value))
+{
+ // COM_TRY_BEGIN
+ NWindows::NCOM::CPropVariant prop;
+ CHashPair &hp = HashPairs[index];
+ switch (propID)
+ {
+ case kpidIsDir:
+ {
+ prop = hp.IsDir();
+ break;
+ }
+ case kpidPath:
+ {
+ UString path;
+ hp.Get_UString_Path(path);
+
+ NArchive::NItemName::ReplaceToOsSlashes_Remove_TailSlash(path,
+ true); // useBackslashReplacement
+
+ prop = path;
+ break;
+ }
+ case kpidSize:
+ {
+ // client needs processed size of last file
+ if (hp.Size_from_Disk_Defined)
+ prop = (UInt64)hp.Size_from_Disk;
+ else if (hp.Size_from_Arc_Defined)
+ prop = (UInt64)hp.Size_from_Arc;
+ break;
+ }
+ case kpidPackSize:
+ {
+ prop = (UInt64)hp.Hash.Size();
+ break;
+ }
+ case kpidMethod:
+ {
+ if (!hp.Method.IsEmpty())
+ prop = hp.Method;
+ break;
+ }
+ }
+ prop.Detach(value);
+ return S_OK;
+ // COM_TRY_END
+}
+
+
+static HRESULT ReadStream_to_Buf(IInStream *stream, CByteBuffer &buf, IArchiveOpenCallback *openCallback)
+{
+ buf.Free();
+ UInt64 len;
+ RINOK(InStream_AtBegin_GetSize(stream, len))
+ if (len == 0 || len >= ((UInt64)1 << 31))
+ return S_FALSE;
+ buf.Alloc((size_t)len);
+ UInt64 pos = 0;
+ // return ReadStream_FALSE(stream, buf, (size_t)len);
+ for (;;)
+ {
+ const UInt32 kBlockSize = ((UInt32)1 << 24);
+ const UInt32 curSize = (len < kBlockSize) ? (UInt32)len : kBlockSize;
+ UInt32 processedSizeLoc;
+ RINOK(stream->Read((Byte *)buf + pos, curSize, &processedSizeLoc))
+ if (processedSizeLoc == 0)
+ return E_FAIL;
+ len -= processedSizeLoc;
+ pos += processedSizeLoc;
+ if (len == 0)
+ return S_OK;
+ if (openCallback)
+ {
+ const UInt64 files = 0;
+ RINOK(openCallback->SetCompleted(&files, &pos))
+ }
+ }
+}
+
+
+Z7_COM7F_IMF(CHandler::Open(IInStream *stream, const UInt64 *, IArchiveOpenCallback *openCallback))
+{
+ COM_TRY_BEGIN
+ {
+ Close();
+
+ CByteBuffer buf;
+ RINOK(ReadStream_to_Buf(stream, buf, openCallback))
+
+ CObjectVector<CHashPair> &pairs = HashPairs;
+
+ bool zeroMode = false;
+ bool cr_lf_Mode = false;
+ {
+ for (size_t i = 0; i < buf.Size(); i++)
+ if (buf[i] == 0)
+ {
+ zeroMode = true;
+ break;
+ }
+ }
+ _is_ZeroMode = zeroMode;
+ if (!zeroMode)
+ cr_lf_Mode = Is_CR_LF_Data(buf, buf.Size());
+
+ if (openCallback)
+ {
+ Z7_DECL_CMyComPtr_QI_FROM(
+ IArchiveOpenVolumeCallback,
+ openVolumeCallback, openCallback)
+ if (openVolumeCallback)
+ {
+ NCOM::CPropVariant prop;
+ RINOK(openVolumeCallback->GetProperty(kpidName, &prop))
+ if (prop.vt == VT_BSTR)
+ _nameExtenstion = GetMethod_from_FileName(prop.bstrVal);
+ }
+ }
+
+ bool cksumMode = false;
+ if (_nameExtenstion.IsEqualTo_Ascii_NoCase("cksum"))
+ cksumMode = true;
+ _is_CksumMode = cksumMode;
+
+ size_t pos = 0;
+ AString s;
+ bool minusMode = false;
+ unsigned numLines = 0;
+
+ while (pos < buf.Size())
+ {
+ if (!GetLine(buf, zeroMode, cr_lf_Mode, pos, s))
+ return S_FALSE;
+ numLines++;
+ if (s.IsEmpty())
+ continue;
+
+ if (s.IsPrefixedBy_Ascii_NoCase("; "))
+ {
+ if (numLines != 1)
+ return S_FALSE;
+ // comment line of FileVerifier++
+ continue;
+ }
+
+ if (s.IsPrefixedBy_Ascii_NoCase("-----"))
+ {
+ if (minusMode)
+ break; // end of pgp mode
+ minusMode = true;
+ if (s.IsPrefixedBy_Ascii_NoCase("-----BEGIN PGP SIGNED MESSAGE"))
+ {
+ if (_is_PgpMethod)
+ return S_FALSE;
+ if (!GetLine(buf, zeroMode, cr_lf_Mode, pos, s))
+ return S_FALSE;
+ const char *kStart = "Hash: ";
+ if (!s.IsPrefixedBy_Ascii_NoCase(kStart))
+ return S_FALSE;
+ _pgpMethod = s.Ptr((unsigned)strlen(kStart));
+ _is_PgpMethod = true;
+ }
+ continue;
+ }
+
+ CHashPair pair;
+ pair.FullLine = s;
+ if (cksumMode)
+ {
+ if (!pair.ParseCksum(s))
+ return S_FALSE;
+ }
+ else if (!pair.Parse(s))
+ return S_FALSE;
+ pairs.Add(pair);
+ }
+
+ {
+ unsigned hashSize = 0;
+ bool hashSize_Dismatch = false;
+ for (unsigned i = 0; i < HashPairs.Size(); i++)
+ {
+ const CHashPair &hp = HashPairs[i];
+ if (i == 0)
+ hashSize = (unsigned)hp.Hash.Size();
+ else
+ if (hashSize != hp.Hash.Size())
+ hashSize_Dismatch = true;
+
+ if (hp.IsBSD)
+ _are_there_Tags = true;
+ if (!_are_there_Dirs && hp.IsDir())
+ _are_there_Dirs = true;
+ }
+ if (!hashSize_Dismatch && hashSize != 0)
+ {
+ _hashSize = hashSize;
+ _hashSize_Defined = true;
+ }
+ }
+
+ _phySize = buf.Size();
+ _isArc = true;
+ return S_OK;
+ }
+ COM_TRY_END
+}
+
+
+void CHandler::ClearVars()
+{
+ _phySize = 0;
+ _isArc = false;
+ _is_CksumMode = false;
+ _is_PgpMethod = false;
+ _is_ZeroMode = false;
+ _are_there_Tags = false;
+ _are_there_Dirs = false;
+ _hashSize_Defined = false;
+ _hashSize = 0;
+}
+
+
+Z7_COM7F_IMF(CHandler::Close())
+{
+ ClearVars();
+ _nameExtenstion.Empty();
+ _pgpMethod.Empty();
+ HashPairs.Clear();
+ return S_OK;
+}
+
+
+static bool CheckDigests(const Byte *a, const Byte *b, size_t size)
+{
+ if (size <= 8)
+ {
+ /* we use reversed order for one digest, when text representation
+ uses big-order for crc-32 and crc-64 */
+ for (size_t i = 0; i < size; i++)
+ if (a[i] != b[size - 1 - i])
+ return false;
+ return true;
+ }
+ {
+ for (size_t i = 0; i < size; i++)
+ if (a[i] != b[i])
+ return false;
+ return true;
+ }
+}
+
+
+static void AddDefaultMethod(UStringVector &methods, unsigned size)
+{
+ const char *m = NULL;
+ if (size == 32) m = "sha256";
+ else if (size == 20) m = "sha1";
+ else if (size == 16) m = "md5";
+ else if (size == 8) m = "crc64";
+ else if (size == 4) m = "crc32";
+ else
+ return;
+ #ifdef Z7_EXTERNAL_CODECS
+ const CExternalCodecs *_externalCodecs = g_ExternalCodecs_Ptr;
+ #endif
+ CMethodId id;
+ if (FindHashMethod(EXTERNAL_CODECS_LOC_VARS
+ AString(m), id))
+ methods.Add(UString(m));
+}
+
+
+Z7_COM7F_IMF(CHandler::Extract(const UInt32 *indices, UInt32 numItems,
+ Int32 testMode, IArchiveExtractCallback *extractCallback))
+{
+ COM_TRY_BEGIN
+
+ /*
+ if (testMode == 0)
+ return E_NOTIMPL;
+ */
+
+ const bool allFilesMode = (numItems == (UInt32)(Int32)-1);
+ if (allFilesMode)
+ numItems = HashPairs.Size();
+ if (numItems == 0)
+ return S_OK;
+
+ #ifdef Z7_EXTERNAL_CODECS
+ const CExternalCodecs *_externalCodecs = g_ExternalCodecs_Ptr;
+ #endif
+
+ CHashBundle hb_Glob;
+ // UStringVector methods = options.Methods;
+ UStringVector methods;
+
+ if (methods.IsEmpty() && !_nameExtenstion.IsEmpty())
+ {
+ AString utf;
+ ConvertUnicodeToUTF8(_nameExtenstion, utf);
+ CMethodId id;
+ if (FindHashMethod(EXTERNAL_CODECS_LOC_VARS utf, id))
+ methods.Add(_nameExtenstion);
+ }
+
+ if (methods.IsEmpty() && !_pgpMethod.IsEmpty())
+ {
+ CMethodId id;
+ if (FindHashMethod(EXTERNAL_CODECS_LOC_VARS _pgpMethod, id))
+ methods.Add(UString(_pgpMethod));
+ }
+
+ if (methods.IsEmpty() && _pgpMethod.IsEmpty() && _hashSize_Defined)
+ AddDefaultMethod(methods, _hashSize);
+
+ RINOK(hb_Glob.SetMethods(
+ EXTERNAL_CODECS_LOC_VARS
+ methods))
+
+ Z7_DECL_CMyComPtr_QI_FROM(
+ IArchiveUpdateCallbackFile,
+ updateCallbackFile, extractCallback)
+ if (!updateCallbackFile)
+ return E_NOTIMPL;
+ {
+ Z7_DECL_CMyComPtr_QI_FROM(
+ IArchiveGetDiskProperty,
+ GetDiskProperty, extractCallback)
+ if (GetDiskProperty)
+ {
+ UInt64 totalSize = 0;
+ UInt32 i;
+ for (i = 0; i < numItems; i++)
+ {
+ const UInt32 index = allFilesMode ? i : indices[i];
+ const CHashPair &hp = HashPairs[index];
+ if (hp.IsDir())
+ continue;
+ {
+ NCOM::CPropVariant prop;
+ RINOK(GetDiskProperty->GetDiskProperty(index, kpidSize, &prop))
+ if (prop.vt != VT_UI8)
+ continue;
+ totalSize += prop.uhVal.QuadPart;
+ }
+ }
+ RINOK(extractCallback->SetTotal(totalSize))
+ // RINOK(Hash_SetTotalUnpacked->Hash_SetTotalUnpacked(indices, numItems));
+ }
+ }
+
+ const UInt32 kBufSize = 1 << 15;
+ CHashMidBuf buf;
+ if (!buf.Alloc(kBufSize))
+ return E_OUTOFMEMORY;
+
+ CLocalProgress *lps = new CLocalProgress;
+ CMyComPtr<ICompressProgressInfo> progress = lps;
+ lps->Init(extractCallback, false);
+ lps->InSize = lps->OutSize = 0;
+
+ UInt32 i;
+ for (i = 0; i < numItems; i++)
+ {
+ RINOK(lps->SetCur())
+ const UInt32 index = allFilesMode ? i : indices[i];
+
+ CHashPair &hp = HashPairs[index];
+
+ UString path;
+ hp.Get_UString_Path(path);
+
+ CMyComPtr<ISequentialInStream> inStream;
+ const bool isDir = hp.IsDir();
+ if (!isDir)
+ {
+ RINOK(updateCallbackFile->GetStream2(index, &inStream, NUpdateNotifyOp::kHashRead))
+ if (!inStream)
+ {
+ continue; // we have shown error in GetStream2()
+ }
+ // askMode = NArchive::NExtract::NAskMode::kSkip;
+ }
+
+ Int32 askMode = testMode ?
+ NArchive::NExtract::NAskMode::kTest :
+ NArchive::NExtract::NAskMode::kExtract;
+
+ CMyComPtr<ISequentialOutStream> realOutStream;
+ RINOK(extractCallback->GetStream(index, &realOutStream, askMode))
+
+ /* PrepareOperation() can expect kExtract to set
+ Attrib and security of output file */
+ askMode = NArchive::NExtract::NAskMode::kReadExternal;
+
+ extractCallback->PrepareOperation(askMode);
+
+ const bool isAltStream = false;
+
+ UInt64 fileSize = 0;
+
+ CHashBundle hb_Loc;
+
+ CHashBundle *hb_Use = &hb_Glob;
+
+ HRESULT res_SetMethods = S_OK;
+
+ UStringVector methods_loc;
+
+ if (!hp.Method.IsEmpty())
+ {
+ hb_Use = &hb_Loc;
+ CMethodId id;
+ if (FindHashMethod(EXTERNAL_CODECS_LOC_VARS hp.Method, id))
+ {
+ methods_loc.Add(UString(hp.Method));
+ RINOK(hb_Loc.SetMethods(
+ EXTERNAL_CODECS_LOC_VARS
+ methods_loc))
+ }
+ else
+ res_SetMethods = E_NOTIMPL;
+ }
+ else if (methods.IsEmpty())
+ {
+ AddDefaultMethod(methods_loc, (unsigned)hp.Hash.Size());
+ if (!methods_loc.IsEmpty())
+ {
+ hb_Use = &hb_Loc;
+ RINOK(hb_Loc.SetMethods(
+ EXTERNAL_CODECS_LOC_VARS
+ methods_loc))
+ }
+ }
+
+ const bool isSupportedMode = hp.IsSupportedMode();
+ hb_Use->InitForNewFile();
+
+ if (inStream)
+ {
+ for (UInt32 step = 0;; step++)
+ {
+ if ((step & 0xFF) == 0)
+ {
+ RINOK(progress->SetRatioInfo(NULL, &fileSize))
+ }
+ UInt32 size;
+ RINOK(inStream->Read(buf, kBufSize, &size))
+ if (size == 0)
+ break;
+ hb_Use->Update(buf, size);
+ if (realOutStream)
+ {
+ RINOK(WriteStream(realOutStream, buf, size))
+ }
+ fileSize += size;
+ }
+
+ hp.Size_from_Disk = fileSize;
+ hp.Size_from_Disk_Defined = true;
+ }
+
+ realOutStream.Release();
+ inStream.Release();
+
+ lps->InSize += hp.Hash.Size();
+ lps->OutSize += fileSize;
+
+ hb_Use->Final(isDir, isAltStream, path);
+
+ Int32 opRes = NArchive::NExtract::NOperationResult::kUnsupportedMethod;
+ if (isSupportedMode
+ && res_SetMethods != E_NOTIMPL
+ && hb_Use->Hashers.Size() > 0
+ )
+ {
+ const CHasherState &hs = hb_Use->Hashers[0];
+ if (hs.DigestSize == hp.Hash.Size())
+ {
+ opRes = NArchive::NExtract::NOperationResult::kCRCError;
+ if (CheckDigests(hp.Hash, hs.Digests[0], hs.DigestSize))
+ if (!hp.Size_from_Arc_Defined || hp.Size_from_Arc == fileSize)
+ opRes = NArchive::NExtract::NOperationResult::kOK;
+ }
+ }
+
+ RINOK(extractCallback->SetOperationResult(opRes))
+ }
+
+ return lps->SetCur();
+
+ COM_TRY_END
+}
+
+
+// ---------- UPDATE ----------
+
+struct CUpdateItem
+{
+ int IndexInArc;
+ unsigned IndexInClient;
+ UInt64 Size;
+ bool NewData;
+ bool NewProps;
+ bool IsDir;
+ UString Path;
+
+ CUpdateItem(): Size(0), IsDir(false) {}
+};
+
+
+static HRESULT GetPropString(IArchiveUpdateCallback *callback, UInt32 index, PROPID propId,
+ UString &res,
+ bool convertSlash)
+{
+ NCOM::CPropVariant prop;
+ RINOK(callback->GetProperty(index, propId, &prop))
+ if (prop.vt == VT_BSTR)
+ {
+ res = prop.bstrVal;
+ if (convertSlash)
+ NArchive::NItemName::ReplaceSlashes_OsToUnix(res);
+ }
+ else if (prop.vt != VT_EMPTY)
+ return E_INVALIDARG;
+ return S_OK;
+}
+
+
+Z7_COM7F_IMF(CHandler::GetFileTimeType(UInt32 *type))
+{
+ *type = NFileTimeType::kUnix;
+ return S_OK;
+}
+
+
+Z7_COM7F_IMF(CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numItems,
+ IArchiveUpdateCallback *callback))
+{
+ COM_TRY_BEGIN
+
+ if (_isArc && !CanUpdate())
+ return E_NOTIMPL;
+
+ /*
+ Z7_DECL_CMyComPtr_QI_FROM(IArchiveUpdateCallbackArcProp,
+ reportArcProp, callback)
+ */
+
+ CObjectVector<CUpdateItem> updateItems;
+
+ UInt64 complexity = 0;
+
+ UInt32 i;
+ for (i = 0; i < numItems; i++)
+ {
+ CUpdateItem ui;
+ Int32 newData;
+ Int32 newProps;
+ UInt32 indexInArc;
+
+ if (!callback)
+ return E_FAIL;
+
+ RINOK(callback->GetUpdateItemInfo(i, &newData, &newProps, &indexInArc))
+
+ ui.NewProps = IntToBool(newProps);
+ ui.NewData = IntToBool(newData);
+ ui.IndexInArc = (int)indexInArc;
+ ui.IndexInClient = i;
+ if (IntToBool(newProps))
+ {
+ {
+ NCOM::CPropVariant prop;
+ RINOK(callback->GetProperty(i, kpidIsDir, &prop))
+ if (prop.vt == VT_EMPTY)
+ ui.IsDir = false;
+ else if (prop.vt != VT_BOOL)
+ return E_INVALIDARG;
+ else
+ ui.IsDir = (prop.boolVal != VARIANT_FALSE);
+ }
+
+ RINOK(GetPropString(callback, i, kpidPath, ui.Path,
+ true)) // convertSlash
+ /*
+ if (ui.IsDir && !ui.Name.IsEmpty() && ui.Name.Back() != '/')
+ ui.Name += '/';
+ */
+ }
+
+ if (IntToBool(newData))
+ {
+ NCOM::CPropVariant prop;
+ RINOK(callback->GetProperty(i, kpidSize, &prop))
+ if (prop.vt == VT_UI8)
+ {
+ ui.Size = prop.uhVal.QuadPart;
+ complexity += ui.Size;
+ }
+ else if (prop.vt == VT_EMPTY)
+ ui.Size = (UInt64)(Int64)-1;
+ else
+ return E_INVALIDARG;
+ }
+
+ updateItems.Add(ui);
+ }
+
+ if (complexity != 0)
+ {
+ RINOK(callback->SetTotal(complexity))
+ }
+
+ #ifdef Z7_EXTERNAL_CODECS
+ const CExternalCodecs *_externalCodecs = g_ExternalCodecs_Ptr;
+ #endif
+
+ CHashBundle hb;
+ UStringVector methods;
+ if (!_methods.IsEmpty())
+ {
+ FOR_VECTOR(k, _methods)
+ {
+ methods.Add(_methods[k]);
+ }
+ }
+ else if (_crcSize_WasSet)
+ {
+ AddDefaultMethod(methods, _crcSize);
+ }
+ else
+ {
+ Z7_DECL_CMyComPtr_QI_FROM(
+ IArchiveGetRootProps,
+ getRootProps, callback)
+ if (getRootProps)
+ {
+ NCOM::CPropVariant prop;
+ RINOK(getRootProps->GetRootProp(kpidArcFileName, &prop))
+ if (prop.vt == VT_BSTR)
+ {
+ const UString method = GetMethod_from_FileName(prop.bstrVal);
+ if (!method.IsEmpty())
+ methods.Add(method);
+ }
+ }
+ }
+
+ RINOK(hb.SetMethods(EXTERNAL_CODECS_LOC_VARS methods))
+
+ CLocalProgress *lps = new CLocalProgress;
+ CMyComPtr<ICompressProgressInfo> progress = lps;
+ lps->Init(callback, true);
+
+ const UInt32 kBufSize = 1 << 15;
+ CHashMidBuf buf;
+ if (!buf.Alloc(kBufSize))
+ return E_OUTOFMEMORY;
+
+ CDynLimBuf hashFileString((size_t)1 << 31);
+
+ CHashOptionsLocal options = _options;
+
+ if (_isArc)
+ {
+ if (!options.HashMode_Zero.Def && _is_ZeroMode)
+ options.HashMode_Zero.Val = true;
+ if (!options.HashMode_Tag.Def && _are_there_Tags)
+ options.HashMode_Tag.Val = true;
+ if (!options.HashMode_Dirs.Def && _are_there_Dirs)
+ options.HashMode_Dirs.Val = true;
+ }
+ if (options.HashMode_OnlyHash.Val && updateItems.Size() != 1)
+ options.HashMode_OnlyHash.Val = false;
+
+ lps->OutSize = 0;
+ complexity = 0;
+
+ for (i = 0; i < updateItems.Size(); i++)
+ {
+ lps->InSize = complexity;
+ RINOK(lps->SetCur())
+
+ const CUpdateItem &ui = updateItems[i];
+
+ /*
+ CHashPair item;
+ if (!ui.NewProps)
+ item = HashPairs[(unsigned)ui.IndexInArc];
+ */
+
+ if (ui.NewData)
+ {
+ UInt64 currentComplexity = ui.Size;
+ UInt64 fileSize = 0;
+
+ CMyComPtr<ISequentialInStream> fileInStream;
+ bool needWrite = true;
+ {
+ HRESULT res = callback->GetStream(ui.IndexInClient, &fileInStream);
+
+ if (res == S_FALSE)
+ needWrite = false;
+ else
+ {
+ RINOK(res)
+
+ if (fileInStream)
+ {
+ Z7_DECL_CMyComPtr_QI_FROM(
+ IStreamGetSize,
+ streamGetSize, fileInStream)
+ if (streamGetSize)
+ {
+ UInt64 size;
+ if (streamGetSize->GetSize(&size) == S_OK)
+ currentComplexity = size;
+ }
+ /*
+ Z7_DECL_CMyComPtr_QI_FROM(
+ IStreamGetProps,
+ getProps, fileInStream)
+ if (getProps)
+ {
+ FILETIME mTime;
+ UInt64 size2;
+ if (getProps->GetProps(&size2, NULL, NULL, &mTime, NULL) == S_OK)
+ {
+ currentComplexity = size2;
+ // item.MTime = NWindows::NTime::FileTimeToUnixTime64(mTime);;
+ }
+ }
+ */
+ }
+ else
+ {
+ currentComplexity = 0;
+ }
+ }
+ }
+
+ hb.InitForNewFile();
+ const bool isDir = ui.IsDir;
+
+ if (needWrite && fileInStream && !isDir)
+ {
+ for (UInt32 step = 0;; step++)
+ {
+ if ((step & 0xFF) == 0)
+ {
+ RINOK(progress->SetRatioInfo(&fileSize, NULL))
+ // RINOK(callback->SetCompleted(&completeValue));
+ }
+ UInt32 size;
+ RINOK(fileInStream->Read(buf, kBufSize, &size))
+ if (size == 0)
+ break;
+ hb.Update(buf, size);
+ fileSize += size;
+ }
+ currentComplexity = fileSize;
+ }
+
+ fileInStream.Release();
+ const bool isAltStream = false;
+ hb.Final(isDir, isAltStream, ui.Path);
+
+ if (options.HashMode_Dirs.Val || !isDir)
+ {
+ if (!hb.Hashers.IsEmpty())
+ lps->OutSize += hb.Hashers[0].DigestSize;
+ WriteLine(hashFileString,
+ options,
+ ui.Path,
+ isDir,
+ hb);
+ if (hashFileString.IsError())
+ return E_OUTOFMEMORY;
+ }
+
+ complexity += currentComplexity;
+
+ /*
+ if (reportArcProp)
+ {
+ PROPVARIANT prop;
+ prop.vt = VT_EMPTY;
+ prop.wReserved1 = 0;
+
+ NCOM::PropVarEm_Set_UInt64(&prop, fileSize);
+ RINOK(reportArcProp->ReportProp(NArchive::NEventIndexType::kOutArcIndex, ui.IndexInClient, kpidSize, &prop));
+
+ for (unsigned k = 0; k < hb.Hashers.Size(); k++)
+ {
+ const CHasherState &hs = hb.Hashers[k];
+
+ if (hs.DigestSize == 4 && hs.Name.IsEqualTo_Ascii_NoCase("crc32"))
+ {
+ NCOM::PropVarEm_Set_UInt32(&prop, GetUi32(hs.Digests[k_HashCalc_Index_Current]));
+ RINOK(reportArcProp->ReportProp(NArchive::NEventIndexType::kOutArcIndex, ui.IndexInClient, kpidCRC, &prop));
+ }
+ else
+ {
+ RINOK(reportArcProp->ReportRawProp(NArchive::NEventIndexType::kOutArcIndex, ui.IndexInClient,
+ kpidChecksum, hs.Digests[k_HashCalc_Index_Current],
+ hs.DigestSize, NPropDataType::kRaw));
+ }
+ RINOK(reportArcProp->ReportFinished(NArchive::NEventIndexType::kOutArcIndex, ui.IndexInClient, NArchive::NUpdate::NOperationResult::kOK));
+ }
+ }
+ */
+ RINOK(callback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK))
+ }
+ else
+ {
+ // old data
+ const CHashPair &existItem = HashPairs[(unsigned)ui.IndexInArc];
+ if (ui.NewProps)
+ {
+ WriteLine(hashFileString,
+ options,
+ ui.Path,
+ ui.IsDir,
+ existItem.Method, existItem.HashString
+ );
+ }
+ else
+ {
+ hashFileString += existItem.FullLine;
+ Add_LF(hashFileString, options);
+ }
+ }
+ if (hashFileString.IsError())
+ return E_OUTOFMEMORY;
+ }
+
+ RINOK(WriteStream(outStream, hashFileString, hashFileString.Len()))
+
+ return S_OK;
+ COM_TRY_END
+}
+
+
+
+HRESULT CHandler::SetProperty(const wchar_t *nameSpec, const PROPVARIANT &value)
+{
+ UString name = nameSpec;
+ name.MakeLower_Ascii();
+ if (name.IsEmpty())
+ return E_INVALIDARG;
+
+ if (name.IsEqualTo("m")) // "hm" hash method
+ {
+ // COneMethodInfo omi;
+ // RINOK(omi.ParseMethodFromPROPVARIANT(L"", value));
+ // _methods.Add(omi.MethodName); // change it. use omi.PropsString
+ if (value.vt != VT_BSTR)
+ return E_INVALIDARG;
+ UString s (value.bstrVal);
+ _methods.Add(s);
+ return S_OK;
+ }
+
+ if (name.IsEqualTo("flags"))
+ {
+ if (value.vt != VT_BSTR)
+ return E_INVALIDARG;
+ if (!_options.ParseString(value.bstrVal))
+ return E_INVALIDARG;
+ return S_OK;
+ }
+
+ if (name.IsPrefixedBy_Ascii_NoCase("crc"))
+ {
+ name.Delete(0, 3);
+ _crcSize = 4;
+ _crcSize_WasSet = true;
+ return ParsePropToUInt32(name, value, _crcSize);
+ }
+
+ // common properties
+ if (name.IsPrefixedBy_Ascii_NoCase("mt")
+ || name.IsPrefixedBy_Ascii_NoCase("memuse"))
+ return S_OK;
+
+ return E_INVALIDARG;
+}
+
+
+Z7_COM7F_IMF(CHandler::SetProperties(const wchar_t * const *names, const PROPVARIANT *values, UInt32 numProps))
+{
+ COM_TRY_BEGIN
+
+ InitProps();
+
+ for (UInt32 i = 0; i < numProps; i++)
+ {
+ RINOK(SetProperty(names[i], values[i]))
+ }
+ return S_OK;
+ COM_TRY_END
+}
+
+CHandler::CHandler()
+{
+ ClearVars();
+ InitProps();
+}
+
+}
+
+
+
+static IInArchive *CreateHashHandler_In() { return new NHash::CHandler; }
+static IOutArchive *CreateHashHandler_Out() { return new NHash::CHandler; }
+
+void Codecs_AddHashArcHandler(CCodecs *codecs)
+{
+ {
+ CArcInfoEx item;
+
+ item.Name = "Hash";
+ item.CreateInArchive = CreateHashHandler_In;
+ item.CreateOutArchive = CreateHashHandler_Out;
+ item.IsArcFunc = NULL;
+ item.Flags =
+ NArcInfoFlags::kKeepName
+ | NArcInfoFlags::kStartOpen
+ | NArcInfoFlags::kByExtOnlyOpen
+ // | NArcInfoFlags::kPureStartOpen
+ | NArcInfoFlags::kHashHandler
+ ;
+
+ // ubuntu uses "SHA256SUMS" file
+ item.AddExts(UString (
+ "sha256 sha512 sha224 sha384 sha1 sha md5"
+ // "b2sum"
+ " crc32 crc64"
+ " asc"
+ " cksum"
+ ),
+ UString());
+
+ item.UpdateEnabled = (item.CreateOutArchive != NULL);
+ item.SignatureOffset = 0;
+ // item.Version = MY_VER_MIX;
+ item.NewInterface = true;
+
+ item.Signatures.AddNew().CopyFrom(NULL, 0);
+
+ codecs->Formats.Add(item);
}
}
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/HashCalc.h b/3rdparty/lzma/CPP/7zip/UI/Common/HashCalc.h
index 38908e2e8b3..0b527c16497 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/HashCalc.h
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/HashCalc.h
@@ -1,20 +1,27 @@
// HashCalc.h
-#ifndef __HASH_CALC_H
-#define __HASH_CALC_H
+#ifndef ZIP7_INC_HASH_CALC_H
+#define ZIP7_INC_HASH_CALC_H
+#include "../../../Common/UTFConvert.h"
#include "../../../Common/Wildcard.h"
#include "../../Common/CreateCoder.h"
#include "../../Common/MethodProps.h"
#include "DirItem.h"
-#include "Property.h"
+#include "IFileExtractCallback.h"
const unsigned k_HashCalc_DigestSize_Max = 64;
-
+const unsigned k_HashCalc_ExtraSize = 8;
const unsigned k_HashCalc_NumGroups = 4;
+/*
+ if (size <= 8) : upper case : reversed byte order : it shows 32-bit/64-bit number, if data contains little-endian number
+ if (size > 8) : lower case : original byte order (as big-endian byte sequence)
+*/
+void HashHexToString(char *dest, const Byte *data, UInt32 size);
+
enum
{
k_HashCalc_Index_Current,
@@ -28,10 +35,40 @@ struct CHasherState
CMyComPtr<IHasher> Hasher;
AString Name;
UInt32 DigestSize;
- Byte Digests[k_HashCalc_NumGroups][k_HashCalc_DigestSize_Max];
+ UInt64 NumSums[k_HashCalc_NumGroups];
+ Byte Digests[k_HashCalc_NumGroups][k_HashCalc_DigestSize_Max + k_HashCalc_ExtraSize];
+
+ void InitDigestGroup(unsigned groupIndex)
+ {
+ NumSums[groupIndex] = 0;
+ memset(Digests[groupIndex], 0, sizeof(Digests[groupIndex]));
+ }
+
+ const Byte *GetExtraData_for_Group(unsigned groupIndex) const
+ {
+ return Digests[groupIndex] + k_HashCalc_DigestSize_Max;
+ }
+
+ unsigned GetNumExtraBytes_for_Group(unsigned groupIndex) const
+ {
+ const Byte *p = GetExtraData_for_Group(groupIndex);
+ // we use little-endian to read extra bytes
+ for (unsigned i = k_HashCalc_ExtraSize; i != 0; i--)
+ if (p[i - 1] != 0)
+ return i;
+ return 0;
+ }
+
+ void AddDigest(unsigned groupIndex, const Byte *data);
+
+ void WriteToString(unsigned digestIndex, char *s) const;
};
-struct IHashCalc
+
+Z7_PURE_INTERFACES_BEGIN
+
+
+DECLARE_INTERFACE(IHashCalc)
{
virtual void InitForNewFile() = 0;
virtual void Update(const void *data, UInt32 size) = 0;
@@ -39,7 +76,9 @@ struct IHashCalc
virtual void Final(bool isDir, bool isAltStream, const UString &path) = 0;
};
-struct CHashBundle: public IHashCalc
+Z7_PURE_INTERFACES_END
+
+struct CHashBundle Z7_final: public IHashCalc
{
CObjectVector<CHasherState> Hashers;
@@ -52,49 +91,123 @@ struct CHashBundle: public IHashCalc
UInt64 CurSize;
+ UString MainName;
+ UString FirstFileName;
+
HRESULT SetMethods(DECL_EXTERNAL_CODECS_LOC_VARS const UStringVector &methods);
- void Init()
+ // void Init() {}
+ CHashBundle()
{
NumDirs = NumFiles = NumAltStreams = FilesSize = AltStreamsSize = NumErrors = 0;
}
- void InitForNewFile();
- void Update(const void *data, UInt32 size);
- void SetSize(UInt64 size);
- void Final(bool isDir, bool isAltStream, const UString &path);
+ void InitForNewFile() Z7_override;
+ void Update(const void *data, UInt32 size) Z7_override;
+ void SetSize(UInt64 size) Z7_override;
+ void Final(bool isDir, bool isAltStream, const UString &path) Z7_override;
};
-#define INTERFACE_IHashCallbackUI(x) \
- INTERFACE_IDirItemsCallback(x) \
- virtual HRESULT StartScanning() x; \
- virtual HRESULT FinishScanning(const CDirItemsStat &st) x; \
- virtual HRESULT SetNumFiles(UInt64 numFiles) x; \
- virtual HRESULT SetTotal(UInt64 size) x; \
- virtual HRESULT SetCompleted(const UInt64 *completeValue) x; \
- virtual HRESULT CheckBreak() x; \
- virtual HRESULT BeforeFirstFile(const CHashBundle &hb) x; \
- virtual HRESULT GetStream(const wchar_t *name, bool isFolder) x; \
- virtual HRESULT OpenFileError(const FString &path, DWORD systemError) x; \
- virtual HRESULT SetOperationResult(UInt64 fileSize, const CHashBundle &hb, bool showHash) x; \
- virtual HRESULT AfterLastFile(const CHashBundle &hb) x; \
-
-struct IHashCallbackUI: public IDirItemsCallback
+Z7_PURE_INTERFACES_BEGIN
+
+// INTERFACE_IDirItemsCallback(x)
+
+#define Z7_IFACEN_IHashCallbackUI(x) \
+ virtual HRESULT StartScanning() x \
+ virtual HRESULT FinishScanning(const CDirItemsStat &st) x \
+ virtual HRESULT SetNumFiles(UInt64 numFiles) x \
+ virtual HRESULT SetTotal(UInt64 size) x \
+ virtual HRESULT SetCompleted(const UInt64 *completeValue) x \
+ virtual HRESULT CheckBreak() x \
+ virtual HRESULT BeforeFirstFile(const CHashBundle &hb) x \
+ virtual HRESULT GetStream(const wchar_t *name, bool isFolder) x \
+ virtual HRESULT OpenFileError(const FString &path, DWORD systemError) x \
+ virtual HRESULT SetOperationResult(UInt64 fileSize, const CHashBundle &hb, bool showHash) x \
+ virtual HRESULT AfterLastFile(CHashBundle &hb) x \
+
+Z7_IFACE_DECL_PURE_(IHashCallbackUI, IDirItemsCallback)
+
+Z7_PURE_INTERFACES_END
+
+
+struct CHashOptionsLocal
{
- INTERFACE_IHashCallbackUI(=0)
+ CBoolPair HashMode_Zero;
+ CBoolPair HashMode_Tag;
+ CBoolPair HashMode_Dirs;
+ CBoolPair HashMode_OnlyHash;
+
+ void Init_HashOptionsLocal()
+ {
+ HashMode_Zero.Init();
+ HashMode_Tag.Init();
+ HashMode_Dirs.Init();
+ HashMode_OnlyHash.Init();
+ // HashMode_Dirs = true; // for debug
+ }
+
+ CHashOptionsLocal()
+ {
+ Init_HashOptionsLocal();
+ }
+
+ bool ParseFlagCharOption(wchar_t c, bool val)
+ {
+ c = MyCharLower_Ascii(c);
+ if (c == 'z') HashMode_Zero.SetVal_as_Defined(val);
+ else if (c == 't') HashMode_Tag.SetVal_as_Defined(val);
+ else if (c == 'd') HashMode_Dirs.SetVal_as_Defined(val);
+ else if (c == 'h') HashMode_OnlyHash.SetVal_as_Defined(val);
+ else return false;
+ return true;
+ }
+
+ bool ParseString(const UString &s)
+ {
+ for (unsigned i = 0; i < s.Len();)
+ {
+ const wchar_t c = s[i++];
+ bool val = true;
+ if (i < s.Len())
+ {
+ const wchar_t next = s[i];
+ if (next == '-')
+ {
+ val = false;
+ i++;
+ }
+ }
+ if (!ParseFlagCharOption(c, val))
+ return false;
+ }
+ return true;
+ }
};
+
struct CHashOptions
+ // : public CHashOptionsLocal
{
UStringVector Methods;
+ // UString HashFilePath;
+
+ bool PreserveATime;
bool OpenShareForWrite;
bool StdInMode;
bool AltStreamsMode;
+ CBoolPair SymLinks;
+
NWildcard::ECensorPathMode PathMode;
-
- CHashOptions(): StdInMode(false), OpenShareForWrite(false), AltStreamsMode(false), PathMode(NWildcard::k_RelatPath) {};
+
+ CHashOptions():
+ PreserveATime(false),
+ OpenShareForWrite(false),
+ StdInMode(false),
+ AltStreamsMode(false),
+ PathMode(NWildcard::k_RelatPath) {}
};
+
HRESULT HashCalc(
DECL_EXTERNAL_CODECS_LOC_VARS
const NWildcard::CCensor &censor,
@@ -102,6 +215,114 @@ HRESULT HashCalc(
AString &errorInfo,
IHashCallbackUI *callback);
-void AddHashHexToString(char *dest, const Byte *data, UInt32 size);
+
+
+#ifndef Z7_SFX
+
+namespace NHash {
+
+struct CHashPair
+{
+ CByteBuffer Hash;
+ char Mode;
+ bool IsBSD;
+ bool Size_from_Arc_Defined;
+ bool Size_from_Disk_Defined;
+ AString Method;
+ AString Name;
+
+ AString FullLine;
+ AString HashString;
+ // unsigned HashLengthInBits;
+
+ // AString MethodName;
+ UInt64 Size_from_Arc;
+ UInt64 Size_from_Disk;
+
+ bool IsDir() const;
+
+ void Get_UString_Path(UString &path) const
+ {
+ path.Empty();
+ if (!ConvertUTF8ToUnicode(Name, path))
+ return;
+ }
+
+ bool ParseCksum(const char *s);
+ bool Parse(const char *s);
+
+ bool IsSupportedMode() const
+ {
+ return Mode != 'U' && Mode != '^';
+ }
+
+ CHashPair():
+ Mode(0)
+ , IsBSD(false)
+ , Size_from_Arc_Defined(false)
+ , Size_from_Disk_Defined(false)
+ // , HashLengthInBits(0)
+ , Size_from_Arc(0)
+ , Size_from_Disk(0)
+ {}
+};
+
+
+Z7_CLASS_IMP_CHandler_IInArchive_3(
+ IArchiveGetRawProps,
+ /* public IGetArchiveHashHandler, */
+ IOutArchive,
+ ISetProperties
+)
+ bool _isArc;
+ UInt64 _phySize;
+ CObjectVector<CHashPair> HashPairs;
+ UString _nameExtenstion;
+ // UString _method_fromName;
+ AString _pgpMethod;
+ bool _is_CksumMode;
+ bool _is_PgpMethod;
+ bool _is_ZeroMode;
+ bool _are_there_Tags;
+ bool _are_there_Dirs;
+ bool _hashSize_Defined;
+ unsigned _hashSize;
+
+ bool _crcSize_WasSet;
+ UInt32 _crcSize;
+ UStringVector _methods;
+
+ void ClearVars();
+
+ void InitProps()
+ {
+ _crcSize_WasSet = false;
+ _crcSize = 4;
+ _methods.Clear();
+ _options.Init_HashOptionsLocal();
+ }
+
+ CHashOptionsLocal _options;
+
+ bool CanUpdate() const
+ {
+ if (!_isArc || _is_PgpMethod || _is_CksumMode)
+ return false;
+ return true;
+
+ }
+
+ HRESULT SetProperty(const wchar_t *nameSpec, const PROPVARIANT &value);
+
+public:
+ CHandler();
+};
+
+}
+
+void Codecs_AddHashArcHandler(CCodecs *codecs);
+
+#endif
+
#endif
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/IFileExtractCallback.h b/3rdparty/lzma/CPP/7zip/UI/Common/IFileExtractCallback.h
index c456c862737..dd5c0d7214e 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/IFileExtractCallback.h
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/IFileExtractCallback.h
@@ -1,7 +1,7 @@
// IFileExtractCallback.h
-#ifndef __I_FILE_EXTRACT_CALLBACK_H
-#define __I_FILE_EXTRACT_CALLBACK_H
+#ifndef ZIP7_INC_I_FILE_EXTRACT_CALLBACK_H
+#define ZIP7_INC_I_FILE_EXTRACT_CALLBACK_H
#include "../../../Common/MyString.h"
@@ -10,6 +10,15 @@
#include "LoadCodecs.h"
#include "OpenArchive.h"
+Z7_PURE_INTERFACES_BEGIN
+
+#define Z7_IFACE_CONSTR_FOLDERARC_SUB(i, base, n) \
+ Z7_DECL_IFACE_7ZIP_SUB(i, base, 1, n) \
+ { Z7_IFACE_COM7_PURE(i) };
+
+#define Z7_IFACE_CONSTR_FOLDERARC(i, n) \
+ Z7_IFACE_CONSTR_FOLDERARC_SUB(i, IUnknown, n)
+
namespace NOverwriteAnswer
{
enum EEnum
@@ -42,27 +51,21 @@ IID_IFolderArchiveExtractCallback is requested by:
IFolderArchiveExtractCallback is used by Common/ArchiveExtractCallback.cpp
*/
-#define INTERFACE_IFolderArchiveExtractCallback(x) \
- STDMETHOD(AskOverwrite)( \
+#define Z7_IFACEM_IFolderArchiveExtractCallback(x) \
+ x(AskOverwrite( \
const wchar_t *existName, const FILETIME *existTime, const UInt64 *existSize, \
const wchar_t *newName, const FILETIME *newTime, const UInt64 *newSize, \
- Int32 *answer) x; \
- STDMETHOD(PrepareOperation)(const wchar_t *name, Int32 isFolder, Int32 askExtractMode, const UInt64 *position) x; \
- STDMETHOD(MessageError)(const wchar_t *message) x; \
- STDMETHOD(SetOperationResult)(Int32 opRes, Int32 encrypted) x; \
+ Int32 *answer)) \
+ x(PrepareOperation(const wchar_t *name, Int32 isFolder, Int32 askExtractMode, const UInt64 *position)) \
+ x(MessageError(const wchar_t *message)) \
+ x(SetOperationResult(Int32 opRes, Int32 encrypted)) \
-DECL_INTERFACE_SUB(IFolderArchiveExtractCallback, IProgress, 0x01, 0x07)
-{
- INTERFACE_IFolderArchiveExtractCallback(PURE)
-};
+Z7_IFACE_CONSTR_FOLDERARC_SUB(IFolderArchiveExtractCallback, IProgress, 0x07)
-#define INTERFACE_IFolderArchiveExtractCallback2(x) \
- STDMETHOD(ReportExtractResult)(Int32 opRes, Int32 encrypted, const wchar_t *name) x; \
+#define Z7_IFACEM_IFolderArchiveExtractCallback2(x) \
+ x(ReportExtractResult(Int32 opRes, Int32 encrypted, const wchar_t *name)) \
-DECL_INTERFACE_SUB(IFolderArchiveExtractCallback2, IUnknown, 0x01, 0x08)
-{
- INTERFACE_IFolderArchiveExtractCallback2(PURE)
-};
+Z7_IFACE_CONSTR_FOLDERARC(IFolderArchiveExtractCallback2, 0x08)
/* ---------- IExtractCallbackUI ----------
is implemented by
@@ -70,45 +73,40 @@ is implemented by
FileManager/ExtractCallback.h CExtractCallbackImp
*/
-#ifdef _NO_CRYPTO
- #define INTERFACE_IExtractCallbackUI_Crypto(x)
+#ifdef Z7_NO_CRYPTO
+ #define Z7_IFACEM_IExtractCallbackUI_Crypto(px)
#else
- #define INTERFACE_IExtractCallbackUI_Crypto(x) \
- virtual HRESULT SetPassword(const UString &password) x;
+ #define Z7_IFACEM_IExtractCallbackUI_Crypto(px) \
+ virtual HRESULT SetPassword(const UString &password) px
#endif
-#define INTERFACE_IExtractCallbackUI(x) \
- virtual HRESULT BeforeOpen(const wchar_t *name, bool testMode) x; \
- virtual HRESULT OpenResult(const CCodecs *codecs, const CArchiveLink &arcLink, const wchar_t *name, HRESULT result) x; \
- virtual HRESULT ThereAreNoFiles() x; \
- virtual HRESULT ExtractResult(HRESULT result) x; \
- INTERFACE_IExtractCallbackUI_Crypto(x)
+#define Z7_IFACEN_IExtractCallbackUI(px) \
+ virtual HRESULT BeforeOpen(const wchar_t *name, bool testMode) px \
+ virtual HRESULT OpenResult(const CCodecs *codecs, const CArchiveLink &arcLink, const wchar_t *name, HRESULT result) px \
+ virtual HRESULT ThereAreNoFiles() px \
+ virtual HRESULT ExtractResult(HRESULT result) px \
+ Z7_IFACEM_IExtractCallbackUI_Crypto(px)
-struct IExtractCallbackUI: IFolderArchiveExtractCallback
-{
- INTERFACE_IExtractCallbackUI(PURE)
-};
+// IExtractCallbackUI - is non-COM interface
+// IFolderArchiveExtractCallback - is COM interface
+// Z7_IFACE_DECL_PURE_(IExtractCallbackUI, IFolderArchiveExtractCallback)
+Z7_IFACE_DECL_PURE(IExtractCallbackUI)
-#define INTERFACE_IGetProp(x) \
- STDMETHOD(GetProp)(PROPID propID, PROPVARIANT *value) x; \
+#define Z7_IFACEM_IGetProp(x) \
+ x(GetProp(PROPID propID, PROPVARIANT *value)) \
-DECL_INTERFACE_SUB(IGetProp, IUnknown, 0x01, 0x20)
-{
- INTERFACE_IGetProp(PURE)
-};
+Z7_IFACE_CONSTR_FOLDERARC(IGetProp, 0x20)
-#define INTERFACE_IFolderExtractToStreamCallback(x) \
- STDMETHOD(UseExtractToStream)(Int32 *res) x; \
- STDMETHOD(GetStream7)(const wchar_t *name, Int32 isDir, ISequentialOutStream **outStream, Int32 askExtractMode, IGetProp *getProp) x; \
- STDMETHOD(PrepareOperation7)(Int32 askExtractMode) x; \
- STDMETHOD(SetOperationResult7)(Int32 resultEOperationResult, Int32 encrypted) x; \
+#define Z7_IFACEM_IFolderExtractToStreamCallback(x) \
+ x(UseExtractToStream(Int32 *res)) \
+ x(GetStream7(const wchar_t *name, Int32 isDir, ISequentialOutStream **outStream, Int32 askExtractMode, IGetProp *getProp)) \
+ x(PrepareOperation7(Int32 askExtractMode)) \
+ x(SetOperationResult8(Int32 resultEOperationResult, Int32 encrypted, UInt64 size)) \
-DECL_INTERFACE_SUB(IFolderExtractToStreamCallback, IUnknown, 0x01, 0x30)
-{
- INTERFACE_IFolderExtractToStreamCallback(PURE)
-};
+Z7_IFACE_CONSTR_FOLDERARC(IFolderExtractToStreamCallback, 0x31)
+Z7_PURE_INTERFACES_END
#endif
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/LoadCodecs.cpp b/3rdparty/lzma/CPP/7zip/UI/Common/LoadCodecs.cpp
index 5435499baa8..5a65bdcee83 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/LoadCodecs.cpp
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/LoadCodecs.cpp
@@ -1,7 +1,7 @@
// LoadCodecs.cpp
/*
-EXTERNAL_CODECS
+Z7_EXTERNAL_CODECS
---------------
CCodecs::Load() tries to detect the directory with plugins.
It stops the checking, if it can find any of the following items:
@@ -22,7 +22,7 @@ EXTERNAL_CODECS
EXPORT_CODECS
-------------
- if (EXTERNAL_CODECS) is defined, then the code exports internal
+ if (Z7_EXTERNAL_CODECS) is defined, then the code exports internal
codecs of client from CCodecs object to external plugins.
7-Zip doesn't use that feature. 7-Zip uses the scheme:
- client application without internal plugins.
@@ -33,38 +33,25 @@ EXPORT_CODECS
#include "StdAfx.h"
-#include "../../../../C/7zVersion.h"
-
#include "../../../Common/MyCom.h"
#include "../../../Common/StringToInt.h"
#include "../../../Common/StringConvert.h"
+#include "../../../Windows/ErrorMsg.h"
+#include "../../../Windows/FileIO.h"
#include "../../../Windows/PropVariant.h"
#include "LoadCodecs.h"
-using namespace NWindows;
-
-#ifdef NEW_FOLDER_INTERFACE
-#include "../../../Common/StringToInt.h"
-#endif
-
#include "../../ICoder.h"
#include "../../Common/RegisterArc.h"
+#include "../../Common/RegisterCodec.h"
-#ifdef EXTERNAL_CODECS
-
+#ifdef Z7_EXTERNAL_CODECS
// #define EXPORT_CODECS
-
-#endif
-
-#ifdef NEW_FOLDER_INTERFACE
-extern HINSTANCE g_hInstance;
-#include "../../../Windows/ResourceString.h"
-static const UINT kIconTypesResId = 100;
#endif
-#ifdef EXTERNAL_CODECS
+#ifdef Z7_EXTERNAL_CODECS
#include "../../../Windows/FileFind.h"
#include "../../../Windows/DLL.h"
@@ -74,6 +61,7 @@ static const UINT kIconTypesResId = 100;
#include "../../../Windows/Registry.h"
#endif
+using namespace NWindows;
using namespace NFile;
@@ -81,19 +69,19 @@ using namespace NFile;
#define kFormatsFolderName FTEXT("Formats")
-static CFSTR kMainDll =
- // #ifdef _WIN32
+static CFSTR const kMainDll =
+ #ifdef _WIN32
FTEXT("7z.dll");
- // #else
- // FTEXT("7z.so");
- // #endif
+ #else
+ FTEXT("7z.so");
+ #endif
#ifdef _WIN32
-static LPCTSTR kRegistryPath = TEXT("Software") TEXT(STRING_PATH_SEPARATOR) TEXT("7-zip");
-static LPCWSTR kProgramPathValue = L"Path";
-static LPCWSTR kProgramPath2Value = L"Path"
+static LPCTSTR const kRegistryPath = TEXT("Software") TEXT(STRING_PATH_SEPARATOR) TEXT("7-zip");
+static LPCWSTR const kProgramPathValue = L"Path";
+static LPCWSTR const kProgramPath2Value = L"Path"
#ifdef _WIN64
L"64";
#else
@@ -110,7 +98,7 @@ static bool ReadPathFromRegistry(HKEY baseKey, LPCWSTR value, FString &path)
{
path = us2fs(pathU);
NName::NormalizeDirPathPrefix(path);
- return NFind::DoesFileExist(path + kMainDll);
+ return NFind::DoesFileExist_Raw(path + kMainDll);
}
}
return false;
@@ -118,10 +106,10 @@ static bool ReadPathFromRegistry(HKEY baseKey, LPCWSTR value, FString &path)
#endif // _WIN32
-#endif // EXTERNAL_CODECS
+#endif // Z7_EXTERNAL_CODECS
-static const unsigned kNumArcsMax = 64;
+static const unsigned kNumArcsMax = 72;
static unsigned g_NumArcs = 0;
static const CArcInfo *g_Arcs[kNumArcsMax];
@@ -132,8 +120,10 @@ void RegisterArc(const CArcInfo *arcInfo) throw()
g_Arcs[g_NumArcs] = arcInfo;
g_NumArcs++;
}
+ // else throw 1;
}
+/*
static void SplitString(const UString &srcString, UStringVector &destStrings)
{
destStrings.Clear();
@@ -158,12 +148,13 @@ static void SplitString(const UString &srcString, UStringVector &destStrings)
if (!s.IsEmpty())
destStrings.Add(s);
}
+*/
int CArcInfoEx::FindExtension(const UString &ext) const
{
FOR_VECTOR (i, Exts)
if (ext.IsEqualTo_NoCase(Exts[i].Ext))
- return i;
+ return (int)i;
return -1;
}
@@ -186,14 +177,14 @@ void CArcInfoEx::AddExts(const UString &ext, const UString &addExt)
}
}
-#ifndef _SFX
+#ifndef Z7_SFX
static bool ParseSignatures(const Byte *data, unsigned size, CObjectVector<CByteBuffer> &signatures)
{
signatures.Clear();
- while (size > 0)
+ while (size != 0)
{
- unsigned len = *data++;
+ const unsigned len = *data++;
size--;
if (len > size)
return false;
@@ -204,17 +195,20 @@ static bool ParseSignatures(const Byte *data, unsigned size, CObjectVector<CByte
return true;
}
-#endif // _SFX
+#endif // Z7_SFX
+
+// #include <stdio.h>
-#ifdef EXTERNAL_CODECS
+#ifdef Z7_EXTERNAL_CODECS
static FString GetBaseFolderPrefixFromRegistry()
{
FString moduleFolderPrefix = NDLL::GetModuleDirPrefix();
+
#ifdef _WIN32
- if (!NFind::DoesFileExist(moduleFolderPrefix + kMainDll) &&
- !NFind::DoesDirExist(moduleFolderPrefix + kCodecsFolderName) &&
- !NFind::DoesDirExist(moduleFolderPrefix + kFormatsFolderName))
+ if ( !NFind::DoesFileOrDirExist(moduleFolderPrefix + kMainDll)
+ && !NFind::DoesFileOrDirExist(moduleFolderPrefix + kCodecsFolderName)
+ && !NFind::DoesFileOrDirExist(moduleFolderPrefix + kFormatsFolderName))
{
FString path;
if (ReadPathFromRegistry(HKEY_CURRENT_USER, kProgramPath2Value, path)) return path;
@@ -223,6 +217,8 @@ static FString GetBaseFolderPrefixFromRegistry()
if (ReadPathFromRegistry(HKEY_LOCAL_MACHINE, kProgramPathValue, path)) return path;
}
#endif
+
+ // printf("\nmoduleFolderPrefix = %s\n", (const char *)GetAnsiString(moduleFolderPrefix));
return moduleFolderPrefix;
}
@@ -232,50 +228,80 @@ static HRESULT GetCoderClass(Func_GetMethodProperty getMethodProperty, UInt32 in
{
NCOM::CPropVariant prop;
isAssigned = false;
- RINOK(getMethodProperty(index, propId, &prop));
+ RINOK(getMethodProperty(index, propId, &prop))
if (prop.vt == VT_BSTR)
{
if (::SysStringByteLen(prop.bstrVal) != sizeof(GUID))
return E_FAIL;
isAssigned = true;
- clsId = *(const GUID *)prop.bstrVal;
+ clsId = *(const GUID *)(const void *)prop.bstrVal;
}
else if (prop.vt != VT_EMPTY)
return E_FAIL;
return S_OK;
}
+
+static HRESULT GetMethodBoolProp(Func_GetMethodProperty getMethodProperty, UInt32 index,
+ PROPID propId, bool &resVal, bool &isAssigned)
+{
+ NCOM::CPropVariant prop;
+ resVal = false;
+ isAssigned = false;
+ RINOK(getMethodProperty(index, propId, &prop))
+ if (prop.vt == VT_BOOL)
+ {
+ isAssigned = true;
+ resVal = VARIANT_BOOLToBool(prop.boolVal);
+ }
+ else if (prop.vt != VT_EMPTY)
+ return E_FAIL;
+ return S_OK;
+}
+
+#if defined(__clang__)
+#pragma GCC diagnostic ignored "-Wc++98-compat-pedantic"
+#endif
+
+#define MY_GET_FUNC(dest, type, lib, func) \
+ dest = Z7_GET_PROC_ADDRESS(type, lib.Get_HMODULE(), func);
+// #define MY_GET_FUNC(dest, type, func) dest = (type)(func);
+
+#define MY_GET_FUNC_LOC(dest, type, lib, func) \
+ type dest; MY_GET_FUNC(dest, type, lib, func)
+
HRESULT CCodecs::LoadCodecs()
{
CCodecLib &lib = Libs.Back();
- lib.CreateDecoder = (Func_CreateDecoder)lib.Lib.GetProc("CreateDecoder");
- lib.CreateEncoder = (Func_CreateEncoder)lib.Lib.GetProc("CreateEncoder");
- lib.GetMethodProperty = (Func_GetMethodProperty)lib.Lib.GetProc("GetMethodProperty");
+ MY_GET_FUNC (lib.CreateDecoder, Func_CreateDecoder, lib.Lib, "CreateDecoder")
+ MY_GET_FUNC (lib.CreateEncoder, Func_CreateEncoder, lib.Lib, "CreateEncoder")
+ MY_GET_FUNC (lib.GetMethodProperty, Func_GetMethodProperty, lib.Lib, "GetMethodProperty")
if (lib.GetMethodProperty)
{
UInt32 numMethods = 1;
- Func_GetNumberOfMethods getNumberOfMethods = (Func_GetNumberOfMethods)lib.Lib.GetProc("GetNumberOfMethods");
+ MY_GET_FUNC_LOC (getNumberOfMethods, Func_GetNumberOfMethods, lib.Lib, "GetNumberOfMethods")
if (getNumberOfMethods)
{
- RINOK(getNumberOfMethods(&numMethods));
+ RINOK(getNumberOfMethods(&numMethods))
}
for (UInt32 i = 0; i < numMethods; i++)
{
CDllCodecInfo info;
info.LibIndex = Libs.Size() - 1;
info.CodecIndex = i;
- RINOK(GetCoderClass(lib.GetMethodProperty, i, NMethodPropID::kEncoder, info.Encoder, info.EncoderIsAssigned));
- RINOK(GetCoderClass(lib.GetMethodProperty, i, NMethodPropID::kDecoder, info.Decoder, info.DecoderIsAssigned));
+ RINOK(GetCoderClass(lib.GetMethodProperty, i, NMethodPropID::kEncoder, info.Encoder, info.EncoderIsAssigned))
+ RINOK(GetCoderClass(lib.GetMethodProperty, i, NMethodPropID::kDecoder, info.Decoder, info.DecoderIsAssigned))
+ RINOK(GetMethodBoolProp(lib.GetMethodProperty, i, NMethodPropID::kIsFilter, info.IsFilter, info.IsFilter_Assigned))
Codecs.Add(info);
}
}
- Func_GetHashers getHashers = (Func_GetHashers)lib.Lib.GetProc("GetHashers");
+ MY_GET_FUNC_LOC (getHashers, Func_GetHashers, lib.Lib, "GetHashers")
if (getHashers)
{
- RINOK(getHashers(&lib.ComHashers));
+ RINOK(getHashers(&lib.ComHashers))
if (lib.ComHashers)
{
UInt32 numMethods = lib.ComHashers->GetNumHashers();
@@ -298,7 +324,7 @@ static HRESULT GetProp(
UInt32 index, PROPID propID, NCOM::CPropVariant &prop)
{
if (getProp2)
- return getProp2(index, propID, &prop);;
+ return getProp2(index, propID, &prop);
return getProp(propID, &prop);
}
@@ -309,7 +335,7 @@ static HRESULT GetProp_Bool(
{
res = false;
NCOM::CPropVariant prop;
- RINOK(GetProp(getProp, getProp2, index, propID, prop));
+ RINOK(GetProp(getProp, getProp2, index, propID, prop))
if (prop.vt == VT_BOOL)
res = VARIANT_BOOLToBool(prop.boolVal);
else if (prop.vt != VT_EMPTY)
@@ -325,7 +351,7 @@ static HRESULT GetProp_UInt32(
res = 0;
defined = false;
NCOM::CPropVariant prop;
- RINOK(GetProp(getProp, getProp2, index, propID, prop));
+ RINOK(GetProp(getProp, getProp2, index, propID, prop))
if (prop.vt == VT_UI4)
{
res = prop.ulVal;
@@ -343,7 +369,7 @@ static HRESULT GetProp_String(
{
res.Empty();
NCOM::CPropVariant prop;
- RINOK(GetProp(getProp, getProp2, index, propID, prop));
+ RINOK(GetProp(getProp, getProp2, index, propID, prop))
if (prop.vt == VT_BSTR)
res.SetFromBstr(prop.bstrVal);
else if (prop.vt != VT_EMPTY)
@@ -358,7 +384,7 @@ static HRESULT GetProp_RawData(
{
bb.Free();
NCOM::CPropVariant prop;
- RINOK(GetProp(getProp, getProp2, index, propID, prop));
+ RINOK(GetProp(getProp, getProp2, index, propID, prop))
if (prop.vt == VT_BSTR)
{
UINT len = ::SysStringByteLen(prop.bstrVal);
@@ -381,22 +407,22 @@ HRESULT CCodecs::LoadFormats()
const NDLL::CLibrary &lib = Libs.Back().Lib;
Func_GetHandlerProperty getProp = NULL;
- Func_GetHandlerProperty2 getProp2 = (Func_GetHandlerProperty2)lib.GetProc("GetHandlerProperty2");
- Func_GetIsArc getIsArc = (Func_GetIsArc)lib.GetProc("GetIsArc");
+ MY_GET_FUNC_LOC (getProp2, Func_GetHandlerProperty2, lib, "GetHandlerProperty2")
+ MY_GET_FUNC_LOC (getIsArc, Func_GetIsArc, lib, "GetIsArc")
UInt32 numFormats = 1;
if (getProp2)
{
- Func_GetNumberOfFormats getNumberOfFormats = (Func_GetNumberOfFormats)lib.GetProc("GetNumberOfFormats");
+ MY_GET_FUNC_LOC (getNumberOfFormats, Func_GetNumberOfFormats, lib, "GetNumberOfFormats")
if (getNumberOfFormats)
{
- RINOK(getNumberOfFormats(&numFormats));
+ RINOK(getNumberOfFormats(&numFormats))
}
}
else
{
- getProp = (Func_GetHandlerProperty)lib.GetProc("GetHandlerProperty");
+ MY_GET_FUNC (getProp, Func_GetHandlerProperty, lib, "GetHandlerProperty")
if (!getProp)
return S_OK;
}
@@ -404,10 +430,10 @@ HRESULT CCodecs::LoadFormats()
for (UInt32 i = 0; i < numFormats; i++)
{
CArcInfoEx item;
- item.LibIndex = Libs.Size() - 1;
+ item.LibIndex = (int)(Libs.Size() - 1);
item.FormatIndex = i;
- RINOK(GetProp_String(getProp, getProp2, i, NArchive::NHandlerPropID::kName, item.Name));
+ RINOK(GetProp_String(getProp, getProp2, i, NArchive::NHandlerPropID::kName, item.Name))
{
NCOM::CPropVariant prop;
@@ -417,23 +443,23 @@ HRESULT CCodecs::LoadFormats()
continue;
if (::SysStringByteLen(prop.bstrVal) != sizeof(GUID))
return E_FAIL;
- item.ClassID = *(const GUID *)prop.bstrVal;
+ item.ClassID = *(const GUID *)(const void *)prop.bstrVal;
prop.Clear();
}
UString ext, addExt;
- RINOK(GetProp_String(getProp, getProp2, i, NArchive::NHandlerPropID::kExtension, ext));
- RINOK(GetProp_String(getProp, getProp2, i, NArchive::NHandlerPropID::kAddExtension, addExt));
+ RINOK(GetProp_String(getProp, getProp2, i, NArchive::NHandlerPropID::kExtension, ext))
+ RINOK(GetProp_String(getProp, getProp2, i, NArchive::NHandlerPropID::kAddExtension, addExt))
item.AddExts(ext, addExt);
GetProp_Bool(getProp, getProp2, i, NArchive::NHandlerPropID::kUpdate, item.UpdateEnabled);
bool flags_Defined = false;
- RINOK(GetProp_UInt32(getProp, getProp2, i, NArchive::NHandlerPropID::kFlags, item.Flags, flags_Defined));
+ RINOK(GetProp_UInt32(getProp, getProp2, i, NArchive::NHandlerPropID::kFlags, item.Flags, flags_Defined))
item.NewInterface = flags_Defined;
if (!flags_Defined) // && item.UpdateEnabled
{
// support for DLL version before 9.31:
- for (unsigned j = 0; j < ARRAY_SIZE(kArcFlagsPars); j += 2)
+ for (unsigned j = 0; j < Z7_ARRAY_SIZE(kArcFlagsPars); j += 2)
{
bool val = false;
GetProp_Bool(getProp, getProp2, i, kArcFlagsPars[j], val);
@@ -441,19 +467,24 @@ HRESULT CCodecs::LoadFormats()
item.Flags |= kArcFlagsPars[j + 1];
}
}
+
+ {
+ bool defined = false;
+ RINOK(GetProp_UInt32(getProp, getProp2, i, NArchive::NHandlerPropID::kTimeFlags, item.TimeFlags, defined))
+ }
CByteBuffer sig;
- RINOK(GetProp_RawData(getProp, getProp2, i, NArchive::NHandlerPropID::kSignature, sig));
+ RINOK(GetProp_RawData(getProp, getProp2, i, NArchive::NHandlerPropID::kSignature, sig))
if (sig.Size() != 0)
item.Signatures.Add(sig);
else
{
- RINOK(GetProp_RawData(getProp, getProp2, i, NArchive::NHandlerPropID::kMultiSignature, sig));
+ RINOK(GetProp_RawData(getProp, getProp2, i, NArchive::NHandlerPropID::kMultiSignature, sig))
ParseSignatures(sig, (unsigned)sig.Size(), item.Signatures);
}
bool signatureOffset_Defined;
- RINOK(GetProp_UInt32(getProp, getProp2, i, NArchive::NHandlerPropID::kSignatureOffset, item.SignatureOffset, signatureOffset_Defined));
+ RINOK(GetProp_UInt32(getProp, getProp2, i, NArchive::NHandlerPropID::kSignatureOffset, item.SignatureOffset, signatureOffset_Defined))
// bool version_Defined;
// RINOK(GetProp_UInt32(getProp, getProp2, i, NArchive::NHandlerPropID::kVersion, item.Version, version_Defined));
@@ -466,86 +497,246 @@ HRESULT CCodecs::LoadFormats()
return S_OK;
}
-#ifdef _7ZIP_LARGE_PAGES
+#ifdef Z7_LARGE_PAGES
extern "C"
{
extern SIZE_T g_LargePageSize;
}
#endif
+
+void CCodecs::AddLastError(const FString &path)
+{
+ const HRESULT res = GetLastError_noZero_HRESULT();
+ CCodecError &error = Errors.AddNew();
+ error.Path = path;
+ error.ErrorCode = res;
+}
+
+
+static bool IsSupportedDll(CCodecLib &lib)
+{
+ MY_GET_FUNC_LOC (
+ f_GetModuleProp,
+ Func_GetModuleProp, lib.Lib,
+ "GetModuleProp")
+ /* p7zip and 7-Zip before v23 used virtual destructor in IUnknown,
+ if _WIN32 is not defined */
+ UInt32 flags =
+ #ifdef _WIN32
+ NModuleInterfaceType::k_IUnknown_VirtDestructor_No;
+ #else
+ NModuleInterfaceType::k_IUnknown_VirtDestructor_Yes;
+ #endif
+ if (f_GetModuleProp)
+ {
+ {
+ NCOM::CPropVariant prop;
+ if (f_GetModuleProp(NModulePropID::kInterfaceType, &prop) == S_OK)
+ {
+ if (prop.vt == VT_UI4)
+ flags = prop.ulVal;
+ else if (prop.vt != VT_EMPTY)
+ return false;
+ }
+ }
+ {
+ NCOM::CPropVariant prop;
+ if (f_GetModuleProp(NModulePropID::kVersion, &prop) == S_OK)
+ {
+ if (prop.vt == VT_UI4)
+ lib.Version = prop.ulVal;
+ }
+ }
+ }
+ if (
+ flags
+ // (flags & NModuleFlags::kMask)
+ != NModuleInterfaceType::k_IUnknown_VirtDestructor_ThisModule)
+ return false;
+ return true;
+}
+
+
HRESULT CCodecs::LoadDll(const FString &dllPath, bool needCheckDll, bool *loadedOK)
{
if (loadedOK)
*loadedOK = false;
+ // needCheckDll = 1;
+
+ #ifdef _WIN32
if (needCheckDll)
{
NDLL::CLibrary lib;
if (!lib.LoadEx(dllPath, LOAD_LIBRARY_AS_DATAFILE))
+ {
+ /* if is not win32
+ // %1 is not a valid Win32 application.
+ // #define ERROR_BAD_EXE_FORMAT 193L
+ */
+ // return GetLastError_noZero_HRESULT();
+ const DWORD lastError = GetLastError();
+ if (lastError != ERROR_BAD_EXE_FORMAT)
+ {
+ CCodecError &error = Errors.AddNew();
+ error.Path = dllPath;
+ error.Message = "cannot load file as datafile library";
+ error.ErrorCode = HRESULT_FROM_WIN32(lastError);
+ }
return S_OK;
+ }
}
+ #else
+ UNUSED_VAR(needCheckDll)
+ #endif
Libs.AddNew();
CCodecLib &lib = Libs.Back();
lib.Path = dllPath;
bool used = false;
- HRESULT res = S_OK;
+ // HRESULT res = S_OK;
- if (lib.Lib.Load(dllPath))
+ if (lib.Lib.Load(dllPath))
+ {
+ if (!IsSupportedDll(lib))
+ {
+ CCodecError &error = Errors.AddNew();
+ error.Path = dllPath;
+ error.Message = "the module is not compatible with program";
+ }
+ else
{
if (loadedOK)
*loadedOK = true;
+ /*
#ifdef NEW_FOLDER_INTERFACE
lib.LoadIcons();
#endif
+ */
- #ifdef _7ZIP_LARGE_PAGES
+ /*
+ {
+ MY_GET_FUNC_LOC (_libStartup, Func_libStartup, lib.Lib, "LibStartup")
+ if (_libStartup)
+ {
+ HRESULT res = _libStartup();
+ if (res != 0)
+ {
+ CCodecError &error = Errors.AddNew();
+ error.Path = dllPath;
+ error.ErrorCode = res;
+ }
+ }
+ }
+ */
+
+ #ifdef Z7_LARGE_PAGES
if (g_LargePageSize != 0)
{
- Func_SetLargePageMode setLargePageMode = (Func_SetLargePageMode)lib.Lib.GetProc("SetLargePageMode");
+ MY_GET_FUNC_LOC (setLargePageMode, Func_SetLargePageMode, lib.Lib, "SetLargePageMode")
if (setLargePageMode)
setLargePageMode();
}
#endif
- if (CaseSensitiveChange)
+ if (CaseSensitive_Change)
{
- Func_SetCaseSensitive setCaseSensitive = (Func_SetCaseSensitive)lib.Lib.GetProc("SetCaseSensitive");
+ MY_GET_FUNC_LOC (setCaseSensitive, Func_SetCaseSensitive, lib.Lib, "SetCaseSensitive")
if (setCaseSensitive)
setCaseSensitive(CaseSensitive ? 1 : 0);
}
- lib.CreateObject = (Func_CreateObject)lib.Lib.GetProc("CreateObject");
- if (lib.CreateObject)
+ /*
+ {
+ MY_GET_FUNC_LOC (setClientVersion, Func_SetClientVersion, lib.Lib, "SetClientVersion")
+ if (setClientVersion)
+ {
+ // const UInt32 kVersion = (MY_VER_MAJOR << 16) | MY_VER_MINOR;
+ setClientVersion(g_ClientVersion);
+ }
+ }
+ */
+
+
+ MY_GET_FUNC (lib.CreateObject, Func_CreateObject, lib.Lib, "CreateObject")
{
unsigned startSize = Codecs.Size() + Hashers.Size();
- res = LoadCodecs();
- used = (startSize != Codecs.Size() + Hashers.Size());
- if (res == S_OK)
+ HRESULT res = LoadCodecs();
+ if (startSize != Codecs.Size() + Hashers.Size())
+ used = true;
+ if (res == S_OK && lib.CreateObject)
{
startSize = Formats.Size();
res = LoadFormats();
if (startSize != Formats.Size())
used = true;
}
+ if (res != S_OK)
+ {
+ CCodecError &error = Errors.AddNew();
+ error.Path = dllPath;
+ error.ErrorCode = res;
+ }
+ }
+ // plugins can use non-7-zip dlls, so we silently ignore non7zip DLLs
+ /*
+ if (!used)
+ {
+ CCodecError &error = Errors.AddNew();
+ error.Path = dllPath;
+ error.Message = "no 7-Zip code";
}
+ */
+ }
+ }
+ else
+ {
+ AddLastError(dllPath);
}
if (!used)
Libs.DeleteBack();
- return res;
+ return S_OK;
}
-HRESULT CCodecs::LoadDllsFromFolder(const FString &folderPrefix)
+HRESULT CCodecs::LoadDllsFromFolder(const FString &folderPath)
{
- NFile::NFind::CEnumerator enumerator(folderPrefix + FCHAR_ANY_MASK);
- NFile::NFind::CFileInfo fi;
- while (enumerator.Next(fi))
+ if (!NFile::NFind::DoesDirExist_FollowLink(folderPath))
+ // if (!NFile::NFind::DoesDirExist(folderPath))
{
+ // AddLastError(folderPath);
+ return S_OK;
+ }
+
+ FString folderPrefix = folderPath;
+ folderPrefix.Add_PathSepar();
+
+ NFile::NFind::CEnumerator enumerator;
+ enumerator.SetDirPrefix(folderPrefix);
+ NFile::NFind::CDirEntry fi;
+ for (;;)
+ {
+ bool found;
+ if (!enumerator.Next(fi, found))
+ {
+ // it can be wrong Symbolic link to folder here
+ AddLastError(folderPath);
+ break;
+ // return GetLastError_noZero_HRESULT();
+ }
+ if (!found)
+ break;
+ #ifdef _WIN32
if (fi.IsDir())
continue;
- RINOK(LoadDll(folderPrefix + fi.Name, true));
+ #else
+ if (enumerator.DirEntry_IsDir(fi, true)) // followLink
+ continue;
+ #endif
+
+ RINOK(LoadDll(folderPrefix + fi.Name, true))
}
return S_OK;
}
@@ -573,18 +764,21 @@ void CCodecs::CloseLibs()
// OutputDebugStringA("~CloseLibs end");
}
-#endif // EXTERNAL_CODECS
+#endif // Z7_EXTERNAL_CODECS
HRESULT CCodecs::Load()
{
+ /*
#ifdef NEW_FOLDER_INTERFACE
InternalIcons.LoadIcons(g_hInstance);
#endif
+ */
Formats.Clear();
- #ifdef EXTERNAL_CODECS
+ #ifdef Z7_EXTERNAL_CODECS
+ Errors.Clear();
MainDll_ErrorPath.Empty();
Codecs.Clear();
Hashers.Clear();
@@ -595,7 +789,7 @@ HRESULT CCodecs::Load()
const CArcInfo &arc = *g_Arcs[i];
CArcInfoEx item;
- item.Name.SetFromAscii(arc.Name);
+ item.Name = arc.Name;
item.CreateInArchive = arc.CreateInArchive;
item.IsArcFunc = arc.IsArc;
item.Flags = arc.Flags;
@@ -603,13 +797,13 @@ HRESULT CCodecs::Load()
{
UString e, ae;
if (arc.Ext)
- e.SetFromAscii(arc.Ext);
+ e = arc.Ext;
if (arc.AddExt)
- ae.SetFromAscii(arc.AddExt);
+ ae = arc.AddExt;
item.AddExts(e, ae);
}
- #ifndef _SFX
+ #ifndef Z7_SFX
item.CreateOutArchive = arc.CreateOutArchive;
item.UpdateEnabled = (arc.CreateOutArchive != NULL);
@@ -620,23 +814,28 @@ HRESULT CCodecs::Load()
if (arc.IsMultiSignature())
ParseSignatures(arc.Signature, arc.SignatureSize, item.Signatures);
else
- item.Signatures.AddNew().CopyFrom(arc.Signature, arc.SignatureSize);
+ {
+ if (arc.SignatureSize != 0) // 21.04
+ item.Signatures.AddNew().CopyFrom(arc.Signature, arc.SignatureSize);
+ }
#endif
Formats.Add(item);
}
- #ifdef EXTERNAL_CODECS
+ // printf("\nLoad codecs \n");
+
+ #ifdef Z7_EXTERNAL_CODECS
const FString baseFolder = GetBaseFolderPrefixFromRegistry();
{
bool loadedOK;
- RINOK(LoadDll(baseFolder + kMainDll, false, &loadedOK));
+ RINOK(LoadDll(baseFolder + kMainDll, false, &loadedOK))
if (!loadedOK)
MainDll_ErrorPath = kMainDll;
}
- RINOK(LoadDllsFromFolder(baseFolder + kCodecsFolderName FSTRING_PATH_SEPARATOR));
- RINOK(LoadDllsFromFolder(baseFolder + kFormatsFolderName FSTRING_PATH_SEPARATOR));
+ RINOK(LoadDllsFromFolder(baseFolder + kCodecsFolderName))
+ RINOK(LoadDllsFromFolder(baseFolder + kFormatsFolderName))
NeedSetLibCodecs = true;
@@ -659,27 +858,29 @@ HRESULT CCodecs::Load()
FOR_VECTOR(i, Libs)
{
CCodecLib &lib = Libs[i];
- lib.SetCodecs = (Func_SetCodecs)lib.Lib.GetProc("SetCodecs");
+ MY_GET_FUNC (lib.SetCodecs, Func_SetCodecs, lib.Lib, "SetCodecs")
if (lib.SetCodecs)
{
- RINOK(lib.SetCodecs(this));
+ RINOK(lib.SetCodecs(this))
}
}
}
#endif
+ // we sort Formats to get fixed order of Formats after compilation.
+ Formats.Sort();
return S_OK;
}
-#ifndef _SFX
+#ifndef Z7_SFX
int CCodecs::FindFormatForArchiveName(const UString &arcPath) const
{
int dotPos = arcPath.ReverseFind_Dot();
if (dotPos <= arcPath.ReverseFind_PathSepar())
return -1;
- const UString ext = arcPath.Ptr(dotPos + 1);
+ const UString ext = arcPath.Ptr((unsigned)(dotPos + 1));
if (ext.IsEmpty())
return -1;
if (ext.IsEqualTo_Ascii_NoCase("exe"))
@@ -692,7 +893,7 @@ int CCodecs::FindFormatForArchiveName(const UString &arcPath) const
continue;
*/
if (arc.FindExtension(ext) >= 0)
- return i;
+ return (int)i;
}
return -1;
}
@@ -703,7 +904,7 @@ int CCodecs::FindFormatForExtension(const UString &ext) const
return -1;
FOR_VECTOR (i, Formats)
if (Formats[i].FindExtension(ext) >= 0)
- return i;
+ return (int)i;
return -1;
}
@@ -711,7 +912,7 @@ int CCodecs::FindFormatForArchiveType(const UString &arcType) const
{
FOR_VECTOR (i, Formats)
if (Formats[i].Name.IsEqualTo_NoCase(arcType))
- return i;
+ return (int)i;
return -1;
}
@@ -722,8 +923,8 @@ bool CCodecs::FindFormatForArchiveType(const UString &arcType, CIntVector &forma
{
int pos2 = arcType.Find(L'.', pos);
if (pos2 < 0)
- pos2 = arcType.Len();
- const UString name = arcType.Mid(pos, pos2 - pos);
+ pos2 = (int)arcType.Len();
+ const UString name = arcType.Mid(pos, (unsigned)pos2 - pos);
if (name.IsEmpty())
return false;
int index = FindFormatForArchiveType(name);
@@ -733,65 +934,15 @@ bool CCodecs::FindFormatForArchiveType(const UString &arcType, CIntVector &forma
return false;
}
formatIndices.Add(index);
- pos = pos2 + 1;
+ pos = (unsigned)pos2 + 1;
}
return true;
}
-#endif // _SFX
-
-
-#ifdef NEW_FOLDER_INTERFACE
-
-void CCodecIcons::LoadIcons(HMODULE m)
-{
- UString iconTypes;
- MyLoadString(m, kIconTypesResId, iconTypes);
- UStringVector pairs;
- SplitString(iconTypes, pairs);
- FOR_VECTOR (i, pairs)
- {
- const UString &s = pairs[i];
- int pos = s.Find(L':');
- CIconPair iconPair;
- iconPair.IconIndex = -1;
- if (pos < 0)
- pos = s.Len();
- else
- {
- UString num = s.Ptr(pos + 1);
- if (!num.IsEmpty())
- {
- const wchar_t *end;
- iconPair.IconIndex = ConvertStringToUInt32(num, &end);
- if (*end != 0)
- continue;
- }
- }
- iconPair.Ext = s.Left(pos);
- IconPairs.Add(iconPair);
- }
-}
-
-bool CCodecIcons::FindIconIndex(const UString &ext, int &iconIndex) const
-{
- iconIndex = -1;
- FOR_VECTOR (i, IconPairs)
- {
- const CIconPair &pair = IconPairs[i];
- if (ext.IsEqualTo_NoCase(pair.Ext))
- {
- iconIndex = pair.IconIndex;
- return true;
- }
- }
- return false;
-}
+#endif // Z7_SFX
-#endif // NEW_FOLDER_INTERFACE
-
-#ifdef EXTERNAL_CODECS
+#ifdef Z7_EXTERNAL_CODECS
// #define EXPORT_CODECS
@@ -815,24 +966,24 @@ STDAPI GetHasherProp(UInt32 codecIndex, PROPID propID, PROPVARIANT *value);
#endif // EXPORT_CODECS
-STDMETHODIMP CCodecs::GetNumMethods(UInt32 *numMethods)
+Z7_COM7F_IMF(CCodecs::GetNumMethods(UInt32 *numMethods))
{
*numMethods = NUM_EXPORT_CODECS
- #ifdef EXTERNAL_CODECS
+ #ifdef Z7_EXTERNAL_CODECS
+ Codecs.Size()
#endif
;
return S_OK;
}
-STDMETHODIMP CCodecs::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
+Z7_COM7F_IMF(CCodecs::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value))
{
#ifdef EXPORT_CODECS
if (index < g_NumCodecs)
return GetMethodProperty(index, propID, value);
#endif
- #ifdef EXTERNAL_CODECS
+ #ifdef Z7_EXTERNAL_CODECS
const CDllCodecInfo &ci = Codecs[index - NUM_EXPORT_CODECS];
if (propID == NMethodPropID::kDecoderIsAssigned ||
@@ -845,6 +996,15 @@ STDMETHODIMP CCodecs::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *valu
prop.Detach(value);
return S_OK;
}
+
+ if (propID == NMethodPropID::kIsFilter && ci.IsFilter_Assigned)
+ {
+ NCOM::CPropVariant prop;
+ prop = (bool)ci.IsFilter;
+ prop.Detach(value);
+ return S_OK;
+ }
+
const CCodecLib &lib = Libs[ci.LibIndex];
return lib.GetMethodProperty(ci.CodecIndex, propID, value);
#else
@@ -852,21 +1012,22 @@ STDMETHODIMP CCodecs::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *valu
#endif
}
-STDMETHODIMP CCodecs::CreateDecoder(UInt32 index, const GUID *iid, void **coder)
+Z7_COM7F_IMF(CCodecs::CreateDecoder(UInt32 index, const GUID *iid, void **coder))
{
#ifdef EXPORT_CODECS
if (index < g_NumCodecs)
return CreateDecoder(index, iid, coder);
#endif
- #ifdef EXTERNAL_CODECS
+ #ifdef Z7_EXTERNAL_CODECS
const CDllCodecInfo &ci = Codecs[index - NUM_EXPORT_CODECS];
if (ci.DecoderIsAssigned)
{
const CCodecLib &lib = Libs[ci.LibIndex];
if (lib.CreateDecoder)
return lib.CreateDecoder(ci.CodecIndex, iid, (void **)coder);
- return lib.CreateObject(&ci.Decoder, iid, (void **)coder);
+ if (lib.CreateObject)
+ return lib.CreateObject(&ci.Decoder, iid, (void **)coder);
}
return S_OK;
#else
@@ -874,21 +1035,22 @@ STDMETHODIMP CCodecs::CreateDecoder(UInt32 index, const GUID *iid, void **coder)
#endif
}
-STDMETHODIMP CCodecs::CreateEncoder(UInt32 index, const GUID *iid, void **coder)
+Z7_COM7F_IMF(CCodecs::CreateEncoder(UInt32 index, const GUID *iid, void **coder))
{
#ifdef EXPORT_CODECS
if (index < g_NumCodecs)
return CreateEncoder(index, iid, coder);
#endif
- #ifdef EXTERNAL_CODECS
+ #ifdef Z7_EXTERNAL_CODECS
const CDllCodecInfo &ci = Codecs[index - NUM_EXPORT_CODECS];
if (ci.EncoderIsAssigned)
{
const CCodecLib &lib = Libs[ci.LibIndex];
if (lib.CreateEncoder)
return lib.CreateEncoder(ci.CodecIndex, iid, (void **)coder);
- return lib.CreateObject(&ci.Encoder, iid, (void **)coder);
+ if (lib.CreateObject)
+ return lib.CreateObject(&ci.Encoder, iid, (void **)coder);
}
return S_OK;
#else
@@ -897,23 +1059,23 @@ STDMETHODIMP CCodecs::CreateEncoder(UInt32 index, const GUID *iid, void **coder)
}
-STDMETHODIMP_(UInt32) CCodecs::GetNumHashers()
+Z7_COM7F_IMF2(UInt32, CCodecs::GetNumHashers())
{
return NUM_EXPORT_HASHERS
- #ifdef EXTERNAL_CODECS
+ #ifdef Z7_EXTERNAL_CODECS
+ Hashers.Size()
#endif
;
}
-STDMETHODIMP CCodecs::GetHasherProp(UInt32 index, PROPID propID, PROPVARIANT *value)
+Z7_COM7F_IMF(CCodecs::GetHasherProp(UInt32 index, PROPID propID, PROPVARIANT *value))
{
#ifdef EXPORT_CODECS
if (index < g_NumHashers)
return ::GetHasherProp(index, propID, value);
#endif
- #ifdef EXTERNAL_CODECS
+ #ifdef Z7_EXTERNAL_CODECS
const CDllHasherInfo &ci = Hashers[index - NUM_EXPORT_HASHERS];
return Libs[ci.LibIndex].ComHashers->GetHasherProp(ci.HasherIndex, propID, value);
#else
@@ -921,13 +1083,13 @@ STDMETHODIMP CCodecs::GetHasherProp(UInt32 index, PROPID propID, PROPVARIANT *va
#endif
}
-STDMETHODIMP CCodecs::CreateHasher(UInt32 index, IHasher **hasher)
+Z7_COM7F_IMF(CCodecs::CreateHasher(UInt32 index, IHasher **hasher))
{
#ifdef EXPORT_CODECS
if (index < g_NumHashers)
return CreateHasher(index, hasher);
#endif
- #ifdef EXTERNAL_CODECS
+ #ifdef Z7_EXTERNAL_CODECS
const CDllHasherInfo &ci = Hashers[index - NUM_EXPORT_HASHERS];
return Libs[ci.LibIndex].ComHashers->CreateHasher(ci.HasherIndex, hasher);
#else
@@ -942,9 +1104,9 @@ int CCodecs::GetCodec_LibIndex(UInt32 index) const
return -1;
#endif
- #ifdef EXTERNAL_CODECS
+ #ifdef Z7_EXTERNAL_CODECS
const CDllCodecInfo &ci = Codecs[index - NUM_EXPORT_CODECS];
- return ci.LibIndex;
+ return (int)ci.LibIndex;
#else
return -1;
#endif
@@ -957,9 +1119,9 @@ int CCodecs::GetHasherLibIndex(UInt32 index)
return -1;
#endif
- #ifdef EXTERNAL_CODECS
+ #ifdef Z7_EXTERNAL_CODECS
const CDllHasherInfo &ci = Hashers[index - NUM_EXPORT_HASHERS];
- return ci.LibIndex;
+ return (int)ci.LibIndex;
#else
return -1;
#endif
@@ -980,13 +1142,14 @@ bool CCodecs::GetCodec_DecoderIsAssigned(UInt32 index) const
}
#endif
- #ifdef EXTERNAL_CODECS
+ #ifdef Z7_EXTERNAL_CODECS
return Codecs[index - NUM_EXPORT_CODECS].DecoderIsAssigned;
#else
return false;
#endif
}
+
bool CCodecs::GetCodec_EncoderIsAssigned(UInt32 index) const
{
#ifdef EXPORT_CODECS
@@ -1002,17 +1165,50 @@ bool CCodecs::GetCodec_EncoderIsAssigned(UInt32 index) const
}
#endif
- #ifdef EXTERNAL_CODECS
+ #ifdef Z7_EXTERNAL_CODECS
return Codecs[index - NUM_EXPORT_CODECS].EncoderIsAssigned;
#else
return false;
#endif
}
+
+bool CCodecs::GetCodec_IsFilter(UInt32 index, bool &isAssigned) const
+{
+ isAssigned = false;
+ #ifdef EXPORT_CODECS
+ if (index < g_NumCodecs)
+ {
+ NCOM::CPropVariant prop;
+ if (GetProperty(index, NMethodPropID::kIsFilter, &prop) == S_OK)
+ {
+ if (prop.vt == VT_BOOL)
+ {
+ isAssigned = true;
+ return VARIANT_BOOLToBool(prop.boolVal);
+ }
+ }
+ return false;
+ }
+ #endif
+
+ #ifdef Z7_EXTERNAL_CODECS
+ {
+ const CDllCodecInfo &c = Codecs[index - NUM_EXPORT_CODECS];
+ isAssigned = c.IsFilter_Assigned;
+ return c.IsFilter;
+ }
+ #else
+ return false;
+ #endif
+}
+
+
UInt32 CCodecs::GetCodec_NumStreams(UInt32 index)
{
NCOM::CPropVariant prop;
- RINOK(GetProperty(index, NMethodPropID::kPackStreams, &prop));
+ if (GetProperty(index, NMethodPropID::kPackStreams, &prop) != S_OK)
+ return 0;
if (prop.vt == VT_UI4)
return (UInt32)prop.ulVal;
if (prop.vt == VT_EMPTY)
@@ -1023,7 +1219,7 @@ UInt32 CCodecs::GetCodec_NumStreams(UInt32 index)
HRESULT CCodecs::GetCodec_Id(UInt32 index, UInt64 &id)
{
NCOM::CPropVariant prop;
- RINOK(GetProperty(index, NMethodPropID::kID, &prop));
+ RINOK(GetProperty(index, NMethodPropID::kID, &prop))
if (prop.vt != VT_UI8)
return E_INVALIDARG;
id = prop.uhVal.QuadPart;
@@ -1063,10 +1259,75 @@ AString CCodecs::GetHasherName(UInt32 index)
UInt32 CCodecs::GetHasherDigestSize(UInt32 index)
{
NCOM::CPropVariant prop;
- RINOK(GetHasherProp(index, NMethodPropID::kDigestSize, &prop));
+ if (GetHasherProp(index, NMethodPropID::kDigestSize, &prop) != S_OK)
+ return 0;
if (prop.vt != VT_UI4)
return 0;
return prop.ulVal;
}
-#endif // EXTERNAL_CODECS
+void CCodecs::GetCodecsErrorMessage(UString &s)
+{
+ s.Empty();
+ FOR_VECTOR (i, Errors)
+ {
+ const CCodecError &ce = Errors[i];
+ s += "Codec Load Error: ";
+ s += fs2us(ce.Path);
+ if (ce.ErrorCode != 0)
+ {
+ s += " : ";
+ s += NWindows::NError::MyFormatMessage(ce.ErrorCode);
+ }
+ if (!ce.Message.IsEmpty())
+ {
+ s += " : ";
+ s += ce.Message;
+ }
+ s.Add_LF();
+ }
+}
+
+#endif // Z7_EXTERNAL_CODECS
+
+#ifndef Z7_SFX
+
+extern unsigned g_NumCodecs;
+extern const CCodecInfo *g_Codecs[];
+
+void CCodecs::Get_CodecsInfoUser_Vector(CObjectVector<CCodecInfoUser> &v)
+{
+ v.Clear();
+ {
+ for (unsigned i = 0; i < g_NumCodecs; i++)
+ {
+ const CCodecInfo &cod = *g_Codecs[i];
+ CCodecInfoUser &u = v.AddNew();
+ u.EncoderIsAssigned = (cod.CreateEncoder != NULL);
+ u.DecoderIsAssigned = (cod.CreateDecoder != NULL);
+ u.IsFilter_Assigned = true;
+ u.IsFilter = cod.IsFilter;
+ u.NumStreams = cod.NumStreams;
+ u.Name = cod.Name;
+ }
+ }
+
+
+ #ifdef Z7_EXTERNAL_CODECS
+ {
+ UInt32 numMethods;
+ if (GetNumMethods(&numMethods) == S_OK)
+ for (UInt32 j = 0; j < numMethods; j++)
+ {
+ CCodecInfoUser &u = v.AddNew();
+ u.EncoderIsAssigned = GetCodec_EncoderIsAssigned(j);
+ u.DecoderIsAssigned = GetCodec_DecoderIsAssigned(j);
+ u.IsFilter = GetCodec_IsFilter(j, u.IsFilter_Assigned);
+ u.NumStreams = GetCodec_NumStreams(j);
+ u.Name = GetCodec_Name(j);
+ }
+ }
+ #endif
+}
+
+#endif
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/LoadCodecs.h b/3rdparty/lzma/CPP/7zip/UI/Common/LoadCodecs.h
index ac9eeac71dd..a81bb5c74a9 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/LoadCodecs.h
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/LoadCodecs.h
@@ -1,7 +1,7 @@
// LoadCodecs.h
-#ifndef __LOAD_CODECS_H
-#define __LOAD_CODECS_H
+#ifndef ZIP7_INC_LOAD_CODECS_H
+#define ZIP7_INC_LOAD_CODECS_H
/*
Client application uses LoadCodecs.* to load plugins to
@@ -10,26 +10,26 @@ CCodecs object, that contains 3 lists of plugins:
2) Codecs - external codecs
3) Hashers - external hashers
-EXTERNAL_CODECS
+Z7_EXTERNAL_CODECS
---------------
- if EXTERNAL_CODECS is defined, then the code tries to load external
+ if Z7_EXTERNAL_CODECS is defined, then the code tries to load external
plugins from DLL files (shared libraries).
There are two types of executables in 7-Zip:
1) Executable that uses external plugins must be compiled
- with EXTERNAL_CODECS defined:
+ with Z7_EXTERNAL_CODECS defined:
- 7z.exe, 7zG.exe, 7zFM.exe
- Note: EXTERNAL_CODECS is used also in CPP/7zip/Common/CreateCoder.h
+ Note: Z7_EXTERNAL_CODECS is used also in CPP/7zip/Common/CreateCoder.h
that code is used in plugin module (7z.dll).
- 2) Standalone modules are compiled without EXTERNAL_CODECS:
+ 2) Standalone modules are compiled without Z7_EXTERNAL_CODECS:
- SFX modules: 7z.sfx, 7zCon.sfx
- standalone versions of console 7-Zip: 7za.exe, 7zr.exe
- if EXTERNAL_CODECS is defined, CCodecs class implements interfaces:
+ if Z7_EXTERNAL_CODECS is defined, CCodecs class implements interfaces:
- ICompressCodecsInfo : for Codecs
- IHashers : for Hashers
@@ -51,7 +51,7 @@ EXTERNAL_CODECS
#include "../../../Common/MyString.h"
#include "../../../Common/ComTry.h"
-#ifdef EXTERNAL_CODECS
+#ifdef Z7_EXTERNAL_CODECS
#include "../../../Windows/DLL.h"
#endif
@@ -60,7 +60,7 @@ EXTERNAL_CODECS
#include "../../Archive/IArchive.h"
-#ifdef EXTERNAL_CODECS
+#ifdef Z7_EXTERNAL_CODECS
struct CDllCodecInfo
{
@@ -68,6 +68,8 @@ struct CDllCodecInfo
UInt32 CodecIndex;
bool EncoderIsAssigned;
bool DecoderIsAssigned;
+ bool IsFilter;
+ bool IsFilter_Assigned;
CLSID Encoder;
CLSID Decoder;
};
@@ -94,6 +96,7 @@ struct CArcExtInfo
struct CArcInfoEx
{
UInt32 Flags;
+ UInt32 TimeFlags;
Func_CreateInArchive CreateInArchive;
Func_IsArc IsArcFunc;
@@ -101,29 +104,48 @@ struct CArcInfoEx
UString Name;
CObjectVector<CArcExtInfo> Exts;
- #ifndef _SFX
+ #ifndef Z7_SFX
Func_CreateOutArchive CreateOutArchive;
bool UpdateEnabled;
bool NewInterface;
// UInt32 Version;
UInt32 SignatureOffset;
CObjectVector<CByteBuffer> Signatures;
+ /*
#ifdef NEW_FOLDER_INTERFACE
UStringVector AssociateExts;
#endif
+ */
#endif
- #ifdef EXTERNAL_CODECS
+ #ifdef Z7_EXTERNAL_CODECS
int LibIndex;
UInt32 FormatIndex;
CLSID ClassID;
#endif
+ int Compare(const CArcInfoEx &a) const
+ {
+ const int res = Name.Compare(a.Name);
+ if (res != 0)
+ return res;
+ #ifdef Z7_EXTERNAL_CODECS
+ return MyCompare(LibIndex, a.LibIndex);
+ #else
+ return 0;
+ #endif
+ /*
+ if (LibIndex < a.LibIndex) return -1;
+ if (LibIndex > a.LibIndex) return 1;
+ return 0;
+ */
+ }
+
bool Flags_KeepName() const { return (Flags & NArcInfoFlags::kKeepName) != 0; }
bool Flags_FindSignature() const { return (Flags & NArcInfoFlags::kFindSignature) != 0; }
bool Flags_AltStreams() const { return (Flags & NArcInfoFlags::kAltStreams) != 0; }
- bool Flags_NtSecure() const { return (Flags & NArcInfoFlags::kNtSecure) != 0; }
+ bool Flags_NtSecurity() const { return (Flags & NArcInfoFlags::kNtSecure) != 0; }
bool Flags_SymLinks() const { return (Flags & NArcInfoFlags::kSymLinks) != 0; }
bool Flags_HardLinks() const { return (Flags & NArcInfoFlags::kHardLinks) != 0; }
@@ -132,7 +154,30 @@ struct CArcInfoEx
bool Flags_BackwardOpen() const { return (Flags & NArcInfoFlags::kBackwardOpen) != 0; }
bool Flags_PreArc() const { return (Flags & NArcInfoFlags::kPreArc) != 0; }
bool Flags_PureStartOpen() const { return (Flags & NArcInfoFlags::kPureStartOpen) != 0; }
-
+ bool Flags_ByExtOnlyOpen() const { return (Flags & NArcInfoFlags::kByExtOnlyOpen) != 0; }
+ bool Flags_HashHandler() const { return (Flags & NArcInfoFlags::kHashHandler) != 0; }
+
+ bool Flags_CTime() const { return (Flags & NArcInfoFlags::kCTime) != 0; }
+ bool Flags_ATime() const { return (Flags & NArcInfoFlags::kATime) != 0; }
+ bool Flags_MTime() const { return (Flags & NArcInfoFlags::kMTime) != 0; }
+
+ bool Flags_CTime_Default() const { return (Flags & NArcInfoFlags::kCTime_Default) != 0; }
+ bool Flags_ATime_Default() const { return (Flags & NArcInfoFlags::kATime_Default) != 0; }
+ bool Flags_MTime_Default() const { return (Flags & NArcInfoFlags::kMTime_Default) != 0; }
+
+ UInt32 Get_TimePrecFlags() const
+ {
+ return (TimeFlags >> NArcInfoTimeFlags::kTime_Prec_Mask_bit_index) &
+ (((UInt32)1 << NArcInfoTimeFlags::kTime_Prec_Mask_num_bits) - 1);
+ }
+
+ UInt32 Get_DefaultTimePrec() const
+ {
+ return (TimeFlags >> NArcInfoTimeFlags::kTime_Prec_Default_bit_index) &
+ (((UInt32)1 << NArcInfoTimeFlags::kTime_Prec_Default_num_bits) - 1);
+ }
+
+
UString GetMainExt() const
{
if (Exts.IsEmpty())
@@ -141,6 +186,16 @@ struct CArcInfoEx
}
int FindExtension(const UString &ext) const;
+ bool Is_7z() const { return Name.IsEqualTo_Ascii_NoCase("7z"); }
+ bool Is_Split() const { return Name.IsEqualTo_Ascii_NoCase("Split"); }
+ bool Is_Xz() const { return Name.IsEqualTo_Ascii_NoCase("xz"); }
+ bool Is_BZip2() const { return Name.IsEqualTo_Ascii_NoCase("bzip2"); }
+ bool Is_GZip() const { return Name.IsEqualTo_Ascii_NoCase("gzip"); }
+ bool Is_Tar() const { return Name.IsEqualTo_Ascii_NoCase("tar"); }
+ bool Is_Zip() const { return Name.IsEqualTo_Ascii_NoCase("zip"); }
+ bool Is_Rar() const { return Name.IsEqualTo_Ascii_NoCase("rar"); }
+ bool Is_Zstd() const { return Name.IsEqualTo_Ascii_NoCase("zstd"); }
+
/*
UString GetAllExtensions() const
{
@@ -148,7 +203,7 @@ struct CArcInfoEx
for (int i = 0; i < Exts.Size(); i++)
{
if (i > 0)
- s += ' ';
+ s.Add_Space();
s += Exts[i].Ext;
}
return s;
@@ -157,49 +212,29 @@ struct CArcInfoEx
void AddExts(const UString &ext, const UString &addExt);
- bool IsSplit() const { return StringsAreEqualNoCase_Ascii(Name, "Split"); }
- // bool IsRar() const { return StringsAreEqualNoCase_Ascii(Name, "Rar"); }
CArcInfoEx():
Flags(0),
+ TimeFlags(0),
CreateInArchive(NULL),
IsArcFunc(NULL)
- #ifndef _SFX
+ #ifndef Z7_SFX
, CreateOutArchive(NULL)
, UpdateEnabled(false)
, NewInterface(false)
// , Version(0)
, SignatureOffset(0)
#endif
- #ifdef EXTERNAL_CODECS
+ #ifdef Z7_EXTERNAL_CODECS
, LibIndex(-1)
#endif
{}
};
-#ifdef NEW_FOLDER_INTERFACE
-
-struct CCodecIcons
-{
- struct CIconPair
- {
- UString Ext;
- int IconIndex;
- };
- CObjectVector<CIconPair> IconPairs;
-
- void LoadIcons(HMODULE m);
- bool FindIconIndex(const UString &ext, int &iconIndex) const;
-};
-#endif
-
-#ifdef EXTERNAL_CODECS
+#ifdef Z7_EXTERNAL_CODECS
struct CCodecLib
- #ifdef NEW_FOLDER_INTERFACE
- : public CCodecIcons
- #endif
{
NWindows::NDLL::CLibrary Lib;
FString Path;
@@ -211,25 +246,53 @@ struct CCodecLib
Func_SetCodecs SetCodecs;
CMyComPtr<IHashers> ComHashers;
+
+ UInt32 Version;
+ /*
#ifdef NEW_FOLDER_INTERFACE
- void LoadIcons() { CCodecIcons::LoadIcons((HMODULE)Lib); }
+ CCodecIcons CodecIcons;
+ void LoadIcons() { CodecIcons.LoadIcons((HMODULE)Lib); }
#endif
+ */
CCodecLib():
CreateObject(NULL),
GetMethodProperty(NULL),
CreateDecoder(NULL),
CreateEncoder(NULL),
- SetCodecs(NULL)
+ SetCodecs(NULL),
+ Version(0)
{}
};
#endif
+struct CCodecError
+{
+ FString Path;
+ HRESULT ErrorCode;
+ AString Message;
+ CCodecError(): ErrorCode(0) {}
+};
+
+
+struct CCodecInfoUser
+{
+ // unsigned LibIndex;
+ // UInt32 CodecIndex;
+ // UInt64 id;
+ bool EncoderIsAssigned;
+ bool DecoderIsAssigned;
+ bool IsFilter;
+ bool IsFilter_Assigned;
+ UInt32 NumStreams;
+ AString Name;
+};
-class CCodecs:
- #ifdef EXTERNAL_CODECS
+
+class CCodecs Z7_final:
+ #ifdef Z7_EXTERNAL_CODECS
public ICompressCodecsInfo,
public IHashers,
#else
@@ -237,18 +300,26 @@ class CCodecs:
#endif
public CMyUnknownImp
{
- CLASS_NO_COPY(CCodecs);
+#ifdef Z7_EXTERNAL_CODECS
+ Z7_IFACES_IMP_UNK_2(ICompressCodecsInfo, IHashers)
+#else
+ Z7_COM_UNKNOWN_IMP_0
+#endif // Z7_EXTERNAL_CODECS
+
+ Z7_CLASS_NO_COPY(CCodecs)
public:
- #ifdef EXTERNAL_CODECS
+ #ifdef Z7_EXTERNAL_CODECS
CObjectVector<CCodecLib> Libs;
FString MainDll_ErrorPath;
-
+ CObjectVector<CCodecError> Errors;
+
+ void AddLastError(const FString &path);
void CloseLibs();
class CReleaser
{
- CLASS_NO_COPY(CReleaser);
+ Z7_CLASS_NO_COPY(CReleaser)
/* CCodecsReleaser object releases CCodecs links.
1) CCodecs is COM object that is deleted when all links to that object will be released/
@@ -272,30 +343,32 @@ public:
HRESULT CreateArchiveHandler(const CArcInfoEx &ai, bool outHandler, void **archive) const
{
- return Libs[ai.LibIndex].CreateObject(&ai.ClassID, outHandler ? &IID_IOutArchive : &IID_IInArchive, (void **)archive);
+ return Libs[(unsigned)ai.LibIndex].CreateObject(&ai.ClassID, outHandler ? &IID_IOutArchive : &IID_IInArchive, (void **)archive);
}
#endif
+ /*
#ifdef NEW_FOLDER_INTERFACE
CCodecIcons InternalIcons;
#endif
+ */
CObjectVector<CArcInfoEx> Formats;
- #ifdef EXTERNAL_CODECS
+ #ifdef Z7_EXTERNAL_CODECS
CRecordVector<CDllCodecInfo> Codecs;
CRecordVector<CDllHasherInfo> Hashers;
#endif
- bool CaseSensitiveChange;
+ bool CaseSensitive_Change;
bool CaseSensitive;
CCodecs():
- #ifdef EXTERNAL_CODECS
+ #ifdef Z7_EXTERNAL_CODECS
NeedSetLibCodecs(true),
#endif
- CaseSensitiveChange(false),
+ CaseSensitive_Change(false),
CaseSensitive(false)
{}
@@ -306,43 +379,24 @@ public:
const wchar_t *GetFormatNamePtr(int formatIndex) const
{
- return formatIndex < 0 ? L"#" : (const wchar_t *)Formats[formatIndex].Name;
+ return formatIndex < 0 ? L"#" : (const wchar_t *)Formats[(unsigned)formatIndex].Name;
}
HRESULT Load();
-
- #ifndef _SFX
+
+ #ifndef Z7_SFX
int FindFormatForArchiveName(const UString &arcPath) const;
int FindFormatForExtension(const UString &ext) const;
int FindFormatForArchiveType(const UString &arcType) const;
bool FindFormatForArchiveType(const UString &arcType, CIntVector &formatIndices) const;
#endif
- #ifdef EXTERNAL_CODECS
-
- MY_UNKNOWN_IMP2(ICompressCodecsInfo, IHashers)
-
- STDMETHOD(GetNumMethods)(UInt32 *numMethods);
- STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value);
- STDMETHOD(CreateDecoder)(UInt32 index, const GUID *iid, void **coder);
- STDMETHOD(CreateEncoder)(UInt32 index, const GUID *iid, void **coder);
-
- STDMETHOD_(UInt32, GetNumHashers)();
- STDMETHOD(GetHasherProp)(UInt32 index, PROPID propID, PROPVARIANT *value);
- STDMETHOD(CreateHasher)(UInt32 index, IHasher **hasher);
-
- #else
-
- MY_UNKNOWN_IMP
-
- #endif // EXTERNAL_CODECS
-
-
- #ifdef EXTERNAL_CODECS
+ #ifdef Z7_EXTERNAL_CODECS
int GetCodec_LibIndex(UInt32 index) const;
bool GetCodec_DecoderIsAssigned(UInt32 index) const;
bool GetCodec_EncoderIsAssigned(UInt32 index) const;
+ bool GetCodec_IsFilter(UInt32 index, bool &isAssigned) const;
UInt32 GetCodec_NumStreams(UInt32 index);
HRESULT GetCodec_Id(UInt32 index, UInt64 &id);
AString GetCodec_Name(UInt32 index);
@@ -352,12 +406,14 @@ public:
AString GetHasherName(UInt32 index);
UInt32 GetHasherDigestSize(UInt32 index);
+ void GetCodecsErrorMessage(UString &s);
+
#endif
HRESULT CreateInArchive(unsigned formatIndex, CMyComPtr<IInArchive> &archive) const
{
const CArcInfoEx &ai = Formats[formatIndex];
- #ifdef EXTERNAL_CODECS
+ #ifdef Z7_EXTERNAL_CODECS
if (ai.LibIndex < 0)
#endif
{
@@ -366,17 +422,17 @@ public:
return S_OK;
COM_TRY_END
}
- #ifdef EXTERNAL_CODECS
+ #ifdef Z7_EXTERNAL_CODECS
return CreateArchiveHandler(ai, false, (void **)&archive);
#endif
}
- #ifndef _SFX
+ #ifndef Z7_SFX
HRESULT CreateOutArchive(unsigned formatIndex, CMyComPtr<IOutArchive> &archive) const
{
const CArcInfoEx &ai = Formats[formatIndex];
- #ifdef EXTERNAL_CODECS
+ #ifdef Z7_EXTERNAL_CODECS
if (ai.LibIndex < 0)
#endif
{
@@ -386,7 +442,7 @@ public:
COM_TRY_END
}
- #ifdef EXTERNAL_CODECS
+ #ifdef Z7_EXTERNAL_CODECS
return CreateArchiveHandler(ai, true, (void **)&archive);
#endif
}
@@ -399,26 +455,28 @@ public:
if (!arc.UpdateEnabled)
continue;
if (arc.Name.IsEqualTo_NoCase(name))
- return i;
+ return (int)i;
}
return -1;
}
- #endif // _SFX
+ void Get_CodecsInfoUser_Vector(CObjectVector<CCodecInfoUser> &v);
+
+ #endif // Z7_SFX
};
-#ifdef EXTERNAL_CODECS
+#ifdef Z7_EXTERNAL_CODECS
#define CREATE_CODECS_OBJECT \
CCodecs *codecs = new CCodecs; \
- CExternalCodecs __externalCodecs; \
- __externalCodecs.GetCodecs = codecs; \
- __externalCodecs.GetHashers = codecs; \
+ CExternalCodecs _externalCodecs; \
+ _externalCodecs.GetCodecs = codecs; \
+ _externalCodecs.GetHashers = codecs; \
CCodecs::CReleaser codecsReleaser; \
codecsReleaser.Set(codecs);
#else
#define CREATE_CODECS_OBJECT \
CCodecs *codecs = new CCodecs; \
- CMyComPtr<IUnknown> __codecsRef = codecs;
+ CMyComPtr<IUnknown> _codecsRef = codecs;
#endif
-
+
#endif
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/OpenArchive.cpp b/3rdparty/lzma/CPP/7zip/UI/Common/OpenArchive.cpp
index bf3b982e44e..a501b86d4b1 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/OpenArchive.cpp
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/OpenArchive.cpp
@@ -14,6 +14,7 @@
#include "../../../Common/IntToString.h"
#include "../../../Common/StringConvert.h"
#include "../../../Common/StringToInt.h"
+#include "../../../Common/UTFConvert.h"
#include "../../../Common/Wildcard.h"
#include "../../../Windows/FileDir.h"
@@ -28,15 +29,17 @@
#include "DefaultName.h"
#include "OpenArchive.h"
-#ifndef _SFX
+#ifndef Z7_SFX
#include "SetProperties.h"
#endif
+#ifndef Z7_SFX
#ifdef SHOW_DEBUG_INFO
#define PRF(x) x
#else
#define PRF(x)
#endif
+#endif
// increase it, if you need to support larger SFX stubs
static const UInt64 kMaxCheckStartPosition = 1 << 23;
@@ -64,7 +67,7 @@ Open:
- open FAIL:
Try to open with all other types from offset 0 only.
If some open type is OK and physical archive size is uequal or larger
- than file size, then return that archive with warning that can not be open as [extension type].
+ than file size, then return that archive with warning that cannot be open as [extension type].
If extension was EXE, it will try to open as unknown_extension case
- file has unknown extension (like a.hhh)
It tries to open via parser code.
@@ -92,7 +95,7 @@ Open:
using namespace NWindows;
/*
-#ifdef _SFX
+#ifdef Z7_SFX
#define OPEN_PROPS_PARAM
#else
#define OPEN_PROPS_PARAM , props
@@ -108,7 +111,7 @@ CArc::~CArc()
}
*/
-#ifndef _SFX
+#ifndef Z7_SFX
namespace NArchive {
namespace NParser {
@@ -141,14 +144,14 @@ struct CParseItem
bool LenIsUnknown;
CParseItem():
- LenIsUnknown(false),
+ // OkSize(0),
FileTime_Defined(false),
UnpackSize_Defined(false),
- NumSubFiles_Defined(false),
NumSubDirs_Defined(false),
+ NumSubFiles_Defined(false),
IsSelfExe(false),
- IsNotArcType(false)
- // OkSize(0)
+ IsNotArcType(false),
+ LenIsUnknown(false)
{}
/*
@@ -169,23 +172,14 @@ struct CParseItem
}
};
-class CHandler:
- public IInArchive,
- public IInArchiveGetStream,
- public CMyUnknownImp
-{
+Z7_CLASS_IMP_CHandler_IInArchive_1(
+ IInArchiveGetStream
+)
public:
CObjectVector<CParseItem> _items;
UInt64 _maxEndOffset;
CMyComPtr<IInStream> _stream;
- MY_UNKNOWN_IMP2(
- IInArchive,
- IInArchiveGetStream)
-
- INTERFACE_IInArchive(;)
- STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);
-
UInt64 GetLastEnd() const
{
if (_items.IsEmpty())
@@ -206,23 +200,25 @@ int CHandler::FindInsertPos(const CParseItem &item) const
unsigned left = 0, right = _items.Size();
while (left != right)
{
- unsigned mid = (left + right) / 2;
- const CParseItem & midItem = _items[mid];
+ const unsigned mid = (unsigned)(((size_t)left + (size_t)right) / 2);
+ const CParseItem &midItem = _items[mid];
if (item.Offset < midItem.Offset)
right = mid;
else if (item.Offset > midItem.Offset)
left = mid + 1;
else if (item.Size < midItem.Size)
right = mid;
+ /*
else if (item.Size > midItem.Size)
left = mid + 1;
+ */
else
{
left = mid + 1;
// return -1;
}
}
- return left;
+ return (int)left;
}
void CHandler::AddUnknownItem(UInt64 next)
@@ -257,10 +253,10 @@ void CHandler::AddUnknownItem(UInt64 next)
void CHandler::AddItem(const CParseItem &item)
{
AddUnknownItem(item.Offset);
- int pos = FindInsertPos(item);
- if (pos >= 0)
+ const int pos = FindInsertPos(item);
+ if (pos != -1)
{
- _items.Insert(pos, item);
+ _items.Insert((unsigned)pos, item);
UInt64 next = item.Offset + item.Size;
if (_maxEndOffset < next)
_maxEndOffset = next;
@@ -295,7 +291,7 @@ static const Byte kProps[] =
IMP_IInArchive_Props
IMP_IInArchive_ArcProps_NO
-STDMETHODIMP CHandler::Open(IInStream *stream, const UInt64 *, IArchiveOpenCallback * /* openArchiveCallback */)
+Z7_COM7F_IMF(CHandler::Open(IInStream *stream, const UInt64 *, IArchiveOpenCallback * /* openArchiveCallback */))
{
COM_TRY_BEGIN
{
@@ -306,20 +302,20 @@ STDMETHODIMP CHandler::Open(IInStream *stream, const UInt64 *, IArchiveOpenCallb
COM_TRY_END
}
-STDMETHODIMP CHandler::Close()
+Z7_COM7F_IMF(CHandler::Close())
{
_items.Clear();
_stream.Release();
return S_OK;
}
-STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
+Z7_COM7F_IMF(CHandler::GetNumberOfItems(UInt32 *numItems))
{
*numItems = _items.Size();
return S_OK;
}
-STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
+Z7_COM7F_IMF(CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value))
{
COM_TRY_BEGIN
NCOM::CPropVariant prop;
@@ -330,17 +326,17 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
{
case kpidPath:
{
- wchar_t sz[32];
+ char sz[32];
ConvertUInt32ToString(index + 1, sz);
- UString s = sz;
+ UString s(sz);
if (!item.Name.IsEmpty())
{
- s += L'.';
+ s.Add_Dot();
s += item.Name;
}
if (!item.Extension.IsEmpty())
{
- s += L'.';
+ s.Add_Dot();
s += item.Extension;
}
prop = s; break;
@@ -360,12 +356,12 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
COM_TRY_END
}
-HRESULT CHandler::Extract(const UInt32 *indices, UInt32 numItems,
- Int32 testMode, IArchiveExtractCallback *extractCallback)
+Z7_COM7F_IMF(CHandler::Extract(const UInt32 *indices, UInt32 numItems,
+ Int32 testMode, IArchiveExtractCallback *extractCallback))
{
COM_TRY_BEGIN
- bool allFilesMode = (numItems == (UInt32)(Int32)-1);
+ const bool allFilesMode = (numItems == (UInt32)(Int32)-1);
if (allFilesMode)
numItems = _items.Size();
if (_stream && numItems == 0)
@@ -396,35 +392,35 @@ HRESULT CHandler::Extract(const UInt32 *indices, UInt32 numItems,
{
lps->InSize = totalSize;
lps->OutSize = totalSize;
- RINOK(lps->SetCur());
+ RINOK(lps->SetCur())
CMyComPtr<ISequentialOutStream> realOutStream;
- Int32 askMode = testMode ?
+ const Int32 askMode = testMode ?
NExtract::NAskMode::kTest :
NExtract::NAskMode::kExtract;
- Int32 index = allFilesMode ? i : indices[i];
+ const UInt32 index = allFilesMode ? i : indices[i];
const CParseItem &item = _items[index];
- RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
+ RINOK(extractCallback->GetStream(index, &realOutStream, askMode))
UInt64 unpackSize = item.Size;
totalSize += unpackSize;
bool skipMode = false;
if (!testMode && !realOutStream)
continue;
- RINOK(extractCallback->PrepareOperation(askMode));
+ RINOK(extractCallback->PrepareOperation(askMode))
outStreamSpec->SetStream(realOutStream);
realOutStream.Release();
outStreamSpec->Init(skipMode ? 0 : unpackSize, true);
Int32 opRes = NExtract::NOperationResult::kOK;
- RINOK(_stream->Seek(item.Offset, STREAM_SEEK_SET, NULL));
+ RINOK(InStream_SeekSet(_stream, item.Offset))
streamSpec->Init(unpackSize);
- RINOK(copyCoder->Code(inStream, outStream, NULL, NULL, progress));
+ RINOK(copyCoder->Code(inStream, outStream, NULL, NULL, progress))
if (outStreamSpec->GetRem() != 0)
opRes = NExtract::NOperationResult::kDataError;
outStreamSpec->ReleaseStream();
- RINOK(extractCallback->SetOperationResult(opRes));
+ RINOK(extractCallback->SetOperationResult(opRes))
}
return S_OK;
@@ -433,7 +429,7 @@ HRESULT CHandler::Extract(const UInt32 *indices, UInt32 numItems,
}
-STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
+Z7_COM7F_IMF(CHandler::GetStream(UInt32 index, ISequentialInStream **stream))
{
COM_TRY_BEGIN
const CParseItem &item = _items[index];
@@ -449,7 +445,7 @@ HRESULT Archive_GetItemBoolProp(IInArchive *arc, UInt32 index, PROPID propID, bo
{
NCOM::CPropVariant prop;
result = false;
- RINOK(arc->GetProperty(index, propID, &prop));
+ RINOK(arc->GetProperty(index, propID, &prop))
if (prop.vt == VT_BOOL)
result = VARIANT_BOOLToBool(prop.boolVal);
else if (prop.vt != VT_EMPTY)
@@ -477,11 +473,11 @@ HRESULT Archive_IsItem_Deleted(IInArchive *arc, UInt32 index, bool &result) thro
return Archive_GetItemBoolProp(arc, index, kpidIsDeleted, result);
}
-static HRESULT Archive_GetArcBoolProp(IInArchive *arc, PROPID propid, bool &result) throw()
+static HRESULT Archive_GetArcProp_Bool(IInArchive *arc, PROPID propid, bool &result) throw()
{
NCOM::CPropVariant prop;
result = false;
- RINOK(arc->GetArchiveProperty(propid, &prop));
+ RINOK(arc->GetArchiveProperty(propid, &prop))
if (prop.vt == VT_BOOL)
result = VARIANT_BOOLToBool(prop.boolVal);
else if (prop.vt != VT_EMPTY)
@@ -493,16 +489,17 @@ static HRESULT Archive_GetArcProp_UInt(IInArchive *arc, PROPID propid, UInt64 &r
{
defined = false;
NCOM::CPropVariant prop;
- RINOK(arc->GetArchiveProperty(propid, &prop));
+ RINOK(arc->GetArchiveProperty(propid, &prop))
switch (prop.vt)
{
- case VT_UI4: result = prop.ulVal; defined = true; break;
- case VT_I4: result = (Int64)prop.lVal; defined = true; break;
- case VT_UI8: result = (UInt64)prop.uhVal.QuadPart; defined = true; break;
- case VT_I8: result = (UInt64)prop.hVal.QuadPart; defined = true; break;
- case VT_EMPTY: break;
+ case VT_UI4: result = prop.ulVal; break;
+ case VT_I4: result = (UInt64)(Int64)prop.lVal; break;
+ case VT_UI8: result = (UInt64)prop.uhVal.QuadPart; break;
+ case VT_I8: result = (UInt64)prop.hVal.QuadPart; break;
+ case VT_EMPTY: return S_OK;
default: return E_FAIL;
}
+ defined = true;
return S_OK;
}
@@ -510,22 +507,23 @@ static HRESULT Archive_GetArcProp_Int(IInArchive *arc, PROPID propid, Int64 &res
{
defined = false;
NCOM::CPropVariant prop;
- RINOK(arc->GetArchiveProperty(propid, &prop));
+ RINOK(arc->GetArchiveProperty(propid, &prop))
switch (prop.vt)
{
- case VT_UI4: result = prop.ulVal; defined = true; break;
- case VT_I4: result = prop.lVal; defined = true; break;
- case VT_UI8: result = (Int64)prop.uhVal.QuadPart; defined = true; break;
- case VT_I8: result = (Int64)prop.hVal.QuadPart; defined = true; break;
- case VT_EMPTY: break;
+ case VT_UI4: result = prop.ulVal; break;
+ case VT_I4: result = prop.lVal; break;
+ case VT_UI8: result = (Int64)prop.uhVal.QuadPart; break;
+ case VT_I8: result = (Int64)prop.hVal.QuadPart; break;
+ case VT_EMPTY: return S_OK;
default: return E_FAIL;
}
+ defined = true;
return S_OK;
}
-#ifndef _SFX
+#ifndef Z7_SFX
-HRESULT CArc::GetItemPathToParent(UInt32 index, UInt32 parent, UStringVector &parts) const
+HRESULT CArc::GetItem_PathToParent(UInt32 index, UInt32 parent, UStringVector &parts) const
{
if (!GetRawProps)
return E_FAIL;
@@ -543,14 +541,14 @@ HRESULT CArc::GetItemPathToParent(UInt32 index, UInt32 parent, UStringVector &pa
const void *p;
UInt32 size;
UInt32 propType;
- RINOK(GetRawProps->GetRawProp(curIndex, kpidName, &p, &size, &propType));
+ RINOK(GetRawProps->GetRawProp(curIndex, kpidName, &p, &size, &propType))
if (p && propType == PROP_DATA_TYPE_wchar_t_PTR_Z_LE)
s = (const wchar_t *)p;
else
#endif
{
NCOM::CPropVariant prop;
- RINOK(Archive->GetProperty(curIndex, kpidName, &prop));
+ RINOK(Archive->GetProperty(curIndex, kpidName, &prop))
if (prop.vt == VT_BSTR && prop.bstrVal)
s.SetFromBstr(prop.bstrVal);
else if (prop.vt == VT_EMPTY)
@@ -561,8 +559,10 @@ HRESULT CArc::GetItemPathToParent(UInt32 index, UInt32 parent, UStringVector &pa
UInt32 curParent = (UInt32)(Int32)-1;
UInt32 parentType = 0;
- RINOK(GetRawProps->GetParent(curIndex, &curParent, &parentType));
+ RINOK(GetRawProps->GetParent(curIndex, &curParent, &parentType))
+ // 18.06: fixed : we don't want to split name to parts
+ /*
if (parentType != NParentType::kAltStream)
{
for (;;)
@@ -576,6 +576,7 @@ HRESULT CArc::GetItemPathToParent(UInt32 index, UInt32 parent, UStringVector &pa
s.DeleteFrom(pos);
}
}
+ */
parts.Insert(0, s);
@@ -583,7 +584,7 @@ HRESULT CArc::GetItemPathToParent(UInt32 index, UInt32 parent, UStringVector &pa
{
{
UString &s2 = parts[parts.Size() - 2];
- s2 += L':';
+ s2 += ':';
s2 += parts.Back();
}
parts.DeleteBack();
@@ -604,7 +605,9 @@ HRESULT CArc::GetItemPathToParent(UInt32 index, UInt32 parent, UStringVector &pa
#endif
-HRESULT CArc::GetItemPath(UInt32 index, UString &result) const
+
+
+HRESULT CArc::GetItem_Path(UInt32 index, UString &result) const
{
#ifdef MY_CPU_LE
if (GetRawProps)
@@ -618,19 +621,42 @@ HRESULT CArc::GetItemPath(UInt32 index, UString &result) const
propType == NPropDataType::kUtf16z)
{
unsigned len = size / 2 - 1;
+ // (len) doesn't include null terminator
+
+ /*
+ #if WCHAR_MAX > 0xffff
+ len = (unsigned)Utf16LE__Get_Num_WCHARs(p, len);
+
+ wchar_t *s = result.GetBuf(len);
+ wchar_t *sEnd = Utf16LE__To_WCHARs_Sep(p, len, s);
+ if (s + len != sEnd) return E_FAIL;
+ *sEnd = 0;
+
+ #else
+ */
+
wchar_t *s = result.GetBuf(len);
for (unsigned i = 0; i < len; i++)
{
wchar_t c = GetUi16(p);
p = (const void *)((const Byte *)p + 2);
+
#if WCHAR_PATH_SEPARATOR != L'/'
if (c == L'/')
c = WCHAR_PATH_SEPARATOR;
+ else if (c == L'\\')
+ c = WCHAR_IN_FILE_NAME_BACKSLASH_REPLACEMENT; // WSL scheme
#endif
+
*s++ = c;
}
*s = 0;
+
+ // #endif
+
result.ReleaseBuf_SetLen(len);
+
+ Convert_UnicodeEsc16_To_UnicodeEscHigh(result);
if (len != 0)
return S_OK;
}
@@ -707,7 +733,7 @@ HRESULT CArc::GetItemPath(UInt32 index, UString &result) const
{
NCOM::CPropVariant prop;
- RINOK(Archive->GetProperty(index, kpidPath, &prop));
+ RINOK(Archive->GetProperty(index, kpidPath, &prop))
if (prop.vt == VT_BSTR && prop.bstrVal)
result.SetFromBstr(prop.bstrVal);
else if (prop.vt == VT_EMPTY)
@@ -717,23 +743,25 @@ HRESULT CArc::GetItemPath(UInt32 index, UString &result) const
}
if (result.IsEmpty())
- return GetDefaultItemPath(index, result);
+ return GetItem_DefaultPath(index, result);
+
+ Convert_UnicodeEsc16_To_UnicodeEscHigh(result);
return S_OK;
}
-HRESULT CArc::GetDefaultItemPath(UInt32 index, UString &result) const
+HRESULT CArc::GetItem_DefaultPath(UInt32 index, UString &result) const
{
result.Empty();
bool isDir;
- RINOK(Archive_IsItem_Dir(Archive, index, isDir));
+ RINOK(Archive_IsItem_Dir(Archive, index, isDir))
if (!isDir)
{
result = DefaultName;
NCOM::CPropVariant prop;
- RINOK(Archive->GetProperty(index, kpidExtension, &prop));
+ RINOK(Archive->GetProperty(index, kpidExtension, &prop))
if (prop.vt == VT_BSTR)
{
- result += L'.';
+ result.Add_Dot();
result += prop.bstrVal;
}
else if (prop.vt != VT_EMPTY)
@@ -742,13 +770,13 @@ HRESULT CArc::GetDefaultItemPath(UInt32 index, UString &result) const
return S_OK;
}
-HRESULT CArc::GetItemPath2(UInt32 index, UString &result) const
+HRESULT CArc::GetItem_Path2(UInt32 index, UString &result) const
{
- RINOK(GetItemPath(index, result));
+ RINOK(GetItem_Path(index, result))
if (Ask_Deleted)
{
bool isDeleted = false;
- RINOK(Archive_IsItem_Deleted(Archive, index, isDeleted));
+ RINOK(Archive_IsItem_Deleted(Archive, index, isDeleted))
if (isDeleted)
result.Insert(0, L"[DELETED]" WSTRING_PATH_SEPARATOR);
}
@@ -769,7 +797,7 @@ int FindAltStreamColon_in_Path(const wchar_t *path)
if (c == ':')
{
if (colonPos < 0)
- colonPos = i;
+ colonPos = (int)i;
continue;
}
if (c == WCHAR_PATH_SEPARATOR)
@@ -793,12 +821,12 @@ HRESULT CArc::GetItem(UInt32 index, CReadArcItem &item) const
item.PathParts.Clear();
- RINOK(Archive_IsItem_Dir(Archive, index, item.IsDir));
+ RINOK(Archive_IsItem_Dir(Archive, index, item.IsDir))
item.MainIsDir = item.IsDir;
- RINOK(GetItemPath2(index, item.Path));
+ RINOK(GetItem_Path2(index, item.Path))
- #ifndef _SFX
+ #ifndef Z7_SFX
UInt32 mainIndex = index;
#endif
@@ -807,7 +835,7 @@ HRESULT CArc::GetItem(UInt32 index, CReadArcItem &item) const
item.MainPath = item.Path;
if (Ask_AltStream)
{
- RINOK(Archive_IsItem_AltStream(Archive, index, item.IsAltStream));
+ RINOK(Archive_IsItem_AltStream(Archive, index, item.IsAltStream))
}
bool needFindAltStream = false;
@@ -819,11 +847,11 @@ HRESULT CArc::GetItem(UInt32 index, CReadArcItem &item) const
{
UInt32 parentType = 0;
UInt32 parentIndex;
- RINOK(GetRawProps->GetParent(index, &parentIndex, &parentType));
+ RINOK(GetRawProps->GetParent(index, &parentIndex, &parentType))
if (parentType == NParentType::kAltStream)
{
NCOM::CPropVariant prop;
- RINOK(Archive->GetProperty(index, kpidName, &prop));
+ RINOK(Archive->GetProperty(index, kpidName, &prop))
if (prop.vt == VT_BSTR && prop.bstrVal)
item.AltStreamName.SetFromBstr(prop.bstrVal);
else if (prop.vt != VT_EMPTY)
@@ -848,8 +876,8 @@ HRESULT CArc::GetItem(UInt32 index, CReadArcItem &item) const
}
else
{
- RINOK(GetItemPath2(parentIndex, item.MainPath));
- RINOK(Archive_IsItem_Dir(Archive, parentIndex, item.MainIsDir));
+ RINOK(GetItem_Path2(parentIndex, item.MainPath))
+ RINOK(Archive_IsItem_Dir(Archive, parentIndex, item.MainIsDir))
}
}
}
@@ -857,13 +885,13 @@ HRESULT CArc::GetItem(UInt32 index, CReadArcItem &item) const
if (item.WriteToAltStreamIfColon || needFindAltStream)
{
- /* Good handler must support GetRawProps::GetParent for alt streams./
+ /* Good handler must support GetRawProps::GetParent for alt streams.
So the following code currently is not used */
int colon = FindAltStreamColon_in_Path(item.Path);
if (colon >= 0)
{
- item.MainPath.DeleteFrom(colon);
- item.AltStreamName = item.Path.Ptr(colon + 1);
+ item.MainPath.DeleteFrom((unsigned)colon);
+ item.AltStreamName = item.Path.Ptr((unsigned)(colon + 1));
item.MainIsDir = (colon == 0 || IsPathSepar(item.Path[(unsigned)colon - 1]));
item.IsAltStream = true;
}
@@ -871,10 +899,10 @@ HRESULT CArc::GetItem(UInt32 index, CReadArcItem &item) const
#endif
- #ifndef _SFX
+ #ifndef Z7_SFX
if (item._use_baseParentFolder_mode)
{
- RINOK(GetItemPathToParent(mainIndex, item._baseParentFolder, item.PathParts));
+ RINOK(GetItem_PathToParent(mainIndex, (unsigned)item._baseParentFolder, item.PathParts))
#ifdef SUPPORT_ALT_STREAMS
if ((item.WriteToAltStreamIfColon || needFindAltStream) && !item.PathParts.IsEmpty())
@@ -885,10 +913,10 @@ HRESULT CArc::GetItem(UInt32 index, CReadArcItem &item) const
colon = FindAltStreamColon_in_Path(s);
if (colon >= 0)
{
- item.AltStreamName = s.Ptr(colon + 1);
+ item.AltStreamName = s.Ptr((unsigned)(colon + 1));
item.MainIsDir = (colon == 0 || IsPathSepar(s[(unsigned)colon - 1]));
item.IsAltStream = true;
- s.DeleteFrom(colon);
+ s.DeleteFrom((unsigned)colon);
}
}
if (colon == 0)
@@ -910,14 +938,14 @@ HRESULT CArc::GetItem(UInt32 index, CReadArcItem &item) const
return S_OK;
}
-#ifndef _SFX
+#ifndef Z7_SFX
static HRESULT Archive_GetItem_Size(IInArchive *archive, UInt32 index, UInt64 &size, bool &defined)
{
NCOM::CPropVariant prop;
defined = false;
size = 0;
- RINOK(archive->GetProperty(index, kpidSize, &prop));
+ RINOK(archive->GetProperty(index, kpidSize, &prop))
switch (prop.vt)
{
case VT_UI1: size = prop.bVal; break;
@@ -933,12 +961,12 @@ static HRESULT Archive_GetItem_Size(IInArchive *archive, UInt32 index, UInt64 &s
#endif
-HRESULT CArc::GetItemSize(UInt32 index, UInt64 &size, bool &defined) const
+HRESULT CArc::GetItem_Size(UInt32 index, UInt64 &size, bool &defined) const
{
NCOM::CPropVariant prop;
defined = false;
size = 0;
- RINOK(Archive->GetProperty(index, kpidSize, &prop));
+ RINOK(Archive->GetProperty(index, kpidSize, &prop))
switch (prop.vt)
{
case VT_UI1: size = prop.bVal; break;
@@ -952,28 +980,56 @@ HRESULT CArc::GetItemSize(UInt32 index, UInt64 &size, bool &defined) const
return S_OK;
}
-HRESULT CArc::GetItemMTime(UInt32 index, FILETIME &ft, bool &defined) const
+HRESULT CArc::GetItem_MTime(UInt32 index, CArcTime &at) const
{
+ at.Clear();
NCOM::CPropVariant prop;
- defined = false;
- ft.dwHighDateTime = ft.dwLowDateTime = 0;
- RINOK(Archive->GetProperty(index, kpidMTime, &prop));
+ RINOK(Archive->GetProperty(index, kpidMTime, &prop))
+
if (prop.vt == VT_FILETIME)
{
- ft = prop.filetime;
- defined = true;
+ /*
+ // for debug
+ if (FILETIME_IsZero(prop.at) && MTime.Def)
+ {
+ at = MTime;
+ return S_OK;
+ }
+ */
+ at.Set_From_Prop(prop);
+ if (at.Prec == 0)
+ {
+ // (at.Prec == 0) before version 22.
+ // so kpidTimeType is required for that code
+ prop.Clear();
+ RINOK(Archive->GetProperty(index, kpidTimeType, &prop))
+ if (prop.vt == VT_UI4)
+ {
+ UInt32 val = prop.ulVal;
+ if (val == NFileTimeType::kWindows)
+ val = k_PropVar_TimePrec_100ns;
+ /*
+ else if (val > k_PropVar_TimePrec_1ns)
+ {
+ val = k_PropVar_TimePrec_100ns;
+ // val = k_PropVar_TimePrec_1ns;
+ // return E_FAIL; // for debug
+ }
+ */
+ at.Prec = (UInt16)val;
+ }
+ }
+ return S_OK;
}
- else if (prop.vt != VT_EMPTY)
+
+ if (prop.vt != VT_EMPTY)
return E_FAIL;
- else if (MTimeDefined)
- {
- ft = MTime;
- defined = true;
- }
+ if (MTime.Def)
+ at = MTime;
return S_OK;
}
-#ifndef _SFX
+#ifndef Z7_SFX
static inline bool TestSignature(const Byte *p1, const Byte *p2, size_t size)
{
@@ -983,52 +1039,52 @@ static inline bool TestSignature(const Byte *p1, const Byte *p2, size_t size)
return true;
}
+
static void MakeCheckOrder(CCodecs *codecs,
CIntVector &orderIndices, unsigned numTypes, CIntVector &orderIndices2,
const Byte *data, size_t dataSize)
{
for (unsigned i = 0; i < numTypes; i++)
{
- int index = orderIndices[i];
+ const int index = orderIndices[i];
if (index < 0)
continue;
- const CArcInfoEx &ai = codecs->Formats[index];
- if (ai.SignatureOffset != 0)
- {
- orderIndices2.Add(index);
- orderIndices[i] = -1;
- continue;
- }
-
- const CObjectVector<CByteBuffer> &sigs = ai.Signatures;
- FOR_VECTOR (k, sigs)
+ const CArcInfoEx &ai = codecs->Formats[(unsigned)index];
+ if (ai.SignatureOffset == 0)
{
- const CByteBuffer &sig = sigs[k];
- if (sig.Size() == 0 && dataSize == 0 ||
- sig.Size() != 0 && sig.Size() <= dataSize &&
- TestSignature(data, sig, sig.Size()))
+ if (ai.Signatures.IsEmpty())
{
- orderIndices2.Add(index);
- orderIndices[i] = -1;
- break;
+ if (dataSize != 0) // 21.04: no Signature means Empty Signature
+ continue;
+ }
+ else
+ {
+ unsigned k;
+ const CObjectVector<CByteBuffer> &sigs = ai.Signatures;
+ for (k = 0; k < sigs.Size(); k++)
+ {
+ const CByteBuffer &sig = sigs[k];
+ if (sig.Size() <= dataSize && TestSignature(data, sig, sig.Size()))
+ break;
+ }
+ if (k == sigs.Size())
+ continue;
}
}
+ orderIndices2.Add(index);
+ orderIndices[i] = -1;
}
}
-#endif
-
#ifdef UNDER_CE
static const unsigned kNumHashBytes = 1;
- #define HASH_VAL(buf, pos) ((buf)[pos])
+ #define HASH_VAL(buf) ((buf)[0])
#else
static const unsigned kNumHashBytes = 2;
- #define HASH_VAL(buf, pos) ((buf)[pos] | ((UInt32)(buf)[pos + 1] << 8))
+ // #define HASH_VAL(buf) ((buf)[0] | ((UInt32)(buf)[1] << 8))
+ #define HASH_VAL(buf) GetUi16(buf)
#endif
-
-#ifndef _SFX
-
static bool IsExeExt(const UString &ext)
{
return ext.IsEqualTo_Ascii_NoCase("exe");
@@ -1056,7 +1112,7 @@ static bool IsPreArcFormat(const CArcInfoEx &ai)
{
if (ai.Flags_PreArc())
return true;
- return IsNameFromList(ai.Name, k_PreArcFormats, ARRAY_SIZE(k_PreArcFormats));
+ return IsNameFromList(ai.Name, k_PreArcFormats, Z7_ARRAY_SIZE(k_PreArcFormats));
}
static const char * const k_Formats_with_simple_signuature[] =
@@ -1078,44 +1134,46 @@ static bool IsNewStyleSignature(const CArcInfoEx &ai)
// if (ai.Version >= 0x91F)
if (ai.NewInterface)
return true;
- return IsNameFromList(ai.Name, k_Formats_with_simple_signuature, ARRAY_SIZE(k_Formats_with_simple_signuature));
+ return IsNameFromList(ai.Name, k_Formats_with_simple_signuature, Z7_ARRAY_SIZE(k_Formats_with_simple_signuature));
}
-class CArchiveOpenCallback_Offset:
+
+
+class CArchiveOpenCallback_Offset Z7_final:
public IArchiveOpenCallback,
public IArchiveOpenVolumeCallback,
- #ifndef _NO_CRYPTO
+ #ifndef Z7_NO_CRYPTO
public ICryptoGetTextPassword,
- #endif
+ #endif
public CMyUnknownImp
{
+ Z7_COM_QI_BEGIN2(IArchiveOpenCallback)
+ Z7_COM_QI_ENTRY(IArchiveOpenVolumeCallback)
+ #ifndef Z7_NO_CRYPTO
+ Z7_COM_QI_ENTRY(ICryptoGetTextPassword)
+ #endif
+ Z7_COM_QI_END
+ Z7_COM_ADDREF_RELEASE
+
+ Z7_IFACE_COM7_IMP(IArchiveOpenCallback)
+ Z7_IFACE_COM7_IMP(IArchiveOpenVolumeCallback)
+ #ifndef Z7_NO_CRYPTO
+ Z7_IFACE_COM7_IMP(ICryptoGetTextPassword)
+ #endif
+
public:
CMyComPtr<IArchiveOpenCallback> Callback;
CMyComPtr<IArchiveOpenVolumeCallback> OpenVolumeCallback;
UInt64 Files;
UInt64 Offset;
- #ifndef _NO_CRYPTO
+ #ifndef Z7_NO_CRYPTO
CMyComPtr<ICryptoGetTextPassword> GetTextPassword;
#endif
-
- MY_QUERYINTERFACE_BEGIN2(IArchiveOpenCallback)
- MY_QUERYINTERFACE_ENTRY(IArchiveOpenVolumeCallback)
- #ifndef _NO_CRYPTO
- MY_QUERYINTERFACE_ENTRY(ICryptoGetTextPassword)
- #endif
- MY_QUERYINTERFACE_END
- MY_ADDREF_RELEASE
-
- INTERFACE_IArchiveOpenCallback(;)
- INTERFACE_IArchiveOpenVolumeCallback(;)
- #ifndef _NO_CRYPTO
- STDMETHOD(CryptoGetTextPassword)(BSTR *password);
- #endif
};
-#ifndef _NO_CRYPTO
-STDMETHODIMP CArchiveOpenCallback_Offset::CryptoGetTextPassword(BSTR *password)
+#ifndef Z7_NO_CRYPTO
+Z7_COM7F_IMF(CArchiveOpenCallback_Offset::CryptoGetTextPassword(BSTR *password))
{
COM_TRY_BEGIN
if (GetTextPassword)
@@ -1125,12 +1183,12 @@ STDMETHODIMP CArchiveOpenCallback_Offset::CryptoGetTextPassword(BSTR *password)
}
#endif
-STDMETHODIMP CArchiveOpenCallback_Offset::SetTotal(const UInt64 *, const UInt64 *)
+Z7_COM7F_IMF(CArchiveOpenCallback_Offset::SetTotal(const UInt64 *, const UInt64 *))
{
return S_OK;
}
-STDMETHODIMP CArchiveOpenCallback_Offset::SetCompleted(const UInt64 *, const UInt64 *bytes)
+Z7_COM7F_IMF(CArchiveOpenCallback_Offset::SetCompleted(const UInt64 *, const UInt64 *bytes))
{
if (!Callback)
return S_OK;
@@ -1140,7 +1198,7 @@ STDMETHODIMP CArchiveOpenCallback_Offset::SetCompleted(const UInt64 *, const UIn
return Callback->SetCompleted(&Files, &value);
}
-STDMETHODIMP CArchiveOpenCallback_Offset::GetProperty(PROPID propID, PROPVARIANT *value)
+Z7_COM7F_IMF(CArchiveOpenCallback_Offset::GetProperty(PROPID propID, PROPVARIANT *value))
{
if (OpenVolumeCallback)
return OpenVolumeCallback->GetProperty(propID, value);
@@ -1149,7 +1207,7 @@ STDMETHODIMP CArchiveOpenCallback_Offset::GetProperty(PROPID propID, PROPVARIANT
// return E_NOTIMPL;
}
-STDMETHODIMP CArchiveOpenCallback_Offset::GetStream(const wchar_t *name, IInStream **inStream)
+Z7_COM7F_IMF(CArchiveOpenCallback_Offset::GetStream(const wchar_t *name, IInStream **inStream))
{
if (OpenVolumeCallback)
return OpenVolumeCallback->GetStream(name, inStream);
@@ -1193,7 +1251,7 @@ void CArcErrorInfo::ClearErrors()
HRESULT CArc::ReadBasicProps(IInArchive *archive, UInt64 startPos, HRESULT openRes)
{
// OkPhySize_Defined = false;
- PhySizeDefined = false;
+ PhySize_Defined = false;
PhySize = 0;
Offset = 0;
AvailPhySize = FileSize - startPos;
@@ -1201,49 +1259,49 @@ HRESULT CArc::ReadBasicProps(IInArchive *archive, UInt64 startPos, HRESULT openR
ErrorInfo.ClearErrors();
{
NCOM::CPropVariant prop;
- RINOK(archive->GetArchiveProperty(kpidErrorFlags, &prop));
+ RINOK(archive->GetArchiveProperty(kpidErrorFlags, &prop))
ErrorInfo.ErrorFlags = GetOpenArcErrorFlags(prop, &ErrorInfo.ErrorFlags_Defined);
}
{
NCOM::CPropVariant prop;
- RINOK(archive->GetArchiveProperty(kpidWarningFlags, &prop));
+ RINOK(archive->GetArchiveProperty(kpidWarningFlags, &prop))
ErrorInfo.WarningFlags = GetOpenArcErrorFlags(prop);
}
{
NCOM::CPropVariant prop;
- RINOK(archive->GetArchiveProperty(kpidError, &prop));
+ RINOK(archive->GetArchiveProperty(kpidError, &prop))
if (prop.vt != VT_EMPTY)
ErrorInfo.ErrorMessage = (prop.vt == VT_BSTR ? prop.bstrVal : L"Unknown error");
}
{
NCOM::CPropVariant prop;
- RINOK(archive->GetArchiveProperty(kpidWarning, &prop));
+ RINOK(archive->GetArchiveProperty(kpidWarning, &prop))
if (prop.vt != VT_EMPTY)
ErrorInfo.WarningMessage = (prop.vt == VT_BSTR ? prop.bstrVal : L"Unknown warning");
}
if (openRes == S_OK || ErrorInfo.IsArc_After_NonOpen())
{
- RINOK(Archive_GetArcProp_UInt(archive, kpidPhySize, PhySize, PhySizeDefined));
+ RINOK(Archive_GetArcProp_UInt(archive, kpidPhySize, PhySize, PhySize_Defined))
/*
RINOK(Archive_GetArcProp_UInt(archive, kpidOkPhySize, OkPhySize, OkPhySize_Defined));
if (!OkPhySize_Defined)
{
- OkPhySize_Defined = PhySizeDefined;
+ OkPhySize_Defined = PhySize_Defined;
OkPhySize = PhySize;
}
*/
bool offsetDefined;
- RINOK(Archive_GetArcProp_Int(archive, kpidOffset, Offset, offsetDefined));
+ RINOK(Archive_GetArcProp_Int(archive, kpidOffset, Offset, offsetDefined))
- Int64 globalOffset = startPos + Offset;
- AvailPhySize = FileSize - globalOffset;
- if (PhySizeDefined)
+ Int64 globalOffset = (Int64)startPos + Offset;
+ AvailPhySize = (UInt64)((Int64)FileSize - globalOffset);
+ if (PhySize_Defined)
{
- UInt64 endPos = globalOffset + PhySize;
+ UInt64 endPos = (UInt64)(globalOffset + (Int64)PhySize);
if (endPos < FileSize)
{
AvailPhySize = PhySize;
@@ -1259,11 +1317,12 @@ HRESULT CArc::ReadBasicProps(IInArchive *archive, UInt64 startPos, HRESULT openR
}
/*
-static PrintNumber(const char *s, int n)
+static void PrintNumber(const char *s, int n)
{
char temp[100];
sprintf(temp, "%s %d", s, n);
- OutputDebugStringA(temp);
+ // OutputDebugStringA(temp);
+ printf(temp);
}
*/
@@ -1272,31 +1331,31 @@ HRESULT CArc::PrepareToOpen(const COpenOptions &op, unsigned formatIndex, CMyCom
// OutputDebugStringA("a1");
// PrintNumber("formatIndex", formatIndex);
- RINOK(op.codecs->CreateInArchive(formatIndex, archive));
+ RINOK(op.codecs->CreateInArchive(formatIndex, archive))
// OutputDebugStringA("a2");
if (!archive)
return S_OK;
- #ifdef EXTERNAL_CODECS
+ #ifdef Z7_EXTERNAL_CODECS
if (op.codecs->NeedSetLibCodecs)
{
const CArcInfoEx &ai = op.codecs->Formats[formatIndex];
if (ai.LibIndex >= 0 ?
- !op.codecs->Libs[ai.LibIndex].SetCodecs :
+ !op.codecs->Libs[(unsigned)ai.LibIndex].SetCodecs :
!op.codecs->Libs.IsEmpty())
{
CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;
archive.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);
if (setCompressCodecsInfo)
{
- RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(op.codecs));
+ RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(op.codecs))
}
}
}
#endif
- #ifndef _SFX
+ #ifndef Z7_SFX
const CArcInfoEx &ai = op.codecs->Formats[formatIndex];
@@ -1326,14 +1385,14 @@ HRESULT CArc::PrepareToOpen(const COpenOptions &op, unsigned formatIndex, CMyCom
}
}
*/
- RINOK(SetProperties(archive, *op.props));
+ RINOK(SetProperties(archive, *op.props))
}
#endif
return S_OK;
}
-#ifndef _SFX
+#ifndef Z7_SFX
static HRESULT ReadParseItemProps(IInArchive *archive, const CArcInfoEx &ai, NArchive::NParser::CParseItem &pi)
{
@@ -1341,14 +1400,14 @@ static HRESULT ReadParseItemProps(IInArchive *archive, const CArcInfoEx &ai, NAr
pi.FileTime_Defined = false;
pi.ArcType = ai.Name;
- RINOK(Archive_GetArcBoolProp(archive, kpidIsNotArcType, pi.IsNotArcType));
+ RINOK(Archive_GetArcProp_Bool(archive, kpidIsNotArcType, pi.IsNotArcType))
- // RINOK(Archive_GetArcBoolProp(archive, kpidIsSelfExe, pi.IsSelfExe));
+ // RINOK(Archive_GetArcProp_Bool(archive, kpidIsSelfExe, pi.IsSelfExe));
pi.IsSelfExe = ai.Flags_PreArc();
{
NCOM::CPropVariant prop;
- RINOK(archive->GetArchiveProperty(kpidMTime, &prop));
+ RINOK(archive->GetArchiveProperty(kpidMTime, &prop))
if (prop.vt == VT_FILETIME)
{
pi.FileTime_Defined = true;
@@ -1359,7 +1418,7 @@ static HRESULT ReadParseItemProps(IInArchive *archive, const CArcInfoEx &ai, NAr
if (!pi.FileTime_Defined)
{
NCOM::CPropVariant prop;
- RINOK(archive->GetArchiveProperty(kpidCTime, &prop));
+ RINOK(archive->GetArchiveProperty(kpidCTime, &prop))
if (prop.vt == VT_FILETIME)
{
pi.FileTime_Defined = true;
@@ -1369,7 +1428,7 @@ static HRESULT ReadParseItemProps(IInArchive *archive, const CArcInfoEx &ai, NAr
{
NCOM::CPropVariant prop;
- RINOK(archive->GetArchiveProperty(kpidName, &prop));
+ RINOK(archive->GetArchiveProperty(kpidName, &prop))
if (prop.vt == VT_BSTR)
{
pi.Name.SetFromBstr(prop.bstrVal);
@@ -1377,7 +1436,7 @@ static HRESULT ReadParseItemProps(IInArchive *archive, const CArcInfoEx &ai, NAr
}
else
{
- RINOK(archive->GetArchiveProperty(kpidExtension, &prop));
+ RINOK(archive->GetArchiveProperty(kpidExtension, &prop))
if (prop.vt == VT_BSTR)
pi.Extension.SetFromBstr(prop.bstrVal);
}
@@ -1385,14 +1444,14 @@ static HRESULT ReadParseItemProps(IInArchive *archive, const CArcInfoEx &ai, NAr
{
NCOM::CPropVariant prop;
- RINOK(archive->GetArchiveProperty(kpidShortComment, &prop));
+ RINOK(archive->GetArchiveProperty(kpidShortComment, &prop))
if (prop.vt == VT_BSTR)
pi.Comment.SetFromBstr(prop.bstrVal);
}
UInt32 numItems;
- RINOK(archive->GetNumberOfItems(&numItems));
+ RINOK(archive->GetNumberOfItems(&numItems))
// pi.NumSubFiles = numItems;
// RINOK(Archive_GetArcProp_UInt(archive, kpidUnpackSize, pi.UnpackSize, pi.UnpackSize_Defined));
@@ -1433,14 +1492,14 @@ HRESULT CArc::CheckZerosTail(const COpenOptions &op, UInt64 offset)
{
if (!op.stream)
return S_OK;
- RINOK(op.stream->Seek(offset, STREAM_SEEK_SET, NULL));
+ RINOK(InStream_SeekSet(op.stream, offset))
const UInt32 kBufSize = 1 << 11;
Byte buf[kBufSize];
for (;;)
{
UInt32 processed = 0;
- RINOK(op.stream->Read(buf, kBufSize, &processed));
+ RINOK(op.stream->Read(buf, kBufSize, &processed))
if (processed == 0)
{
// ErrorInfo.NonZerosTail = false;
@@ -1459,21 +1518,21 @@ HRESULT CArc::CheckZerosTail(const COpenOptions &op, UInt64 offset)
}
}
-#ifndef _SFX
-class CExtractCallback_To_OpenCallback:
- public IArchiveExtractCallback,
- public ICompressProgressInfo,
- public CMyUnknownImp
-{
+
+#ifndef Z7_SFX
+
+Z7_CLASS_IMP_COM_2(
+ CExtractCallback_To_OpenCallback
+ , IArchiveExtractCallback
+ , ICompressProgressInfo
+)
+ Z7_IFACE_COM7_IMP(IProgress)
public:
CMyComPtr<IArchiveOpenCallback> Callback;
UInt64 Files;
UInt64 Offset;
- MY_UNKNOWN_IMP2(IArchiveExtractCallback, ICompressProgressInfo)
- INTERFACE_IArchiveExtractCallback(;)
- STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);
void Init(IArchiveOpenCallback *callback)
{
Callback = callback;
@@ -1482,17 +1541,17 @@ public:
}
};
-STDMETHODIMP CExtractCallback_To_OpenCallback::SetTotal(UInt64 /* size */)
+Z7_COM7F_IMF(CExtractCallback_To_OpenCallback::SetTotal(UInt64 /* size */))
{
return S_OK;
}
-STDMETHODIMP CExtractCallback_To_OpenCallback::SetCompleted(const UInt64 * /* completeValue */)
+Z7_COM7F_IMF(CExtractCallback_To_OpenCallback::SetCompleted(const UInt64 * /* completeValue */))
{
return S_OK;
}
-STDMETHODIMP CExtractCallback_To_OpenCallback::SetRatioInfo(const UInt64 *inSize, const UInt64 * /* outSize */)
+Z7_COM7F_IMF(CExtractCallback_To_OpenCallback::SetRatioInfo(const UInt64 *inSize, const UInt64 * /* outSize */))
{
if (Callback)
{
@@ -1504,22 +1563,23 @@ STDMETHODIMP CExtractCallback_To_OpenCallback::SetRatioInfo(const UInt64 *inSize
return S_OK;
}
-STDMETHODIMP CExtractCallback_To_OpenCallback::GetStream(UInt32 /* index */, ISequentialOutStream **outStream, Int32 /* askExtractMode */)
+Z7_COM7F_IMF(CExtractCallback_To_OpenCallback::GetStream(UInt32 /* index */, ISequentialOutStream **outStream, Int32 /* askExtractMode */))
{
- *outStream = 0;
+ *outStream = NULL;
return S_OK;
}
-STDMETHODIMP CExtractCallback_To_OpenCallback::PrepareOperation(Int32 /* askExtractMode */)
+Z7_COM7F_IMF(CExtractCallback_To_OpenCallback::PrepareOperation(Int32 /* askExtractMode */))
{
return S_OK;
}
-STDMETHODIMP CExtractCallback_To_OpenCallback::SetOperationResult(Int32 /* operationResult */)
+Z7_COM7F_IMF(CExtractCallback_To_OpenCallback::SetOperationResult(Int32 /* operationResult */))
{
return S_OK;
}
+
static HRESULT OpenArchiveSpec(IInArchive *archive, bool needPhySize,
IInStream *stream, const UInt64 *maxCheckStartPosition,
IArchiveOpenCallback *openCallback,
@@ -1528,37 +1588,48 @@ static HRESULT OpenArchiveSpec(IInArchive *archive, bool needPhySize,
/*
if (needPhySize)
{
- CMyComPtr<IArchiveOpen2> open2;
- archive->QueryInterface(IID_IArchiveOpen2, (void **)&open2);
+ Z7_DECL_CMyComPtr_QI_FROM(
+ IArchiveOpen2,
+ open2, archive)
if (open2)
return open2->ArcOpen2(stream, kOpenFlags_RealPhySize, openCallback);
}
*/
- RINOK(archive->Open(stream, maxCheckStartPosition, openCallback));
+ RINOK(archive->Open(stream, maxCheckStartPosition, openCallback))
if (needPhySize)
{
bool phySize_Defined = false;
UInt64 phySize = 0;
- RINOK(Archive_GetArcProp_UInt(archive, kpidPhySize, phySize, phySize_Defined));
+ RINOK(Archive_GetArcProp_UInt(archive, kpidPhySize, phySize, phySize_Defined))
if (phySize_Defined)
return S_OK;
- bool phySizeCantBeDetected = false;;
- RINOK(Archive_GetArcBoolProp(archive, kpidPhySizeCantBeDetected, phySizeCantBeDetected));
+ bool phySizeCantBeDetected = false;
+ RINOK(Archive_GetArcProp_Bool(archive, kpidPhySizeCantBeDetected, phySizeCantBeDetected))
if (!phySizeCantBeDetected)
{
- RINOK(archive->Extract(0, (UInt32)(Int32)-1, BoolToInt(true), extractCallback));
+ PRF(printf("\n-- !phySize_Defined after Open, call archive->Extract()"));
+ // It's for bzip2/gz and some xz archives, where Open operation doesn't know phySize.
+ // But the Handler will know phySize after full archive testing.
+ RINOK(archive->Extract(NULL, (UInt32)(Int32)-1, BoolToInt(true), extractCallback))
+ PRF(printf("\n-- OK"));
}
}
return S_OK;
}
+
+
static int FindFormatForArchiveType(CCodecs *codecs, CIntVector orderIndices, const char *name)
{
FOR_VECTOR (i, orderIndices)
- if (StringsAreEqualNoCase_Ascii(codecs->Formats[orderIndices[i]].Name, name))
- return i;
+ {
+ int oi = orderIndices[i];
+ if (oi >= 0)
+ if (StringsAreEqualNoCase_Ascii(codecs->Formats[(unsigned)oi].Name, name))
+ return (int)i;
+ }
return -1;
}
@@ -1584,15 +1655,15 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
const UString fileName = ExtractFileNameFromPath(Path);
UString extension;
{
- int dotPos = fileName.ReverseFind_Dot();
+ const int dotPos = fileName.ReverseFind_Dot();
if (dotPos >= 0)
- extension = fileName.Ptr(dotPos + 1);
+ extension = fileName.Ptr((unsigned)(dotPos + 1));
}
CIntVector orderIndices;
bool searchMarkerInHandler = false;
- #ifdef _SFX
+ #ifdef Z7_SFX
searchMarkerInHandler = true;
#endif
@@ -1602,22 +1673,27 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
isMainFormatArr[i] = false;
}
- UInt64 maxStartOffset =
+ const UInt64 maxStartOffset =
op.openType.MaxStartOffset_Defined ?
op.openType.MaxStartOffset :
kMaxCheckStartPosition;
- #ifndef _SFX
+ #ifndef Z7_SFX
bool isUnknownExt = false;
#endif
+ #ifndef Z7_SFX
bool isForced = false;
+ #endif
+
unsigned numMainTypes = 0;
- int formatIndex = op.openType.FormatIndex;
+ const int formatIndex = op.openType.FormatIndex;
if (formatIndex >= 0)
{
+ #ifndef Z7_SFX
isForced = true;
+ #endif
orderIndices.Add(formatIndex);
numMainTypes = 1;
isMainFormatArr[(unsigned)formatIndex] = true;
@@ -1627,12 +1703,12 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
else
{
unsigned numFinded = 0;
- #ifndef _SFX
+ #ifndef Z7_SFX
bool isPrearcExt = false;
#endif
{
- #ifndef _SFX
+ #ifndef Z7_SFX
bool isZip = false;
bool isRar = false;
@@ -1654,10 +1730,12 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
isNumber = true;
}
if (isNumber)
+ {
if (c == 'z' || c == 'Z')
isZip = true;
else
isRar = true;
+ }
}
#endif
@@ -1667,29 +1745,29 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
const CArcInfoEx &ai = op.codecs->Formats[i];
if (IgnoreSplit || !op.openType.CanReturnArc)
- if (ai.IsSplit())
+ if (ai.Is_Split())
continue;
- if (op.excludedFormats->FindInSorted(i) >= 0)
+ if (op.excludedFormats->FindInSorted((int)i) >= 0)
continue;
- #ifndef _SFX
+ #ifndef Z7_SFX
if (IsPreArcFormat(ai))
isPrearcExt = true;
#endif
if (ai.FindExtension(extension) >= 0
- #ifndef _SFX
- || isZip && StringsAreEqualNoCase_Ascii(ai.Name, "zip")
- || isRar && StringsAreEqualNoCase_Ascii(ai.Name, "rar")
+ #ifndef Z7_SFX
+ || (isZip && ai.Is_Zip())
+ || (isRar && ai.Is_Rar())
#endif
)
{
// PrintNumber("orderIndices.Insert", i);
- orderIndices.Insert(numFinded++, i);
+ orderIndices.Insert(numFinded++, (int)i);
isMainFormatArr[i] = true;
}
else
- orderIndices.Add(i);
+ orderIndices.Add((int)i);
}
}
@@ -1709,11 +1787,11 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
}
*/
- #ifndef _SFX
+ #ifndef Z7_SFX
if (op.stream && orderIndices.Size() >= 2)
{
- RINOK(op.stream->Seek(0, STREAM_SEEK_SET, NULL));
+ RINOK(InStream_SeekToBegin(op.stream))
CByteBuffer byteBuffer;
CIntVector orderIndices2;
if (numFinded == 0 || IsExeExt(extension))
@@ -1722,21 +1800,21 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
}
else if (extension.IsEqualTo("000") || extension.IsEqualTo("001"))
{
- int i = FindFormatForArchiveType(op.codecs, orderIndices, "rar");
+ const int i = FindFormatForArchiveType(op.codecs, orderIndices, "rar");
if (i >= 0)
{
const size_t kBufSize = (1 << 10);
byteBuffer.Alloc(kBufSize);
size_t processedSize = kBufSize;
- RINOK(ReadStream(op.stream, byteBuffer, &processedSize));
+ RINOK(ReadStream(op.stream, byteBuffer, &processedSize))
if (processedSize >= 16)
{
const Byte *buf = byteBuffer;
const Byte kRarHeader[] = { 0x52 , 0x61, 0x72, 0x21, 0x1a, 0x07, 0x00 };
if (TestSignature(buf, kRarHeader, 7) && buf[9] == 0x73 && (buf[10] & 1) != 0)
{
- orderIndices2.Add(orderIndices[i]);
- orderIndices[i] = -1;
+ orderIndices2.Add(orderIndices[(unsigned)i]);
+ orderIndices[(unsigned)i] = -1;
if (i >= (int)numFinded)
numFinded++;
}
@@ -1748,17 +1826,33 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
const size_t kBufSize = (1 << 10);
byteBuffer.Alloc(kBufSize);
size_t processedSize = kBufSize;
- RINOK(ReadStream(op.stream, byteBuffer, &processedSize));
+ RINOK(ReadStream(op.stream, byteBuffer, &processedSize))
if (processedSize == 0)
return S_FALSE;
/*
check type order:
- 1) matched extension, no signuature
- 2) matched extension, matched signuature
+ 0) matched_extension && Backward
+ 1) matched_extension && (no_signuature || SignatureOffset != 0)
+ 2) matched_extension && (matched_signature)
// 3) no signuature
// 4) matched signuature
*/
+ // we move index from orderIndices to orderIndices2 for priority handlers.
+
+ for (unsigned i = 0; i < numFinded; i++)
+ {
+ const int index = orderIndices[i];
+ if (index < 0)
+ continue;
+ const CArcInfoEx &ai = op.codecs->Formats[(unsigned)index];
+ if (ai.Flags_BackwardOpen())
+ {
+ // backward doesn't need start signatures
+ orderIndices2.Add(index);
+ orderIndices[i] = -1;
+ }
+ }
MakeCheckOrder(op.codecs, orderIndices, numFinded, orderIndices2, NULL, 0);
MakeCheckOrder(op.codecs, orderIndices, numFinded, orderIndices2, byteBuffer, processedSize);
@@ -1768,7 +1862,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
FOR_VECTOR (i, orderIndices)
{
- int val = orderIndices[i];
+ const int val = orderIndices[i];
if (val != -1)
orderIndices2.Add(val);
}
@@ -1777,21 +1871,21 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
if (orderIndices.Size() >= 2)
{
- int iIso = FindFormatForArchiveType(op.codecs, orderIndices, "iso");
- int iUdf = FindFormatForArchiveType(op.codecs, orderIndices, "udf");
+ const int iIso = FindFormatForArchiveType(op.codecs, orderIndices, "iso");
+ const int iUdf = FindFormatForArchiveType(op.codecs, orderIndices, "udf");
if (iUdf > iIso && iIso >= 0)
{
- int isoIndex = orderIndices[iIso];
- int udfIndex = orderIndices[iUdf];
- orderIndices[iUdf] = isoIndex;
- orderIndices[iIso] = udfIndex;
+ const int isoIndex = orderIndices[(unsigned)iIso];
+ const int udfIndex = orderIndices[(unsigned)iUdf];
+ orderIndices[(unsigned)iUdf] = isoIndex;
+ orderIndices[(unsigned)iIso] = udfIndex;
}
}
numMainTypes = numFinded;
isUnknownExt = (numMainTypes == 0) || isPrearcExt;
- #else // _SFX
+ #else // Z7_SFX
numMainTypes = orderIndices.Size();
@@ -1805,13 +1899,12 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
UInt64 fileSize = 0;
if (op.stream)
{
- RINOK(op.stream->Seek(0, STREAM_SEEK_END, &fileSize));
- RINOK(op.stream->Seek(0, STREAM_SEEK_SET, NULL));
+ RINOK(InStream_GetSize_SeekToBegin(op.stream, fileSize))
}
FileSize = fileSize;
- #ifndef _SFX
+ #ifndef Z7_SFX
CBoolArr skipFrontalFormat(op.codecs->Formats.Size());
{
@@ -1838,15 +1931,18 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
for (unsigned i = 0; i < numCheckTypes; i++)
{
FormatIndex = orderIndices[i];
+
+ // orderIndices[] item cannot be negative here
bool exactOnly = false;
- #ifndef _SFX
+ #ifndef Z7_SFX
- const CArcInfoEx &ai = op.codecs->Formats[FormatIndex];
+ const CArcInfoEx &ai = op.codecs->Formats[(unsigned)FormatIndex];
// OutputDebugStringW(ai.Name);
if (i >= numMainTypes)
{
+ // here we allow mismatched extension only for backward handlers
if (!ai.Flags_BackwardOpen()
// && !ai.Flags_PureStartOpen()
)
@@ -1858,16 +1954,16 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
// Some handlers do not set total bytes. So we set it here
if (op.callback)
- RINOK(op.callback->SetTotal(NULL, &fileSize));
+ RINOK(op.callback->SetTotal(NULL, &fileSize))
if (op.stream)
{
- RINOK(op.stream->Seek(0, STREAM_SEEK_SET, NULL));
+ RINOK(InStream_SeekToBegin(op.stream))
}
CMyComPtr<IInArchive> archive;
- RINOK(PrepareToOpen(op, FormatIndex, archive));
+ RINOK(PrepareToOpen(op, (unsigned)FormatIndex, archive))
if (!archive)
continue;
@@ -1886,13 +1982,13 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
result = openSeq->OpenSeq(op.seqStream);
}
- RINOK(ReadBasicProps(archive, 0, result));
+ RINOK(ReadBasicProps(archive, 0, result))
if (result == S_FALSE)
{
bool isArc = ErrorInfo.IsArc_After_NonOpen();
- #ifndef _SFX
+ #ifndef Z7_SFX
// if it's archive, we allow another open attempt for parser
if (!mode.CanReturnParser || !isArc)
skipFrontalFormat[(unsigned)FormatIndex] = true;
@@ -1912,7 +2008,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
// if (formatIndex < 0 && !searchMarkerInHandler)
{
// if bad archive was detected, we don't need additional open attempts
- #ifndef _SFX
+ #ifndef Z7_SFX
if (!IsPreArcFormat(ai) /* || !mode.SkipSfxStub */)
#endif
return S_FALSE;
@@ -1921,7 +2017,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
}
/*
- #ifndef _SFX
+ #ifndef Z7_SFX
if (IsExeExt(extension) || ai.Flags_PreArc())
{
// openOnlyFullArc = false;
@@ -1934,9 +2030,9 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
continue;
}
- RINOK(result);
+ RINOK(result)
- #ifndef _SFX
+ #ifndef Z7_SFX
bool isMainFormat = isMainFormatArr[(unsigned)FormatIndex];
const COpenSpecFlags &specFlags = mode.GetSpec(isForced, isMainFormat, isUnknownExt);
@@ -1944,7 +2040,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
bool thereIsTail = ErrorInfo.ThereIsTail;
if (thereIsTail && mode.ZerosTailIsAllowed)
{
- RINOK(CheckZerosTail(op, Offset + PhySize));
+ RINOK(CheckZerosTail(op, (UInt64)(Offset + (Int64)PhySize)))
if (ErrorInfo.IgnoreTail)
thereIsTail = false;
}
@@ -1998,7 +2094,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
- #ifndef _SFX
+ #ifndef Z7_SFX
if (!op.stream)
return S_FALSE;
@@ -2012,7 +2108,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
}
else
{
- const CArcInfoEx &ai = op.codecs->Formats[formatIndex];
+ const CArcInfoEx &ai = op.codecs->Formats[(unsigned)formatIndex];
if (ai.FindExtension(extension) >= 0)
{
if (ai.Flags_FindSignature() && searchMarkerInHandler)
@@ -2043,9 +2139,9 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
endOfFile = true;
}
byteBuffer.Alloc(bufSize);
- RINOK(op.stream->Seek(0, STREAM_SEEK_SET, NULL));
+ RINOK(InStream_SeekToBegin(op.stream))
processedSize = bufSize;
- RINOK(ReadStream(op.stream, byteBuffer, &processedSize));
+ RINOK(ReadStream(op.stream, byteBuffer, &processedSize))
if (processedSize == 0)
return S_FALSE;
if (processedSize < bufSize)
@@ -2059,16 +2155,22 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
for (i = 0; i < orderIndices.Size(); i++)
{
- unsigned form = orderIndices[i];
+ // orderIndices[] item cannot be negative here
+ unsigned form = (unsigned)orderIndices[i];
if (skipFrontalFormat[form])
continue;
+
const CArcInfoEx &ai = op.codecs->Formats[form];
- if (ai.IsSplit())
+
+ if (ai.Is_Split())
{
- splitIndex = form;
+ splitIndex = (int)form;
continue;
}
+ if (ai.Flags_ByExtOnlyOpen())
+ continue;
+
if (ai.IsArcFunc)
{
UInt32 isArcRes = ai.IsArcFunc(byteBuffer, processedSize);
@@ -2081,7 +2183,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
continue;
}
- bool isNewStyleSignature = IsNewStyleSignature(ai);
+ const bool isNewStyleSignature = IsNewStyleSignature(ai);
bool needCheck = !isNewStyleSignature
|| ai.Signatures.IsEmpty()
|| ai.Flags_PureStartOpen()
@@ -2094,13 +2196,12 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
for (k = 0; k < ai.Signatures.Size(); k++)
{
const CByteBuffer &sig = ai.Signatures[k];
- UInt32 signatureEnd = ai.SignatureOffset + (UInt32)sig.Size();
- if (processedSize < signatureEnd)
+ if (processedSize < ai.SignatureOffset + sig.Size())
{
if (!endOfFile)
needCheck = true;
}
- else if (memcmp(sig, byteBuffer + ai.SignatureOffset, sig.Size()) == 0)
+ else if (TestSignature(sig, byteBuffer + ai.SignatureOffset, sig.Size()))
break;
}
if (k != ai.Signatures.Size())
@@ -2114,20 +2215,20 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
}
if (splitIndex >= 0)
- sortedFormats.Insert(0, splitIndex);
+ sortedFormats.Insert(0, (unsigned)splitIndex);
for (i = 0; i < sortedFormats.Size(); i++)
{
- FormatIndex = sortedFormats[i];
- const CArcInfoEx &ai = op.codecs->Formats[FormatIndex];
+ FormatIndex = (int)sortedFormats[i];
+ const CArcInfoEx &ai = op.codecs->Formats[(unsigned)FormatIndex];
if (op.callback)
- RINOK(op.callback->SetTotal(NULL, &fileSize));
+ RINOK(op.callback->SetTotal(NULL, &fileSize))
- RINOK(op.stream->Seek(0, STREAM_SEEK_SET, NULL));
+ RINOK(InStream_SeekToBegin(op.stream))
CMyComPtr<IInArchive> archive;
- RINOK(PrepareToOpen(op, FormatIndex, archive));
+ RINOK(PrepareToOpen(op, (unsigned)FormatIndex, archive))
if (!archive)
continue;
@@ -2140,7 +2241,10 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
result = archive->Open(op.stream, &searchLimit, op.callback);
else
*/
- result = OpenArchiveSpec(archive, !mode.CanReturnArc, op.stream, &searchLimit, op.callback, extractCallback_To_OpenCallback);
+ // if (!CanReturnArc), it's ParserMode, and we need phy size
+ result = OpenArchiveSpec(archive,
+ !mode.CanReturnArc, // needPhySize
+ op.stream, &searchLimit, op.callback, extractCallback_To_OpenCallback);
}
if (result == S_FALSE)
@@ -2150,9 +2254,9 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
// printf(" OpenForSize Error");
continue;
}
- RINOK(result);
+ RINOK(result)
- RINOK(ReadBasicProps(archive, 0, result));
+ RINOK(ReadBasicProps(archive, 0, result))
if (Offset > 0)
{
@@ -2162,12 +2266,12 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
}
NArchive::NParser::CParseItem pi;
- pi.Offset = Offset;
+ pi.Offset = (UInt64)Offset;
pi.Size = AvailPhySize;
// bool needScan = false;
- if (!PhySizeDefined)
+ if (!PhySize_Defined)
{
// it's for Z format
pi.LenIsUnknown = true;
@@ -2189,7 +2293,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
if (mode.CanReturnArc)
{
- bool isMainFormat = isMainFormatArr[(unsigned)FormatIndex];
+ const bool isMainFormat = isMainFormatArr[(unsigned)FormatIndex];
const COpenSpecFlags &specFlags = mode.GetSpec(isForced, isMainFormat, isUnknownExt);
bool openCur = false;
@@ -2199,7 +2303,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
{
if (mode.ZerosTailIsAllowed)
{
- RINOK(CheckZerosTail(op, Offset + PhySize));
+ RINOK(CheckZerosTail(op, (UInt64)(Offset + (Int64)PhySize)))
if (ErrorInfo.IgnoreTail)
openCur = true;
}
@@ -2239,7 +2343,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
continue;
// printf("\nAdd offset = %d", (int)pi.Offset);
- RINOK(ReadParseItemProps(archive, ai, pi));
+ RINOK(ReadParseItemProps(archive, ai, pi))
handlerSpec->AddItem(pi);
}
}
@@ -2294,7 +2398,9 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
int index = orderIndices[i];
if (index < 0)
continue;
- const CArcInfoEx &ai = op.codecs->Formats[index];
+ const CArcInfoEx &ai = op.codecs->Formats[(unsigned)index];
+ if (ai.Flags_ByExtOnlyOpen())
+ continue;
bool isDifficult = false;
// if (ai.Version < 0x91F) // we don't use parser with old DLL (before 9.31)
if (!ai.NewInterface)
@@ -2317,7 +2423,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
continue;
}
thereAreHandlersForSearch = true;
- UInt32 v = HASH_VAL(sig, 0);
+ UInt32 v = HASH_VAL(sig);
unsigned sigIndex = arc2sig[(unsigned)index] + k;
prevs[sigIndex] = hash[v];
hash[v] = (Byte)sigIndex;
@@ -2325,8 +2431,8 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
}
if (isDifficult)
{
- difficultFormats.Add(index);
- difficultBools[index] = true;
+ difficultFormats.Add((unsigned)index);
+ difficultBools[(unsigned)index] = true;
}
}
@@ -2336,7 +2442,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
// canReturnTailArc = true;
}
- RINOK(op.stream->Seek(0, STREAM_SEEK_SET, NULL));
+ RINOK(InStream_SeekToBegin(op.stream))
CLimitedCachedInStream *limitedStreamSpec = new CLimitedCachedInStream;
CMyComPtr<IInStream> limitedStream = limitedStreamSpec;
@@ -2350,13 +2456,13 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
openCallback_Offset = openCallback_Offset_Spec;
openCallback_Offset_Spec->Callback = op.callback;
openCallback_Offset_Spec->Callback.QueryInterface(IID_IArchiveOpenVolumeCallback, &openCallback_Offset_Spec->OpenVolumeCallback);
- #ifndef _NO_CRYPTO
+ #ifndef Z7_NO_CRYPTO
openCallback_Offset_Spec->Callback.QueryInterface(IID_ICryptoGetTextPassword, &openCallback_Offset_Spec->GetTextPassword);
#endif
}
if (op.callback)
- RINOK(op.callback->SetTotal(NULL, &fileSize));
+ RINOK(op.callback->SetTotal(NULL, &fileSize))
CByteBuffer &byteBuffer = limitedStreamSpec->Buffer;
byteBuffer.Alloc(kBufSize);
@@ -2394,8 +2500,8 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
size_t processedSize = kBufSize - bytesInBuf;
// printf("\nRead ask = %d", (unsigned)processedSize);
UInt64 seekPos = bufPhyPos + bytesInBuf;
- RINOK(op.stream->Seek(bufPhyPos + bytesInBuf, STREAM_SEEK_SET, NULL));
- RINOK(ReadStream(op.stream, byteBuffer + bytesInBuf, &processedSize));
+ RINOK(InStream_SeekSet(op.stream, bufPhyPos + bytesInBuf))
+ RINOK(ReadStream(op.stream, byteBuffer + bytesInBuf, &processedSize))
// printf(" processed = %d", (unsigned)processedSize);
if (processedSize == 0)
{
@@ -2440,6 +2546,9 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
}
}
+ if (bytesInBuf <= (size_t)posInBuf)
+ break;
+
bool useOffsetCallback = false;
if (openCallback_Offset)
{
@@ -2450,7 +2559,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
if (pos >= callbackPrev + (1 << 23))
{
- RINOK(openCallback_Offset_Spec->SetCompleted(NULL, NULL));
+ RINOK(openCallback_Offset->SetCompleted(NULL, NULL))
callbackPrev = pos;
}
}
@@ -2464,7 +2573,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
}
}
- size_t availSize = bytesInBuf - (size_t)posInBuf;
+ const size_t availSize = bytesInBuf - (size_t)posInBuf;
if (availSize < kNumHashBytes)
break;
size_t scanSize = availSize -
@@ -2489,17 +2598,19 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
scanSize++;
const Byte *buf = byteBuffer + (size_t)posInBuf;
+ const Byte *bufLimit = buf + scanSize;
size_t ppp = 0;
if (!needCheckStartOpen)
{
- for (; ppp < scanSize && hash[HASH_VAL(buf, ppp)] == 0xFF; ppp++);
+ for (; buf < bufLimit && hash[HASH_VAL(buf)] == 0xFF; buf++);
+ ppp = (size_t)(buf - (byteBuffer + (size_t)posInBuf));
pos += ppp;
- if (ppp == scanSize)
+ if (buf == bufLimit)
continue;
}
- UInt32 v = HASH_VAL(buf, ppp);
+ UInt32 v = HASH_VAL(buf);
bool nextNeedCheckStartOpen = true;
unsigned i = hash[v];
unsigned indexOfDifficult = 0;
@@ -2539,7 +2650,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
const CByteBuffer &sig = ai.Signatures[sigIndex];
if (ppp + sig.Size() > availSize
- || !TestSignature(buf + ppp, sig, sig.Size()))
+ || !TestSignature(buf, sig, sig.Size()))
continue;
// printf("\nSignature OK: %10S %8x %5d", (const wchar_t *)ai.Name, (int)pos, (int)(pos - prevPos));
// prevPos = pos;
@@ -2571,10 +2682,10 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
if (ai.IsArcFunc && startArcPos >= bufPhyPos)
{
- size_t offsetInBuf = (size_t)(startArcPos - bufPhyPos);
+ const size_t offsetInBuf = (size_t)(startArcPos - bufPhyPos);
if (offsetInBuf < bytesInBuf)
{
- UInt32 isArcRes = ai.IsArcFunc(byteBuffer + offsetInBuf, bytesInBuf - offsetInBuf);
+ const UInt32 isArcRes = ai.IsArcFunc(byteBuffer + offsetInBuf, bytesInBuf - offsetInBuf);
if (isArcRes == k_IsArc_Res_NO)
continue;
if (isArcRes == k_IsArc_Res_NEED_MORE && endOfFile)
@@ -2590,34 +2701,30 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
// printf("\nIsArc OK: %S", (const wchar_t *)ai.Name);
}
- /*
- if (pos == 67109888)
- pos = pos;
- */
PRF(printf("\npos = %9I64d : %S", pos, (const wchar_t *)ai.Name));
- bool isMainFormat = isMainFormatArr[index];
+ const bool isMainFormat = isMainFormatArr[index];
const COpenSpecFlags &specFlags = mode.GetSpec(isForced, isMainFormat, isUnknownExt);
CMyComPtr<IInArchive> archive;
- RINOK(PrepareToOpen(op, index, archive));
+ RINOK(PrepareToOpen(op, index, archive))
if (!archive)
return E_FAIL;
// OutputDebugStringW(ai.Name);
- UInt64 rem = fileSize - startArcPos;
+ const UInt64 rem = fileSize - startArcPos;
UInt64 arcStreamOffset = 0;
if (ai.Flags_UseGlobalOffset())
{
- limitedStreamSpec->InitAndSeek(0, fileSize);
- limitedStream->Seek(startArcPos, STREAM_SEEK_SET, NULL);
+ RINOK(limitedStreamSpec->InitAndSeek(0, fileSize))
+ RINOK(InStream_SeekSet(limitedStream, startArcPos))
}
else
{
- limitedStreamSpec->InitAndSeek(startArcPos, rem);
+ RINOK(limitedStreamSpec->InitAndSeek(startArcPos, rem))
arcStreamOffset = startArcPos;
}
@@ -2633,33 +2740,42 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
extractCallback_To_OpenCallback_Spec->Files = 0;
extractCallback_To_OpenCallback_Spec->Offset = startArcPos;
- HRESULT result = OpenArchiveSpec(archive, true, limitedStream, &maxCheckStartPosition,
+ HRESULT result = OpenArchiveSpec(archive,
+ true, // needPhySize
+ limitedStream, &maxCheckStartPosition,
useOffsetCallback ? (IArchiveOpenCallback *)openCallback_Offset : (IArchiveOpenCallback *)op.callback,
extractCallback_To_OpenCallback);
- RINOK(ReadBasicProps(archive, ai.Flags_UseGlobalOffset() ? 0 : startArcPos, result));
+ RINOK(ReadBasicProps(archive, ai.Flags_UseGlobalOffset() ? 0 : startArcPos, result))
bool isOpen = false;
+
if (result == S_FALSE)
{
if (!mode.CanReturnParser)
{
if (formatIndex < 0 && ErrorInfo.IsArc_After_NonOpen())
{
- ErrorInfo.ErrorFormatIndex = index;
+ ErrorInfo.ErrorFormatIndex = (int)index;
NonOpen_ErrorInfo = ErrorInfo;
// if archive was detected, we don't need additional open attempts
return S_FALSE;
}
continue;
}
- if (!ErrorInfo.IsArc_After_NonOpen() || !PhySizeDefined || PhySize == 0)
+ if (!ErrorInfo.IsArc_After_NonOpen() || !PhySize_Defined || PhySize == 0)
continue;
}
else
{
+ if (PhySize_Defined && PhySize == 0)
+ {
+ PRF(printf(" phySize_Defined && PhySize == 0 "));
+ // we skip that epmty archive case with unusual unexpected (PhySize == 0) from Code function.
+ continue;
+ }
isOpen = true;
- RINOK(result);
+ RINOK(result)
PRF(printf(" OK "));
}
@@ -2671,13 +2787,14 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
pi.Offset = startArcPos;
if (ai.Flags_UseGlobalOffset())
- pi.Offset = Offset;
+ pi.Offset = (UInt64)Offset;
else if (Offset != 0)
return E_FAIL;
- UInt64 arcRem = FileSize - pi.Offset;
+
+ const UInt64 arcRem = FileSize - pi.Offset;
UInt64 phySize = arcRem;
- bool phySizeDefined = PhySizeDefined;
- if (phySizeDefined)
+ const bool phySize_Defined = PhySize_Defined;
+ if (phySize_Defined)
{
if (pi.Offset + PhySize > FileSize)
{
@@ -2703,9 +2820,9 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
bool needScan = false;
- if (isOpen && !phySizeDefined)
+ if (isOpen && !phySize_Defined)
{
- // it's for Z format
+ // it's for Z format, or bzip2,gz,xz with phySize that was not detected
pi.LenIsUnknown = true;
needScan = true;
phySize = arcRem;
@@ -2722,7 +2839,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
/*
if (needSkipFullArc)
- if (pi.Offset == 0 && phySizeDefined && pi.Size >= fileSize)
+ if (pi.Offset == 0 && phySize_Defined && pi.Size >= fileSize)
continue;
*/
if (pi.Offset == 0 && !pi.LenIsUnknown && pi.Size >= FileSize)
@@ -2748,9 +2865,9 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
pos = pi.Offset + pi.Size;
- RINOK(ReadParseItemProps(archive, ai, pi));
+ RINOK(ReadParseItemProps(archive, ai, pi))
- if (pi.Offset < startArcPos && !mode.EachPos /* && phySizeDefined */)
+ if (pi.Offset < startArcPos && !mode.EachPos /* && phySize_Defined */)
{
/* It's for DMG format.
This code deletes all previous items that are included to current item */
@@ -2769,7 +2886,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
}
- if (isOpen && mode.CanReturnArc && phySizeDefined)
+ if (isOpen && mode.CanReturnArc && phySize_Defined)
{
// if (pi.Offset + pi.Size >= fileSize)
bool openCur = false;
@@ -2777,7 +2894,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
bool thereIsTail = ErrorInfo.ThereIsTail;
if (thereIsTail && mode.ZerosTailIsAllowed)
{
- RINOK(CheckZerosTail(op, arcStreamOffset + Offset + PhySize));
+ RINOK(CheckZerosTail(op, (UInt64)((Int64)arcStreamOffset + Offset + (Int64)PhySize)))
if (ErrorInfo.IgnoreTail)
thereIsTail = false;
}
@@ -2785,10 +2902,12 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
if (pi.Offset != 0)
{
if (!pi.IsNotArcType)
+ {
if (thereIsTail)
openCur = specFlags.CanReturnMid;
else
openCur = specFlags.CanReturnTail;
+ }
}
else
{
@@ -2796,11 +2915,11 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
openCur = true;
else
openCur = specFlags.CanReturnFrontal;
-
if (formatIndex >= -2)
openCur = true;
}
+
if (formatIndex < 0 && pi.IsSelfExe /* && mode.SkipSfxStub */)
openCur = false;
@@ -2827,7 +2946,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
{
InStream = op.stream;
Archive = archive;
- FormatIndex = index;
+ FormatIndex = (int)index;
ArcStreamOffset = arcStreamOffset;
return S_OK;
}
@@ -2841,7 +2960,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
}
*/
- pi.FormatIndex = index;
+ pi.FormatIndex = (int)index;
// printf("\nAdd offset = %d", (int)pi.Offset);
handlerSpec->AddItem(pi);
@@ -2896,9 +3015,12 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
return S_OK;
}
+
+
+
HRESULT CArc::OpenStream(const COpenOptions &op)
{
- RINOK(OpenStream2(op));
+ RINOK(OpenStream2(op))
// PrintNumber("op.formatIndex 3", op.formatIndex);
if (Archive)
@@ -2908,25 +3030,25 @@ HRESULT CArc::OpenStream(const COpenOptions &op)
Archive->QueryInterface(IID_IArchiveGetRawProps, (void **)&GetRawProps);
Archive->QueryInterface(IID_IArchiveGetRootProps, (void **)&GetRootProps);
- RINOK(Archive_GetArcBoolProp(Archive, kpidIsTree, IsTree));
- RINOK(Archive_GetArcBoolProp(Archive, kpidIsDeleted, Ask_Deleted));
- RINOK(Archive_GetArcBoolProp(Archive, kpidIsAltStream, Ask_AltStream));
- RINOK(Archive_GetArcBoolProp(Archive, kpidIsAux, Ask_Aux));
- RINOK(Archive_GetArcBoolProp(Archive, kpidINode, Ask_INode));
- RINOK(Archive_GetArcBoolProp(Archive, kpidReadOnly, IsReadOnly));
+ RINOK(Archive_GetArcProp_Bool(Archive, kpidIsTree, IsTree))
+ RINOK(Archive_GetArcProp_Bool(Archive, kpidIsDeleted, Ask_Deleted))
+ RINOK(Archive_GetArcProp_Bool(Archive, kpidIsAltStream, Ask_AltStream))
+ RINOK(Archive_GetArcProp_Bool(Archive, kpidIsAux, Ask_Aux))
+ RINOK(Archive_GetArcProp_Bool(Archive, kpidINode, Ask_INode))
+ RINOK(Archive_GetArcProp_Bool(Archive, kpidReadOnly, IsReadOnly))
const UString fileName = ExtractFileNameFromPath(Path);
UString extension;
{
int dotPos = fileName.ReverseFind_Dot();
if (dotPos >= 0)
- extension = fileName.Ptr(dotPos + 1);
+ extension = fileName.Ptr((unsigned)(dotPos + 1));
}
DefaultName.Empty();
if (FormatIndex >= 0)
{
- const CArcInfoEx &ai = op.codecs->Formats[FormatIndex];
+ const CArcInfoEx &ai = op.codecs->Formats[(unsigned)FormatIndex];
if (ai.Exts.Size() == 0)
DefaultName = GetDefaultName2(fileName, UString(), UString());
else
@@ -2934,7 +3056,7 @@ HRESULT CArc::OpenStream(const COpenOptions &op)
int subExtIndex = ai.FindExtension(extension);
if (subExtIndex < 0)
subExtIndex = 0;
- const CArcExtInfo &extInfo = ai.Exts[subExtIndex];
+ const CArcExtInfo &extInfo = ai.Exts[(unsigned)subExtIndex];
DefaultName = GetDefaultName2(fileName, extInfo.Ext, extInfo.AddExt);
}
}
@@ -2943,13 +3065,13 @@ HRESULT CArc::OpenStream(const COpenOptions &op)
return S_OK;
}
-#ifdef _SFX
+#ifdef Z7_SFX
#ifdef _WIN32
- static const char *k_ExeExt = ".exe";
+ #define k_ExeExt ".exe"
static const unsigned k_ExeExt_Len = 4;
#else
- static const char *k_ExeExt = "";
+ #define k_ExeExt ""
static const unsigned k_ExeExt_Len = 0;
#endif
@@ -2972,11 +3094,9 @@ HRESULT CArc::OpenStreamOrFile(COpenOptions &op)
fileStream = fileStreamSpec;
Path = filePath;
if (!fileStreamSpec->Open(us2fs(Path)))
- {
- return GetLastError();
- }
+ return GetLastError_noZero_HRESULT();
op.stream = fileStream;
- #ifdef _SFX
+ #ifdef Z7_SFX
IgnoreSplit = true;
#endif
}
@@ -2985,7 +3105,7 @@ HRESULT CArc::OpenStreamOrFile(COpenOptions &op)
if (callback)
{
UInt64 fileSize;
- RINOK(op.stream->Seek(0, STREAM_SEEK_END, &fileSize));
+ RINOK(InStream_GetSize_SeekToEnd(op.stream, fileSize));
RINOK(op.callback->SetTotal(NULL, &fileSize))
}
*/
@@ -2993,7 +3113,7 @@ HRESULT CArc::OpenStreamOrFile(COpenOptions &op)
HRESULT res = OpenStream(op);
IgnoreSplit = false;
- #ifdef _SFX
+ #ifdef Z7_SFX
if (res != S_FALSE
|| !fileStreamSpec
@@ -3009,13 +3129,13 @@ HRESULT CArc::OpenStreamOrFile(COpenOptions &op)
FOR_VECTOR (i, op.codecs->Formats)
{
const CArcInfoEx &ai = op.codecs->Formats[i];
- if (ai.IsSplit())
+ if (ai.Is_Split())
continue;
UString path3 = path2;
- path3 += L'.';
+ path3.Add_Dot();
path3 += ai.GetMainExt(); // "7z" for SFX.
Path = path3;
- Path.AddAscii(".001");
+ Path += ".001";
bool isOk = op.callbackSpec->SetSecondFileInfo(us2fs(Path));
if (!isOk)
{
@@ -3058,7 +3178,7 @@ HRESULT CArchiveLink::Close()
for (unsigned i = Arcs.Size(); i != 0;)
{
i--;
- RINOK(Arcs[i].Close());
+ RINOK(Arcs[i].Close())
}
IsOpen = false;
// ErrorsText.Empty();
@@ -3191,13 +3311,13 @@ HRESULT CArchiveLink::Open(COpenOptions &op)
UInt32 mainSubfile;
{
NCOM::CPropVariant prop;
- RINOK(arc.Archive->GetArchiveProperty(kpidMainSubfile, &prop));
+ RINOK(arc.Archive->GetArchiveProperty(kpidMainSubfile, &prop))
if (prop.vt == VT_UI4)
mainSubfile = prop.ulVal;
else
break;
UInt32 numItems;
- RINOK(arc.Archive->GetNumberOfItems(&numItems));
+ RINOK(arc.Archive->GetNumberOfItems(&numItems))
if (mainSubfile >= numItems)
break;
}
@@ -3216,16 +3336,17 @@ HRESULT CArchiveLink::Open(COpenOptions &op)
break;
CArc arc2;
- RINOK(arc.GetItemPath(mainSubfile, arc2.Path));
+ RINOK(arc.GetItem_Path(mainSubfile, arc2.Path))
bool zerosTailIsAllowed;
- RINOK(Archive_GetItemBoolProp(arc.Archive, mainSubfile, kpidZerosTailIsAllowed, zerosTailIsAllowed));
+ RINOK(Archive_GetItemBoolProp(arc.Archive, mainSubfile, kpidZerosTailIsAllowed, zerosTailIsAllowed))
if (op.callback)
{
- CMyComPtr<IArchiveOpenSetSubArchiveName> setSubArchiveName;
- op.callback->QueryInterface(IID_IArchiveOpenSetSubArchiveName, (void **)&setSubArchiveName);
+ Z7_DECL_CMyComPtr_QI_FROM(
+ IArchiveOpenSetSubArchiveName,
+ setSubArchiveName, op.callback)
if (setSubArchiveName)
setSubArchiveName->SetSubArchiveName(arc2.Path);
}
@@ -3236,7 +3357,7 @@ HRESULT CArchiveLink::Open(COpenOptions &op)
CIntVector excl;
COpenOptions op2;
- #ifndef _SFX
+ #ifndef Z7_SFX
op2.props = op.props;
#endif
op2.codecs = op.codecs;
@@ -3259,8 +3380,8 @@ HRESULT CArchiveLink::Open(COpenOptions &op)
NonOpen_ArcPath = arc2.Path;
break;
}
- RINOK(result);
- RINOK(arc.GetItemMTime(mainSubfile, arc2.MTime, arc2.MTimeDefined));
+ RINOK(result)
+ RINOK(arc.GetItem_MTime(mainSubfile, arc2.MTime))
Arcs.Add(arc2);
}
IsOpen = !Arcs.IsEmpty();
@@ -3279,7 +3400,7 @@ HRESULT CArchiveLink::Open2(COpenOptions &op, IOpenCallbackUI *callbackUI)
if (!op.stream && !op.stdInMode)
{
NFile::NDir::GetFullPathAndSplit(us2fs(op.filePath), prefix, name);
- openCallbackSpec->Init(prefix, name);
+ RINOK(openCallbackSpec->Init2(prefix, name))
}
else
{
@@ -3294,7 +3415,7 @@ HRESULT CArchiveLink::Open2(COpenOptions &op, IOpenCallbackUI *callbackUI)
PasswordWasAsked = openCallbackSpec->PasswordWasAsked;
// Password = openCallbackSpec->Password;
- RINOK(res);
+ RINOK(res)
// VolumePaths.Add(fs2us(prefix + name));
FOR_VECTOR (i, openCallbackSpec->FileNames_WasUsed)
@@ -3309,7 +3430,7 @@ HRESULT CArchiveLink::Open2(COpenOptions &op, IOpenCallbackUI *callbackUI)
return S_OK;
}
-HRESULT CArc::ReOpen(const COpenOptions &op)
+HRESULT CArc::ReOpen(const COpenOptions &op, IArchiveOpenCallback *openCallback_Additional)
{
ErrorInfo.ClearErrors();
ErrorInfo.ErrorFormatIndex = -1;
@@ -3317,8 +3438,9 @@ HRESULT CArc::ReOpen(const COpenOptions &op)
UInt64 fileSize = 0;
if (op.stream)
{
- RINOK(op.stream->Seek(0, STREAM_SEEK_END, &fileSize));
- RINOK(op.stream->Seek(0, STREAM_SEEK_SET, NULL));
+ RINOK(InStream_SeekToBegin(op.stream))
+ RINOK(InStream_AtBegin_GetSize(op.stream, fileSize))
+ // RINOK(InStream_GetSize_SeekToBegin(op.stream, fileSize))
}
FileSize = fileSize;
@@ -3331,20 +3453,23 @@ HRESULT CArc::ReOpen(const COpenOptions &op)
CTailInStream *tailStreamSpec = new CTailInStream;
stream2 = tailStreamSpec;
tailStreamSpec->Stream = op.stream;
- tailStreamSpec->Offset = globalOffset;
+ tailStreamSpec->Offset = (UInt64)globalOffset;
tailStreamSpec->Init();
- RINOK(tailStreamSpec->SeekToStart());
+ RINOK(tailStreamSpec->SeekToStart())
}
// There are archives with embedded STUBs (like ZIP), so we must support signature scanning
// But for another archives we can use 0 here. So the code can be fixed !!!
UInt64 maxStartPosition = kMaxCheckStartPosition;
- HRESULT res = Archive->Open(stream2, &maxStartPosition, op.callback);
+ IArchiveOpenCallback *openCallback = openCallback_Additional;
+ if (!openCallback)
+ openCallback = op.callback;
+ HRESULT res = Archive->Open(stream2, &maxStartPosition, openCallback);
if (res == S_OK)
{
- RINOK(ReadBasicProps(Archive, globalOffset, res));
- ArcStreamOffset = globalOffset;
+ RINOK(ReadBasicProps(Archive, (UInt64)globalOffset, res))
+ ArcStreamOffset = (UInt64)globalOffset;
if (ArcStreamOffset != 0)
InStream = op.stream;
}
@@ -3356,7 +3481,7 @@ HRESULT CArchiveLink::Open3(COpenOptions &op, IOpenCallbackUI *callbackUI)
HRESULT res = Open2(op, callbackUI);
if (callbackUI)
{
- RINOK(callbackUI->Open_Finished());
+ RINOK(callbackUI->Open_Finished())
}
return res;
}
@@ -3376,6 +3501,8 @@ HRESULT CArchiveLink::ReOpen(COpenOptions &op)
if (Arcs.Size() == 0) // ???
return Open2(op, NULL);
+ /* if archive is multivolume (unsupported here still)
+ COpenCallbackImp object will exist after Open stage. */
COpenCallbackImp *openCallbackSpec = new COpenCallbackImp;
CMyComPtr<IArchiveOpenCallback> openCallbackNew = openCallbackSpec;
@@ -3384,18 +3511,20 @@ HRESULT CArchiveLink::ReOpen(COpenOptions &op)
{
FString dirPrefix, fileName;
NFile::NDir::GetFullPathAndSplit(us2fs(op.filePath), dirPrefix, fileName);
- openCallbackSpec->Init(dirPrefix, fileName);
+ RINOK(openCallbackSpec->Init2(dirPrefix, fileName))
}
CInFileStream *fileStreamSpec = new CInFileStream;
CMyComPtr<IInStream> stream(fileStreamSpec);
if (!fileStreamSpec->Open(us2fs(op.filePath)))
- return GetLastError();
+ return GetLastError_noZero_HRESULT();
op.stream = stream;
CArc &arc = Arcs[0];
- HRESULT res = arc.ReOpen(op);
+ const HRESULT res = arc.ReOpen(op, openCallbackNew);
+
+ openCallbackSpec->ReOpenCallback = NULL;
PasswordWasAsked = openCallbackSpec->PasswordWasAsked;
// Password = openCallbackSpec->Password;
@@ -3404,8 +3533,9 @@ HRESULT CArchiveLink::ReOpen(COpenOptions &op)
return res;
}
-#ifndef _SFX
+#ifndef Z7_SFX
+bool ParseComplexSize(const wchar_t *s, UInt64 &result);
bool ParseComplexSize(const wchar_t *s, UInt64 &result)
{
result = 0;
@@ -3463,7 +3593,7 @@ static bool ParseTypeParams(const UString &s, COpenType &type)
return false;
}
-bool ParseType(CCodecs &codecs, const UString &s, COpenType &type)
+static bool ParseType(CCodecs &codecs, const UString &s, COpenType &type)
{
int pos2 = s.Find(L':');
@@ -3472,11 +3602,11 @@ bool ParseType(CCodecs &codecs, const UString &s, COpenType &type)
if (pos2 < 0)
{
name = s;
- pos2 = s.Len();
+ pos2 = (int)s.Len();
}
else
{
- name = s.Left(pos2);
+ name = s.Left((unsigned)pos2);
pos2++;
}
@@ -3497,6 +3627,12 @@ bool ParseType(CCodecs &codecs, const UString &s, COpenType &type)
type.CanReturnArc = false;
type.CanReturnParser = true;
}
+ else if (name.IsEqualTo_Ascii_NoCase("hash"))
+ {
+ // type.CanReturnArc = false;
+ // type.CanReturnParser = false;
+ type.IsHashType = true;
+ }
else
return false;
}
@@ -3505,17 +3641,17 @@ bool ParseType(CCodecs &codecs, const UString &s, COpenType &type)
}
- for (unsigned i = pos2; i < s.Len();)
+ for (unsigned i = (unsigned)pos2; i < s.Len();)
{
int next = s.Find(L':', i);
if (next < 0)
- next = s.Len();
- const UString name = s.Mid(i, next - i);
+ next = (int)s.Len();
+ const UString name = s.Mid(i, (unsigned)next - i);
if (name.IsEmpty())
return false;
if (!ParseTypeParams(name, type))
return false;
- i = next + 1;
+ i = (unsigned)next + 1;
}
return true;
@@ -3524,21 +3660,36 @@ bool ParseType(CCodecs &codecs, const UString &s, COpenType &type)
bool ParseOpenTypes(CCodecs &codecs, const UString &s, CObjectVector<COpenType> &types)
{
types.Clear();
+ bool isHashType = false;
for (unsigned pos = 0; pos < s.Len();)
{
int pos2 = s.Find(L'.', pos);
if (pos2 < 0)
- pos2 = s.Len();
- UString name = s.Mid(pos, pos2 - pos);
+ pos2 = (int)s.Len();
+ UString name = s.Mid(pos, (unsigned)pos2 - pos);
if (name.IsEmpty())
return false;
COpenType type;
if (!ParseType(codecs, name, type))
return false;
+ if (isHashType)
+ return false;
+ if (type.IsHashType)
+ isHashType = true;
types.Add(type);
- pos = pos2 + 1;
+ pos = (unsigned)pos2 + 1;
}
return true;
}
+/*
+bool IsHashType(const CObjectVector<COpenType> &types)
+{
+ if (types.Size() != 1)
+ return false;
+ return types[0].IsHashType;
+}
+*/
+
+
#endif
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/OpenArchive.h b/3rdparty/lzma/CPP/7zip/UI/Common/OpenArchive.h
index d46d69e8a8d..5c3bfe5df95 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/OpenArchive.h
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/OpenArchive.h
@@ -1,15 +1,16 @@
// OpenArchive.h
-#ifndef __OPEN_ARCHIVE_H
-#define __OPEN_ARCHIVE_H
+#ifndef ZIP7_INC_OPEN_ARCHIVE_H
+#define ZIP7_INC_OPEN_ARCHIVE_H
#include "../../../Windows/PropVariant.h"
#include "ArchiveOpenCallback.h"
#include "LoadCodecs.h"
#include "Property.h"
+#include "DirItem.h"
-#ifndef _SFX
+#ifndef Z7_SFX
#define SUPPORT_ALT_STREAMS
@@ -33,7 +34,7 @@ struct COptionalOpenProperties
};
*/
-#ifdef _SFX
+#ifdef Z7_SFX
#define OPEN_PROPS_DECL
#else
#define OPEN_PROPS_DECL const CObjectVector<CProperty> *props;
@@ -70,6 +71,7 @@ struct COpenType
bool CanReturnArc;
bool CanReturnParser;
+ bool IsHashType;
bool EachPos;
// bool SkipSfxStub;
@@ -88,9 +90,10 @@ struct COpenType
COpenType():
FormatIndex(-1),
Recursive(true),
- EachPos(false),
CanReturnArc(true),
CanReturnParser(false),
+ IsHashType(false),
+ EachPos(false),
// SkipSfxStub(true),
// ExeAsUnknown(true),
ZerosTailIsAllowed(false),
@@ -121,7 +124,7 @@ struct COpenOptions
IInStream *stream;
ISequentialInStream *seqStream;
IArchiveOpenCallback *callback;
- COpenCallbackImp *callbackSpec;
+ COpenCallbackImp *callbackSpec; // it's used for SFX only
OPEN_PROPS_DECL
// bool openOnlySpecifiedByExtension,
@@ -240,7 +243,7 @@ struct CReadArcItem
bool MainIsDir;
UInt32 ParentIndex; // use it, if IsAltStream
- #ifndef _SFX
+ #ifndef Z7_SFX
bool _use_baseParentFolder_mode;
int _baseParentFolder;
#endif
@@ -251,22 +254,25 @@ struct CReadArcItem
WriteToAltStreamIfColon = false;
#endif
- #ifndef _SFX
+ #ifndef Z7_SFX
_use_baseParentFolder_mode = false;
_baseParentFolder = -1;
#endif
}
};
+
+
+
class CArc
{
HRESULT PrepareToOpen(const COpenOptions &op, unsigned formatIndex, CMyComPtr<IInArchive> &archive);
HRESULT CheckZerosTail(const COpenOptions &op, UInt64 offset);
HRESULT OpenStream2(const COpenOptions &options);
- #ifndef _SFX
+ #ifndef Z7_SFX
// parts.Back() can contain alt stream name "nams:AltName"
- HRESULT GetItemPathToParent(UInt32 index, UInt32 parent, UStringVector &parts) const;
+ HRESULT GetItem_PathToParent(UInt32 index, UInt32 parent, UStringVector &parts) const;
#endif
public:
@@ -279,49 +285,50 @@ public:
CMyComPtr<IArchiveGetRawProps> GetRawProps;
CMyComPtr<IArchiveGetRootProps> GetRootProps;
- CArcErrorInfo ErrorInfo; // for OK archives
- CArcErrorInfo NonOpen_ErrorInfo; // ErrorInfo for mainArchive (false OPEN)
+ bool IsParseArc;
+
+ bool IsTree;
+ bool IsReadOnly;
+
+ bool Ask_Deleted;
+ bool Ask_AltStream;
+ bool Ask_Aux;
+ bool Ask_INode;
+
+ bool IgnoreSplit; // don't try split handler
UString Path;
UString filePath;
UString DefaultName;
- int FormatIndex; // - 1 means Parser.
- int SubfileIndex;
- FILETIME MTime;
- bool MTimeDefined;
+ int FormatIndex; // -1 means Parser
+ UInt32 SubfileIndex; // (UInt32)(Int32)-1; means no subfile
+
+ // CFiTime MTime;
+ // bool MTime_Defined;
+ CArcTime MTime;
Int64 Offset; // it's offset of start of archive inside stream that is open by Archive Handler
UInt64 PhySize;
// UInt64 OkPhySize;
- bool PhySizeDefined;
+ bool PhySize_Defined;
// bool OkPhySize_Defined;
UInt64 FileSize;
UInt64 AvailPhySize; // PhySize, but it's reduced if exceed end of file
- // bool offsetDefined;
- UInt64 GetEstmatedPhySize() const { return PhySizeDefined ? PhySize : FileSize; }
+ CArcErrorInfo ErrorInfo; // for OK archives
+ CArcErrorInfo NonOpen_ErrorInfo; // ErrorInfo for mainArchive (false OPEN)
+
+ UInt64 GetEstmatedPhySize() const { return PhySize_Defined ? PhySize : FileSize; }
UInt64 ArcStreamOffset; // offset of stream that is open by Archive Handler
- Int64 GetGlobalOffset() const { return ArcStreamOffset + Offset; } // it's global offset of archive
+ Int64 GetGlobalOffset() const { return (Int64)ArcStreamOffset + Offset; } // it's global offset of archive
// AString ErrorFlagsText;
- bool IsParseArc;
-
- bool IsTree;
- bool IsReadOnly;
-
- bool Ask_Deleted;
- bool Ask_AltStream;
- bool Ask_Aux;
- bool Ask_INode;
-
- bool IgnoreSplit; // don't try split handler
-
// void Set_ErrorFlagsText();
CArc():
- MTimeDefined(false),
+ // MTime_Defined(false),
IsTree(false),
IsReadOnly(false),
Ask_Deleted(false),
@@ -333,34 +340,51 @@ public:
HRESULT ReadBasicProps(IInArchive *archive, UInt64 startPos, HRESULT openRes);
- // ~CArc();
-
HRESULT Close()
{
InStream.Release();
return Archive->Close();
}
- HRESULT GetItemPath(UInt32 index, UString &result) const;
- HRESULT GetDefaultItemPath(UInt32 index, UString &result) const;
+ HRESULT GetItem_Path(UInt32 index, UString &result) const;
+ HRESULT GetItem_DefaultPath(UInt32 index, UString &result) const;
// GetItemPath2 adds [DELETED] dir prefix for deleted items.
- HRESULT GetItemPath2(UInt32 index, UString &result) const;
+ HRESULT GetItem_Path2(UInt32 index, UString &result) const;
HRESULT GetItem(UInt32 index, CReadArcItem &item) const;
- HRESULT GetItemSize(UInt32 index, UInt64 &size, bool &defined) const;
- HRESULT GetItemMTime(UInt32 index, FILETIME &ft, bool &defined) const;
- HRESULT IsItemAnti(UInt32 index, bool &result) const
+ HRESULT GetItem_Size(UInt32 index, UInt64 &size, bool &defined) const;
+
+ /* if (GetProperty() returns vt==VT_EMPTY), this function sets
+ timestamp from archive file timestamp (MTime).
+ So (at) will be set in most cases (at.Def == true)
+ if (at.Prec == 0)
+ {
+ it means that (Prec == 0) was returned for (kpidMTime),
+ and no value was returned for (kpidTimeType).
+ it can mean Windows precision or unknown precision.
+ }
+ */
+ HRESULT GetItem_MTime(UInt32 index, CArcTime &at) const;
+
+ HRESULT IsItem_Anti(UInt32 index, bool &result) const
{ return Archive_GetItemBoolProp(Archive, index, kpidIsAnti, result); }
HRESULT OpenStream(const COpenOptions &options);
HRESULT OpenStreamOrFile(COpenOptions &options);
- HRESULT ReOpen(const COpenOptions &options);
+ HRESULT ReOpen(const COpenOptions &options, IArchiveOpenCallback *openCallback_Additional);
HRESULT CreateNewTailStream(CMyComPtr<IInStream> &stream);
+
+ bool IsHashHandler(const COpenOptions &options) const
+ {
+ if (FormatIndex < 0)
+ return false;
+ return options.codecs->Formats[(unsigned)FormatIndex].Flags_HashHandler();
+ }
};
struct CArchiveLink
@@ -397,6 +421,13 @@ struct CArchiveLink
IArchiveGetRawProps *GetArchiveGetRawProps() const { return Arcs.Back().GetRawProps; }
IArchiveGetRootProps *GetArchiveGetRootProps() const { return Arcs.Back().GetRootProps; }
+ /*
+ Open() opens archive and COpenOptions::callback
+ Open2() uses COpenCallbackImp that implements Volumes and password callback
+ Open3() calls Open2() and callbackUI->Open_Finished();
+ Open_Strict() returns S_FALSE also in case, if there is non-open expected nested archive.
+ */
+
HRESULT Open(COpenOptions &options);
HRESULT Open2(COpenOptions &options, IOpenCallbackUI *callbackUI);
HRESULT Open3(COpenOptions &options, IOpenCallbackUI *callbackUI);
@@ -414,4 +445,25 @@ struct CArchiveLink
bool ParseOpenTypes(CCodecs &codecs, const UString &s, CObjectVector<COpenType> &types);
+// bool IsHashType(const CObjectVector<COpenType> &types);
+
+
+struct CDirPathSortPair
+{
+ unsigned Len;
+ unsigned Index;
+
+ void SetNumSlashes(const FChar *s);
+
+ int Compare(const CDirPathSortPair &a) const
+ {
+ // We need sorting order where parent items will be after child items
+ if (Len < a.Len) return 1;
+ if (Len > a.Len) return -1;
+ if (Index < a.Index) return -1;
+ if (Index > a.Index) return 1;
+ return 0;
+ }
+};
+
#endif
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/PropIDUtils.cpp b/3rdparty/lzma/CPP/7zip/UI/Common/PropIDUtils.cpp
index dccc08b171e..ee9ff323632 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/PropIDUtils.cpp
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/PropIDUtils.cpp
@@ -14,17 +14,23 @@
#include "PropIDUtils.h"
+#ifndef Z7_SFX
#define Get16(x) GetUi16(x)
#define Get32(x) GetUi32(x)
+#endif
using namespace NWindows;
-static const char g_WinAttribChars[16 + 1] = "RHS8DAdNTsLCOnE_";
+static const unsigned kNumWinAtrribFlags = 21;
+static const char g_WinAttribChars[kNumWinAtrribFlags + 1] = "RHS8DAdNTsLCOIEV.X.PU";
+
/*
+FILE_ATTRIBUTE_
+
0 READONLY
1 HIDDEN
2 SYSTEM
-
+3 (Volume label - obsolete)
4 DIRECTORY
5 ARCHIVE
6 DEVICE
@@ -34,14 +40,21 @@ static const char g_WinAttribChars[16 + 1] = "RHS8DAdNTsLCOnE_";
10 REPARSE_POINT
11 COMPRESSED
12 OFFLINE
-13 NOT_CONTENT_INDEXED
+13 NOT_CONTENT_INDEXED (I - Win10 attrib/Explorer)
14 ENCRYPTED
-
-16 VIRTUAL
+15 INTEGRITY_STREAM (V - ReFS Win8/Win2012)
+16 VIRTUAL (reserved)
+17 NO_SCRUB_DATA (X - ReFS Win8/Win2012 attrib)
+18 RECALL_ON_OPEN or EA
+19 PINNED
+20 UNPINNED
+21 STRICTLY_SEQUENTIAL
+22 RECALL_ON_DATA_ACCESS
*/
+
static const char kPosixTypes[16] = { '0', 'p', 'c', '3', 'd', '5', 'b', '7', '-', '9', 'l', 'B', 's', 'D', 'E', 'F' };
-#define MY_ATTR_CHAR(a, n, c) ((a) & (1 << (n))) ? c : '-';
+#define MY_ATTR_CHAR(a, n, c) (((a) & (1 << (n))) ? c : '-')
static void ConvertPosixAttribToString(char *s, UInt32 a) throw()
{
@@ -52,9 +65,9 @@ static void ConvertPosixAttribToString(char *s, UInt32 a) throw()
s[8 - i] = MY_ATTR_CHAR(a, i + 1, 'w');
s[9 - i] = MY_ATTR_CHAR(a, i + 0, 'x');
}
- if ((a & 0x800) != 0) s[3] = ((a & (1 << 6)) ? 's' : 'S');
- if ((a & 0x400) != 0) s[6] = ((a & (1 << 3)) ? 's' : 'S');
- if ((a & 0x200) != 0) s[9] = ((a & (1 << 0)) ? 't' : 'T');
+ if ((a & 0x800) != 0) s[3] = ((a & (1 << 6)) ? 's' : 'S'); // S_ISUID
+ if ((a & 0x400) != 0) s[6] = ((a & (1 << 3)) ? 's' : 'S'); // S_ISGID
+ if ((a & 0x200) != 0) s[9] = ((a & (1 << 0)) ? 't' : 'T'); // S_ISVTX
s[10] = 0;
a &= ~(UInt32)0xFFFF;
@@ -65,36 +78,95 @@ static void ConvertPosixAttribToString(char *s, UInt32 a) throw()
}
}
+
void ConvertWinAttribToString(char *s, UInt32 wa) throw()
{
- for (int i = 0; i < 16; i++)
- if ((wa & (1 << i)) && i != 7)
- *s++ = g_WinAttribChars[i];
- *s = 0;
+ /*
+ some programs store posix attributes in high 16 bits.
+ p7zip - stores additional 0x8000 flag marker.
+ macos - stores additional 0x4000 flag marker.
+ info-zip - no additional marker.
+ */
+
+ const bool isPosix = ((wa & 0xF0000000) != 0);
+
+ UInt32 posix = 0;
+ if (isPosix)
+ {
+ posix = wa >> 16;
+ wa &= (UInt32)0x3FFF;
+ }
- // we support p7zip trick that stores posix attributes in high 16 bits, and 0x8000 flag
- // we also support ZIP archives created in Unix, that store posix attributes in high 16 bits without 0x8000 flag
+ for (unsigned i = 0; i < kNumWinAtrribFlags; i++)
+ {
+ UInt32 flag = (1 << i);
+ if ((wa & flag) != 0)
+ {
+ char c = g_WinAttribChars[i];
+ if (c != '.')
+ {
+ wa &= ~flag;
+ // if (i != 7) // we can disable N (NORMAL) printing
+ *s++ = c;
+ }
+ }
+ }
- // if (wa & 0x8000)
- if ((wa >> 16) != 0)
+ if (wa != 0)
+ {
+ *s++ = ' ';
+ ConvertUInt32ToHex8Digits(wa, s);
+ s += strlen(s);
+ }
+
+ *s = 0;
+
+ if (isPosix)
{
*s++ = ' ';
- ConvertPosixAttribToString(s, wa >> 16);
+ ConvertPosixAttribToString(s, posix);
}
}
-void ConvertPropertyToShortString(char *dest, const PROPVARIANT &prop, PROPID propID, bool full) throw()
+
+void ConvertPropertyToShortString2(char *dest, const PROPVARIANT &prop, PROPID propID, int level) throw()
{
*dest = 0;
if (prop.vt == VT_FILETIME)
{
- FILETIME localFileTime;
- if ((prop.filetime.dwHighDateTime == 0 &&
- prop.filetime.dwLowDateTime == 0) ||
- !::FileTimeToLocalFileTime(&prop.filetime, &localFileTime))
+ const FILETIME &ft = prop.filetime;
+ unsigned ns100 = 0;
+ int numDigits = kTimestampPrintLevel_NTFS;
+ const unsigned prec = prop.wReserved1;
+ const unsigned ns100_Temp = prop.wReserved2;
+ if (prec != 0
+ && prec <= k_PropVar_TimePrec_1ns
+ && ns100_Temp < 100
+ && prop.wReserved3 == 0)
+ {
+ ns100 = ns100_Temp;
+ if (prec == k_PropVar_TimePrec_Unix ||
+ prec == k_PropVar_TimePrec_DOS)
+ numDigits = 0;
+ else if (prec == k_PropVar_TimePrec_HighPrec)
+ numDigits = 9;
+ else
+ {
+ numDigits = (int)prec - (int)k_PropVar_TimePrec_Base;
+ if (
+ // numDigits < kTimestampPrintLevel_DAY // for debuf
+ numDigits < kTimestampPrintLevel_SEC
+ )
+
+ numDigits = kTimestampPrintLevel_NTFS;
+ }
+ }
+ if (ft.dwHighDateTime == 0 && ft.dwLowDateTime == 0 && ns100 == 0)
return;
- ConvertFileTimeToString(localFileTime, dest, true, full);
+ if (level > numDigits)
+ level = numDigits;
+ ConvertUtcFileTimeToString2(ft, ns100, dest, level);
return;
}
@@ -111,7 +183,7 @@ void ConvertPropertyToShortString(char *dest, const PROPVARIANT &prop, PROPID pr
{
if (prop.vt != VT_UI4)
break;
- UInt32 a = prop.ulVal;
+ const UInt32 a = prop.ulVal;
/*
if ((a & 0x8000) && (a & 0x7FFF) == 0)
@@ -135,7 +207,7 @@ void ConvertPropertyToShortString(char *dest, const PROPVARIANT &prop, PROPID pr
ConvertUInt32ToString((UInt32)(prop.uhVal.QuadPart >> 48), dest);
dest += strlen(dest);
*dest++ = '-';
- UInt64 low = prop.uhVal.QuadPart & (((UInt64)1 << 48) - 1);
+ const UInt64 low = prop.uhVal.QuadPart & (((UInt64)1 << 48) - 1);
ConvertUInt64ToString(low, dest);
return;
}
@@ -153,12 +225,30 @@ void ConvertPropertyToShortString(char *dest, const PROPVARIANT &prop, PROPID pr
ConvertUInt64ToHex(v, dest + 2);
return;
}
+
+ /*
+ case kpidDevice:
+ {
+ UInt64 v = 0;
+ if (prop.vt == VT_UI4)
+ v = prop.ulVal;
+ else if (prop.vt == VT_UI8)
+ v = (UInt64)prop.uhVal.QuadPart;
+ else
+ break;
+ ConvertUInt32ToString(MY_dev_major(v), dest);
+ dest += strlen(dest);
+ *dest++ = ',';
+ ConvertUInt32ToString(MY_dev_minor(v), dest);
+ return;
+ }
+ */
}
ConvertPropVariantToShortString(prop, dest);
}
-void ConvertPropertyToString(UString &dest, const PROPVARIANT &prop, PROPID propID, bool full)
+void ConvertPropertyToString2(UString &dest, const PROPVARIANT &prop, PROPID propID, int level)
{
if (prop.vt == VT_BSTR)
{
@@ -166,22 +256,21 @@ void ConvertPropertyToString(UString &dest, const PROPVARIANT &prop, PROPID prop
return;
}
char temp[64];
- ConvertPropertyToShortString(temp, prop, propID, full);
- dest.SetFromAscii(temp);
+ ConvertPropertyToShortString2(temp, prop, propID, level);
+ dest = temp;
}
+#ifndef Z7_SFX
+
static inline unsigned GetHex(unsigned v)
{
return (v < 10) ? ('0' + v) : ('A' + (v - 10));
}
-#ifndef _SFX
-
static inline void AddHexToString(AString &res, unsigned v)
{
res += (char)GetHex(v >> 4);
res += (char)GetHex(v & 0xF);
- res += ' ';
}
/*
@@ -226,6 +315,14 @@ struct CSecID2Name
const char *sz;
};
+static int FindPairIndex(const CSecID2Name * pairs, unsigned num, UInt32 id)
+{
+ for (unsigned i = 0; i < num; i++)
+ if (pairs[i].n == id)
+ return (int)i;
+ return -1;
+}
+
static const CSecID2Name sid_32_Names[] =
{
{ 544, "Administrators" },
@@ -290,52 +387,52 @@ static void ParseSid(AString &s, const Byte *p, UInt32 lim, UInt32 &sidSize)
s += "ERROR";
return;
}
- UInt32 rev = p[0];
+ const UInt32 rev = p[0];
if (rev != 1)
{
s += "UNSUPPORTED";
return;
}
- UInt32 num = p[1];
+ const UInt32 num = p[1];
if (8 + num * 4 > lim)
{
s += "ERROR";
return;
}
sidSize = 8 + num * 4;
- UInt32 authority = GetBe32(p + 4);
+ const UInt32 authority = GetBe32(p + 4);
if (p[2] == 0 && p[3] == 0 && authority == 5 && num >= 1)
{
- UInt32 v0 = Get32(p + 8);
- if (v0 < ARRAY_SIZE(sidNames))
+ const UInt32 v0 = Get32(p + 8);
+ if (v0 < Z7_ARRAY_SIZE(sidNames))
{
s += sidNames[v0];
return;
}
if (v0 == 32 && num == 2)
{
- UInt32 v1 = Get32(p + 12);
- for (unsigned i = 0; i < ARRAY_SIZE(sid_32_Names); i++)
- if (sid_32_Names[i].n == v1)
- {
- s += sid_32_Names[i].sz;
- return;
- }
+ const UInt32 v1 = Get32(p + 12);
+ const int index = FindPairIndex(sid_32_Names, Z7_ARRAY_SIZE(sid_32_Names), v1);
+ if (index >= 0)
+ {
+ s += sid_32_Names[(unsigned)index].sz;
+ return;
+ }
}
if (v0 == 21 && num == 5)
{
UInt32 v4 = Get32(p + 8 + 4 * 4);
- for (unsigned i = 0; i < ARRAY_SIZE(sid_21_Names); i++)
- if (sid_21_Names[i].n == v4)
- {
- s += sid_21_Names[i].sz;
- return;
- }
+ const int index = FindPairIndex(sid_21_Names, Z7_ARRAY_SIZE(sid_21_Names), v4);
+ if (index >= 0)
+ {
+ s += sid_21_Names[(unsigned)index].sz;
+ return;
+ }
}
if (v0 == 80 && num == 6)
{
- for (unsigned i = 0; i < ARRAY_SIZE(services_to_name); i++)
+ for (unsigned i = 0; i < Z7_ARRAY_SIZE(services_to_name); i++)
{
const CServicesToName &sn = services_to_name[i];
int j;
@@ -349,13 +446,9 @@ static void ParseSid(AString &s, const Byte *p, UInt32 lim, UInt32 &sidSize)
}
}
- char sz[16];
s += "S-1-";
if (p[2] == 0 && p[3] == 0)
- {
- ConvertUInt32ToString(authority, sz);
- s += sz;
- }
+ s.Add_UInt32(authority);
else
{
s += "0x";
@@ -364,9 +457,8 @@ static void ParseSid(AString &s, const Byte *p, UInt32 lim, UInt32 &sidSize)
}
for (UInt32 i = 0; i < num; i++)
{
- s += '-';
- ConvertUInt32ToString(Get32(p + 8 + i * 4), sz);
- s += sz;
+ s.Add_Minus();
+ s.Add_UInt32(Get32(p + 8 + i * 4));
}
}
@@ -381,20 +473,13 @@ static void ParseOwner(AString &s, const Byte *p, UInt32 size, UInt32 pos)
ParseSid(s, p + pos, size - pos, sidSize);
}
-static void AddUInt32ToString(AString &s, UInt32 val)
-{
- char sz[16];
- ConvertUInt32ToString(val, sz);
- s += sz;
-}
-
static void ParseAcl(AString &s, const Byte *p, UInt32 size, const char *strName, UInt32 flags, UInt32 offset)
{
- UInt32 control = Get16(p + 2);
+ const UInt32 control = Get16(p + 2);
if ((flags & control) == 0)
return;
- UInt32 pos = Get32(p + offset);
- s += ' ';
+ const UInt32 pos = Get32(p + offset);
+ s.Add_Space();
s += strName;
if (pos >= size)
return;
@@ -404,8 +489,8 @@ static void ParseAcl(AString &s, const Byte *p, UInt32 size, const char *strName
return;
if (Get16(p) != 2) // revision
return;
- UInt32 num = Get32(p + 4);
- AddUInt32ToString(s, num);
+ const UInt32 num = Get32(p + 4);
+ s.Add_UInt32(num);
/*
UInt32 aclSize = Get16(p + 2);
@@ -428,7 +513,7 @@ static void ParseAcl(AString &s, const Byte *p, UInt32 size, const char *strName
size -= 8;
UInt32 sidSize = 0;
- s += ' ';
+ s.Add_Space();
ParseSid(s, p, size, sidSize);
if (sidSize == 0)
return;
@@ -441,11 +526,16 @@ static void ParseAcl(AString &s, const Byte *p, UInt32 size, const char *strName
*/
}
+/*
#define MY_SE_OWNER_DEFAULTED (0x0001)
#define MY_SE_GROUP_DEFAULTED (0x0002)
+*/
#define MY_SE_DACL_PRESENT (0x0004)
+/*
#define MY_SE_DACL_DEFAULTED (0x0008)
+*/
#define MY_SE_SACL_PRESENT (0x0010)
+/*
#define MY_SE_SACL_DEFAULTED (0x0020)
#define MY_SE_DACL_AUTO_INHERIT_REQ (0x0100)
#define MY_SE_SACL_AUTO_INHERIT_REQ (0x0200)
@@ -455,6 +545,7 @@ static void ParseAcl(AString &s, const Byte *p, UInt32 size, const char *strName
#define MY_SE_SACL_PROTECTED (0x2000)
#define MY_SE_RM_CONTROL_VALID (0x4000)
#define MY_SE_SELF_RELATIVE (0x8000)
+*/
void ConvertNtSecureToString(const Byte *data, UInt32 size, AString &s)
{
@@ -470,12 +561,12 @@ void ConvertNtSecureToString(const Byte *data, UInt32 size, AString &s)
return;
}
ParseOwner(s, data, size, Get32(data + 4));
- s += ' ';
+ s.Add_Space();
ParseOwner(s, data, size, Get32(data + 8));
ParseAcl(s, data, size, "s:", MY_SE_SACL_PRESENT, 12);
ParseAcl(s, data, size, "d:", MY_SE_DACL_PRESENT, 16);
- s += ' ';
- AddUInt32ToString(s, size);
+ s.Add_Space();
+ s.Add_UInt32(size);
// s += '\n';
// s += Data_To_Hex(data, size);
}
@@ -489,26 +580,26 @@ static bool CheckSid(const Byte *data, UInt32 size, UInt32 pos) throw()
size -= pos;
if (size < 8)
return false;
- UInt32 rev = data[pos];
+ const UInt32 rev = data[pos];
if (rev != 1)
return false;
- UInt32 num = data[pos + 1];
+ const UInt32 num = data[pos + 1];
return (8 + num * 4 <= size);
}
static bool CheckAcl(const Byte *p, UInt32 size, UInt32 flags, UInt32 offset) throw()
{
- UInt32 control = Get16(p + 2);
+ const UInt32 control = Get16(p + 2);
if ((flags & control) == 0)
return true;
- UInt32 pos = Get32(p + offset);
+ const UInt32 pos = Get32(p + offset);
if (pos >= size)
return false;
p += pos;
size -= pos;
if (size < 8)
return false;
- UInt32 aclSize = Get16(p + 2);
+ const UInt32 aclSize = Get16(p + 2);
return (aclSize <= size);
}
@@ -529,45 +620,121 @@ bool CheckNtSecure(const Byte *data, UInt32 size) throw()
#endif
+
+
+// IO_REPARSE_TAG_*
+
+static const CSecID2Name k_ReparseTags[] =
+{
+ { 0xA0000003, "MOUNT_POINT" },
+ { 0xC0000004, "HSM" },
+ { 0x80000005, "DRIVE_EXTENDER" },
+ { 0x80000006, "HSM2" },
+ { 0x80000007, "SIS" },
+ { 0x80000008, "WIM" },
+ { 0x80000009, "CSV" },
+ { 0x8000000A, "DFS" },
+ { 0x8000000B, "FILTER_MANAGER" },
+ { 0xA000000C, "SYMLINK" },
+ { 0xA0000010, "IIS_CACHE" },
+ { 0x80000012, "DFSR" },
+ { 0x80000013, "DEDUP" },
+ { 0xC0000014, "APPXSTRM" },
+ { 0x80000014, "NFS" },
+ { 0x80000015, "FILE_PLACEHOLDER" },
+ { 0x80000016, "DFM" },
+ { 0x80000017, "WOF" },
+ { 0x80000018, "WCI" },
+ { 0x8000001B, "APPEXECLINK" },
+ { 0xA000001D, "LX_SYMLINK" },
+ { 0x80000023, "AF_UNIX" },
+ { 0x80000024, "LX_FIFO" },
+ { 0x80000025, "LX_CHR" },
+ { 0x80000026, "LX_BLK" }
+};
+
bool ConvertNtReparseToString(const Byte *data, UInt32 size, UString &s)
{
s.Empty();
NFile::CReparseAttr attr;
+
if (attr.Parse(data, size))
{
- if (!attr.IsSymLink())
- s.AddAscii("Junction: ");
- s += attr.GetPath();
- if (!attr.IsOkNamePair())
+ if (attr.IsSymLink_WSL())
{
- s.AddAscii(" : ");
- s += attr.PrintName;
+ s += "WSL: ";
+ s += attr.GetPath();
}
+ else
+ {
+ if (!attr.IsSymLink_Win())
+ s += "Junction: ";
+ s += attr.GetPath();
+ if (s.IsEmpty())
+ s += "Link: ";
+ if (!attr.IsOkNamePair())
+ {
+ s += " : ";
+ s += attr.PrintName;
+ }
+ }
+ if (attr.MinorError)
+ s += " : MINOR_ERROR";
return true;
+ // s += " "; // for debug
}
if (size < 8)
return false;
- UInt32 tag = Get32(data);
- UInt32 len = Get16(data + 4);
+ const UInt32 tag = Get32(data);
+ const UInt32 len = Get16(data + 4);
if (len + 8 > size)
return false;
if (Get16(data + 6) != 0) // padding
return false;
- char hex[16];
- ConvertUInt32ToHex8Digits(tag, hex);
- s.AddAscii(hex);
- s.Add_Space();
+ /*
+ #define my_IO_REPARSE_TAG_DEDUP (0x80000013L)
+ if (tag == my_IO_REPARSE_TAG_DEDUP)
+ {
+ }
+ */
+
+ {
+ const int index = FindPairIndex(k_ReparseTags, Z7_ARRAY_SIZE(k_ReparseTags), tag);
+ if (index >= 0)
+ s += k_ReparseTags[(unsigned)index].sz;
+ else
+ {
+ s += "REPARSE:";
+ char hex[16];
+ ConvertUInt32ToHex8Digits(tag, hex);
+ s += hex;
+ }
+ }
- data += 8;
+ s += ":";
+ s.Add_UInt32(len);
- for (UInt32 i = 0; i < len; i++)
+ if (len != 0)
{
- unsigned b = ((const Byte *)data)[i];
- s += (wchar_t)GetHex((b >> 4) & 0xF);
- s += (wchar_t)GetHex(b & 0xF);
+ s.Add_Space();
+
+ data += 8;
+
+ for (UInt32 i = 0; i < len; i++)
+ {
+ if (i >= 16)
+ {
+ s += "...";
+ break;
+ }
+ const unsigned b = data[i];
+ s += (char)GetHex((b >> 4) & 0xF);
+ s += (char)GetHex(b & 0xF);
+ }
}
+
return true;
}
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/PropIDUtils.h b/3rdparty/lzma/CPP/7zip/UI/Common/PropIDUtils.h
index 1dea321e9ac..6df1e94c37d 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/PropIDUtils.h
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/PropIDUtils.h
@@ -1,17 +1,17 @@
// PropIDUtils.h
-#ifndef __PROPID_UTILS_H
-#define __PROPID_UTILS_H
+#ifndef ZIP7_INC_PROPID_UTILS_H
+#define ZIP7_INC_PROPID_UTILS_H
#include "../../../Common/MyString.h"
// provide at least 64 bytes for buffer including zero-end
-void ConvertPropertyToShortString(char *dest, const PROPVARIANT &propVariant, PROPID propID, bool full = true) throw();
-void ConvertPropertyToString(UString &dest, const PROPVARIANT &propVariant, PROPID propID, bool full = true);
+void ConvertPropertyToShortString2(char *dest, const PROPVARIANT &propVariant, PROPID propID, int level = 0) throw();
+void ConvertPropertyToString2(UString &dest, const PROPVARIANT &propVariant, PROPID propID, int level = 0);
bool ConvertNtReparseToString(const Byte *data, UInt32 size, UString &s);
void ConvertNtSecureToString(const Byte *data, UInt32 size, AString &s);
-bool CheckNtSecure(const Byte *data, UInt32 size) throw();;
+bool CheckNtSecure(const Byte *data, UInt32 size) throw();
void ConvertWinAttribToString(char *s, UInt32 wa) throw();
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/Property.h b/3rdparty/lzma/CPP/7zip/UI/Common/Property.h
index 8b57a2a648a..04628098916 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/Property.h
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/Property.h
@@ -1,7 +1,7 @@
// Property.h
-#ifndef __7Z_PROPERTY_H
-#define __7Z_PROPERTY_H
+#ifndef ZIP7_INC_7Z_PROPERTY_H
+#define ZIP7_INC_7Z_PROPERTY_H
#include "../../../Common/MyString.h"
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/SetProperties.cpp b/3rdparty/lzma/CPP/7zip/UI/Common/SetProperties.cpp
index c3de5d5a323..5e15d9c09fb 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/SetProperties.cpp
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/SetProperties.cpp
@@ -18,7 +18,7 @@ using namespace NCOM;
static void ParseNumberString(const UString &s, NCOM::CPropVariant &prop)
{
const wchar_t *end;
- UInt64 result = ConvertStringToUInt64(s, &end);
+ const UInt64 result = ConvertStringToUInt64(s, &end);
if (*end != 0 || s.IsEmpty())
prop = s;
else if (result <= (UInt32)0xFFFFFFFF)
@@ -27,18 +27,33 @@ static void ParseNumberString(const UString &s, NCOM::CPropVariant &prop)
prop = result;
}
+
+struct CPropPropetiesVector
+{
+ CPropVariant *values;
+ CPropPropetiesVector(unsigned num)
+ {
+ values = new CPropVariant[num];
+ }
+ ~CPropPropetiesVector()
+ {
+ delete []values;
+ }
+};
+
+
HRESULT SetProperties(IUnknown *unknown, const CObjectVector<CProperty> &properties)
{
if (properties.IsEmpty())
return S_OK;
- CMyComPtr<ISetProperties> setProperties;
- unknown->QueryInterface(IID_ISetProperties, (void **)&setProperties);
+ Z7_DECL_CMyComPtr_QI_FROM(
+ ISetProperties,
+ setProperties, unknown)
if (!setProperties)
return S_OK;
UStringVector realNames;
- CPropVariant *values = new CPropVariant[properties.Size()];
- try
+ CPropPropetiesVector values(properties.Size());
{
unsigned i;
for (i = 0; i < properties.Size(); i++)
@@ -50,7 +65,7 @@ HRESULT SetProperties(IUnknown *unknown, const CObjectVector<CProperty> &propert
{
if (!name.IsEmpty())
{
- wchar_t c = name.Back();
+ const wchar_t c = name.Back();
if (c == L'-')
propVariant = false;
else if (c == L'+')
@@ -62,19 +77,12 @@ HRESULT SetProperties(IUnknown *unknown, const CObjectVector<CProperty> &propert
else
ParseNumberString(property.Value, propVariant);
realNames.Add(name);
- values[i] = propVariant;
+ values.values[i] = propVariant;
}
CRecordVector<const wchar_t *> names;
for (i = 0; i < realNames.Size(); i++)
names.Add((const wchar_t *)realNames[i]);
- RINOK(setProperties->SetProperties(&names.Front(), values, names.Size()));
- }
- catch(...)
- {
- delete []values;
- throw;
+ return setProperties->SetProperties(&names.Front(), values.values, names.Size());
}
- delete []values;
- return S_OK;
}
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/SetProperties.h b/3rdparty/lzma/CPP/7zip/UI/Common/SetProperties.h
index 892f1a21037..0676c45daa8 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/SetProperties.h
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/SetProperties.h
@@ -1,7 +1,7 @@
// SetProperties.h
-#ifndef __SETPROPERTIES_H
-#define __SETPROPERTIES_H
+#ifndef ZIP7_INC_SETPROPERTIES_H
+#define ZIP7_INC_SETPROPERTIES_H
#include "Property.h"
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/SortUtils.h b/3rdparty/lzma/CPP/7zip/UI/Common/SortUtils.h
index 8e42e06827a..07aa24d22e9 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/SortUtils.h
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/SortUtils.h
@@ -1,7 +1,7 @@
// SortUtils.h
-#ifndef __SORT_UTLS_H
-#define __SORT_UTLS_H
+#ifndef ZIP7_INC_SORT_UTLS_H
+#define ZIP7_INC_SORT_UTLS_H
#include "../../../Common/MyString.h"
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/StdAfx.h b/3rdparty/lzma/CPP/7zip/UI/Common/StdAfx.h
index 2854ff3e935..035267ccd02 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/StdAfx.h
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/StdAfx.h
@@ -1,8 +1,11 @@
// StdAfx.h
-#ifndef __STDAFX_H
-#define __STDAFX_H
+#ifndef ZIP7_INC_STDAFX_H
+#define ZIP7_INC_STDAFX_H
+#if defined(_MSC_VER) && _MSC_VER >= 1800
+#pragma warning(disable : 4464) // relative include path contains '..'
+#endif
#include "../../../Common/Common.h"
#endif
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/TempFiles.h b/3rdparty/lzma/CPP/7zip/UI/Common/TempFiles.h
index 4099e655898..dd4ac2038d0 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/TempFiles.h
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/TempFiles.h
@@ -1,7 +1,7 @@
// TempFiles.h
-#ifndef __TEMP_FILES_H
-#define __TEMP_FILES_H
+#ifndef ZIP7_INC_TEMP_FILES_H
+#define ZIP7_INC_TEMP_FILES_H
#include "../../../Common/MyString.h"
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/Update.cpp b/3rdparty/lzma/CPP/7zip/UI/Common/Update.cpp
index 0db4a87f0d4..27625aebbe4 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/Update.cpp
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/Update.cpp
@@ -2,9 +2,10 @@
#include "StdAfx.h"
+// #include <stdio.h>
+
#include "Update.h"
-#include "../../../Common/IntToString.h"
#include "../../../Common/StringConvert.h"
#include "../../../Windows/DLL.h"
@@ -17,6 +18,8 @@
#include "../../Common/FileStreams.h"
#include "../../Common/LimitedStreams.h"
+#include "../../Common/MultiOutStream.h"
+#include "../../Common/StreamUtils.h"
#include "../../Compress/CopyCoder.h"
@@ -30,17 +33,21 @@
#include "TempFiles.h"
#include "UpdateCallback.h"
-static const char *kUpdateIsNotSupoorted =
+static const char * const kUpdateIsNotSupoorted =
"update operations are not supported for this archive";
+static const char * const kUpdateIsNotSupported_MultiVol =
+ "Updating for multivolume archives is not implemented";
+
using namespace NWindows;
using namespace NCOM;
using namespace NFile;
using namespace NDir;
using namespace NName;
-static CFSTR kTempFolderPrefix = FTEXT("7zE");
-
+#ifdef _WIN32
+static CFSTR const kTempFolderPrefix = FTEXT("7zE");
+#endif
void CUpdateErrorInfo::SetFromLastError(const char *message)
{
@@ -55,228 +62,55 @@ HRESULT CUpdateErrorInfo::SetFromLastError(const char *message, const FString &f
return Get_HRESULT_Error();
}
-static bool DeleteEmptyFolderAndEmptySubFolders(const FString &path)
+HRESULT CUpdateErrorInfo::SetFromError_DWORD(const char *message, const FString &fileName, DWORD error)
{
- NFind::CFileInfo fileInfo;
- FString pathPrefix = path + FCHAR_PATH_SEPARATOR;
- {
- NFind::CEnumerator enumerator(pathPrefix + FCHAR_ANY_MASK);
- while (enumerator.Next(fileInfo))
- {
- if (fileInfo.IsDir())
- if (!DeleteEmptyFolderAndEmptySubFolders(pathPrefix + fileInfo.Name))
- return false;
- }
- }
- /*
- // we don't need clear read-only for folders
- if (!MySetFileAttributes(path, 0))
- return false;
- */
- return RemoveDir(path);
+ Message = message;
+ FileNames.Add(fileName);
+ SystemError = error;
+ return Get_HRESULT_Error();
}
using namespace NUpdateArchive;
-class COutMultiVolStream:
- public IOutStream,
- public CMyUnknownImp
+struct CMultiOutStream_Rec
{
- unsigned _streamIndex; // required stream
- UInt64 _offsetPos; // offset from start of _streamIndex index
- UInt64 _absPos;
- UInt64 _length;
-
- struct CAltStreamInfo
- {
- COutFileStream *StreamSpec;
- CMyComPtr<IOutStream> Stream;
- FString Name;
- UInt64 Pos;
- UInt64 RealSize;
- };
- CObjectVector<CAltStreamInfo> Streams;
-public:
- // CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;
- CRecordVector<UInt64> Sizes;
- FString Prefix;
- CTempFiles *TempFiles;
-
- void Init()
- {
- _streamIndex = 0;
- _offsetPos = 0;
- _absPos = 0;
- _length = 0;
- }
-
- bool SetMTime(const FILETIME *mTime);
- HRESULT Close();
-
- UInt64 GetSize() const { return _length; }
-
- MY_UNKNOWN_IMP1(IOutStream)
-
- STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
- STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
- STDMETHOD(SetSize)(UInt64 newSize);
+ CMultiOutStream *Spec;
+ CMyComPtr<IOutStream> Ref;
};
-// static NSynchronization::CCriticalSection g_TempPathsCS;
-
-HRESULT COutMultiVolStream::Close()
+struct CMultiOutStream_Bunch
{
- HRESULT res = S_OK;
- FOR_VECTOR (i, Streams)
- {
- COutFileStream *s = Streams[i].StreamSpec;
- if (s)
- {
- HRESULT res2 = s->Close();
- if (res2 != S_OK)
- res = res2;
- }
- }
- return res;
-}
-
-bool COutMultiVolStream::SetMTime(const FILETIME *mTime)
-{
- bool res = true;
- FOR_VECTOR (i, Streams)
- {
- COutFileStream *s = Streams[i].StreamSpec;
- if (s)
- if (!s->SetMTime(mTime))
- res = false;
- }
- return res;
-}
-
-STDMETHODIMP COutMultiVolStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
-{
- if (processedSize != NULL)
- *processedSize = 0;
- while (size > 0)
+ CObjectVector<CMultiOutStream_Rec> Items;
+
+ HRESULT Destruct()
{
- if (_streamIndex >= Streams.Size())
+ HRESULT hres = S_OK;
+ FOR_VECTOR (i, Items)
{
- CAltStreamInfo altStream;
-
- FChar temp[16];
- ConvertUInt32ToString(_streamIndex + 1, temp);
- FString name = temp;
- while (name.Len() < 3)
- name.InsertAtFront(FTEXT('0'));
- name.Insert(0, Prefix);
- altStream.StreamSpec = new COutFileStream;
- altStream.Stream = altStream.StreamSpec;
- if (!altStream.StreamSpec->Create(name, false))
- return ::GetLastError();
+ CMultiOutStream_Rec &rec = Items[i];
+ if (rec.Ref)
{
- // NSynchronization::CCriticalSectionLock lock(g_TempPathsCS);
- TempFiles->Paths.Add(name);
+ const HRESULT hres2 = rec.Spec->Destruct();
+ if (hres == S_OK)
+ hres = hres2;
}
-
- altStream.Pos = 0;
- altStream.RealSize = 0;
- altStream.Name = name;
- Streams.Add(altStream);
- continue;
}
- CAltStreamInfo &altStream = Streams[_streamIndex];
-
- unsigned index = _streamIndex;
- if (index >= Sizes.Size())
- index = Sizes.Size() - 1;
- UInt64 volSize = Sizes[index];
-
- if (_offsetPos >= volSize)
- {
- _offsetPos -= volSize;
- _streamIndex++;
- continue;
- }
- if (_offsetPos != altStream.Pos)
- {
- // CMyComPtr<IOutStream> outStream;
- // RINOK(altStream.Stream.QueryInterface(IID_IOutStream, &outStream));
- RINOK(altStream.Stream->Seek(_offsetPos, STREAM_SEEK_SET, NULL));
- altStream.Pos = _offsetPos;
- }
-
- UInt32 curSize = (UInt32)MyMin((UInt64)size, volSize - altStream.Pos);
- UInt32 realProcessed;
- RINOK(altStream.Stream->Write(data, curSize, &realProcessed));
- data = (void *)((Byte *)data + realProcessed);
- size -= realProcessed;
- altStream.Pos += realProcessed;
- _offsetPos += realProcessed;
- _absPos += realProcessed;
- if (_absPos > _length)
- _length = _absPos;
- if (_offsetPos > altStream.RealSize)
- altStream.RealSize = _offsetPos;
- if (processedSize != NULL)
- *processedSize += realProcessed;
- if (altStream.Pos == volSize)
- {
- _streamIndex++;
- _offsetPos = 0;
- }
- if (realProcessed == 0 && curSize != 0)
- return E_FAIL;
- break;
+ Items.Clear();
+ return hres;
}
- return S_OK;
-}
-STDMETHODIMP COutMultiVolStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
-{
- if (seekOrigin >= 3)
- return STG_E_INVALIDFUNCTION;
- switch (seekOrigin)
- {
- case STREAM_SEEK_SET: _absPos = offset; break;
- case STREAM_SEEK_CUR: _absPos += offset; break;
- case STREAM_SEEK_END: _absPos = _length + offset; break;
- }
- _offsetPos = _absPos;
- if (newPosition != NULL)
- *newPosition = _absPos;
- _streamIndex = 0;
- return S_OK;
-}
-
-STDMETHODIMP COutMultiVolStream::SetSize(UInt64 newSize)
-{
- unsigned i = 0;
- while (i < Streams.Size())
- {
- CAltStreamInfo &altStream = Streams[i++];
- if ((UInt64)newSize < altStream.RealSize)
- {
- RINOK(altStream.Stream->SetSize(newSize));
- altStream.RealSize = newSize;
- break;
- }
- newSize -= altStream.RealSize;
- }
- while (i < Streams.Size())
+ void DisableDeletion()
{
+ FOR_VECTOR (i, Items)
{
- CAltStreamInfo &altStream = Streams.Back();
- altStream.Stream.Release();
- DeleteFileAlways(altStream.Name);
+ CMultiOutStream_Rec &rec = Items[i];
+ if (rec.Ref)
+ rec.Spec->NeedDelete = false;
}
- Streams.DeleteBack();
}
- _offsetPos = _absPos;
- _streamIndex = 0;
- _length = newSize;
- return S_OK;
-}
+};
+
void CArchivePath::ParseFromPath(const UString &path, EArcNameMode mode)
{
@@ -286,29 +120,27 @@ void CArchivePath::ParseFromPath(const UString &path, EArcNameMode mode)
if (mode == k_ArcNameMode_Add)
return;
- if (mode == k_ArcNameMode_Exact)
- {
- BaseExtension.Empty();
- return;
- }
- int dotPos = Name.ReverseFind_Dot();
- if (dotPos < 0)
- return;
- if ((unsigned)dotPos == Name.Len() - 1)
- {
- Name.DeleteBack();
- BaseExtension.Empty();
- return;
- }
- const UString ext = Name.Ptr(dotPos + 1);
- if (BaseExtension.IsEqualTo_NoCase(ext))
+ if (mode != k_ArcNameMode_Exact)
{
- BaseExtension = ext;
- Name.DeleteFrom(dotPos);
+ int dotPos = Name.ReverseFind_Dot();
+ if (dotPos < 0)
+ return;
+ if ((unsigned)dotPos == Name.Len() - 1)
+ Name.DeleteBack();
+ else
+ {
+ const UString ext = Name.Ptr((unsigned)(dotPos + 1));
+ if (BaseExtension.IsEqualTo_NoCase(ext))
+ {
+ BaseExtension = ext;
+ Name.DeleteFrom((unsigned)dotPos);
+ return;
+ }
+ }
}
- else
- BaseExtension.Empty();
+
+ BaseExtension.Empty();
}
UString CArchivePath::GetFinalPath() const
@@ -316,7 +148,7 @@ UString CArchivePath::GetFinalPath() const
UString path = GetPathWithoutExt();
if (!BaseExtension.IsEmpty())
{
- path += L'.';
+ path.Add_Dot();
path += BaseExtension;
}
return path;
@@ -325,9 +157,10 @@ UString CArchivePath::GetFinalPath() const
UString CArchivePath::GetFinalVolPath() const
{
UString path = GetPathWithoutExt();
+ // if BaseExtension is empty, we must ignore VolExtension also.
if (!BaseExtension.IsEmpty())
{
- path += L'.';
+ path.Add_Dot();
path += VolExtension;
}
return path;
@@ -339,17 +172,17 @@ FString CArchivePath::GetTempPath() const
path += us2fs(Name);
if (!BaseExtension.IsEmpty())
{
- path += FTEXT('.');
+ path.Add_Dot();
path += us2fs(BaseExtension);
}
- path.AddAscii(".tmp");
+ path += ".tmp";
path += TempPostfix;
return path;
}
-static const wchar_t *kDefaultArcType = L"7z";
-static const wchar_t *kDefaultArcExt = L"7z";
-static const char *kSFXExtension =
+static const char * const kDefaultArcType = "7z";
+static const char * const kDefaultArcExt = "7z";
+static const char * const kSFXExtension =
#ifdef _WIN32
"exe";
#else
@@ -391,14 +224,14 @@ bool CUpdateOptions::SetArcPath(const CCodecs *codecs, const UString &arcPath)
}
else
{
- const CArcInfoEx &arcInfo = codecs->Formats[formatIndex];
+ const CArcInfoEx &arcInfo = codecs->Formats[(unsigned)formatIndex];
if (!arcInfo.UpdateEnabled)
return false;
typeExt = arcInfo.GetMainExt();
}
UString ext = typeExt;
if (SfxMode)
- ext.SetFromAscii(kSFXExtension);
+ ext = kSFXExtension;
ArchivePath.BaseExtension = ext;
ArchivePath.VolExtension = typeExt;
ArchivePath.ParseFromPath(arcPath, ArcNameMode);
@@ -412,19 +245,43 @@ bool CUpdateOptions::SetArcPath(const CCodecs *codecs, const UString &arcPath)
return true;
}
-struct CUpdateProduceCallbackImp: public IUpdateProduceCallback
+
+struct CUpdateProduceCallbackImp Z7_final: public IUpdateProduceCallback
{
const CObjectVector<CArcItem> *_arcItems;
+ CDirItemsStat *_stat;
IUpdateCallbackUI *_callback;
- CUpdateProduceCallbackImp(const CObjectVector<CArcItem> *a,
- IUpdateCallbackUI *callback): _arcItems(a), _callback(callback) {}
- virtual HRESULT ShowDeleteFile(unsigned arcIndex);
+ CUpdateProduceCallbackImp(
+ const CObjectVector<CArcItem> *a,
+ CDirItemsStat *stat,
+ IUpdateCallbackUI *callback):
+ _arcItems(a),
+ _stat(stat),
+ _callback(callback) {}
+
+ virtual HRESULT ShowDeleteFile(unsigned arcIndex) Z7_override;
};
+
HRESULT CUpdateProduceCallbackImp::ShowDeleteFile(unsigned arcIndex)
{
const CArcItem &ai = (*_arcItems)[arcIndex];
+ {
+ CDirItemsStat &stat = *_stat;
+ if (ai.IsDir)
+ stat.NumDirs++;
+ else if (ai.IsAltStream)
+ {
+ stat.NumAltStreams++;
+ stat.AltStreamsSize += ai.Size;
+ }
+ else
+ {
+ stat.NumFiles++;
+ stat.FilesSize += ai.Size;
+ }
+ }
return _callback->ShowDeleteFile(ai.Name, ai.IsDir);
}
@@ -485,6 +342,8 @@ bool CRenamePair::GetNewPath(bool isFolder, const UString &src, UString &dest) c
int FindAltStreamColon_in_Path(const wchar_t *path);
#endif
+
+
static HRESULT Compress(
const CUpdateOptions &options,
bool isUpdatingItself,
@@ -497,6 +356,7 @@ static HRESULT Compress(
const CDirItems &dirItems,
const CDirItem *parentDirItem,
CTempFiles &tempFiles,
+ CMultiOutStream_Bunch &multiStreams,
CUpdateErrorInfo &errorInfo,
IUpdateCallbackUI *callback,
CFinishArchiveStat &st)
@@ -516,28 +376,63 @@ static HRESULT Compress(
}
else
{
- RINOK(codecs->CreateOutArchive(formatIndex, outArchive));
+ RINOK(codecs->CreateOutArchive((unsigned)formatIndex, outArchive))
- #ifdef EXTERNAL_CODECS
+ #ifdef Z7_EXTERNAL_CODECS
{
CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;
outArchive.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);
if (setCompressCodecsInfo)
{
- RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecs));
+ RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecs))
}
}
#endif
}
- if (outArchive == 0)
+ if (!outArchive)
throw kUpdateIsNotSupoorted;
-
+
+ // we need to set properties to get fileTimeType.
+ RINOK(SetProperties(outArchive, options.MethodMode.Properties))
+
NFileTimeType::EEnum fileTimeType;
{
+ /*
+ how we compare file_in_archive::MTime with dirItem.MTime
+ for GetUpdatePairInfoList():
+
+ if (kpidMTime is not defined), external MTime of archive is used.
+
+ before 22.00:
+ if (kpidTimeType is defined)
+ {
+ kpidTimeType is used as precision.
+ (kpidTimeType > kDOS) is not allowed.
+ }
+ else GetFileTimeType() value is used as precision.
+
+ 22.00:
+ if (kpidMTime is defined)
+ {
+ if (kpidMTime::precision != 0), then kpidMTime::precision is used as precision.
+ else
+ {
+ if (kpidTimeType is defined), kpidTimeType is used as precision.
+ else GetFileTimeType() value is used as precision.
+ }
+ }
+ else external MTime of archive is used as precision.
+ */
+
UInt32 value;
- RINOK(outArchive->GetFileTimeType(&value));
+ RINOK(outArchive->GetFileTimeType(&value))
+
+ // we support any future fileType here.
+ fileTimeType = (NFileTimeType::EEnum)value;
+ /*
+ old 21.07 code:
switch (value)
{
case NFileTimeType::kWindows:
@@ -548,13 +443,28 @@ static HRESULT Compress(
default:
return E_FAIL;
}
+ */
}
+ // bool noTimestampExpected = false;
{
- const CArcInfoEx &arcInfo = codecs->Formats[formatIndex];
+ const CArcInfoEx &arcInfo = codecs->Formats[(unsigned)formatIndex];
+
+ // if (arcInfo.Flags_KeepName()) noTimestampExpected = true;
+ if (arcInfo.Is_Xz() ||
+ arcInfo.Is_BZip2())
+ {
+ /* 7-zip before 22.00 returns NFileTimeType::kUnix for xz and bzip2,
+ but we want to set timestamp without reduction to unix. */
+ // noTimestampExpected = true;
+ fileTimeType = NFileTimeType::kNotDefined; // it means not defined
+ }
+
if (options.AltStreams.Val && !arcInfo.Flags_AltStreams())
return E_NOTIMPL;
- if (options.NtSecurity.Val && !arcInfo.Flags_NtSecure())
+ if (options.NtSecurity.Val && !arcInfo.Flags_NtSecurity())
+ return E_NOTIMPL;
+ if (options.DeleteAfterCompressing && arcInfo.Flags_HashHandler())
return E_NOTIMPL;
}
@@ -562,6 +472,8 @@ static HRESULT Compress(
UStringVector newNames;
+ CArcToDoStat stat2;
+
if (options.RenamePairs.Size() != 0)
{
FOR_VECTOR (i, arcItems)
@@ -587,7 +499,7 @@ static HRESULT Compress(
int colonPos = FindAltStreamColon_in_Path(ai.Name);
if (colonPos >= 0)
{
- UString mainName = ai.Name.Left(colonPos);
+ UString mainName = ai.Name.Left((unsigned)colonPos);
/*
actually we must improve that code to support cases
with folder renaming like: rn arc dir1\ dir2\
@@ -595,8 +507,8 @@ static HRESULT Compress(
if (rp.GetNewPath(false, mainName, dest))
{
needRename = true;
- dest += L':';
- dest += ai.Name.Ptr(colonPos + 1);
+ dest += ':';
+ dest += ai.Name.Ptr((unsigned)(colonPos + 1));
break;
}
}
@@ -610,8 +522,8 @@ static HRESULT Compress(
if (needRename)
{
up2.NewProps = true;
- RINOK(arc->IsItemAnti(i, up2.IsAnti));
- up2.NewNameIndex = newNames.Add(dest);
+ RINOK(arc->IsItem_Anti(i, up2.IsAnti))
+ up2.NewNameIndex = (int)newNames.Add(dest);
}
updatePairs2.Add(up2);
}
@@ -620,23 +532,97 @@ static HRESULT Compress(
{
CRecordVector<CUpdatePair> updatePairs;
GetUpdatePairInfoList(dirItems, arcItems, fileTimeType, updatePairs); // must be done only once!!!
- CUpdateProduceCallbackImp upCallback(&arcItems, callback);
+ CUpdateProduceCallbackImp upCallback(&arcItems, &stat2.DeleteData, callback);
UpdateProduce(updatePairs, actionSet, updatePairs2, isUpdatingItself ? &upCallback : NULL);
}
{
- UInt32 numItems = 0;
FOR_VECTOR (i, updatePairs2)
- if (updatePairs2[i].NewData)
- numItems++;
- RINOK(callback->SetNumItems(numItems));
+ {
+ const CUpdatePair2 &up = updatePairs2[i];
+
+ // 17.01: anti-item is (up.NewData && (p.UseArcProps in most cases))
+
+ if (up.NewData && !up.UseArcProps)
+ {
+ if (up.ExistOnDisk())
+ {
+ CDirItemsStat2 &stat = stat2.NewData;
+ const CDirItem &di = dirItems.Items[(unsigned)up.DirIndex];
+ if (di.IsDir())
+ {
+ if (up.IsAnti)
+ stat.Anti_NumDirs++;
+ else
+ stat.NumDirs++;
+ }
+ #ifdef _WIN32
+ else if (di.IsAltStream)
+ {
+ if (up.IsAnti)
+ stat.Anti_NumAltStreams++;
+ else
+ {
+ stat.NumAltStreams++;
+ stat.AltStreamsSize += di.Size;
+ }
+ }
+ #endif
+ else
+ {
+ if (up.IsAnti)
+ stat.Anti_NumFiles++;
+ else
+ {
+ stat.NumFiles++;
+ stat.FilesSize += di.Size;
+ }
+ }
+ }
+ }
+ else if (up.ArcIndex >= 0)
+ {
+ CDirItemsStat2 &stat = *(up.NewData ? &stat2.NewData : &stat2.OldData);
+ const CArcItem &ai = arcItems[(unsigned)up.ArcIndex];
+ if (ai.IsDir)
+ {
+ if (up.IsAnti)
+ stat.Anti_NumDirs++;
+ else
+ stat.NumDirs++;
+ }
+ else if (ai.IsAltStream)
+ {
+ if (up.IsAnti)
+ stat.Anti_NumAltStreams++;
+ else
+ {
+ stat.NumAltStreams++;
+ stat.AltStreamsSize += ai.Size;
+ }
+ }
+ else
+ {
+ if (up.IsAnti)
+ stat.Anti_NumFiles++;
+ else
+ {
+ stat.NumFiles++;
+ stat.FilesSize += ai.Size;
+ }
+ }
+ }
+ }
+ RINOK(callback->SetNumItems(stat2))
}
CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback;
CMyComPtr<IArchiveUpdateCallback> updateCallback(updateCallbackSpec);
+ updateCallbackSpec->PreserveATime = options.PreserveATime;
updateCallbackSpec->ShareForWrite = options.OpenShareForWrite;
+ updateCallbackSpec->StopAfterOpenError = options.StopAfterOpenError;
updateCallbackSpec->StdInMode = options.StdInMode;
updateCallbackSpec->Callback = callback;
@@ -652,6 +638,8 @@ static HRESULT Compress(
updateCallbackSpec->StoreNtSecurity = options.NtSecurity.Val;
updateCallbackSpec->StoreHardLinks = options.HardLinks.Val;
updateCallbackSpec->StoreSymLinks = options.SymLinks.Val;
+ updateCallbackSpec->StoreOwnerName = options.StoreOwnerName.Val;
+ updateCallbackSpec->StoreOwnerId = options.StoreOwnerId.Val;
updateCallbackSpec->Arc = arc;
updateCallbackSpec->ArcItems = &arcItems;
@@ -659,9 +647,20 @@ static HRESULT Compress(
updateCallbackSpec->ProcessedItemsStatuses = processedItemsStatuses;
+ {
+ const UString arcPath = archivePath.GetFinalPath();
+ updateCallbackSpec->ArcFileName = ExtractFileNameFromPath(arcPath);
+ }
+
if (options.RenamePairs.Size() != 0)
updateCallbackSpec->NewNames = &newNames;
+ if (options.SetArcMTime)
+ {
+ // updateCallbackSpec->Need_ArcMTime_Report = true;
+ updateCallbackSpec->Need_LatestMTime = true;
+ }
+
CMyComPtr<IOutStream> outSeekStream;
CMyComPtr<ISequentialOutStream> outStream;
@@ -675,7 +674,7 @@ static HRESULT Compress(
COutFileStream *outStreamSpec = NULL;
CStdOutFileStream *stdOutFileStreamSpec = NULL;
- COutMultiVolStream *volStreamSpec = NULL;
+ CMultiOutStream *volStreamSpec = NULL;
if (options.VolumesSizes.Size() == 0)
{
@@ -698,9 +697,8 @@ static HRESULT Compress(
{
if (i > 0)
{
- FChar s[16];
- ConvertUInt32ToString(i, s);
- archivePath.TempPostfix = s;
+ archivePath.TempPostfix.Empty();
+ archivePath.TempPostfix.Add_UInt32(i);
}
realPath = archivePath.GetTempPath();
}
@@ -729,25 +727,26 @@ static HRESULT Compress(
if (arc && arc->GetGlobalOffset() > 0)
return E_NOTIMPL;
- volStreamSpec = new COutMultiVolStream;
+ volStreamSpec = new CMultiOutStream();
outSeekStream = volStreamSpec;
outStream = outSeekStream;
- volStreamSpec->Sizes = options.VolumesSizes;
volStreamSpec->Prefix = us2fs(archivePath.GetFinalVolPath());
- volStreamSpec->Prefix += FTEXT('.');
- volStreamSpec->TempFiles = &tempFiles;
- volStreamSpec->Init();
+ volStreamSpec->Prefix.Add_Dot();
+ volStreamSpec->Init(options.VolumesSizes);
+ {
+ CMultiOutStream_Rec &rec = multiStreams.Items.AddNew();
+ rec.Spec = volStreamSpec;
+ rec.Ref = rec.Spec;
+ }
/*
updateCallbackSpec->VolumesSizes = volumesSizes;
updateCallbackSpec->VolName = archivePath.Prefix + archivePath.Name;
if (!archivePath.VolExtension.IsEmpty())
- updateCallbackSpec->VolExt = UString(L'.') + archivePath.VolExtension;
+ updateCallbackSpec->VolExt = UString('.') + archivePath.VolExtension;
*/
}
- RINOK(SetProperties(outArchive, options.MethodMode.Properties));
-
if (options.SfxMode)
{
CInFileStream *sfxStreamSpec = new CInFileStream;
@@ -763,22 +762,22 @@ static HRESULT Compress(
{
outStreamSpec2 = new COutFileStream;
sfxOutStream = outStreamSpec2;
- FString realPath = us2fs(archivePath.GetFinalPath());
+ const FString realPath = us2fs(archivePath.GetFinalPath());
if (!outStreamSpec2->Create(realPath, false))
return errorInfo.SetFromLastError("cannot open file", realPath);
}
{
UInt64 sfxSize;
- RINOK(sfxStreamSpec->GetSize(&sfxSize));
- RINOK(callback->WriteSfx(fs2us(options.SfxModule), sfxSize));
+ RINOK(sfxStreamSpec->GetSize(&sfxSize))
+ RINOK(callback->WriteSfx(fs2us(options.SfxModule), sfxSize))
}
- RINOK(NCompress::CopyStream(sfxStream, sfxOutStream, NULL));
+ RINOK(NCompress::CopyStream(sfxStream, sfxOutStream, NULL))
if (outStreamSpec2)
{
- RINOK(outStreamSpec2->Close());
+ RINOK(outStreamSpec2->Close())
}
}
@@ -789,8 +788,8 @@ static HRESULT Compress(
else
{
// Int64 globalOffset = arc->GetGlobalOffset();
- RINOK(arc->InStream->Seek(0, STREAM_SEEK_SET, NULL));
- RINOK(NCompress::CopyStream_ExactSize(arc->InStream, outStream, arc->ArcStreamOffset, NULL));
+ RINOK(InStream_SeekToBegin(arc->InStream))
+ RINOK(NCompress::CopyStream_ExactSize(arc->InStream, outStream, arc->ArcStreamOffset, NULL))
if (options.StdOutMode)
tailStream = outStream;
else
@@ -803,10 +802,57 @@ static HRESULT Compress(
}
}
+ CFiTime ft;
+ FiTime_Clear(ft);
+ bool ft_Defined = false;
+ {
+ FOR_VECTOR (i, updatePairs2)
+ {
+ const CUpdatePair2 &pair2 = updatePairs2[i];
+ CFiTime ft2;
+ FiTime_Clear(ft2);
+ bool ft2_Defined = false;
+ /* we use full precision of dirItem, if dirItem is defined
+ and (dirItem will be used or dirItem is sameTime in dir and arc */
+ if (pair2.DirIndex >= 0 &&
+ (pair2.NewProps || pair2.IsSameTime))
+ {
+ ft2 = dirItems.Items[(unsigned)pair2.DirIndex].MTime;
+ ft2_Defined = true;
+ }
+ else if (pair2.UseArcProps && pair2.ArcIndex >= 0)
+ {
+ const CArcItem &arcItem = arcItems[(unsigned)pair2.ArcIndex];
+ if (arcItem.MTime.Def)
+ {
+ arcItem.MTime.Write_To_FiTime(ft2);
+ ft2_Defined = true;
+ }
+ }
+ if (ft2_Defined)
+ {
+ if (!ft_Defined || Compare_FiTime(&ft, &ft2) < 0)
+ {
+ ft = ft2;
+ ft_Defined = true;
+ }
+ }
+ }
+ /*
+ if (fileTimeType != NFileTimeType::kNotDefined)
+ FiTime_Normalize_With_Prec(ft, fileTimeType);
+ */
+ }
+
+ if (volStreamSpec && options.SetArcMTime && ft_Defined)
+ {
+ volStreamSpec->MTime = ft;
+ volStreamSpec->MTime_Defined = true;
+ }
HRESULT result = outArchive->UpdateItems(tailStream, updatePairs2.Size(), updateCallback);
// callback->Finalize();
- RINOK(result);
+ RINOK(result)
if (!updateCallbackSpec->AreAllFilesClosed())
{
@@ -817,29 +863,43 @@ static HRESULT Compress(
if (options.SetArcMTime)
{
- FILETIME ft;
- ft.dwLowDateTime = 0;
- ft.dwHighDateTime = 0;
- FOR_VECTOR (i, updatePairs2)
+ // bool needNormalizeAfterStream;
+ // needParse;
+ /*
+ if (updateCallbackSpec->ArcMTime_WasReported)
{
- CUpdatePair2 &pair2 = updatePairs2[i];
- const FILETIME *ft2 = NULL;
- if (pair2.NewProps && pair2.DirIndex >= 0)
- ft2 = &dirItems.Items[pair2.DirIndex].MTime;
- else if (pair2.UseArcProps && pair2.ArcIndex >= 0)
- ft2 = &arcItems[pair2.ArcIndex].MTime;
- if (ft2)
+ isDefined = updateCallbackSpec->Reported_ArcMTime.Def;
+ if (isDefined)
+ updateCallbackSpec->Reported_ArcMTime.Write_To_FiTime(ft);
+ else
+ fileTimeType = NFileTimeType::kNotDefined;
+ }
+ if (!isDefined)
+ */
+ {
+ if (updateCallbackSpec->LatestMTime_Defined)
{
- if (::CompareFileTime(&ft, ft2) < 0)
- ft = *ft2;
+ // CArcTime at = StreamCallback_ArcMTime;
+ // updateCallbackSpec->StreamCallback_ArcMTime.Write_To_FiTime(ft);
+ // we must normalize with precision from archive;
+ if (!ft_Defined || Compare_FiTime(&ft, &updateCallbackSpec->LatestMTime) < 0)
+ ft = updateCallbackSpec->LatestMTime;
+ ft_Defined = true;
}
+ /*
+ if (fileTimeType != NFileTimeType::kNotDefined)
+ FiTime_Normalize_With_Prec(ft, fileTimeType);
+ */
}
- if (ft.dwLowDateTime != 0 || ft.dwHighDateTime != 0)
+ // if (ft.dwLowDateTime != 0 || ft.dwHighDateTime != 0)
+ if (ft_Defined)
{
+ // we ignore set time errors here.
+ // note that user could move some finished volumes to another folder.
if (outStreamSpec)
outStreamSpec->SetMTime(&ft);
else if (volStreamSpec)
- volStreamSpec->SetMTime(&ft);;
+ volStreamSpec->SetMTime_Final(ft);
}
}
@@ -859,10 +919,43 @@ static HRESULT Compress(
if (outStreamSpec)
result = outStreamSpec->Close();
else if (volStreamSpec)
- result = volStreamSpec->Close();
+ {
+ result = volStreamSpec->FinalFlush_and_CloseFiles(st.NumVolumes);
+ st.IsMultiVolMode = true;
+ }
+
+ RINOK(result)
+
+ if (processedItemsStatuses)
+ {
+ FOR_VECTOR (i, updatePairs2)
+ {
+ const CUpdatePair2 &up = updatePairs2[i];
+ if (up.NewData && up.DirIndex >= 0)
+ {
+ const CDirItem &di = dirItems.Items[(unsigned)up.DirIndex];
+ if (di.AreReparseData() || (!di.IsDir() && di.Size == 0))
+ processedItemsStatuses[(unsigned)up.DirIndex] = 1;
+ }
+ }
+ }
+
return result;
}
+
+
+static bool Censor_AreAllAllowed(const NWildcard::CCensor &censor)
+{
+ if (censor.Pairs.Size() != 1)
+ return false;
+ const NWildcard::CPair &pair = censor.Pairs[0];
+ /* Censor_CheckPath() ignores (CPair::Prefix).
+ So we also ignore (CPair::Prefix) here */
+ // if (!pair.Prefix.IsEmpty()) return false;
+ return pair.Head.AreAllAllowed();
+}
+
bool CensorNode_CheckPath2(const NWildcard::CCensorNode &node, const CReadArcItem &item, bool &include);
static bool Censor_CheckPath(const NWildcard::CCensor &censor, const CReadArcItem &item)
@@ -870,9 +963,13 @@ static bool Censor_CheckPath(const NWildcard::CCensor &censor, const CReadArcIte
bool finded = false;
FOR_VECTOR (i, censor.Pairs)
{
+ /* (CPair::Prefix) in not used for matching items in archive.
+ So we ignore (CPair::Prefix) here */
bool include;
if (CensorNode_CheckPath2(censor.Pairs[i].Head, item, include))
{
+ // Check it and FIXME !!!!
+ // here we can exclude item via some Pair, that is still allowed by another Pair
if (!include)
return false;
finded = true;
@@ -890,16 +987,18 @@ static HRESULT EnumerateInArchiveItems(
arcItems.Clear();
UInt32 numItems;
IInArchive *archive = arc.Archive;
- RINOK(archive->GetNumberOfItems(&numItems));
+ RINOK(archive->GetNumberOfItems(&numItems))
arcItems.ClearAndReserve(numItems);
CReadArcItem item;
+ const bool allFilesAreAllowed = Censor_AreAllAllowed(censor);
+
for (UInt32 i = 0; i < numItems; i++)
{
CArcItem ai;
- RINOK(arc.GetItem(i, item));
+ RINOK(arc.GetItem(i, item))
ai.Name = item.Path;
ai.IsDir = item.IsDir;
ai.IsAltStream =
@@ -913,28 +1012,14 @@ static HRESULT EnumerateInArchiveItems(
if (!storeStreamsMode && ai.IsAltStream)
continue;
*/
- ai.Censored = Censor_CheckPath(censor, item);
+ if (allFilesAreAllowed)
+ ai.Censored = true;
+ else
+ ai.Censored = Censor_CheckPath(censor, item);
- RINOK(arc.GetItemMTime(i, ai.MTime, ai.MTimeDefined));
- RINOK(arc.GetItemSize(i, ai.Size, ai.SizeDefined));
-
- {
- CPropVariant prop;
- RINOK(archive->GetProperty(i, kpidTimeType, &prop));
- if (prop.vt == VT_UI4)
- {
- ai.TimeType = (int)(NFileTimeType::EEnum)prop.ulVal;
- switch (ai.TimeType)
- {
- case NFileTimeType::kWindows:
- case NFileTimeType::kUnix:
- case NFileTimeType::kDOS:
- break;
- default:
- return E_FAIL;
- }
- }
- }
+ // ai.MTime will be set to archive MTime, if not present in archive item
+ RINOK(arc.GetItem_MTime(i, ai.MTime))
+ RINOK(arc.GetItem_Size(i, ai.Size, ai.Size_Defined))
ai.IndexInServer = i;
arcItems.AddInReserved(ai);
@@ -944,39 +1029,72 @@ static HRESULT EnumerateInArchiveItems(
#if defined(_WIN32) && !defined(UNDER_CE)
+#if defined(__MINGW32__) || defined(__MINGW64__)
#include <mapi.h>
-
+#else
+#include <MAPI.h>
#endif
-struct CRefSortPair
-{
- unsigned Len;
- unsigned Index;
-};
+extern "C" {
-#define RINOZ(x) { int __tt = (x); if (__tt != 0) return __tt; }
+#ifdef MAPI_FORCE_UNICODE
-static int CompareRefSortPair(const CRefSortPair *a1, const CRefSortPair *a2, void *)
-{
- RINOZ(-MyCompare(a1->Len, a2->Len));
- return MyCompare(a1->Index, a2->Index);
-}
+#define Z7_WIN_LPMAPISENDMAILW LPMAPISENDMAILW
+#define Z7_WIN_MapiFileDescW MapiFileDescW
+#define Z7_WIN_MapiMessageW MapiMessageW
+#define Z7_WIN_MapiRecipDescW MapiRecipDescW
+
+#else
-static unsigned GetNumSlashes(const FChar *s)
+typedef struct
{
- for (unsigned numSlashes = 0;;)
- {
- FChar c = *s++;
- if (c == 0)
- return numSlashes;
- if (IS_PATH_SEPAR(c))
- numSlashes++;
- }
+ ULONG ulReserved;
+ ULONG ulRecipClass;
+ PWSTR lpszName;
+ PWSTR lpszAddress;
+ ULONG ulEIDSize;
+ PVOID lpEntryID;
+} Z7_WIN_MapiRecipDescW, *Z7_WIN_lpMapiRecipDescW;
+
+typedef struct
+{
+ ULONG ulReserved;
+ ULONG flFlags;
+ ULONG nPosition;
+ PWSTR lpszPathName;
+ PWSTR lpszFileName;
+ PVOID lpFileType;
+} Z7_WIN_MapiFileDescW, *Z7_WIN_lpMapiFileDescW;
+
+typedef struct
+{
+ ULONG ulReserved;
+ PWSTR lpszSubject;
+ PWSTR lpszNoteText;
+ PWSTR lpszMessageType;
+ PWSTR lpszDateReceived;
+ PWSTR lpszConversationID;
+ FLAGS flFlags;
+ Z7_WIN_lpMapiRecipDescW lpOriginator;
+ ULONG nRecipCount;
+ Z7_WIN_lpMapiRecipDescW lpRecips;
+ ULONG nFileCount;
+ Z7_WIN_lpMapiFileDescW lpFiles;
+} Z7_WIN_MapiMessageW, *Z7_WIN_lpMapiMessageW;
+
+typedef ULONG (FAR PASCAL Z7_WIN_MAPISENDMAILW)(
+ LHANDLE lhSession,
+ ULONG_PTR ulUIParam,
+ Z7_WIN_lpMapiMessageW lpMessage,
+ FLAGS flFlags,
+ ULONG ulReserved
+);
+typedef Z7_WIN_MAPISENDMAILW FAR *Z7_WIN_LPMAPISENDMAILW;
+
+#endif // MAPI_FORCE_UNICODE
}
+#endif // _WIN32
-#ifdef _WIN32
-void ConvertToLongNames(NWildcard::CCensor &censor);
-#endif
HRESULT UpdateArchive(
CCodecs *codecs,
@@ -1007,7 +1125,7 @@ HRESULT UpdateArchive(
if (options.Commands.Size() != 1)
return E_NOTIMPL;
const CActionSet &as = options.Commands[0].ActionSet;
- for (int i = 2; i < NPairState::kNumValues; i++)
+ for (unsigned i = 2; i < NPairState::kNumValues; i++)
if (as.StateActions[i] != NPairAction::kCompress)
return E_NOTIMPL;
}
@@ -1025,7 +1143,7 @@ HRESULT UpdateArchive(
if (options.SfxMode)
{
CProperty property;
- property.Name.SetFromAscii("rsfx");
+ property.Name = "rsfx";
options.MethodMode.Properties.Add(property);
if (options.SfxModule.IsEmpty())
{
@@ -1036,7 +1154,7 @@ HRESULT UpdateArchive(
if (options.SfxModule.Find(FCHAR_PATH_SEPARATOR) < 0)
{
const FString fullName = NDLL::GetModuleDirPrefix() + options.SfxModule;
- if (NFind::DoesFileExist(fullName))
+ if (NFind::DoesFileExist_FollowLink(fullName))
{
options.SfxModule = fullName;
found = true;
@@ -1044,7 +1162,7 @@ HRESULT UpdateArchive(
}
if (!found)
{
- if (!NFind::DoesFileExist(options.SfxModule))
+ if (!NFind::DoesFileExist_FollowLink(options.SfxModule))
return errorInfo.SetFromLastError("cannot find specified SFX module", options.SfxModule);
}
}
@@ -1058,7 +1176,14 @@ HRESULT UpdateArchive(
!options.SetArcPath(codecs, cmdArcPath2))
return E_NOTIMPL;
}
- const UString arcPath = options.ArchivePath.GetFinalPath();
+
+ UString arcPath = options.ArchivePath.GetFinalPath();
+
+ if (!options.VolumesSizes.IsEmpty())
+ {
+ arcPath = options.ArchivePath.GetFinalVolPath();
+ arcPath += ".001";
+ }
if (cmdArcPath2.IsEmpty())
{
@@ -1068,10 +1193,10 @@ HRESULT UpdateArchive(
else
{
NFind::CFileInfo fi;
- if (!fi.Find(us2fs(arcPath)))
+ if (!fi.Find_FollowLink(us2fs(arcPath)))
{
if (renameMode)
- throw "can't find archive";;
+ throw "can't find archive";
if (options.MethodMode.Type.FormatIndex < 0)
{
if (!options.SetArcPath(codecs, cmdArcPath2))
@@ -1081,11 +1206,39 @@ HRESULT UpdateArchive(
else
{
if (fi.IsDir())
- throw "there is no such archive";
+ return errorInfo.SetFromError_DWORD("There is a folder with the name of archive",
+ us2fs(arcPath),
+ #ifdef _WIN32
+ ERROR_ACCESS_DENIED
+ #else
+ EISDIR
+ #endif
+ );
+ #ifdef _WIN32
if (fi.IsDevice)
return E_NOTIMPL;
+ #endif
+
+ if (!options.StdOutMode && options.UpdateArchiveItself)
+ if (fi.IsReadOnly())
+ {
+ return errorInfo.SetFromError_DWORD("The file is read-only",
+ us2fs(arcPath),
+ #ifdef _WIN32
+ ERROR_ACCESS_DENIED
+ #else
+ EACCES
+ #endif
+ );
+ }
+
if (options.VolumesSizes.Size() > 0)
+ {
+ errorInfo.FileNames.Add(us2fs(arcPath));
+ // errorInfo.SystemError = (DWORD)E_NOTIMPL;
+ errorInfo.Message = kUpdateIsNotSupported_MultiVol;
return E_NOTIMPL;
+ }
CObjectVector<COpenType> types2;
// change it.
if (options.MethodMode.Type_Defined)
@@ -1094,7 +1247,7 @@ HRESULT UpdateArchive(
CIntVector excl;
COpenOptions op;
- #ifndef _SFX
+ #ifndef Z7_SFX
op.props = &options.MethodMode.Properties;
#endif
op.codecs = codecs;
@@ -1104,7 +1257,7 @@ HRESULT UpdateArchive(
op.stream = NULL;
op.filePath = arcPath;
- RINOK(callback->StartOpenArchive(arcPath));
+ RINOK(callback->StartOpenArchive(arcPath))
HRESULT result = arcLink.Open_Strict(op, openCallback);
@@ -1116,23 +1269,29 @@ HRESULT UpdateArchive(
if (result == S_FALSE)
return E_FAIL;
*/
- RINOK(res2);
- RINOK(result);
+ RINOK(res2)
+ RINOK(result)
if (arcLink.VolumePaths.Size() > 1)
{
- errorInfo.SystemError = (DWORD)E_NOTIMPL;
- errorInfo.Message = "Updating for multivolume archives is not implemented";
+ // errorInfo.SystemError = (DWORD)E_NOTIMPL;
+ errorInfo.Message = kUpdateIsNotSupported_MultiVol;
return E_NOTIMPL;
}
CArc &arc = arcLink.Arcs.Back();
- arc.MTimeDefined = !fi.IsDevice;
- arc.MTime = fi.MTime;
+ arc.MTime.Def =
+ #ifdef _WIN32
+ !fi.IsDevice;
+ #else
+ true;
+ #endif
+ if (arc.MTime.Def)
+ arc.MTime.Set_From_FiTime(fi.MTime);
if (arc.ErrorInfo.ThereIsTail)
{
- errorInfo.SystemError = (DWORD)E_NOTIMPL;
+ // errorInfo.SystemError = (DWORD)E_NOTIMPL;
errorInfo.Message = "There is some data block after the end of the archive";
return E_NOTIMPL;
}
@@ -1147,7 +1306,7 @@ HRESULT UpdateArchive(
if (options.MethodMode.Type.FormatIndex < 0)
{
- options.MethodMode.Type.FormatIndex = codecs->FindFormatForArchiveType(kDefaultArcType);
+ options.MethodMode.Type.FormatIndex = codecs->FindFormatForArchiveType((UString)kDefaultArcType);
if (options.MethodMode.Type.FormatIndex < 0)
return E_NOTIMPL;
}
@@ -1172,10 +1331,11 @@ HRESULT UpdateArchive(
if (options.StdInMode)
{
CDirItem di;
+ di.ClearBase();
di.Name = options.StdInFileName;
di.Size = (UInt64)(Int64)-1;
- di.Attrib = 0;
- NTime::GetCurUtcFileTime(di.MTime);
+ di.SetAsFile();
+ NTime::GetCurUtc_FiTime(di.MTime);
di.CTime = di.ATime = di.MTime;
dirItems.Items.Add(di);
}
@@ -1190,7 +1350,7 @@ HRESULT UpdateArchive(
if (needScanning)
{
- RINOK(callback->StartScanning());
+ RINOK(callback->StartScanning())
dirItems.SymLinks = options.SymLinks.Val;
@@ -1199,10 +1359,18 @@ HRESULT UpdateArchive(
#endif
dirItems.ScanAltStreams = options.AltStreams.Val;
+ dirItems.ExcludeDirItems = censor.ExcludeDirItems;
+ dirItems.ExcludeFileItems = censor.ExcludeFileItems;
+
+ dirItems.ShareForWrite = options.OpenShareForWrite;
+
+ #ifndef _WIN32
+ dirItems.StoreOwnerName = options.StoreOwnerName.Val;
+ #endif
- HRESULT res = EnumerateItems(censor,
+ const HRESULT res = EnumerateItems(censor,
options.PathMode,
- options.AddPathPrefix,
+ UString(), // options.AddPathPrefix,
dirItems);
if (res != S_OK)
@@ -1212,13 +1380,15 @@ HRESULT UpdateArchive(
return res;
}
- RINOK(callback->FinishScanning(dirItems.Stat));
+ RINOK(callback->FinishScanning(dirItems.Stat))
+ // 22.00: we don't need parent folder, if absolute path mode
+ if (options.PathMode != NWildcard::k_AbsPath)
if (censor.Pairs.Size() == 1)
{
NFind::CFileInfo fi;
FString prefix = us2fs(censor.Pairs[0].Prefix);
- prefix += FTEXT('.');
+ prefix.Add_Dot();
// UString prefix = censor.Pairs[0].Prefix;
/*
if (prefix.Back() == WCHAR_PATH_SEPARATOR)
@@ -1229,11 +1399,7 @@ HRESULT UpdateArchive(
if (fi.Find(prefix))
if (fi.IsDir())
{
- parentDirItem.Size = fi.Size;
- parentDirItem.CTime = fi.CTime;
- parentDirItem.ATime = fi.ATime;
- parentDirItem.MTime = fi.MTime;
- parentDirItem.Attrib = fi.Attrib;
+ parentDirItem.Copy_From_FileInfoBase(fi);
parentDirItem_Ptr = &parentDirItem;
int secureIndex = -1;
@@ -1242,8 +1408,6 @@ HRESULT UpdateArchive(
dirItems.AddSecurityItem(prefix, secureIndex);
#endif
parentDirItem.SecureIndex = secureIndex;
-
- parentDirItem_Ptr = &parentDirItem;
}
}
}
@@ -1286,6 +1450,31 @@ HRESULT UpdateArchive(
unsigned ci;
+
+ // self including protection
+ if (options.DeleteAfterCompressing)
+ {
+ for (ci = 0; ci < options.Commands.Size(); ci++)
+ {
+ CArchivePath &ap = options.Commands[ci].ArchivePath;
+ const FString path = us2fs(ap.GetFinalPath());
+ // maybe we must compare absolute paths path here
+ FOR_VECTOR (i, dirItems.Items)
+ {
+ const FString phyPath = dirItems.GetPhyPath(i);
+ if (phyPath == path)
+ {
+ UString s;
+ s = "It is not allowed to include archive to itself";
+ s.Add_LF();
+ s += fs2us(path);
+ throw s;
+ }
+ }
+ }
+ }
+
+
for (ci = 0; ci < options.Commands.Size(); ci++)
{
CArchivePath &ap = options.Commands[ci].ArchivePath;
@@ -1315,7 +1504,7 @@ HRESULT UpdateArchive(
{
RINOK(EnumerateInArchiveItems(
// options.StoreAltStreams,
- censor, arcLink.Arcs.Back(), arcItems));
+ censor, arcLink.Arcs.Back(), arcItems))
}
/*
@@ -1328,14 +1517,16 @@ HRESULT UpdateArchive(
CByteBuffer processedItems;
if (options.DeleteAfterCompressing)
{
- unsigned num = dirItems.Items.Size();
+ const unsigned num = dirItems.Items.Size();
processedItems.Alloc(num);
for (unsigned i = 0; i < num; i++)
processedItems[i] = 0;
}
+ CMultiOutStream_Bunch multiStreams;
+
/*
- #ifndef _NO_CRYPTO
+ #ifndef Z7_NO_CRYPTO
if (arcLink.PasswordWasAsked)
{
// We set password, if open have requested password
@@ -1353,7 +1544,7 @@ HRESULT UpdateArchive(
if (options.StdOutMode)
{
- name.SetFromAscii("stdout");
+ name = "stdout";
isUpdating = thereIsInArchive;
}
else
@@ -1379,18 +1570,22 @@ HRESULT UpdateArchive(
parentDirItem_Ptr,
tempFiles,
- errorInfo, callback, st));
+ multiStreams,
+ errorInfo, callback, st))
- RINOK(callback->FinishArchive(st));
+ RINOK(callback->FinishArchive(st))
}
if (thereIsInArchive)
{
- RINOK(arcLink.Close());
+ RINOK(arcLink.Close())
arcLink.Release();
}
+ multiStreams.DisableDeletion();
+ RINOK(multiStreams.Destruct())
+
tempFiles.Paths.Clear();
if (createTempFile)
{
@@ -1399,9 +1594,13 @@ HRESULT UpdateArchive(
CArchivePath &ap = options.Commands[0].ArchivePath;
const FString &tempPath = ap.GetTempPath();
+ // DWORD attrib = 0;
if (thereIsInArchive)
+ {
+ // attrib = NFind::GetFileAttrib(us2fs(arcPath));
if (!DeleteFileAlways(us2fs(arcPath)))
return errorInfo.SetFromLastError("cannot delete the file", us2fs(arcPath));
+ }
if (!MyMoveFile(tempPath, us2fs(arcPath)))
{
@@ -1409,6 +1608,15 @@ HRESULT UpdateArchive(
errorInfo.FileNames.Add(us2fs(arcPath));
return errorInfo.Get_HRESULT_Error();
}
+
+ /*
+ if (attrib != INVALID_FILE_ATTRIBUTES && (attrib & FILE_ATTRIBUTE_READONLY))
+ {
+ DWORD attrib2 = NFind::GetFileAttrib(us2fs(arcPath));
+ if (attrib2 != INVALID_FILE_ATTRIBUTES)
+ NDir::SetFileAttrib(us2fs(arcPath), attrib2 | FILE_ATTRIBUTE_READONLY);
+ }
+ */
}
catch(...)
{
@@ -1428,6 +1636,19 @@ HRESULT UpdateArchive(
return errorInfo.Get_HRESULT_Error();
}
+ FStringVector fullPaths;
+ unsigned i;
+
+ for (i = 0; i < options.Commands.Size(); i++)
+ {
+ CArchivePath &ap = options.Commands[i].ArchivePath;
+ const FString finalPath = us2fs(ap.GetFinalPath());
+ FString arcPath2;
+ if (!MyGetFullPathName(finalPath, arcPath2))
+ return errorInfo.SetFromLastError("GetFullPathName error", finalPath);
+ fullPaths.Add(arcPath2);
+ }
+
/*
LPMAPISENDDOCUMENTS fnSend = (LPMAPISENDDOCUMENTS)mapiLib.GetProc("MAPISendDocuments");
if (fnSend == 0)
@@ -1436,69 +1657,128 @@ HRESULT UpdateArchive(
return errorInfo.Get_HRESULT_Error();
}
*/
+ const
+ Z7_WIN_LPMAPISENDMAILW sendMailW = Z7_GET_PROC_ADDRESS(
+ Z7_WIN_LPMAPISENDMAILW, mapiLib.Get_HMODULE(),
+ "MAPISendMailW");
+ if (sendMailW)
+ {
+
+ CCurrentDirRestorer curDirRestorer;
+
+ UStringVector paths;
+ UStringVector names;
- LPMAPISENDMAIL sendMail = (LPMAPISENDMAIL)mapiLib.GetProc("MAPISendMail");
- if (sendMail == 0)
+ for (i = 0; i < fullPaths.Size(); i++)
{
- errorInfo.SetFromLastError("7-Zip cannot find MAPISendMail function");
- return errorInfo.Get_HRESULT_Error();;
+ const UString arcPath2 = fs2us(fullPaths[i]);
+ const UString fileName = ExtractFileNameFromPath(arcPath2);
+ paths.Add(arcPath2);
+ names.Add(fileName);
+ // Warning!!! MAPISendDocuments function changes Current directory
+ // fnSend(0, ";", (LPSTR)(LPCSTR)path, (LPSTR)(LPCSTR)name, 0);
}
- FStringVector fullPaths;
- unsigned i;
+ CRecordVector<Z7_WIN_MapiFileDescW> files;
+ files.ClearAndSetSize(paths.Size());
- for (i = 0; i < options.Commands.Size(); i++)
+ for (i = 0; i < paths.Size(); i++)
{
- CArchivePath &ap = options.Commands[i].ArchivePath;
- FString finalPath = us2fs(ap.GetFinalPath());
- FString arcPath2;
- if (!MyGetFullPathName(finalPath, arcPath2))
- return errorInfo.SetFromLastError("GetFullPathName error", finalPath);
- fullPaths.Add(arcPath2);
+ Z7_WIN_MapiFileDescW &f = files[i];
+ memset(&f, 0, sizeof(f));
+ f.nPosition = 0xFFFFFFFF;
+ f.lpszPathName = paths[i].Ptr_non_const();
+ f.lpszFileName = names[i].Ptr_non_const();
+ }
+
+ {
+ Z7_WIN_MapiMessageW m;
+ memset(&m, 0, sizeof(m));
+ m.nFileCount = files.Size();
+ m.lpFiles = &files.Front();
+
+ const UString addr (options.EMailAddress);
+ Z7_WIN_MapiRecipDescW rec;
+ if (!addr.IsEmpty())
+ {
+ memset(&rec, 0, sizeof(rec));
+ rec.ulRecipClass = MAPI_TO;
+ rec.lpszAddress = addr.Ptr_non_const();
+ m.nRecipCount = 1;
+ m.lpRecips = &rec;
+ }
+
+ sendMailW((LHANDLE)0, 0, &m, MAPI_DIALOG, 0);
+ }
+ }
+ else
+ {
+ const
+ LPMAPISENDMAIL sendMail = Z7_GET_PROC_ADDRESS(
+ LPMAPISENDMAIL, mapiLib.Get_HMODULE(),
+ "MAPISendMail");
+ if (!sendMail)
+ {
+ errorInfo.SetFromLastError("7-Zip cannot find MAPISendMail function");
+ return errorInfo.Get_HRESULT_Error();
}
CCurrentDirRestorer curDirRestorer;
+
+ AStringVector paths;
+ AStringVector names;
for (i = 0; i < fullPaths.Size(); i++)
{
- UString arcPath2 = fs2us(fullPaths[i]);
- UString fileName = ExtractFileNameFromPath(arcPath2);
- AString path = GetAnsiString(arcPath2);
- AString name = GetAnsiString(fileName);
+ const UString arcPath2 = fs2us(fullPaths[i]);
+ const UString fileName = ExtractFileNameFromPath(arcPath2);
+ paths.Add(GetAnsiString(arcPath2));
+ names.Add(GetAnsiString(fileName));
+ // const AString path (GetAnsiString(arcPath2));
+ // const AString name (GetAnsiString(fileName));
// Warning!!! MAPISendDocuments function changes Current directory
// fnSend(0, ";", (LPSTR)(LPCSTR)path, (LPSTR)(LPCSTR)name, 0);
+ }
- MapiFileDesc f;
+ CRecordVector<MapiFileDesc> files;
+ files.ClearAndSetSize(paths.Size());
+
+ for (i = 0; i < paths.Size(); i++)
+ {
+ MapiFileDesc &f = files[i];
memset(&f, 0, sizeof(f));
f.nPosition = 0xFFFFFFFF;
- f.lpszPathName = (char *)(const char *)path;
- f.lpszFileName = (char *)(const char *)name;
-
+ f.lpszPathName = paths[i].Ptr_non_const();
+ f.lpszFileName = names[i].Ptr_non_const();
+ }
+
+ {
MapiMessage m;
memset(&m, 0, sizeof(m));
- m.nFileCount = 1;
- m.lpFiles = &f;
+ m.nFileCount = files.Size();
+ m.lpFiles = &files.Front();
- const AString addr = GetAnsiString(options.EMailAddress);
+ const AString addr (GetAnsiString(options.EMailAddress));
MapiRecipDesc rec;
if (!addr.IsEmpty())
{
memset(&rec, 0, sizeof(rec));
rec.ulRecipClass = MAPI_TO;
- rec.lpszAddress = (char *)(const char *)addr;
+ rec.lpszAddress = addr.Ptr_non_const();
m.nRecipCount = 1;
m.lpRecips = &rec;
}
sendMail((LHANDLE)0, 0, &m, MAPI_DIALOG, 0);
}
+ }
}
#endif
if (options.DeleteAfterCompressing)
{
- CRecordVector<CRefSortPair> pairs;
+ CRecordVector<CDirPathSortPair> pairs;
FStringVector foldersNames;
unsigned i;
@@ -1506,47 +1786,71 @@ HRESULT UpdateArchive(
for (i = 0; i < dirItems.Items.Size(); i++)
{
const CDirItem &dirItem = dirItems.Items[i];
- FString phyPath = dirItems.GetPhyPath(i);
+ const FString phyPath = dirItems.GetPhyPath(i);
if (dirItem.IsDir())
{
- CRefSortPair pair;
+ CDirPathSortPair pair;
pair.Index = i;
- pair.Len = GetNumSlashes(phyPath);
+ pair.SetNumSlashes(phyPath);
pairs.Add(pair);
}
else
{
- if (processedItems[i] != 0 || dirItem.Size == 0)
+ // 21.04: we have set processedItems[*] before for all required items
+ if (processedItems[i] != 0
+ // || dirItem.Size == 0
+ // || dirItem.AreReparseData()
+ )
{
- RINOK(callback->DeletingAfterArchiving(phyPath, false));
- DeleteFileAlways(phyPath);
+ NFind::CFileInfo fileInfo;
+ /* if (!SymLinks), we follow link here, similar to (dirItem) filling */
+ if (fileInfo.Find(phyPath, !options.SymLinks.Val))
+ {
+ bool is_SameSize = false;
+ if (options.SymLinks.Val && dirItem.AreReparseData())
+ {
+ /* (dirItem.Size = dirItem.ReparseData.Size()) was set before.
+ So we don't compare sizes for that case here */
+ is_SameSize = fileInfo.IsOsSymLink();
+ }
+ else
+ is_SameSize = (fileInfo.Size == dirItem.Size);
+
+ if (is_SameSize
+ && Compare_FiTime(&fileInfo.MTime, &dirItem.MTime) == 0
+ && Compare_FiTime(&fileInfo.CTime, &dirItem.CTime) == 0)
+ {
+ RINOK(callback->DeletingAfterArchiving(phyPath, false))
+ DeleteFileAlways(phyPath);
+ }
+ }
}
else
{
- // file was skipped
+ // file was skipped by some reason. We can throw error for debug:
/*
errorInfo.SystemError = 0;
errorInfo.Message = "file was not processed";
- errorInfo.FileName = phyPath;
+ errorInfo.FileNames.Add(phyPath);
return E_FAIL;
*/
}
}
}
- pairs.Sort(CompareRefSortPair, NULL);
+ pairs.Sort2();
for (i = 0; i < pairs.Size(); i++)
{
- FString phyPath = dirItems.GetPhyPath(pairs[i].Index);
+ const FString phyPath = dirItems.GetPhyPath(pairs[i].Index);
if (NFind::DoesDirExist(phyPath))
{
- RINOK(callback->DeletingAfterArchiving(phyPath, true));
+ RINOK(callback->DeletingAfterArchiving(phyPath, true))
RemoveDir(phyPath);
}
}
- RINOK(callback->FinishDeletingAfterArchiving());
+ RINOK(callback->FinishDeletingAfterArchiving())
}
return S_OK;
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/Update.h b/3rdparty/lzma/CPP/7zip/UI/Common/Update.h
index 0301ae7660e..a9459ffb614 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/Update.h
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/Update.h
@@ -1,7 +1,7 @@
// Update.h
-#ifndef __COMMON_UPDATE_H
-#define __COMMON_UPDATE_H
+#ifndef ZIP7_INC_COMMON_UPDATE_H
+#define ZIP7_INC_COMMON_UPDATE_H
#include "../../../Common/Wildcard.h"
@@ -18,7 +18,7 @@ enum EArcNameMode
{
k_ArcNameMode_Smart,
k_ArcNameMode_Exact,
- k_ArcNameMode_Add,
+ k_ArcNameMode_Add
};
struct CArchivePath
@@ -34,7 +34,7 @@ struct CArchivePath
FString TempPrefix; // path(folder) for temp location
FString TempPostfix;
- CArchivePath(): Temp(false) {};
+ CArchivePath(): Temp(false) {}
void ParseFromPath(const UString &path, EArcNameMode mode);
UString GetPathWithoutExt() const { return Prefix + Name; }
@@ -81,40 +81,46 @@ struct CRenamePair
struct CUpdateOptions
{
- CCompressionMethodMode MethodMode;
-
- CObjectVector<CUpdateArchiveCommand> Commands;
bool UpdateArchiveItself;
- CArchivePath ArchivePath;
- EArcNameMode ArcNameMode;
-
bool SfxMode;
- FString SfxModule;
-
+
+ bool PreserveATime;
bool OpenShareForWrite;
+ bool StopAfterOpenError;
bool StdInMode;
- UString StdInFileName;
bool StdOutMode;
-
+
bool EMailMode;
bool EMailRemoveAfter;
- UString EMailAddress;
- FString WorkingDir;
- NWildcard::ECensorPathMode PathMode;
- UString AddPathPrefix;
+ bool DeleteAfterCompressing;
+ bool SetArcMTime;
CBoolPair NtSecurity;
CBoolPair AltStreams;
CBoolPair HardLinks;
CBoolPair SymLinks;
- bool DeleteAfterCompressing;
+ CBoolPair StoreOwnerId;
+ CBoolPair StoreOwnerName;
- bool SetArcMTime;
+ EArcNameMode ArcNameMode;
+ NWildcard::ECensorPathMode PathMode;
+
+ CCompressionMethodMode MethodMode;
+
+ CObjectVector<CUpdateArchiveCommand> Commands;
+ CArchivePath ArchivePath;
+
+ FString SfxModule;
+ UString StdInFileName;
+ UString EMailAddress;
+ FString WorkingDir;
+ // UString AddPathPrefix;
CObjectVector<CRenamePair> RenamePairs;
+ CRecordVector<UInt64> VolumesSizes;
bool InitFormatIndex(const CCodecs *codecs, const CObjectVector<COpenType> &types, const UString &arcPath);
bool SetArcPath(const CCodecs *codecs, const UString &arcPath);
@@ -122,18 +128,24 @@ struct CUpdateOptions
CUpdateOptions():
UpdateArchiveItself(true),
SfxMode(false),
+
+ PreserveATime(false),
+ OpenShareForWrite(false),
+ StopAfterOpenError(false),
+
StdInMode(false),
StdOutMode(false),
+
EMailMode(false),
EMailRemoveAfter(false),
- OpenShareForWrite(false),
- ArcNameMode(k_ArcNameMode_Smart),
- PathMode(NWildcard::k_RelatPath),
DeleteAfterCompressing(false),
- SetArcMTime(false)
+ SetArcMTime(false),
- {};
+ ArcNameMode(k_ArcNameMode_Smart),
+ PathMode(NWildcard::k_RelatPath)
+
+ {}
void SetActionCommand_Add()
{
@@ -142,13 +154,12 @@ struct CUpdateOptions
c.ActionSet = NUpdateArchive::k_ActionSet_Add;
Commands.Add(c);
}
-
- CRecordVector<UInt64> VolumesSizes;
};
+
struct CUpdateErrorInfo
{
- DWORD SystemError;
+ DWORD SystemError; // it's DWORD (WRes) only;
AString Message;
FStringVector FileNames;
@@ -156,33 +167,42 @@ struct CUpdateErrorInfo
HRESULT Get_HRESULT_Error() const { return SystemError == 0 ? E_FAIL : HRESULT_FROM_WIN32(SystemError); }
void SetFromLastError(const char *message);
HRESULT SetFromLastError(const char *message, const FString &fileName);
+ HRESULT SetFromError_DWORD(const char *message, const FString &fileName, DWORD error);
- CUpdateErrorInfo(): SystemError(0) {};
+ CUpdateErrorInfo(): SystemError(0) {}
};
struct CFinishArchiveStat
{
UInt64 OutArcFileSize;
+ unsigned NumVolumes;
+ bool IsMultiVolMode;
- CFinishArchiveStat(): OutArcFileSize(0) {}
+ CFinishArchiveStat(): OutArcFileSize(0), NumVolumes(0), IsMultiVolMode(false) {}
};
-#define INTERFACE_IUpdateCallbackUI2(x) \
- INTERFACE_IUpdateCallbackUI(x) \
- INTERFACE_IDirItemsCallback(x) \
- virtual HRESULT OpenResult(const CCodecs *codecs, const CArchiveLink &arcLink, const wchar_t *name, HRESULT result) x; \
- virtual HRESULT StartScanning() x; \
- virtual HRESULT FinishScanning(const CDirItemsStat &st) x; \
- virtual HRESULT StartOpenArchive(const wchar_t *name) x; \
- virtual HRESULT StartArchive(const wchar_t *name, bool updating) x; \
- virtual HRESULT FinishArchive(const CFinishArchiveStat &st) x; \
- virtual HRESULT DeletingAfterArchiving(const FString &path, bool isDir) x; \
- virtual HRESULT FinishDeletingAfterArchiving() x; \
-
-struct IUpdateCallbackUI2: public IUpdateCallbackUI, public IDirItemsCallback
+Z7_PURE_INTERFACES_BEGIN
+
+// INTERFACE_IUpdateCallbackUI(x)
+// INTERFACE_IDirItemsCallback(x)
+
+#define Z7_IFACEN_IUpdateCallbackUI2(x) \
+ virtual HRESULT OpenResult(const CCodecs *codecs, const CArchiveLink &arcLink, const wchar_t *name, HRESULT result) x \
+ virtual HRESULT StartScanning() x \
+ virtual HRESULT FinishScanning(const CDirItemsStat &st) x \
+ virtual HRESULT StartOpenArchive(const wchar_t *name) x \
+ virtual HRESULT StartArchive(const wchar_t *name, bool updating) x \
+ virtual HRESULT FinishArchive(const CFinishArchiveStat &st) x \
+ virtual HRESULT DeletingAfterArchiving(const FString &path, bool isDir) x \
+ virtual HRESULT FinishDeletingAfterArchiving() x \
+
+DECLARE_INTERFACE(IUpdateCallbackUI2):
+ public IUpdateCallbackUI,
+ public IDirItemsCallback
{
- INTERFACE_IUpdateCallbackUI2(=0)
+ Z7_IFACE_PURE(IUpdateCallbackUI2)
};
+Z7_PURE_INTERFACES_END
HRESULT UpdateArchive(
CCodecs *codecs,
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/UpdateAction.h b/3rdparty/lzma/CPP/7zip/UI/Common/UpdateAction.h
index bc53fcdbbb1..6a3565e79a6 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/UpdateAction.h
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/UpdateAction.h
@@ -1,7 +1,7 @@
// UpdateAction.h
-#ifndef __UPDATE_ACTION_H
-#define __UPDATE_ACTION_H
+#ifndef ZIP7_INC_UPDATE_ACTION_H
+#define ZIP7_INC_UPDATE_ACTION_H
namespace NUpdateArchive {
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/UpdateCallback.cpp b/3rdparty/lzma/CPP/7zip/UI/Common/UpdateCallback.cpp
index 5499f2a1a9f..5e2860dd08d 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/UpdateCallback.cpp
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/UpdateCallback.cpp
@@ -2,7 +2,28 @@
#include "StdAfx.h"
-#ifndef _7ZIP_ST
+// #include <stdio.h>
+
+#ifndef _WIN32
+// #include <grp.h>
+// #include <pwd.h>
+/*
+inclusion of <sys/sysmacros.h> by <sys/types.h> is deprecated since glibc 2.25.
+Since glibc 2.3.3, macros have been aliases for three GNU-specific
+functions: gnu_dev_makedev(), gnu_dev_major(), and gnu_dev_minor()
+*/
+// for major()/minor():
+#include <sys/types.h>
+#if defined(__FreeBSD__) || defined(BSD) || defined(__APPLE__)
+#else
+#ifndef major
+#include <sys/sysmacros.h>
+#endif
+#endif
+
+#endif // _WIN32
+
+#ifndef Z7_ST
#include "../../../Windows/Synchronization.h"
#endif
@@ -10,6 +31,7 @@
#include "../../../Common/IntToString.h"
#include "../../../Common/StringConvert.h"
#include "../../../Common/Wildcard.h"
+#include "../../../Common/UTFConvert.h"
#include "../../../Windows/FileDir.h"
#include "../../../Windows/FileName.h"
@@ -20,14 +42,14 @@
#include "UpdateCallback.h"
#if defined(_WIN32) && !defined(UNDER_CE)
-#define _USE_SECURITY_CODE
+#define Z7_USE_SECURITY_CODE
#include "../../../Windows/SecurityUtils.h"
#endif
using namespace NWindows;
using namespace NFile;
-#ifndef _7ZIP_ST
+#ifndef Z7_ST
static NSynchronization::CCriticalSection g_CriticalSection;
#define MT_LOCK NSynchronization::CCriticalSectionLock lock(g_CriticalSection);
#else
@@ -35,12 +57,32 @@ static NSynchronization::CCriticalSection g_CriticalSection;
#endif
-#ifdef _USE_SECURITY_CODE
+#ifdef Z7_USE_SECURITY_CODE
bool InitLocalPrivileges();
#endif
CArchiveUpdateCallback::CArchiveUpdateCallback():
- _hardIndex_From((UInt32)(Int32)-1),
+ PreserveATime(false),
+ ShareForWrite(false),
+ StopAfterOpenError(false),
+ StdInMode(false),
+
+ KeepOriginalItemNames(false),
+ StoreNtSecurity(false),
+ StoreHardLinks(false),
+ StoreSymLinks(false),
+
+ #ifndef _WIN32
+ StoreOwnerId(false),
+ StoreOwnerName(false),
+ #endif
+
+ /*
+ , Need_ArcMTime_Report(false),
+ , ArcMTime_WasReported(false),
+ */
+ Need_LatestMTime(false),
+ LatestMTime_Defined(false),
Callback(NULL),
@@ -51,38 +93,33 @@ CArchiveUpdateCallback::CArchiveUpdateCallback():
ArcItems(NULL),
UpdatePairs(NULL),
NewNames(NULL),
+ Comment(NULL),
+ CommentIndex(-1),
- ShareForWrite(false),
- StdInMode(false),
-
- KeepOriginalItemNames(false),
- StoreNtSecurity(false),
- StoreHardLinks(false),
- StoreSymLinks(false),
-
- ProcessedItemsStatuses(NULL)
+ ProcessedItemsStatuses(NULL),
+ _hardIndex_From((UInt32)(Int32)-1)
{
- #ifdef _USE_SECURITY_CODE
+ #ifdef Z7_USE_SECURITY_CODE
_saclEnabled = InitLocalPrivileges();
#endif
}
-STDMETHODIMP CArchiveUpdateCallback::SetTotal(UInt64 size)
+Z7_COM7F_IMF(CArchiveUpdateCallback::SetTotal(UInt64 size))
{
COM_TRY_BEGIN
return Callback->SetTotal(size);
COM_TRY_END
}
-STDMETHODIMP CArchiveUpdateCallback::SetCompleted(const UInt64 *completeValue)
+Z7_COM7F_IMF(CArchiveUpdateCallback::SetCompleted(const UInt64 *completeValue))
{
COM_TRY_BEGIN
return Callback->SetCompleted(completeValue);
COM_TRY_END
}
-STDMETHODIMP CArchiveUpdateCallback::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)
+Z7_COM7F_IMF(CArchiveUpdateCallback::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize))
{
COM_TRY_BEGIN
return Callback->SetRatioInfo(inSize, outSize);
@@ -103,17 +140,17 @@ static const CStatProp kProps[] =
{ NULL, kpidIsAnti, VT_BOOL}
};
-STDMETHODIMP CArchiveUpdateCallback::EnumProperties(IEnumSTATPROPSTG **)
+Z7_COM7F_IMF(CArchiveUpdateCallback::EnumProperties(IEnumSTATPROPSTG **)
{
- return CStatPropEnumerator::CreateEnumerator(kProps, ARRAY_SIZE(kProps), enumerator);
+ return CStatPropEnumerator::CreateEnumerator(kProps, Z7_ARRAY_SIZE(kProps), enumerator);
}
*/
-STDMETHODIMP CArchiveUpdateCallback::GetUpdateItemInfo(UInt32 index,
- Int32 *newData, Int32 *newProps, UInt32 *indexInArchive)
+Z7_COM7F_IMF(CArchiveUpdateCallback::GetUpdateItemInfo(UInt32 index,
+ Int32 *newData, Int32 *newProps, UInt32 *indexInArchive))
{
COM_TRY_BEGIN
- RINOK(Callback->CheckBreak());
+ RINOK(Callback->CheckBreak())
const CUpdatePair2 &up = (*UpdatePairs)[index];
if (newData) *newData = BoolToInt(up.NewData);
if (newProps) *newProps = BoolToInt(up.NewProps);
@@ -121,35 +158,37 @@ STDMETHODIMP CArchiveUpdateCallback::GetUpdateItemInfo(UInt32 index,
{
*indexInArchive = (UInt32)(Int32)-1;
if (up.ExistInArchive())
- *indexInArchive = (ArcItems == 0) ? up.ArcIndex : (*ArcItems)[up.ArcIndex].IndexInServer;
+ *indexInArchive = ArcItems ? (*ArcItems)[(unsigned)up.ArcIndex].IndexInServer : (UInt32)(Int32)up.ArcIndex;
}
return S_OK;
COM_TRY_END
}
-STDMETHODIMP CArchiveUpdateCallback::GetRootProp(PROPID propID, PROPVARIANT *value)
+
+Z7_COM7F_IMF(CArchiveUpdateCallback::GetRootProp(PROPID propID, PROPVARIANT *value))
{
NCOM::CPropVariant prop;
switch (propID)
{
case kpidIsDir: prop = true; break;
- case kpidAttrib: if (ParentDirItem) prop = ParentDirItem->Attrib; break;
- case kpidCTime: if (ParentDirItem) prop = ParentDirItem->CTime; break;
- case kpidATime: if (ParentDirItem) prop = ParentDirItem->ATime; break;
- case kpidMTime: if (ParentDirItem) prop = ParentDirItem->MTime; break;
+ case kpidAttrib: if (ParentDirItem) prop = ParentDirItem->GetWinAttrib(); break;
+ case kpidCTime: if (ParentDirItem) PropVariant_SetFrom_FiTime(prop, ParentDirItem->CTime); break;
+ case kpidATime: if (ParentDirItem) PropVariant_SetFrom_FiTime(prop, ParentDirItem->ATime); break;
+ case kpidMTime: if (ParentDirItem) PropVariant_SetFrom_FiTime(prop, ParentDirItem->MTime); break;
+ case kpidArcFileName: if (!ArcFileName.IsEmpty()) prop = ArcFileName; break;
}
prop.Detach(value);
return S_OK;
}
-STDMETHODIMP CArchiveUpdateCallback::GetParent(UInt32 /* index */, UInt32 *parent, UInt32 *parentType)
+Z7_COM7F_IMF(CArchiveUpdateCallback::GetParent(UInt32 /* index */, UInt32 *parent, UInt32 *parentType))
{
*parentType = NParentType::kDir;
*parent = (UInt32)(Int32)-1;
return S_OK;
}
-STDMETHODIMP CArchiveUpdateCallback::GetNumRawProps(UInt32 *numProps)
+Z7_COM7F_IMF(CArchiveUpdateCallback::GetNumRawProps(UInt32 *numProps))
{
*numProps = 0;
if (StoreNtSecurity)
@@ -157,25 +196,27 @@ STDMETHODIMP CArchiveUpdateCallback::GetNumRawProps(UInt32 *numProps)
return S_OK;
}
-STDMETHODIMP CArchiveUpdateCallback::GetRawPropInfo(UInt32 /* index */, BSTR *name, PROPID *propID)
+Z7_COM7F_IMF(CArchiveUpdateCallback::GetRawPropInfo(UInt32 /* index */, BSTR *name, PROPID *propID))
{
*name = NULL;
*propID = kpidNtSecure;
return S_OK;
}
-STDMETHODIMP CArchiveUpdateCallback::GetRootRawProp(PROPID
- #ifdef _USE_SECURITY_CODE
+Z7_COM7F_IMF(CArchiveUpdateCallback::GetRootRawProp(PROPID
propID
- #endif
- , const void **data, UInt32 *dataSize, UInt32 *propType)
+ , const void **data, UInt32 *dataSize, UInt32 *propType))
{
- *data = 0;
+ #ifndef Z7_USE_SECURITY_CODE
+ UNUSED_VAR(propID)
+ #endif
+
+ *data = NULL;
*dataSize = 0;
*propType = 0;
if (!StoreNtSecurity)
return S_OK;
- #ifdef _USE_SECURITY_CODE
+ #ifdef Z7_USE_SECURITY_CODE
if (propID == kpidNtSecure)
{
if (StdInMode)
@@ -185,7 +226,7 @@ STDMETHODIMP CArchiveUpdateCallback::GetRootRawProp(PROPID
{
if (ParentDirItem->SecureIndex < 0)
return S_OK;
- const CByteBuffer &buf = DirItems->SecureBlocks.Bufs[ParentDirItem->SecureIndex];
+ const CByteBuffer &buf = DirItems->SecureBlocks.Bufs[(unsigned)ParentDirItem->SecureIndex];
*data = buf;
*dataSize = (UInt32)buf.Size();
*propType = NPropDataType::kRaw;
@@ -199,12 +240,10 @@ STDMETHODIMP CArchiveUpdateCallback::GetRootRawProp(PROPID
return S_OK;
}
-// #ifdef _USE_SECURITY_CODE
-// #endif
-STDMETHODIMP CArchiveUpdateCallback::GetRawProp(UInt32 index, PROPID propID, const void **data, UInt32 *dataSize, UInt32 *propType)
+Z7_COM7F_IMF(CArchiveUpdateCallback::GetRawProp(UInt32 index, PROPID propID, const void **data, UInt32 *dataSize, UInt32 *propType))
{
- *data = 0;
+ *data = NULL;
*dataSize = 0;
*propType = 0;
@@ -217,7 +256,7 @@ STDMETHODIMP CArchiveUpdateCallback::GetRawProp(UInt32 index, PROPID propID, con
const CUpdatePair2 &up = (*UpdatePairs)[index];
if (up.UseArcProps && up.ExistInArchive() && Arc->GetRawProps)
return Arc->GetRawProps->GetRawProp(
- ArcItems ? (*ArcItems)[up.ArcIndex].IndexInServer : up.ArcIndex,
+ ArcItems ? (*ArcItems)[(unsigned)up.ArcIndex].IndexInServer : (UInt32)(Int32)up.ArcIndex,
propID, data, dataSize, propType);
{
/*
@@ -227,29 +266,30 @@ STDMETHODIMP CArchiveUpdateCallback::GetRawProp(UInt32 index, PROPID propID, con
if (up.IsAnti)
return S_OK;
- #ifndef UNDER_CE
- const CDirItem &di = DirItems->Items[up.DirIndex];
+ #if defined(_WIN32) && !defined(UNDER_CE)
+ const CDirItem &di = DirItems->Items[(unsigned)up.DirIndex];
#endif
- #ifdef _USE_SECURITY_CODE
+ #ifdef Z7_USE_SECURITY_CODE
if (propID == kpidNtSecure)
{
if (!StoreNtSecurity)
return S_OK;
if (di.SecureIndex < 0)
return S_OK;
- const CByteBuffer &buf = DirItems->SecureBlocks.Bufs[di.SecureIndex];
+ const CByteBuffer &buf = DirItems->SecureBlocks.Bufs[(unsigned)di.SecureIndex];
*data = buf;
*dataSize = (UInt32)buf.Size();
*propType = NPropDataType::kRaw;
}
else
#endif
+ if (propID == kpidNtReparse)
{
- // propID == kpidNtReparse
if (!StoreSymLinks)
return S_OK;
- #ifndef UNDER_CE
+ #if defined(_WIN32) && !defined(UNDER_CE)
+ // we use ReparseData2 instead of ReparseData for WIM format
const CByteBuffer *buf = &di.ReparseData2;
if (buf->Size() == 0)
buf = &di.ReparseData;
@@ -269,7 +309,7 @@ STDMETHODIMP CArchiveUpdateCallback::GetRawProp(UInt32 index, PROPID propID, con
return S_OK;
}
-#ifndef UNDER_CE
+#if defined(_WIN32) && !defined(UNDER_CE)
static UString GetRelativePath(const UString &to, const UString &from)
{
@@ -300,7 +340,7 @@ static UString GetRelativePath(const UString &to, const UString &from)
unsigned k;
for (k = i + 1; k < partsFrom.Size(); k++)
- s += L".." WSTRING_PATH_SEPARATOR;
+ s += ".." STRING_PATH_SEPARATOR;
for (k = i; k < partsTo.Size(); k++)
{
@@ -314,7 +354,7 @@ static UString GetRelativePath(const UString &to, const UString &from)
#endif
-STDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
+Z7_COM7F_IMF(CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value))
{
COM_TRY_BEGIN
const CUpdatePair2 &up = (*UpdatePairs)[index];
@@ -337,21 +377,25 @@ STDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PR
prop.Detach(value);
return S_OK;
}
+
+ #if !defined(UNDER_CE)
+
if (up.DirIndex >= 0)
{
- #ifndef UNDER_CE
- const CDirItem &di = DirItems->Items[up.DirIndex];
+ const CDirItem &di = DirItems->Items[(unsigned)up.DirIndex];
+
+ #ifdef _WIN32
// if (di.IsDir())
{
CReparseAttr attr;
if (attr.Parse(di.ReparseData, di.ReparseData.Size()))
{
- UString simpleName = attr.GetPath();
- if (attr.IsRelative())
+ const UString simpleName = attr.GetPath();
+ if (!attr.IsSymLink_WSL() && attr.IsRelative_Win())
prop = simpleName;
else
{
- const FString phyPath = DirItems->GetPhyPath(up.DirIndex);
+ const FString phyPath = DirItems->GetPhyPath((unsigned)up.DirIndex);
FString fullPath;
if (NDir::MyGetFullPathName(phyPath, fullPath))
{
@@ -362,8 +406,26 @@ STDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PR
return S_OK;
}
}
- #endif
+
+ #else // _WIN32
+
+ if (di.ReparseData.Size() != 0)
+ {
+ AString utf;
+ utf.SetFrom_CalcLen((const char *)(const Byte *)di.ReparseData, (unsigned)di.ReparseData.Size());
+
+ UString us;
+ if (ConvertUTF8ToUnicode(utf, us))
+ {
+ prop = us;
+ prop.Detach(value);
+ return S_OK;
+ }
+ }
+
+ #endif // _WIN32
}
+ #endif // !defined(UNDER_CE)
}
else if (propID == kpidHardLink)
{
@@ -371,7 +433,7 @@ STDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PR
{
const CKeyKeyValPair &pair = _map[_hardIndex_To];
const CUpdatePair2 &up2 = (*UpdatePairs)[pair.Value];
- prop = DirItems->GetLogPath(up2.DirIndex);
+ prop = DirItems->GetLogPath((unsigned)up2.DirIndex);
prop.Detach(value);
return S_OK;
}
@@ -395,30 +457,75 @@ STDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PR
}
}
else if (propID == kpidPath && up.NewNameIndex >= 0)
- prop = (*NewNames)[up.NewNameIndex];
+ prop = (*NewNames)[(unsigned)up.NewNameIndex];
+ else if (propID == kpidComment
+ && CommentIndex >= 0
+ && (unsigned)CommentIndex == index
+ && Comment)
+ prop = *Comment;
else if (propID == kpidShortName && up.NewNameIndex >= 0 && up.IsMainRenameItem)
{
// we can generate new ShortName here;
}
else if ((up.UseArcProps || (KeepOriginalItemNames && (propID == kpidPath || propID == kpidIsAltStream)))
&& up.ExistInArchive() && Archive)
- return Archive->GetProperty(ArcItems ? (*ArcItems)[up.ArcIndex].IndexInServer : up.ArcIndex, propID, value);
+ return Archive->GetProperty(ArcItems ? (*ArcItems)[(unsigned)up.ArcIndex].IndexInServer : (UInt32)(Int32)up.ArcIndex, propID, value);
else if (up.ExistOnDisk())
{
- const CDirItem &di = DirItems->Items[up.DirIndex];
+ const CDirItem &di = DirItems->Items[(unsigned)up.DirIndex];
switch (propID)
{
- case kpidPath: prop = DirItems->GetLogPath(up.DirIndex); break;
+ case kpidPath: prop = DirItems->GetLogPath((unsigned)up.DirIndex); break;
case kpidIsDir: prop = di.IsDir(); break;
- case kpidSize: prop = di.IsDir() ? (UInt64)0 : di.Size; break;
- case kpidAttrib: prop = di.Attrib; break;
- case kpidCTime: prop = di.CTime; break;
- case kpidATime: prop = di.ATime; break;
- case kpidMTime: prop = di.MTime; break;
+ case kpidSize: prop = (UInt64)(di.IsDir() ? (UInt64)0 : di.Size); break;
+ case kpidCTime: PropVariant_SetFrom_FiTime(prop, di.CTime); break;
+ case kpidATime: PropVariant_SetFrom_FiTime(prop, di.ATime); break;
+ case kpidMTime: PropVariant_SetFrom_FiTime(prop, di.MTime); break;
+ case kpidAttrib: prop = (UInt32)di.GetWinAttrib(); break;
+ case kpidPosixAttrib: prop = (UInt32)di.GetPosixAttrib(); break;
+
+ #if defined(_WIN32)
case kpidIsAltStream: prop = di.IsAltStream; break;
- #if defined(_WIN32) && !defined(UNDER_CE)
// case kpidShortName: prop = di.ShortName; break;
- #endif
+ #else
+
+ #if defined(__APPLE__)
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wsign-conversion"
+ #endif
+
+ case kpidDeviceMajor:
+ /*
+ printf("\ndi.mode = %o\n", di.mode);
+ printf("\nst.st_rdev major = %d\n", (unsigned)major(di.rdev));
+ printf("\nst.st_rdev minor = %d\n", (unsigned)minor(di.rdev));
+ */
+ if (S_ISCHR(di.mode) || S_ISBLK(di.mode))
+ prop = (UInt32)major(di.rdev);
+ break;
+
+ case kpidDeviceMinor:
+ if (S_ISCHR(di.mode) || S_ISBLK(di.mode))
+ prop = (UInt32)minor(di.rdev);
+ break;
+
+ #if defined(__APPLE__)
+ #pragma GCC diagnostic pop
+ #endif
+
+ // case kpidDevice: if (S_ISCHR(di.mode) || S_ISBLK(di.mode)) prop = (UInt64)(di.rdev); break;
+
+ case kpidUserId: if (StoreOwnerId) prop = (UInt32)di.uid; break;
+ case kpidGroupId: if (StoreOwnerId) prop = (UInt32)di.gid; break;
+ case kpidUser:
+ if (di.OwnerNameIndex >= 0)
+ prop = DirItems->OwnerNameMap.Strings[(unsigned)di.OwnerNameIndex];
+ break;
+ case kpidGroup:
+ if (di.OwnerGroupIndex >= 0)
+ prop = DirItems->OwnerGroupMap.Strings[(unsigned)di.OwnerGroupIndex];
+ break;
+ #endif
}
}
prop.Detach(value);
@@ -426,11 +533,22 @@ STDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PR
COM_TRY_END
}
-#ifndef _7ZIP_ST
-static NSynchronization::CCriticalSection CS;
+#ifndef Z7_ST
+static NSynchronization::CCriticalSection g_CS;
#endif
-STDMETHODIMP CArchiveUpdateCallback::GetStream2(UInt32 index, ISequentialInStream **inStream, UInt32 mode)
+void CArchiveUpdateCallback::UpdateProcessedItemStatus(unsigned dirIndex)
+{
+ if (ProcessedItemsStatuses)
+ {
+ #ifndef Z7_ST
+ NSynchronization::CCriticalSectionLock lock(g_CS);
+ #endif
+ ProcessedItemsStatuses[dirIndex] = 1;
+ }
+}
+
+Z7_COM7F_IMF(CArchiveUpdateCallback::GetStream2(UInt32 index, ISequentialInStream **inStream, UInt32 mode))
{
COM_TRY_BEGIN
*inStream = NULL;
@@ -438,7 +556,7 @@ STDMETHODIMP CArchiveUpdateCallback::GetStream2(UInt32 index, ISequentialInStrea
if (!up.NewData)
return E_FAIL;
- RINOK(Callback->CheckBreak());
+ RINOK(Callback->CheckBreak())
// RINOK(Callback->Finalize());
bool isDir = IsDir(up);
@@ -447,10 +565,10 @@ STDMETHODIMP CArchiveUpdateCallback::GetStream2(UInt32 index, ISequentialInStrea
{
UString name;
if (up.ArcIndex >= 0)
- name = (*ArcItems)[up.ArcIndex].Name;
+ name = (*ArcItems)[(unsigned)up.ArcIndex].Name;
else if (up.DirIndex >= 0)
- name = DirItems->GetLogPath(up.DirIndex);
- RINOK(Callback->GetStream(name, isDir, true, mode));
+ name = DirItems->GetLogPath((unsigned)up.DirIndex);
+ RINOK(Callback->GetStream(name, isDir, true, mode))
/* 9.33: fixed. Handlers expect real stream object for files, even for anti-file.
so we return empty stream */
@@ -465,7 +583,7 @@ STDMETHODIMP CArchiveUpdateCallback::GetStream2(UInt32 index, ISequentialInStrea
return S_OK;
}
- RINOK(Callback->GetStream(DirItems->GetLogPath(up.DirIndex), isDir, false, mode));
+ RINOK(Callback->GetStream(DirItems->GetLogPath((unsigned)up.DirIndex), isDir, false, mode))
if (isDir)
return S_OK;
@@ -482,32 +600,121 @@ STDMETHODIMP CArchiveUpdateCallback::GetStream2(UInt32 index, ISequentialInStrea
}
else
{
+ #if !defined(UNDER_CE)
+ const CDirItem &di = DirItems->Items[(unsigned)up.DirIndex];
+ if (di.AreReparseData())
+ {
+ /*
+ // we still need DeviceIoControlOut() instead of Read
+ if (!inStreamSpec->File.OpenReparse(path))
+ {
+ return Callback->OpenFileError(path, ::GetLastError());
+ }
+ */
+ // 20.03: we use Reparse Data instead of real data
+
+ CBufInStream *inStreamSpec = new CBufInStream();
+ CMyComPtr<ISequentialInStream> inStreamLoc = inStreamSpec;
+ inStreamSpec->Init(di.ReparseData, di.ReparseData.Size());
+ *inStream = inStreamLoc.Detach();
+
+ UpdateProcessedItemStatus((unsigned)up.DirIndex);
+ return S_OK;
+ }
+ #endif // !defined(UNDER_CE)
+
CInFileStream *inStreamSpec = new CInFileStream;
CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);
+ /*
+ // for debug:
+ #ifdef _WIN32
+ inStreamSpec->StoreOwnerName = true;
+ inStreamSpec->OwnerName = "user_name";
+ inStreamSpec->OwnerName += di.Name;
+ inStreamSpec->OwnerName += "11111111112222222222222333333333333";
+ inStreamSpec->OwnerGroup = "gname_";
+ inStreamSpec->OwnerGroup += inStreamSpec->OwnerName;
+ #endif
+ */
+
+ #ifndef _WIN32
+ inStreamSpec->StoreOwnerId = StoreOwnerId;
+ inStreamSpec->StoreOwnerName = StoreOwnerName;
+
+ // if (StoreOwner)
+ {
+ inStreamSpec->_uid = di.uid;
+ inStreamSpec->_gid = di.gid;
+ if (di.OwnerNameIndex >= 0)
+ inStreamSpec->OwnerName = DirItems->OwnerNameMap.Strings[(unsigned)di.OwnerNameIndex];
+ if (di.OwnerGroupIndex >= 0)
+ inStreamSpec->OwnerGroup = DirItems->OwnerGroupMap.Strings[(unsigned)di.OwnerGroupIndex];
+ }
+ #endif
+
inStreamSpec->SupportHardLinks = StoreHardLinks;
- inStreamSpec->Callback = this;
- inStreamSpec->CallbackRef = index;
+ const bool preserveATime = (PreserveATime
+ || mode == NUpdateNotifyOp::kAnalyze); // 22.00 : we don't change access time in Analyze pass.
+ inStreamSpec->Set_PreserveATime(preserveATime);
- const FString path = DirItems->GetPhyPath(up.DirIndex);
+ const FString path = DirItems->GetPhyPath((unsigned)up.DirIndex);
_openFiles_Indexes.Add(index);
_openFiles_Paths.Add(path);
+ // _openFiles_Streams.Add(inStreamSpec);
- #if defined(_WIN32) && !defined(UNDER_CE)
- if (DirItems->Items[up.DirIndex].AreReparseData())
+ /* 21.02 : we set Callback/CallbackRef after _openFiles_Indexes adding
+ for correct working if exception was raised in GetPhyPath */
+ inStreamSpec->Callback = this;
+ inStreamSpec->CallbackRef = index;
+
+ if (!inStreamSpec->OpenShared(path, ShareForWrite))
{
- if (!inStreamSpec->File.OpenReparse(path))
+ bool isOpen = false;
+ if (preserveATime)
{
- return Callback->OpenFileError(path, ::GetLastError());
+ inStreamSpec->Set_PreserveATime(false);
+ isOpen = inStreamSpec->OpenShared(path, ShareForWrite);
+ }
+ if (!isOpen)
+ {
+ const DWORD error = ::GetLastError();
+ const HRESULT hres = Callback->OpenFileError(path, error);
+ if (hres == S_OK || hres == S_FALSE)
+ if (StopAfterOpenError ||
+ // v23: we check also for some critical errors:
+ #ifdef _WIN32
+ error == ERROR_NO_SYSTEM_RESOURCES
+ #else
+ error == EMFILE
+ #endif
+ )
+ {
+ if (error == 0)
+ return E_FAIL;
+ return HRESULT_FROM_WIN32(error);
+ }
+ return hres;
}
}
- else
- #endif
- if (!inStreamSpec->OpenShared(path, ShareForWrite))
+
+ /*
+ {
+ // for debug:
+ Byte b = 0;
+ UInt32 processedSize = 0;
+ if (inStreamSpec->Read(&b, 1, &processedSize) != S_OK ||
+ processedSize != 1)
+ return E_FAIL;
+ }
+ */
+
+ if (Need_LatestMTime)
{
- return Callback->OpenFileError(path, ::GetLastError());
+ inStreamSpec->ReloadProps();
}
+ // #if defined(Z7_FILE_STREAMS_USE_WIN_FILE) || !defined(_WIN32)
if (StoreHardLinks)
{
CStreamFileProps props;
@@ -519,8 +726,8 @@ STDMETHODIMP CArchiveUpdateCallback::GetStream2(UInt32 index, ISequentialInStrea
pair.Key1 = props.VolID;
pair.Key2 = props.FileID_Low;
pair.Value = index;
- unsigned numItems = _map.Size();
- unsigned pairIndex = _map.AddToUniqueSorted2(pair);
+ const unsigned numItems = _map.Size();
+ const unsigned pairIndex = _map.AddToUniqueSorted2(pair);
if (numItems == _map.Size())
{
// const CKeyKeyValPair &pair2 = _map.Pairs[pairIndex];
@@ -532,14 +739,9 @@ STDMETHODIMP CArchiveUpdateCallback::GetStream2(UInt32 index, ISequentialInStrea
}
}
}
+ // #endif
- if (ProcessedItemsStatuses)
- {
- #ifndef _7ZIP_ST
- NSynchronization::CCriticalSectionLock lock(CS);
- #endif
- ProcessedItemsStatuses[(unsigned)up.DirIndex] = 1;
- }
+ UpdateProcessedItemStatus((unsigned)up.DirIndex);
*inStream = inStreamLoc.Detach();
}
@@ -547,14 +749,14 @@ STDMETHODIMP CArchiveUpdateCallback::GetStream2(UInt32 index, ISequentialInStrea
COM_TRY_END
}
-STDMETHODIMP CArchiveUpdateCallback::SetOperationResult(Int32 opRes)
+Z7_COM7F_IMF(CArchiveUpdateCallback::SetOperationResult(Int32 opRes))
{
COM_TRY_BEGIN
return Callback->SetOperationResult(opRes);
COM_TRY_END
}
-STDMETHODIMP CArchiveUpdateCallback::GetStream(UInt32 index, ISequentialInStream **inStream)
+Z7_COM7F_IMF(CArchiveUpdateCallback::GetStream(UInt32 index, ISequentialInStream **inStream))
{
COM_TRY_BEGIN
return GetStream2(index, inStream,
@@ -564,10 +766,12 @@ STDMETHODIMP CArchiveUpdateCallback::GetStream(UInt32 index, ISequentialInStream
COM_TRY_END
}
-STDMETHODIMP CArchiveUpdateCallback::ReportOperation(UInt32 indexType, UInt32 index, UInt32 op)
+Z7_COM7F_IMF(CArchiveUpdateCallback::ReportOperation(UInt32 indexType, UInt32 index, UInt32 op))
{
COM_TRY_BEGIN
+ // if (op == NUpdateNotifyOp::kOpFinished) return Callback->ReportFinished(indexType, index);
+
bool isDir = false;
if (indexType == NArchive::NEventIndexType::kOutArcIndex)
@@ -578,11 +782,11 @@ STDMETHODIMP CArchiveUpdateCallback::ReportOperation(UInt32 indexType, UInt32 in
const CUpdatePair2 &up = (*UpdatePairs)[index];
if (up.ExistOnDisk())
{
- name = DirItems->GetLogPath(up.DirIndex);
- isDir = DirItems->Items[up.DirIndex].IsDir();
+ name = DirItems->GetLogPath((unsigned)up.DirIndex);
+ isDir = DirItems->Items[(unsigned)up.DirIndex].IsDir();
}
}
- return Callback->ReportUpdateOpeartion(op, name.IsEmpty() ? NULL : name.Ptr(), isDir);
+ return Callback->ReportUpdateOperation(op, name.IsEmpty() ? NULL : name.Ptr(), isDir);
}
wchar_t temp[16];
@@ -601,9 +805,9 @@ STDMETHODIMP CArchiveUpdateCallback::ReportOperation(UInt32 indexType, UInt32 in
}
else if (Arc)
{
- RINOK(Arc->GetItemPath(index, s2));
+ RINOK(Arc->GetItem_Path(index, s2))
s = s2;
- RINOK(Archive_IsItem_Dir(Arc->Archive, index, isDir));
+ RINOK(Archive_IsItem_Dir(Arc->Archive, index, isDir))
}
}
}
@@ -617,12 +821,12 @@ STDMETHODIMP CArchiveUpdateCallback::ReportOperation(UInt32 indexType, UInt32 in
if (!s)
s = L"";
- return Callback->ReportUpdateOpeartion(op, s, isDir);
+ return Callback->ReportUpdateOperation(op, s, isDir);
COM_TRY_END
}
-STDMETHODIMP CArchiveUpdateCallback::ReportExtractResult(UInt32 indexType, UInt32 index, Int32 opRes)
+Z7_COM7F_IMF(CArchiveUpdateCallback::ReportExtractResult(UInt32 indexType, UInt32 index, Int32 opRes))
{
COM_TRY_BEGIN
@@ -656,12 +860,12 @@ STDMETHODIMP CArchiveUpdateCallback::ReportExtractResult(UInt32 indexType, UInt3
s = (*ArcItems)[index].Name;
else if (Arc)
{
- RINOK(Arc->GetItemPath(index, s2));
+ RINOK(Arc->GetItem_Path(index, s2))
s = s2;
}
if (Archive)
{
- RINOK(Archive_GetItemBoolProp(Archive, index, kpidEncrypted, isEncrypted));
+ RINOK(Archive_GetItemBoolProp(Archive, index, kpidEncrypted, isEncrypted))
}
}
}
@@ -677,7 +881,52 @@ STDMETHODIMP CArchiveUpdateCallback::ReportExtractResult(UInt32 indexType, UInt3
COM_TRY_END
}
-STDMETHODIMP CArchiveUpdateCallback::GetVolumeSize(UInt32 index, UInt64 *size)
+
+/*
+Z7_COM7F_IMF(CArchiveUpdateCallback::DoNeedArcProp(PROPID propID, Int32 *answer))
+{
+ *answer = 0;
+ if (Need_ArcMTime_Report && propID == kpidComboMTime)
+ *answer = 1;
+ return S_OK;
+}
+
+Z7_COM7F_IMF(CArchiveUpdateCallback::ReportProp(UInt32 indexType, UInt32 index, PROPID propID, const PROPVARIANT *value))
+{
+ if (indexType == NArchive::NEventIndexType::kArcProp)
+ {
+ if (propID == kpidComboMTime)
+ {
+ ArcMTime_WasReported = true;
+ if (value->vt == VT_FILETIME)
+ {
+ Reported_ArcMTime.Set_From_Prop(*value);
+ Reported_ArcMTime.Def = true;
+ }
+ else
+ {
+ Reported_ArcMTime.Clear();
+ if (value->vt != VT_EMPTY)
+ return E_FAIL; // for debug
+ }
+ }
+ }
+ return Callback->ReportProp(indexType, index, propID, value);
+}
+
+Z7_COM7F_IMF(CArchiveUpdateCallback::ReportRawProp(UInt32 indexType, UInt32 index,
+ PROPID propID, const void *data, UInt32 dataSize, UInt32 propType))
+{
+ return Callback->ReportRawProp(indexType, index, propID, data, dataSize, propType);
+}
+
+Z7_COM7F_IMF(CArchiveUpdateCallback::ReportFinished(UInt32 indexType, UInt32 index, Int32 opRes))
+{
+ return Callback->ReportFinished(indexType, index, opRes);
+}
+*/
+
+Z7_COM7F_IMF(CArchiveUpdateCallback::GetVolumeSize(UInt32 index, UInt64 *size))
{
if (VolumesSizes.Size() == 0)
return S_FALSE;
@@ -687,35 +936,35 @@ STDMETHODIMP CArchiveUpdateCallback::GetVolumeSize(UInt32 index, UInt64 *size)
return S_OK;
}
-STDMETHODIMP CArchiveUpdateCallback::GetVolumeStream(UInt32 index, ISequentialOutStream **volumeStream)
+Z7_COM7F_IMF(CArchiveUpdateCallback::GetVolumeStream(UInt32 index, ISequentialOutStream **volumeStream))
{
COM_TRY_BEGIN
- FChar temp[16];
+ char temp[16];
ConvertUInt32ToString(index + 1, temp);
- FString res = temp;
+ FString res (temp);
while (res.Len() < 2)
res.InsertAtFront(FTEXT('0'));
FString fileName = VolName;
- fileName += FTEXT('.');
+ fileName.Add_Dot();
fileName += res;
fileName += VolExt;
COutFileStream *streamSpec = new COutFileStream;
CMyComPtr<ISequentialOutStream> streamLoc(streamSpec);
if (!streamSpec->Create(fileName, false))
- return ::GetLastError();
+ return GetLastError_noZero_HRESULT();
*volumeStream = streamLoc.Detach();
return S_OK;
COM_TRY_END
}
-STDMETHODIMP CArchiveUpdateCallback::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password)
+Z7_COM7F_IMF(CArchiveUpdateCallback::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password))
{
COM_TRY_BEGIN
return Callback->CryptoGetTextPassword2(passwordIsDefined, password);
COM_TRY_END
}
-STDMETHODIMP CArchiveUpdateCallback::CryptoGetTextPassword(BSTR *password)
+Z7_COM7F_IMF(CArchiveUpdateCallback::CryptoGetTextPassword(BSTR *password))
{
COM_TRY_BEGIN
return Callback->CryptoGetTextPassword(password);
@@ -724,15 +973,18 @@ STDMETHODIMP CArchiveUpdateCallback::CryptoGetTextPassword(BSTR *password)
HRESULT CArchiveUpdateCallback::InFileStream_On_Error(UINT_PTR val, DWORD error)
{
- if (error == ERROR_LOCK_VIOLATION)
+ #ifdef _WIN32 // FIX IT !!!
+ // why did we check only for ERROR_LOCK_VIOLATION ?
+ // if (error == ERROR_LOCK_VIOLATION)
+ #endif
{
MT_LOCK
- UInt32 index = (UInt32)val;
+ const UInt32 index = (UInt32)val;
FOR_VECTOR(i, _openFiles_Indexes)
{
if (_openFiles_Indexes[i] == index)
{
- RINOK(Callback->ReadingFileError(_openFiles_Paths[i], error));
+ RINOK(Callback->ReadingFileError(_openFiles_Paths[i], error))
break;
}
}
@@ -740,18 +992,35 @@ HRESULT CArchiveUpdateCallback::InFileStream_On_Error(UINT_PTR val, DWORD error)
return HRESULT_FROM_WIN32(error);
}
-void CArchiveUpdateCallback::InFileStream_On_Destroy(UINT_PTR val)
+void CArchiveUpdateCallback::InFileStream_On_Destroy(CInFileStream *stream, UINT_PTR val)
{
MT_LOCK
- UInt32 index = (UInt32)val;
+ if (Need_LatestMTime)
+ {
+ if (stream->_info_WasLoaded)
+ {
+ const CFiTime &ft = ST_MTIME(stream->_info);
+ if (!LatestMTime_Defined
+ || Compare_FiTime(&LatestMTime, &ft) < 0)
+ LatestMTime = ft;
+ LatestMTime_Defined = true;
+ }
+ }
+ const UInt32 index = (UInt32)val;
FOR_VECTOR(i, _openFiles_Indexes)
{
if (_openFiles_Indexes[i] == index)
{
_openFiles_Indexes.Delete(i);
_openFiles_Paths.Delete(i);
+ // _openFiles_Streams.Delete(i);
return;
}
}
- throw 20141125;
+ /* 21.02 : this function can be called in destructor.
+ And destructor can be called after some exception.
+ If we don't want to throw exception in desctructors or after another exceptions,
+ we must disable the code below that raises new exception.
+ */
+ // throw 20141125;
}
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/UpdateCallback.h b/3rdparty/lzma/CPP/7zip/UI/Common/UpdateCallback.h
index 4ff4a7ebe1d..379b8146293 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/UpdateCallback.h
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/UpdateCallback.h
@@ -1,7 +1,7 @@
// UpdateCallback.h
-#ifndef __UPDATE_CALLBACK_H
-#define __UPDATE_CALLBACK_H
+#ifndef ZIP7_INC_UPDATE_CALLBACK_H
+#define ZIP7_INC_UPDATE_CALLBACK_H
#include "../../../Common/MyCom.h"
@@ -15,31 +15,51 @@
#include "OpenArchive.h"
-#define INTERFACE_IUpdateCallbackUI(x) \
- virtual HRESULT WriteSfx(const wchar_t *name, UInt64 size) x; \
- virtual HRESULT SetTotal(UInt64 size) x; \
- virtual HRESULT SetCompleted(const UInt64 *completeValue) x; \
- virtual HRESULT SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize) x; \
- virtual HRESULT CheckBreak() x; \
- /* virtual HRESULT Finalize() x; */ \
- virtual HRESULT SetNumItems(UInt64 numItems) x; \
- virtual HRESULT GetStream(const wchar_t *name, bool isDir, bool isAnti, UInt32 mode) x; \
- virtual HRESULT OpenFileError(const FString &path, DWORD systemError) x; \
- virtual HRESULT ReadingFileError(const FString &path, DWORD systemError) x; \
- virtual HRESULT SetOperationResult(Int32 opRes) x; \
- virtual HRESULT ReportExtractResult(Int32 opRes, Int32 isEncrypted, const wchar_t *name) x; \
- virtual HRESULT ReportUpdateOpeartion(UInt32 op, const wchar_t *name, bool isDir) x; \
- /* virtual HRESULT SetPassword(const UString &password) x; */ \
- virtual HRESULT CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password) x; \
- virtual HRESULT CryptoGetTextPassword(BSTR *password) x; \
- virtual HRESULT ShowDeleteFile(const wchar_t *name, bool isDir) x; \
- /* virtual HRESULT CloseProgress() { return S_OK; } */
-
-struct IUpdateCallbackUI
+struct CArcToDoStat
{
- INTERFACE_IUpdateCallbackUI(=0)
+ CDirItemsStat2 NewData;
+ CDirItemsStat2 OldData;
+ CDirItemsStat2 DeleteData;
+
+ UInt64 Get_NumDataItems_Total() const
+ {
+ return NewData.Get_NumDataItems2() + OldData.Get_NumDataItems2();
+ }
};
+
+Z7_PURE_INTERFACES_BEGIN
+
+#define Z7_IFACEN_IUpdateCallbackUI(x) \
+ virtual HRESULT WriteSfx(const wchar_t *name, UInt64 size) x \
+ virtual HRESULT SetTotal(UInt64 size) x \
+ virtual HRESULT SetCompleted(const UInt64 *completeValue) x \
+ virtual HRESULT SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize) x \
+ virtual HRESULT CheckBreak() x \
+ /* virtual HRESULT Finalize() x */ \
+ virtual HRESULT SetNumItems(const CArcToDoStat &stat) x \
+ virtual HRESULT GetStream(const wchar_t *name, bool isDir, bool isAnti, UInt32 mode) x \
+ virtual HRESULT OpenFileError(const FString &path, DWORD systemError) x \
+ virtual HRESULT ReadingFileError(const FString &path, DWORD systemError) x \
+ virtual HRESULT SetOperationResult(Int32 opRes) x \
+ virtual HRESULT ReportExtractResult(Int32 opRes, Int32 isEncrypted, const wchar_t *name) x \
+ virtual HRESULT ReportUpdateOperation(UInt32 op, const wchar_t *name, bool isDir) x \
+ /* virtual HRESULT SetPassword(const UString &password) x */ \
+ virtual HRESULT CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password) x \
+ virtual HRESULT CryptoGetTextPassword(BSTR *password) x \
+ virtual HRESULT ShowDeleteFile(const wchar_t *name, bool isDir) x \
+
+ /*
+ virtual HRESULT ReportProp(UInt32 indexType, UInt32 index, PROPID propID, const PROPVARIANT *value) x \
+ virtual HRESULT ReportRawProp(UInt32 indexType, UInt32 index, PROPID propID, const void *data, UInt32 dataSize, UInt32 propType) x \
+ virtual HRESULT ReportFinished(UInt32 indexType, UInt32 index, Int32 opRes) x \
+ */
+
+ /* virtual HRESULT CloseProgress() { return S_OK; } */
+
+Z7_IFACE_DECL_PURE(IUpdateCallbackUI)
+Z7_PURE_INTERFACES_END
+
struct CKeyKeyValPair
{
UInt64 Key1;
@@ -55,10 +75,11 @@ struct CKeyKeyValPair
};
-class CArchiveUpdateCallback:
+class CArchiveUpdateCallback Z7_final:
public IArchiveUpdateCallback2,
public IArchiveUpdateCallbackFile,
- public IArchiveExtractCallbackMessage,
+ // public IArchiveUpdateCallbackArcProp,
+ public IArchiveExtractCallbackMessage2,
public IArchiveGetRawProps,
public IArchiveGetRootProps,
public ICryptoGetTextPassword2,
@@ -67,48 +88,63 @@ class CArchiveUpdateCallback:
public IInFileStream_Callback,
public CMyUnknownImp
{
- #if defined(_WIN32) && !defined(UNDER_CE)
- bool _saclEnabled;
- #endif
- CRecordVector<CKeyKeyValPair> _map;
-
- UInt32 _hardIndex_From;
- UInt32 _hardIndex_To;
+ Z7_COM_QI_BEGIN2(IArchiveUpdateCallback2)
+ Z7_COM_QI_ENTRY(IArchiveUpdateCallbackFile)
+ // Z7_COM_QI_ENTRY(IArchiveUpdateCallbackArcProp)
+ Z7_COM_QI_ENTRY(IArchiveExtractCallbackMessage2)
+ Z7_COM_QI_ENTRY(IArchiveGetRawProps)
+ Z7_COM_QI_ENTRY(IArchiveGetRootProps)
+ Z7_COM_QI_ENTRY(ICryptoGetTextPassword2)
+ Z7_COM_QI_ENTRY(ICryptoGetTextPassword)
+ Z7_COM_QI_ENTRY(ICompressProgressInfo)
+ Z7_COM_QI_END
+ Z7_COM_ADDREF_RELEASE
+
+ Z7_IFACE_COM7_IMP(ICompressProgressInfo)
+
+ Z7_IFACE_COM7_IMP(IProgress)
+ Z7_IFACE_COM7_IMP(IArchiveUpdateCallback)
+ Z7_IFACE_COM7_IMP(IArchiveUpdateCallback2)
+ Z7_IFACE_COM7_IMP(IArchiveUpdateCallbackFile)
+ // Z7_IFACE_COM7_IMP(IArchiveUpdateCallbackArcProp)
+ Z7_IFACE_COM7_IMP(IArchiveExtractCallbackMessage2)
+ Z7_IFACE_COM7_IMP(IArchiveGetRawProps)
+ Z7_IFACE_COM7_IMP(IArchiveGetRootProps)
+ Z7_IFACE_COM7_IMP(ICryptoGetTextPassword2)
+ Z7_IFACE_COM7_IMP(ICryptoGetTextPassword)
+
+
+ void UpdateProcessedItemStatus(unsigned dirIndex);
public:
- MY_QUERYINTERFACE_BEGIN2(IArchiveUpdateCallback2)
- MY_QUERYINTERFACE_ENTRY(IArchiveUpdateCallbackFile)
- MY_QUERYINTERFACE_ENTRY(IArchiveExtractCallbackMessage)
- MY_QUERYINTERFACE_ENTRY(IArchiveGetRawProps)
- MY_QUERYINTERFACE_ENTRY(IArchiveGetRootProps)
- MY_QUERYINTERFACE_ENTRY(ICryptoGetTextPassword2)
- MY_QUERYINTERFACE_ENTRY(ICryptoGetTextPassword)
- MY_QUERYINTERFACE_ENTRY(ICompressProgressInfo)
- MY_QUERYINTERFACE_END
- MY_ADDREF_RELEASE
+ bool PreserveATime;
+ bool ShareForWrite;
+ bool StopAfterOpenError;
+ bool StdInMode;
+ bool KeepOriginalItemNames;
+ bool StoreNtSecurity;
+ bool StoreHardLinks;
+ bool StoreSymLinks;
- STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);
+ bool StoreOwnerId;
+ bool StoreOwnerName;
- INTERFACE_IArchiveUpdateCallback2(;)
- INTERFACE_IArchiveUpdateCallbackFile(;)
- INTERFACE_IArchiveExtractCallbackMessage(;)
- INTERFACE_IArchiveGetRawProps(;)
- INTERFACE_IArchiveGetRootProps(;)
+ bool Need_LatestMTime;
+ bool LatestMTime_Defined;
- STDMETHOD(CryptoGetTextPassword2)(Int32 *passwordIsDefined, BSTR *password);
- STDMETHOD(CryptoGetTextPassword)(BSTR *password);
+ /*
+ bool Need_ArcMTime_Report;
+ bool ArcMTime_WasReported;
+ */
CRecordVector<UInt32> _openFiles_Indexes;
FStringVector _openFiles_Paths;
+ // CRecordVector< CInFileStream* > _openFiles_Streams;
bool AreAllFilesClosed() const { return _openFiles_Indexes.IsEmpty(); }
- virtual HRESULT InFileStream_On_Error(UINT_PTR val, DWORD error);
- virtual void InFileStream_On_Destroy(UINT_PTR val);
-
- CRecordVector<UInt64> VolumesSizes;
- FString VolName;
- FString VolExt;
+ virtual HRESULT InFileStream_On_Error(UINT_PTR val, DWORD error) Z7_override;
+ virtual void InFileStream_On_Destroy(CInFileStream *stream, UINT_PTR val) Z7_override;
IUpdateCallbackUI *Callback;
@@ -119,15 +155,20 @@ public:
CMyComPtr<IInArchive> Archive;
const CObjectVector<CArcItem> *ArcItems;
const CRecordVector<CUpdatePair2> *UpdatePairs;
- const UStringVector *NewNames;
- bool ShareForWrite;
- bool StdInMode;
+ CRecordVector<UInt64> VolumesSizes;
+ FString VolName;
+ FString VolExt;
+ UString ArcFileName; // without path prefix
- bool KeepOriginalItemNames;
- bool StoreNtSecurity;
- bool StoreHardLinks;
- bool StoreSymLinks;
+ const UStringVector *NewNames;
+ const UString *Comment;
+ int CommentIndex;
+
+ /*
+ CArcTime Reported_ArcMTime;
+ */
+ CFiTime LatestMTime;
Byte *ProcessedItemsStatuses;
@@ -137,11 +178,20 @@ public:
bool IsDir(const CUpdatePair2 &up) const
{
if (up.DirIndex >= 0)
- return DirItems->Items[up.DirIndex].IsDir();
+ return DirItems->Items[(unsigned)up.DirIndex].IsDir();
else if (up.ArcIndex >= 0)
- return (*ArcItems)[up.ArcIndex].IsDir;
+ return (*ArcItems)[(unsigned)up.ArcIndex].IsDir;
return false;
}
+
+private:
+ #if defined(_WIN32) && !defined(UNDER_CE)
+ bool _saclEnabled;
+ #endif
+ CRecordVector<CKeyKeyValPair> _map;
+
+ UInt32 _hardIndex_From;
+ UInt32 _hardIndex_To;
};
#endif
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/UpdatePair.cpp b/3rdparty/lzma/CPP/7zip/UI/Common/UpdatePair.cpp
index e21151974be..99b0aafb281 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/UpdatePair.cpp
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/UpdatePair.cpp
@@ -3,6 +3,7 @@
#include "StdAfx.h"
#include <time.h>
+// #include <stdio.h>
#include "../../../Common/Wildcard.h"
@@ -14,38 +15,99 @@
using namespace NWindows;
using namespace NTime;
-static int MyCompareTime(NFileTimeType::EEnum fileTimeType, const FILETIME &time1, const FILETIME &time2)
+
+/*
+ a2.Prec =
+ {
+ 0 (k_PropVar_TimePrec_0):
+ if GetProperty(kpidMTime) returned 0 and
+ GetProperty(kpidTimeType) did not returned VT_UI4.
+ 7z, wim, tar in 7-Zip before v21)
+ in that case we use
+ (prec) that is set by IOutArchive::GetFileTimeType()
+ }
+*/
+
+static int MyCompareTime(unsigned prec, const CFiTime &f1, const CArcTime &a2)
{
- switch (fileTimeType)
+ // except of precision, we also have limitation, when timestamp is out of range
+
+ /* if (Prec) in archive item is defined, then use global (prec) */
+ if (a2.Prec != k_PropVar_TimePrec_0)
+ prec = a2.Prec;
+
+ CArcTime a1;
+ a1.Set_From_FiTime(f1);
+ /* Set_From_FiTime() must set full form precision:
+ k_PropVar_TimePrec_Base + numDigits
+ windows: 7 digits, non-windows: 9 digits */
+
+ if (prec == k_PropVar_TimePrec_DOS)
{
- case NFileTimeType::kWindows:
- return ::CompareFileTime(&time1, &time2);
- case NFileTimeType::kUnix:
- {
- UInt32 unixTime1, unixTime2;
- FileTimeToUnixTime(time1, unixTime1);
- FileTimeToUnixTime(time2, unixTime2);
- return MyCompare(unixTime1, unixTime2);
- }
- case NFileTimeType::kDOS:
- {
- UInt32 dosTime1, dosTime2;
- FileTimeToDosTime(time1, dosTime1);
- FileTimeToDosTime(time2, dosTime2);
- return MyCompare(dosTime1, dosTime2);
- }
+ const UInt32 dosTime1 = a1.Get_DosTime();
+ const UInt32 dosTime2 = a2.Get_DosTime();
+ return MyCompare(dosTime1, dosTime2);
}
- throw 4191618;
+
+ if (prec == k_PropVar_TimePrec_Unix)
+ {
+ const Int64 u2 = FileTime_To_UnixTime64(a2.FT);
+ if (u2 == 0 || u2 == (UInt32)0xFFFFFFFF)
+ {
+ // timestamp probably was saturated in archive to 32-bit
+ // so we use saturated 32-bit value for disk file too.
+ UInt32 u1;
+ FileTime_To_UnixTime(a1.FT, u1);
+ const UInt32 u2_32 = (UInt32)u2;
+ return MyCompare(u1, u2_32);
+ }
+
+ const Int64 u1 = FileTime_To_UnixTime64(a1.FT);
+ return MyCompare(u1, u2);
+ // prec = k_PropVar_TimePrec_Base; // for debug
+ }
+
+ if (prec == k_PropVar_TimePrec_0)
+ prec = k_PropVar_TimePrec_Base + 7;
+ else if (prec == k_PropVar_TimePrec_HighPrec)
+ prec = k_PropVar_TimePrec_Base + 9;
+ else if (prec < k_PropVar_TimePrec_Base)
+ prec = k_PropVar_TimePrec_Base;
+ else if (prec > k_PropVar_TimePrec_Base + 9)
+ prec = k_PropVar_TimePrec_Base + 7;
+
+ // prec now is full form: k_PropVar_TimePrec_Base + numDigits;
+ if (prec > a1.Prec && a1.Prec >= k_PropVar_TimePrec_Base)
+ prec = a1.Prec;
+
+ const unsigned numDigits = prec - k_PropVar_TimePrec_Base;
+ if (numDigits >= 7)
+ {
+ const int comp = CompareFileTime(&a1.FT, &a2.FT);
+ if (comp != 0 || numDigits == 7)
+ return comp;
+ return MyCompare(a1.Ns100, a2.Ns100);
+ }
+ UInt32 d = 1;
+ for (unsigned k = numDigits; k < 7; k++)
+ d *= 10;
+ const UInt64 v1 = a1.Get_FILETIME_as_UInt64() / d * d;
+ const UInt64 v2 = a2.Get_FILETIME_as_UInt64() / d * d;
+ // printf("\ndelta=%d numDigits=%d\n", (unsigned)(v1- v2), numDigits);
+ return MyCompare(v1, v2);
}
-static const char *k_Duplicate_inArc_Message = "Duplicate filename in archive:";
-static const char *k_Duplicate_inDir_Message = "Duplicate filename on disk:";
-static const char *k_NotCensoredCollision_Message = "Internal file name collision (file on disk, file in archive):";
-static void ThrowError(const char *message, const UString &s1, const UString &s2)
+
+static const char * const k_Duplicate_inArc_Message = "Duplicate filename in archive:";
+static const char * const k_Duplicate_inDir_Message = "Duplicate filename on disk:";
+static const char * const k_NotCensoredCollision_Message = "Internal file name collision (file on disk, file in archive):";
+
+Z7_ATTR_NORETURN
+static
+void ThrowError(const char *message, const UString &s1, const UString &s2)
{
- UString m;
- m.SetFromAscii(message);
+ UString m (message);
m.Add_LF(); m += s1;
m.Add_LF(); m += s2;
throw m;
@@ -53,7 +115,7 @@ static void ThrowError(const char *message, const UString &s1, const UString &s2
static int CompareArcItemsBase(const CArcItem &ai1, const CArcItem &ai2)
{
- int res = CompareFileNames(ai1.Name, ai2.Name);
+ const int res = CompareFileNames(ai1.Name, ai2.Name);
if (res != 0)
return res;
if (ai1.IsDir != ai2.IsDir)
@@ -63,10 +125,10 @@ static int CompareArcItemsBase(const CArcItem &ai1, const CArcItem &ai2)
static int CompareArcItems(const unsigned *p1, const unsigned *p2, void *param)
{
- unsigned i1 = *p1;
- unsigned i2 = *p2;
+ const unsigned i1 = *p1;
+ const unsigned i2 = *p2;
const CObjectVector<CArcItem> &arcItems = *(const CObjectVector<CArcItem> *)param;
- int res = CompareArcItemsBase(arcItems[i1], arcItems[i2]);
+ const int res = CompareArcItemsBase(arcItems[i1], arcItems[i2]);
if (res != 0)
return res;
return MyCompare(i1, i2);
@@ -80,8 +142,8 @@ void GetUpdatePairInfoList(
{
CUIntVector dirIndices, arcIndices;
- unsigned numDirItems = dirItems.Items.Size();
- unsigned numArcItems = arcItems.Size();
+ const unsigned numDirItems = dirItems.Items.Size();
+ const unsigned numArcItems = arcItems.Size();
CIntArr duplicatedArcItem(numArcItems);
{
@@ -145,18 +207,18 @@ void GetUpdatePairInfoList(
if (dirIndex < numDirItems)
{
- dirIndex2 = dirIndices[dirIndex];
- di = &dirItems.Items[dirIndex2];
+ dirIndex2 = (int)dirIndices[dirIndex];
+ di = &dirItems.Items[(unsigned)dirIndex2];
}
if (arcIndex < numArcItems)
{
- arcIndex2 = arcIndices[arcIndex];
- ai = &arcItems[arcIndex2];
+ arcIndex2 = (int)arcIndices[arcIndex];
+ ai = &arcItems[(unsigned)arcIndex2];
compareResult = 1;
if (dirIndex < numDirItems)
{
- compareResult = CompareFileNames(dirNames[dirIndex2], ai->Name);
+ compareResult = CompareFileNames(dirNames[(unsigned)dirIndex2], ai->Name);
if (compareResult == 0)
{
if (di->IsDir() != ai->IsDir)
@@ -167,7 +229,7 @@ void GetUpdatePairInfoList(
if (compareResult < 0)
{
- name = &dirNames[dirIndex2];
+ name = &dirNames[(unsigned)dirIndex2];
pair.State = NUpdateArchive::NPairState::kOnlyOnDisk;
pair.DirIndex = dirIndex2;
dirIndex++;
@@ -183,25 +245,28 @@ void GetUpdatePairInfoList(
}
else
{
- int dupl = duplicatedArcItem[arcIndex];
+ const int dupl = duplicatedArcItem[arcIndex];
if (dupl != 0)
- ThrowError(k_Duplicate_inArc_Message, ai->Name, arcItems[arcIndices[arcIndex + dupl]].Name);
+ ThrowError(k_Duplicate_inArc_Message, ai->Name, arcItems[arcIndices[(unsigned)((int)arcIndex + dupl)]].Name);
- name = &dirNames[dirIndex2];
+ name = &dirNames[(unsigned)dirIndex2];
if (!ai->Censored)
ThrowError(k_NotCensoredCollision_Message, *name, ai->Name);
pair.DirIndex = dirIndex2;
pair.ArcIndex = arcIndex2;
- switch (ai->MTimeDefined ? MyCompareTime(
- ai->TimeType != - 1 ? (NFileTimeType::EEnum)ai->TimeType : fileTimeType,
- di->MTime, ai->MTime): 0)
+ int compResult = 0;
+ if (ai->MTime.Def)
+ {
+ compResult = MyCompareTime((unsigned)fileTimeType, di->MTime, ai->MTime);
+ }
+ switch (compResult)
{
case -1: pair.State = NUpdateArchive::NPairState::kNewInArchive; break;
case 1: pair.State = NUpdateArchive::NPairState::kOldInArchive; break;
default:
- pair.State = (ai->SizeDefined && di->Size == ai->Size) ?
+ pair.State = (ai->Size_Defined && di->Size == ai->Size) ?
NUpdateArchive::NPairState::kSameFiles :
NUpdateArchive::NPairState::kUnknowNewerFiles;
}
@@ -210,12 +275,15 @@ void GetUpdatePairInfoList(
arcIndex++;
}
- if ((di && di->IsAltStream) ||
+ if (
+ #ifdef _WIN32
+ (di && di->IsAltStream) ||
+ #endif
(ai && ai->IsAltStream))
{
if (prevHostName)
{
- unsigned hostLen = prevHostName->Len();
+ const unsigned hostLen = prevHostName->Len();
if (name->Len() > hostLen)
if ((*name)[hostLen] == ':' && CompareFileNames(*prevHostName, name->Left(hostLen)) == 0)
pair.HostIndex = prevHostFile;
@@ -223,7 +291,7 @@ void GetUpdatePairInfoList(
}
else
{
- prevHostFile = updatePairs.Size();
+ prevHostFile = (int)updatePairs.Size();
prevHostName = name;
}
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/UpdatePair.h b/3rdparty/lzma/CPP/7zip/UI/Common/UpdatePair.h
index 296d3b09745..13228b0e012 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/UpdatePair.h
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/UpdatePair.h
@@ -1,7 +1,7 @@
// UpdatePair.h
-#ifndef __UPDATE_PAIR_H
-#define __UPDATE_PAIR_H
+#ifndef ZIP7_INC_UPDATE_PAIR_H
+#define ZIP7_INC_UPDATE_PAIR_H
#include "DirItem.h"
#include "UpdateAction.h"
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/UpdateProduce.cpp b/3rdparty/lzma/CPP/7zip/UI/Common/UpdateProduce.cpp
index e6eabcf148e..e921dc326b6 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/UpdateProduce.cpp
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/UpdateProduce.cpp
@@ -6,7 +6,7 @@
using namespace NUpdateArchive;
-static const char *kUpdateActionSetCollision = "Internal collision in update action set";
+static const char * const kUpdateActionSetCollision = "Internal collision in update action set";
void UpdateProduce(
const CRecordVector<CUpdatePair> &updatePairs,
@@ -28,7 +28,7 @@ void UpdateProduce(
{
case NPairAction::kIgnore:
if (pair.ArcIndex >= 0 && callback)
- callback->ShowDeleteFile(pair.ArcIndex);
+ callback->ShowDeleteFile((unsigned)pair.ArcIndex);
continue;
case NPairAction::kCopy:
@@ -43,7 +43,7 @@ void UpdateProduce(
1) no such alt stream in Disk
2) there is Host file in disk
*/
- if (updatePairs[pair.HostIndex].DirIndex >= 0)
+ if (updatePairs[(unsigned)pair.HostIndex].DirIndex >= 0)
continue;
}
}
@@ -63,6 +63,8 @@ void UpdateProduce(
break;
}
+ up2.IsSameTime = ((unsigned)pair.State == NUpdateArchive::NPairState::kSameFiles);
+
operationChain.Add(up2);
}
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/UpdateProduce.h b/3rdparty/lzma/CPP/7zip/UI/Common/UpdateProduce.h
index 64c58cc5772..9db6c1e44b2 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/UpdateProduce.h
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/UpdateProduce.h
@@ -1,7 +1,7 @@
// UpdateProduce.h
-#ifndef __UPDATE_PRODUCE_H
-#define __UPDATE_PRODUCE_H
+#ifndef ZIP7_INC_UPDATE_PRODUCE_H
+#define ZIP7_INC_UPDATE_PRODUCE_H
#include "UpdatePair.h"
@@ -17,13 +17,14 @@ struct CUpdatePair2
int NewNameIndex;
bool IsMainRenameItem;
+ bool IsSameTime;
- void SetAs_NoChangeArcItem(int arcIndex)
+ void SetAs_NoChangeArcItem(unsigned arcIndex) // int
{
NewData = NewProps = false;
UseArcProps = true;
IsAnti = false;
- ArcIndex = arcIndex;
+ ArcIndex = (int)arcIndex;
}
bool ExistOnDisk() const { return DirIndex != -1; }
@@ -37,14 +38,18 @@ struct CUpdatePair2
DirIndex(-1),
ArcIndex(-1),
NewNameIndex(-1),
- IsMainRenameItem(false)
+ IsMainRenameItem(false),
+ IsSameTime(false)
{}
};
-struct IUpdateProduceCallback
+Z7_PURE_INTERFACES_BEGIN
+
+DECLARE_INTERFACE(IUpdateProduceCallback)
{
virtual HRESULT ShowDeleteFile(unsigned arcIndex) = 0;
};
+Z7_PURE_INTERFACES_END
void UpdateProduce(
const CRecordVector<CUpdatePair> &updatePairs,
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/WorkDir.cpp b/3rdparty/lzma/CPP/7zip/UI/Common/WorkDir.cpp
index 284eaa16ac3..cfec63507af 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/WorkDir.cpp
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/WorkDir.cpp
@@ -2,10 +2,8 @@
#include "StdAfx.h"
-#include "../../../Common/StringConvert.h"
-#include "../../../Common/Wildcard.h"
-
#include "../../../Windows/FileName.h"
+#include "../../../Windows/FileSystem.h"
#include "WorkDir.h"
@@ -21,10 +19,10 @@ FString GetWorkDir(const NWorkDir::CInfo &workDirInfo, const FString &path, FStr
if (workDirInfo.ForRemovableOnly)
{
mode = NWorkDir::NMode::kCurrent;
- FString prefix = path.Left(3);
- if (prefix[1] == FTEXT(':') && prefix[2] == FTEXT('\\'))
+ const FString prefix = path.Left(3);
+ if (NName::IsDrivePath(prefix))
{
- UINT driveType = GetDriveType(GetSystemString(prefix, ::AreFileApisANSI() ? CP_ACP : CP_OEMCP));
+ const UINT driveType = NSystem::MyGetDriveType(prefix);
if (driveType == DRIVE_CDROM || driveType == DRIVE_REMOVABLE)
mode = workDirInfo.Mode;
}
@@ -38,29 +36,26 @@ FString GetWorkDir(const NWorkDir::CInfo &workDirInfo, const FString &path, FStr
}
#endif
- int pos = path.ReverseFind_PathSepar() + 1;
- fileName = path.Ptr(pos);
+ const int pos = path.ReverseFind_PathSepar() + 1;
+ fileName = path.Ptr((unsigned)pos);
- switch (mode)
+ FString tempDir;
+ switch ((int)mode)
{
case NWorkDir::NMode::kCurrent:
- {
- return path.Left(pos);
- }
+ tempDir = path.Left((unsigned)pos);
+ break;
case NWorkDir::NMode::kSpecified:
- {
- FString tempDir = workDirInfo.Path;
- NName::NormalizeDirPathPrefix(tempDir);
- return tempDir;
- }
+ tempDir = workDirInfo.Path;
+ break;
+ // case NWorkDir::NMode::kSystem:
default:
- {
- FString tempDir;
if (!MyGetTempPath(tempDir))
throw 141717;
- return tempDir;
- }
+ break;
}
+ NName::NormalizeDirPathPrefix(tempDir);
+ return tempDir;
}
HRESULT CWorkDirTempFile::CreateTempFile(const FString &originalPath)
@@ -68,15 +63,13 @@ HRESULT CWorkDirTempFile::CreateTempFile(const FString &originalPath)
NWorkDir::CInfo workDirInfo;
workDirInfo.Load();
FString namePart;
- FString workDir = GetWorkDir(workDirInfo, originalPath, namePart);
+ const FString workDir = GetWorkDir(workDirInfo, originalPath, namePart);
CreateComplexDir(workDir);
- CTempFile tempFile;
_outStreamSpec = new COutFileStream;
OutStream = _outStreamSpec;
if (!_tempFile.Create(workDir + namePart, &_outStreamSpec->File))
{
- DWORD error = GetLastError();
- return error ? error : E_FAIL;
+ return GetLastError_noZero_HRESULT();
}
_originalPath = originalPath;
return S_OK;
@@ -87,8 +80,7 @@ HRESULT CWorkDirTempFile::MoveToOriginal(bool deleteOriginal)
OutStream.Release();
if (!_tempFile.MoveTo(_originalPath, deleteOriginal))
{
- DWORD error = GetLastError();
- return error ? error : E_FAIL;
+ return GetLastError_noZero_HRESULT();
}
return S_OK;
}
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/WorkDir.h b/3rdparty/lzma/CPP/7zip/UI/Common/WorkDir.h
index 75850a92b1c..d32ab9d3d2b 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/WorkDir.h
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/WorkDir.h
@@ -1,7 +1,7 @@
// WorkDir.h
-#ifndef __WORK_DIR_H
-#define __WORK_DIR_H
+#ifndef ZIP7_INC_WORK_DIR_H
+#define ZIP7_INC_WORK_DIR_H
#include "../../../Windows/FileDir.h"
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/ZipRegistry.h b/3rdparty/lzma/CPP/7zip/UI/Common/ZipRegistry.h
index 935f97bbaa4..6bc6977b611 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/ZipRegistry.h
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/ZipRegistry.h
@@ -1,13 +1,25 @@
// ZipRegistry.h
-#ifndef __ZIP_REGISTRY_H
-#define __ZIP_REGISTRY_H
+#ifndef ZIP7_INC_ZIP_REGISTRY_H
+#define ZIP7_INC_ZIP_REGISTRY_H
#include "../../../Common/MyTypes.h"
#include "../../../Common/MyString.h"
+#include "../../Common/MethodProps.h"
+
#include "ExtractMode.h"
+/*
+CBoolPair::Def in writing functions means:
+ if ( CBoolPair::Def ), we write CBoolPair::Val
+ if ( !CBoolPair::Def )
+ {
+ in NCompression functions we delete registry value
+ in another functions we do nothing
+ }
+*/
+
namespace NExtract
{
struct CInfo
@@ -35,27 +47,87 @@ namespace NExtract
namespace NCompression
{
+ struct CMemUse
+ {
+ // UString Str;
+ bool IsDefined;
+ bool IsPercent;
+ UInt64 Val;
+
+ CMemUse():
+ IsDefined(false),
+ IsPercent(false),
+ Val(0)
+ {}
+
+ void Clear()
+ {
+ // Str.Empty();
+ IsDefined = false;
+ IsPercent = false;
+ Val = 0;
+ }
+
+ UInt64 GetBytes(UInt64 ramSize) const
+ {
+ if (!IsPercent)
+ return Val;
+ return Calc_From_Val_Percents(ramSize, Val);
+ }
+ void Parse(const UString &s);
+ };
+
struct CFormatOptions
{
UInt32 Level;
UInt32 Dictionary;
+ // UInt32 DictionaryChain;
UInt32 Order;
UInt32 BlockLogSize;
UInt32 NumThreads;
+ UInt32 TimePrec;
+ CBoolPair MTime;
+ CBoolPair ATime;
+ CBoolPair CTime;
+ CBoolPair SetArcMTime;
+
CSysString FormatID;
UString Method;
UString Options;
UString EncryptionMethod;
+ UString MemUse;
+
+ void Reset_TimePrec()
+ {
+ TimePrec = (UInt32)(Int32)-1;
+ }
+
+ bool IsSet_TimePrec() const
+ {
+ return TimePrec != (UInt32)(Int32)-1;
+ }
+
+
+ void Reset_BlockLogSize()
+ {
+ BlockLogSize = (UInt32)(Int32)-1;
+ }
void ResetForLevelChange()
{
- BlockLogSize = NumThreads = Level = Dictionary = Order = UInt32(-1);
+ BlockLogSize = NumThreads = Level = Dictionary = Order = (UInt32)(Int32)-1;
+ // DictionaryChain = (UInt32)(Int32)-1;
Method.Empty();
// Options.Empty();
// EncryptionMethod.Empty();
}
- CFormatOptions() { ResetForLevelChange(); }
+ CFormatOptions()
+ {
+ // TimePrec = 0;
+ Reset_TimePrec();
+ ResetForLevelChange();
+ }
};
struct CInfo
@@ -63,16 +135,19 @@ namespace NCompression
UInt32 Level;
bool ShowPassword;
bool EncryptHeaders;
- UString ArcType;
- UStringVector ArcPaths;
-
- CObjectVector<CFormatOptions> Formats;
CBoolPair NtSecurity;
CBoolPair AltStreams;
CBoolPair HardLinks;
CBoolPair SymLinks;
+ CBoolPair PreserveATime;
+
+ UString ArcType;
+ UStringVector ArcPaths;
+
+ CObjectVector<CFormatOptions> Formats;
+
void Save() const;
void Load();
};
@@ -92,8 +167,8 @@ namespace NWorkDir
struct CInfo
{
NMode::EEnum Mode;
- FString Path;
bool ForRemovableOnly;
+ FString Path;
void SetForRemovableOnlyDefault() { ForRemovableOnly = true; }
void SetDefault()
@@ -114,9 +189,18 @@ struct CContextMenuInfo
CBoolPair Cascaded;
CBoolPair MenuIcons;
CBoolPair ElimDup;
-
+
bool Flags_Def;
UInt32 Flags;
+ UInt32 WriteZone;
+
+ /*
+ CContextMenuInfo():
+ Flags_Def(0),
+ WriteZone((UInt32)(Int32)-1),
+ Flags((UInt32)(Int32)-1)
+ {}
+ */
void Save() const;
void Load();