Update to 7-Zip 17.00 Beta

This commit is contained in:
Tino Reichardt
2017-04-30 14:14:14 +02:00
parent 54389d6e2f
commit aa5ba75da0
451 changed files with 15746 additions and 8574 deletions

View File

@@ -29,6 +29,7 @@
#include "UpdateAction.h"
extern bool g_CaseSensitive;
extern bool g_PathTrailReplaceMode;
#ifdef UNDER_CE
@@ -61,10 +62,10 @@ static bool StringToUInt32(const wchar_t *s, UInt32 &v)
CArcCmdLineException::CArcCmdLineException(const char *a, const wchar_t *u)
{
(*this) += MultiByteToUnicodeString(a);
(*this) += a;
if (u)
{
this->Add_LF();
Add_LF();
(*this) += u;
}
}
@@ -133,10 +134,13 @@ enum Enum
kHardLinks,
kSymLinks,
kNtSecurity,
kAltStreams,
kReplaceColonForAltStream,
kWriteToAltStreamIfColon,
kNameTrailReplace,
kDeleteAfterCompressing,
kSetArcMTime
@@ -149,11 +153,11 @@ 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)
{
@@ -180,7 +184,7 @@ static const char 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 char *kOverwritePostCharSet = "asut";
static const char * const kOverwritePostCharSet = "asut";
static const NExtract::NOverwriteMode::EEnum k_OverwriteModes[] =
{
@@ -251,10 +255,13 @@ static const CSwitchForm kSwitchForms[] =
{ "snh", NSwitchType::kMinus },
{ "snl", NSwitchType::kMinus },
{ "sni" },
{ "sns", NSwitchType::kMinus },
{ "snr" },
{ "snc" },
{ "snt", NSwitchType::kMinus },
{ "sdel" },
{ "stl" }
@@ -263,17 +270,17 @@ static const CSwitchForm kSwitchForms[] =
#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";
static const char * const kCannotFindArchive = "Cannot find archive";
bool CArcCommand::IsFromExtractGroup() const
{
@@ -328,7 +335,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)
{
@@ -386,9 +393,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);
}
}
@@ -422,23 +429,28 @@ static void AddToCensorFromNonSwitchesStrings(
CObjectVector<CRenamePair> *renamePairs,
unsigned startIndex,
NWildcard::CCensor &censor,
const UStringVector &nonSwitchStrings, NRecursedType::EEnum type,
const UStringVector &nonSwitchStrings,
int stopSwitchIndex,
NRecursedType::EEnum type,
bool wildcardMatching,
bool thereAreSwitchIncludes, Int32 codePage)
{
if ((renamePairs || nonSwitchStrings.Size() == startIndex) && !thereAreSwitchIncludes)
AddNameToCensor(censor, kUniversalWildcard, true, type,
AddNameToCensor(censor, UString(kUniversalWildcard), true, type,
true // wildcardMatching
);
int oldIndex = -1;
if (stopSwitchIndex < 0)
stopSwitchIndex = 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)
if (i < (unsigned)stopSwitchIndex && s[0] == kFileListID)
AddToCensorFromListFile(renamePairs, censor, s.Ptr(1), true, type, wildcardMatching, codePage);
else if (renamePairs)
{
@@ -477,7 +489,7 @@ 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,
@@ -485,7 +497,7 @@ static const char *ParseMapWithPaths(
NRecursedType::EEnum commonRecursedType,
bool wildcardMatching)
{
UString s = s2;
UString s (s2);
int pos = s.Find(L':');
if (pos < 0)
return k_IncorrectMapCommand;
@@ -577,7 +589,7 @@ static void AddSwitchWildcardsToCensor(
break;
}
UString tail = name.Ptr(pos + 1);
const UString tail = name.Ptr(pos + 1);
if (name[pos] == kImmediateNameID)
AddNameToCensor(censor, tail, include, recursedType, wildcardMatching);
@@ -610,7 +622,7 @@ static void ConvertToLongName(const UString &prefix, UString &name)
if (name.IsEmpty() || DoesNameContainWildcard(name))
return;
NFind::CFileInfo fi;
const FString path = us2fs(prefix + name);
const FString path (us2fs(prefix + name));
#ifndef UNDER_CE
if (NFile::NName::IsDevicePath(path))
return;
@@ -693,11 +705,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 +719,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;
@@ -849,7 +861,6 @@ static void SetMethodOptions(const CParser &parser, CObjectVector<CProperty> &pr
}
}
CArcCmdLineParser::CArcCmdLineParser(): parser(ARRAY_SIZE(kSwitchForms)) {}
static inline void SetStreamMode(const CSwitchResult &sw, unsigned &res)
{
@@ -857,10 +868,11 @@ static inline void SetStreamMode(const CSwitchResult &sw, unsigned &res)
res = sw.PostCharIndex;
}
void CArcCmdLineParser::Parse1(const UStringVector &commandStrings,
CArcCmdLineOptions &options)
{
if (!parser.ParseStrings(kSwitchForms, commandStrings))
if (!parser.ParseStrings(kSwitchForms, ARRAY_SIZE(kSwitchForms), commandStrings))
throw CArcCmdLineException(parser.ErrorMessage, parser.ErrorLine);
options.IsInTerminal = MY_IS_TERMINAL(stdin);
@@ -965,7 +977,7 @@ 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))
@@ -1051,7 +1063,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");
@@ -1082,6 +1094,9 @@ void CArcCmdLineParser::Parse2(CArcCmdLineOptions &options)
}
}
if (parser[NKey::kNameTrailReplace].ThereIs)
g_PathTrailReplaceMode = !parser[NKey::kNameTrailReplace].WithMinus;
NRecursedType::EEnum recursedType;
if (parser[NKey::kRecursed].ThereIs)
recursedType = GetRecursedTypeFromIndex(parser[NKey::kRecursed].PostCharIndex);
@@ -1138,7 +1153,8 @@ void CArcCmdLineParser::Parse2(CArcCmdLineOptions &options)
AddToCensorFromNonSwitchesStrings(isRename ? &options.UpdateOptions.RenamePairs : NULL,
curCommandIndex, options.Censor,
nonSwitchStrings, recursedType, wildcardMatching,
nonSwitchStrings, parser.StopSwitchIndex,
recursedType, wildcardMatching,
thereAreSwitchIncludes, codePage);
options.YesToAll = parser[NKey::kYes].ThereIs;

View File

@@ -130,7 +130,6 @@ class CArcCmdLineParser
{
NCommandLineParser::CParser parser;
public:
CArcCmdLineParser();
void Parse1(const UStringVector &commandStrings, CArcCmdLineOptions &options);
void Parse2(CArcCmdLineOptions &options);
};

View File

