This commit is contained in:
Igor Pavlov
2018-05-02 22:28:04 +01:00
committed by Kornel
parent f19b649c73
commit 18dc2b4161
121 changed files with 3523 additions and 1866 deletions

View File

@@ -8,9 +8,17 @@
#ifndef UNDER_CE
#include <io.h>
#endif
#else
// for isatty()
#include <unistd.h>
#endif
#include <stdio.h>
#ifdef _7ZIP_LARGE_PAGES
#include "../../../../C/Alloc.h"
#endif
#include "../../../Common/ListFileUtils.h"
#include "../../../Common/StringConvert.h"
#include "../../../Common/StringToInt.h"
@@ -19,18 +27,20 @@
#include "../../../Windows/FileName.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;
bool g_LargePagesMode = false;
#ifdef UNDER_CE
#define MY_IS_TERMINAL(x) false;
@@ -60,15 +70,6 @@ static bool StringToUInt32(const wchar_t *s, UInt32 &v)
return *end == 0;
}
CArcCmdLineException::CArcCmdLineException(const char *a, const wchar_t *u)
{
(*this) += a;
if (u)
{
Add_LF();
(*this) += u;
}
}
int g_CodePage = -1;
@@ -240,7 +241,7 @@ static const CSwitchForm kSwitchForms[] =
{ "si", NSwitchType::kString },
{ "so" },
{ "slp", NSwitchType::kMinus },
{ "slp", NSwitchType::kString },
{ "scs", NSwitchType::kString },
{ "scc", NSwitchType::kString },
{ "slt" },
@@ -282,7 +283,6 @@ static const char * const kIncorrectListFile = "Incorrect item in listfile.\nChe
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
{
@@ -615,84 +615,6 @@ static void AddSwitchWildcardsToCensor(
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)
{
@@ -922,9 +844,45 @@ void CArcCmdLineParser::Parse1(const UStringVector &commandStrings,
options.CaseSensitive = g_CaseSensitive;
}
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;
{
unsigned 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 _7ZIP_LARGE_PAGES
if (slp >
#ifndef UNDER_CE
(unsigned)NSecurity::Get_LargePages_RiskLevel()
#else
0
#endif
)
{
SetLargePageSize();
// 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
@@ -996,64 +954,6 @@ static Int32 FindCharset(const NCommandLineParser::CParser &parser, unsigned key
}
}
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)
{

View File

@@ -6,14 +6,13 @@
#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,7 +50,7 @@ struct CArcCmdLineOptions
{
bool HelpMode;
bool LargePages;
// bool LargePages;
bool CaseSensitiveChange;
bool CaseSensitive;
@@ -110,7 +109,7 @@ struct CArcCmdLineOptions
UInt32 NumIterations;
CArcCmdLineOptions():
LargePages(false),
// LargePages(false),
CaseSensitiveChange(false),
CaseSensitive(false),
@@ -134,13 +133,4 @@ public:
void Parse2(CArcCmdLineOptions &options);
};
HRESULT EnumerateDirItemsAndSort(
NWildcard::CCensor &censor,
NWildcard::ECensorPathMode pathMode,
const UString &addPathPrefix,
UStringVector &sortedPaths,
UStringVector &sortedFullPaths,
CDirItemsStat &st,
IDirItemsCallback *callback);
#endif

View File

@@ -2602,7 +2602,8 @@ static void SysInfo_To_String(AString &s, const SYSTEM_INFO &si)
PrintHex(s, si.wProcessorLevel);
s += ".";
PrintHex(s, si.wProcessorRevision);
if (si.dwActiveProcessorMask + 1 != ((UInt64)1 << si.dwNumberOfProcessors))
if ((UInt64)si.dwActiveProcessorMask + 1 != ((UInt64)1 << si.dwNumberOfProcessors))
if ((UInt64)si.dwActiveProcessorMask + 1 != 0 || si.dwNumberOfProcessors != sizeof(UInt64) * 8)
{
s += " act:";
PrintHex(s, si.dwActiveProcessorMask);
@@ -2686,13 +2687,15 @@ void GetCpuName(AString &s)
AString s2;
x86cpuid_to_String(cpuid, s2);
s += s2;
return;
}
else
{
#ifdef MY_CPU_AMD64
s += "x64";
#else
s += "x86";
#endif
}
}
#else
@@ -2703,6 +2706,9 @@ void GetCpuName(AString &s)
#endif
#endif
if (g_LargePagesMode)
s += " (LP)";
}
@@ -2725,6 +2731,27 @@ void GetCpuFeatures(AString &s)
}
#ifdef _WIN32
#ifndef UNDER_CE
typedef void (WINAPI * Func_RtlGetVersion) (OSVERSIONINFOEXW *);
static BOOL My_RtlGetVersion(OSVERSIONINFOEXW *vi)
{
HMODULE ntdll = ::GetModuleHandleW(L"ntdll.dll");
if (!ntdll)
return FALSE;
Func_RtlGetVersion func = (Func_RtlGetVersion)GetProcAddress(ntdll, "RtlGetVersion");
if (!func)
return FALSE;
func(vi);
return TRUE;
}
#endif
#endif
HRESULT Bench(
DECL_EXTERNAL_CODECS_LOC_VARS
IBenchPrintCallback *printCallback,
@@ -2859,6 +2886,30 @@ HRESULT Bench(
if (printCallback)
{
#ifdef _WIN32
#ifndef UNDER_CE
{
AString s;
// OSVERSIONINFO vi;
OSVERSIONINFOEXW vi;
vi.dwOSVersionInfoSize = sizeof(vi);
// if (::GetVersionEx(&vi))
if (My_RtlGetVersion(&vi))
{
s += "Windows";
if (vi.dwPlatformId != VER_PLATFORM_WIN32_NT)
s.Add_UInt32(vi.dwPlatformId);
s += " "; s.Add_UInt32(vi.dwMajorVersion);
s += "."; s.Add_UInt32(vi.dwMinorVersion);
s += " "; s.Add_UInt32(vi.dwBuildNumber);
// s += " "; s += GetAnsiString(vi.szCSDVersion);
}
printCallback->Print(s);
printCallback->NewLine();
}
#endif
#endif
{
AString s1, s2;
GetSysInfo(s1, s2);

View File

@@ -13,6 +13,7 @@
#include "../../../Windows/ErrorMsg.h"
#include "../../../Windows/FileDir.h"
#include "../../../Windows/FileMapping.h"
#include "../../../Windows/MemoryLock.h"
#include "../../../Windows/ProcessUtils.h"
#include "../../../Windows/Synchronization.h"
@@ -94,6 +95,9 @@ static HRESULT Call7zGui(const UString &params,
static void AddLagePagesSwitch(UString &params)
{
if (ReadLockMemoryEnable())
#ifndef UNDER_CE
if (NSecurity::Get_LargePages_RiskLevel() == 0)
#endif
params += " -slp";
}

View File

@@ -1,10 +1,10 @@
// CompressCall.cpp
// CompressCall2.cpp
#include "StdAfx.h"
#include "../../../Common/MyException.h"
#include "../../UI/common/ArchiveCommandLine.h"
#include "../../UI/Common/EnumDirItems.h"
#include "../../UI/GUI/BenchmarkDialog.h"
#include "../../UI/GUI/ExtractGUI.h"
@@ -20,6 +20,7 @@ extern HWND g_HWND;
#define MY_TRY_BEGIN HRESULT result; try {
#define MY_TRY_FINISH } \
catch(CSystemException &e) { result = e.ErrorCode; } \
catch(UString &s) { ErrorMessage(s); result = E_FAIL; } \
catch(...) { result = E_FAIL; } \
if (result != S_OK && result != E_ABORT) \
ErrorMessageHRESULT(result);

View File

@@ -16,6 +16,7 @@
#endif
#include "EnumDirItems.h"
#include "SortUtils.h"
using namespace NWindows;
using namespace NFile;
@@ -925,3 +926,161 @@ void CDirItems::FillFixedReparse()
}
#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
// 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
CMessagePathException::CMessagePathException(const char *a, const wchar_t *u)
{
(*this) += a;
if (u)
{
Add_LF();
(*this) += u;
}
}

View File

@@ -18,4 +18,24 @@ HRESULT EnumerateItems(
const UString &addPathPrefix,
CDirItems &dirItems);
struct CMessagePathException: public UString
{
CMessagePathException(const char *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

View File

@@ -9,7 +9,6 @@
#include "../../Common/MethodProps.h"
#include "DirItem.h"
#include "Property.h"
const unsigned k_HashCalc_DigestSize_Max = 64;

View File

@@ -992,7 +992,7 @@ static void MakeCheckOrder(CCodecs *codecs,
int index = orderIndices[i];
if (index < 0)
continue;
const CArcInfoEx &ai = codecs->Formats[index];
const CArcInfoEx &ai = codecs->Formats[(unsigned)index];
if (ai.SignatureOffset != 0)
{
orderIndices2.Add(index);
@@ -2295,7 +2295,7 @@ 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];
bool isDifficult = false;
// if (ai.Version < 0x91F) // we don't use parser with old DLL (before 9.31)
if (!ai.NewInterface)
@@ -2327,7 +2327,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
if (isDifficult)
{
difficultFormats.Add(index);
difficultBools[index] = true;
difficultBools[(unsigned)index] = true;
}
}

View File

@@ -369,7 +369,7 @@ static void ParseSid(AString &s, const Byte *p, UInt32 lim, UInt32 &sidSize)
int index = FindPairIndex(sid_32_Names, ARRAY_SIZE(sid_32_Names), v1);
if (index >= 0)
{
s += sid_32_Names[index].sz;
s += sid_32_Names[(unsigned)index].sz;
return;
}
}
@@ -379,7 +379,7 @@ static void ParseSid(AString &s, const Byte *p, UInt32 lim, UInt32 &sidSize)
int index = FindPairIndex(sid_21_Names, ARRAY_SIZE(sid_21_Names), v4);
if (index >= 0)
{
s += sid_21_Names[index].sz;
s += sid_21_Names[(unsigned)index].sz;
return;
}
}
@@ -630,7 +630,7 @@ bool ConvertNtReparseToString(const Byte *data, UInt32 size, UString &s)
{
int index = FindPairIndex(k_ReparseTags, ARRAY_SIZE(k_ReparseTags), tag);
if (index >= 0)
s += k_ReparseTags[index].sz;
s += k_ReparseTags[(unsigned)index].sz;
else
{
s += "REPARSE:";

View File

@@ -1046,10 +1046,6 @@ static HRESULT EnumerateInArchiveItems(
#endif
#ifdef _WIN32
void ConvertToLongNames(NWildcard::CCensor &censor);
#endif
HRESULT UpdateArchive(
CCodecs *codecs,
const CObjectVector<COpenType> &types,