mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-14 12:11:39 -06:00
4.20
This commit is contained in:
committed by
Kornel Lesiński
parent
8c1b5c7b7e
commit
3c510ba80b
@@ -1,64 +0,0 @@
|
||||
// ArError.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __ARERROR_H
|
||||
#define __ARERROR_H
|
||||
|
||||
namespace NExitCode {
|
||||
|
||||
struct CSystemError
|
||||
{
|
||||
UINT32 ErrorValue;
|
||||
CSystemError(UINT32 anErrorValue): ErrorValue(anErrorValue) {}
|
||||
};
|
||||
|
||||
struct CMultipleErrors
|
||||
{
|
||||
UINT64 NumErrors;
|
||||
CMultipleErrors(UINT64 aNumErrors): NumErrors(aNumErrors) {}
|
||||
};
|
||||
|
||||
|
||||
enum EEnum {
|
||||
|
||||
kSuccess = 0, // Successful operation (User exit)
|
||||
kWarning = 1, // Non fatal error(s) occurred
|
||||
kFatalError = 2, // A fatal error occurred
|
||||
kCRCError = 3, // A CRC error occurred when unpacking
|
||||
kLockedArchive = 4, // Attempt to modify an archive previously locked
|
||||
kWriteError = 5, // Write to disk error
|
||||
kOpenError = 6, // Open file error
|
||||
kUserError = 7, // Command line option error
|
||||
kMemoryError = 8, // Not enough memory for operation
|
||||
|
||||
|
||||
kNotSupported = 102, // format of file doesn't supported
|
||||
kFileError = 103, //
|
||||
|
||||
kVerError = 110, // Version doesn't supported
|
||||
kMethodError = 111, // Unsupported method
|
||||
|
||||
kUserQuit = 120, // Unsupported method
|
||||
|
||||
kFileIsNotArchive = 130, // File Is Not Archive
|
||||
|
||||
kCommonError = 150,
|
||||
|
||||
kInputArchiveException = 160, // archive file does not exist
|
||||
|
||||
kErrorsDuringDecompression = 170, // Errors during decompression
|
||||
|
||||
|
||||
kDirFileWith64BitSize = 171,
|
||||
kFileTimeWinToDosConvertError = 172,
|
||||
|
||||
kFileChangedDuringOperation = 180,
|
||||
|
||||
kUserBreak = 255 // User stopped the process
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,28 +0,0 @@
|
||||
// CompressionMethodUtils.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __COMPRESSIONMETHODUTILS_H
|
||||
#define __COMPRESSIONMETHODUTILS_H
|
||||
|
||||
struct CProperty
|
||||
{
|
||||
UString Name;
|
||||
UString Value;
|
||||
};
|
||||
|
||||
struct CCompressionMethodMode
|
||||
{
|
||||
#ifndef EXCLUDE_COM
|
||||
UString FilePath;
|
||||
CLSID ClassID1;
|
||||
#else
|
||||
UString Name;
|
||||
#endif
|
||||
CObjectVector<CProperty> Properties;
|
||||
bool PasswordIsDefined;
|
||||
bool AskPassword;
|
||||
UString Password;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -158,14 +158,6 @@ SOURCE=.\StdAfx.h
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ArError.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CompressionMode.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ConsoleClose.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@@ -174,19 +166,11 @@ SOURCE=.\ConsoleClose.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Extract.cpp
|
||||
SOURCE=.\ExtractCallbackConsole.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Extract.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ExtractCallback.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ExtractCallback.h
|
||||
SOURCE=.\ExtractCallbackConsole.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
@@ -206,11 +190,11 @@ SOURCE=.\MainAr.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\OpenCallback.cpp
|
||||
SOURCE=.\OpenCallbackConsole.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\OpenCallback.h
|
||||
SOURCE=.\OpenCallbackConsole.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
@@ -222,27 +206,11 @@ SOURCE=.\PercentPrinter.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TempFiles.cpp
|
||||
SOURCE=.\UpdateCallbackConsole.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TempFiles.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Update.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Update.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\UpdateCallback.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\UpdateCallback.h
|
||||
SOURCE=.\UpdateCallbackConsole.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
@@ -328,20 +296,24 @@ SOURCE=..\..\..\Windows\Registry.cpp
|
||||
|
||||
SOURCE=..\..\..\Windows\Registry.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Windows\System.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Windows\System.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Common"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\Alloc.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\Alloc.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\Buffer.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\CommandLineParser.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@@ -422,6 +394,14 @@ SOURCE=..\..\..\Common\StringConvert.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\StringToInt.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\StringToInt.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\UTFConvert.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@@ -450,6 +430,30 @@ SOURCE=..\..\..\Common\Wildcard.h
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Common\ArchiveCommandLine.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Common\ArchiveCommandLine.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Common\ArchiveExtractCallback.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Common\ArchiveExtractCallback.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Common\ArchiveOpenCallback.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Common\ArchiveOpenCallback.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Common\ArchiverInfo.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@@ -458,6 +462,10 @@ SOURCE=..\Common\ArchiverInfo.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Common\CompressionMode.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Common\DefaultName.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@@ -478,6 +486,18 @@ SOURCE=..\Common\EnumDirItems.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Common\ExitCode.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Common\Extract.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Common\Extract.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Common\ExtractingFilePath.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@@ -490,6 +510,10 @@ SOURCE=..\Common\HandlerLoader.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Common\IFileExtractCallback.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Common\OpenArchive.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@@ -514,6 +538,22 @@ SOURCE=..\Common\SortUtils.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Common\TempFiles.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Common\TempFiles.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Common\Update.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Common\Update.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Common\UpdateAction.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@@ -522,6 +562,14 @@ SOURCE=..\Common\UpdateAction.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Common\UpdateCallback.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Common\UpdateCallback.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Common\UpdatePair.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@@ -544,6 +592,10 @@ SOURCE=..\Common\WorkDir.cpp
|
||||
|
||||
SOURCE=..\Common\WorkDir.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Common\ZipRegistry.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "7-zip Common"
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// ConsoleCloseUtils.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __CONSOLECLOSEUTILS_H
|
||||
#define __CONSOLECLOSEUTILS_H
|
||||
|
||||
@@ -24,4 +22,3 @@ void CheckCtrlBreak();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
// Extract.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "Extract.h"
|
||||
#include "ExtractCallback.h"
|
||||
#include "ArError.h"
|
||||
|
||||
#include "Common/StdOutStream.h"
|
||||
#include "Windows/Defs.h"
|
||||
#include "Windows/PropVariant.h"
|
||||
#include "Windows/FileDir.h"
|
||||
|
||||
using namespace NWindows;
|
||||
|
||||
static const char *kEverythingIsOk = "Everything is Ok";
|
||||
|
||||
HRESULT DeCompressArchiveSTD(
|
||||
IInArchive *archive,
|
||||
const NWildcard::CCensor &wildcardCensor,
|
||||
const CExtractOptions &options)
|
||||
{
|
||||
CRecordVector<UINT32> realIndices;
|
||||
UINT32 numItems;
|
||||
RINOK(archive->GetNumberOfItems(&numItems));
|
||||
|
||||
for(UINT32 i = 0; i < numItems; i++)
|
||||
{
|
||||
NCOM::CPropVariant propVariant;
|
||||
RINOK(archive->GetProperty(i, kpidPath, &propVariant));
|
||||
UString filePath;
|
||||
if(propVariant.vt == VT_EMPTY)
|
||||
filePath = options.DefaultItemName;
|
||||
else
|
||||
{
|
||||
if(propVariant.vt != VT_BSTR)
|
||||
return E_FAIL;
|
||||
filePath = propVariant.bstrVal;
|
||||
}
|
||||
if (!wildcardCensor.CheckName(filePath))
|
||||
continue;
|
||||
realIndices.Add(i);
|
||||
}
|
||||
if (realIndices.Size() == 0)
|
||||
{
|
||||
g_StdOut << endl << "No files to process" << endl;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
CExtractCallbackImp *extractCallbackSpec = new CExtractCallbackImp;
|
||||
CMyComPtr<IArchiveExtractCallback> extractCallback(extractCallbackSpec);
|
||||
|
||||
UStringVector removePathParts;
|
||||
|
||||
NExtraction::CInfo extractionInfo;
|
||||
extractionInfo.PathMode = options.FullPathMode() ? NExtraction::NPathMode::kFullPathnames:
|
||||
NExtraction::NPathMode::kNoPathnames;
|
||||
|
||||
if (options.YesToAll)
|
||||
extractionInfo.OverwriteMode = NExtraction::NOverwriteMode::kWithoutPrompt;
|
||||
else
|
||||
{
|
||||
extractionInfo.OverwriteMode = options.OverwriteMode;
|
||||
}
|
||||
|
||||
if(!options.OutputBaseDir.IsEmpty())
|
||||
if(!NFile::NDirectory::CreateComplexDirectory(options.OutputBaseDir))
|
||||
{
|
||||
throw "Can not create output directory";
|
||||
}
|
||||
|
||||
extractCallbackSpec->Init(archive,
|
||||
options.OutputBaseDir,
|
||||
extractionInfo, removePathParts,
|
||||
options.DefaultItemName,
|
||||
options.ArchiveFileInfo.LastWriteTime,
|
||||
options.ArchiveFileInfo.Attributes,
|
||||
options.PasswordEnabled,
|
||||
options.Password);
|
||||
|
||||
HRESULT result = archive->Extract(&realIndices.Front(),
|
||||
realIndices.Size(), options.ExtractMode == NExtractMode::kTest,
|
||||
extractCallback);
|
||||
|
||||
if (extractCallbackSpec->m_NumErrors != 0)
|
||||
throw NExitCode::CMultipleErrors(extractCallbackSpec->m_NumErrors);
|
||||
|
||||
if (result != S_OK)
|
||||
throw NExitCode::CSystemError(result);
|
||||
|
||||
g_StdOut << endl << kEverythingIsOk << endl;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
// Extract.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __EXTRACT_H
|
||||
#define __EXTRACT_H
|
||||
|
||||
#include "Common/Wildcard.h"
|
||||
#include "Windows/FileFind.h"
|
||||
|
||||
#include "../../Archive/IArchive.h"
|
||||
#include "../Common/ZipRegistry.h"
|
||||
|
||||
namespace NExtractMode {
|
||||
|
||||
enum EEnum
|
||||
{
|
||||
kTest,
|
||||
kFullPath,
|
||||
kExtractToOne
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
class CExtractOptions
|
||||
{
|
||||
public:
|
||||
NExtractMode::EEnum ExtractMode;
|
||||
UString OutputBaseDir;
|
||||
bool YesToAll;
|
||||
UString DefaultItemName;
|
||||
NWindows::NFile::NFind::CFileInfoW ArchiveFileInfo;
|
||||
bool PasswordEnabled;
|
||||
UString Password;
|
||||
|
||||
NExtraction::NOverwriteMode::EEnum OverwriteMode;
|
||||
|
||||
|
||||
CExtractOptions(NExtractMode::EEnum extractMode, const UString &outputBaseDir,
|
||||
bool yesToAll, bool passwordEnabled, const UString &password,
|
||||
NExtraction::NOverwriteMode::EEnum overwriteMode):
|
||||
ExtractMode(extractMode),
|
||||
OutputBaseDir(outputBaseDir),
|
||||
YesToAll(yesToAll),
|
||||
PasswordEnabled(passwordEnabled),
|
||||
Password(password),
|
||||
OverwriteMode(overwriteMode)
|
||||
{}
|
||||
|
||||
bool TestMode() const { return (ExtractMode == NExtractMode::kTest); }
|
||||
bool FullPathMode() const { return (ExtractMode == NExtractMode::kTest) ||
|
||||
(ExtractMode == NExtractMode::kFullPath); }
|
||||
};
|
||||
|
||||
HRESULT DeCompressArchiveSTD(IInArchive *archive,
|
||||
const NWildcard::CCensor &wildcardCensor,
|
||||
const CExtractOptions &options);
|
||||
|
||||
/*
|
||||
bool DeCompressArchiveSTD(TTWildCardInputArchive &anArchive,
|
||||
const TTExtractOptions &anOptions);
|
||||
*/
|
||||
|
||||
#endif
|
||||
@@ -1,405 +0,0 @@
|
||||
// ExtractCallback.h
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "ExtractCallback.h"
|
||||
#include "UserInputUtils.h"
|
||||
|
||||
#include "ConsoleClose.h"
|
||||
#include "Common/StdOutStream.h"
|
||||
#include "Common/StdInStream.h"
|
||||
#include "Common/Wildcard.h"
|
||||
#include "Common/StringConvert.h"
|
||||
|
||||
#include "Windows/COM.h"
|
||||
#include "Windows/FileDir.h"
|
||||
#include "Windows/FileFind.h"
|
||||
#include "Windows/Time.h"
|
||||
#include "Windows/Defs.h"
|
||||
#include "Windows/PropVariant.h"
|
||||
|
||||
#include "Windows/PropVariantConversions.h"
|
||||
|
||||
#include "../../Common/FilePathAutoRename.h"
|
||||
|
||||
#include "../Common/ExtractingFilePath.h"
|
||||
|
||||
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 *kCantAutoRename = "can not create file with auto name\n";
|
||||
static const char *kCantRenameFile = "can not rename existing file\n";
|
||||
static const char *kCantDeleteOutputFile = "can not delete output file ";
|
||||
void CExtractCallbackImp::Init(IInArchive *archive,
|
||||
const UString &directoryPath,
|
||||
const NExtraction::CInfo &extractModeInfo,
|
||||
const UStringVector &removePathParts,
|
||||
const UString &itemDefaultName,
|
||||
const FILETIME &utcLastWriteTimeDefault,
|
||||
UINT32 attributesDefault,
|
||||
bool passwordIsDefined,
|
||||
const UString &password)
|
||||
{
|
||||
m_PasswordIsDefined = passwordIsDefined;
|
||||
m_Password = password;
|
||||
m_NumErrors = 0;
|
||||
|
||||
m_ItemDefaultName = itemDefaultName;
|
||||
m_UTCLastWriteTimeDefault = utcLastWriteTimeDefault;
|
||||
m_AttributesDefault = attributesDefault;
|
||||
|
||||
m_RemovePathParts = removePathParts;
|
||||
m_ExtractModeInfo = extractModeInfo;
|
||||
m_ArchiveHandler = archive;
|
||||
m_DirectoryPath = directoryPath;
|
||||
NFile::NName::NormalizeDirPathPrefix(m_DirectoryPath);
|
||||
}
|
||||
|
||||
bool CExtractCallbackImp::IsEncrypted(UINT32 index)
|
||||
{
|
||||
NCOM::CPropVariant propVariant;
|
||||
if(m_ArchiveHandler->GetProperty(index, kpidEncrypted, &propVariant) != S_OK)
|
||||
return false;
|
||||
if (propVariant.vt != VT_BOOL)
|
||||
return false;
|
||||
return VARIANT_BOOLToBool(propVariant.boolVal);
|
||||
}
|
||||
|
||||
STDMETHODIMP CExtractCallbackImp::SetTotal(UINT64 size)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CExtractCallbackImp::SetCompleted(const UINT64 *completeValue)
|
||||
{
|
||||
if (NConsoleClose::TestBreakSignal())
|
||||
return E_ABORT;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void CExtractCallbackImp::CreateComplexDirectory(const UStringVector &dirPathParts)
|
||||
{
|
||||
UString fullPath = m_DirectoryPath;
|
||||
for(int i = 0; i < dirPathParts.Size(); i++)
|
||||
{
|
||||
fullPath += dirPathParts[i];
|
||||
MyCreateDirectory(fullPath);
|
||||
fullPath += (wchar_t)NFile::NName::kDirDelimiter;
|
||||
}
|
||||
}
|
||||
|
||||
static UString MakePathNameFromParts(const UStringVector &parts)
|
||||
{
|
||||
UString result;
|
||||
for(int i = 0; i < parts.Size(); i++)
|
||||
{
|
||||
if(i != 0)
|
||||
result += wchar_t(NFile::NName::kDirDelimiter);
|
||||
result += parts[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
STDMETHODIMP CExtractCallbackImp::GetStream(UINT32 index,
|
||||
ISequentialOutStream **outStream, INT32 askExtractMode)
|
||||
{
|
||||
*outStream = NULL;
|
||||
if (NConsoleClose::TestBreakSignal())
|
||||
return E_ABORT;
|
||||
m_OutFileStream.Release();
|
||||
NCOM::CPropVariant propVariantName;
|
||||
RINOK(m_ArchiveHandler->GetProperty(index, kpidPath, &propVariantName));
|
||||
UString fullPath;
|
||||
if(propVariantName.vt == VT_EMPTY)
|
||||
fullPath = m_ItemDefaultName;
|
||||
else
|
||||
{
|
||||
if(propVariantName.vt != VT_BSTR)
|
||||
return E_FAIL;
|
||||
fullPath = propVariantName.bstrVal;
|
||||
}
|
||||
|
||||
m_FilePath = fullPath;
|
||||
|
||||
UString fullPathCorrect = GetCorrectPath(fullPath);
|
||||
|
||||
if(askExtractMode == NArchive::NExtract::NAskMode::kExtract)
|
||||
{
|
||||
NCOM::CPropVariant propVariant;
|
||||
RINOK(m_ArchiveHandler->GetProperty(index, kpidAttributes, &propVariant));
|
||||
if (propVariant.vt == VT_EMPTY)
|
||||
{
|
||||
m_ProcessedFileInfo.Attributes = m_AttributesDefault;
|
||||
m_ProcessedFileInfo.AttributesAreDefined = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (propVariant.vt != VT_UI4)
|
||||
throw "incorrect item";
|
||||
m_ProcessedFileInfo.Attributes = propVariant.ulVal;
|
||||
m_ProcessedFileInfo.AttributesAreDefined = true;
|
||||
}
|
||||
|
||||
RINOK(m_ArchiveHandler->GetProperty(index, kpidIsFolder, &propVariant));
|
||||
m_ProcessedFileInfo.IsDirectory = VARIANT_BOOLToBool(propVariant.boolVal);
|
||||
|
||||
bool isAnti = false;
|
||||
{
|
||||
NCOM::CPropVariant propVariantTemp;
|
||||
RINOK(m_ArchiveHandler->GetProperty(index, kpidIsAnti,
|
||||
&propVariantTemp));
|
||||
if (propVariantTemp.vt == VT_BOOL)
|
||||
isAnti = VARIANT_BOOLToBool(propVariantTemp.boolVal);
|
||||
}
|
||||
|
||||
RINOK(m_ArchiveHandler->GetProperty(index, kpidLastWriteTime, &propVariant));
|
||||
switch(propVariant.vt)
|
||||
{
|
||||
case VT_EMPTY:
|
||||
m_ProcessedFileInfo.UTCLastWriteTime = m_UTCLastWriteTimeDefault;
|
||||
break;
|
||||
case VT_FILETIME:
|
||||
m_ProcessedFileInfo.UTCLastWriteTime = propVariant.filetime;
|
||||
break;
|
||||
default:
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
// GetPropertyValue(anItemIDList, kpidSize, &propVariant);
|
||||
// UINT64 newFileSize = ConvertPropVariantToUINT64(propVariant);
|
||||
|
||||
UStringVector pathParts;
|
||||
SplitPathToParts(fullPathCorrect, pathParts);
|
||||
if(pathParts.IsEmpty())
|
||||
return E_FAIL;
|
||||
UString processedPath;
|
||||
switch(m_ExtractModeInfo.PathMode)
|
||||
{
|
||||
case NExtraction::NPathMode::kFullPathnames:
|
||||
{
|
||||
processedPath = fullPathCorrect;
|
||||
break;
|
||||
}
|
||||
case NExtraction::NPathMode::kCurrentPathnames:
|
||||
{
|
||||
int numRemovePathParts = m_RemovePathParts.Size();
|
||||
if(pathParts.Size() <= numRemovePathParts)
|
||||
return E_FAIL;
|
||||
for(int i = 0; i < numRemovePathParts; i++)
|
||||
if(m_RemovePathParts[i].CollateNoCase(pathParts[i]) != 0)
|
||||
return E_FAIL;
|
||||
pathParts.Delete(0, numRemovePathParts);
|
||||
processedPath = MakePathNameFromParts(pathParts);
|
||||
break;
|
||||
}
|
||||
case NExtraction::NPathMode::kNoPathnames:
|
||||
{
|
||||
processedPath = pathParts.Back();
|
||||
pathParts.Delete(0, pathParts.Size() - 1); // Test it!!
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!m_ProcessedFileInfo.IsDirectory)
|
||||
pathParts.DeleteBack();
|
||||
if (!pathParts.IsEmpty())
|
||||
{
|
||||
if (!isAnti)
|
||||
CreateComplexDirectory(pathParts);
|
||||
}
|
||||
|
||||
UString fullProcessedPath = m_DirectoryPath + GetCorrectPath(processedPath);
|
||||
|
||||
if(m_ProcessedFileInfo.IsDirectory)
|
||||
{
|
||||
m_DiskFilePath = fullProcessedPath;
|
||||
|
||||
if (isAnti)
|
||||
MyRemoveDirectory(m_DiskFilePath);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
NFile::NFind::CFileInfoW fileInfo;
|
||||
if(NFile::NFind::FindFile(fullProcessedPath, fileInfo))
|
||||
{
|
||||
switch(m_ExtractModeInfo.OverwriteMode)
|
||||
{
|
||||
case NExtraction::NOverwriteMode::kSkipExisting:
|
||||
return S_OK;
|
||||
case NExtraction::NOverwriteMode::kAskBefore:
|
||||
{
|
||||
/*
|
||||
NOverwriteDialog::CFileInfo oldFileInfo, newFileInfo;
|
||||
oldFileInfo.Time = fileInfo.LastWriteTime;
|
||||
oldFileInfo.Size = fileInfo.Size;
|
||||
oldFileInfo.Name = fullProcessedPath;
|
||||
|
||||
newFileInfo.Time = m_ProcessedFileInfo.UTCLastWriteTime;
|
||||
newFileInfo.Size = newFileSize;
|
||||
newFileInfo.Name = fullPath;
|
||||
|
||||
NOverwriteDialog::NResult::EEnum result =
|
||||
NOverwriteDialog::Execute(oldFileInfo, newFileInfo);
|
||||
*/
|
||||
|
||||
g_StdOut << "file " << fullProcessedPath <<
|
||||
"\nalready exists. Overwrite with " << endl;
|
||||
g_StdOut << fullPathCorrect;
|
||||
|
||||
NUserAnswerMode::EEnum overwriteAnswer = ScanUserYesNoAllQuit();
|
||||
|
||||
switch(overwriteAnswer)
|
||||
{
|
||||
case NUserAnswerMode::kQuit:
|
||||
return E_ABORT;
|
||||
case NUserAnswerMode::kNo:
|
||||
return S_OK;
|
||||
case NUserAnswerMode::kNoAll:
|
||||
m_ExtractModeInfo.OverwriteMode = NExtraction::NOverwriteMode::kSkipExisting;
|
||||
return S_OK;
|
||||
case NUserAnswerMode::kYesAll:
|
||||
m_ExtractModeInfo.OverwriteMode = NExtraction::NOverwriteMode::kWithoutPrompt;
|
||||
break;
|
||||
case NUserAnswerMode::kYes:
|
||||
break;
|
||||
case NUserAnswerMode::kAutoRename:
|
||||
m_ExtractModeInfo.OverwriteMode = NExtraction::NOverwriteMode::kAutoRename;
|
||||
break;
|
||||
default:
|
||||
throw 20413;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (m_ExtractModeInfo.OverwriteMode == NExtraction::NOverwriteMode::kAutoRename)
|
||||
{
|
||||
if (!AutoRenamePath(fullProcessedPath))
|
||||
{
|
||||
g_StdOut << kCantAutoRename;
|
||||
g_StdOut << fullProcessedPath;
|
||||
return E_ABORT;
|
||||
}
|
||||
}
|
||||
else if (m_ExtractModeInfo.OverwriteMode == NExtraction::NOverwriteMode::kAutoRenameExisting)
|
||||
{
|
||||
UString existPath = fullProcessedPath;
|
||||
if (!AutoRenamePath(existPath))
|
||||
{
|
||||
g_StdOut << kCantAutoRename;
|
||||
g_StdOut << fullProcessedPath;
|
||||
return E_ABORT;
|
||||
}
|
||||
if(!MyMoveFile(fullProcessedPath, existPath))
|
||||
{
|
||||
g_StdOut << kCantRenameFile;
|
||||
return E_ABORT;
|
||||
}
|
||||
}
|
||||
else
|
||||
if (!DeleteFileAlways(fullProcessedPath))
|
||||
{
|
||||
g_StdOut << kCantDeleteOutputFile << endl;
|
||||
g_StdOut << fullProcessedPath;
|
||||
return E_ABORT;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isAnti)
|
||||
{
|
||||
m_OutFileStreamSpec = new COutFileStream;
|
||||
CMyComPtr<ISequentialOutStream> outStreamLoc(m_OutFileStreamSpec);
|
||||
if (!m_OutFileStreamSpec->Open(fullProcessedPath))
|
||||
{
|
||||
m_NumErrors++;
|
||||
g_StdOut << "Can not open output file " << endl;
|
||||
g_StdOut << fullProcessedPath << endl;
|
||||
return S_OK;
|
||||
}
|
||||
m_OutFileStream = outStreamLoc;
|
||||
*outStream = outStreamLoc.Detach();
|
||||
}
|
||||
m_DiskFilePath = fullProcessedPath;
|
||||
}
|
||||
else
|
||||
{
|
||||
*outStream = NULL;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CExtractCallbackImp::PrepareOperation(INT32 askExtractMode)
|
||||
{
|
||||
m_ExtractMode = false;
|
||||
switch (askExtractMode)
|
||||
{
|
||||
case NArchive::NExtract::NAskMode::kExtract:
|
||||
m_ExtractMode = true;
|
||||
g_StdOut << kExtractingString;
|
||||
break;
|
||||
case NArchive::NExtract::NAskMode::kTest:
|
||||
g_StdOut << kTestingString;
|
||||
break;
|
||||
case NArchive::NExtract::NAskMode::kSkip:
|
||||
g_StdOut << kSkippingString;
|
||||
break;
|
||||
};
|
||||
g_StdOut << m_FilePath;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CExtractCallbackImp::SetOperationResult(INT32 resultEOperationResult)
|
||||
{
|
||||
switch(resultEOperationResult)
|
||||
{
|
||||
case NArchive::NExtract::NOperationResult::kOK:
|
||||
{
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
m_NumErrors++;
|
||||
switch(resultEOperationResult)
|
||||
{
|
||||
case NArchive::NExtract::NOperationResult::kUnSupportedMethod:
|
||||
g_StdOut << " Unsupported Method";
|
||||
break;
|
||||
case NArchive::NExtract::NOperationResult::kCRCError:
|
||||
g_StdOut << " CRC Failed";
|
||||
break;
|
||||
case NArchive::NExtract::NOperationResult::kDataError:
|
||||
g_StdOut << " Data Error";
|
||||
break;
|
||||
default:
|
||||
g_StdOut << " Unknown Error";
|
||||
// m_OutFileStream.Release();
|
||||
// return E_FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(m_OutFileStream != NULL)
|
||||
m_OutFileStreamSpec->File.SetLastWriteTime(&m_ProcessedFileInfo.UTCLastWriteTime);
|
||||
m_OutFileStream.Release();
|
||||
if (m_ExtractMode && m_ProcessedFileInfo.AttributesAreDefined)
|
||||
MySetFileAttributes(m_DiskFilePath, m_ProcessedFileInfo.Attributes);
|
||||
g_StdOut << endl;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CExtractCallbackImp::CryptoGetTextPassword(BSTR *password)
|
||||
{
|
||||
if (!m_PasswordIsDefined)
|
||||
{
|
||||
g_StdOut << "\nEnter password:";
|
||||
AString oemPassword = g_StdIn.ScanStringUntilNewLine();
|
||||
m_Password = MultiByteToUnicodeString(oemPassword, CP_OEMCP);
|
||||
m_PasswordIsDefined = true;
|
||||
}
|
||||
CMyComBSTR tempName(m_Password);
|
||||
*password = tempName.Detach();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
// ExtractCallback.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __EXTRACTCALLBACK_H
|
||||
#define __EXTRACTCALLBACK_H
|
||||
|
||||
#include "Common/String.h"
|
||||
#include "../../Common/FileStreams.h"
|
||||
#include "../../IPassword.h"
|
||||
#include "../../Archive/IArchive.h"
|
||||
#include "../Common/ZipRegistry.h"
|
||||
|
||||
class CExtractCallbackImp:
|
||||
public IArchiveExtractCallback,
|
||||
public ICryptoGetTextPassword,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
public:
|
||||
MY_UNKNOWN_IMP1(ICryptoGetTextPassword)
|
||||
|
||||
// IProgress
|
||||
STDMETHOD(SetTotal)(UINT64 size);
|
||||
STDMETHOD(SetCompleted)(const UINT64 *completeValue);
|
||||
|
||||
// IExtractCallback200
|
||||
STDMETHOD(GetStream)(UINT32 index, ISequentialOutStream **outStream,
|
||||
INT32 askExtractMode);
|
||||
STDMETHOD(PrepareOperation)(INT32 askExtractMode);
|
||||
STDMETHOD(SetOperationResult)(INT32 resultEOperationResult);
|
||||
|
||||
// ICryptoGetTextPassword
|
||||
STDMETHOD(CryptoGetTextPassword)(BSTR *password);
|
||||
|
||||
private:
|
||||
CMyComPtr<IInArchive> m_ArchiveHandler;
|
||||
UString m_DirectoryPath;
|
||||
NExtraction::CInfo m_ExtractModeInfo;
|
||||
|
||||
UString m_FilePath;
|
||||
|
||||
UString m_DiskFilePath;
|
||||
|
||||
bool m_ExtractMode;
|
||||
struct CProcessedFileInfo
|
||||
{
|
||||
FILETIME UTCLastWriteTime;
|
||||
bool IsDirectory;
|
||||
bool AttributesAreDefined;
|
||||
UINT32 Attributes;
|
||||
} m_ProcessedFileInfo;
|
||||
|
||||
COutFileStream *m_OutFileStreamSpec;
|
||||
CMyComPtr<ISequentialOutStream> m_OutFileStream;
|
||||
UStringVector m_RemovePathParts;
|
||||
|
||||
UString m_ItemDefaultName;
|
||||
FILETIME m_UTCLastWriteTimeDefault;
|
||||
UINT32 m_AttributesDefault;
|
||||
|
||||
bool m_PasswordIsDefined;
|
||||
UString m_Password;
|
||||
|
||||
void CreateComplexDirectory(const UStringVector &dirPathParts);
|
||||
bool IsEncrypted(UINT32 index);
|
||||
public:
|
||||
void Init(IInArchive *archive, const UString &directoryPath,
|
||||
const NExtraction::CInfo &anExtractModeInfo,
|
||||
const UStringVector &removePathParts,
|
||||
const UString &itemDefaultName,
|
||||
const FILETIME &utcLastWriteTimeDefault, UINT32 attributesDefault,
|
||||
bool passwordIsDefined, const UString &password);
|
||||
|
||||
UINT64 m_NumErrors;
|
||||
};
|
||||
|
||||
#endif
|
||||
227
7zip/UI/Console/ExtractCallbackConsole.cpp
Executable file
227
7zip/UI/Console/ExtractCallbackConsole.cpp
Executable file
@@ -0,0 +1,227 @@
|
||||
// ExtractCallbackConsole.h
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "ExtractCallbackConsole.h"
|
||||
#include "UserInputUtils.h"
|
||||
#include "ConsoleClose.h"
|
||||
|
||||
#include "Common/Wildcard.h"
|
||||
|
||||
#include "Windows/FileDir.h"
|
||||
#include "Windows/FileFind.h"
|
||||
#include "Windows/Time.h"
|
||||
#include "Windows/Defs.h"
|
||||
#include "Windows/PropVariant.h"
|
||||
#include "Windows/Error.h"
|
||||
#include "Windows/PropVariantConversions.h"
|
||||
|
||||
#include "../../Common/FilePathAutoRename.h"
|
||||
|
||||
#include "../Common/ExtractingFilePath.h"
|
||||
|
||||
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 *kCantAutoRename = "can not create file with auto name\n";
|
||||
static const char *kCantRenameFile = "can not rename existing file\n";
|
||||
static const char *kCantDeleteOutputFile = "can not delete output file ";
|
||||
static const char *kError = "ERROR: ";
|
||||
static const char *kMemoryExceptionMessage = "Can't allocate required memory!";
|
||||
|
||||
static const char *kProcessing = "Processing archive: ";
|
||||
static const char *kEverythingIsOk = "Everything is Ok";
|
||||
static const char *kNoFiles = "No files to process";
|
||||
|
||||
static const char *kUnsupportedMethod = "Unsupported Method";
|
||||
static const char *kCRCFailed = "CRC Failed";
|
||||
static const char *kDataError = "Data Error";
|
||||
static const char *kUnknownError = "Unknown Error";
|
||||
|
||||
STDMETHODIMP CExtractCallbackConsole::SetTotal(UInt64 size)
|
||||
{
|
||||
if (NConsoleClose::TestBreakSignal())
|
||||
return E_ABORT;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CExtractCallbackConsole::SetCompleted(const UInt64 *completeValue)
|
||||
{
|
||||
if (NConsoleClose::TestBreakSignal())
|
||||
return E_ABORT;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CExtractCallbackConsole::AskOverwrite(
|
||||
const wchar_t *existName, const FILETIME *existTime, const UInt64 *existSize,
|
||||
const wchar_t *newName, const FILETIME *newTime, const UInt64 *newSize,
|
||||
Int32 *answer)
|
||||
{
|
||||
(*OutStream) << "file " << existName <<
|
||||
"\nalready exists. Overwrite with " << endl;
|
||||
(*OutStream) << newName;
|
||||
|
||||
NUserAnswerMode::EEnum overwriteAnswer = ScanUserYesNoAllQuit(OutStream);
|
||||
|
||||
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;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CExtractCallbackConsole::PrepareOperation(const wchar_t *name, Int32 askExtractMode, const UInt64 *position)
|
||||
{
|
||||
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;
|
||||
};
|
||||
(*OutStream) << name;
|
||||
if (position != 0)
|
||||
(*OutStream) << " <" << *position << ">";
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CExtractCallbackConsole::MessageError(const wchar_t *message)
|
||||
{
|
||||
(*OutStream) << message << endl;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CExtractCallbackConsole::SetOperationResult(Int32 operationResult)
|
||||
{
|
||||
switch(operationResult)
|
||||
{
|
||||
case NArchive::NExtract::NOperationResult::kOK:
|
||||
break;
|
||||
default:
|
||||
{
|
||||
NumFileErrorsInCurrentArchive++;
|
||||
NumFileErrors++;
|
||||
(*OutStream) << " ";
|
||||
switch(operationResult)
|
||||
{
|
||||
case NArchive::NExtract::NOperationResult::kUnSupportedMethod:
|
||||
(*OutStream) << kUnsupportedMethod;
|
||||
break;
|
||||
case NArchive::NExtract::NOperationResult::kCRCError:
|
||||
(*OutStream) << kCRCFailed;
|
||||
break;
|
||||
case NArchive::NExtract::NOperationResult::kDataError:
|
||||
(*OutStream) << kDataError;
|
||||
break;
|
||||
default:
|
||||
(*OutStream) << kUnknownError;
|
||||
}
|
||||
}
|
||||
}
|
||||
(*OutStream) << endl;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CExtractCallbackConsole::CryptoGetTextPassword(BSTR *password)
|
||||
{
|
||||
if (!PasswordIsDefined)
|
||||
{
|
||||
Password = GetPassword(OutStream);
|
||||
PasswordIsDefined = true;
|
||||
}
|
||||
CMyComBSTR tempName(Password);
|
||||
*password = tempName.Detach();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CExtractCallbackConsole::BeforeOpen(const wchar_t *name)
|
||||
{
|
||||
NumArchives++;
|
||||
NumFileErrorsInCurrentArchive = 0;
|
||||
(*OutStream) << endl << kProcessing << name << endl;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CExtractCallbackConsole::OpenResult(const wchar_t *name, HRESULT result)
|
||||
{
|
||||
(*OutStream) << endl;
|
||||
if (result != S_OK)
|
||||
{
|
||||
(*OutStream) << "Error: " << name << " is not supported archive" << endl;
|
||||
NumArchiveErrors++;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CExtractCallbackConsole::ThereAreNoFiles()
|
||||
{
|
||||
(*OutStream) << endl << kNoFiles << endl;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CExtractCallbackConsole::ExtractResult(HRESULT result)
|
||||
{
|
||||
if (result == S_OK)
|
||||
{
|
||||
(*OutStream) << endl;
|
||||
if (NumFileErrorsInCurrentArchive == 0)
|
||||
(*OutStream) << kEverythingIsOk << endl;
|
||||
else
|
||||
{
|
||||
NumArchiveErrors++;
|
||||
(*OutStream) << "Sub items Errors: " << NumFileErrorsInCurrentArchive << endl;
|
||||
}
|
||||
}
|
||||
if (result == S_OK)
|
||||
return result;
|
||||
if (result == E_ABORT)
|
||||
return result;
|
||||
(*OutStream) << endl << kError;
|
||||
if (result == E_OUTOFMEMORY)
|
||||
(*OutStream) << kMemoryExceptionMessage;
|
||||
else
|
||||
{
|
||||
UString message;
|
||||
NError::MyFormatMessage(result, message);
|
||||
(*OutStream) << message;
|
||||
}
|
||||
(*OutStream) << endl;
|
||||
|
||||
NumArchiveErrors++;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CExtractCallbackConsole::SetPassword(const UString &password)
|
||||
{
|
||||
PasswordIsDefined = true;
|
||||
Password = password;
|
||||
return S_OK;
|
||||
}
|
||||
65
7zip/UI/Console/ExtractCallbackConsole.h
Executable file
65
7zip/UI/Console/ExtractCallbackConsole.h
Executable file
@@ -0,0 +1,65 @@
|
||||
// ExtractCallbackConsole.h
|
||||
|
||||
#ifndef __EXTRACTCALLBACKCONSOLE_H
|
||||
#define __EXTRACTCALLBACKCONSOLE_H
|
||||
|
||||
#include "Common/String.h"
|
||||
#include "Common/StdOutStream.h"
|
||||
#include "../../Common/FileStreams.h"
|
||||
#include "../../IPassword.h"
|
||||
#include "../../Archive/IArchive.h"
|
||||
#include "../Common/ArchiveExtractCallback.h"
|
||||
|
||||
class CExtractCallbackConsole:
|
||||
public IExtractCallbackUI,
|
||||
public ICryptoGetTextPassword,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
public:
|
||||
MY_UNKNOWN_IMP2(IFolderArchiveExtractCallback, ICryptoGetTextPassword)
|
||||
|
||||
STDMETHOD(SetTotal)(UInt64 total);
|
||||
STDMETHOD(SetCompleted)(const UInt64 *completeValue);
|
||||
|
||||
// IFolderArchiveExtractCallback
|
||||
STDMETHOD(AskOverwrite)(
|
||||
const wchar_t *existName, const FILETIME *existTime, const UInt64 *existSize,
|
||||
const wchar_t *newName, const FILETIME *newTime, const UInt64 *newSize,
|
||||
Int32 *answer);
|
||||
STDMETHOD (PrepareOperation)(const wchar_t *name, Int32 askExtractMode, const UInt64 *position);
|
||||
|
||||
STDMETHOD(MessageError)(const wchar_t *message);
|
||||
STDMETHOD(SetOperationResult)(Int32 operationResult);
|
||||
|
||||
// ICryptoGetTextPassword
|
||||
STDMETHOD(CryptoGetTextPassword)(BSTR *password);
|
||||
|
||||
HRESULT BeforeOpen(const wchar_t *name);
|
||||
HRESULT OpenResult(const wchar_t *name, HRESULT result);
|
||||
HRESULT ThereAreNoFiles();
|
||||
HRESULT ExtractResult(HRESULT result);
|
||||
|
||||
HRESULT SetPassword(const UString &password);
|
||||
|
||||
public:
|
||||
bool PasswordIsDefined;
|
||||
UString Password;
|
||||
|
||||
UInt64 NumArchives;
|
||||
UInt64 NumArchiveErrors;
|
||||
UInt64 NumFileErrors;
|
||||
UInt64 NumFileErrorsInCurrentArchive;
|
||||
|
||||
CStdOutStream *OutStream;
|
||||
|
||||
void CExtractCallbackConsole::Init()
|
||||
{
|
||||
NumArchives = 0;
|
||||
NumArchiveErrors = 0;
|
||||
NumFileErrors = 0;
|
||||
NumFileErrorsInCurrentArchive = 0;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,31 +1,13 @@
|
||||
// List.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __LIST_H
|
||||
#define __LIST_H
|
||||
|
||||
#include "../../Archive/IArchive.h"
|
||||
#include "Common/Wildcard.h"
|
||||
#include "Windows/FileFind.h"
|
||||
|
||||
/*
|
||||
namespace NListMode
|
||||
{
|
||||
enum EEnum
|
||||
{
|
||||
kDefault,
|
||||
kAdd,
|
||||
kAll
|
||||
};
|
||||
}
|
||||
*/
|
||||
|
||||
HRESULT ListArchive(IInArchive *archive,
|
||||
const UString &defaultItemName,
|
||||
const NWindows::NFile::NFind::CFileInfoW &srchiveFileInfo,
|
||||
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);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -4,28 +4,34 @@
|
||||
|
||||
// #include <locale.h>
|
||||
|
||||
#include "Windows/COM.h"
|
||||
#include "Windows/Error.h"
|
||||
|
||||
#include "Common/StdOutStream.h"
|
||||
#include "Common/NewHandler.h"
|
||||
#include "Common/Exception.h"
|
||||
#include "Common/StringConvert.h"
|
||||
|
||||
#include "../Common/ExitCode.h"
|
||||
#include "ConsoleClose.h"
|
||||
#include "ArError.h"
|
||||
|
||||
using namespace NWindows;
|
||||
|
||||
// extern int Main2(int numArguments, const char *arguments[]);
|
||||
extern int Main2();
|
||||
CStdOutStream *g_StdStream = 0;
|
||||
|
||||
extern int Main2(
|
||||
#ifndef _WIN32
|
||||
int numArguments, const char *arguments[]
|
||||
#endif
|
||||
);
|
||||
|
||||
static const char *kExceptionErrorMessage = "\n\nError:\n";
|
||||
static const char *kUserBreak = "\nBreak signaled\n";
|
||||
|
||||
static const char *kMemoryExceptionMessage = "\n\nMemory Error! Can't allocate!\n";
|
||||
static const char *kMemoryExceptionMessage = "\n\nERROR: Can't allocate required memory!\n";
|
||||
static const char *kUnknownExceptionMessage = "\n\nUnknown Error\n";
|
||||
static const char *kInternalExceptionMessage = "\n\nInternal Error #";
|
||||
|
||||
#ifdef UNICODE
|
||||
static inline bool IsItWindowsNT()
|
||||
{
|
||||
OSVERSIONINFO versionInfo;
|
||||
@@ -34,81 +40,100 @@ static inline bool IsItWindowsNT()
|
||||
return false;
|
||||
return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);
|
||||
}
|
||||
#endif
|
||||
|
||||
int __cdecl main()
|
||||
// int __cdecl main(int numArguments, const char *arguments[])
|
||||
int
|
||||
#ifdef _MSC_VER
|
||||
__cdecl
|
||||
#endif
|
||||
main
|
||||
(
|
||||
#ifndef _WIN32
|
||||
int numArguments, const char *arguments[]
|
||||
#endif
|
||||
)
|
||||
{
|
||||
g_StdStream = &g_StdOut;
|
||||
#ifdef UNICODE
|
||||
if (!IsItWindowsNT())
|
||||
{
|
||||
g_StdOut << "This program requires Windows NT/2000/XP";
|
||||
(*g_StdStream) << "This program requires Windows NT/2000/XP/2003";
|
||||
return NExitCode::kFatalError;
|
||||
}
|
||||
#endif
|
||||
// setlocale(LC_COLLATE, ".OCP");
|
||||
int result=1;
|
||||
NCOM::CComInitializer comInitializer;
|
||||
NConsoleClose::CCtrlHandlerSetter ctrlHandlerSetter;
|
||||
try
|
||||
{
|
||||
NConsoleClose::CCtrlHandlerSetter aCtrlHandlerSetter;
|
||||
try
|
||||
{
|
||||
// result = Main2(numArguments, arguments);
|
||||
result = Main2();
|
||||
}
|
||||
catch(const NConsoleClose::CCtrlBreakException &)
|
||||
{
|
||||
g_StdOut << endl << kUserBreak;
|
||||
return (NExitCode::kUserBreak);
|
||||
}
|
||||
return Main2(
|
||||
#ifndef _WIN32
|
||||
numArguments, arguments
|
||||
#endif
|
||||
);
|
||||
}
|
||||
catch(const CNewException)
|
||||
catch(const CNewException &)
|
||||
{
|
||||
g_StdOut << kMemoryExceptionMessage;
|
||||
(*g_StdStream) << kMemoryExceptionMessage;
|
||||
return (NExitCode::kMemoryError);
|
||||
}
|
||||
catch(const CSystemException &e)
|
||||
catch(const NConsoleClose::CCtrlBreakException &)
|
||||
{
|
||||
g_StdOut << "System Error: " << (UINT64)(e.ErrorCode);
|
||||
return (NExitCode::kFatalError);
|
||||
(*g_StdStream) << endl << kUserBreak;
|
||||
return (NExitCode::kUserBreak);
|
||||
}
|
||||
catch(NExitCode::EEnum &aExitCode)
|
||||
{
|
||||
g_StdOut << kInternalExceptionMessage << aExitCode << endl;
|
||||
return (aExitCode);
|
||||
}
|
||||
catch(const NExitCode::CSystemError &systemError)
|
||||
catch(const CSystemException &systemError)
|
||||
{
|
||||
if (systemError.ErrorCode == E_OUTOFMEMORY)
|
||||
{
|
||||
(*g_StdStream) << kMemoryExceptionMessage;
|
||||
return (NExitCode::kMemoryError);
|
||||
}
|
||||
if (systemError.ErrorCode == E_ABORT)
|
||||
{
|
||||
(*g_StdStream) << endl << kUserBreak;
|
||||
return (NExitCode::kUserBreak);
|
||||
}
|
||||
UString message;
|
||||
NError::MyFormatMessage(systemError.ErrorValue, message);
|
||||
g_StdOut << endl << endl << "System error:" << endl <<
|
||||
NError::MyFormatMessage(systemError.ErrorCode, message);
|
||||
(*g_StdStream) << endl << endl << "System error:" << endl <<
|
||||
message << endl;
|
||||
return (NExitCode::kFatalError);
|
||||
}
|
||||
catch(NExitCode::EEnum &exitCode)
|
||||
{
|
||||
(*g_StdStream) << kInternalExceptionMessage << exitCode << endl;
|
||||
return (exitCode);
|
||||
}
|
||||
/*
|
||||
catch(const NExitCode::CMultipleErrors &multipleErrors)
|
||||
{
|
||||
g_StdOut << endl << multipleErrors.NumErrors << " errors" << endl;
|
||||
(*g_StdStream) << endl << multipleErrors.NumErrors << " errors" << endl;
|
||||
return (NExitCode::kFatalError);
|
||||
}
|
||||
*/
|
||||
catch(const UString &s)
|
||||
{
|
||||
g_StdOut << kExceptionErrorMessage << s << endl;
|
||||
(*g_StdStream) << kExceptionErrorMessage << s << endl;
|
||||
return (NExitCode::kFatalError);
|
||||
}
|
||||
catch(const AString &s)
|
||||
{
|
||||
(*g_StdStream) << kExceptionErrorMessage << s << endl;
|
||||
return (NExitCode::kFatalError);
|
||||
}
|
||||
catch(const char *s)
|
||||
{
|
||||
g_StdOut << kExceptionErrorMessage << s << endl;
|
||||
(*g_StdStream) << kExceptionErrorMessage << s << endl;
|
||||
return (NExitCode::kFatalError);
|
||||
}
|
||||
catch(int t)
|
||||
{
|
||||
g_StdOut << kInternalExceptionMessage << t << endl;
|
||||
(*g_StdStream) << kInternalExceptionMessage << t << endl;
|
||||
return (NExitCode::kFatalError);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
g_StdOut << kUnknownExceptionMessage;
|
||||
(*g_StdStream) << kUnknownExceptionMessage;
|
||||
return (NExitCode::kFatalError);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
// OpenCallback.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "OpenCallback.h"
|
||||
|
||||
#include "Common/StdOutStream.h"
|
||||
#include "Common/StdInStream.h"
|
||||
#include "Common/StringConvert.h"
|
||||
|
||||
#include "../../Common/FileStreams.h"
|
||||
|
||||
#include "Windows/PropVariant.h"
|
||||
|
||||
#include "ConsoleClose.h"
|
||||
|
||||
STDMETHODIMP COpenCallbackImp::SetTotal(const UINT64 *files, const UINT64 *bytes)
|
||||
{
|
||||
if (NConsoleClose::TestBreakSignal())
|
||||
return E_ABORT;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP COpenCallbackImp::SetCompleted(const UINT64 *files, const UINT64 *bytes)
|
||||
{
|
||||
if (NConsoleClose::TestBreakSignal())
|
||||
return E_ABORT;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP COpenCallbackImp::GetProperty(PROPID propID, PROPVARIANT *value)
|
||||
{
|
||||
NWindows::NCOM::CPropVariant propVariant;
|
||||
switch(propID)
|
||||
{
|
||||
case kpidName:
|
||||
propVariant = _fileInfo.Name;
|
||||
break;
|
||||
case kpidIsFolder:
|
||||
propVariant = _fileInfo.IsDirectory();
|
||||
break;
|
||||
case kpidSize:
|
||||
propVariant = _fileInfo.Size;
|
||||
break;
|
||||
case kpidAttributes:
|
||||
propVariant = (UINT32)_fileInfo.Attributes;
|
||||
break;
|
||||
case kpidLastAccessTime:
|
||||
propVariant = _fileInfo.LastAccessTime;
|
||||
break;
|
||||
case kpidCreationTime:
|
||||
propVariant = _fileInfo.CreationTime;
|
||||
break;
|
||||
case kpidLastWriteTime:
|
||||
propVariant = _fileInfo.LastWriteTime;
|
||||
break;
|
||||
}
|
||||
propVariant.Detach(value);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP COpenCallbackImp::GetStream(const wchar_t *name,
|
||||
IInStream **inStream)
|
||||
{
|
||||
*inStream = NULL;
|
||||
UString fullPath = _folderPrefix + name;
|
||||
if (!NWindows::NFile::NFind::FindFile(fullPath, _fileInfo))
|
||||
return S_FALSE;
|
||||
if (_fileInfo.IsDirectory())
|
||||
return S_FALSE;
|
||||
CInFileStream *inFile = new CInFileStream;
|
||||
CMyComPtr<IInStream> inStreamTemp = inFile;
|
||||
if (!inFile->Open(fullPath))
|
||||
return ::GetLastError();
|
||||
*inStream = inStreamTemp.Detach();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP COpenCallbackImp::CryptoGetTextPassword(BSTR *password)
|
||||
{
|
||||
if (!PasswordIsDefined)
|
||||
{
|
||||
g_StdOut << "\nEnter password:";
|
||||
AString oemPassword = g_StdIn.ScanStringUntilNewLine();
|
||||
Password = MultiByteToUnicodeString(oemPassword, CP_OEMCP);
|
||||
PasswordIsDefined = true;
|
||||
}
|
||||
CMyComBSTR temp(Password);
|
||||
*password = temp.Detach();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
// OpenCallback.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __OPENCALLBACK_H
|
||||
#define __OPENCALLBACK_H
|
||||
|
||||
#include "Common/String.h"
|
||||
#include "Common/MyCom.h"
|
||||
#include "Windows/FileFind.h"
|
||||
|
||||
#include "../../Archive/IArchive.h"
|
||||
#include "../../IPassword.h"
|
||||
|
||||
class COpenCallbackImp:
|
||||
public IArchiveOpenCallback,
|
||||
public IArchiveOpenVolumeCallback,
|
||||
public ICryptoGetTextPassword,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
public:
|
||||
MY_UNKNOWN_IMP2(
|
||||
IArchiveOpenVolumeCallback,
|
||||
ICryptoGetTextPassword
|
||||
)
|
||||
|
||||
STDMETHOD(SetTotal)(const UINT64 *files, const UINT64 *bytes);
|
||||
STDMETHOD(SetCompleted)(const UINT64 *files, const UINT64 *bytes);
|
||||
|
||||
// IArchiveOpenVolumeCallback
|
||||
STDMETHOD(GetProperty)(PROPID propID, PROPVARIANT *value);
|
||||
STDMETHOD(GetStream)(const wchar_t *name, IInStream **inStream);
|
||||
|
||||
// ICryptoGetTextPassword
|
||||
STDMETHOD(CryptoGetTextPassword)(BSTR *password);
|
||||
|
||||
private:
|
||||
UString _folderPrefix;
|
||||
NWindows::NFile::NFind::CFileInfoW _fileInfo;
|
||||
public:
|
||||
bool PasswordIsDefined;
|
||||
UString Password;
|
||||
COpenCallbackImp(): PasswordIsDefined(false) {}
|
||||
void LoadFileInfo(const UString &folderPrefix, const UString &fileName)
|
||||
{
|
||||
_folderPrefix = folderPrefix;
|
||||
if (!NWindows::NFile::NFind::FindFile(_folderPrefix + fileName, _fileInfo))
|
||||
throw 1;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
47
7zip/UI/Console/OpenCallbackConsole.cpp
Executable file
47
7zip/UI/Console/OpenCallbackConsole.cpp
Executable file
@@ -0,0 +1,47 @@
|
||||
// OpenCallbackConsole.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "OpenCallbackConsole.h"
|
||||
|
||||
#include "ConsoleClose.h"
|
||||
#include "UserInputUtils.h"
|
||||
|
||||
HRESULT COpenCallbackConsole::CheckBreak()
|
||||
{
|
||||
if (NConsoleClose::TestBreakSignal())
|
||||
return E_ABORT;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT COpenCallbackConsole::SetTotal(const UInt64 *files, const UInt64 *bytes)
|
||||
{
|
||||
return CheckBreak();
|
||||
}
|
||||
|
||||
HRESULT COpenCallbackConsole::SetCompleted(const UInt64 *files, const UInt64 *bytes)
|
||||
{
|
||||
return CheckBreak();
|
||||
}
|
||||
|
||||
HRESULT COpenCallbackConsole::CryptoGetTextPassword(BSTR *password)
|
||||
{
|
||||
RINOK(CheckBreak());
|
||||
if (!PasswordIsDefined)
|
||||
{
|
||||
Password = GetPassword(OutStream);
|
||||
PasswordIsDefined = true;
|
||||
}
|
||||
CMyComBSTR temp(Password);
|
||||
*password = temp.Detach();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT COpenCallbackConsole::GetPasswordIfAny(UString &password)
|
||||
{
|
||||
if (PasswordIsDefined)
|
||||
password = Password;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
24
7zip/UI/Console/OpenCallbackConsole.h
Executable file
24
7zip/UI/Console/OpenCallbackConsole.h
Executable file
@@ -0,0 +1,24 @@
|
||||
// OpenCallbackConsole.h
|
||||
|
||||
#ifndef __OPENCALLBACKCONSOLE_H
|
||||
#define __OPENCALLBACKCONSOLE_H
|
||||
|
||||
#include "Common/StdOutStream.h"
|
||||
#include "../Common/ArchiveOpenCallback.h"
|
||||
|
||||
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);
|
||||
|
||||
CStdOutStream *OutStream;
|
||||
bool PasswordIsDefined;
|
||||
UString Password;
|
||||
COpenCallbackConsole(): PasswordIsDefined(false) {}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "Common/StdOutStream.h"
|
||||
#include "Common/IntToString.h"
|
||||
#include "Common/String.h"
|
||||
|
||||
@@ -14,7 +13,7 @@ static const char *kCloseString = "\b\b\b\b \b\b\b\b";
|
||||
static const char *kPercentFormatString1 = "\b\b\b\b";
|
||||
static const int kNumDigits = 3;
|
||||
|
||||
CPercentPrinter::CPercentPrinter(UINT64 minStepSize):
|
||||
CPercentPrinter::CPercentPrinter(UInt64 minStepSize):
|
||||
m_MinStepSize(minStepSize),
|
||||
m_ScreenPos(0),
|
||||
m_StringIsPrinted(false)
|
||||
@@ -27,53 +26,51 @@ CPercentPrinter::CPercentPrinter(UINT64 minStepSize):
|
||||
void CPercentPrinter::PreparePrint()
|
||||
{
|
||||
if (m_ScreenPos < kNumPercentSpaces)
|
||||
g_StdOut << (m_Spaces + m_ScreenPos);
|
||||
(*OutStream) << (m_Spaces + m_ScreenPos);
|
||||
m_ScreenPos = kNumPercentSpaces;
|
||||
g_StdOut << kPrepareString;
|
||||
(*OutStream) << kPrepareString;
|
||||
}
|
||||
|
||||
void CPercentPrinter::ClosePrint()
|
||||
{
|
||||
g_StdOut << kCloseString;
|
||||
(*OutStream) << kCloseString;
|
||||
m_StringIsPrinted = false;
|
||||
}
|
||||
|
||||
void CPercentPrinter::PrintString(const char *s)
|
||||
{
|
||||
m_ScreenPos += MyStringLen(s);
|
||||
g_StdOut << s;
|
||||
(*OutStream) << s;
|
||||
}
|
||||
|
||||
void CPercentPrinter::PrintString(const wchar_t *s)
|
||||
{
|
||||
m_ScreenPos += MyStringLen(s);
|
||||
g_StdOut << s;
|
||||
(*OutStream) << s;
|
||||
}
|
||||
|
||||
void CPercentPrinter::PrintNewLine()
|
||||
{
|
||||
m_ScreenPos = 0;
|
||||
g_StdOut << "\n";
|
||||
(*OutStream) << "\n";
|
||||
m_StringIsPrinted = false;
|
||||
}
|
||||
|
||||
void CPercentPrinter::SetRatio(UINT64 doneValue)
|
||||
void CPercentPrinter::SetRatio(UInt64 doneValue)
|
||||
{ m_CurValue = doneValue; }
|
||||
|
||||
void CPercentPrinter::RePrintRatio()
|
||||
{
|
||||
if (m_Total == 0)
|
||||
return;
|
||||
UINT64 ratio = m_CurValue * 100 / m_Total;
|
||||
// char temp[32];
|
||||
// sprintf(temp, kPercentFormatString, ratio);
|
||||
UInt64 ratio = m_CurValue * 100 / m_Total;
|
||||
char temp[32 + kNumDigits] = " "; // for 4 digits;
|
||||
ConvertUINT64ToString(ratio, temp + kNumDigits);
|
||||
int len = lstrlenA(temp + kNumDigits);
|
||||
lstrcatA(temp, "%");
|
||||
ConvertUInt64ToString(ratio, temp + kNumDigits);
|
||||
int len = strlen(temp + kNumDigits);
|
||||
strcat(temp, "%");
|
||||
int pos = (len > kNumDigits)? kNumDigits : len;
|
||||
g_StdOut << kPercentFormatString1;
|
||||
g_StdOut << (temp + pos);
|
||||
(*OutStream) << kPercentFormatString1;
|
||||
(*OutStream) << (temp + pos);
|
||||
m_PrevValue = m_CurValue;
|
||||
m_StringIsPrinted = true;
|
||||
}
|
||||
|
||||
@@ -1,25 +1,27 @@
|
||||
// PercentPrinter.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __PERCENTPRINTER_H
|
||||
#define __PERCENTPRINTER_H
|
||||
|
||||
#include "Common/Defs.h"
|
||||
#include "Common/Types.h"
|
||||
#include "Common/StdOutStream.h"
|
||||
|
||||
const int kNumPercentSpaces = 70;
|
||||
class CPercentPrinter
|
||||
{
|
||||
UINT64 m_MinStepSize;
|
||||
UINT64 m_PrevValue;
|
||||
UINT64 m_CurValue;
|
||||
UINT64 m_Total;
|
||||
UINT32 m_ScreenPos;
|
||||
UInt64 m_MinStepSize;
|
||||
UInt64 m_PrevValue;
|
||||
UInt64 m_CurValue;
|
||||
UInt64 m_Total;
|
||||
UInt32 m_ScreenPos;
|
||||
char m_Spaces[kNumPercentSpaces + 1];
|
||||
bool m_StringIsPrinted;
|
||||
public:
|
||||
CPercentPrinter(UINT64 minStepSize = 1);
|
||||
void SetTotal(UINT64 total)
|
||||
CStdOutStream *OutStream;
|
||||
|
||||
CPercentPrinter(UInt64 minStepSize = 1);
|
||||
void SetTotal(UInt64 total)
|
||||
{
|
||||
m_Total = total;
|
||||
m_PrevValue = 0;
|
||||
@@ -30,7 +32,7 @@ public:
|
||||
void PrintNewLine();
|
||||
void PreparePrint();
|
||||
void ClosePrint();
|
||||
void SetRatio(UINT64 doneValue);
|
||||
void SetRatio(UInt64 doneValue);
|
||||
void RePrintRatio();
|
||||
void PrintRatio();
|
||||
};
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
// StdAfx.cpp
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "StdAfx.h"
|
||||
|
||||
@@ -1,16 +1,8 @@
|
||||
// stdafx.h
|
||||
// StdAfx.h
|
||||
|
||||
#ifndef __STDAFX_H
|
||||
#define __STDAFX_H
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#include <tchar.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <vector>
|
||||
#include "../../../Common/MyWindows.h"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
// TempFiles.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "TempFiles.h"
|
||||
|
||||
#include "Windows/FileDir.h"
|
||||
#include "Windows/FileIO.h"
|
||||
|
||||
using namespace NWindows;
|
||||
using namespace NFile;
|
||||
|
||||
void CFileVectorBundle::DisableDeleting(int index)
|
||||
{
|
||||
m_FileNames.Delete(index);
|
||||
}
|
||||
|
||||
bool CFileVectorBundle::Add(const UString &filePath, bool tryToOpen)
|
||||
{
|
||||
if (tryToOpen)
|
||||
{
|
||||
NIO::COutFile file;
|
||||
if (!file.Open(filePath))
|
||||
return false;
|
||||
}
|
||||
m_FileNames.Add(filePath);
|
||||
return true;
|
||||
}
|
||||
|
||||
void CFileVectorBundle::Clear()
|
||||
{
|
||||
while(!m_FileNames.IsEmpty())
|
||||
{
|
||||
NDirectory::DeleteFileAlways(m_FileNames.Back());
|
||||
m_FileNames.DeleteBack();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
// FileCreationUtils.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __FILECREATIONUTILS_H
|
||||
#define __FILECREATIONUTILS_H
|
||||
|
||||
#include "Common/String.h"
|
||||
|
||||
class CFileVectorBundle
|
||||
{
|
||||
UStringVector m_FileNames;
|
||||
public:
|
||||
~CFileVectorBundle() { Clear(); }
|
||||
bool Add(const UString &filePath, bool tryToOpen = true);
|
||||
void DisableDeleting(int index);
|
||||
void Clear();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,503 +0,0 @@
|
||||
// Update.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "Update.h"
|
||||
|
||||
#include "Common/StdOutStream.h"
|
||||
#include "Common/StringConvert.h"
|
||||
#include "Common/MyCom.h"
|
||||
|
||||
#include "Windows/Defs.h"
|
||||
#include "Windows/Error.h"
|
||||
#include "Windows/FileDir.h"
|
||||
#include "Windows/FileFind.h"
|
||||
#include "Windows/FileName.h"
|
||||
#include "Windows/PropVariant.h"
|
||||
#include "Windows/PropVariantConversions.h"
|
||||
#include "Windows/Error.h"
|
||||
|
||||
#include "../../Common/FileStreams.h"
|
||||
#include "../../Compress/Copy/CopyCoder.h"
|
||||
|
||||
#include "../Common/DirItem.h"
|
||||
#include "../Common/EnumDirItems.h"
|
||||
#include "../Common/UpdateProduce.h"
|
||||
|
||||
#include "TempFiles.h"
|
||||
#include "ConsoleClose.h"
|
||||
#include "UpdateCallback.h"
|
||||
|
||||
#ifdef FORMAT_7Z
|
||||
#include "../../Archive/7z/7zHandler.h"
|
||||
#endif
|
||||
|
||||
#ifdef FORMAT_BZIP2
|
||||
#include "../../Archive/BZip2/BZip2Handler.h"
|
||||
#endif
|
||||
|
||||
#ifdef FORMAT_GZIP
|
||||
#include "../../Archive/GZip/GZipHandler.h"
|
||||
#endif
|
||||
|
||||
#ifdef FORMAT_TAR
|
||||
#include "../../Archive/Tar/TarHandler.h"
|
||||
#endif
|
||||
|
||||
#ifdef FORMAT_ZIP
|
||||
#include "../../Archive/Zip/ZipHandler.h"
|
||||
#endif
|
||||
|
||||
#ifndef EXCLUDE_COM
|
||||
#include "../Common/HandlerLoader.h"
|
||||
#endif
|
||||
|
||||
static const char *kCreatingArchiveMessage = "Creating archive ";
|
||||
static const char *kUpdatingArchiveMessage = "Updating archive ";
|
||||
static const char *kScanningMessage = "Scanning";
|
||||
static const char *kNoFilesScannedMessage = "No files scanned";
|
||||
static const char *kTotalFilesAddedMessage = "Total files added to archive: ";
|
||||
|
||||
using namespace NWindows;
|
||||
using namespace NCOM;
|
||||
using namespace NFile;
|
||||
using namespace NName;
|
||||
|
||||
static wchar_t *kTempArchiveFilePrefixString = L"7zi";
|
||||
static const char *kEverythingIsOk = "Everything is Ok";
|
||||
|
||||
static const char *kIllegalFileNameMessage = "Illegal file name for temp archive";
|
||||
|
||||
using namespace NUpdateArchive;
|
||||
|
||||
static bool ParseNumberString(const UString &srcString, UINT32 &number)
|
||||
{
|
||||
wchar_t *anEndPtr;
|
||||
number = wcstoul(srcString, &anEndPtr, 10);
|
||||
return (anEndPtr - srcString == srcString.Length());
|
||||
}
|
||||
|
||||
|
||||
static HRESULT CopyBlock(ISequentialInStream *inStream, ISequentialOutStream *outStream)
|
||||
{
|
||||
CMyComPtr<ICompressCoder> copyCoder = new NCompress::CCopyCoder;
|
||||
return copyCoder->Code(inStream, outStream, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
HRESULT Compress(
|
||||
const CActionSet &actionSet,
|
||||
IInArchive *archive,
|
||||
const CCompressionMethodMode &compressionMethod,
|
||||
const UString &archiveName,
|
||||
const CObjectVector<CArchiveItem> &archiveItems,
|
||||
const CObjectVector<CDirItem> &dirItems,
|
||||
bool enablePercents,
|
||||
bool sfxMode,
|
||||
const UString &sfxModule)
|
||||
{
|
||||
#ifndef EXCLUDE_COM
|
||||
CHandlerLoader loader;
|
||||
#endif
|
||||
|
||||
CMyComPtr<IOutArchive> outArchive;
|
||||
if(archive != NULL)
|
||||
{
|
||||
CMyComPtr<IInArchive> archive2 = archive;
|
||||
HRESULT result = archive2.QueryInterface(IID_IOutArchive, &outArchive);
|
||||
if(result != S_OK)
|
||||
{
|
||||
throw "update operations are not supported for this archive";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifndef EXCLUDE_COM
|
||||
|
||||
HRESULT result = loader.CreateHandler(compressionMethod.FilePath,
|
||||
compressionMethod.ClassID1, (void **)&outArchive, true);
|
||||
|
||||
if (result != S_OK)
|
||||
{
|
||||
throw "update operations are not supported for this archive";
|
||||
return E_FAIL;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef FORMAT_7Z
|
||||
if (compressionMethod.Name.CompareNoCase(L"7z") == 0)
|
||||
outArchive = new NArchive::N7z::CHandler;
|
||||
#endif
|
||||
|
||||
#ifdef FORMAT_BZIP2
|
||||
if (compressionMethod.Name.CompareNoCase(L"BZip2") == 0)
|
||||
outArchive = new NArchive::NBZip2::CHandler;
|
||||
#endif
|
||||
|
||||
#ifdef FORMAT_GZIP
|
||||
if (compressionMethod.Name.CompareNoCase(L"GZip") == 0)
|
||||
outArchive = new NArchive::NGZip::CHandler;
|
||||
#endif
|
||||
|
||||
#ifdef FORMAT_TAR
|
||||
if (compressionMethod.Name.CompareNoCase(L"Tar") == 0)
|
||||
outArchive = new NArchive::NTar::CHandler;
|
||||
#endif
|
||||
|
||||
#ifdef FORMAT_ZIP
|
||||
if (compressionMethod.Name.CompareNoCase(L"Zip") == 0)
|
||||
outArchive = new NArchive::NZip::CHandler;
|
||||
#endif
|
||||
|
||||
|
||||
if (outArchive == 0)
|
||||
{
|
||||
throw "update operations are not supported for this archive";
|
||||
return E_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
NFileTimeType::EEnum fileTimeType;
|
||||
UINT32 value;
|
||||
RINOK(outArchive->GetFileTimeType(&value));
|
||||
|
||||
switch(value)
|
||||
{
|
||||
case NFileTimeType::kWindows:
|
||||
case NFileTimeType::kDOS:
|
||||
case NFileTimeType::kUnix:
|
||||
fileTimeType = NFileTimeType::EEnum(value);
|
||||
break;
|
||||
default:
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
CObjectVector<CUpdatePair> updatePairs;
|
||||
GetUpdatePairInfoList(dirItems, archiveItems, fileTimeType, updatePairs); // must be done only once!!!
|
||||
|
||||
CObjectVector<CUpdatePair2> operationChain;
|
||||
UpdateProduce(dirItems, archiveItems, updatePairs, actionSet,
|
||||
operationChain);
|
||||
|
||||
CUpdateCallbackImp *updateCallbackSpec = new CUpdateCallbackImp;
|
||||
CMyComPtr<IArchiveUpdateCallback> updateCallback(updateCallbackSpec );
|
||||
|
||||
updateCallbackSpec->Init(&dirItems, &archiveItems, &operationChain, enablePercents,
|
||||
compressionMethod.PasswordIsDefined, compressionMethod.Password,
|
||||
compressionMethod.AskPassword);
|
||||
|
||||
COutFileStream *outStreamSpec = new COutFileStream;
|
||||
CMyComPtr<IOutStream> outStream(outStreamSpec);
|
||||
|
||||
{
|
||||
UString resultPath;
|
||||
int pos;
|
||||
if(! NFile::NDirectory::MyGetFullPathName(archiveName, resultPath, pos))
|
||||
throw 141716;
|
||||
NFile::NDirectory::CreateComplexDirectory(resultPath.Left(pos));
|
||||
}
|
||||
if (!outStreamSpec->Open(archiveName))
|
||||
{
|
||||
UString message;
|
||||
NError::MyFormatMessage(::GetLastError(), message);
|
||||
g_StdOut << message << endl;
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
CMyComPtr<ISetProperties> setProperties;
|
||||
if (outArchive.QueryInterface(IID_ISetProperties, &setProperties) == S_OK)
|
||||
{
|
||||
CObjectVector<CMyComBSTR> realNames;
|
||||
std::vector<CPropVariant> values;
|
||||
int i;
|
||||
for(i = 0; i < compressionMethod.Properties.Size(); i++)
|
||||
{
|
||||
const CProperty &property = compressionMethod.Properties[i];
|
||||
NCOM::CPropVariant propVariant;
|
||||
UINT32 number;
|
||||
if (!property.Value.IsEmpty())
|
||||
{
|
||||
if (ParseNumberString(property.Value, number))
|
||||
propVariant = number;
|
||||
else
|
||||
propVariant = property.Value;
|
||||
}
|
||||
CMyComBSTR comBSTR(property.Name);
|
||||
realNames.Add(comBSTR);
|
||||
values.push_back(propVariant);
|
||||
}
|
||||
std::vector<BSTR> names;
|
||||
for(i = 0; i < realNames.Size(); i++)
|
||||
names.push_back(realNames[i]);
|
||||
|
||||
RINOK(setProperties->SetProperties(&names.front(),
|
||||
&values.front(), names.size()));
|
||||
}
|
||||
|
||||
if (sfxMode)
|
||||
{
|
||||
CInFileStream *sfxStreamSpec = new CInFileStream;
|
||||
CMyComPtr<IInStream> sfxStream(sfxStreamSpec);
|
||||
if (!sfxStreamSpec->Open(sfxModule))
|
||||
throw "Can't open sfx module";
|
||||
RINOK(CopyBlock(sfxStream, outStream));
|
||||
}
|
||||
|
||||
return outArchive->UpdateItems(outStream, operationChain.Size(),
|
||||
updateCallback);
|
||||
}
|
||||
|
||||
static void EnumerateDirItems(const NWildcard::CCensorNode &curNode,
|
||||
const UString &directory,
|
||||
const UString &prefix,
|
||||
bool checkNameFull,
|
||||
CObjectVector<CDirItem> &dirItems,
|
||||
bool enterToSubFolders)
|
||||
{
|
||||
NConsoleClose::CheckCtrlBreak();
|
||||
|
||||
NFind::CEnumeratorW enumerator(directory + wchar_t(kAnyStringWildcard));
|
||||
NFind::CFileInfoW fileInfo;
|
||||
while (enumerator.Next(fileInfo))
|
||||
{
|
||||
NConsoleClose::CheckCtrlBreak();
|
||||
UString unicodeName = fileInfo.Name;
|
||||
if (checkNameFull)
|
||||
{
|
||||
if (curNode.CheckNameFull(unicodeName))
|
||||
AddDirFileInfo(prefix, directory + fileInfo.Name, fileInfo,
|
||||
dirItems);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (curNode.CheckNameRecursive(unicodeName))
|
||||
AddDirFileInfo(prefix, directory + fileInfo.Name, fileInfo,
|
||||
dirItems);
|
||||
}
|
||||
if (enterToSubFolders && fileInfo.IsDirectory())
|
||||
{
|
||||
const NWildcard::CCensorNode *nextNode = &curNode;
|
||||
if (checkNameFull)
|
||||
{
|
||||
nextNode = ((NWildcard::CCensorNode *)&curNode)->FindSubNode(unicodeName);
|
||||
if (nextNode == NULL)
|
||||
nextNode = &curNode;
|
||||
}
|
||||
EnumerateDirItems(*nextNode,
|
||||
directory + fileInfo.Name + wchar_t(kDirDelimiter),
|
||||
prefix + unicodeName + wchar_t(kDirDelimiter),
|
||||
nextNode != (&curNode), dirItems, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void EnumerateItems(const NWildcard::CCensorNode &curNode,
|
||||
const UString &directory,
|
||||
const UString &prefix,
|
||||
CObjectVector<CDirItem> &dirItems)
|
||||
{
|
||||
NConsoleClose::CheckCtrlBreak();
|
||||
if (!curNode.GetAllowedRecursedNamesVector(false).IsEmpty() ||
|
||||
!curNode.GetAllowedRecursedNamesVector(true).IsEmpty())
|
||||
{
|
||||
EnumerateDirItems(curNode, directory, prefix, true, dirItems,
|
||||
true);
|
||||
return;
|
||||
}
|
||||
if (!curNode.GetAllowedNamesVector(false, true).IsEmpty())
|
||||
{
|
||||
EnumerateDirItems(curNode, directory, prefix, true, dirItems,
|
||||
false);
|
||||
}
|
||||
else
|
||||
{
|
||||
const UStringVector &directNames = curNode.GetAllowedNamesVector(false, false);
|
||||
for (int i = 0; i < directNames.Size(); i++)
|
||||
{
|
||||
const UString &nameSpec = directNames[i];
|
||||
if (curNode.CheckName(nameSpec, false, false))
|
||||
continue;
|
||||
|
||||
NFind::CFileInfoW fileInfo;
|
||||
if (!NFind::FindFile(directory + nameSpec, fileInfo))
|
||||
continue;
|
||||
|
||||
AddDirFileInfo(prefix, directory + fileInfo.Name, fileInfo, dirItems);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < curNode.SubNodes.Size(); i++)
|
||||
{
|
||||
const NWildcard::CCensorNode &nextNode = curNode.SubNodes[i];
|
||||
EnumerateItems(nextNode,
|
||||
directory + nextNode.Name + wchar_t(kDirDelimiter),
|
||||
prefix + nextNode.Name + wchar_t(kDirDelimiter),
|
||||
dirItems);
|
||||
}
|
||||
}
|
||||
|
||||
HRESULT GetFileTime(IInArchive *archive, UINT32 index,
|
||||
FILETIME &fileTime, const FILETIME &defaultFileTime)
|
||||
{
|
||||
CPropVariant property;
|
||||
RINOK(archive->GetProperty(index, kpidLastWriteTime, &property));
|
||||
if (property.vt == VT_FILETIME)
|
||||
fileTime = property.filetime;
|
||||
else if (property.vt == VT_EMPTY)
|
||||
fileTime = defaultFileTime;
|
||||
else
|
||||
throw 4190407;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT EnumerateInArchiveItems(const NWildcard::CCensor &censor,
|
||||
IInArchive *archive,
|
||||
const UString &defaultItemName,
|
||||
const NWindows::NFile::NFind::CFileInfoW &archiveFileInfo,
|
||||
CObjectVector<CArchiveItem> &archiveItems)
|
||||
{
|
||||
archiveItems.Clear();
|
||||
UINT32 numItems;
|
||||
RINOK(archive->GetNumberOfItems(&numItems));
|
||||
archiveItems.Reserve(numItems);
|
||||
for(UINT32 i = 0; i < numItems; i++)
|
||||
{
|
||||
CArchiveItem archiveItem;
|
||||
NCOM::CPropVariant propVariantPath;
|
||||
RINOK(archive->GetProperty(i, kpidPath, &propVariantPath));
|
||||
UString filePath;
|
||||
if(propVariantPath.vt == VT_EMPTY)
|
||||
archiveItem.Name = defaultItemName;
|
||||
else
|
||||
{
|
||||
if(propVariantPath.vt != VT_BSTR)
|
||||
return E_FAIL;
|
||||
archiveItem.Name = propVariantPath.bstrVal;
|
||||
}
|
||||
archiveItem.Censored = censor.CheckName(archiveItem.Name);
|
||||
|
||||
RINOK(GetFileTime(archive, i, archiveItem.LastWriteTime,
|
||||
archiveFileInfo.LastWriteTime));
|
||||
|
||||
CPropVariant propertySize;
|
||||
RINOK(archive->GetProperty(i, kpidSize, &propertySize));
|
||||
if (archiveItem.SizeIsDefined = (propertySize.vt != VT_EMPTY))
|
||||
archiveItem.Size = ConvertPropVariantToUINT64(propertySize);
|
||||
|
||||
CPropVariant propertyIsFolder;
|
||||
RINOK(archive->GetProperty(i, kpidIsFolder, &propertyIsFolder));
|
||||
if(propertyIsFolder.vt != VT_BOOL)
|
||||
return E_FAIL;
|
||||
archiveItem.IsDirectory = VARIANT_BOOLToBool(propertyIsFolder.boolVal);
|
||||
|
||||
archiveItem.IndexInServer = i;
|
||||
archiveItems.Add(archiveItem);
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
static HRESULT UpdateWithItemLists(
|
||||
const CUpdateArchiveOptions &options,
|
||||
IInArchive *archive,
|
||||
const CObjectVector<CArchiveItem> &archiveItems,
|
||||
const CObjectVector<CDirItem> &dirItems,
|
||||
bool enablePercents)
|
||||
{
|
||||
for(int i = 0; i < options.Commands.Size(); i++)
|
||||
{
|
||||
const CUpdateArchiveCommand &command = options.Commands[i];
|
||||
const UString &realArchivePath = command.ArchivePath;
|
||||
if (i == 0 && options.UpdateArchiveItself)
|
||||
{
|
||||
if(archive != 0)
|
||||
g_StdOut << kUpdatingArchiveMessage;
|
||||
else
|
||||
g_StdOut << kCreatingArchiveMessage;
|
||||
g_StdOut << options.ArchivePath;
|
||||
}
|
||||
else
|
||||
g_StdOut << kCreatingArchiveMessage << realArchivePath;
|
||||
|
||||
g_StdOut << endl << endl;
|
||||
|
||||
RINOK(Compress(command.ActionSet, archive,
|
||||
options.MethodMode, realArchivePath,
|
||||
archiveItems, dirItems, enablePercents,
|
||||
options.SfxMode, options.SfxModule));
|
||||
|
||||
g_StdOut << endl;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT UpdateArchiveStdMain(const NWildcard::CCensor &censor,
|
||||
CUpdateArchiveOptions &options, const UString &workingDir,
|
||||
IInArchive *archive,
|
||||
const UString *defaultItemName,
|
||||
const NWindows::NFile::NFind::CFileInfoW *archiveFileInfo,
|
||||
bool enablePercents)
|
||||
{
|
||||
CObjectVector<CDirItem> dirItems;
|
||||
g_StdOut << kScanningMessage;
|
||||
EnumerateItems(censor._head, L"", L"", dirItems);
|
||||
g_StdOut << endl;
|
||||
|
||||
CFileVectorBundle fileVectorBundle;
|
||||
if(options.UpdateArchiveItself)
|
||||
{
|
||||
if (!NDirectory::MyGetTempFileName(workingDir, kTempArchiveFilePrefixString,
|
||||
options.Commands[0].ArchivePath))
|
||||
throw "create temp file error";
|
||||
}
|
||||
|
||||
int i;
|
||||
for(i = 0; i < options.Commands.Size(); i++)
|
||||
{
|
||||
fileVectorBundle.Add(options.Commands[i].ArchivePath,
|
||||
i > 0 || !options.UpdateArchiveItself);
|
||||
// SetBanOnFile(censor,currentDir, options.Commands[i].ArchivePath);
|
||||
}
|
||||
g_StdOut << endl;
|
||||
|
||||
CObjectVector<CArchiveItem> archiveItems;
|
||||
if (archive != NULL)
|
||||
{
|
||||
RINOK(EnumerateInArchiveItems(censor,
|
||||
archive, *defaultItemName, *archiveFileInfo, archiveItems));
|
||||
}
|
||||
|
||||
RINOK(UpdateWithItemLists(options, archive, archiveItems, dirItems, enablePercents));
|
||||
|
||||
if (archive != NULL)
|
||||
{
|
||||
RINOK(archive->Close());
|
||||
}
|
||||
|
||||
int firstNotTempArchiveIndex = options.UpdateArchiveItself ? 1 : 0;
|
||||
for(i = options.Commands.Size() - 1; i >= firstNotTempArchiveIndex; i--)
|
||||
fileVectorBundle.DisableDeleting(i);
|
||||
if(options.UpdateArchiveItself)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (archive != NULL)
|
||||
if (!NDirectory::DeleteFileAlways(options.ArchivePath))
|
||||
throw "delete file error";
|
||||
|
||||
if (!NDirectory::MyMoveFile(options.Commands[0].ArchivePath, options.ArchivePath))
|
||||
{
|
||||
g_StdOut << endl << "Error: ";
|
||||
g_StdOut << NError::MyFormatMessage(::GetLastError()) << endl;
|
||||
g_StdOut << options.Commands[0].ArchivePath << endl;
|
||||
g_StdOut << options.ArchivePath << endl;
|
||||
throw "move file error";
|
||||
}
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
fileVectorBundle.DisableDeleting(0);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
g_StdOut << kEverythingIsOk << endl;
|
||||
return S_OK;
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
// Update.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __UPDATE_H
|
||||
#define __UPDATE_H
|
||||
|
||||
#include "Common/Wildcard.h"
|
||||
#include "../Common/UpdateAction.h"
|
||||
// #include "ProxyHandler.h"
|
||||
#include "Windows/FileFind.h"
|
||||
#include "../../Archive/IArchive.h"
|
||||
#include "CompressionMode.h"
|
||||
|
||||
struct CUpdateArchiveCommand
|
||||
{
|
||||
UString ArchivePath;
|
||||
NUpdateArchive::CActionSet ActionSet;
|
||||
};
|
||||
|
||||
struct CUpdateArchiveOptions
|
||||
{
|
||||
CObjectVector<CUpdateArchiveCommand> Commands;
|
||||
bool UpdateArchiveItself;
|
||||
|
||||
bool SfxMode;
|
||||
UString SfxModule;
|
||||
|
||||
UString ArchivePath;
|
||||
CCompressionMethodMode MethodMode;
|
||||
};
|
||||
|
||||
|
||||
HRESULT UpdateArchiveStdMain(const NWildcard::CCensor &censor,
|
||||
CUpdateArchiveOptions &options, const UString &workingDir,
|
||||
IInArchive *archive,
|
||||
const UString *defaultItemName,
|
||||
const NWindows::NFile::NFind::CFileInfoW *archiveFileInfo,
|
||||
bool enablePercents);
|
||||
|
||||
#endif
|
||||
@@ -1,259 +0,0 @@
|
||||
// UpdateCallback.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "UpdateCallback.h"
|
||||
|
||||
#include "Common/StdInStream.h"
|
||||
#include "Common/StdOutStream.h"
|
||||
#include "Common/StringConvert.h"
|
||||
#include "Common/Defs.h"
|
||||
#include "Windows/PropVariant.h"
|
||||
|
||||
#include "../../Common/FileStreams.h"
|
||||
// #include "Interface/EnumStatProp.h"
|
||||
|
||||
#include "ConsoleClose.h"
|
||||
|
||||
CUpdateCallbackImp::CUpdateCallbackImp():
|
||||
m_PercentPrinter(1 << 16) {}
|
||||
|
||||
void CUpdateCallbackImp::Init(
|
||||
const CObjectVector<CDirItem> *dirItems,
|
||||
const CObjectVector<CArchiveItem> *archiveItems, // test CItemInfoExList
|
||||
CObjectVector<CUpdatePair2> *updatePairs,
|
||||
bool enablePercents,
|
||||
bool passwordIsDefined,
|
||||
const UString &password,
|
||||
bool askPassword)
|
||||
{
|
||||
_passwordIsDefined = passwordIsDefined;
|
||||
_password = password;
|
||||
_askPassword = askPassword;
|
||||
|
||||
m_EnablePercents = enablePercents;
|
||||
m_DirItems = dirItems;
|
||||
m_ArchiveItems = archiveItems;
|
||||
m_UpdatePairs = updatePairs;
|
||||
m_PercentCanBePrint = false;
|
||||
m_NeedBeClosed = false;
|
||||
}
|
||||
|
||||
void CUpdateCallbackImp::Finilize()
|
||||
{
|
||||
if (m_NeedBeClosed)
|
||||
{
|
||||
if (m_EnablePercents)
|
||||
{
|
||||
m_PercentPrinter.ClosePrint();
|
||||
m_PercentCanBePrint = false;
|
||||
m_NeedBeClosed = false;
|
||||
}
|
||||
m_PercentPrinter.PrintNewLine();
|
||||
}
|
||||
}
|
||||
|
||||
STDMETHODIMP CUpdateCallbackImp::SetTotal(UINT64 size)
|
||||
{
|
||||
if (m_EnablePercents)
|
||||
m_PercentPrinter.SetTotal(size);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CUpdateCallbackImp::SetCompleted(const UINT64 *completeValue)
|
||||
{
|
||||
if (completeValue != NULL)
|
||||
{
|
||||
if (m_EnablePercents)
|
||||
{
|
||||
m_PercentPrinter.SetRatio(*completeValue);
|
||||
if (m_PercentCanBePrint)
|
||||
m_PercentPrinter.PrintRatio();
|
||||
}
|
||||
}
|
||||
|
||||
if (NConsoleClose::TestBreakSignal())
|
||||
return E_ABORT;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
STATPROPSTG kProperties[] =
|
||||
{
|
||||
{ NULL, kpidPath, VT_BSTR},
|
||||
{ NULL, kpidIsFolder, VT_BOOL},
|
||||
{ NULL, kpidSize, VT_UI8},
|
||||
{ NULL, kpidLastAccessTime, VT_FILETIME},
|
||||
{ NULL, kpidCreationTime, VT_FILETIME},
|
||||
{ NULL, kpidLastWriteTime, VT_FILETIME},
|
||||
{ NULL, kpidAttributes, VT_UI4},
|
||||
{ NULL, kpidIsAnti, VT_BOOL}
|
||||
};
|
||||
*/
|
||||
|
||||
STDMETHODIMP CUpdateCallbackImp::EnumProperties(IEnumSTATPROPSTG **enumerator)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
|
||||
/*
|
||||
return CStatPropEnumerator::CreateEnumerator(kProperties,
|
||||
sizeof(kProperties) / sizeof(kProperties[0]), enumerator);
|
||||
*/
|
||||
}
|
||||
|
||||
STDMETHODIMP CUpdateCallbackImp::GetUpdateItemInfo(UINT32 index,
|
||||
INT32 *newData, INT32 *newProperties, UINT32 *indexInArchive)
|
||||
{
|
||||
if (NConsoleClose::TestBreakSignal())
|
||||
return E_ABORT;
|
||||
const CUpdatePair2 &updatePair = (*m_UpdatePairs)[index];
|
||||
if(newData != NULL)
|
||||
*newData = BoolToInt(updatePair.NewData);
|
||||
if(newProperties != NULL)
|
||||
*newProperties = BoolToInt(updatePair.NewProperties);
|
||||
if(indexInArchive != NULL)
|
||||
{
|
||||
if (updatePair.ExistInArchive)
|
||||
*indexInArchive = (*m_ArchiveItems)[updatePair.ArchiveItemIndex].IndexInServer;
|
||||
else
|
||||
*indexInArchive = UINT32(-1);
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CUpdateCallbackImp::GetProperty(UINT32 index, PROPID propID, PROPVARIANT *value)
|
||||
{
|
||||
const CUpdatePair2 &updatePair = (*m_UpdatePairs)[index];
|
||||
NWindows::NCOM::CPropVariant propVariant;
|
||||
|
||||
if (propID == kpidIsAnti)
|
||||
{
|
||||
propVariant = updatePair.IsAnti;
|
||||
propVariant.Detach(value);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
if (updatePair.IsAnti)
|
||||
{
|
||||
switch(propID)
|
||||
{
|
||||
case kpidIsFolder:
|
||||
case kpidPath:
|
||||
break;
|
||||
case kpidSize:
|
||||
propVariant = (UINT64)0;
|
||||
propVariant.Detach(value);
|
||||
return S_OK;
|
||||
default:
|
||||
propVariant.Detach(value);
|
||||
return S_OK;
|
||||
}
|
||||
}
|
||||
|
||||
if(updatePair.ExistOnDisk)
|
||||
{
|
||||
const CDirItem &dirItem =
|
||||
(*m_DirItems)[updatePair.DirItemIndex];
|
||||
switch(propID)
|
||||
{
|
||||
case kpidPath:
|
||||
propVariant = dirItem.Name;
|
||||
break;
|
||||
case kpidIsFolder:
|
||||
propVariant = dirItem.IsDirectory();
|
||||
break;
|
||||
case kpidSize:
|
||||
propVariant = dirItem.Size;
|
||||
break;
|
||||
case kpidAttributes:
|
||||
propVariant = dirItem.Attributes;
|
||||
break;
|
||||
case kpidLastAccessTime:
|
||||
propVariant = dirItem.LastAccessTime;
|
||||
break;
|
||||
case kpidCreationTime:
|
||||
propVariant = dirItem.CreationTime;
|
||||
break;
|
||||
case kpidLastWriteTime:
|
||||
propVariant = dirItem.LastWriteTime;
|
||||
break;
|
||||
}
|
||||
}
|
||||
propVariant.Detach(value);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CUpdateCallbackImp::GetStream(UINT32 index,
|
||||
IInStream **inStream)
|
||||
{
|
||||
const CUpdatePair2 &updatePair = (*m_UpdatePairs)[index];
|
||||
if(!updatePair.NewData)
|
||||
return E_FAIL;
|
||||
|
||||
if (NConsoleClose::TestBreakSignal())
|
||||
return E_ABORT;
|
||||
|
||||
Finilize();
|
||||
|
||||
if(updatePair.IsAnti)
|
||||
{
|
||||
m_PercentPrinter.PrintString("Anti item ");
|
||||
m_PercentPrinter.PrintString(
|
||||
(*m_ArchiveItems)[updatePair.ArchiveItemIndex].Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
const CDirItem &dirItem =
|
||||
(*m_DirItems)[updatePair.DirItemIndex];
|
||||
|
||||
m_PercentPrinter.PrintString("Compressing ");
|
||||
m_PercentPrinter.PrintString(dirItem.Name);
|
||||
}
|
||||
if (m_EnablePercents)
|
||||
{
|
||||
m_PercentCanBePrint = true;
|
||||
m_PercentPrinter.PreparePrint();
|
||||
m_PercentPrinter.RePrintRatio();
|
||||
}
|
||||
|
||||
if(updatePair.IsAnti)
|
||||
return S_OK;
|
||||
|
||||
const CDirItem &dirItem =
|
||||
(*m_DirItems)[updatePair.DirItemIndex];
|
||||
|
||||
if(dirItem.IsDirectory())
|
||||
return S_OK;
|
||||
|
||||
CInFileStream *inStreamSpec = new CInFileStream;
|
||||
CMyComPtr<IInStream> inStreamLoc(inStreamSpec);
|
||||
if(!inStreamSpec->Open(dirItem.FullPath))
|
||||
return ::GetLastError();
|
||||
*inStream = inStreamLoc.Detach();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CUpdateCallbackImp::SetOperationResult(INT32 operationResult)
|
||||
{
|
||||
m_NeedBeClosed = true;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
STDMETHODIMP CUpdateCallbackImp::CryptoGetTextPassword2(INT32 *passwordIsDefined, BSTR *password)
|
||||
{
|
||||
if (!_passwordIsDefined)
|
||||
{
|
||||
if (_askPassword)
|
||||
{
|
||||
g_StdOut << "\nEnter password:";
|
||||
AString oemPassword = g_StdIn.ScanStringUntilNewLine();
|
||||
_password = MultiByteToUnicodeString(oemPassword, CP_OEMCP);
|
||||
_passwordIsDefined = true;
|
||||
}
|
||||
}
|
||||
*passwordIsDefined = BoolToInt(_passwordIsDefined);
|
||||
CMyComBSTR tempName(_password);
|
||||
*password = tempName.Detach();
|
||||
return S_OK;
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
// UpdateCallback.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __UPDATECALLBACK_H
|
||||
#define __UPDATECALLBACK_H
|
||||
|
||||
// #include "../Format/Common/ArchiveInterface.h"
|
||||
#include "Common/MyCom.h"
|
||||
#include "Common/String.h"
|
||||
|
||||
#include "../../IPassword.h"
|
||||
|
||||
#include "../Common/UpdatePair.h"
|
||||
#include "../Common/UpdateProduce.h"
|
||||
|
||||
#include "PercentPrinter.h"
|
||||
|
||||
class CUpdateCallbackImp:
|
||||
public IArchiveUpdateCallback,
|
||||
public ICryptoGetTextPassword2,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
public:
|
||||
MY_UNKNOWN_IMP1(ICryptoGetTextPassword2)
|
||||
|
||||
// IProfress
|
||||
|
||||
STDMETHOD(SetTotal)(UINT64 size);
|
||||
STDMETHOD(SetCompleted)(const UINT64 *completeValue);
|
||||
|
||||
// IUpdateCallback
|
||||
STDMETHOD(EnumProperties)(IEnumSTATPROPSTG **enumerator);
|
||||
STDMETHOD(GetUpdateItemInfo)(UINT32 index,
|
||||
INT32 *newData, INT32 *newProperties, UINT32 *indexInArchive);
|
||||
|
||||
STDMETHOD(GetProperty)(UINT32 index, PROPID propID, PROPVARIANT *value);
|
||||
|
||||
STDMETHOD(GetStream)(UINT32 index, IInStream **inStream);
|
||||
|
||||
STDMETHOD(SetOperationResult)(INT32 operationResult);
|
||||
|
||||
STDMETHOD(CryptoGetTextPassword2)(INT32 *passwordIsDefined, BSTR *password);
|
||||
|
||||
private:
|
||||
const CObjectVector<CDirItem> *m_DirItems;
|
||||
const CObjectVector<CArchiveItem> *m_ArchiveItems;
|
||||
const CObjectVector<CUpdatePair2> *m_UpdatePairs;
|
||||
|
||||
CPercentPrinter m_PercentPrinter;
|
||||
|
||||
bool m_EnablePercents;
|
||||
bool m_PercentCanBePrint;
|
||||
bool m_NeedBeClosed;
|
||||
|
||||
bool _passwordIsDefined;
|
||||
UString _password;
|
||||
bool _askPassword;
|
||||
|
||||
public:
|
||||
CUpdateCallbackImp();
|
||||
~CUpdateCallbackImp()
|
||||
{ Finilize(); }
|
||||
void Init(
|
||||
const CObjectVector<CDirItem> *dirItems,
|
||||
const CObjectVector<CArchiveItem> *archiveItems, // test CItemInfoExList
|
||||
CObjectVector<CUpdatePair2> *updatePairs,
|
||||
bool enablePercents,
|
||||
bool passwordIsDefined,
|
||||
const UString &password,
|
||||
bool askPassword);
|
||||
void Finilize();
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
159
7zip/UI/Console/UpdateCallbackConsole.cpp
Executable file
159
7zip/UI/Console/UpdateCallbackConsole.cpp
Executable file
@@ -0,0 +1,159 @@
|
||||
// UpdateCallbackConsole.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "UpdateCallbackConsole.h"
|
||||
|
||||
#include "Windows/Error.h"
|
||||
|
||||
#include "ConsoleClose.h"
|
||||
#include "UserInputUtils.h"
|
||||
|
||||
using namespace NWindows;
|
||||
|
||||
static const char *kCreatingArchiveMessage = "Creating archive ";
|
||||
static const char *kUpdatingArchiveMessage = "Updating archive ";
|
||||
static const char *kScanningMessage = "Scanning";
|
||||
static const char *kNoFilesScannedMessage = "No files scanned";
|
||||
static const char *kTotalFilesAddedMessage = "Total files added to archive: ";
|
||||
|
||||
HRESULT CUpdateCallbackConsole::OpenResult(const wchar_t *name, HRESULT result)
|
||||
{
|
||||
(*OutStream) << endl;
|
||||
if (result != S_OK)
|
||||
(*OutStream) << "Error: " << name << " is not supported archive" << endl;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CUpdateCallbackConsole::StartScanning()
|
||||
{
|
||||
(*OutStream) << kScanningMessage;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CUpdateCallbackConsole::FinishScanning()
|
||||
{
|
||||
(*OutStream) << endl << endl;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CUpdateCallbackConsole::StartArchive(const wchar_t *name, bool updating)
|
||||
{
|
||||
if(updating)
|
||||
(*OutStream) << kUpdatingArchiveMessage;
|
||||
else
|
||||
(*OutStream) << kCreatingArchiveMessage;
|
||||
if (name != 0)
|
||||
(*OutStream) << name;
|
||||
else
|
||||
(*OutStream) << "StdOut";
|
||||
(*OutStream) << endl << endl;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CUpdateCallbackConsole::FinishArchive()
|
||||
{
|
||||
(*OutStream) << endl;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CUpdateCallbackConsole::CheckBreak()
|
||||
{
|
||||
if (NConsoleClose::TestBreakSignal())
|
||||
return E_ABORT;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CUpdateCallbackConsole::Finilize()
|
||||
{
|
||||
if (m_NeedBeClosed)
|
||||
{
|
||||
if (EnablePercents)
|
||||
{
|
||||
m_PercentPrinter.ClosePrint();
|
||||
m_PercentCanBePrint = false;
|
||||
}
|
||||
if (!StdOutMode)
|
||||
m_PercentPrinter.PrintNewLine();
|
||||
m_NeedBeClosed = false;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CUpdateCallbackConsole::SetTotal(UInt64 size)
|
||||
{
|
||||
if (EnablePercents)
|
||||
m_PercentPrinter.SetTotal(size);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CUpdateCallbackConsole::SetCompleted(const UInt64 *completeValue)
|
||||
{
|
||||
if (completeValue != NULL)
|
||||
{
|
||||
if (EnablePercents)
|
||||
{
|
||||
m_PercentPrinter.SetRatio(*completeValue);
|
||||
if (m_PercentCanBePrint)
|
||||
m_PercentPrinter.PrintRatio();
|
||||
}
|
||||
}
|
||||
if (NConsoleClose::TestBreakSignal())
|
||||
return E_ABORT;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CUpdateCallbackConsole::GetStream(const wchar_t *name, bool isAnti)
|
||||
{
|
||||
if (StdOutMode)
|
||||
return S_OK;
|
||||
if(isAnti)
|
||||
m_PercentPrinter.PrintString("Anti item ");
|
||||
else
|
||||
m_PercentPrinter.PrintString("Compressing ");
|
||||
m_PercentPrinter.PrintString(name);
|
||||
if (EnablePercents)
|
||||
{
|
||||
m_PercentCanBePrint = true;
|
||||
m_PercentPrinter.PreparePrint();
|
||||
m_PercentPrinter.RePrintRatio();
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CUpdateCallbackConsole::OpenFileError(const wchar_t *name, DWORD systemError)
|
||||
{
|
||||
FailedCodes.Add(systemError);
|
||||
FailedFiles.Add(name);
|
||||
// if (systemError == ERROR_SHARING_VIOLATION)
|
||||
{
|
||||
m_PercentPrinter.ClosePrint();
|
||||
m_PercentPrinter.PrintNewLine();
|
||||
m_PercentPrinter.PrintString("WARNING: ");
|
||||
m_PercentPrinter.PrintString(NError::MyFormatMessageW(systemError));
|
||||
return S_FALSE;
|
||||
}
|
||||
return systemError;
|
||||
}
|
||||
|
||||
HRESULT CUpdateCallbackConsole::SetOperationResult(Int32 operationResult)
|
||||
{
|
||||
m_NeedBeClosed = true;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CUpdateCallbackConsole::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password)
|
||||
{
|
||||
if (!PasswordIsDefined)
|
||||
{
|
||||
if (AskPassword)
|
||||
{
|
||||
Password = GetPassword(OutStream);
|
||||
PasswordIsDefined = true;
|
||||
}
|
||||
}
|
||||
*passwordIsDefined = BoolToInt(PasswordIsDefined);
|
||||
CMyComBSTR tempName(Password);
|
||||
*password = tempName.Detach();
|
||||
return S_OK;
|
||||
}
|
||||
68
7zip/UI/Console/UpdateCallbackConsole.h
Executable file
68
7zip/UI/Console/UpdateCallbackConsole.h
Executable file
@@ -0,0 +1,68 @@
|
||||
// UpdateCallbackConsole.h
|
||||
|
||||
#ifndef __UPDATECALLBACKCONSOLE_H
|
||||
#define __UPDATECALLBACKCONSOLE_H
|
||||
|
||||
#include "Common/String.h"
|
||||
#include "Common/StdOutStream.h"
|
||||
#include "PercentPrinter.h"
|
||||
#include "../Common/Update.h"
|
||||
|
||||
class CUpdateCallbackConsole: public IUpdateCallbackUI2
|
||||
{
|
||||
CPercentPrinter m_PercentPrinter;
|
||||
bool m_PercentCanBePrint;
|
||||
bool m_NeedBeClosed;
|
||||
|
||||
CStdOutStream *OutStream;
|
||||
public:
|
||||
bool EnablePercents;
|
||||
bool StdOutMode;
|
||||
|
||||
bool PasswordIsDefined;
|
||||
UString Password;
|
||||
bool AskPassword;
|
||||
|
||||
|
||||
CUpdateCallbackConsole():
|
||||
m_PercentPrinter(1 << 16),
|
||||
PasswordIsDefined(false),
|
||||
AskPassword(false),
|
||||
StdOutMode(false),
|
||||
EnablePercents(true)
|
||||
{}
|
||||
|
||||
~CUpdateCallbackConsole() { Finilize(); }
|
||||
void Init(CStdOutStream *outStream)
|
||||
{
|
||||
m_PercentCanBePrint = false;
|
||||
m_NeedBeClosed = false;
|
||||
FailedFiles.Clear();
|
||||
FailedCodes.Clear();
|
||||
OutStream = outStream;
|
||||
m_PercentPrinter.OutStream = outStream;
|
||||
}
|
||||
|
||||
HRESULT OpenResult(const wchar_t *name, HRESULT result);
|
||||
|
||||
HRESULT StartScanning();
|
||||
HRESULT FinishScanning();
|
||||
|
||||
HRESULT StartArchive(const wchar_t *name, bool updating);
|
||||
HRESULT FinishArchive();
|
||||
|
||||
HRESULT CheckBreak();
|
||||
HRESULT Finilize();
|
||||
HRESULT SetTotal(UInt64 size);
|
||||
HRESULT SetCompleted(const UInt64 *completeValue);
|
||||
|
||||
HRESULT GetStream(const wchar_t *name, bool isAnti);
|
||||
HRESULT OpenFileError(const wchar_t *name, DWORD systemError);
|
||||
HRESULT SetOperationResult(Int32 operationResult);
|
||||
HRESULT CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password);
|
||||
|
||||
UStringVector FailedFiles;
|
||||
CRecordVector<HRESULT> FailedCodes;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -3,16 +3,16 @@
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "Common/StdInStream.h"
|
||||
#include "Common/StdOutStream.h"
|
||||
#include "Common/StringConvert.h"
|
||||
|
||||
#include "UserInputUtils.h"
|
||||
|
||||
static const char kYes = 'Y';
|
||||
static const char kNo = 'N';
|
||||
static const char kYesAll = 'A';
|
||||
static const char kNoAll = 'S';
|
||||
static const char kAutoRename = 'U';
|
||||
static const char kQuit = 'Q';
|
||||
static const char kYes = 'Y';
|
||||
static const char kNo = 'N';
|
||||
static const char kYesAll = 'A';
|
||||
static const char kNoAll = 'S';
|
||||
static const char kAutoRename = 'U';
|
||||
static const char kQuit = 'Q';
|
||||
|
||||
static const char *kFirstQuestionMessage = "?\n";
|
||||
static const char *kHelpQuestionMessage =
|
||||
@@ -22,12 +22,12 @@ static const char *kHelpQuestionMessage =
|
||||
// in: anAll
|
||||
// out: anAll, anYes;
|
||||
|
||||
NUserAnswerMode::EEnum ScanUserYesNoAllQuit()
|
||||
NUserAnswerMode::EEnum ScanUserYesNoAllQuit(CStdOutStream *outStream)
|
||||
{
|
||||
g_StdOut << kFirstQuestionMessage;
|
||||
(*outStream) << kFirstQuestionMessage;
|
||||
do
|
||||
{
|
||||
g_StdOut << kHelpQuestionMessage;
|
||||
(*outStream) << kHelpQuestionMessage;
|
||||
AString scannedString = g_StdIn.ScanStringUntilNewLine();
|
||||
scannedString.Trim();
|
||||
if(!scannedString.IsEmpty())
|
||||
@@ -49,3 +49,10 @@ NUserAnswerMode::EEnum ScanUserYesNoAllQuit()
|
||||
}
|
||||
while(true);
|
||||
}
|
||||
|
||||
UString GetPassword(CStdOutStream *outStream)
|
||||
{
|
||||
(*outStream) << "\nEnter password:";
|
||||
AString oemPassword = g_StdIn.ScanStringUntilNewLine();
|
||||
return MultiByteToUnicodeString(oemPassword, CP_OEMCP);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
// UserInputUtils.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __USERINPUTUTILS_H
|
||||
#define __USERINPUTUTILS_H
|
||||
|
||||
#include "Common/StdOutStream.h"
|
||||
|
||||
namespace NUserAnswerMode {
|
||||
|
||||
enum EEnum
|
||||
@@ -18,6 +18,7 @@ enum EEnum
|
||||
};
|
||||
}
|
||||
|
||||
NUserAnswerMode::EEnum ScanUserYesNoAllQuit();
|
||||
NUserAnswerMode::EEnum ScanUserYesNoAllQuit(CStdOutStream *outStream);
|
||||
UString GetPassword(CStdOutStream *outStream);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -66,8 +66,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 3,12,0,0
|
||||
PRODUCTVERSION 3,12,0,0
|
||||
FILEVERSION 4,20,0,0
|
||||
PRODUCTVERSION 4,20,0,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
@@ -85,14 +85,14 @@ BEGIN
|
||||
VALUE "Comments", "\0"
|
||||
VALUE "CompanyName", "Igor Pavlov\0"
|
||||
VALUE "FileDescription", "7-Zip Console version\0"
|
||||
VALUE "FileVersion", "3, 12, 0, 0\0"
|
||||
VALUE "FileVersion", "4, 20, 0, 0\0"
|
||||
VALUE "InternalName", "7z\0"
|
||||
VALUE "LegalCopyright", "Copyright (C) 1999-2003 Igor Pavlov\0"
|
||||
VALUE "LegalCopyright", "Copyright (C) 1999-2005 Igor Pavlov\0"
|
||||
VALUE "LegalTrademarks", "\0"
|
||||
VALUE "OriginalFilename", "7z.exe\0"
|
||||
VALUE "PrivateBuild", "\0"
|
||||
VALUE "ProductName", "7-Zip\0"
|
||||
VALUE "ProductVersion", "3, 12, 0, 0\0"
|
||||
VALUE "ProductVersion", "4, 20, 0, 0\0"
|
||||
VALUE "SpecialBuild", "\0"
|
||||
END
|
||||
END
|
||||
|
||||
Reference in New Issue
Block a user