@@ -5,7 +5,12 @@
#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"
@@ -36,10 +41,14 @@ 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 = "Can not create file with auto name";
static const char * const kCantRenameFile = "Can not rename existing file";
static const char * const kCantDeleteOutputFile = "Can not delete output file";
static const char * const kCantDeleteOutputDir = "Can not delete output folder";
static const char * const kCantCreateHardLink = "Can not create hard link";
static const char * const kCantCreateSymLink = "Can not create symbolic link";
static const char * const kCantOpenOutFile = "Can not open output file";
static const char * const kCantSetFileLen = "Can not set length for output file";
#ifndef _SFX
@@ -381,14 +390,13 @@ HRESULT CArchiveExtractCallback::GetUnpackSize()
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,11 +404,10 @@ 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);
UString s (message);
if (errorCode != 0)
{
s.AddAscii(" : ");
s += " : ";
s += NError::MyFormatMessage(errorCode);
}
AddPathToMessage(s, path);
@@ -409,8 +416,7 @@ HRESULT CArchiveExtractCallback::SendMessageError_with_LastError(const char *mes
HRESULT CArchiveExtractCallback::SendMessageError2(const char *message, const FString &path1, const FString &path2)
{
UString s;
s.AddAscii(message);
UString s (message);
AddPathToMessage(s, path1);
AddPathToMessage(s, path2);
return _extractCallback2->MessageError(s);
@@ -440,7 +446,7 @@ STDMETHODIMP CGetProp::GetProp(PROPID propID, PROPVARIANT *value)
static UString GetDirPrefixOf(const UString &src)
{
UString s = src;
UString s (src);
if (!s.IsEmpty())
{
if (IsPathSepar(s.Back()))
@@ -514,7 +520,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;
@@ -541,7 +547,7 @@ bool CensorNode_CheckPath(const NWildcard::CCensorNode &node, const CReadArcItem
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()))
{
@@ -596,6 +602,7 @@ HRESULT CArchiveExtractCallback::MyCopyFile(ISequentialOutStream *outStream)
#endif
*/
STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode)
{
COM_TRY_BEGIN
@@ -616,6 +623,7 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStre
_curSize = 0;
_curSizeDefined = false;
_fileLengthWasSet = false;
_index = index;
_diskFilePath.Empty();
@@ -928,13 +936,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
@@ -986,7 +994,7 @@ if (askExtractMode == NArchive::NExtract::NAskMode::kExtract && !_testMode)
if (_item.IsAltStream)
{
UString s = _item.AltStreamName;
UString s (_item.AltStreamName);
Correct_AltStream_Name(s);
bool needColon = true;
@@ -1002,13 +1010,13 @@ if (askExtractMode == NArchive::NExtract::NAskMode::kExtract && !_testMode)
UString &name = pathParts.Back();
if (needColon)
name += (wchar_t)(_ntOptions.ReplaceColonForAltStream ? L'_' : L':');
name += (char)(_ntOptions.ReplaceColonForAltStream ? '_' : ':');
name += s;
}
#endif
UString processedPath = MakePathFromParts(pathParts);
UString processedPath (MakePathFromParts(pathParts));
if (!isAnti)
{
@@ -1035,7 +1043,7 @@ if (askExtractMode == NArchive::NExtract::NAskMode::kExtract && !_testMode)
}
FString fullProcessedPath = us2fs(processedPath);
FString fullProcessedPath (us2fs(processedPath));
if (_pathMode != NExtract::NPathMode::kAbsPaths
|| !NName::IsAbsolutePath(processedPath))
{
@@ -1051,8 +1059,8 @@ if (askExtractMode == NArchive::NExtract::NAskMode::kExtract && !_testMode)
{
const CIndexToPathPair &pair = _renamedFiles[renIndex];
fullProcessedPath = pair.Path;
fullProcessedPath += (FChar)':';
UString s = _item.AltStreamName;
fullProcessedPath += ':';
UString s (_item.AltStreamName);
Correct_AltStream_Name(s);
fullProcessedPath += us2fs(s);
}
@@ -1086,7 +1094,7 @@ if (askExtractMode == NArchive::NExtract::NAskMode::kExtract && !_testMode)
case NExtract::NOverwriteMode::kAsk:
{
int slashPos = fullProcessedPath.ReverseFind_PathSepar();
FString realFullProcessedPath = fullProcessedPath.Left(slashPos + 1) + fileInfo.Name;
FString realFullProcessedPath (fullProcessedPath.Left(slashPos + 1) + fileInfo.Name);
Int32 overwriteResult;
RINOK(_extractCallback2->AskOverwrite(
@@ -1119,7 +1127,7 @@ if (askExtractMode == NArchive::NExtract::NAskMode::kExtract && !_testMode)
}
else if (_overwriteMode == NExtract::NOverwriteMode::kRenameExisting)
{
FString existPath = fullProcessedPath;
FString existPath (fullProcessedPath);
if (!AutoRenamePath(existPath))
{
RINOK(SendMessageError(kCantAutoRename, fullProcessedPath));
@@ -1165,7 +1173,7 @@ if (askExtractMode == NArchive::NExtract::NAskMode::kExtract && !_testMode)
int colonPos = NName::FindAltStreamColon(fullProcessedPath);
if (colonPos >= 0 && fullProcessedPath[(unsigned)colonPos + 1] != 0)
{
FString parentFsPath = fullProcessedPath;
FString parentFsPath (fullProcessedPath);
parentFsPath.DeleteFrom(colonPos);
NFind::CFileInfo parentFi;
if (parentFi.Find(parentFsPath))
@@ -1222,7 +1230,7 @@ if (askExtractMode == NArchive::NExtract::NAskMode::kExtract && !_testMode)
{
if (!MyCreateHardLink(fullProcessedPath, existPath))
{
RINOK(SendMessageError2("Can not create hard link", fullProcessedPath, existPath));
RINOK(SendMessageError2(kCantCreateHardLink, fullProcessedPath, existPath));
// return S_OK;
}
}
@@ -1270,7 +1278,7 @@ if (askExtractMode == NArchive::NExtract::NAskMode::kExtract && !_testMode)
else
if (!NFile::NIO::SetReparseData(fullProcessedPath, _item.IsDir, data, (DWORD)data.Size()))
{
RINOK(SendMessageError_with_LastError("Can not create symbolic link", fullProcessedPath));
RINOK(SendMessageError_with_LastError(kCantCreateSymLink, fullProcessedPath));
}
}
}
@@ -1304,7 +1312,7 @@ if (askExtractMode == NArchive::NExtract::NAskMode::kExtract && !_testMode)
{
if (!MyCreateHardLink(fullProcessedPath, hl))
{
RINOK(SendMessageError2("Can not create hard link", fullProcessedPath, hl));
RINOK(SendMessageError2(kCantCreateHardLink, fullProcessedPath, hl));
return S_OK;
}
needWriteFile = false;
@@ -1323,11 +1331,24 @@ if (askExtractMode == NArchive::NExtract::NAskMode::kExtract && !_testMode)
{
// if (::GetLastError() != ERROR_FILE_EXISTS || !isSplit)
{
RINOK(SendMessageError_with_LastError("Can not open output file", fullProcessedPath));
RINOK(SendMessageError_with_LastError(kCantOpenOutFile, fullProcessedPath));
return S_OK;
}
}
if (_ntOptions.PreAllocateOutFile && !_isSplit && _curSizeDefined && _curSize > (1 << 12))
{
// UInt64 ticks = GetCpuTicks();
bool res = _outFileStreamSpec->File.SetLength(_curSize);
_fileLengthWasSet = res;
_outFileStreamSpec->File.SeekToBegin();
// ticks = GetCpuTicks() - ticks;
// printf("\nticks = %10d\n", (unsigned)ticks);
if (!res)
{
RINOK(SendMessageError_with_LastError(kCantSetFileLen, fullProcessedPath));
}
}
#ifdef SUPPORT_ALT_STREAMS
if (isRenamed && !_item.IsAltStream)
@@ -1456,14 +1477,24 @@ STDMETHODIMP CArchiveExtractCallback::SetOperationResult(Int32 opRes)
if (_outFileStream)
{
HRESULT hres = S_OK;
_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;
const UInt64 processedSize = _outFileStreamSpec->ProcessedSize;
if (_fileLengthWasSet && _curSize > processedSize)
{
bool res = _outFileStreamSpec->File.SetLength(processedSize);
_fileLengthWasSet = res;
if (!res)
hres = SendMessageError_with_LastError(kCantSetFileLen, us2fs(_item.Path));
}
_curSize = processedSize;
_curSizeDefined = true;
RINOK(_outFileStreamSpec->Close());
_outFileStream.Release();
RINOK(hres);
}
#ifdef _USE_SECURITY_CODE
@@ -1525,23 +1556,19 @@ STDMETHODIMP CArchiveExtractCallback::ReportExtractResult(UInt32 indexType, UInt
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;
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) {}
}

View File

@@ -57,6 +57,8 @@ struct CExtractNtOptions
bool ReplaceColonForAltStream;
bool WriteToAltStreamIfColon;
bool PreAllocateOutFile;
CExtractNtOptions():
ReplaceColonForAltStream(false),
WriteToAltStreamIfColon(false)
@@ -64,6 +66,13 @@ struct CExtractNtOptions
SymLinks.Val = true;
HardLinks.Val = true;
AltStreams.Val = true;
PreAllocateOutFile =
#ifdef _WIN32
true;
#else
false;
#endif
}
};
@@ -201,6 +210,7 @@ class CArchiveExtractCallback:
UInt32 _index;
UInt64 _curSize;
bool _curSizeDefined;
bool _fileLengthWasSet;
COutFileStream *_outFileStreamSpec;
CMyComPtr<ISequentialOutStream> _outFileStream;

View File

@@ -29,7 +29,7 @@ UString CreateArchiveName(const NFind::CFileInfo &fi, bool keepName)
static FString CreateArchiveName2(const FString &path, bool fromPrev, bool keepName)
{
FString resultName = FTEXT("Archive");
FString resultName ("Archive");
if (fromPrev)
{
FString dirPrefix;

View File

@@ -32,8 +32,6 @@
#include "../../../../C/Alloc.h"
#include "../../../../C/CpuArch.h"
#include "../../../Windows/System.h"
#ifndef _7ZIP_ST
#include "../../../Windows/Synchronization.h"
#include "../../../Windows/Thread.h"
@@ -1200,10 +1198,9 @@ static HRESULT MethodBench(
if (oldLzmaBenchMode && 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;
@@ -1858,6 +1855,37 @@ static void PrintTotals(IBenchPrintCallback &f, bool showFreq, UInt64 cpuFreq, c
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);
if (ti.processAffinityMask != ti.systemAffinityMask)
{
// if (ti.numProcessThreads != ti.numSysThreads)
{
s += " / ";
s.Add_UInt32(ti.GetNumSystemThreads());
}
s += " : ";
PrintHex(s, ti.processAffinityMask);
s += " / ";
PrintHex(s, ti.systemAffinityMask);
}
return s;
}
extern bool g_LargePagesMode;
static void PrintRequirements(IBenchPrintCallback &f, const char *sizeString,
bool size_Defined, UInt64 size, const char *threadsString, UInt32 numThreads)
{
@@ -1867,12 +1895,16 @@ static void PrintRequirements(IBenchPrintCallback &f, const char *sizeString,
PrintNumber(f, (size >> 20), 6);
else
f.Print(" ?");
f.Print(" MB, # ");
f.Print(" MB");
if (g_LargePagesMode)
f.Print(" LP");
f.Print(", # ");
f.Print(threadsString);
PrintNumber(f, numThreads, 3);
f.NewLine();
}
struct CBenchCallbackToPrint: public IBenchCallback
{
CBenchProps BenchProps;
@@ -1930,7 +1962,7 @@ 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)
{
@@ -2147,7 +2179,7 @@ static HRESULT CrcBench(
numThreads = 1;
#endif
AString methodName = method.MethodName;
const AString &methodName = method.MethodName;
// methodName.RemoveChar(L'-');
CMethodId hashID;
if (!FindHashMethod(
@@ -2410,6 +2442,240 @@ static void x86cpuid_to_String(const Cx86cpuid &c, AString &s)
#endif
static const char * const k_PROCESSOR_ARCHITECTURE[] =
{
"x86" // "INTEL"
, "MIPS"
, "ALPHA"
, "PPC"
, "SHX"
, "ARM"
, "IA64"
, "ALPHA64"
, "MSIL"
, "x64" // "AMD64"
, "IA32_ON_WIN64"
, "NEUTRAL"
, "ARM64"
, "ARM32_ON_WIN64"
};
#define MY__PROCESSOR_ARCHITECTURE_INTEL 0
#define MY__PROCESSOR_ARCHITECTURE_AMD64 9
#define MY__PROCESSOR_INTEL_PENTIUM 586
#define MY__PROCESSOR_AMD_X8664 8664
/*
static const CUInt32PCharPair k_PROCESSOR[] =
{
{ 2200, "IA64" },
{ 8664, "x64" }
};
#define PROCESSOR_INTEL_386 386
#define PROCESSOR_INTEL_486 486
#define PROCESSOR_INTEL_PENTIUM 586
#define PROCESSOR_INTEL_860 860
#define PROCESSOR_INTEL_IA64 2200
#define PROCESSOR_AMD_X8664 8664
#define PROCESSOR_MIPS_R2000 2000
#define PROCESSOR_MIPS_R3000 3000
#define PROCESSOR_MIPS_R4000 4000
#define PROCESSOR_ALPHA_21064 21064
#define PROCESSOR_PPC_601 601
#define PROCESSOR_PPC_603 603
#define PROCESSOR_PPC_604 604
#define PROCESSOR_PPC_620 620
#define PROCESSOR_HITACHI_SH3 10003
#define PROCESSOR_HITACHI_SH3E 10004
#define PROCESSOR_HITACHI_SH4 10005
#define PROCESSOR_MOTOROLA_821 821
#define PROCESSOR_SHx_SH3 103
#define PROCESSOR_SHx_SH4 104
#define PROCESSOR_STRONGARM 2577 // 0xA11
#define PROCESSOR_ARM720 1824 // 0x720
#define PROCESSOR_ARM820 2080 // 0x820
#define PROCESSOR_ARM920 2336 // 0x920
#define PROCESSOR_ARM_7TDMI 70001
#define PROCESSOR_OPTIL 18767 // 0x494f
*/
#ifdef _WIN32
static const char * const k_PF[] =
{
"FP_ERRATA"
, "FP_EMU"
, "CMPXCHG"
, "MMX"
, "PPC_MOVEMEM_64BIT"
, "ALPHA_BYTE"
, "SSE"
, "3DNOW"
, "RDTSC"
, "PAE"
, "SSE2"
, "SSE_DAZ"
, "NX"
, "SSE3"
, "CMPXCHG16B"
, "CMP8XCHG16"
, "CHANNELS"
, "XSAVE"
, "ARM_VFP_32"
, "ARM_NEON"
, "L2AT"
, "VIRT_FIRMWARE"
, "RDWRFSGSBASE"
, "FASTFAIL"
, "ARM_DIVIDE"
, "ARM_64BIT_LOADSTORE_ATOMIC"
, "ARM_EXTERNAL_CACHE"
, "ARM_FMAC"
, "RDRAND"
, "ARM_V8"
, "ARM_V8_CRYPTO"
, "ARM_V8_CRC32"
, "RDTSCP"
};
#endif
static void PrintSize(AString &s, UInt64 ptr)
{
UInt64 v = ptr;
UInt64 t = v >> 40;
UInt64 g = v >> 30;
UInt64 m = v >> 20;
UInt64 k = v >> 10;
UInt32 d = (UInt32)v;
char c = 0;
if (t >= 1000) { d = (UInt32)t; c = 'T'; }
else if (g >= 1000) { d = (UInt32)g; c = 'G'; }
else if (m >= 1000) { d = (UInt32)m; c = 'M'; }
else if (k >= 10) { d = (UInt32)k; c = 'K'; }
s.Add_UInt32(d);
// s += ' ';
if (c)
s += c;
// PrintHex(s, (DWORD_PTR)v);
}
static void PrintPage(AString &s, UInt32 v)
{
if ((v & 0x3FF) == 0)
{
s.Add_UInt32(v >> 10);
s += "K";
}
else
s.Add_UInt32(v >> 10);
}
static AString TypeToString2(const char * const table[], unsigned num, UInt32 value)
{
char sz[16];
const char *p = NULL;
if (value < num)
p = table[value];
if (!p)
{
ConvertUInt32ToString(value, sz);
p = sz;
}
return (AString)p;
}
#ifdef _WIN32
static void SysInfo_To_String(AString &s, const SYSTEM_INFO &si)
{
s += TypeToString2(k_PROCESSOR_ARCHITECTURE, ARRAY_SIZE(k_PROCESSOR_ARCHITECTURE), si.wProcessorArchitecture);
if (!( si.wProcessorArchitecture == MY__PROCESSOR_ARCHITECTURE_INTEL && si.dwProcessorType == MY__PROCESSOR_INTEL_PENTIUM
|| si.wProcessorArchitecture == MY__PROCESSOR_ARCHITECTURE_AMD64 && si.dwProcessorType == MY__PROCESSOR_AMD_X8664))
{
s += " ";
// s += TypePairToString(k_PROCESSOR, ARRAY_SIZE(k_PROCESSOR), si.dwProcessorType);
s.Add_UInt32(si.dwProcessorType);
}
s += " ";
PrintHex(s, si.wProcessorLevel);
s += ".";
PrintHex(s, si.wProcessorRevision);
if (si.dwActiveProcessorMask + 1 != ((UInt64)1 << si.dwNumberOfProcessors))
{
s += " act:";
PrintHex(s, si.dwActiveProcessorMask);
}
s += " cpus:";
s.Add_UInt32(si.dwNumberOfProcessors);
if (si.dwPageSize != 1 << 12)
{
s += " page:";
PrintPage(s, si.dwPageSize);
}
if (si.dwAllocationGranularity != 1 << 16)
{
s += " gran:";
PrintPage(s, si.dwAllocationGranularity);
}
s += " ";
DWORD_PTR minAdd = (DWORD_PTR)si.lpMinimumApplicationAddress;
if (minAdd != (1 << 16))
{
PrintSize(s, minAdd);
s += "-";
}
PrintSize(s, (UInt64)(DWORD_PTR)si.lpMaximumApplicationAddress + 1);
}
#ifndef _WIN64
typedef VOID (WINAPI *Func_GetNativeSystemInfo)(LPSYSTEM_INFO lpSystemInfo);
#endif
#endif
void GetSysInfo(AString &s1, AString &s2)
{
s1.Empty();
s2.Empty();
#ifdef _WIN32
SYSTEM_INFO si;
GetSystemInfo(&si);
{
SysInfo_To_String(s1, si);
// s += " : ";
}
#if !defined(_WIN64) && !defined(UNDER_CE)
Func_GetNativeSystemInfo fn_GetNativeSystemInfo = (Func_GetNativeSystemInfo)GetProcAddress(
GetModuleHandleA("kernel32.dll"), "GetNativeSystemInfo");
if (fn_GetNativeSystemInfo)
{
SYSTEM_INFO si2;
fn_GetNativeSystemInfo(&si2);
// if (memcmp(&si, &si2, sizeof(si)) != 0)
{
// s += " - ";
SysInfo_To_String(s2, si2);
}
}
#endif
#endif
}
void GetCpuName(AString &s)
{
s.Empty();
@@ -2419,31 +2685,53 @@ void GetCpuName(AString &s)
Cx86cpuid cpuid;
if (x86cpuid_CheckAndRead(&cpuid))
{
x86cpuid_to_String(cpuid, s);
AString s2;
x86cpuid_to_String(cpuid, s2);
s += s2;
return;
}
#ifdef MY_CPU_AMD64
s = "x64";
s += "x64";
#else
s = "x86";
s += "x86";
#endif
}
#else
#ifdef MY_CPU_LE
s = "LE";
s += "LE";
#elif defined(MY_CPU_BE)
s = "BE";
s += "BE";
#endif
#endif
}
void GetCpuFeatures(AString &s)
{
s.Empty();
#ifdef _WIN32
const unsigned kNumFeatures_Extra = 32; // we check also for unknown features
const unsigned kNumFeatures = ARRAY_SIZE(k_PF) + kNumFeatures_Extra;
for (unsigned i = 0; i < kNumFeatures; i++)
{
if (IsProcessorFeaturePresent(i))
{
s.Add_Space_if_NotEmpty();
s += TypeToString2(k_PF, ARRAY_SIZE(k_PF), i);
}
}
#endif
}
HRESULT Bench(
DECL_EXTERNAL_CODECS_LOC_VARS
IBenchPrintCallback *printCallback,
IBenchCallback *benchCallback,
// IBenchFreqCallback *freqCallback,
const CObjectVector<CProperty> &props,
UInt32 numIterations,
bool multiDict)
@@ -2454,8 +2742,16 @@ HRESULT Bench(
UInt32 numCPUs = 1;
UInt64 ramSize = (UInt64)(sizeof(size_t)) << 29;
NSystem::CProcessAffinity threadsInfo;
threadsInfo.InitST();
#ifndef _7ZIP_ST
numCPUs = NSystem::GetNumberOfProcessors();
if (threadsInfo.Get() && threadsInfo.processAffinityMask != 0)
numCPUs = threadsInfo.GetNumProcessThreads();
else
numCPUs = NSystem::GetNumberOfProcessors();
#endif
bool ramSize_Defined = NSystem::GetRamSize(ramSize);
@@ -2477,7 +2773,7 @@ HRESULT Bench(
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"))
@@ -2504,7 +2800,6 @@ HRESULT Bench(
if (printCallback)
{
printCallback->Print("file size =");
// printCallback->Print(GetOemString(property.Value));
PrintNumber(*printCallback, len, 0);
printCallback->NewLine();
}
@@ -2523,14 +2818,14 @@ HRESULT Bench(
if (name.IsEqualTo("time"))
{
RINOK(ParsePropToUInt32(L"", propVariant, testTime));
RINOK(ParsePropToUInt32(UString(), propVariant, testTime));
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;
@@ -2548,19 +2843,12 @@ HRESULT Bench(
if (name.IsPrefixedBy_Ascii_NoCase("mt"))
{
UString s = name.Ptr(2);
if (s == L"*")
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));
#endif
@@ -2573,10 +2861,38 @@ HRESULT Bench(
if (printCallback)
{
AString s;
GetCpuName(s);
printCallback->Print(s);
printCallback->NewLine();
{
AString s1, s2;
GetSysInfo(s1, s2);
if (!s1.IsEmpty() || !s2.IsEmpty())
{
printCallback->Print(s1);
if (s1 != s2 && !s2.IsEmpty())
{
printCallback->Print(" - ");
printCallback->Print(s2);
}
printCallback->NewLine();
}
}
{
AString s;
GetCpuFeatures(s);
if (!s.IsEmpty())
{
printCallback->Print(s);
printCallback->NewLine();
}
}
{
AString s;
GetCpuName(s);
if (!s.IsEmpty())
{
printCallback->Print(s);
printCallback->NewLine();
}
}
}
if (printCallback)
@@ -2586,7 +2902,7 @@ HRESULT Bench(
UInt64 complexInCommands = kComplexInCommands;
if (printCallback /* || benchCallback */)
if (printCallback /* || freqCallback */)
{
UInt64 numMilCommands = 1 << 6;
if (specifiedFreq != 0)
@@ -2623,8 +2939,8 @@ HRESULT Bench(
}
}
/*
if (benchCallback)
benchCallback->AddCpuFreq(mipsVal);
if (freqCallback)
freqCallback->AddCpuFreq(mipsVal);
*/
if (jj >= 3)
@@ -2643,6 +2959,8 @@ HRESULT Bench(
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)
@@ -2669,7 +2987,7 @@ HRESULT Bench(
kOldLzmaDictBits, printCallback, benchCallback, &benchProps);
}
AString methodName = method.MethodName;
AString methodName (method.MethodName);
if (methodName.IsEqualTo_Ascii_NoCase("CRC"))
methodName = "crc32";
method.MethodName = methodName;
@@ -2691,7 +3009,7 @@ HRESULT Bench(
for (unsigned i = 0; i < ARRAY_SIZE(g_Hash); i++)
{
const CBenchHash &h = g_Hash[i];
AString s = h.Name;
AString s (h.Name);
AString hProp;
int propPos = s.Find(':');
if (propPos >= 0)
@@ -2852,6 +3170,7 @@ HRESULT Bench(
}
PrintRequirements(f, "usage:", true, GetBenchMemoryUsage(numThreads, dict, totalBenchMode), "Benchmark threads: ", numThreads);
f.NewLine();
f.NewLine();
@@ -3000,7 +3319,6 @@ HRESULT Bench(
for (unsigned i = 0; i < ARRAY_SIZE(g_Bench); i++)
{
const CBenchMethod &h = g_Bench[i];
AString s = h.Name;
if (AreSameMethodNames(h.Name, methodName))
{
callback.BenchProps.EncComplex = h.EncComplex;
@@ -3040,7 +3358,7 @@ 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;

View File

@@ -3,6 +3,8 @@
#ifndef __7ZIP_BENCH_H
#define __7ZIP_BENCH_H
#include "../../../Windows/System.h"
#include "../../Common/CreateCoder.h"
#include "../../UI/Common/Property.h"
@@ -43,13 +45,28 @@ struct IBenchPrintCallback
virtual HRESULT CheckBreak() = 0;
};
/*
struct IBenchFreqCallback
{
virtual void AddCpuFreq(UInt64 freq) = 0;
};
*/
HRESULT Bench(
DECL_EXTERNAL_CODECS_LOC_VARS
IBenchPrintCallback *printCallback,
IBenchCallback *benchCallback,
// IBenchFreqCallback *freqCallback,
const CObjectVector<CProperty> &props,
UInt32 numIterations,
bool multiDict
);
AString GetProcessThreadsInfo(const NWindows::NSystem::CProcessAffinity &ti);
void GetSysInfo(AString &s1, AString &s2);
void GetCpuName(AString &s);
void GetCpuFeatures(AString &s);
#endif

View File

@@ -30,24 +30,24 @@ using namespace NWindows;
#define MY_TRY_FINISH_VOID } \
catch(...) { ErrorMessageHRESULT(E_FAIL); }
static const char *k7zGui = "7zG.exe";
#define k7zGui "7zG.exe"
static const char *kShowDialogSwitch = " -ad";
static const char *kEmailSwitch = " -seml.";
static const char *kIncludeSwitch = " -i";
static const char *kArchiveTypeSwitch = " -t";
static const char *kArcIncludeSwitches = " -an -ai";
static const char *kHashIncludeSwitches = " -i";
static const char *kStopSwitchParsing = " --";
static const char *kLargePagesDisable = " -slp-";
#define kShowDialogSwitch " -ad"
#define kEmailSwitch " -seml."
#define kIncludeSwitch " -i"
#define kArchiveTypeSwitch " -t"
#define kArcIncludeSwitches " -an -ai"
#define kHashIncludeSwitches " -i"
#define kStopSwitchParsing " --"
#define kLargePagesDisable " -slp-"
extern HWND g_HWND;
UString GetQuotedString(const UString &s)
{
UString s2 = L'\"';
UString s2 ('\"');
s2 += s;
s2 += L'\"';
s2 += '\"';
return s2;
}
@@ -73,7 +73,7 @@ static HRESULT Call7zGui(const UString &params,
NSynchronization::CBaseEvent *event)
{
UString imageName = fs2us(NWindows::NDLL::GetModuleDirPrefix());
imageName.AddAscii(k7zGui);
imageName += k7zGui;
CProcess process;
WRes res = process.Create(imageName, params, NULL); // curDir);
@@ -95,7 +95,7 @@ static HRESULT Call7zGui(const UString &params,
static void AddLagePagesSwitch(UString &params)
{
if (!ReadLockMemoryEnable())
params.AddAscii(kLargePagesDisable);
params += kLargePagesDisable;
}
class CRandNameGenerator
@@ -105,10 +105,8 @@ public:
CRandNameGenerator() { _random.Init(); }
void GenerateName(UString &s, const char *prefix)
{
s.AddAscii(prefix);
char temp[16];
ConvertUInt32ToString((UInt32)(unsigned)_random.Generate(), temp);
s.AddAscii(temp);
s += prefix;
s.Add_UInt32((UInt32)(unsigned)_random.Generate());
}
};
@@ -150,14 +148,14 @@ static HRESULT CreateMap(const UStringVector &names,
event.Close();
}
params += L'#';
params += '#';
params += mappingName;
params += L':';
params += ':';
char temp[32];
ConvertUInt64ToString(totalSize, temp);
params.AddAscii(temp);
params += temp;
params += L':';
params += ':';
params += eventName;
LPVOID data = fileMapping.Map(FILE_MAP_WRITE, 0, totalSize);
@@ -187,36 +185,36 @@ HRESULT CompressFiles(
bool email, bool showDialog, bool waitFinish)
{
MY_TRY_BEGIN
UString params = L'a';
UString params ('a');
CFileMapping fileMapping;
NSynchronization::CManualResetEvent event;
params.AddAscii(kIncludeSwitch);
params += kIncludeSwitch;
RINOK(CreateMap(names, fileMapping, event, params));
if (!arcType.IsEmpty())
{
params.AddAscii(kArchiveTypeSwitch);
params += kArchiveTypeSwitch;
params += arcType;
}
if (email)
params.AddAscii(kEmailSwitch);
params += kEmailSwitch;
if (showDialog)
params.AddAscii(kShowDialogSwitch);
params += kShowDialogSwitch;
AddLagePagesSwitch(params);
if (arcName.IsEmpty())
params.AddAscii(" -an");
params += " -an";
if (addExtension)
params.AddAscii(" -saa");
params += " -saa";
else
params.AddAscii(" -sae");
params += " -sae";
params.AddAscii(kStopSwitchParsing);
params += kStopSwitchParsing;
params.Add_Space();
if (!arcName.IsEmpty())
@@ -237,7 +235,7 @@ HRESULT CompressFiles(
static void ExtractGroupCommand(const UStringVector &arcPaths, UString &params, bool isHash)
{
AddLagePagesSwitch(params);
params.AddAscii(isHash ? kHashIncludeSwitches : kArcIncludeSwitches);
params += (isHash ? kHashIncludeSwitches : kArcIncludeSwitches);
CFileMapping fileMapping;
NSynchronization::CManualResetEvent event;
HRESULT result = CreateMap(arcPaths, fileMapping, event, params);
@@ -250,16 +248,16 @@ static void ExtractGroupCommand(const UStringVector &arcPaths, UString &params,
void ExtractArchives(const UStringVector &arcPaths, const UString &outFolder, bool showDialog, bool elimDup)
{
MY_TRY_BEGIN
UString params = L'x';
UString params ('x');
if (!outFolder.IsEmpty())
{
params.AddAscii(" -o");
params += " -o";
params += GetQuotedString(outFolder);
}
if (elimDup)
params.AddAscii(" -spe");
params += " -spe";
if (showDialog)
params.AddAscii(kShowDialogSwitch);
params += kShowDialogSwitch;
ExtractGroupCommand(arcPaths, params, false);
MY_TRY_FINISH_VOID
}
@@ -267,7 +265,7 @@ void ExtractArchives(const UStringVector &arcPaths, const UString &outFolder, bo
void TestArchives(const UStringVector &arcPaths)
{
MY_TRY_BEGIN
UString params = L't';
UString params ('t');
ExtractGroupCommand(arcPaths, params, false);
MY_TRY_FINISH_VOID
}
@@ -275,10 +273,10 @@ void TestArchives(const UStringVector &arcPaths)
void CalcChecksum(const UStringVector &paths, const UString &methodName)
{
MY_TRY_BEGIN
UString params = L'h';
UString params ('h');
if (!methodName.IsEmpty())
{
params.AddAscii(" -scrc");
params += " -scrc";
params += methodName;
}
ExtractGroupCommand(paths, params, true);
@@ -288,7 +286,10 @@ void CalcChecksum(const UStringVector &paths, const UString &methodName)
void Benchmark(bool totalMode)
{
MY_TRY_BEGIN
HRESULT result = Call7zGui(totalMode ? L"b -mm=*" : L"b", false, NULL);
UString params ('b');
if (totalMode)
params += " -mm=*";
HRESULT result = Call7zGui(params, false, NULL);
if (result != S_OK)
ErrorMessageHRESULT(result);
MY_TRY_FINISH_VOID

View File

@@ -59,9 +59,9 @@ static void ThrowException_if_Error(HRESULT res)
UString GetQuotedString(const UString &s)
{
UString s2 = L'\"';
UString s2 ('\"');
s2 += s;
s2 += L'\"';
s2 += '\"';
return s2;
}
@@ -145,6 +145,7 @@ HRESULT CompressFiles(
return S_OK;
}
static HRESULT ExtractGroupCommand(const UStringVector &arcPaths,
bool showDialog, const UString &outFolder, bool testMode, bool elimDup = false)
{
@@ -192,10 +193,14 @@ static HRESULT ExtractGroupCommand(const UStringVector &arcPaths,
censor.AddPathsToCensor(NWildcard::k_RelatPath);
bool messageWasDisplayed = false;
ecs->MultiArcMode = (arcPathsSorted.Size() > 1);
result = ExtractGUI(codecs,
formatIndices, CIntVector(),
arcPathsSorted, arcFullPathsSorted,
censor.Pairs.Front().Head, eo, NULL, showDialog, messageWasDisplayed, ecs, g_HWND);
if (result != S_OK)
{
if (result != E_ABORT && messageWasDisplayed)
@@ -260,8 +265,8 @@ void Benchmark(bool totalMode)
if (totalMode)
{
CProperty prop;
prop.Name = L"m";
prop.Value = L"*";
prop.Name = "m";
prop.Value = "*";
props.Add(prop);
}
result = Benchmark(EXTERNAL_CODECS_VARS_L props, g_HWND);

View File

@@ -20,9 +20,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),

View File

@@ -213,7 +213,8 @@ HRESULT CDirItems::EnumerateDir(int phyParent, int logParent, const FString &phy
{
RINOK(ScanProgress(phyPrefix));
NFind::CEnumerator enumerator(phyPrefix + FCHAR_ANY_MASK);
NFind::CEnumerator enumerator;
enumerator.SetDirPrefix(phyPrefix);
for (unsigned ttt = 0; ; ttt++)
{
NFind::CFileInfo fi;
@@ -570,7 +571,7 @@ static HRESULT EnumerateDirItems(
#endif
*/
fullPath = FCHAR_PATH_SEPARATOR;
fullPath = CHAR_PATH_SEPARATOR;
}
#if defined(_WIN32) && !defined(UNDER_CE)
else if (item.IsDriveItem())
@@ -682,7 +683,7 @@ static HRESULT EnumerateDirItems(
{
{
if (nextNode.Name.IsEmpty())
fullPath = FCHAR_PATH_SEPARATOR;
fullPath = CHAR_PATH_SEPARATOR;
#ifdef _WIN32
else if (NWildcard::IsDriveColonName(nextNode.Name))
fullPath.Add_PathSepar();
@@ -773,7 +774,9 @@ static HRESULT EnumerateDirItems(
#endif
#endif
NFind::CEnumerator enumerator(phyPrefix + FCHAR_ANY_MASK);
NFind::CEnumerator enumerator;
enumerator.SetDirPrefix(phyPrefix);
for (unsigned ttt = 0; ; ttt++)
{
NFind::CFileInfo fi;

View File

@@ -51,7 +51,7 @@ static HRESULT DecompressArchive(
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
@@ -156,7 +156,7 @@ static HRESULT DecompressArchive(
#endif
if (outDir.IsEmpty())
outDir = FTEXT(".") FSTRING_PATH_SEPARATOR;
outDir = "." STRING_PATH_SEPARATOR;
/*
#ifdef _WIN32
else if (NName::IsAltPathPrefix(outDir)) {}
@@ -167,7 +167,7 @@ static HRESULT DecompressArchive(
HRESULT res = ::GetLastError();
if (res == S_OK)
res = E_FAIL;
errorMessage.SetFromAscii("Can not create output directory: ");
errorMessage = "Can not create output directory: ";
errorMessage += fs2us(outDir);
return res;
}

View File

@@ -8,6 +8,15 @@
#include "ExtractingFilePath.h"
bool g_PathTrailReplaceMode =
#ifdef _WIN32
true
#else
false
#endif
;
static void ReplaceIncorrectChars(UString &s)
{
{
@@ -26,17 +35,42 @@ static void ReplaceIncorrectChars(UString &s)
}
}
#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
@@ -61,7 +95,7 @@ void Correct_AltStream_Name(UString &s)
s.ReplaceOneCharAtPos(i, '_');
}
if (s.IsEmpty())
s = L'_';
s = '_';
}
static const unsigned g_ReservedWithNum_Index = 4;
@@ -120,8 +154,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)
{
@@ -176,11 +210,11 @@ 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
@@ -214,7 +248,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();

View File

@@ -30,17 +30,13 @@ public:
~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;

View File

@@ -81,7 +81,7 @@ using namespace NFile;
#define kFormatsFolderName FTEXT("Formats")
static CFSTR kMainDll =
static CFSTR const kMainDll =
// #ifdef _WIN32
FTEXT("7z.dll");
// #else
@@ -91,9 +91,9 @@ static CFSTR kMainDll =
#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
@@ -516,12 +516,11 @@ HRESULT CCodecs::LoadDll(const FString &dllPath, bool needCheckDll, bool *loaded
}
lib.CreateObject = (Func_CreateObject)lib.Lib.GetProc("CreateObject");
if (lib.CreateObject)
{
unsigned startSize = Codecs.Size() + Hashers.Size();
res = LoadCodecs();
used = (startSize != Codecs.Size() + Hashers.Size());
if (res == S_OK)
if (res == S_OK && lib.CreateObject)
{
startSize = Formats.Size();
res = LoadFormats();
@@ -539,7 +538,8 @@ HRESULT CCodecs::LoadDll(const FString &dllPath, bool needCheckDll, bool *loaded
HRESULT CCodecs::LoadDllsFromFolder(const FString &folderPrefix)
{
NFile::NFind::CEnumerator enumerator(folderPrefix + FCHAR_ANY_MASK);
NFile::NFind::CEnumerator enumerator;
enumerator.SetDirPrefix(folderPrefix);
NFile::NFind::CFileInfo fi;
while (enumerator.Next(fi))
{
@@ -595,7 +595,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,9 +603,9 @@ 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);
}
@@ -866,7 +866,8 @@ STDMETHODIMP CCodecs::CreateDecoder(UInt32 index, const GUID *iid, void **coder)
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
@@ -888,7 +889,8 @@ STDMETHODIMP CCodecs::CreateEncoder(UInt32 index, const GUID *iid, void **coder)
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

View File

@@ -330,17 +330,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 += '.';
s += item.Name;
}
if (!item.Extension.IsEmpty())
{
s += L'.';
s += '.';
s += item.Extension;
}
prop = s; break;
@@ -583,7 +583,7 @@ HRESULT CArc::GetItemPathToParent(UInt32 index, UInt32 parent, UStringVector &pa
{
{
UString &s2 = parts[parts.Size() - 2];
s2 += L':';
s2 += ':';
s2 += parts.Back();
}
parts.DeleteBack();
@@ -733,7 +733,7 @@ HRESULT CArc::GetDefaultItemPath(UInt32 index, UString &result) const
RINOK(Archive->GetProperty(index, kpidExtension, &prop));
if (prop.vt == VT_BSTR)
{
result += L'.';
result += '.';
result += prop.bstrVal;
}
else if (prop.vt != VT_EMPTY)
@@ -1020,10 +1020,11 @@ static void MakeCheckOrder(CCodecs *codecs,
#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
@@ -2318,7 +2319,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;
@@ -2441,6 +2442,9 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
}
}
if (bytesInBuf <= (size_t)posInBuf)
break;
bool useOffsetCallback = false;
if (openCallback_Offset)
{
@@ -2490,17 +2494,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 = 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;
@@ -2540,7 +2546,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;
@@ -2947,10 +2953,10 @@ HRESULT CArc::OpenStream(const COpenOptions &op)
#ifdef _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
@@ -3013,10 +3019,10 @@ HRESULT CArc::OpenStreamOrFile(COpenOptions &op)
if (ai.IsSplit())
continue;
UString path3 = path2;
path3 += L'.';
path3 += '.';
path3 += ai.GetMainExt(); // "7z" for SFX.
Path = path3;
Path.AddAscii(".001");
Path += ".001";
bool isOk = op.callbackSpec->SetSecondFileInfo(us2fs(Path));
if (!isOk)
{

View File

@@ -83,18 +83,17 @@ void ConvertWinAttribToString(char *s, UInt32 wa) throw()
}
}
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;
if ((ft.dwHighDateTime == 0 &&
ft.dwLowDateTime == 0))
return;
ConvertFileTimeToString(localFileTime, dest, true, full);
ConvertUtcFileTimeToString(prop.filetime, dest, level);
return;
}
@@ -158,7 +157,7 @@ void ConvertPropertyToShortString(char *dest, const PROPVARIANT &prop, PROPID pr
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,8 +165,8 @@ 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;
}
static inline unsigned GetHex(unsigned v)
@@ -349,13 +348,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";
@@ -365,8 +360,7 @@ 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_UInt32(Get32(p + 8 + i * 4));
}
}
@@ -536,11 +530,11 @@ bool ConvertNtReparseToString(const Byte *data, UInt32 size, UString &s)
if (attr.Parse(data, size))
{
if (!attr.IsSymLink())
s.AddAscii("Junction: ");
s += "Junction: ";
s += attr.GetPath();
if (!attr.IsOkNamePair())
{
s.AddAscii(" : ");
s += " : ";
s += attr.PrintName;
}
return true;
@@ -557,7 +551,7 @@ bool ConvertNtReparseToString(const Byte *data, UInt32 size, UString &s)
char hex[16];
ConvertUInt32ToHex8Digits(tag, hex);
s.AddAscii(hex);
s += hex;
s.Add_Space();
data += 8;
@@ -565,8 +559,8 @@ bool ConvertNtReparseToString(const Byte *data, UInt32 size, UString &s)
for (UInt32 i = 0; i < len; i++)
{
unsigned b = ((const Byte *)data)[i];
s += (wchar_t)GetHex((b >> 4) & 0xF);
s += (wchar_t)GetHex(b & 0xF);
s += (char)GetHex((b >> 4) & 0xF);
s += (char)GetHex(b & 0xF);
}
return true;
}

View File

@@ -6,8 +6,8 @@
#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);

View File

@@ -4,7 +4,6 @@
#include "Update.h"
#include "../../../Common/IntToString.h"
#include "../../../Common/StringConvert.h"
#include "../../../Windows/DLL.h"
@@ -30,16 +29,19 @@
#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 kUpdateIsNotSupoorted_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");
static CFSTR const kTempFolderPrefix = FTEXT("7zE");
void CUpdateErrorInfo::SetFromLastError(const char *message)
@@ -60,7 +62,8 @@ static bool DeleteEmptyFolderAndEmptySubFolders(const FString &path)
NFind::CFileInfo fileInfo;
FString pathPrefix = path + FCHAR_PATH_SEPARATOR;
{
NFind::CEnumerator enumerator(pathPrefix + FCHAR_ANY_MASK);
NFind::CEnumerator enumerator;
enumerator.SetDirPrefix(pathPrefix);
while (enumerator.Next(fileInfo))
{
if (fileInfo.IsDir())
@@ -156,7 +159,7 @@ bool COutMultiVolStream::SetMTime(const FILETIME *mTime)
STDMETHODIMP COutMultiVolStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
{
if (processedSize != NULL)
if (processedSize)
*processedSize = 0;
while (size > 0)
{
@@ -164,9 +167,8 @@ STDMETHODIMP COutMultiVolStream::Write(const void *data, UInt32 size, UInt32 *pr
{
CAltStreamInfo altStream;
FChar temp[16];
ConvertUInt32ToString(_streamIndex + 1, temp);
FString name = temp;
FString name;
name.Add_UInt32(_streamIndex + 1);
while (name.Len() < 3)
name.InsertAtFront(FTEXT('0'));
name.Insert(0, Prefix);
@@ -218,7 +220,7 @@ STDMETHODIMP COutMultiVolStream::Write(const void *data, UInt32 size, UInt32 *pr
_length = _absPos;
if (_offsetPos > altStream.RealSize)
altStream.RealSize = _offsetPos;
if (processedSize != NULL)
if (processedSize)
*processedSize += realProcessed;
if (altStream.Pos == volSize)
{
@@ -243,7 +245,7 @@ STDMETHODIMP COutMultiVolStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *n
case STREAM_SEEK_END: _absPos = _length + offset; break;
}
_offsetPos = _absPos;
if (newPosition != NULL)
if (newPosition)
*newPosition = _absPos;
_streamIndex = 0;
return S_OK;
@@ -316,7 +318,7 @@ UString CArchivePath::GetFinalPath() const
UString path = GetPathWithoutExt();
if (!BaseExtension.IsEmpty())
{
path += L'.';
path += '.';
path += BaseExtension;
}
return path;
@@ -327,7 +329,7 @@ UString CArchivePath::GetFinalVolPath() const
UString path = GetPathWithoutExt();
if (!BaseExtension.IsEmpty())
{
path += L'.';
path += '.';
path += VolExtension;
}
return path;
@@ -339,17 +341,17 @@ FString CArchivePath::GetTempPath() const
path += us2fs(Name);
if (!BaseExtension.IsEmpty())
{
path += FTEXT('.');
path += '.';
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
@@ -398,7 +400,7 @@ bool CUpdateOptions::SetArcPath(const CCodecs *codecs, const UString &arcPath)
}
UString ext = typeExt;
if (SfxMode)
ext.SetFromAscii(kSFXExtension);
ext = kSFXExtension;
ArchivePath.BaseExtension = ext;
ArchivePath.VolExtension = typeExt;
ArchivePath.ParseFromPath(arcPath, ArcNameMode);
@@ -412,19 +414,43 @@ bool CUpdateOptions::SetArcPath(const CCodecs *codecs, const UString &arcPath)
return true;
}
struct CUpdateProduceCallbackImp: public IUpdateProduceCallback
{
const CObjectVector<CArcItem> *_arcItems;
IUpdateCallbackUI *_callback;
CDirItemsStat *_stat;
CUpdateProduceCallbackImp(
const CObjectVector<CArcItem> *a,
CDirItemsStat *stat,
IUpdateCallbackUI *callback):
_arcItems(a),
_stat(stat),
_callback(callback) {}
CUpdateProduceCallbackImp(const CObjectVector<CArcItem> *a,
IUpdateCallbackUI *callback): _arcItems(a), _callback(callback) {}
virtual HRESULT ShowDeleteFile(unsigned arcIndex);
};
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);
}
@@ -562,6 +588,8 @@ static HRESULT Compress(
UStringVector newNames;
CArcToDoStat stat2;
if (options.RenamePairs.Size() != 0)
{
FOR_VECTOR (i, arcItems)
@@ -595,7 +623,7 @@ static HRESULT Compress(
if (rp.GetNewPath(false, mainName, dest))
{
needRename = true;
dest += L':';
dest += ':';
dest += ai.Name.Ptr(colonPos + 1);
break;
}
@@ -620,17 +648,51 @@ 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];
if (up.NewData)
{
CDirItemsStat &stat = stat2.NewData;
const CDirItem &di = dirItems.Items[up.DirIndex];
if (di.IsDir())
stat.NumDirs++;
else if (di.IsAltStream)
{
stat.NumAltStreams++;
stat.AltStreamsSize += di.Size;
}
else
{
stat.NumFiles++;
stat.FilesSize += di.Size;
}
}
else if (up.ArcIndex >= 0)
{
CDirItemsStat &stat = stat2.OldData;
const CArcItem &ai = arcItems[up.ArcIndex];
if (ai.IsDir)
stat.NumDirs++;
else if (ai.IsAltStream)
{
stat.NumAltStreams++;
stat.AltStreamsSize += ai.Size;
}
else
{
stat.NumFiles++;
stat.FilesSize += ai.Size;
}
}
}
RINOK(callback->SetNumItems(stat2));
}
CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback;
@@ -698,9 +760,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();
}
@@ -734,7 +795,7 @@ static HRESULT Compress(
outStream = outSeekStream;
volStreamSpec->Sizes = options.VolumesSizes;
volStreamSpec->Prefix = us2fs(archivePath.GetFinalVolPath());
volStreamSpec->Prefix += FTEXT('.');
volStreamSpec->Prefix += '.';
volStreamSpec->TempFiles = &tempFiles;
volStreamSpec->Init();
@@ -742,7 +803,7 @@ static HRESULT Compress(
updateCallbackSpec->VolumesSizes = volumesSizes;
updateCallbackSpec->VolName = archivePath.Prefix + archivePath.Name;
if (!archivePath.VolExtension.IsEmpty())
updateCallbackSpec->VolExt = UString(L'.') + archivePath.VolExtension;
updateCallbackSpec->VolExt = UString('.') + archivePath.VolExtension;
*/
}
@@ -1025,7 +1086,7 @@ HRESULT UpdateArchive(
if (options.SfxMode)
{
CProperty property;
property.Name.SetFromAscii("rsfx");
property.Name = "rsfx";
options.MethodMode.Properties.Add(property);
if (options.SfxModule.IsEmpty())
{
@@ -1058,7 +1119,15 @@ 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 += '.';
arcPath += "001";
}
if (cmdArcPath2.IsEmpty())
{
@@ -1085,7 +1154,12 @@ HRESULT UpdateArchive(
if (fi.IsDevice)
return E_NOTIMPL;
if (options.VolumesSizes.Size() > 0)
{
errorInfo.FileNames.Add(us2fs(arcPath));
errorInfo.SystemError = (DWORD)E_NOTIMPL;
errorInfo.Message = kUpdateIsNotSupoorted_MultiVol;
return E_NOTIMPL;
}
CObjectVector<COpenType> types2;
// change it.
if (options.MethodMode.Type_Defined)
@@ -1122,7 +1196,7 @@ HRESULT UpdateArchive(
if (arcLink.VolumePaths.Size() > 1)
{
errorInfo.SystemError = (DWORD)E_NOTIMPL;
errorInfo.Message = "Updating for multivolume archives is not implemented";
errorInfo.Message = kUpdateIsNotSupoorted_MultiVol;
return E_NOTIMPL;
}
@@ -1147,7 +1221,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;
}
@@ -1218,7 +1292,7 @@ HRESULT UpdateArchive(
{
NFind::CFileInfo fi;
FString prefix = us2fs(censor.Pairs[0].Prefix);
prefix += FTEXT('.');
prefix += '.';
// UString prefix = censor.Pairs[0].Prefix;
/*
if (prefix.Back() == WCHAR_PATH_SEPARATOR)
@@ -1353,7 +1427,7 @@ HRESULT UpdateArchive(
if (options.StdOutMode)
{
name.SetFromAscii("stdout");
name = "stdout";
isUpdating = thereIsInArchive;
}
else
@@ -1461,10 +1535,10 @@ HRESULT UpdateArchive(
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);
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);
@@ -1479,7 +1553,7 @@ HRESULT UpdateArchive(
m.nFileCount = 1;
m.lpFiles = &f;
const AString addr = GetAnsiString(options.EMailAddress);
const AString addr (GetAnsiString(options.EMailAddress));
MapiRecipDesc rec;
if (!addr.IsEmpty())
{

View File

@@ -51,6 +51,8 @@ CArchiveUpdateCallback::CArchiveUpdateCallback():
ArcItems(NULL),
UpdatePairs(NULL),
NewNames(NULL),
CommentIndex(-1),
Comment(NULL),
ShareForWrite(false),
StdInMode(false),
@@ -300,7 +302,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++)
{
@@ -396,6 +398,11 @@ STDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PR
}
else if (propID == kpidPath && up.NewNameIndex >= 0)
prop = (*NewNames)[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;
@@ -690,13 +697,13 @@ STDMETHODIMP CArchiveUpdateCallback::GetVolumeSize(UInt32 index, UInt64 *size)
STDMETHODIMP 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 += '.';
fileName += res;
fileName += VolExt;
COutFileStream *streamSpec = new COutFileStream;

View File

@@ -15,6 +15,18 @@
#include "OpenArchive.h"
struct CArcToDoStat
{
CDirItemsStat NewData;
CDirItemsStat OldData;
CDirItemsStat DeleteData;
UInt64 Get_NumDataItems_Total() const
{
return NewData.Get_NumDataItems() + OldData.Get_NumDataItems();
}
};
#define INTERFACE_IUpdateCallbackUI(x) \
virtual HRESULT WriteSfx(const wchar_t *name, UInt64 size) x; \
virtual HRESULT SetTotal(UInt64 size) x; \
@@ -22,7 +34,7 @@
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 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; \
@@ -120,6 +132,8 @@ public:
const CObjectVector<CArcItem> *ArcItems;
const CRecordVector<CUpdatePair2> *UpdatePairs;
const UStringVector *NewNames;
int CommentIndex;
const UString *Comment;
bool ShareForWrite;
bool StdInMode;

View File

@@ -38,14 +38,13 @@ static int MyCompareTime(NFileTimeType::EEnum fileTimeType, const FILETIME &time
throw 4191618;
}
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 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):";
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;

View File

@@ -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,

View File

@@ -16,9 +16,9 @@ using namespace NRegistry;
static NSynchronization::CCriticalSection g_CS;
#define CS_LOCK NSynchronization::CCriticalSectionLock lock(g_CS);
static const TCHAR *kCuPrefix = TEXT("Software") TEXT(STRING_PATH_SEPARATOR) TEXT("7-Zip") TEXT(STRING_PATH_SEPARATOR);
static LPCTSTR const kCuPrefix = TEXT("Software") TEXT(STRING_PATH_SEPARATOR) TEXT("7-Zip") TEXT(STRING_PATH_SEPARATOR);
static CSysString GetKeyPath(const CSysString &path) { return kCuPrefix + path; }
static CSysString GetKeyPath(LPCTSTR path) { return kCuPrefix + (CSysString)path; }
static LONG OpenMainKey(CKey &key, LPCTSTR keyName)
{
@@ -51,16 +51,16 @@ static void Key_Get_BoolPair_true(CKey &key, LPCTSTR name, CBoolPair &b)
namespace NExtract
{
static const TCHAR *kKeyName = TEXT("Extraction");
static LPCTSTR const kKeyName = TEXT("Extraction");
static const TCHAR *kExtractMode = TEXT("ExtractMode");
static const TCHAR *kOverwriteMode = TEXT("OverwriteMode");
static const TCHAR *kShowPassword = TEXT("ShowPassword");
static const TCHAR *kPathHistory = TEXT("PathHistory");
static const TCHAR *kSplitDest = TEXT("SplitDest");
static const TCHAR *kElimDup = TEXT("ElimDup");
// static const TCHAR *kAltStreams = TEXT("AltStreams");
static const TCHAR *kNtSecur = TEXT("Security");
static LPCTSTR const kExtractMode = TEXT("ExtractMode");
static LPCTSTR const kOverwriteMode = TEXT("OverwriteMode");
static LPCTSTR const kShowPassword = TEXT("ShowPassword");
static LPCTSTR const kPathHistory = TEXT("PathHistory");
static LPCTSTR const kSplitDest = TEXT("SplitDest");
static LPCTSTR const kElimDup = TEXT("ElimDup");
// static LPCTSTR const kAltStreams = TEXT("AltStreams");
static LPCTSTR const kNtSecur = TEXT("Security");
void CInfo::Save() const
{
@@ -144,30 +144,30 @@ bool Read_ShowPassword()
namespace NCompression
{
static const TCHAR *kKeyName = TEXT("Compression");
static LPCTSTR const kKeyName = TEXT("Compression");
static const TCHAR *kArcHistory = TEXT("ArcHistory");
static const WCHAR *kArchiver = L"Archiver";
static const TCHAR *kShowPassword = TEXT("ShowPassword");
static const TCHAR *kEncryptHeaders = TEXT("EncryptHeaders");
static LPCTSTR const kArcHistory = TEXT("ArcHistory");
static LPCWSTR const kArchiver = L"Archiver";
static LPCTSTR const kShowPassword = TEXT("ShowPassword");
static LPCTSTR const kEncryptHeaders = TEXT("EncryptHeaders");
static const TCHAR *kOptionsKeyName = TEXT("Options");
static LPCTSTR const kOptionsKeyName = TEXT("Options");
static const TCHAR *kLevel = TEXT("Level");
static const TCHAR *kDictionary = TEXT("Dictionary");
static const TCHAR *kOrder = TEXT("Order");
static const TCHAR *kBlockSize = TEXT("BlockSize");
static const TCHAR *kNumThreads = TEXT("NumThreads");
static const WCHAR *kMethod = L"Method";
static const WCHAR *kOptions = L"Options";
static const WCHAR *kEncryptionMethod = L"EncryptionMethod";
static LPCTSTR const kLevel = TEXT("Level");
static LPCTSTR const kDictionary = TEXT("Dictionary");
static LPCTSTR const kOrder = TEXT("Order");
static LPCTSTR const kBlockSize = TEXT("BlockSize");
static LPCTSTR const kNumThreads = TEXT("NumThreads");
static LPCWSTR const kMethod = L"Method";
static LPCWSTR const kOptions = L"Options";
static LPCWSTR const kEncryptionMethod = L"EncryptionMethod";
static const TCHAR *kNtSecur = TEXT("Security");
static const TCHAR *kAltStreams = TEXT("AltStreams");
static const TCHAR *kHardLinks = TEXT("HardLinks");
static const TCHAR *kSymLinks = TEXT("SymLinks");
static LPCTSTR const kNtSecur = TEXT("Security");
static LPCTSTR const kAltStreams = TEXT("AltStreams");
static LPCTSTR const kHardLinks = TEXT("HardLinks");
static LPCTSTR const kSymLinks = TEXT("SymLinks");
static void SetRegString(CKey &key, const WCHAR *name, const UString &value)
static void SetRegString(CKey &key, LPCWSTR name, const UString &value)
{
if (value.IsEmpty())
key.DeleteValue(name);
@@ -175,7 +175,7 @@ static void SetRegString(CKey &key, const WCHAR *name, const UString &value)
key.SetValue(name, value);
}
static void SetRegUInt32(CKey &key, const TCHAR *name, UInt32 value)
static void SetRegUInt32(CKey &key, LPCTSTR name, UInt32 value)
{
if (value == (UInt32)(Int32)-1)
key.DeleteValue(name);
@@ -183,13 +183,13 @@ static void SetRegUInt32(CKey &key, const TCHAR *name, UInt32 value)
key.SetValue(name, value);
}
static void GetRegString(CKey &key, const WCHAR *name, UString &value)
static void GetRegString(CKey &key, LPCWSTR name, UString &value)
{
if (key.QueryValue(name, value) != ERROR_SUCCESS)
value.Empty();
}
static void GetRegUInt32(CKey &key, const TCHAR *name, UInt32 &value)
static void GetRegUInt32(CKey &key, LPCTSTR name, UInt32 &value)
{
if (key.QueryValue(name, value) != ERROR_SUCCESS)
value = (UInt32)(Int32)-1;
@@ -300,13 +300,13 @@ void CInfo::Load()
}
static const TCHAR *kOptionsInfoKeyName = TEXT("Options");
static LPCTSTR const kOptionsInfoKeyName = TEXT("Options");
namespace NWorkDir
{
static const TCHAR *kWorkDirType = TEXT("WorkDirType");
static const WCHAR *kWorkDirPath = L"WorkDirPath";
static const TCHAR *kTempRemovableOnly = TEXT("TempRemovableOnly");
static LPCTSTR const kWorkDirType = TEXT("WorkDirType");
static LPCWSTR const kWorkDirPath = L"WorkDirPath";
static LPCTSTR const kTempRemovableOnly = TEXT("TempRemovableOnly");
void CInfo::Save()const
@@ -352,10 +352,10 @@ void CInfo::Load()
}
static const TCHAR *kCascadedMenu = TEXT("CascadedMenu");
static const TCHAR *kContextMenu = TEXT("ContextMenu");
static const TCHAR *kMenuIcons = TEXT("MenuIcons");
static const TCHAR *kElimDup = TEXT("ElimDupExtract");
static LPCTSTR const kCascadedMenu = TEXT("CascadedMenu");
static LPCTSTR const kContextMenu = TEXT("ContextMenu");
static LPCTSTR const kMenuIcons = TEXT("MenuIcons");
static LPCTSTR const kElimDup = TEXT("ElimDupExtract");
void CContextMenuInfo::Save() const
{