summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/lzma/CPP/7zip/UI/Client7z/Client7z.cpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/lzma/CPP/7zip/UI/Client7z/Client7z.cpp')
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Client7z/Client7z.cpp245
1 files changed, 156 insertions, 89 deletions
diff --git a/3rdparty/lzma/CPP/7zip/UI/Client7z/Client7z.cpp b/3rdparty/lzma/CPP/7zip/UI/Client7z/Client7z.cpp
index d181843d178..55650cfa0fe 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Client7z/Client7z.cpp
+++ b/3rdparty/lzma/CPP/7zip/UI/Client7z/Client7z.cpp
@@ -2,39 +2,54 @@
#include "StdAfx.h"
-#include "Common/IntToString.h"
-#include "Common/MyInitGuid.h"
-#include "Common/StringConvert.h"
-
-#include "Windows/DLL.h"
-#include "Windows/FileDir.h"
-#include "Windows/FileFind.h"
-#include "Windows/FileName.h"
-#include "Windows/NtCheck.h"
-#include "Windows/PropVariant.h"
-#include "Windows/PropVariantConversions.h"
+#include <stdio.h>
+
+#include "../../../Common/MyWindows.h"
+
+#include "../../../Common/Defs.h"
+#include "../../../Common/MyInitGuid.h"
+
+#include "../../../Common/IntToString.h"
+#include "../../../Common/StringConvert.h"
+
+#include "../../../Windows/DLL.h"
+#include "../../../Windows/FileDir.h"
+#include "../../../Windows/FileFind.h"
+#include "../../../Windows/FileName.h"
+#include "../../../Windows/NtCheck.h"
+#include "../../../Windows/PropVariant.h"
+#include "../../../Windows/PropVariantConv.h"
#include "../../Common/FileStreams.h"
#include "../../Archive/IArchive.h"
#include "../../IPassword.h"
-#include "../../MyVersion.h"
+#include "../../../../C/7zVersion.h"
#ifdef _WIN32
HINSTANCE g_hInstance = 0;
#endif
+// Tou can find the list of all GUIDs in Guid.txt file.
// use another CLSIDs, if you want to support other formats (zip, rar, ...).
// {23170F69-40C1-278A-1000-000110070000}
+
DEFINE_GUID(CLSID_CFormat7z,
0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x07, 0x00, 0x00);
+DEFINE_GUID(CLSID_CFormatXz,
+ 0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x0C, 0x00, 0x00);
+
+#define CLSID_Format CLSID_CFormat7z
+// #define CLSID_Format CLSID_CFormatXz
using namespace NWindows;
+using namespace NFile;
+using namespace NDir;
#define kDllName "7z.dll"
-static const char *kCopyrightString = "\n" MY_7ZIP_VERSION
+static const char *kCopyrightString = "\n7-Zip " MY_VERSION
" (" kDllName " client) "
MY_COPYRIGHT " " MY_DATE "\n";
@@ -46,12 +61,6 @@ static const char *kHelpString =
" Client7z.exe x archive.7z : eXtract files from archive.7z\n";
-typedef UINT32 (WINAPI * CreateObjectFunc)(
- const GUID *clsID,
- const GUID *interfaceID,
- void **outObject);
-
-
static AString FStringToConsoleString(const FString &s)
{
return GetOemString(fs2us(s));
@@ -177,7 +186,11 @@ static const char *kSkippingString = "Skipping ";
static const char *kUnsupportedMethod = "Unsupported Method";
static const char *kCRCFailed = "CRC Failed";
static const char *kDataError = "Data Error";
-static const char *kUnknownError = "Unknown Error";
+static const char *kUnavailableData = "Unavailable data";
+static const char *kUnexpectedEnd = "Unexpected end of data";
+static const char *kDataAfterEnd = "There are some data after the end of the payload data";
+static const char *kIsNotArc = "Is not archive";
+static const char *kHeadersError = "Headers Error";
class CArchiveExtractCallback:
public IArchiveExtractCallback,
@@ -232,7 +245,7 @@ void CArchiveExtractCallback::Init(IInArchive *archiveHandler, const FString &di
NumErrors = 0;
_archiveHandler = archiveHandler;
_directoryPath = directoryPath;
- NFile::NName::NormalizeDirPathPrefix(_directoryPath);
+ NName::NormalizeDirPathPrefix(_directoryPath);
}
STDMETHODIMP CArchiveExtractCallback::SetTotal(UInt64 /* size */)
@@ -296,7 +309,7 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index,
NCOM::CPropVariant prop;
RINOK(_archiveHandler->GetProperty(index, kpidMTime, &prop));
_processedFileInfo.MTimeDefined = false;
- switch(prop.vt)
+ switch (prop.vt)
{
case VT_EMPTY:
// _processedFileInfo.MTime = _utcMTimeDefault;
@@ -314,18 +327,16 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index,
// Get Size
NCOM::CPropVariant prop;
RINOK(_archiveHandler->GetProperty(index, kpidSize, &prop));
- bool newFileSizeDefined = (prop.vt != VT_EMPTY);
UInt64 newFileSize;
- if (newFileSizeDefined)
- newFileSize = ConvertPropVariantToUInt64(prop);
+ /* bool newFileSizeDefined = */ ConvertPropVariantToUInt64(prop, newFileSize);
}
{
// Create folders for file
- int slashPos = _filePath.ReverseFind(WCHAR_PATH_SEPARATOR);
+ int slashPos = _filePath.ReverseFind_PathSepar();
if (slashPos >= 0)
- NFile::NDirectory::CreateComplexDirectory(_directoryPath + us2fs(_filePath.Left(slashPos)));
+ CreateComplexDir(_directoryPath + us2fs(_filePath.Left(slashPos)));
}
FString fullProcessedPath = _directoryPath + us2fs(_filePath);
@@ -333,14 +344,14 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index,
if (_processedFileInfo.isDir)
{
- NFile::NDirectory::CreateComplexDirectory(fullProcessedPath);
+ CreateComplexDir(fullProcessedPath);
}
else
{
- NFile::NFind::CFileInfo fi;
+ NFind::CFileInfo fi;
if (fi.Find(fullProcessedPath))
{
- if (!NFile::NDirectory::DeleteFileAlways(fullProcessedPath))
+ if (!DeleteFileAlways(fullProcessedPath))
{
PrintError("Can not delete output file", fullProcessedPath);
return E_ABORT;
@@ -379,32 +390,58 @@ STDMETHODIMP CArchiveExtractCallback::PrepareOperation(Int32 askExtractMode)
STDMETHODIMP CArchiveExtractCallback::SetOperationResult(Int32 operationResult)
{
- switch(operationResult)
+ switch (operationResult)
{
case NArchive::NExtract::NOperationResult::kOK:
break;
default:
{
NumErrors++;
- PrintString(" ");
- switch(operationResult)
+ PrintString(" : ");
+ const char *s = NULL;
+ switch (operationResult)
{
- case NArchive::NExtract::NOperationResult::kUnSupportedMethod:
- PrintString(kUnsupportedMethod);
+ case NArchive::NExtract::NOperationResult::kUnsupportedMethod:
+ s = kUnsupportedMethod;
break;
case NArchive::NExtract::NOperationResult::kCRCError:
- PrintString(kCRCFailed);
+ s = kCRCFailed;
break;
case NArchive::NExtract::NOperationResult::kDataError:
- PrintString(kDataError);
+ s = kDataError;
+ break;
+ case NArchive::NExtract::NOperationResult::kUnavailable:
+ s = kUnavailableData;
+ break;
+ case NArchive::NExtract::NOperationResult::kUnexpectedEnd:
+ s = kUnexpectedEnd;
+ break;
+ case NArchive::NExtract::NOperationResult::kDataAfterEnd:
+ s = kDataAfterEnd;
+ break;
+ case NArchive::NExtract::NOperationResult::kIsNotArc:
+ s = kIsNotArc;
+ break;
+ case NArchive::NExtract::NOperationResult::kHeadersError:
+ s = kHeadersError;
break;
- default:
- PrintString(kUnknownError);
+ }
+ if (s)
+ {
+ PrintString("Error : ");
+ PrintString(s);
+ }
+ else
+ {
+ char temp[16];
+ ConvertUInt32ToString(operationResult, temp);
+ PrintString("Error #");
+ PrintString(temp);
}
}
}
- if (_outFileStream != NULL)
+ if (_outFileStream)
{
if (_processedFileInfo.MTimeDefined)
_outFileStreamSpec->SetMTime(&_processedFileInfo.MTime);
@@ -412,7 +449,7 @@ STDMETHODIMP CArchiveExtractCallback::SetOperationResult(Int32 operationResult)
}
_outFileStream.Release();
if (_extractMode && _processedFileInfo.AttribDefined)
- NFile::NDirectory::MySetFileAttributes(_diskFilePath, _processedFileInfo.Attrib);
+ SetFileAttrib(_diskFilePath, _processedFileInfo.Attrib);
PrintNewLine();
return S_OK;
}
@@ -462,7 +499,6 @@ public:
STDMETHOD(SetCompleted)(const UInt64 *completeValue);
// IUpdateCallback2
- STDMETHOD(EnumProperties)(IEnumSTATPROPSTG **enumerator);
STDMETHOD(GetUpdateItemInfo)(UInt32 index,
Int32 *newData, Int32 *newProperties, UInt32 *indexInArchive);
STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value);
@@ -514,21 +550,15 @@ STDMETHODIMP CArchiveUpdateCallback::SetCompleted(const UInt64 * /* completeValu
return S_OK;
}
-
-STDMETHODIMP CArchiveUpdateCallback::EnumProperties(IEnumSTATPROPSTG ** /* enumerator */)
-{
- return E_NOTIMPL;
-}
-
STDMETHODIMP CArchiveUpdateCallback::GetUpdateItemInfo(UInt32 /* index */,
Int32 *newData, Int32 *newProperties, UInt32 *indexInArchive)
{
- if (newData != NULL)
+ if (newData)
*newData = BoolToInt(true);
- if (newProperties != NULL)
+ if (newProperties)
*newProperties = BoolToInt(true);
- if (indexInArchive != NULL)
- *indexInArchive = (UInt32)-1;
+ if (indexInArchive)
+ *indexInArchive = (UInt32)(Int32)-1;
return S_OK;
}
@@ -545,7 +575,7 @@ STDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PR
{
const CDirItem &dirItem = (*DirItems)[index];
- switch(propID)
+ switch (propID)
{
case kpidPath: prop = dirItem.Name; break;
case kpidIsDir: prop = dirItem.isDir(); break;
@@ -632,8 +662,8 @@ STDMETHODIMP CArchiveUpdateCallback::GetVolumeStream(UInt32 index, ISequentialOu
wchar_t temp[16];
ConvertUInt32ToString(index + 1, temp);
UString res = temp;
- while (res.Length() < 2)
- res = UString(L'0') + res;
+ while (res.Len() < 2)
+ res.InsertAtFront(L'0');
UString fileName = VolName;
fileName += L'.';
fileName += res;
@@ -663,7 +693,7 @@ STDMETHODIMP CArchiveUpdateCallback::CryptoGetTextPassword2(Int32 *passwordIsDef
return StringToBstr(Password, password);
}
-//////////////////////////////////////////////////////////////////////////
+
// Main function
#define NT_CHECK_FAIL_ACTION PrintError("Unsupported Windows version"); return 1;
@@ -679,14 +709,16 @@ int MY_CDECL main(int numArgs, const char *args[])
PrintStringLn(kHelpString);
return 1;
}
+
NDLL::CLibrary lib;
if (!lib.Load(NDLL::GetModuleDirPrefix() + FTEXT(kDllName)))
{
PrintError("Can not load 7-zip library");
return 1;
}
- CreateObjectFunc createObjectFunc = (CreateObjectFunc)lib.GetProc("CreateObject");
- if (createObjectFunc == 0)
+
+ Func_CreateObject createObjectFunc = (Func_CreateObject)lib.GetProc("CreateObject");
+ if (!createObjectFunc)
{
PrintError("Can not get CreateObject");
return 1;
@@ -695,15 +727,17 @@ int MY_CDECL main(int numArgs, const char *args[])
char c;
{
AString command = args[1];
- if (command.Length() != 1)
+ if (command.Len() != 1)
{
PrintError("incorrect command");
return 1;
}
- c = (char)MyCharUpper(command[0]);
+ c = (char)MyCharLower_Ascii(command[0]);
}
+
FString archiveName = CmdStringToFString(args[2]);
- if (c == 'A')
+
+ if (c == 'a')
{
// create archive command
if (numArgs < 4)
@@ -712,28 +746,31 @@ int MY_CDECL main(int numArgs, const char *args[])
return 1;
}
CObjectVector<CDirItem> dirItems;
- int i;
- for (i = 3; i < numArgs; i++)
{
- CDirItem di;
- FString name = CmdStringToFString(args[i]);
-
- NFile::NFind::CFileInfo fi;
- if (!fi.Find(name))
+ int i;
+ for (i = 3; i < numArgs; i++)
{
- PrintError("Can't find file", name);
- return 1;
+ CDirItem di;
+ FString name = CmdStringToFString(args[i]);
+
+ NFind::CFileInfo fi;
+ if (!fi.Find(name))
+ {
+ PrintError("Can't find file", name);
+ return 1;
+ }
+
+ di.Attrib = fi.Attrib;
+ di.Size = fi.Size;
+ di.CTime = fi.CTime;
+ di.ATime = fi.ATime;
+ di.MTime = fi.MTime;
+ di.Name = fs2us(name);
+ di.FullPath = name;
+ dirItems.Add(di);
}
-
- di.Attrib = fi.Attrib;
- di.Size = fi.Size;
- di.CTime = fi.CTime;
- di.ATime = fi.ATime;
- di.MTime = fi.MTime;
- di.Name = fs2us(name);
- di.FullPath = name;
- dirItems.Add(di);
}
+
COutFileStream *outFileStreamSpec = new COutFileStream;
CMyComPtr<IOutStream> outFileStream = outFileStreamSpec;
if (!outFileStreamSpec->Create(archiveName, false))
@@ -743,7 +780,7 @@ int MY_CDECL main(int numArgs, const char *args[])
}
CMyComPtr<IOutArchive> outArchive;
- if (createObjectFunc(&CLSID_CFormat7z, &IID_IOutArchive, (void **)&outArchive) != S_OK)
+ if (createObjectFunc(&CLSID_Format, &IID_IOutArchive, (void **)&outArchive) != S_OK)
{
PrintError("Can not get class object");
return 1;
@@ -762,7 +799,7 @@ int MY_CDECL main(int numArgs, const char *args[])
L"s",
L"x"
};
- const int kNumProps = sizeof(names) / sizeof(names[0]);
+ const unsigned kNumProps = ARRAY_SIZE(names);
NCOM::CPropVariant values[kNumProps] =
{
false, // solid mode OFF
@@ -780,17 +817,21 @@ int MY_CDECL main(int numArgs, const char *args[])
*/
HRESULT result = outArchive->UpdateItems(outFileStream, dirItems.Size(), updateCallback);
+
updateCallbackSpec->Finilize();
+
if (result != S_OK)
{
PrintError("Update Error");
return 1;
}
- for (i = 0; i < updateCallbackSpec->FailedFiles.Size(); i++)
+
+ FOR_VECTOR (i, updateCallbackSpec->FailedFiles)
{
PrintNewLine();
PrintError("Error for file", updateCallbackSpec->FailedFiles[i]);
}
+
if (updateCallbackSpec->FailedFiles.Size() != 0)
return 1;
}
@@ -803,9 +844,10 @@ int MY_CDECL main(int numArgs, const char *args[])
}
bool listCommand;
- if (c == 'L')
+
+ if (c == 'l')
listCommand = true;
- else if (c == 'X')
+ else if (c == 'x')
listCommand = false;
else
{
@@ -814,7 +856,7 @@ int MY_CDECL main(int numArgs, const char *args[])
}
CMyComPtr<IInArchive> archive;
- if (createObjectFunc(&CLSID_CFormat7z, &IID_IInArchive, (void **)&archive) != S_OK)
+ if (createObjectFunc(&CLSID_Format, &IID_IInArchive, (void **)&archive) != S_OK)
{
PrintError("Can not get class object");
return 1;
@@ -836,7 +878,8 @@ int MY_CDECL main(int numArgs, const char *args[])
// openCallbackSpec->PasswordIsDefined = true;
// openCallbackSpec->Password = L"1";
- if (archive->Open(file, 0, openCallback) != S_OK)
+ const UInt64 scanSize = 1 << 23;
+ if (archive->Open(file, &scanSize, openCallback) != S_OK)
{
PrintError("Can not open file as archive", archiveName);
return 1;
@@ -854,7 +897,8 @@ int MY_CDECL main(int numArgs, const char *args[])
// Get uncompressed size of file
NCOM::CPropVariant prop;
archive->GetProperty(i, kpidSize, &prop);
- UString s = ConvertPropVariantToString(prop);
+ char s[32];
+ ConvertPropVariantToShortString(prop, s);
PrintString(s);
PrintString(" ");
}
@@ -862,8 +906,10 @@ int MY_CDECL main(int numArgs, const char *args[])
// Get name of file
NCOM::CPropVariant prop;
archive->GetProperty(i, kpidPath, &prop);
- UString s = ConvertPropVariantToString(prop);
- PrintString(s);
+ if (prop.vt == VT_BSTR)
+ PrintString(prop.bstrVal);
+ else if (prop.vt != VT_EMPTY)
+ PrintString("ERROR!");
}
PrintNewLine();
}
@@ -877,7 +923,27 @@ int MY_CDECL main(int numArgs, const char *args[])
extractCallbackSpec->PasswordIsDefined = false;
// extractCallbackSpec->PasswordIsDefined = true;
// extractCallbackSpec->Password = L"1";
+
+ /*
+ const wchar_t *names[] =
+ {
+ L"mt",
+ L"mtf"
+ };
+ const unsigned kNumProps = sizeof(names) / sizeof(names[0]);
+ NCOM::CPropVariant values[kNumProps] =
+ {
+ (UInt32)1,
+ false
+ };
+ CMyComPtr<ISetProperties> setProperties;
+ archive->QueryInterface(IID_ISetProperties, (void **)&setProperties);
+ if (setProperties)
+ setProperties->SetProperties(names, values, kNumProps);
+ */
+
HRESULT result = archive->Extract(NULL, (UInt32)(Int32)(-1), false, extractCallback);
+
if (result != S_OK)
{
PrintError("Extract Error");
@@ -885,5 +951,6 @@ int MY_CDECL main(int numArgs, const char *args[])
}
}
}
+
return 0;
}