This commit is contained in:
Igor Pavlov
2005-05-30 00:00:00 +00:00
committed by Kornel Lesiński
parent 8c1b5c7b7e
commit 3c510ba80b
926 changed files with 40559 additions and 23519 deletions

View File

@@ -13,45 +13,40 @@
#include "Windows/PropVariant.h"
#include "Windows/Defs.h"
#include "Windows/PropVariantConversions.h"
#include "Windows/FileDir.h"
#include "../../Archive/IArchive.h"
#include "../Common/PropIDUtils.h"
#include "../Common/OpenArchive.h"
#include "OpenCallbackConsole.h"
using namespace NWindows;
/*
static const char kEmptyFlag = '.';
static const char kPasswordFlag = '*';
static const char kSolidFlag = 'S';
static const char kSplitBeforeFlag = 'B';
static const char kSplitAfterFlag = 'A';
static const char kCommentedFlag = 'C';
*/
static const char kEmptyAttributeChar = '.';
//static const char kVolumeAttributeChar = 'V';
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 AString GetAttributesString(DWORD winAttributes, bool directory)
static const char *kListing = "Listing archive: ";
static const wchar_t *kFilesMessage = L"files";
static void GetAttributesString(DWORD wa, bool directory, char *s)
{
AString s;
// s = ((winAttributes & kLabelFileAttribute) != 0) ?
// kVolumeAttributeChar: kEmptyAttributeChar;
s += ((winAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0 || directory) ?
kDirectoryAttributeChar: kEmptyAttributeChar;
s += ((winAttributes & FILE_ATTRIBUTE_READONLY) != 0)?
kReadonlyAttributeChar: kEmptyAttributeChar;
s += ((winAttributes & FILE_ATTRIBUTE_HIDDEN) != 0) ?
kHiddenAttributeChar: kEmptyAttributeChar;
s += ((winAttributes & FILE_ATTRIBUTE_SYSTEM) != 0) ?
kSystemAttributeChar: kEmptyAttributeChar;
s += ((winAttributes & FILE_ATTRIBUTE_ARCHIVE) != 0) ?
kArchiveAttributeChar: kEmptyAttributeChar;
return 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[5] = '\0';
}
enum EAdjustment
@@ -127,9 +122,9 @@ public:
HRESULT PrintItemInfo(IInArchive *archive,
const UString &defaultItemName,
const NWindows::NFile::NFind::CFileInfoW &archiveFileInfo,
UINT32 index);
HRESULT PrintSummaryInfo(UINT64 numFiles, const UINT64 *size,
const UINT64 *compressedSize);
UInt32 index);
HRESULT PrintSummaryInfo(UInt64 numFiles, const UInt64 *size,
const UInt64 *compressedSize);
};
void CFieldPrinter::Init(const CFieldInfoInit *standardFieldTable, int numItems)
@@ -155,7 +150,8 @@ void CFieldPrinter::PrintTitle()
{
const CFieldInfo &fieldInfo = _fields[i];
PrintSpaces(fieldInfo.PrefixSpacesWidth);
PrintString(fieldInfo.TitleAdjustment, fieldInfo.Width, fieldInfo.Name);
PrintString(fieldInfo.TitleAdjustment,
((fieldInfo.PropID == kpidPath) ? 0: fieldInfo.Width), fieldInfo.Name);
}
}
@@ -176,8 +172,7 @@ BOOL IsFileTimeZero(CONST FILETIME *lpFileTime)
return (lpFileTime->dwLowDateTime == 0) && (lpFileTime->dwHighDateTime == 0);
}
const char *kEmptyTimeString = " ";
static const char *kEmptyTimeString = " ";
void PrintTime(const NCOM::CPropVariant &propVariant)
{
if (propVariant.vt != VT_FILETIME)
@@ -189,14 +184,9 @@ void PrintTime(const NCOM::CPropVariant &propVariant)
FILETIME localFileTime;
if (!FileTimeToLocalFileTime(&propVariant.filetime, &localFileTime))
throw "FileTimeToLocalFileTime error";
SYSTEMTIME st;
if (FileTimeToSystemTime(&localFileTime, &st))
{
char s[32];
wsprintfA(s, "%04u-%02u-%02u %02u:%02u:%02u",
st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
char s[32];
if (ConvertFileTimeToString(localFileTime, s, true, true))
g_StdOut << s;
}
else
g_StdOut << kEmptyTimeString;
}
@@ -205,7 +195,7 @@ void PrintTime(const NCOM::CPropVariant &propVariant)
HRESULT CFieldPrinter::PrintItemInfo(IInArchive *archive,
const UString &defaultItemName,
const NWindows::NFile::NFind::CFileInfoW &archiveFileInfo,
UINT32 index)
UInt32 index)
{
for (int i = 0; i < _fields.Size(); i++)
{
@@ -213,8 +203,8 @@ HRESULT CFieldPrinter::PrintItemInfo(IInArchive *archive,
PrintSpaces(fieldInfo.PrefixSpacesWidth);
NCOM::CPropVariant propVariant;
RINOK(archive->GetProperty(index,
fieldInfo.PropID, &propVariant));
RINOK(archive->GetProperty(index, fieldInfo.PropID, &propVariant));
int width = (fieldInfo.PropID == kpidPath) ? 0: fieldInfo.Width;
if (propVariant.vt == VT_EMPTY)
{
switch(fieldInfo.PropID)
@@ -226,7 +216,7 @@ HRESULT CFieldPrinter::PrintItemInfo(IInArchive *archive,
propVariant = archiveFileInfo.LastWriteTime;
break;
default:
PrintSpaces(fieldInfo.Width);
PrintSpaces(width);
continue;
}
}
@@ -240,39 +230,37 @@ HRESULT CFieldPrinter::PrintItemInfo(IInArchive *archive,
{
if (propVariant.vt != VT_UI4)
throw "incorrect item";
UINT32 attributes = propVariant.ulVal;
NCOM::CPropVariant propVariantIsFolder;
RINOK(archive->GetProperty(index,
kpidIsFolder, &propVariantIsFolder));
if(propVariantIsFolder.vt != VT_BOOL)
return E_FAIL;
g_StdOut << GetAttributesString(attributes, VARIANT_BOOLToBool(propVariantIsFolder.boolVal));
UInt32 attributes = propVariant.ulVal;
bool isFolder;
RINOK(IsArchiveItemFolder(archive, index, isFolder));
char s[8];
GetAttributesString(attributes, isFolder, s);
g_StdOut << s;
continue;
}
if (propVariant.vt == VT_BSTR)
{
PrintString(fieldInfo.TextAdjustment, fieldInfo.Width, propVariant.bstrVal);
PrintString(fieldInfo.TextAdjustment, width, propVariant.bstrVal);
continue;
}
PrintString(fieldInfo.TextAdjustment, fieldInfo.Width,
PrintString(fieldInfo.TextAdjustment, width,
ConvertPropertyToString(propVariant, fieldInfo.PropID));
}
return S_OK;
}
void PrintNumberString(EAdjustment adjustment, int width, const UINT64 *value)
void PrintNumberString(EAdjustment adjustment, int width, const UInt64 *value)
{
wchar_t textString[32] = { 0 };
if (value != NULL)
ConvertUINT64ToString(*value, textString);
ConvertUInt64ToString(*value, textString);
PrintString(adjustment, width, textString);
}
static const wchar_t *kFilesMessage = L"files";
HRESULT CFieldPrinter::PrintSummaryInfo(UINT64 numFiles,
const UINT64 *size, const UINT64 *compressedSize)
HRESULT CFieldPrinter::PrintSummaryInfo(UInt64 numFiles,
const UInt64 *size, const UInt64 *compressedSize)
{
for (int i = 0; i < _fields.Size(); i++)
{
@@ -286,11 +274,11 @@ HRESULT CFieldPrinter::PrintSummaryInfo(UINT64 numFiles,
else if (fieldInfo.PropID == kpidPath)
{
wchar_t textString[32];
ConvertUINT64ToString(numFiles, textString);
ConvertUInt64ToString(numFiles, textString);
UString temp = textString;
temp += L" ";
temp += kFilesMessage;
PrintString(fieldInfo.TextAdjustment, fieldInfo.Width, temp);
PrintString(fieldInfo.TextAdjustment, 0, temp);
}
else
PrintString(fieldInfo.TextAdjustment, fieldInfo.Width, L"");
@@ -298,84 +286,147 @@ HRESULT CFieldPrinter::PrintSummaryInfo(UINT64 numFiles,
return S_OK;
}
bool GetUINT64Value(IInArchive *archive, UINT32 index,
PROPID propID, UINT64 &value)
bool GetUInt64Value(IInArchive *archive, UInt32 index, PROPID propID, UInt64 &value)
{
NCOM::CPropVariant propVariant;
if (archive->GetProperty(index, propID, &propVariant) != S_OK)
throw "GetPropertyValue error";
if (propVariant.vt == VT_EMPTY)
return false;
value = ConvertPropVariantToUINT64(propVariant);
value = ConvertPropVariantToUInt64(propVariant);
return true;
}
HRESULT ListArchive(IInArchive *archive,
const UString &defaultItemName,
const NWindows::NFile::NFind::CFileInfoW &archiveFileInfo,
const NWildcard::CCensor &wildcardCensor/*, bool fullPathMode,
NListMode::EEnum mode*/)
HRESULT ListArchives(UStringVector &archivePaths, UStringVector &archivePathsFull,
const NWildcard::CCensorNode &wildcardCensor,
bool enableHeaders, bool &passwordEnabled, UString &password)
{
CFieldPrinter fieldPrinter;
fieldPrinter.Init(kStandardFieldTable, sizeof(kStandardFieldTable) / sizeof(kStandardFieldTable[0]));
fieldPrinter.PrintTitle();
g_StdOut << endl;
fieldPrinter.PrintTitleLines();
g_StdOut << endl;
// bool nameFirst = (fullPathMode && (mode != NListMode::kDefault)) || (mode == NListMode::kAll);
UINT64 numFiles = 0, totalPackSize = 0, totalUnPackSize = 0;
UINT64 *totalPackSizePointer = 0, *totalUnPackSizePointer = 0;
UINT32 numItems;
RINOK(archive->GetNumberOfItems(&numItems));
for(UINT32 i = 0; i < numItems; i++)
UInt64 numFiles2 = 0, totalPackSize2 = 0, totalUnPackSize2 = 0;
UInt64 *totalPackSizePointer2 = 0, *totalUnPackSizePointer2 = 0;
int numErrors = 0;
for (int i = 0; i < archivePaths.Size(); i++)
{
if (NConsoleClose::TestBreakSignal())
return E_ABORT;
NCOM::CPropVariant propVariant;
RINOK(archive->GetProperty(i, kpidPath, &propVariant));
UString filePath;
if(propVariant.vt == VT_EMPTY)
filePath = defaultItemName;
else
const UString &archiveName = archivePaths[i];
NFile::NFind::CFileInfoW archiveFileInfo;
if (!NFile::NFind::FindFile(archiveName, archiveFileInfo) || archiveFileInfo.IsDirectory())
{
if(propVariant.vt != VT_BSTR)
return E_FAIL;
filePath = propVariant.bstrVal;
}
if (!wildcardCensor.CheckName(filePath))
g_StdOut << endl << "Error: " << archiveName << " is not archive" << endl;
numErrors++;
continue;
}
if (archiveFileInfo.IsDirectory())
{
g_StdOut << endl << "Error: " << archiveName << " is not file" << endl;
numErrors++;
continue;
}
fieldPrinter.PrintItemInfo(archive, defaultItemName, archiveFileInfo, i);
CArchiveLink archiveLink;
UINT64 packSize, unpackSize;
if (!GetUINT64Value(archive, i, kpidSize, unpackSize))
unpackSize = 0;
else
totalUnPackSizePointer = &totalUnPackSize;
if (!GetUINT64Value(archive, i, kpidPackedSize, packSize))
packSize = 0;
else
totalPackSizePointer = &totalPackSize;
COpenCallbackConsole openCallback;
openCallback.OutStream = &g_StdOut;
openCallback.PasswordIsDefined = passwordEnabled;
openCallback.Password = password;
g_StdOut << endl;
HRESULT result = MyOpenArchive(archiveName, archiveLink, &openCallback);
if (result != S_OK)
{
g_StdOut << endl << "Error: " << archiveName << " is not supported archive" << endl;
numErrors++;
continue;
}
numFiles++;
totalPackSize += packSize;
totalUnPackSize += unpackSize;
for (int v = 0; v < archiveLink.VolumePaths.Size(); v++)
{
int index = archivePathsFull.FindInSorted(archiveLink.VolumePaths[v]);
if (index >= 0 && index > i)
{
archivePaths.Delete(index);
archivePathsFull.Delete(index);
}
}
IInArchive *archive = archiveLink.GetArchive();
const UString defaultItemName = archiveLink.GetDefaultItemName();
if (enableHeaders)
g_StdOut << endl << kListing << archiveName << endl << endl;
if (enableHeaders)
{
fieldPrinter.PrintTitle();
g_StdOut << endl;
fieldPrinter.PrintTitleLines();
g_StdOut << endl;
}
UInt64 numFiles = 0, totalPackSize = 0, totalUnPackSize = 0;
UInt64 *totalPackSizePointer = 0, *totalUnPackSizePointer = 0;
UInt32 numItems;
RINOK(archive->GetNumberOfItems(&numItems));
for(UInt32 i = 0; i < numItems; i++)
{
if (NConsoleClose::TestBreakSignal())
return E_ABORT;
UString filePath;
RINOK(GetArchiveItemPath(archive, i, defaultItemName, filePath));
bool isFolder;
RINOK(IsArchiveItemFolder(archive, i, isFolder));
if (!wildcardCensor.CheckPath(filePath, !isFolder))
continue;
fieldPrinter.PrintItemInfo(archive, defaultItemName, archiveFileInfo, i);
UInt64 packSize, unpackSize;
if (!GetUInt64Value(archive, i, kpidSize, unpackSize))
unpackSize = 0;
else
totalUnPackSizePointer = &totalUnPackSize;
if (!GetUInt64Value(archive, i, kpidPackedSize, packSize))
packSize = 0;
else
totalPackSizePointer = &totalPackSize;
g_StdOut << endl;
numFiles++;
totalPackSize += packSize;
totalUnPackSize += unpackSize;
}
if (enableHeaders)
{
fieldPrinter.PrintTitleLines();
g_StdOut << endl;
fieldPrinter.PrintSummaryInfo(numFiles, totalUnPackSizePointer, totalPackSizePointer);
g_StdOut << endl;
}
if (totalPackSizePointer != 0)
{
totalPackSizePointer2 = &totalPackSize2;
totalPackSize2 += totalPackSize;
}
if (totalUnPackSizePointer != 0)
{
totalUnPackSizePointer2 = &totalUnPackSize2;
totalUnPackSize2 += totalUnPackSize;
}
numFiles2 += numFiles;
}
fieldPrinter.PrintTitleLines();
g_StdOut << endl;
/*
if(numFiles == 0)
g_StdOut << kNoFilesMessage);
else
*/
fieldPrinter.PrintSummaryInfo(numFiles, totalUnPackSizePointer, totalPackSizePointer);
g_StdOut << endl;
if (enableHeaders && archivePaths.Size() > 1)
{
g_StdOut << endl;
fieldPrinter.PrintTitleLines();
g_StdOut << endl;
fieldPrinter.PrintSummaryInfo(numFiles2, totalUnPackSizePointer2, totalPackSizePointer2);
g_StdOut << endl;
g_StdOut << "Archives: " << archivePaths.Size() << endl;
}
if (numErrors > 0)
g_StdOut << endl << "Errors: " << numErrors;
return S_OK;
}