4.59 beta

This commit is contained in:
Igor Pavlov
2008-08-13 00:00:00 +00:00
committed by Kornel Lesiński
parent 3901bf0ab8
commit 173c07e166
781 changed files with 22124 additions and 13650 deletions

View File

@@ -316,6 +316,10 @@ SOURCE=..\..\..\Windows\System.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\Time.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\Time.h
# End Source File
# End Group

View File

@@ -14,7 +14,7 @@ public:
virtual ~CCtrlHandlerSetter();
};
class CCtrlBreakException
class CCtrlBreakException
{};
void CheckCtrlBreak();

View File

@@ -24,9 +24,9 @@ using namespace NWindows;
using namespace NFile;
using namespace NDirectory;
static const char *kTestingString = "Testing ";
static const char *kExtractingString = "Extracting ";
static const char *kSkippingString = "Skipping ";
static const char *kTestString = "Testing ";
static const char *kExtractString = "Extracting ";
static const char *kSkipString = "Skipping ";
// static const char *kCantAutoRename = "can not create file with auto name\n";
// static const char *kCantRenameFile = "can not rename existing file\n";
@@ -64,7 +64,7 @@ STDMETHODIMP CExtractCallbackConsole::AskOverwrite(
const wchar_t *newName, const FILETIME *, const UInt64 *,
Int32 *answer)
{
(*OutStream) << "file " << existName <<
(*OutStream) << "file " << existName <<
"\nalready exists. Overwrite with " << endl;
(*OutStream) << newName;
@@ -72,25 +72,13 @@ STDMETHODIMP CExtractCallbackConsole::AskOverwrite(
switch(overwriteAnswer)
{
case NUserAnswerMode::kQuit:
return E_ABORT;
case NUserAnswerMode::kNo:
*answer = NOverwriteAnswer::kNo;
break;
case NUserAnswerMode::kNoAll:
*answer = NOverwriteAnswer::kNoToAll;
break;
case NUserAnswerMode::kYesAll:
*answer = NOverwriteAnswer::kYesToAll;
break;
case NUserAnswerMode::kYes:
*answer = NOverwriteAnswer::kYes;
break;
case NUserAnswerMode::kAutoRename:
*answer = NOverwriteAnswer::kAutoRename;
break;
default:
return E_FAIL;
case NUserAnswerMode::kQuit: return E_ABORT;
case NUserAnswerMode::kNo: *answer = NOverwriteAnswer::kNo; break;
case NUserAnswerMode::kNoAll: *answer = NOverwriteAnswer::kNoToAll; break;
case NUserAnswerMode::kYesAll: *answer = NOverwriteAnswer::kYesToAll; break;
case NUserAnswerMode::kYes: *answer = NOverwriteAnswer::kYes; break;
case NUserAnswerMode::kAutoRename: *answer = NOverwriteAnswer::kAutoRename; break;
default: return E_FAIL;
}
return S_OK;
}
@@ -99,15 +87,9 @@ STDMETHODIMP CExtractCallbackConsole::PrepareOperation(const wchar_t *name, bool
{
switch (askExtractMode)
{
case NArchive::NExtract::NAskMode::kExtract:
(*OutStream) << kExtractingString;
break;
case NArchive::NExtract::NAskMode::kTest:
(*OutStream) << kTestingString;
break;
case NArchive::NExtract::NAskMode::kSkip:
(*OutStream) << kSkippingString;
break;
case NArchive::NExtract::NAskMode::kExtract: (*OutStream) << kExtractString; break;
case NArchive::NExtract::NAskMode::kTest: (*OutStream) << kTestString; break;
case NArchive::NExtract::NAskMode::kSkip: (*OutStream) << kSkipString; break;
};
(*OutStream) << name;
if (position != 0)
@@ -154,11 +136,20 @@ STDMETHODIMP CExtractCallbackConsole::SetOperationResult(Int32 operationResult,
return S_OK;
}
#ifndef _NO_CRYPTO
HRESULT CExtractCallbackConsole::SetPassword(const UString &password)
{
PasswordIsDefined = true;
Password = password;
return S_OK;
}
STDMETHODIMP CExtractCallbackConsole::CryptoGetTextPassword(BSTR *password)
{
if (!PasswordIsDefined)
{
Password = GetPassword(OutStream);
Password = GetPassword(OutStream);
PasswordIsDefined = true;
}
CMyComBSTR tempName(Password);
@@ -166,6 +157,8 @@ STDMETHODIMP CExtractCallbackConsole::CryptoGetTextPassword(BSTR *password)
return S_OK;
}
#endif
HRESULT CExtractCallbackConsole::BeforeOpen(const wchar_t *name)
{
NumArchives++;
@@ -180,10 +173,19 @@ HRESULT CExtractCallbackConsole::OpenResult(const wchar_t * /* name */, HRESULT
if (result != S_OK)
{
(*OutStream) << "Error: ";
if (encrypted)
(*OutStream) << "Can not open encrypted archive. Wrong password?";
if (result == S_FALSE)
{
(*OutStream) << (encrypted ?
"Can not open encrypted archive. Wrong password?" :
"Can not open file as archive");
}
else
(*OutStream) << "Can not open file as archive";
{
if (result == E_OUTOFMEMORY)
(*OutStream) << "Can't allocate required memory";
else
(*OutStream) << NError::MyFormatMessage(result);
}
(*OutStream) << endl;
NumArchiveErrors++;
}
@@ -203,7 +205,7 @@ HRESULT CExtractCallbackConsole::ExtractResult(HRESULT result)
(*OutStream) << endl;
if (NumFileErrorsInCurrentArchive == 0)
(*OutStream) << kEverythingIsOk << endl;
else
else
{
NumArchiveErrors++;
(*OutStream) << "Sub items Errors: " << NumFileErrorsInCurrentArchive << endl;
@@ -226,10 +228,3 @@ HRESULT CExtractCallbackConsole::ExtractResult(HRESULT result)
(*OutStream) << endl;
return S_OK;
}
HRESULT CExtractCallbackConsole::SetPassword(const UString &password)
{
PasswordIsDefined = true;
Password = password;
return S_OK;
}

View File

@@ -10,13 +10,20 @@
#include "../../Archive/IArchive.h"
#include "../Common/ArchiveExtractCallback.h"
class CExtractCallbackConsole:
class CExtractCallbackConsole:
public IExtractCallbackUI,
#ifndef _NO_CRYPTO
public ICryptoGetTextPassword,
#endif
public CMyUnknownImp
{
public:
MY_UNKNOWN_IMP2(IFolderArchiveExtractCallback, ICryptoGetTextPassword)
MY_QUERYINTERFACE_BEGIN2(IFolderArchiveExtractCallback)
#ifndef _NO_CRYPTO
MY_QUERYINTERFACE_ENTRY(ICryptoGetTextPassword)
#endif
MY_QUERYINTERFACE_END
MY_ADDREF_RELEASE
STDMETHOD(SetTotal)(UInt64 total);
STDMETHOD(SetCompleted)(const UInt64 *completeValue);
@@ -31,19 +38,20 @@ public:
STDMETHOD(MessageError)(const wchar_t *message);
STDMETHOD(SetOperationResult)(Int32 operationResult, bool encrypted);
// ICryptoGetTextPassword
STDMETHOD(CryptoGetTextPassword)(BSTR *password);
HRESULT BeforeOpen(const wchar_t *name);
HRESULT OpenResult(const wchar_t *name, HRESULT result, bool encrypted);
HRESULT ThereAreNoFiles();
HRESULT ExtractResult(HRESULT result);
#ifndef _NO_CRYPTO
HRESULT SetPassword(const UString &password);
STDMETHOD(CryptoGetTextPassword)(BSTR *password);
public:
bool PasswordIsDefined;
UString Password;
#endif
UInt64 NumArchives;
UInt64 NumArchiveErrors;

View File

@@ -14,6 +14,7 @@
#include "Windows/Defs.h"
#include "Windows/PropVariantConversions.h"
#include "Windows/FileDir.h"
#include "Windows/Error.h"
#include "../../Archive/IArchive.h"
@@ -30,17 +31,17 @@ struct CPropIdToName
const wchar_t *Name;
};
static CPropIdToName kPropIdToName[] =
static CPropIdToName kPropIdToName[] =
{
{ kpidPath, L"Path" },
{ kpidName, L"Name" },
{ kpidIsFolder, L"Folder" },
{ kpidIsDir, L"Folder" },
{ kpidSize, L"Size" },
{ kpidPackedSize, L"Packed Size" },
{ kpidAttributes, L"Attributes" },
{ kpidCreationTime, L"Created" },
{ kpidLastAccessTime, L"Accessed" },
{ kpidLastWriteTime, L"Modified" },
{ kpidPackSize, L"Packed Size" },
{ kpidAttrib, L"Attributes" },
{ kpidCTime, L"Created" },
{ kpidATime, L"Accessed" },
{ kpidMTime, L"Modified" },
{ kpidSolid, L"Solid" },
{ kpidCommented, L"Commented" },
{ kpidEncrypted, L"Encrypted" },
@@ -59,7 +60,7 @@ static CPropIdToName kPropIdToName[] =
{ kpidComment, L"Comment" },
{ kpidPosition, L"Position" },
{ kpidPrefix, L"Prefix" },
{ kpidNumSubFolders, L"Folders" },
{ kpidNumSubDirs, L"Folders" },
{ kpidNumSubFiles, L"Files" },
{ kpidUnpackVer, L"Version" },
{ kpidVolume, L"Volume" },
@@ -67,32 +68,33 @@ static CPropIdToName kPropIdToName[] =
{ kpidOffset, L"Offset" },
{ kpidLinks, L"Links" },
{ kpidNumBlocks, L"Blocks" },
{ kpidNumVolumes, L"Volumes" }
{ kpidNumVolumes, L"Volumes" },
{ kpidBit64, L"64-bit" },
{ kpidBigEndian, L"Big-endian" },
{ kpidCpu, L"CPU" },
{ kpidPhySize, L"Physical Size" },
{ kpidHeadersSize, L"Headers Size" },
{ kpidChecksum, L"Checksum" },
{ kpidCharacts, L"Characteristics" },
{ kpidVa, L"Virtual Address" },
{ kpidFreeSpace, L"Free Space" },
{ kpidClusterSize, L"Cluster Size" }
};
static const char kEmptyAttributeChar = '.';
static const char kDirectoryAttributeChar = 'D';
static const char kReadonlyAttributeChar = 'R';
static const char kHiddenAttributeChar = 'H';
static const char kSystemAttributeChar = 'S';
static const char kArchiveAttributeChar = 'A';
static const char kEmptyAttribChar = '.';
static const char *kListing = "Listing archive: ";
static const wchar_t *kFilesMessage = L"files";
static const wchar_t *kDirsMessage = L"folders";
static void GetAttributesString(DWORD wa, bool directory, char *s)
static void GetAttribString(DWORD wa, bool isDir, char *s)
{
s[0] = ((wa & FILE_ATTRIBUTE_DIRECTORY) != 0 || directory) ?
kDirectoryAttributeChar: kEmptyAttributeChar;
s[1] = ((wa & FILE_ATTRIBUTE_READONLY) != 0)?
kReadonlyAttributeChar: kEmptyAttributeChar;
s[2] = ((wa & FILE_ATTRIBUTE_HIDDEN) != 0) ?
kHiddenAttributeChar: kEmptyAttributeChar;
s[3] = ((wa & FILE_ATTRIBUTE_SYSTEM) != 0) ?
kSystemAttributeChar: kEmptyAttributeChar;
s[4] = ((wa & FILE_ATTRIBUTE_ARCHIVE) != 0) ?
kArchiveAttributeChar: kEmptyAttributeChar;
s[0] = ((wa & FILE_ATTRIBUTE_DIRECTORY) != 0 || isDir) ? 'D' : kEmptyAttribChar;
s[1] = ((wa & FILE_ATTRIBUTE_READONLY) != 0) ? 'R': kEmptyAttribChar;
s[2] = ((wa & FILE_ATTRIBUTE_HIDDEN) != 0) ? 'H': kEmptyAttribChar;
s[3] = ((wa & FILE_ATTRIBUTE_SYSTEM) != 0) ? 'S': kEmptyAttribChar;
s[4] = ((wa & FILE_ATTRIBUTE_ARCHIVE) != 0) ? 'A': kEmptyAttribChar;
s[5] = '\0';
}
@@ -123,12 +125,12 @@ struct CFieldInfoInit
int Width;
};
CFieldInfoInit kStandardFieldTable[] =
CFieldInfoInit kStandardFieldTable[] =
{
{ kpidLastWriteTime, L" Date Time", kLeft, kLeft, 0, 19 },
{ kpidAttributes, L"Attr", kRight, kCenter, 1, 5 },
{ kpidMTime, L" Date Time", kLeft, kLeft, 0, 19 },
{ kpidAttrib, L"Attr", kRight, kCenter, 1, 5 },
{ kpidSize, L"Size", kRight, kRight, 1, 12 },
{ kpidPackedSize, L"Compressed", kRight, kRight, 1, 12 },
{ kpidPackSize, L"Compressed", kRight, kRight, 1, 12 },
{ kpidPath, L"Name", kLeft, kLeft, 2, 24 }
};
@@ -168,12 +170,11 @@ public:
HRESULT Init(IInArchive *archive);
void PrintTitle();
void PrintTitleLines();
HRESULT PrintItemInfo(IInArchive *archive,
HRESULT PrintItemInfo(IInArchive *archive,
const UString &defaultItemName,
const NWindows::NFile::NFind::CFileInfoW &archiveFileInfo,
UInt32 index,
bool techMode);
HRESULT PrintSummaryInfo(UInt64 numFiles, UInt64 numDirs,
HRESULT PrintSummaryInfo(UInt64 numFiles, UInt64 numDirs,
const UInt64 *size, const UInt64 *compressedSize);
};
@@ -204,7 +205,9 @@ static UString GetPropName(PROPID propID, BSTR name)
}
if (name)
return name;
return L"?";
wchar_t s[32];
ConvertUInt64ToString(propID, s);
return s;
}
HRESULT CFieldPrinter::Init(IInArchive *archive)
@@ -232,7 +235,7 @@ void CFieldPrinter::PrintTitle()
{
const CFieldInfo &fieldInfo = _fields[i];
PrintSpaces(fieldInfo.PrefixSpacesWidth);
PrintString(fieldInfo.TitleAdjustment,
PrintString(fieldInfo.TitleAdjustment,
((fieldInfo.PropID == kpidPath) ? 0: fieldInfo.Width), fieldInfo.Name);
}
}
@@ -255,16 +258,16 @@ BOOL IsFileTimeZero(CONST FILETIME *lpFileTime)
}
static const char *kEmptyTimeString = " ";
void PrintTime(const NCOM::CPropVariant &propVariant)
void PrintTime(const NCOM::CPropVariant &prop)
{
if (propVariant.vt != VT_FILETIME)
if (prop.vt != VT_FILETIME)
throw "incorrect item";
if (IsFileTimeZero(&propVariant.filetime))
if (IsFileTimeZero(&prop.filetime))
g_StdOut << kEmptyTimeString;
else
{
FILETIME localFileTime;
if (!FileTimeToLocalFileTime(&propVariant.filetime, &localFileTime))
if (!FileTimeToLocalFileTime(&prop.filetime, &localFileTime))
throw "FileTimeToLocalFileTime error";
char s[32];
if (ConvertFileTimeToString(localFileTime, s, true, true))
@@ -274,9 +277,8 @@ void PrintTime(const NCOM::CPropVariant &propVariant)
}
}
HRESULT CFieldPrinter::PrintItemInfo(IInArchive *archive,
const UString &defaultItemName,
const NWindows::NFile::NFind::CFileInfoW &archiveFileInfo,
HRESULT CFieldPrinter::PrintItemInfo(IInArchive *archive,
const UString &defaultItemName,
UInt32 index,
bool techMode)
{
@@ -294,32 +296,27 @@ HRESULT CFieldPrinter::PrintItemInfo(IInArchive *archive,
if (!techMode)
PrintSpaces(fieldInfo.PrefixSpacesWidth);
NCOM::CPropVariant propVariant;
NCOM::CPropVariant prop;
if (fieldInfo.PropID == kpidPath)
{
UString s;
RINOK(GetArchiveItemPath(archive, index, defaultItemName, s));
propVariant = s;
prop = s;
}
else
{
RINOK(archive->GetProperty(index, fieldInfo.PropID, &propVariant));
RINOK(archive->GetProperty(index, fieldInfo.PropID, &prop));
}
if (techMode)
{
g_StdOut << fieldInfo.Name << " = ";
}
int width = (fieldInfo.PropID == kpidPath) ? 0: fieldInfo.Width;
if (propVariant.vt == VT_EMPTY)
if (prop.vt == VT_EMPTY)
{
switch(fieldInfo.PropID)
{
case kpidPath:
propVariant = defaultItemName;
break;
case kpidLastWriteTime:
propVariant = archiveFileInfo.LastWriteTime;
break;
case kpidPath: prop = defaultItemName; break;
default:
if (techMode)
g_StdOut << endl;
@@ -328,33 +325,33 @@ HRESULT CFieldPrinter::PrintItemInfo(IInArchive *archive,
continue;
}
}
if (fieldInfo.PropID == kpidLastWriteTime)
if (fieldInfo.PropID == kpidMTime)
{
PrintTime(propVariant);
PrintTime(prop);
}
else if (fieldInfo.PropID == kpidAttributes)
else if (fieldInfo.PropID == kpidAttrib)
{
if (propVariant.vt != VT_UI4)
if (prop.vt != VT_UI4)
throw "incorrect item";
UInt32 attributes = propVariant.ulVal;
UInt32 attributes = prop.ulVal;
bool isFolder;
RINOK(IsArchiveItemFolder(archive, index, isFolder));
char s[8];
GetAttributesString(attributes, isFolder, s);
GetAttribString(attributes, isFolder, s);
g_StdOut << s;
}
else if (propVariant.vt == VT_BSTR)
else if (prop.vt == VT_BSTR)
{
if (techMode)
g_StdOut << propVariant.bstrVal;
g_StdOut << prop.bstrVal;
else
PrintString(fieldInfo.TextAdjustment, width, propVariant.bstrVal);
PrintString(fieldInfo.TextAdjustment, width, prop.bstrVal);
}
else
{
UString s = ConvertPropertyToString(propVariant, fieldInfo.PropID);
s.Replace(wchar_t(0xA), L' ');
s.Replace(wchar_t(0xD), L' ');
UString s = ConvertPropertyToString(prop, fieldInfo.PropID);
s.Replace(wchar_t(0xA), L' ');
s.Replace(wchar_t(0xD), L' ');
if (techMode)
g_StdOut << s;
@@ -376,17 +373,17 @@ void PrintNumberString(EAdjustment adjustment, int width, const UInt64 *value)
}
HRESULT CFieldPrinter::PrintSummaryInfo(UInt64 numFiles, UInt64 numDirs,
HRESULT CFieldPrinter::PrintSummaryInfo(UInt64 numFiles, UInt64 numDirs,
const UInt64 *size, const UInt64 *compressedSize)
{
for (int i = 0; i < _fields.Size(); i++)
{
const CFieldInfo &fieldInfo = _fields[i];
PrintSpaces(fieldInfo.PrefixSpacesWidth);
NCOM::CPropVariant propVariant;
NCOM::CPropVariant prop;
if (fieldInfo.PropID == kpidSize)
PrintNumberString(fieldInfo.TextAdjustment, fieldInfo.Width, size);
else if (fieldInfo.PropID == kpidPackedSize)
else if (fieldInfo.PropID == kpidPackSize)
PrintNumberString(fieldInfo.TextAdjustment, fieldInfo.Width, compressedSize);
else if (fieldInfo.PropID == kpidPath)
{
@@ -402,7 +399,7 @@ HRESULT CFieldPrinter::PrintSummaryInfo(UInt64 numFiles, UInt64 numDirs,
temp += kDirsMessage;
PrintString(fieldInfo.TextAdjustment, 0, temp);
}
else
else
PrintString(fieldInfo.TextAdjustment, fieldInfo.Width, L"");
}
return S_OK;
@@ -410,20 +407,23 @@ HRESULT CFieldPrinter::PrintSummaryInfo(UInt64 numFiles, UInt64 numDirs,
bool GetUInt64Value(IInArchive *archive, UInt32 index, PROPID propID, UInt64 &value)
{
NCOM::CPropVariant propVariant;
if (archive->GetProperty(index, propID, &propVariant) != S_OK)
NCOM::CPropVariant prop;
if (archive->GetProperty(index, propID, &prop) != S_OK)
throw "GetPropertyValue error";
if (propVariant.vt == VT_EMPTY)
if (prop.vt == VT_EMPTY)
return false;
value = ConvertPropVariantToUInt64(propVariant);
value = ConvertPropVariantToUInt64(prop);
return true;
}
HRESULT ListArchives(
CCodecs *codecs,
HRESULT ListArchives(CCodecs *codecs, const CIntVector &formatIndices,
UStringVector &archivePaths, UStringVector &archivePathsFull,
const NWildcard::CCensorNode &wildcardCensor,
bool enableHeaders, bool techMode, bool &passwordEnabled, UString &password, UInt64 &numErrors)
bool enableHeaders, bool techMode,
#ifndef _NO_CRYPTO
bool &passwordEnabled, UString &password,
#endif
UInt64 &numErrors)
{
numErrors = 0;
CFieldPrinter fieldPrinter;
@@ -435,14 +435,8 @@ HRESULT ListArchives(
for (int i = 0; i < archivePaths.Size(); i++)
{
const UString &archiveName = archivePaths[i];
NFile::NFind::CFileInfoW archiveFileInfo;
if (!NFile::NFind::FindFile(archiveName, archiveFileInfo) || archiveFileInfo.IsDirectory())
{
g_StdOut << endl << "Error: " << archiveName << " is not archive" << endl;
numErrors++;
continue;
}
if (archiveFileInfo.IsDirectory())
NFile::NFind::CFileInfoW fi;
if (!NFile::NFind::FindFile(archiveName, fi) || fi.IsDir())
{
g_StdOut << endl << "Error: " << archiveName << " is not file" << endl;
numErrors++;
@@ -453,13 +447,27 @@ HRESULT ListArchives(
COpenCallbackConsole openCallback;
openCallback.OutStream = &g_StdOut;
#ifndef _NO_CRYPTO
openCallback.PasswordIsDefined = passwordEnabled;
openCallback.Password = password;
HRESULT result = MyOpenArchive(codecs, archiveName, archiveLink, &openCallback);
#endif
HRESULT result = MyOpenArchive(codecs, formatIndices, archiveName, archiveLink, &openCallback);
if (result != S_OK)
{
g_StdOut << endl << "Error: " << archiveName << " is not supported archive" << endl;
if (result == E_ABORT)
return result;
g_StdOut << endl << "Error: " << archiveName << ": ";
if (result == S_FALSE)
g_StdOut << "is not supported archive";
else if (result == E_OUTOFMEMORY)
g_StdOut << "Can't allocate required memory";
else
g_StdOut << NError::MyFormatMessage(result);
g_StdOut << endl;
numErrors++;
continue;
}
@@ -534,14 +542,14 @@ HRESULT ListArchives(
if (!wildcardCensor.CheckPath(filePath, !isFolder))
continue;
fieldPrinter.PrintItemInfo(archive, defaultItemName, archiveFileInfo, i, techMode);
fieldPrinter.PrintItemInfo(archive, defaultItemName, i, techMode);
UInt64 packSize, unpackSize;
if (!GetUInt64Value(archive, i, kpidSize, unpackSize))
unpackSize = 0;
else
totalUnPackSizePointer = &totalUnPackSize;
if (!GetUInt64Value(archive, i, kpidPackedSize, packSize))
if (!GetUInt64Value(archive, i, kpidPackSize, packSize))
packSize = 0;
else
totalPackSizePointer = &totalPackSize;

View File

@@ -6,11 +6,14 @@
#include "Common/Wildcard.h"
#include "../Common/LoadCodecs.h"
HRESULT ListArchives(
CCodecs *codecs,
HRESULT ListArchives(CCodecs *codecs, const CIntVector &formatIndices,
UStringVector &archivePaths, UStringVector &archivePathsFull,
const NWildcard::CCensorNode &wildcardCensor,
bool enableHeaders, bool techMode, bool &passwordEnabled, UString &password, UInt64 &errors);
bool enableHeaders, bool techMode,
#ifndef _NO_CRYPTO
bool &passwordEnabled, UString &password,
#endif
UInt64 &errors);
#endif

View File

@@ -40,8 +40,8 @@
#include "../../MyVersion.h"
#if defined( _WIN32) && defined( _7ZIP_LARGE_PAGES)
extern "C"
{
extern "C"
{
#include "../../../../C/Alloc.h"
}
#endif
@@ -64,7 +64,7 @@ static const char *kCopyrightString = "\n7-Zip"
" " MY_VERSION_COPYRIGHT_DATE "\n";
static const char *kHelpString =
static const char *kHelpString =
"\nUsage: 7z"
#ifdef _NO_CRYPTO
"r"
@@ -96,7 +96,9 @@ static const char *kHelpString =
" -i[r[-|0]]{@listfile|!wildcard}: Include filenames\n"
" -m{Parameters}: set compression Method\n"
" -o{Directory}: set Output directory\n"
#ifndef _NO_CRYPTO
" -p{Password}: set Password\n"
#endif
" -r[-|0]: Recurse subdirectories\n"
" -scs{UTF-8 | WIN | DOS}: set charset for list files\n"
" -sfx[{name}]: Create SFX archive\n"
@@ -117,6 +119,7 @@ static const char *kHelpString =
static const char *kEverythingIsOk = "Everything is Ok";
static const char *kUserErrorMessage = "Incorrect command line"; // NExitCode::kUserError
static const char *kNoFormats = "7-Zip cannot find the code that works with archives.";
static const wchar_t *kDefaultSfxModule = L"7zCon.sfx";
@@ -148,7 +151,7 @@ static void ShowCopyrightAndHelp(CStdOutStream &s, bool needHelp)
{
s << kCopyrightString;
// s << "# CPUs: " << (UInt64)NWindows::NSystem::GetNumberOfProcessors() << "\n";
if (needHelp)
if (needHelp)
s << kHelpString;
}
@@ -175,18 +178,20 @@ static inline char GetHex(Byte value)
return (char)((value < 10) ? ('0' + value) : ('A' + (value - 10)));
}
const char *kUnsupportedArcTypeMessage = "Unsupported archive type";
int Main2(
#ifndef _WIN32
#ifndef _WIN32
int numArguments, const char *arguments[]
#endif
)
{
#ifdef _WIN32
#ifdef _WIN32
SetFileApisToOEM();
#endif
UStringVector commandStrings;
#ifdef _WIN32
#ifdef _WIN32
NCommandLineParser::SplitCommandLine(GetCommandLineW(), commandStrings);
#else
GetArguments(numArguments, arguments, commandStrings);
@@ -240,6 +245,17 @@ int Main2(
throw CSystemException(result);
bool isExtractGroupCommand = options.Command.IsFromExtractGroup();
if (codecs->Formats.Size() == 0 &&
(isExtractGroupCommand ||
options.Command.CommandType == NCommandType::kList ||
options.Command.IsFromUpdateGroup()))
throw kNoFormats;
CIntVector formatIndices;
if (!codecs->FindFormatForArchiveType(options.ArcType, formatIndices))
throw kUnsupportedArcTypeMessage;
if (options.Command.CommandType == NCommandType::kInfo)
{
stdStream << endl << "Formats:" << endl;
@@ -373,14 +389,21 @@ int Main2(
CMyComPtr<IFolderArchiveExtractCallback> extractCallback = ecs;
ecs->OutStream = &stdStream;
#ifndef _NO_CRYPTO
ecs->PasswordIsDefined = options.PasswordEnabled;
ecs->Password = options.Password;
#endif
ecs->Init();
COpenCallbackConsole openCallback;
openCallback.OutStream = &stdStream;
#ifndef _NO_CRYPTO
openCallback.PasswordIsDefined = options.PasswordEnabled;
openCallback.Password = options.Password;
#endif
CExtractOptions eo;
eo.StdOutMode = options.StdOutMode;
@@ -396,9 +419,10 @@ int Main2(
CDecompressStat stat;
HRESULT result = DecompressArchives(
codecs,
options.ArchivePathsSorted,
formatIndices,
options.ArchivePathsSorted,
options.ArchivePathsFullSorted,
options.WildcardCensor.Pairs.Front().Head,
options.WildcardCensor.Pairs.Front().Head,
eo, &openCallback, ecs, errorMessage, stat);
if (!errorMessage.IsEmpty())
{
@@ -430,7 +454,7 @@ int Main2(
stdStream << "Folders: " << stat.NumFolders << endl;
if (stat.NumFiles != 1 || stat.NumFolders != 0)
stdStream << "Files: " << stat.NumFiles << endl;
stdStream
stdStream
<< "Size: " << stat.UnpackSize << endl
<< "Compressed: " << stat.PackSize << endl;
}
@@ -439,13 +463,17 @@ int Main2(
UInt64 numErrors = 0;
HRESULT result = ListArchives(
codecs,
options.ArchivePathsSorted,
formatIndices,
options.ArchivePathsSorted,
options.ArchivePathsFullSorted,
options.WildcardCensor.Pairs.Front().Head,
options.EnableHeaders,
options.WildcardCensor.Pairs.Front().Head,
options.EnableHeaders,
options.TechMode,
options.PasswordEnabled,
options.Password, numErrors);
#ifndef _NO_CRYPTO
options.PasswordEnabled,
options.Password,
#endif
numErrors);
if (numErrors > 0)
{
g_StdOut << endl << "Errors: " << numErrors;
@@ -463,28 +491,33 @@ int Main2(
if (uo.SfxMode && uo.SfxModule.IsEmpty())
uo.SfxModule = kDefaultSfxModule;
bool passwordIsDefined =
options.PasswordEnabled && !options.Password.IsEmpty();
COpenCallbackConsole openCallback;
openCallback.OutStream = &stdStream;
#ifndef _NO_CRYPTO
bool passwordIsDefined =
options.PasswordEnabled && !options.Password.IsEmpty();
openCallback.PasswordIsDefined = passwordIsDefined;
openCallback.Password = options.Password;
#endif
CUpdateCallbackConsole callback;
callback.EnablePercents = options.EnablePercents;
#ifndef _NO_CRYPTO
callback.PasswordIsDefined = passwordIsDefined;
callback.AskPassword = options.PasswordEnabled && options.Password.IsEmpty();
callback.Password = options.Password;
#endif
callback.StdOutMode = uo.StdOutMode;
callback.Init(&stdStream);
CUpdateErrorInfo errorInfo;
if (!uo.Init(codecs, options.ArchiveName, options.ArcType))
throw "Unsupported archive type";
HRESULT result = UpdateArchive(codecs,
options.WildcardCensor, uo,
if (!uo.Init(codecs, formatIndices, options.ArchiveName))
throw kUnsupportedArcTypeMessage;
HRESULT result = UpdateArchive(codecs,
options.WildcardCensor, uo,
errorInfo, &openCallback, &callback);
int exitCode = NExitCode::kSuccess;
@@ -557,7 +590,7 @@ int Main2(
}
return exitCode;
}
else
else
PrintHelpAndExit(stdStream);
return 0;
}

View File

@@ -28,7 +28,7 @@ static inline bool IsItWindowsNT()
{
OSVERSIONINFO versionInfo;
versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);
if (!::GetVersionEx(&versionInfo))
if (!::GetVersionEx(&versionInfo))
return false;
return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);
}
@@ -36,7 +36,7 @@ static inline bool IsItWindowsNT()
#endif
extern int Main2(
#ifndef _WIN32
#ifndef _WIN32
int numArguments, const char *arguments[]
#endif
);
@@ -50,7 +50,7 @@ static const char *kInternalExceptionMessage = "\n\nInternal Error #";
int MY_CDECL main
(
#ifndef _WIN32
#ifndef _WIN32
int numArguments, const char *arguments[]
#endif
)
@@ -62,7 +62,7 @@ int numArguments, const char *arguments[]
#ifndef _WIN64
if (!IsItWindowsNT())
{
(*g_StdStream) << "This program requires Windows NT/2000/XP/2003/Vista";
(*g_StdStream) << "This program requires Windows NT/2000/2003/2008/XP/Vista";
return NExitCode::kFatalError;
}
#endif
@@ -112,7 +112,7 @@ int numArguments, const char *arguments[]
}
UString message;
NError::MyFormatMessage(systemError.ErrorCode, message);
(*g_StdStream) << endl << endl << "System error:" << endl <<
(*g_StdStream) << endl << endl << "System error:" << endl <<
message << endl;
return (NExitCode::kFatalError);
}

View File

@@ -7,30 +7,32 @@
#include "ConsoleClose.h"
#include "UserInputUtils.h"
HRESULT COpenCallbackConsole::CheckBreak()
HRESULT COpenCallbackConsole::Open_CheckBreak()
{
if (NConsoleClose::TestBreakSignal())
return E_ABORT;
return S_OK;
}
HRESULT COpenCallbackConsole::SetTotal(const UInt64 *, const UInt64 *)
HRESULT COpenCallbackConsole::Open_SetTotal(const UInt64 *, const UInt64 *)
{
return CheckBreak();
return Open_CheckBreak();
}
HRESULT COpenCallbackConsole::SetCompleted(const UInt64 *, const UInt64 *)
HRESULT COpenCallbackConsole::Open_SetCompleted(const UInt64 *, const UInt64 *)
{
return CheckBreak();
return Open_CheckBreak();
}
HRESULT COpenCallbackConsole::CryptoGetTextPassword(BSTR *password)
#ifndef _NO_CRYPTO
HRESULT COpenCallbackConsole::Open_CryptoGetTextPassword(BSTR *password)
{
PasswordWasAsked = true;
RINOK(CheckBreak());
RINOK(Open_CheckBreak());
if (!PasswordIsDefined)
{
Password = GetPassword(OutStream);
Password = GetPassword(OutStream);
PasswordIsDefined = true;
}
CMyComBSTR temp(Password);
@@ -38,21 +40,21 @@ HRESULT COpenCallbackConsole::CryptoGetTextPassword(BSTR *password)
return S_OK;
}
HRESULT COpenCallbackConsole::GetPasswordIfAny(UString &password)
HRESULT COpenCallbackConsole::Open_GetPasswordIfAny(UString &password)
{
if (PasswordIsDefined)
password = Password;
return S_OK;
}
bool COpenCallbackConsole::WasPasswordAsked()
bool COpenCallbackConsole::Open_WasPasswordAsked()
{
return PasswordWasAsked;
}
void COpenCallbackConsole::ClearPasswordWasAskedFlag()
void COpenCallbackConsole::Open_ClearPasswordWasAskedFlag()
{
PasswordWasAsked = false;
}
#endif

View File

@@ -9,19 +9,16 @@
class COpenCallbackConsole: public IOpenCallbackUI
{
public:
HRESULT CheckBreak();
HRESULT SetTotal(const UInt64 *files, const UInt64 *bytes);
HRESULT SetCompleted(const UInt64 *files, const UInt64 *bytes);
HRESULT CryptoGetTextPassword(BSTR *password);
HRESULT GetPasswordIfAny(UString &password);
bool WasPasswordAsked();
void ClearPasswordWasAskedFlag();
INTERFACE_IOpenCallbackUI(;)
CStdOutStream *OutStream;
#ifndef _NO_CRYPTO
bool PasswordIsDefined;
UString Password;
bool PasswordWasAsked;
UString Password;
COpenCallbackConsole(): PasswordIsDefined(false), PasswordWasAsked(false) {}
#endif
};
#endif

View File

@@ -65,25 +65,25 @@ void CPercentPrinter::RePrintRatio()
int i;
if (m_NumExtraChars == 0)
{
for (i = 0; i < extraSize; i++)
for (i = 0; i < extraSize; i++)
*p++ = ' ';
m_NumExtraChars = extraSize;
}
for (i = 0; i < m_NumExtraChars; i++)
for (i = 0; i < m_NumExtraChars; i++)
*p++ = '\b';
m_NumExtraChars = extraSize;
for (; size < m_NumExtraChars; size++)
*p++ = ' ';
MyStringCopy(p, s);
(*OutStream) << fullString;
OutStream->Flush();
OutStream->Flush();
m_PrevValue = m_CurValue;
}
void CPercentPrinter::PrintRatio()
{
if (m_CurValue < m_PrevValue + m_MinStepSize &&
if (m_CurValue < m_PrevValue + m_MinStepSize &&
m_CurValue + m_MinStepSize > m_PrevValue && m_NumExtraChars != 0)
return;
RePrintRatio();

View File

@@ -16,7 +16,7 @@ class CPercentPrinter
public:
CStdOutStream *OutStream;
CPercentPrinter(UInt64 minStepSize = 1): m_MinStepSize(minStepSize),
CPercentPrinter(UInt64 minStepSize = 1): m_MinStepSize(minStepSize),
m_PrevValue(0), m_CurValue(0), m_Total(1), m_NumExtraChars(0) {}
void SetTotal(UInt64 total) { m_Total = total; m_PrevValue = 0; }
void SetRatio(UInt64 doneValue) { m_CurValue = doneValue; }

View File

@@ -6,4 +6,4 @@
#include "../../../Common/MyWindows.h"
#include "../../../Common/NewHandler.h"
#endif
#endif

View File

@@ -42,6 +42,11 @@ HRESULT CUpdateCallbackConsole::StartScanning()
return S_OK;
}
HRESULT CUpdateCallbackConsole::ScanProgress(UInt64 /* numFolders */, UInt64 /* numFiles */, const wchar_t * /* path */)
{
return CheckBreak();
}
HRESULT CUpdateCallbackConsole::CanNotFindError(const wchar_t *name, DWORD systemError)
{
CantFindFiles.Add(name);
@@ -71,7 +76,7 @@ HRESULT CUpdateCallbackConsole::StartArchive(const wchar_t *name, bool updating)
if(updating)
(*OutStream) << kUpdatingArchiveMessage;
else
(*OutStream) << kCreatingArchiveMessage;
(*OutStream) << kCreatingArchiveMessage;
if (name != 0)
(*OutStream) << name;
else
@@ -186,21 +191,32 @@ HRESULT CUpdateCallbackConsole::SetOperationResult(Int32 )
{
m_NeedBeClosed = true;
m_NeedNewLine = true;
return S_OK;
return S_OK;
}
HRESULT CUpdateCallbackConsole::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password)
{
if (!PasswordIsDefined)
#ifdef _NO_CRYPTO
*passwordIsDefined = false;
CMyComBSTR tempName(L"");
*password = tempName.Detach();
#else
if (!PasswordIsDefined)
{
if (AskPassword)
{
Password = GetPassword(OutStream);
Password = GetPassword(OutStream);
PasswordIsDefined = true;
}
}
*passwordIsDefined = BoolToInt(PasswordIsDefined);
CMyComBSTR tempName(Password);
*password = tempName.Detach();
#endif
return S_OK;
}

View File

@@ -21,15 +21,18 @@ public:
bool EnablePercents;
bool StdOutMode;
#ifndef _NO_CRYPTO
bool PasswordIsDefined;
UString Password;
bool AskPassword;
#endif
CUpdateCallbackConsole():
CUpdateCallbackConsole():
m_PercentPrinter(1 << 16),
#ifndef _NO_CRYPTO
PasswordIsDefined(false),
AskPassword(false),
#endif
StdOutMode(false),
EnablePercents(true),
m_WarningsMode(false)

View File

@@ -15,7 +15,7 @@ static const char kAutoRename = 'U';
static const char kQuit = 'Q';
static const char *kFirstQuestionMessage = "?\n";
static const char *kHelpQuestionMessage =
static const char *kHelpQuestionMessage =
"(Y)es / (N)o / (A)lways / (S)kip all / A(u)to rename / (Q)uit? ";
// return true if pressed Quite;
@@ -54,5 +54,5 @@ UString GetPassword(CStdOutStream *outStream)
(*outStream) << "\nEnter password:";
outStream->Flush();
AString oemPassword = g_StdIn.ScanStringUntilNewLine();
return MultiByteToUnicodeString(oemPassword, CP_OEMCP);
return MultiByteToUnicodeString(oemPassword, CP_OEMCP);
}

View File

@@ -1 +0,0 @@
#include <winresrc.h>

View File

@@ -47,6 +47,7 @@ WIN_OBJS = \
$O\PropVariantConversions.obj \
$O\Registry.obj \
$O\System.obj \
$O\Time.obj \
7ZIP_COMMON_OBJS = \
$O\FilePathAutoRename.obj \