This commit is contained in:
Igor Pavlov
2003-12-11 00:00:00 +00:00
committed by Kornel Lesiński
commit 8c1b5c7b7e
982 changed files with 118799 additions and 0 deletions

407
7zip/UI/Agent/Agent.cpp Executable file
View File

@@ -0,0 +1,407 @@
// Agent.cpp
#include "StdAfx.h"
#include "Common/StringConvert.h"
#include "Common/ComTry.h"
#include "Windows/Defs.h"
#include "Windows/PropVariant.h"
#include "Windows/FileFind.h"
#include "../Common/OpenArchive.h"
#include "../Common/DefaultName.h"
#include "Agent.h"
#include "ArchiveExtractCallback.h"
#ifdef FORMAT_7Z
#include "../../Archive/7z/7zHandler.h"
#endif
using namespace NWindows;
STDMETHODIMP CAgentFolder::GetAgentFolder(CAgentFolder **agentFolder)
{
*agentFolder = this;
return S_OK;
}
STDMETHODIMP CAgentFolder::LoadItems()
{
return S_OK;
}
STDMETHODIMP CAgentFolder::GetNumberOfItems(UINT32 *numItems)
{
*numItems = _proxyFolderItem->Folders.Size() +
_proxyFolderItem->Files.Size();
return S_OK;
}
/*
STDMETHODIMP CAgentFolder::GetNumberOfSubFolders(UINT32 *aNumSubFolders)
{
*aNumSubFolders = _proxyFolderItem->Folders.Size();
return S_OK;
}
*/
STDMETHODIMP CAgentFolder::GetProperty(UINT32 itemIndex, PROPID propID, PROPVARIANT *value)
{
NCOM::CPropVariant propVariant;
if (itemIndex < (UINT32)_proxyFolderItem->Folders.Size())
{
const CProxyFolder &item = _proxyFolderItem->Folders[itemIndex];
switch(propID)
{
case kpidIsFolder:
propVariant = true;
break;
case kpidName:
propVariant = item.Name;
break;
default:
if (item.IsLeaf)
return _agentSpec->_archive->GetProperty(item.Index,
propID, value);
}
}
else
{
itemIndex -= _proxyFolderItem->Folders.Size();
const CProxyFile &item = _proxyFolderItem->Files[itemIndex];
switch(propID)
{
case kpidIsFolder:
propVariant = false;
break;
case kpidName:
propVariant = item.Name;
break;
default:
return _agentSpec->_archive->GetProperty(item.Index,
propID, value);
}
}
propVariant.Detach(value);
return S_OK;
}
STDMETHODIMP CAgentFolder::BindToFolder(UINT32 index, IFolderFolder **resultFolder)
{
COM_TRY_BEGIN
if (index >= (UINT32)_proxyFolderItem->Folders.Size())
return E_INVALIDARG;
CAgentFolder *folderSpec = new CAgentFolder;
CMyComPtr<IFolderFolder> agentFolder = folderSpec;
folderSpec->Init(_proxyArchive, &_proxyFolderItem->Folders[index],
this, _agentSpec);
*resultFolder = agentFolder.Detach();
return S_OK;
COM_TRY_END
}
STDMETHODIMP CAgentFolder::BindToFolder(const wchar_t *name, IFolderFolder **resultFolder)
{
COM_TRY_BEGIN
int index = _proxyFolderItem->FindDirSubItemIndex(name);
if (index < 0)
return E_INVALIDARG;
return BindToFolder(index, resultFolder);
COM_TRY_END
}
STDMETHODIMP CAgentFolder::BindToParentFolder(IFolderFolder **resultFolder)
{
COM_TRY_BEGIN
CMyComPtr<IFolderFolder> parentFolder = _parentFolder;
*resultFolder = parentFolder.Detach();
return S_OK;
COM_TRY_END
}
STDMETHODIMP CAgentFolder::GetName(BSTR *name)
{
CMyComBSTR temp = _proxyFolderItem->Name;
*name = temp.Detach();
return S_OK;
}
#ifdef NEW_FOLDER_INTERFACE
struct CArchiveItemPropertyTemp
{
UString Name;
PROPID ID;
VARTYPE Type;
};
STDMETHODIMP CAgentFolder::GetNumberOfProperties(UINT32 *numProperties)
{
COM_TRY_BEGIN
return _agentSpec->_archive->GetNumberOfProperties(numProperties);
COM_TRY_END
}
STDMETHODIMP CAgentFolder::GetPropertyInfo(UINT32 index,
BSTR *name, PROPID *propID, VARTYPE *varType)
{
COM_TRY_BEGIN
RINOK(_agentSpec->_archive->GetPropertyInfo(index, name, propID, varType));
if (*propID == kpidPath)
*propID = kpidName;
return S_OK;
COM_TRY_END
}
STDMETHODIMP CAgentFolder::GetTypeID(BSTR *name)
{
COM_TRY_BEGIN
UString temp = UString(L"7-Zip.") + _agentSpec->ArchiveType;
CMyComBSTR bstrTemp = temp;
*name = bstrTemp.Detach();
return S_OK;
COM_TRY_END
}
STDMETHODIMP CAgentFolder::GetPath(BSTR *path)
{
COM_TRY_BEGIN
UStringVector pathParts;
pathParts.Clear();
CMyComPtr<IFolderFolder> currentFolder = this;
while (true)
{
CMyComPtr<IFolderFolder> newFolder;
currentFolder->BindToParentFolder(&newFolder);
if (newFolder == NULL)
break;
CMyComBSTR aName;
currentFolder->GetName(&aName);
pathParts.Insert(0, (const wchar_t *)aName);
currentFolder = newFolder;
}
UString prefix;
for(int i = 0; i < pathParts.Size(); i++)
{
prefix += pathParts[i];
prefix += L'\\';
}
CMyComBSTR tempPath = prefix;
*path = tempPath.Detach();
return S_OK;
COM_TRY_END
}
#endif
STDMETHODIMP CAgentFolder::Extract(const UINT32 *indices,
UINT32 numItems,
NExtractionMode::NPath::EEnum pathMode,
NExtractionMode::NOverwrite::EEnum overwriteMode,
const wchar_t *path,
INT32 testMode,
IFolderArchiveExtractCallback *extractCallback2)
{
COM_TRY_BEGIN
CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback;
CMyComPtr<IArchiveExtractCallback> extractCallback = extractCallbackSpec;
UStringVector pathParts;
CProxyFolder *currentProxyFolder = _proxyFolderItem;
while (currentProxyFolder->Parent)
{
pathParts.Insert(0, currentProxyFolder->Name);
currentProxyFolder = currentProxyFolder->Parent;
}
extractCallbackSpec->Init(_agentSpec->_archive,
extractCallback2,
path,
pathMode,
overwriteMode,
pathParts,
_agentSpec->DefaultName,
_agentSpec->DefaultTime,
_agentSpec->DefaultAttributes
// ,_agentSpec->_srcDirectoryPrefix
);
CUIntVector realIndices;
_proxyFolderItem->GetRealIndices(indices, numItems, realIndices);
return _agentSpec->_archive->Extract(&realIndices.Front(),
realIndices.Size(), testMode, extractCallback);
COM_TRY_END
}
/////////////////////////////////////////
// CAgent
CAgent::CAgent():
_proxyArchive(NULL)
{
}
CAgent::~CAgent()
{
if (_proxyArchive != NULL)
delete _proxyArchive;
}
STDMETHODIMP CAgent::Open(
const wchar_t *filePath,
BSTR *archiveType,
// CLSID *clsIDResult,
IArchiveOpenCallback *openArchiveCallback)
{
COM_TRY_BEGIN
_archiveFilePath = filePath;
NFile::NFind::CFileInfoW fileInfo;
if (!NFile::NFind::FindFile(_archiveFilePath, fileInfo))
return ::GetLastError();
if (fileInfo.IsDirectory())
return E_FAIL;
CArchiverInfo archiverInfo;
int subExtIndex;
HRESULT res = OpenArchive(_archiveFilePath,
#ifndef EXCLUDE_COM
&_library,
#endif
&_archive, archiverInfo, subExtIndex, openArchiveCallback);
RINOK(res);
DefaultName = GetDefaultName(_archiveFilePath,
archiverInfo.Extensions[subExtIndex].Extension,
archiverInfo.Extensions[subExtIndex].AddExtension);
DefaultTime = fileInfo.LastWriteTime;
DefaultAttributes = fileInfo.Attributes;
ArchiveType = archiverInfo.Name;
if (archiveType != 0)
{
CMyComBSTR name = archiverInfo.Name;
*archiveType = name.Detach();
}
return S_OK;
COM_TRY_END
}
STDMETHODIMP CAgent::ReOpen(
// const wchar_t *filePath,
IArchiveOpenCallback *openArchiveCallback)
{
COM_TRY_BEGIN
if (_proxyArchive != NULL)
{
delete _proxyArchive;
_proxyArchive = NULL;
}
RINOK(ReOpenArchive(_archive, _archiveFilePath));
return ReadItems();
COM_TRY_END
}
STDMETHODIMP CAgent::Close()
{
COM_TRY_BEGIN
return _archive->Close();
COM_TRY_END
}
/*
STDMETHODIMP CAgent::EnumProperties(IEnumSTATPROPSTG **EnumProperties)
{
return _archive->EnumProperties(EnumProperties);
}
*/
HRESULT CAgent::ReadItems()
{
if (_proxyArchive != NULL)
return S_OK;
_proxyArchive = new CProxyArchive();
return _proxyArchive->Load(_archive,
DefaultName,
// _defaultTime,
// _defaultAttributes,
NULL);
}
STDMETHODIMP CAgent::BindToRootFolder(IFolderFolder **resultFolder)
{
COM_TRY_BEGIN
RINOK(ReadItems());
CAgentFolder *folderSpec = new CAgentFolder;
CMyComPtr<IFolderFolder> rootFolder = folderSpec;
folderSpec->Init(_proxyArchive, &_proxyArchive->RootFolder, NULL, this);
*resultFolder = rootFolder.Detach();
return S_OK;
COM_TRY_END
}
STDMETHODIMP CAgent::Extract(
NExtractionMode::NPath::EEnum pathMode,
NExtractionMode::NOverwrite::EEnum overwriteMode,
const wchar_t *path,
INT32 testMode,
IFolderArchiveExtractCallback *extractCallback2)
{
COM_TRY_BEGIN
CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback;
CMyComPtr<IArchiveExtractCallback> extractCallback = extractCallbackSpec;
extractCallbackSpec->Init(_archive,
extractCallback2,
path,
pathMode,
overwriteMode,
UStringVector(),
DefaultName,
DefaultTime,
DefaultAttributes
// ,_srcDirectoryPrefix
);
return _archive->Extract(0, -1, testMode, extractCallback);
COM_TRY_END
}
STDMETHODIMP CAgent::GetNumberOfProperties(UINT32 *numProperties)
{
COM_TRY_BEGIN
return _archive->GetNumberOfProperties(numProperties);
COM_TRY_END
}
STDMETHODIMP CAgent::GetPropertyInfo(UINT32 index,
BSTR *name, PROPID *propID, VARTYPE *varType)
{
COM_TRY_BEGIN
RINOK(_archive->GetPropertyInfo(index, name, propID, varType));
if (*propID == kpidPath)
*propID = kpidName;
return S_OK;
COM_TRY_END
}
STDMETHODIMP CAgent::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
{
COM_TRY_BEGIN
return _archive->GetArchiveProperty(propID, value);
COM_TRY_END
}
STDMETHODIMP CAgent::GetNumberOfArchiveProperties(UINT32 *numProperties)
{
COM_TRY_BEGIN
return _archive->GetNumberOfArchiveProperties(numProperties);
COM_TRY_END
}
STDMETHODIMP CAgent::GetArchivePropertyInfo(UINT32 index,
BSTR *name, PROPID *propID, VARTYPE *varType)
{
COM_TRY_BEGIN
return _archive->GetArchivePropertyInfo(index,
name, propID, varType);
COM_TRY_END
}

292
7zip/UI/Agent/Agent.h Executable file
View File

@@ -0,0 +1,292 @@
// Agent/Agent.h
#pragma once
#ifndef __AGENT_AGENT_H
#define __AGENT_AGENT_H
#include "Windows/PropVariant.h"
#include "Common/MyCom.h"
#include "../Common/UpdateAction.h"
#include "../Common/ArchiverInfo.h"
#include "IFolderArchive.h"
#include "AgentProxy.h"
#ifndef EXCLUDE_COM
#include "Windows/DLL.h"
#endif
#ifdef NEW_FOLDER_INTERFACE
#include "../../FileManager/IFolder.h"
#endif
class CAgentFolder;
// {23170F69-40C1-278A-0000-000100050001}
DEFINE_GUID(IID_IArchiveFolderInternal,
0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x01, 0x00, 0x05, 0x00, 0x01);
MIDL_INTERFACE("23170F69-40C1-278A-0000-000100050001")
IArchiveFolderInternal: public IUnknown
{
public:
STDMETHOD(GetAgentFolder)(CAgentFolder **agentFolder) PURE;
};
class CAgent;
class CAgentFolder:
public IFolderFolder,
public IArchiveFolder,
public IArchiveFolderInternal,
#ifdef NEW_FOLDER_INTERFACE
public IEnumProperties,
public IFolderGetTypeID,
public IFolderGetPath,
public IFolderOperations,
#endif
public CMyUnknownImp
{
public:
MY_QUERYINTERFACE_BEGIN
MY_QUERYINTERFACE_ENTRY(IFolderFolder)
MY_QUERYINTERFACE_ENTRY(IArchiveFolder)
MY_QUERYINTERFACE_ENTRY(IArchiveFolderInternal)
#ifdef NEW_FOLDER_INTERFACE
MY_QUERYINTERFACE_ENTRY(IEnumProperties)
MY_QUERYINTERFACE_ENTRY(IFolderGetTypeID)
MY_QUERYINTERFACE_ENTRY(IFolderGetPath)
MY_QUERYINTERFACE_ENTRY(IFolderOperations)
#endif
MY_QUERYINTERFACE_END
MY_ADDREF_RELEASE
// IFolderFolder
STDMETHOD(LoadItems)();
STDMETHOD(GetNumberOfItems)(UINT32 *numItems);
STDMETHOD(GetProperty)(UINT32 itemIndex, PROPID propID, PROPVARIANT *value);
STDMETHOD(BindToFolder)(UINT32 index, IFolderFolder **resultFolder);
STDMETHOD(BindToFolder)(const wchar_t *name, IFolderFolder **resultFolder);
STDMETHOD(BindToParentFolder)(IFolderFolder **resultFolder);
STDMETHOD(GetName)(BSTR *name);
// IArchiveFolder
STDMETHOD(Extract)(const UINT32 *indices, UINT32 numItems,
NExtractionMode::NPath::EEnum pathMode,
NExtractionMode::NOverwrite::EEnum overwriteMode,
const wchar_t *path,
INT32 testMode,
IFolderArchiveExtractCallback *extractCallback);
STDMETHOD(GetAgentFolder)(CAgentFolder **agentFolder);
#ifdef NEW_FOLDER_INTERFACE
STDMETHOD(GetNumberOfProperties)(UINT32 *numProperties);
STDMETHOD(GetPropertyInfo)(UINT32 index,
BSTR *name, PROPID *propID, VARTYPE *varType);
STDMETHOD(GetTypeID)(BSTR *name);
STDMETHOD(GetPath)(BSTR *path);
// IFolderOperations
STDMETHOD(CreateFolder)(const wchar_t *name, IProgress *progress);
STDMETHOD(CreateFile)(const wchar_t *name, IProgress *progress);
STDMETHOD(Rename)(UINT32 index, const wchar_t *newName, IProgress *progress);
STDMETHOD(Delete)(const UINT32 *indices, UINT32 numItems, IProgress *progress);
STDMETHOD(CopyTo)(const UINT32 *indices, UINT32 numItems,
const wchar_t *path, IFolderOperationsExtractCallback *callback);
STDMETHOD(MoveTo)(const UINT32 *indices, UINT32 numItems,
const wchar_t *path, IFolderOperationsExtractCallback *callback);
STDMETHOD(CopyFrom)(const wchar_t *fromFolderPath,
const wchar_t **itemsPaths, UINT32 numItems, IProgress *progress);
STDMETHOD(SetProperty)(UINT32 index, PROPID propID, const PROPVARIANT *value, IProgress *progress);
#endif
CAgentFolder(): _proxyFolderItem(NULL) {}
void Init(CProxyArchive *proxyHandler,
CProxyFolder *proxyFolderItem,
IFolderFolder *parentFolder,
CAgent *agent)
{
_proxyArchive = proxyHandler;
_proxyFolderItem = proxyFolderItem;
_parentFolder = parentFolder;
_agent = (IInFolderArchive *)agent;
_agentSpec = agent;
}
void GetPathParts(UStringVector &pathParts);
HRESULT CommonUpdateOperation(
bool deleteOperation,
bool createFolderOperation,
bool renameOperation,
const wchar_t *newItemName,
const NUpdateArchive::CActionSet *actionSet,
const UINT32 *indices, UINT32 numItems,
IFolderArchiveUpdateCallback *updateCallback100);
public:
CProxyArchive *_proxyArchive;
CProxyFolder *_proxyFolderItem;
CMyComPtr<IFolderFolder> _parentFolder;
CMyComPtr<IInFolderArchive> _agent;
CAgent *_agentSpec;
};
// {23170F69-40C1-278A-1000-000100030000}
DEFINE_GUID(CLSID_CAgentArchiveHandler,
0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x00, 0x03, 0x00, 0x00);
class CAgent:
public IInFolderArchive,
#ifndef EXTRACT_ONLY
public IOutFolderArchive,
public ISetProperties,
#endif
public CMyUnknownImp
{
public:
MY_QUERYINTERFACE_BEGIN
MY_QUERYINTERFACE_ENTRY(IInFolderArchive)
#ifndef EXTRACT_ONLY
MY_QUERYINTERFACE_ENTRY(IOutFolderArchive)
MY_QUERYINTERFACE_ENTRY(ISetProperties)
#endif
MY_QUERYINTERFACE_END
MY_ADDREF_RELEASE
STDMETHOD(Open)(
const wchar_t *filePath,
// CLSID *clsIDResult,
BSTR *archiveType,
IArchiveOpenCallback *openArchiveCallback);
STDMETHOD(ReOpen)(
// const wchar_t *filePath,
IArchiveOpenCallback *openArchiveCallback);
/*
STDMETHOD(ReOpen)(IInStream *stream,
const wchar_t *defaultName,
const FILETIME *defaultTime,
UINT32 defaultAttributes,
const UINT64 *maxCheckStartPosition,
IArchiveOpenCallback *openArchiveCallback);
*/
STDMETHOD(Close)();
STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value);
STDMETHOD(GetNumberOfProperties)(UINT32 *numProperties);
STDMETHOD(GetPropertyInfo)(UINT32 index,
BSTR *name, PROPID *propID, VARTYPE *varType);
STDMETHOD(GetNumberOfArchiveProperties)(UINT32 *numProperties);
STDMETHOD(GetArchivePropertyInfo)(UINT32 index,
BSTR *name, PROPID *propID, VARTYPE *varType);
STDMETHOD(BindToRootFolder)(IFolderFolder **resultFolder);
STDMETHOD(Extract)(
NExtractionMode::NPath::EEnum pathMode,
NExtractionMode::NOverwrite::EEnum overwriteMode,
const wchar_t *path,
INT32 testMode,
IFolderArchiveExtractCallback *extractCallback2);
#ifndef EXTRACT_ONLY
STDMETHOD(SetFolder)(IFolderFolder *folder);
STDMETHOD(SetFiles)(const wchar_t *folderPrefix, const wchar_t **names, UINT32 numNames);
STDMETHOD(DeleteItems)(const wchar_t *newArchiveName, const UINT32 *indices,
UINT32 numItems, IFolderArchiveUpdateCallback *updateCallback);
STDMETHOD(DoOperation)(
const wchar_t *filePath,
const CLSID *clsID,
const wchar_t *newArchiveName,
const BYTE *stateActions,
const wchar_t *sfxModule,
IFolderArchiveUpdateCallback *updateCallback);
HRESULT CommonUpdate(const wchar_t *newArchiveName,
int numUpdateItems,
IArchiveUpdateCallback *updateCallback);
HRESULT CreateFolder(
const wchar_t *newArchiveName,
const wchar_t *folderName,
IFolderArchiveUpdateCallback *updateCallback100);
HRESULT RenameItem(
const wchar_t *newArchiveName,
const UINT32 *indices, UINT32 numItems,
const wchar_t *newItemName,
IFolderArchiveUpdateCallback *updateCallback100);
// ISetProperties
STDMETHOD(SetProperties)(const BSTR *names, const PROPVARIANT *values, INT32 numProperties);
#endif
CAgent();
~CAgent();
private:
HRESULT ReadItems();
public:
CProxyArchive *_proxyArchive;
#ifndef EXCLUDE_COM
NWindows::NDLL::CLibrary _library;
#endif
CMyComPtr<IInArchive> _archive;
// CLSID _CLSID;
// CMyComPtr<IArchiveFolder> m_RootFolder;
UString DefaultName;
FILETIME DefaultTime;
UINT32 DefaultAttributes;
UString ArchiveType;
UStringVector _names;
UString _folderPrefix;
UString _archiveNamePrefix;
CProxyFolder *_archiveFolderItem;
UString _archiveFilePath;
#ifndef EXTRACT_ONLY
CObjectVector<CMyComBSTR> m_PropNames;
std::vector<NWindows::NCOM::CPropVariant> m_PropValues;
#endif
};
#ifdef NEW_FOLDER_INTERFACE
class CArchiveFolderManager:
public IFolderManager,
public IFolderManagerGetIconPath,
public CMyUnknownImp
{
public:
MY_UNKNOWN_IMP2(
IFolderManager,
IFolderManagerGetIconPath
)
// IFolderManager
STDMETHOD(OpenFolderFile)(const wchar_t *filePath, IFolderFolder **resultFolder, IProgress *progress);
STDMETHOD(GetTypes)(BSTR *types);
STDMETHOD(GetExtension)(const wchar_t *type, BSTR *extension);
STDMETHOD(CreateFolderFile)(const wchar_t *type, const wchar_t *filePath, IProgress *progress);
STDMETHOD(GetIconPath)(const wchar_t *type, BSTR *iconPath);
CArchiveFolderManager(): _formatsLoaded(false) {}
private:
void LoadFormats();
int FindFormat(const UString &type);
bool _formatsLoaded;
CObjectVector<CArchiverInfo> _formats;
};
#endif
#endif

469
7zip/UI/Agent/AgentOut.cpp Executable file
View File

@@ -0,0 +1,469 @@
// Zip/Handler.cpp
#include "StdAfx.h"
#include "../Common/UpdatePair.h"
#include "../Common/EnumDirItems.h"
#include "../Common/HandlerLoader.h"
// #include "../Common/UpdatePairAction.h"
// #include "../Common/CompressEngineCommon.h"
// #include "../Common/UpdateProducer.h"
#include "../../Compress/Copy/CopyCoder.h"
#include "Common/StringConvert.h"
#include "Windows/Defs.h"
#include "Windows/PropVariant.h"
#include "Windows/PropVariantConversions.h"
#include "Windows/FileDir.h"
#include "../../Common/FileStreams.h"
#include "Agent.h"
#include "ArchiveUpdateCallback.h"
using namespace NWindows;
using namespace NCOM;
static HRESULT CopyBlock(ISequentialInStream *inStream, ISequentialOutStream *outStream)
{
CMyComPtr<ICompressCoder> copyCoder = new NCompress::CCopyCoder;
return copyCoder->Code(inStream, outStream, NULL, NULL, NULL);
}
STDMETHODIMP CAgent::SetFolder(IFolderFolder *folder)
{
_archiveNamePrefix.Empty();
if (folder == NULL)
{
_archiveFolderItem = NULL;
return S_OK;
// folder = m_RootFolder;
}
else
{
CMyComPtr<IFolderFolder> archiveFolder = folder;
CMyComPtr<IArchiveFolderInternal> archiveFolderInternal;
RINOK(archiveFolder.QueryInterface(
IID_IArchiveFolderInternal, &archiveFolderInternal));
CAgentFolder *agentFolder;
RINOK(archiveFolderInternal->GetAgentFolder(&agentFolder));
_archiveFolderItem = agentFolder->_proxyFolderItem;
}
UStringVector pathParts;
pathParts.Clear();
CMyComPtr<IFolderFolder> folderItem = folder;
if (_archiveFolderItem != NULL)
while (true)
{
CMyComPtr<IFolderFolder> newFolder;
folderItem->BindToParentFolder(&newFolder);
if (newFolder == NULL)
break;
CMyComBSTR name;
folderItem->GetName(&name);
pathParts.Insert(0, (const wchar_t *)name);
folderItem = newFolder;
}
for(int i = 0; i < pathParts.Size(); i++)
{
_archiveNamePrefix += pathParts[i];
_archiveNamePrefix += L'\\';
}
return S_OK;
}
STDMETHODIMP CAgent::SetFiles(const wchar_t *folderPrefix,
const wchar_t **names, UINT32 numNames)
{
_folderPrefix = folderPrefix;
_names.Clear();
_names.Reserve(numNames);
for (int i = 0; i < numNames; i++)
_names.Add(names[i]);
return S_OK;
}
static HRESULT GetFileTime(CAgent *agent, UINT32 itemIndex, FILETIME &fileTime)
{
CPropVariant property;
RINOK(agent->_archive->GetProperty(itemIndex, kpidLastWriteTime, &property));
if (property.vt == VT_FILETIME)
fileTime = property.filetime;
else if (property.vt == VT_EMPTY)
fileTime = agent->DefaultTime;
else
throw 4190407;
return S_OK;
}
static HRESULT EnumerateArchiveItems(CAgent *agent,
const CProxyFolder &item,
const UString &prefix,
CObjectVector<CArchiveItem> &archiveItems)
{
int i;
for(i = 0; i < item.Files.Size(); i++)
{
const CProxyFile &fileItem = item.Files[i];
CArchiveItem archiveItem;
RINOK(::GetFileTime(agent, fileItem.Index, archiveItem.LastWriteTime));
CPropVariant property;
agent->_archive->GetProperty(fileItem.Index, kpidSize, &property);
if (archiveItem.SizeIsDefined = (property.vt != VT_EMPTY))
archiveItem.Size = ConvertPropVariantToUINT64(property);
archiveItem.IsDirectory = false;
archiveItem.Name = prefix + fileItem.Name;
archiveItem.Censored = true; // test it
archiveItem.IndexInServer = fileItem.Index;
archiveItems.Add(archiveItem);
}
for(i = 0; i < item.Folders.Size(); i++)
{
const CProxyFolder &dirItem = item.Folders[i];
UString fullName = prefix + dirItem.Name;
if(dirItem.IsLeaf)
{
CArchiveItem archiveItem;
RINOK(::GetFileTime(agent, dirItem.Index, archiveItem.LastWriteTime));
archiveItem.IsDirectory = true;
archiveItem.SizeIsDefined = false;
archiveItem.Name = fullName;
archiveItem.Censored = true; // test it
archiveItem.IndexInServer = dirItem.Index;
archiveItems.Add(archiveItem);
}
RINOK(EnumerateArchiveItems(agent, dirItem, fullName + UString(L'\\'), archiveItems));
}
return S_OK;
}
STDMETHODIMP CAgent::DoOperation(
const wchar_t *filePath,
const CLSID *clsID,
const wchar_t *newArchiveName,
const BYTE *stateActions,
const wchar_t *sfxModule,
IFolderArchiveUpdateCallback *updateCallback100)
{
NUpdateArchive::CActionSet actionSet;
for (int i = 0; i < NUpdateArchive::NPairState::kNumValues; i++)
actionSet.StateActions[i] = (NUpdateArchive::NPairAction::EEnum)stateActions[i];
CObjectVector<CDirItem> dirItems;
UString folderPrefix = _folderPrefix;
NFile::NName::NormalizeDirPathPrefix(folderPrefix);
::EnumerateDirItems(folderPrefix, _names, _archiveNamePrefix, dirItems);
CMyComPtr<IOutArchive> outArchive;
if (_archive)
{
RINOK(_archive.QueryInterface(IID_IOutArchive, &outArchive));
}
else
{
CHandlerLoader loader;
RINOK(loader.CreateHandler(filePath, *clsID, (void **)&outArchive, true));
_library.Attach(loader.Detach());
}
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;
CObjectVector<CArchiveItem> archiveItems;
if (_archive)
{
RINOK(ReadItems());
EnumerateArchiveItems(this, _proxyArchive->RootFolder, L"", archiveItems);
}
GetUpdatePairInfoList(dirItems, archiveItems, fileTimeType, updatePairs);
CObjectVector<CUpdatePair2> operationChain;
UpdateProduce(dirItems, archiveItems, updatePairs, actionSet,
operationChain);
CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback;
CMyComPtr<IArchiveUpdateCallback> updateCallback(updateCallbackSpec );
updateCallbackSpec->Init(folderPrefix,&dirItems, &archiveItems,
&operationChain, NULL, updateCallback100);
COutFileStream *outStreamSpec = new COutFileStream;
CMyComPtr<IOutStream> outStream(outStreamSpec);
UString archiveName = newArchiveName;
{
UString resultPath;
int pos;
if(!NFile::NDirectory::MyGetFullPathName(archiveName, resultPath, pos))
throw 141716;
NFile::NDirectory::CreateComplexDirectory(resultPath.Left(pos));
}
if (!outStreamSpec->Open(archiveName))
{
// ShowLastErrorMessage();
return E_FAIL;
}
CMyComPtr<ISetProperties> setProperties;
if (outArchive->QueryInterface(&setProperties) == S_OK)
{
if (m_PropNames.Size() == 0)
{
RINOK(setProperties->SetProperties(0, 0, 0));
}
else
{
std::vector<BSTR> names;
for(i = 0; i < m_PropNames.Size(); i++)
names.push_back(m_PropNames[i]);
RINOK(setProperties->SetProperties(&names.front(),
&m_PropValues.front(), names.size()));
}
}
m_PropNames.Clear();
m_PropValues.clear();
if (sfxModule != NULL)
{
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);
}
HRESULT CAgent::CommonUpdate(const wchar_t *newArchiveName,
int numUpdateItems,
IArchiveUpdateCallback *updateCallback)
{
CMyComPtr<IOutArchive> outArchive;
RINOK(_archive.QueryInterface(IID_IOutArchive, &outArchive));
COutFileStream *outStreamSpec = new COutFileStream;
CMyComPtr<IOutStream> outStream(outStreamSpec);
UString archiveName = newArchiveName;
{
UString resultPath;
int pos;
if(!NFile::NDirectory::MyGetFullPathName(archiveName, resultPath, pos))
throw 141716;
NFile::NDirectory::CreateComplexDirectory(resultPath.Left(pos));
}
if (!outStreamSpec->Open(archiveName))
{
// ShowLastErrorMessage();
return E_FAIL;
}
return outArchive->UpdateItems(outStream, numUpdateItems, updateCallback);
}
STDMETHODIMP CAgent::DeleteItems(
const wchar_t *newArchiveName,
const UINT32 *indices, UINT32 numItems,
IFolderArchiveUpdateCallback *updateCallback100)
{
CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback;
CMyComPtr<IArchiveUpdateCallback> updateCallback(updateCallbackSpec);
CUIntVector realIndices;
_archiveFolderItem->GetRealIndices(indices, numItems, realIndices);
CObjectVector<CUpdatePair2> updatePairs;
int curIndex = 0;
UINT32 numItemsInArchive;
RINOK(_archive->GetNumberOfItems(&numItemsInArchive));
for (int i = 0; i < numItemsInArchive; i++)
{
if (curIndex < realIndices.Size())
if (realIndices[curIndex] == i)
{
curIndex++;
continue;
}
CUpdatePair2 updatePair;
updatePair.NewData = updatePair.NewProperties = false;
updatePair.ExistInArchive = true;
updatePair.ExistOnDisk = false;
updatePair.IsAnti = false;
updatePair.ArchiveItemIndex = i;
updatePairs.Add(updatePair);
}
updateCallbackSpec->Init(L"", NULL, NULL, &updatePairs, NULL, updateCallback100);
return CommonUpdate(newArchiveName, updatePairs.Size(), updateCallback);
}
HRESULT CAgent::CreateFolder(
const wchar_t *newArchiveName,
const wchar_t *folderName,
IFolderArchiveUpdateCallback *updateCallback100)
{
CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback;
CMyComPtr<IArchiveUpdateCallback> updateCallback(updateCallbackSpec);
CObjectVector<CUpdatePair2> updatePairs;
UINT32 numItemsInArchive;
RINOK(_archive->GetNumberOfItems(&numItemsInArchive));
for (int i = 0; i < numItemsInArchive; i++)
{
CUpdatePair2 updatePair;
updatePair.NewData = updatePair.NewProperties = false;
updatePair.ExistInArchive = true;
updatePair.ExistOnDisk = false;
updatePair.IsAnti = false;
updatePair.ArchiveItemIndex = i;
updatePairs.Add(updatePair);
}
CUpdatePair2 updatePair;
updatePair.NewData = updatePair.NewProperties = true;
updatePair.ExistInArchive = false;
updatePair.ExistOnDisk = true;
updatePair.IsAnti = false;
updatePair.ArchiveItemIndex = -1;
updatePair.DirItemIndex = 0;
updatePairs.Add(updatePair);
CObjectVector<CDirItem> dirItems;
CDirItem dirItem;
dirItem.Attributes = FILE_ATTRIBUTE_DIRECTORY;
dirItem.Size = 0;
dirItem.Name = _archiveFolderItem->GetFullPathPrefix() + folderName;
SYSTEMTIME systemTime;
FILETIME fileTime;
::GetSystemTime(&systemTime);
::SystemTimeToFileTime(&systemTime, &fileTime);
dirItem.LastAccessTime = dirItem.LastWriteTime =
dirItem.CreationTime = fileTime;
dirItems.Add(dirItem);
updateCallbackSpec->Init(L"", &dirItems, NULL, &updatePairs, NULL, updateCallback100);
return CommonUpdate(newArchiveName, updatePairs.Size(), updateCallback);
}
HRESULT CAgent::RenameItem(
const wchar_t *newArchiveName,
const UINT32 *indices, UINT32 numItems,
const wchar_t *newItemName,
IFolderArchiveUpdateCallback *updateCallback100)
{
if (numItems != 1)
return E_INVALIDARG;
CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback;
CMyComPtr<IArchiveUpdateCallback> updateCallback(updateCallbackSpec);
CUIntVector realIndices;
_archiveFolderItem->GetRealIndices(indices, numItems, realIndices);
UString fullPrefix = _archiveFolderItem->GetFullPathPrefix();
UString oldItemPath = fullPrefix +
_archiveFolderItem->GetItemName(indices[0]);
UString newItemPath = fullPrefix + newItemName;
CObjectVector<CUpdatePair2> updatePairs;
int curIndex = 0;
UINT32 numItemsInArchive;
RINOK(_archive->GetNumberOfItems(&numItemsInArchive));
for (int i = 0; i < numItemsInArchive; i++)
{
if (curIndex < realIndices.Size())
if (realIndices[curIndex] == i)
{
CUpdatePair2 updatePair;
updatePair.NewData = false;
updatePair.NewProperties = true;
updatePair.ExistInArchive = true;
updatePair.ExistOnDisk = false;
updatePair.IsAnti = false; // ?
updatePair.ArchiveItemIndex = i;
updatePair.NewNameIsDefined = true;
updatePair.NewName = newItemName;
UString oldFullPath;
{
NCOM::CPropVariant propVariant;
RINOK(_archive->GetProperty(
updatePair.ArchiveItemIndex, kpidPath, &propVariant));
if (propVariant.vt != VT_BSTR)
return E_INVALIDARG;
oldFullPath = propVariant.bstrVal;
}
if (oldItemPath.CollateNoCase(oldFullPath.Left(oldItemPath.Length())) != 0)
return E_INVALIDARG;
{
NCOM::CPropVariant propVariant;
RINOK(_archive->GetProperty(i, kpidIsAnti, &propVariant));
if (propVariant.vt == VT_EMPTY)
updatePair.IsAnti = false;
else if (propVariant.vt != VT_BOOL)
return E_INVALIDARG;
else
updatePair.IsAnti = (propVariant.boolVal != VARIANT_FALSE);
}
updatePair.NewName = newItemPath + oldFullPath.Mid(oldItemPath.Length());
updatePairs.Add(updatePair);
curIndex++;
continue;
}
CUpdatePair2 updatePair;
updatePair.NewData = updatePair.NewProperties = false;
updatePair.ExistInArchive = true;
updatePair.ExistOnDisk = false;
updatePair.IsAnti = false;
updatePair.ArchiveItemIndex = i;
updatePairs.Add(updatePair);
}
updateCallbackSpec->Init(L"", NULL, NULL, &updatePairs, _archive, updateCallback100);
return CommonUpdate(newArchiveName, updatePairs.Size(), updateCallback);
}
STDMETHODIMP CAgent::SetProperties(const BSTR *names,
const PROPVARIANT *values, INT32 numProperties)
{
m_PropNames.Clear();
m_PropValues.clear();
for (int i = 0; i < numProperties; i++)
{
m_PropNames.Add(names[i]);
m_PropValues.push_back(values[i]);
}
return S_OK;
}

198
7zip/UI/Agent/AgentProxy.cpp Executable file
View File

@@ -0,0 +1,198 @@
// AgentProxy.cpp
#include "StdAfx.h"
#include "AgentProxy.h"
#include "Common/MyCom.h"
#include "Windows/PropVariant.h"
#include "Windows/Defs.h"
using namespace NWindows;
int CProxyFolder::FindDirSubItemIndex(const UString &name, int &insertPos) const
{
int left = 0, right = Folders.Size();
while(true)
{
if (left == right)
{
insertPos = left;
return -1;
}
int mid = (left + right) / 2;
int compare = name.CollateNoCase(Folders[mid].Name);
if (compare == 0)
return mid;
if (compare < 0)
right = mid;
else
left = mid + 1;
}
}
int CProxyFolder::FindDirSubItemIndex(const UString &name) const
{
int insertPos;
return FindDirSubItemIndex(name, insertPos);
}
void CProxyFolder::AddFileSubItem(UINT32 index, const UString &name)
{
Files.Add(CProxyFile());
Files.Back().Name = name;
Files.Back().Index = index;
}
CProxyFolder* CProxyFolder::AddDirSubItem(UINT32 index, bool leaf,
const UString &name)
{
int insertPos;
int folderIndex = FindDirSubItemIndex(name, insertPos);
if (folderIndex >= 0)
{
CProxyFolder *item = &Folders[folderIndex];
if(leaf)
{
item->Index = index;
item->IsLeaf = true;
}
return item;
}
Folders.Insert(insertPos, CProxyFolder());
CProxyFolder *item = &Folders[insertPos];
item->Name = name;
item->Index = index;
item->Parent = this;
item->IsLeaf = leaf;
return item;
}
void CProxyFolder::Clear()
{
Folders.Clear();
Files.Clear();
}
UString CProxyFolder::GetFullPathPrefix() const
{
UString result;
const CProxyFolder *current = this;
while (current->Parent != NULL)
{
result = current->Name + UString(L'\\') + result;
current = current->Parent;
}
return result;
}
UString CProxyFolder::GetItemName(UINT32 index) const
{
if (index < (UINT32)Folders.Size())
return Folders[index].Name;
return Files[index - Folders.Size()].Name;
}
void CProxyFolder::AddRealIndices(CUIntVector &realIndices) const
{
if (IsLeaf)
realIndices.Add(Index);
for(int i = 0; i < Folders.Size(); i++)
Folders[i].AddRealIndices(realIndices);
for(i = 0; i < Files.Size(); i++)
realIndices.Add(Files[i].Index);
}
void CProxyFolder::GetRealIndices(const UINT32 *indices,
UINT32 numItems, CUIntVector &realIndices) const
{
realIndices.Clear();
for(UINT32 i = 0; i < numItems; i++)
{
int index = indices[i];
int numDirItems = Folders.Size();
if (index < numDirItems)
Folders[index].AddRealIndices(realIndices);
else
realIndices.Add(Files[index - numDirItems].Index);
}
realIndices.Sort();
}
///////////////////////////////////////////////
// CProxyArchive
HRESULT CProxyArchive::Reload(IInArchive *archive, IProgress *progress)
{
RootFolder.Clear();
return ReadObjects(archive, progress);
}
HRESULT CProxyArchive::Load(IInArchive *archive,
const UString &defaultName,
// const FILETIME &defaultTime,
// UINT32 defaultAttributes,
IProgress *progress)
{
DefaultName = defaultName;
// DefaultTime = defaultTime;
// DefaultAttributes = defaultAttributes;
return Reload(archive, progress);
}
HRESULT CProxyArchive::ReadObjects(IInArchive *archiveHandler, IProgress *progress)
{
UINT32 numItems;
RINOK(archiveHandler->GetNumberOfItems(&numItems));
if (progress != NULL)
{
UINT64 totalItems = numItems;
RINOK(progress->SetTotal(totalItems));
}
for(UINT32 i = 0; i < numItems; i++)
{
if (progress != NULL)
{
UINT64 currentItemIndex = i;
RINOK(progress->SetCompleted(&currentItemIndex));
}
NCOM::CPropVariant propVariantPath;
RINOK(archiveHandler->GetProperty(i, kpidPath, &propVariantPath));
CProxyFolder *currentItem = &RootFolder;
UString fileName;
if(propVariantPath.vt == VT_EMPTY)
fileName = DefaultName;
else
{
if(propVariantPath.vt != VT_BSTR)
return E_FAIL;
UString filePath = propVariantPath.bstrVal;
int len = filePath.Length();
for (int i = 0; i < len; i++)
{
wchar_t c = filePath[i];
if (c == '\\' || c == '/')
{
currentItem = currentItem->AddDirSubItem(-1, false, fileName);
fileName.Empty();
}
else
fileName += c;
}
}
NCOM::CPropVariant propVariantIsFolder;
RINOK(archiveHandler->GetProperty(i,
kpidIsFolder, &propVariantIsFolder));
if(propVariantIsFolder.vt != VT_BOOL)
return E_FAIL;
if(VARIANT_BOOLToBool(propVariantIsFolder.boolVal))
currentItem->AddDirSubItem(i, true, fileName);
else
currentItem->AddFileSubItem(i, fileName);
}
return S_OK;
}

58
7zip/UI/Agent/AgentProxy.h Executable file
View File

@@ -0,0 +1,58 @@
// AgentProxy.h
#pragma once
#ifndef __AGENT_PROXY_H
#define __AGENT_PROXY_H
#include "Common/String.h"
#include "../../Archive/IArchive.h"
class CProxyFile
{
public:
UINT32 Index;
UString Name;
};
class CProxyFolder: public CProxyFile
{
public:
CProxyFolder *Parent;
CObjectVector<CProxyFolder> Folders;
CObjectVector<CProxyFile> Files;
bool IsLeaf;
CProxyFolder(): Parent(NULL) {};
int FindDirSubItemIndex(const UString &name, int &insertPos) const;
int FindDirSubItemIndex(const UString &name) const;
CProxyFolder* AddDirSubItem(UINT32 index,
bool leaf, const UString &name);
void AddFileSubItem(UINT32 index, const UString &name);
void Clear();
UString GetFullPathPrefix() const;
UString GetItemName(UINT32 index) const;
void AddRealIndices(CUIntVector &realIndices) const;
void GetRealIndices(const UINT32 *indices, UINT32 numItems,
CUIntVector &realIndices) const;
};
class CProxyArchive
{
HRESULT ReadObjects(IInArchive *inArchive, IProgress *progress);
public:
UString DefaultName;
// FILETIME DefaultTime;
// UINT32 DefaultAttributes;
CProxyFolder RootFolder;
HRESULT Reload(IInArchive *archive, IProgress *progress);
HRESULT Load(IInArchive *archive,
const UString &defaultName,
// const FILETIME &defaultTime,
// UINT32 defaultAttributes,
IProgress *progress);
};
#endif

View File

@@ -0,0 +1,358 @@
// ExtractCallback.cpp
#include "StdAfx.h"
#include "ArchiveExtractCallback.h"
#include "Common/Wildcard.h"
#include "Common/StringConvert.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;
void CArchiveExtractCallback::Init(
IInArchive *archiveHandler,
IFolderArchiveExtractCallback *extractCallback2,
const UString &directoryPath,
NExtractionMode::NPath::EEnum pathMode,
NExtractionMode::NOverwrite::EEnum overwriteMode,
const UStringVector &removePathParts,
const UString &itemDefaultName,
const FILETIME &utcLastWriteTimeDefault,
UINT32 attributesDefault)
// bool passwordIsDefined, const UString &password
// UString srcDirectoryPrefix)
{
_extractCallback2 = extractCallback2;
// m_PasswordIsDefined = passwordIsDefined;
// m_Password = password;
_numErrors = 0;
_itemDefaultName = itemDefaultName;
_utcLastWriteTimeDefault = utcLastWriteTimeDefault;
_attributesDefault = attributesDefault;
_removePathParts = removePathParts;
_pathMode = pathMode;
_overwriteMode = overwriteMode;
_archiveHandler = archiveHandler;
_directoryPath = directoryPath;
NFile::NName::NormalizeDirPathPrefix(_directoryPath);
// _srcDirectoryPrefix = srcDirectoryPrefix;
}
STDMETHODIMP CArchiveExtractCallback::SetTotal(UINT64 size)
{
return _extractCallback2->SetTotal(size);
}
STDMETHODIMP CArchiveExtractCallback::SetCompleted(const UINT64 *completeValue)
{
return _extractCallback2->SetCompleted(completeValue);
}
void CArchiveExtractCallback::CreateComplexDirectory(const UStringVector &dirPathParts)
{
UString fullPath = _directoryPath;
for(int i = 0; i < dirPathParts.Size(); i++)
{
fullPath += dirPathParts[i];
NFile::NDirectory::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 CArchiveExtractCallback::GetStream(UINT32 index,
ISequentialOutStream **outStream, INT32 askExtractMode)
{
*outStream = 0;
_outFileStream.Release();
NCOM::CPropVariant propVariant;
RINOK(_archiveHandler->GetProperty(index, kpidPath, &propVariant));
UString fullPath;
if(propVariant.vt == VT_EMPTY)
{
fullPath = _itemDefaultName;
}
else
{
if(propVariant.vt != VT_BSTR)
return E_FAIL;
fullPath = propVariant.bstrVal;
}
// UString fullPathCorrect = GetCorrectPath(fullPath);
_filePath = fullPath;
if(askExtractMode == NArchive::NExtract::NAskMode::kExtract)
{
RINOK(_archiveHandler->GetProperty(index, kpidAttributes, &propVariant));
if (propVariant.vt == VT_EMPTY)
{
_processedFileInfo.Attributes = _attributesDefault;
_processedFileInfo.AttributesAreDefined = false;
}
else
{
if (propVariant.vt != VT_UI4)
throw "incorrect item";
_processedFileInfo.Attributes = propVariant.ulVal;
_processedFileInfo.AttributesAreDefined = true;
}
RINOK(_archiveHandler->GetProperty(index, kpidIsFolder, &propVariant));
_processedFileInfo.IsDirectory = VARIANT_BOOLToBool(propVariant.boolVal);
RINOK(_archiveHandler->GetProperty(index, kpidLastWriteTime, &propVariant));
switch(propVariant.vt)
{
case VT_EMPTY:
_processedFileInfo.UTCLastWriteTime = _utcLastWriteTimeDefault;
break;
case VT_FILETIME:
_processedFileInfo.UTCLastWriteTime = propVariant.filetime;
break;
default:
return E_FAIL;
}
RINOK(_archiveHandler->GetProperty(index, kpidSize, &propVariant));
bool newFileSizeDefined = (propVariant.vt != VT_EMPTY);
UINT64 newFileSize;
if (newFileSizeDefined)
newFileSize = ConvertPropVariantToUINT64(propVariant);
bool isAnti = false;
{
NCOM::CPropVariant propVariantTemp;
RINOK(_archiveHandler->GetProperty(index, kpidIsAnti,
&propVariantTemp));
if (propVariantTemp.vt == VT_BOOL)
isAnti = VARIANT_BOOLToBool(propVariantTemp.boolVal);
}
UStringVector pathParts;
// SplitPathToParts(fullPathCorrect, pathParts);
SplitPathToParts(fullPath, pathParts);
if(pathParts.IsEmpty())
return E_FAIL;
UString processedPath;
switch(_pathMode)
{
case NExtractionMode::NPath::kFullPathnames:
{
// processedPath = fullPathCorrect;
processedPath = GetCorrectPath(fullPath);
break;
}
case NExtractionMode::NPath::kCurrentPathnames:
{
int numRemovePathParts = _removePathParts.Size();
if(pathParts.Size() <= numRemovePathParts)
return E_FAIL;
for(int i = 0; i < numRemovePathParts; i++)
if(_removePathParts[i].CollateNoCase(pathParts[i]) != 0)
return E_FAIL;
pathParts.Delete(0, numRemovePathParts);
processedPath = MakePathNameFromParts(pathParts);
processedPath = GetCorrectPath(processedPath);
break;
}
case NExtractionMode::NPath::kNoPathnames:
{
processedPath = pathParts.Back();
pathParts.Delete(0, pathParts.Size() - 1); // Test it!!
break;
}
}
if(!_processedFileInfo.IsDirectory)
pathParts.DeleteBack();
for(int i = 0; i < pathParts.Size(); i++)
pathParts[i] = GetCorrectFileName(pathParts[i]);
if (!isAnti)
if (!pathParts.IsEmpty())
CreateComplexDirectory(pathParts);
const UString fullProcessedPathUnicode = _directoryPath + processedPath;
UString fullProcessedPath = _directoryPath + processedPath;
if(_processedFileInfo.IsDirectory)
{
_diskFilePath = fullProcessedPath;
if (isAnti)
NFile::NDirectory::MyRemoveDirectory(_diskFilePath);
return S_OK;
}
NFile::NFind::CFileInfoW fileInfo;
if(NFile::NFind::FindFile(fullProcessedPath, fileInfo))
{
switch(_overwriteMode)
{
case NExtractionMode::NOverwrite::kSkipExisting:
return S_OK;
case NExtractionMode::NOverwrite::kAskBefore:
{
INT32 overwiteResult;
RINOK(_extractCallback2->AskOverwrite(
fullProcessedPathUnicode, &fileInfo.LastWriteTime, &fileInfo.Size,
fullPath, &_processedFileInfo.UTCLastWriteTime, newFileSizeDefined?
&newFileSize : NULL, &overwiteResult))
switch(overwiteResult)
{
case NOverwriteAnswer::kCancel:
return E_ABORT;
case NOverwriteAnswer::kNo:
return S_OK;
case NOverwriteAnswer::kNoToAll:
_overwriteMode = NExtractionMode::NOverwrite::kSkipExisting;
return S_OK;
case NOverwriteAnswer::kYesToAll:
_overwriteMode = NExtractionMode::NOverwrite::kWithoutPrompt;
break;
case NOverwriteAnswer::kYes:
break;
case NOverwriteAnswer::kAutoRename:
_overwriteMode = NExtractionMode::NOverwrite::kAutoRename;
break;
default:
throw 20413;
}
}
}
if (_overwriteMode == NExtractionMode::NOverwrite::kAutoRename)
{
if (!AutoRenamePath(fullProcessedPath))
{
UString message = UString(L"can not create name of file ") +
fullProcessedPathUnicode;
RINOK(_extractCallback2->MessageError(message));
return E_ABORT;
}
}
else
if (!NFile::NDirectory::DeleteFileAlways(fullProcessedPath))
{
UString message = UString(L"can not delete output file ") +
fullProcessedPathUnicode;
RINOK(_extractCallback2->MessageError(message));
return E_ABORT;
}
}
if (!isAnti)
{
_outFileStreamSpec = new COutFileStream;
CMyComPtr<ISequentialOutStream> outStreamLoc(_outFileStreamSpec);
if (!_outFileStreamSpec->Open(fullProcessedPath))
{
UString message = L"can not open output file " + fullProcessedPathUnicode;
RINOK(_extractCallback2->MessageError(message));
return S_OK;
}
_outFileStream = outStreamLoc;
*outStream = outStreamLoc.Detach();
}
_diskFilePath = fullProcessedPath;
}
else
{
*outStream = NULL;
}
return S_OK;
}
STDMETHODIMP CArchiveExtractCallback::PrepareOperation(INT32 askExtractMode)
{
_extractMode = false;
switch (askExtractMode)
{
case NArchive::NExtract::NAskMode::kExtract:
_extractMode = true;
};
return _extractCallback2->PrepareOperation(_filePath, askExtractMode);
}
void CArchiveExtractCallback::AddErrorMessage(LPCTSTR message)
{
_messages.Add(message);
}
STDMETHODIMP CArchiveExtractCallback::SetOperationResult(INT32 operationResult)
{
switch(operationResult)
{
case NArchive::NExtract::NOperationResult::kOK:
case NArchive::NExtract::NOperationResult::kUnSupportedMethod:
case NArchive::NExtract::NOperationResult::kCRCError:
case NArchive::NExtract::NOperationResult::kDataError:
break;
default:
_outFileStream.Release();
return E_FAIL;
}
if(_outFileStream != NULL)
_outFileStreamSpec->File.SetLastWriteTime(&_processedFileInfo.UTCLastWriteTime);
_outFileStream.Release();
if (_extractMode && _processedFileInfo.AttributesAreDefined)
NFile::NDirectory::MySetFileAttributes(_diskFilePath, _processedFileInfo.Attributes);
RINOK(_extractCallback2->SetOperationResult(operationResult));
return S_OK;
}
/*
STDMETHODIMP CArchiveExtractCallback::GetInStream(
const wchar_t *name, ISequentialInStream **inStream)
{
CInFileStream *inFile = new CInFileStream;
CMyComPtr<ISequentialInStream> inStreamTemp = inFile;
if (!inFile->Open(_srcDirectoryPrefix + name))
return ::GetLastError();
*inStream = inStreamTemp.Detach();
return S_OK;
}
*/
STDMETHODIMP CArchiveExtractCallback::CryptoGetTextPassword(BSTR *password)
{
if (!_cryptoGetTextPassword)
{
RINOK(_extractCallback2.QueryInterface(IID_ICryptoGetTextPassword,
&_cryptoGetTextPassword));
}
return _cryptoGetTextPassword->CryptoGetTextPassword(password);
}

View File

@@ -0,0 +1,107 @@
// ArchiveExtractCallback.h
#pragma once
#ifndef __ARCHIVEEXTRACTCALLBACK_H
#define __ARCHIVEEXTRACTCALLBACK_H
#include "../../Archive/IArchive.h"
#include "IFolderArchive.h"
#include "Common/String.h"
#include "Common/MyCom.h"
#include "../../Common/FileStreams.h"
#include "../../IPassword.h"
class CArchiveExtractCallback:
public IArchiveExtractCallback,
// public IArchiveVolumeExtractCallback,
public ICryptoGetTextPassword,
public CMyUnknownImp
{
public:
MY_UNKNOWN_IMP1(ICryptoGetTextPassword)
// COM_INTERFACE_ENTRY(IArchiveVolumeExtractCallback)
// IProgress
STDMETHOD(SetTotal)(UINT64 aize);
STDMETHOD(SetCompleted)(const UINT64 *completeValue);
// IExtractCallBack
STDMETHOD(GetStream)(UINT32 anIndex, ISequentialOutStream **outStream,
INT32 askExtractMode);
STDMETHOD(PrepareOperation)(INT32 askExtractMode);
STDMETHOD(SetOperationResult)(INT32 resultEOperationResult);
// IArchiveVolumeExtractCallback
// STDMETHOD(GetInStream)(const wchar_t *name, ISequentialInStream **inStream);
// ICryptoGetTextPassword
STDMETHOD(CryptoGetTextPassword)(BSTR *aPassword);
private:
CMyComPtr<IInArchive> _archiveHandler;
CMyComPtr<IFolderArchiveExtractCallback> _extractCallback2;
CMyComPtr<ICryptoGetTextPassword> _cryptoGetTextPassword;
UString _directoryPath;
NExtractionMode::NPath::EEnum _pathMode;
NExtractionMode::NOverwrite::EEnum _overwriteMode;
UString _filePath;
UString _diskFilePath;
CSysStringVector _messages;
bool _extractMode;
struct CProcessedFileInfo
{
FILETIME UTCLastWriteTime;
bool IsDirectory;
bool AttributesAreDefined;
UINT32 Attributes;
} _processedFileInfo;
COutFileStream *_outFileStreamSpec;
CMyComPtr<ISequentialOutStream> _outFileStream;
UStringVector _removePathParts;
UString _itemDefaultName;
FILETIME _utcLastWriteTimeDefault;
UINT32 _attributesDefault;
// bool m_PasswordIsDefined;
// UString m_Password;
// UString _srcDirectoryPrefix;
void CreateComplexDirectory(const UStringVector &dirPathParts);
/*
void GetPropertyValue(LPITEMIDLIST anItemIDList, PROPID aPropId,
PROPVARIANT *aValue);
bool IsEncrypted(LPITEMIDLIST anItemIDList);
*/
void AddErrorMessage(LPCTSTR message);
public:
// CProgressDialog m_ProcessDialog;
void Init(
IInArchive *archiveHandler,
IFolderArchiveExtractCallback *extractCallback2,
const UString &directoryPath,
NExtractionMode::NPath::EEnum pathMode,
NExtractionMode::NOverwrite::EEnum overwriteMode,
const UStringVector &removePathParts,
const UString &itemDefaultName,
const FILETIME &utcLastWriteTimeDefault,
UINT32 anAttributesDefault
// bool passwordIsDefined, const UString &password
// UString srcDirectoryPrefix
);
UINT64 _numErrors;
};
#endif

67
7zip/UI/Agent/ArchiveFolder.cpp Executable file
View File

@@ -0,0 +1,67 @@
// Zip/ArchiveFolder.cpp
#include "StdAfx.h"
#include "Common/ComTry.h"
#include "Common/StringConvert.h"
#include "Windows/Defs.h"
#include "Windows/PropVariant.h"
#include "Windows/PropVariantConversions.h"
#include "Windows/FileDir.h"
#include "../../Common/FileStreams.h"
#include "../Common/UpdatePair.h"
#include "Agent.h"
#include "ArchiveExtractCallback.h"
using namespace NWindows;
using namespace NCOM;
STDMETHODIMP CAgentFolder::CopyTo(const UINT32 *indices, UINT32 numItems,
const wchar_t *path, IFolderOperationsExtractCallback *callback)
{
COM_TRY_BEGIN
CArchiveExtractCallback *extractCallbackSpec = new
CArchiveExtractCallback;
CMyComPtr<IArchiveExtractCallback> extractCallback = extractCallbackSpec;
UStringVector pathParts;
CProxyFolder *currentProxyFolder = _proxyFolderItem;
while (currentProxyFolder->Parent)
{
pathParts.Insert(0, currentProxyFolder->Name);
currentProxyFolder = currentProxyFolder->Parent;
}
CMyComPtr<IFolderArchiveExtractCallback> extractCallback2;
{
CMyComPtr<IFolderOperationsExtractCallback> callbackWrap = callback;
RINOK(callbackWrap.QueryInterface(
IID_IFolderArchiveExtractCallback, &extractCallback2));
}
extractCallbackSpec->Init(_agentSpec->_archive,
extractCallback2,
path,
NExtractionMode::NPath::kCurrentPathnames,
NExtractionMode::NOverwrite::kAskBefore,
pathParts,
_agentSpec->DefaultName,
_agentSpec->DefaultTime,
_agentSpec->DefaultAttributes
// ,_agentSpec->_srcDirectoryPrefix
);
CUIntVector realIndices;
_proxyFolderItem->GetRealIndices(indices, numItems, realIndices);
return _agentSpec->_archive->Extract(&realIndices.Front(),
realIndices.Size(), BoolToInt(false), extractCallback);
COM_TRY_END
}
STDMETHODIMP CAgentFolder::MoveTo(const UINT32 *indices, UINT32 numItems,
const wchar_t *path, IFolderOperationsExtractCallback *callback)
{
return E_NOTIMPL;
}

View File

@@ -0,0 +1,98 @@
// Zip/ArchiveFolder.cpp
#include "StdAfx.h"
#include "Agent.h"
#include "Common/StringConvert.h"
#include "../Common/OpenArchive.h"
static const UINT64 kMaxCheckStartPosition = 1 << 20;
static inline UINT GetCurrentFileCodePage()
{ return AreFileApisANSI() ? CP_ACP : CP_OEMCP; }
void CArchiveFolderManager::LoadFormats()
{
if (!_formatsLoaded)
ReadArchiverInfoList(_formats);
}
int CArchiveFolderManager::FindFormat(const UString &type)
{
// LoadFormats();
for (int i = 0; i < _formats.Size(); i++)
if (type.CompareNoCase(_formats[i].Name) == 0)
return i;
return -1;
}
STDMETHODIMP CArchiveFolderManager::OpenFolderFile(const wchar_t *filePath,
IFolderFolder **resultFolder, IProgress *progress)
{
CMyComPtr<IArchiveOpenCallback> openArchiveCallback;
if (progress != 0)
{
CMyComPtr<IProgress> progressWrapper = progress;
progressWrapper.QueryInterface(IID_IArchiveOpenCallback, &openArchiveCallback);
}
CAgent *agent = new CAgent();
CComPtr<IInFolderArchive> archive = agent;
RINOK(agent->Open(filePath, NULL, openArchiveCallback));
return agent->BindToRootFolder(resultFolder);
}
/*
HRESULT CAgent::FolderReOpen(
IArchiveOpenCallback *openArchiveCallback)
{
return ReOpenArchive(_archive, _archiveFilePath);
}
*/
STDMETHODIMP CArchiveFolderManager::GetTypes(BSTR *types)
{
LoadFormats();
UString typesStrings;
for(int i = 0; i < _formats.Size(); i++)
{
if (i != 0)
typesStrings += L' ';
typesStrings += _formats[i].Name;
}
CMyComBSTR valueTemp = typesStrings;
*types = valueTemp.Detach();
return S_OK;
}
STDMETHODIMP CArchiveFolderManager::GetExtension(const wchar_t *type, BSTR *extension)
{
*extension = 0;
int formatIndex = FindFormat(type);
if (formatIndex < 0)
return E_INVALIDARG;
// CMyComBSTR valueTemp = _formats[formatIndex].GetAllExtensions();
CMyComBSTR valueTemp = _formats[formatIndex].Extensions[0].Extension;
*extension = valueTemp.Detach();
return S_OK;
}
STDMETHODIMP CArchiveFolderManager::GetIconPath(const wchar_t *type, BSTR *iconPath)
{
*iconPath = 0;
int formatIndex = FindFormat(type);
if (formatIndex < 0)
return E_INVALIDARG;
CMyComBSTR iconPathTemp = _formats[formatIndex].FilePath;
*iconPath = iconPathTemp.Detach();
return S_OK;
}
STDMETHODIMP CArchiveFolderManager::CreateFolderFile(const wchar_t *type, const wchar_t *filePath, IProgress *progress)
{
return E_NOTIMPL;
}

View File

@@ -0,0 +1,219 @@
// FolderOut.cpp
#include "StdAfx.h"
#include "Agent.h"
#include "Common/StringConvert.h"
#include "Common/ComTry.h"
#include "Windows/FileDir.h"
// #include "../Common/CompressEngineCommon.h"
#include "../Common/ZipRegistry.h"
#include "../Common/UpdateAction.h"
#include "../Common/WorkDir.h"
using namespace NWindows;
using namespace NFile;
using namespace NDirectory;
static LPCWSTR kTempArcivePrefix = L"7zA";
void CAgentFolder::GetPathParts(UStringVector &pathParts)
{
pathParts.Clear();
CMyComPtr<IFolderFolder> folder = this;
while (true)
{
CMyComPtr<IFolderFolder> newFolder;
folder->BindToParentFolder(&newFolder);
if (newFolder == NULL)
break;
CMyComBSTR name;
folder->GetName(&name);
pathParts.Insert(0, (const wchar_t *)name);
folder = newFolder;
}
}
HRESULT CAgentFolder::CommonUpdateOperation(
bool deleteOperation,
bool createFolderOperation,
bool renameOperation,
const wchar_t *newItemName,
const NUpdateArchive::CActionSet *actionSet,
const UINT32 *indices, UINT32 numItems,
IFolderArchiveUpdateCallback *updateCallback100)
{
NWorkDir::CInfo workDirInfo;
ReadWorkDirInfo(workDirInfo);
UString archiveFilePath = _agentSpec->_archiveFilePath;
UString workDir = GetWorkDir(workDirInfo, archiveFilePath );
CreateComplexDirectory(workDir);
CTempFileW tempFile;
UString tempFileName;
if (tempFile.Create(workDir, kTempArcivePrefix, tempFileName) == 0)
return E_FAIL;
/*
if (SetOutProperties(anOutArchive, aCompressionInfo.Method) != S_OK)
return NFileOperationReturnCode::kError;
*/
////////////////////////////
// Save FolderItem;
UStringVector pathParts;
GetPathParts(pathParts);
HRESULT result;
if (deleteOperation)
result = _agentSpec->DeleteItems(tempFileName,
indices, numItems, updateCallback100);
else if (createFolderOperation)
{
result = _agentSpec->CreateFolder(tempFileName,
newItemName, updateCallback100);
}
else if (renameOperation)
{
result = _agentSpec->RenameItem(
tempFileName,
indices, numItems,
newItemName,
updateCallback100);
}
else
{
BYTE actionSetByte[NUpdateArchive::NPairState::kNumValues];
for (int i = 0; i < NUpdateArchive::NPairState::kNumValues; i++)
actionSetByte[i] = actionSet->StateActions[i];
result = _agentSpec->DoOperation(NULL, NULL,
tempFileName, actionSetByte, NULL, updateCallback100);
}
if (result != S_OK)
return result;
_agentSpec->Close();
// m_FolderItem = NULL;
if (!DeleteFileAlways(archiveFilePath ))
return GetLastError();
tempFile.DisableDeleting();
if (!MyMoveFile(tempFileName, archiveFilePath ))
return GetLastError();
RINOK(_agentSpec->ReOpen(NULL));
////////////////////////////
// Restore FolderItem;
CMyComPtr<IFolderFolder> archiveFolder;
RINOK(_agentSpec->BindToRootFolder(&archiveFolder));
for (int i = 0; i < pathParts.Size(); i++)
{
CMyComPtr<IFolderFolder> newFolder;
archiveFolder->BindToFolder(pathParts[i], &newFolder);
if(!newFolder)
break;
archiveFolder = newFolder;
}
CMyComPtr<IArchiveFolderInternal> archiveFolderInternal;
RINOK(archiveFolder.QueryInterface(IID_IArchiveFolderInternal, &archiveFolderInternal));
CAgentFolder *agentFolder;
RINOK(archiveFolderInternal->GetAgentFolder(&agentFolder));
_proxyFolderItem = agentFolder->_proxyFolderItem;
_proxyArchive = agentFolder->_proxyArchive;
_parentFolder = agentFolder->_parentFolder;
return S_OK;
}
STDMETHODIMP CAgentFolder::CopyFrom(
const wchar_t *fromFolderPath, // test it
const wchar_t **itemsPaths,
UINT32 numItems,
IProgress *progress)
{
COM_TRY_BEGIN
RINOK(_agentSpec->SetFiles(fromFolderPath, itemsPaths, numItems));
RINOK(_agentSpec->SetFolder(this));
CMyComPtr<IFolderArchiveUpdateCallback> updateCallback100;
if (progress != 0)
{
CMyComPtr<IProgress> progressWrapper = progress;
RINOK(progressWrapper.QueryInterface(
IID_IFolderArchiveUpdateCallback, &updateCallback100));
}
return CommonUpdateOperation(false, false, false, NULL,
&NUpdateArchive::kAddActionSet, 0, 0, updateCallback100);
COM_TRY_END
}
STDMETHODIMP CAgentFolder::Delete(const UINT32 *indices, UINT32 numItems, IProgress *progress)
{
COM_TRY_BEGIN
RINOK(_agentSpec->SetFolder(this));
CMyComPtr<IFolderArchiveUpdateCallback> updateCallback100;
if (progress != 0)
{
CMyComPtr<IProgress> progressWrapper = progress;
RINOK(progressWrapper.QueryInterface(
IID_IFolderArchiveUpdateCallback, &updateCallback100));
}
return CommonUpdateOperation(true, false, false, NULL,
&NUpdateArchive::kDeleteActionSet, indices, numItems, updateCallback100);
COM_TRY_END
}
STDMETHODIMP CAgentFolder::CreateFolder(const wchar_t *name, IProgress *progress)
{
COM_TRY_BEGIN
if (_proxyFolderItem->FindDirSubItemIndex(name) >= 0)
return ERROR_ALREADY_EXISTS;
RINOK(_agentSpec->SetFolder(this));
CMyComPtr<IFolderArchiveUpdateCallback> updateCallback100;
if (progress != 0)
{
CMyComPtr<IProgress> progressWrapper = progress;
RINOK(progressWrapper.QueryInterface(
IID_IFolderArchiveUpdateCallback, &updateCallback100));
}
return CommonUpdateOperation(false, true, false, name, NULL, NULL,
0, updateCallback100);
COM_TRY_END
}
STDMETHODIMP CAgentFolder::Rename(UINT32 index, const wchar_t *newName, IProgress *progress)
{
COM_TRY_BEGIN
CUIntVector realIndices;
CUIntVector indices;
indices.Add(index);
RINOK(_agentSpec->SetFolder(this));
CMyComPtr<IFolderArchiveUpdateCallback> updateCallback100;
if (progress != 0)
{
CMyComPtr<IProgress> progressWrapper = progress;
RINOK(progressWrapper.QueryInterface(
IID_IFolderArchiveUpdateCallback, &updateCallback100));
}
return CommonUpdateOperation(false, false, true, newName, NULL, &indices.Front(),
indices.Size(), updateCallback100);
COM_TRY_END
}
STDMETHODIMP CAgentFolder::CreateFile(const wchar_t *name, IProgress *progress)
{
return E_NOTIMPL;
}
STDMETHODIMP CAgentFolder::SetProperty(UINT32 index, PROPID propID,
const PROPVARIANT *value, IProgress *progress)
{
return E_NOTIMPL;
}

View File

@@ -0,0 +1,229 @@
// ArchiveUpdateCallback.h
#include "StdAfx.h"
#include "ArchiveUpdateCallback.h"
#include "Common/StringConvert.h"
#include "Common/Defs.h"
#include "Windows/FileName.h"
#include "Windows/PropVariant.h"
#include "../../Common/FileStreams.h"
#include "Windows/Defs.h"
using namespace NWindows;
void CArchiveUpdateCallback::Init(const UString &baseFolderPrefix,
const CObjectVector<CDirItem> *dirItems,
const CObjectVector<CArchiveItem> *archiveItems, // test CItemInfoExList
CObjectVector<CUpdatePair2> *updatePairs,
IInArchive *inArchive,
IFolderArchiveUpdateCallback *updateCallback)
{
m_BaseFolderPrefix = baseFolderPrefix;
NFile::NName::NormalizeDirPathPrefix(m_BaseFolderPrefix);
m_DirItems = dirItems;
m_ArchiveItems = archiveItems;
m_UpdatePairs = updatePairs;
m_UpdateCallback = updateCallback;
m_CodePage = ::AreFileApisANSI() ? CP_ACP : CP_OEMCP;
_inArchive = inArchive;;
}
STDMETHODIMP CArchiveUpdateCallback::SetTotal(UINT64 size)
{
if (m_UpdateCallback)
return m_UpdateCallback->SetTotal(size);
return S_OK;
}
STDMETHODIMP CArchiveUpdateCallback::SetCompleted(const UINT64 *completeValue)
{
if (m_UpdateCallback)
return m_UpdateCallback->SetCompleted(completeValue);
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 CArchiveUpdateCallback::EnumProperties(IEnumSTATPROPSTG **enumerator)
{
return CStatPropEnumerator::CreateEnumerator(kProperties,
sizeof(kProperties) / sizeof(kProperties[0]), enumerator);
}
*/
STDMETHODIMP CArchiveUpdateCallback::GetUpdateItemInfo(UINT32 index,
INT32 *newData, INT32 *newProperties, UINT32 *indexInArchive)
{
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)
{
if (m_ArchiveItems == 0)
*indexInArchive = updatePair.ArchiveItemIndex;
else
*indexInArchive = (*m_ArchiveItems)[updatePair.ArchiveItemIndex].IndexInServer;
}
else
*indexInArchive = UINT32(-1);
}
return S_OK;
}
STDMETHODIMP CArchiveUpdateCallback::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;
}
}
else
{
if (propID == kpidPath)
{
if (updatePair.NewNameIsDefined)
{
propVariant = updatePair.NewName;
propVariant.Detach(value);
return S_OK;
}
}
if (updatePair.ExistInArchive && _inArchive)
{
UINT32 indexInArchive;
if (m_ArchiveItems == 0)
indexInArchive = updatePair.ArchiveItemIndex;
else
indexInArchive = (*m_ArchiveItems)[updatePair.ArchiveItemIndex].IndexInServer;
return _inArchive->GetProperty(indexInArchive, propID, value);
}
}
propVariant.Detach(value);
return S_OK;
}
STDMETHODIMP CArchiveUpdateCallback::GetStream(UINT32 index,
IInStream **inStream)
{
const CUpdatePair2 &updatePair = (*m_UpdatePairs)[index];
if(!updatePair.NewData)
return E_FAIL;
const CDirItem &dirItem = (*m_DirItems)[updatePair.DirItemIndex];
/*
m_PercentPrinter.PrintString("Compressing ");
m_PercentCanBePrint = true;
m_PercentPrinter.PrintString(UnicodeStringToMultiByte(dirItem.Name, CP_OEMCP));
m_PercentPrinter.PreparePrint();
m_PercentPrinter.RePrintRatio();
*/
if (m_UpdateCallback)
{
RINOK(m_UpdateCallback->CompressOperation(
GetUnicodeString(dirItem.FullPath, m_CodePage)));
}
if(dirItem.IsDirectory())
return S_OK;
CInFileStream *inStreamSpec = new CInFileStream;
CMyComPtr<IInStream> inStreamLoc(inStreamSpec);
if(!inStreamSpec->Open(m_BaseFolderPrefix + dirItem.FullPath))
return ::GetLastError();
*inStream = inStreamLoc.Detach();
return S_OK;
}
STDMETHODIMP CArchiveUpdateCallback::SetOperationResult(INT32 operationResult)
{
if (m_UpdateCallback)
return m_UpdateCallback->OperationResult(operationResult);
return S_OK;
}
STDMETHODIMP CArchiveUpdateCallback::CryptoGetTextPassword2(INT32 *passwordIsDefined, BSTR *password)
{
*passwordIsDefined = BoolToInt(false);
if (!_cryptoGetTextPassword)
{
if (!m_UpdateCallback)
return S_OK;
HRESULT result = m_UpdateCallback.QueryInterface(
IID_ICryptoGetTextPassword2, &_cryptoGetTextPassword);
if (result != S_OK)
return S_OK;
}
return _cryptoGetTextPassword->CryptoGetTextPassword2(passwordIsDefined, password);
}

View File

@@ -0,0 +1,71 @@
// ArchiveUpdateCallback.h
#pragma once
#ifndef __ARCHIVEUPDATECALLBACK_H
#define __ARCHIVEUPDATECALLBACK_H
#include "../../Archive/IArchive.h"
#include "../../IPassword.h"
#include "IFolderArchive.h"
#include "Common/String.h"
#include "Common/MyCom.h"
#include "../Common/UpdateProduce.h"
// #include "Interface/CryptoInterface.h"
// #include "Interface/MyCom.h"
class CArchiveUpdateCallback:
public IArchiveUpdateCallback,
public ICryptoGetTextPassword2,
public CMyUnknownImp
{
public:
MY_UNKNOWN_IMP1(ICryptoGetTextPassword2)
// IProgress
STDMETHOD(SetTotal)(UINT64 size);
STDMETHOD(SetCompleted)(const UINT64 *completeValue);
// IArchiveUpdateCallback
// STDMETHOD(EnumProperties)(IEnumSTATPROPSTG **enumerator);
STDMETHOD(GetUpdateItemInfo)(UINT32 index,
INT32 *newData, // 1 - new data, 0 - old data
INT32 *newProperties, // 1 - new properties, 0 - old properties
UINT32 *indexInArchive// set if existInArchive == true
);
STDMETHOD(GetProperty)(UINT32 index, PROPID propID, PROPVARIANT *value);
STDMETHOD(GetStream)(UINT32 index, IInStream **anInStream);
STDMETHOD(SetOperationResult)(INT32 operationResult);
STDMETHOD(CryptoGetTextPassword2)(INT32 *passwordIsDefined, BSTR *password);
private:
UString m_BaseFolderPrefix;
const CObjectVector<CDirItem> *m_DirItems;
const CObjectVector<CArchiveItem> *m_ArchiveItems;
const CObjectVector<CUpdatePair2> *m_UpdatePairs;
CMyComPtr<IFolderArchiveUpdateCallback> m_UpdateCallback;
CMyComPtr<ICryptoGetTextPassword2> _cryptoGetTextPassword;
UINT m_CodePage;
CMyComPtr<IInArchive> _inArchive;
public:
void Init(const UString &baseFolderPrefix,
const CObjectVector<CDirItem> *dirItems,
const CObjectVector<CArchiveItem> *archiveItems, // test CItemInfoExList
CObjectVector<CUpdatePair2> *updatePairs,
// UINT codePage,
IInArchive *inArchive,
IFolderArchiveUpdateCallback *updateCallback);
};
#endif

141
7zip/UI/Agent/IFolderArchive.h Executable file
View File

@@ -0,0 +1,141 @@
// IFolderArchive.h
#pragma once
#ifndef __IFOLDERARCHIVE_H
#define __IFOLDERARCHIVE_H
#include "../../Archive/IArchive.h"
// #include "../Format/Common/ArchiveInterface.h"
#include "../../FileManager/IFolder.h"
namespace NExtractionMode {
namespace NPath
{
enum EEnum
{
kFullPathnames,
kCurrentPathnames,
kNoPathnames
};
}
namespace NOverwrite
{
enum EEnum
{
kAskBefore,
kWithoutPrompt,
kSkipExisting,
kAutoRename
};
}
}
namespace NOverwriteAnswer
{
enum EEnum
{
kYes,
kYesToAll,
kNo,
kNoToAll,
kAutoRename,
kCancel,
};
}
// {23170F69-40C1-278A-0000-000100070000}
DEFINE_GUID(IID_IFolderArchiveExtractCallback,
0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x01, 0x00, 0x07, 0x00, 0x00);
MIDL_INTERFACE("23170F69-40C1-278A-0000-000100070000")
IFolderArchiveExtractCallback: public IProgress
{
public:
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) PURE;
STDMETHOD(MessageError)(const wchar_t *message) PURE;
STDMETHOD(SetOperationResult)(INT32 operationResult) PURE;
};
// {23170F69-40C1-278A-0000-000100050000}
DEFINE_GUID(IID_IArchiveFolder,
0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x01, 0x00, 0x05, 0x00, 0x00);
MIDL_INTERFACE("23170F69-40C1-278A-0000-000100050000")
IArchiveFolder: public IUnknown
{
public:
STDMETHOD(Extract)(const UINT32 *indices, UINT32 numItems,
NExtractionMode::NPath::EEnum pathMode,
NExtractionMode::NOverwrite::EEnum overwriteMode,
const wchar_t *path,
INT32 testMode,
IFolderArchiveExtractCallback *extractCallback2) PURE;
};
// {23170F69-40C1-278A-0000-000100060000}
DEFINE_GUID(IID_IInFolderArchive,
0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x01, 0x00, 0x06, 0x00, 0x00);
MIDL_INTERFACE("23170F69-40C1-278A-0000-000100060000")
IInFolderArchive: public IUnknown
{
public:
STDMETHOD(Open)(const wchar_t *filePath,
// CLSID *clsIDResult,
BSTR *archiveType,
IArchiveOpenCallback *openArchiveCallback) PURE;
STDMETHOD(ReOpen)(
// const wchar_t *filePath,
IArchiveOpenCallback *openArchiveCallback) PURE;
STDMETHOD(Close)() PURE;
STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value) PURE;
STDMETHOD(GetNumberOfProperties)(UINT32 *numProperties) PURE;
STDMETHOD(GetPropertyInfo)(UINT32 index,
BSTR *name, PROPID *propID, VARTYPE *varType) PURE;
STDMETHOD(GetNumberOfArchiveProperties)(UINT32 *numProperties) PURE;
STDMETHOD(GetArchivePropertyInfo)(UINT32 index,
BSTR *name, PROPID *propID, VARTYPE *varType) PURE;
STDMETHOD(BindToRootFolder)(IFolderFolder **resultFolder) PURE;
STDMETHOD(Extract)(
NExtractionMode::NPath::EEnum pathMode,
NExtractionMode::NOverwrite::EEnum overwriteMode,
const wchar_t *path,
INT32 testMode,
IFolderArchiveExtractCallback *extractCallback2) PURE;
};
// {23170F69-40C1-278A-0000-0001000B0000}
DEFINE_GUID(IID_IFolderArchiveUpdateCallback,
0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0B, 0x00, 0x00);
MIDL_INTERFACE("23170F69-40C1-278A-0000-0001000B0000")
IFolderArchiveUpdateCallback: public IProgress
{
public:
STDMETHOD(CompressOperation)(const wchar_t *name) PURE;
STDMETHOD(DeleteOperation)(const wchar_t *name) PURE;
STDMETHOD(OperationResult)(INT32 operationResult) PURE;
};
// {23170F69-40C1-278A-0000-0001000A0000}
DEFINE_GUID(IID_IOutFolderArchive,
0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0A, 0x00, 0x00);
MIDL_INTERFACE("23170F69-40C1-278A-0000-0001000A0000")
IOutFolderArchive: public IUnknown
{
STDMETHOD(SetFolder)(IFolderFolder *folder) PURE;
STDMETHOD(SetFiles)(const wchar_t *folderPrefix, const wchar_t **names, UINT32 numNames) PURE;
STDMETHOD(DeleteItems)(const wchar_t *newArchiveName,
const UINT32 *indices, UINT32 numItems, IFolderArchiveUpdateCallback *updateCallback) PURE;
STDMETHOD(DoOperation)(
const wchar_t *filePath,
const CLSID *clsID,
const wchar_t *newArchiveName,
const BYTE *stateActions,
const wchar_t *sfxModule,
IFolderArchiveUpdateCallback *updateCallback) PURE;
};
#endif

72
7zip/UI/Client7z/Client7z.cpp Executable file
View File

@@ -0,0 +1,72 @@
// Client7z.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include <initguid.h>
#include "Common/StringConvert.h"
#include "../../Common/FileStreams.h"
#include "../../Archive/IArchive.h"
#include "Windows/PropVariant.h"
#include "Windows/PropVariantConversions.h"
#include "Windows/DLL.h"
// {23170F69-40C1-278A-1000-000110050000}
DEFINE_GUID(CLSID_CFormat7z,
0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x05, 0x00, 0x00);
typedef UINT32 (WINAPI * CreateObjectFunc)(
const GUID *clsID,
const GUID *interfaceID,
void **outObject);
int main(int argc, char* argv[])
{
if (argc != 2)
{
printf("Use Client7z.exe file.7z");
return 1;
}
NWindows::NDLL::CLibrary library;
if (!library.Load("7za.dll"))
{
printf("Can not load library");
return 1;
}
CreateObjectFunc
createObjectFunc =
(CreateObjectFunc)library.GetProcAddress("CreateObject");
if (createObjectFunc == 0)
{
printf("Can not get CreateObject");
return 1;
}
CMyComPtr<IInArchive> archive;
if (createObjectFunc(&CLSID_CFormat7z,
&IID_IInArchive, (void **)&archive) != S_OK)
{
printf("Can not get class object");
return 1;
}
CInFileStream *fileSpec = new CInFileStream;
CMyComPtr<IInStream> file = fileSpec;
if (!fileSpec->Open(argv[1]))
{
printf("Can not open");
return 1;
}
if (archive->Open(file, 0, 0) != S_OK)
return 0;
UINT32 numItems = 0;
archive->GetNumberOfItems(&numItems);
for (UINT32 i = 0; i < numItems; i++)
{
NWindows::NCOM::CPropVariant propVariant;
archive->GetProperty(i, kpidPath, &propVariant);
UString s = ConvertPropVariantToString(propVariant);
printf("%s\n", (LPCSTR)GetOemString(s));
}
return 0;
}

190
7zip/UI/Client7z/Client7z.dsp Executable file
View File

@@ -0,0 +1,190 @@
# Microsoft Developer Studio Project File - Name="Client7z" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=Client7z - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "Client7z.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "Client7z.mak" CFG="Client7z - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "Client7z - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "Client7z - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "Client7z - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /c
# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\..\\" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /c
# ADD BASE RSC /l 0x419 /d "NDEBUG"
# ADD RSC /l 0x419 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "Client7z - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /GZ /c
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "..\..\..\\" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /GZ /c
# ADD BASE RSC /l 0x419 /d "_DEBUG"
# ADD RSC /l 0x419 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "Client7z - Win32 Release"
# Name "Client7z - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\Client7z.cpp
# End Source File
# Begin Source File
SOURCE=.\StdAfx.cpp
# ADD CPP /Yc"stdafx.h"
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\StdAfx.h
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# Begin Group "SDK"
# PROP Default_Filter ""
# End Group
# Begin Group "Windows"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\..\..\Windows\DLL.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\DLL.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\FileIO.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\FileIO.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\PropVariant.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\PropVariant.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\PropVariantConversions.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\PropVariantConversions.h
# End Source File
# End Group
# Begin Group "Common"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\..\..\Common\IntToString.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\IntToString.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\String.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\String.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\StringConvert.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\StringConvert.h
# End Source File
# End Group
# Begin Group "7zip Common"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\..\Common\FileStreams.cpp
# End Source File
# Begin Source File
SOURCE=..\..\Common\FileStreams.h
# End Source File
# End Group
# End Target
# End Project

29
7zip/UI/Client7z/Client7z.dsw Executable file
View File

@@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "Client7z"=.\Client7z.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

8
7zip/UI/Client7z/StdAfx.cpp Executable file
View File

@@ -0,0 +1,8 @@
// stdafx.cpp : source file that includes just the standard includes
// Client7z.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file

12
7zip/UI/Client7z/StdAfx.h Executable file
View File

@@ -0,0 +1,12 @@
// stdafx.h
#pragma once
#ifndef __STDAFX_H
#define __STDAFX_H
#include <windows.h>
#include <stdio.h>
#endif

46
7zip/UI/Common/ArchiveName.cpp Executable file
View File

@@ -0,0 +1,46 @@
// ArchiveName.cpp
#include "StdAfx.h"
#include "Windows/FileFind.h"
#include "Windows/FileDir.h"
using namespace NWindows;
UString CreateArchiveName(const UString &srcName, bool fromPrev, bool keepName)
{
UString resultName = L"Archive";
if (fromPrev)
{
UString dirPrefix;
if (NFile::NDirectory::GetOnlyDirPrefix(srcName, dirPrefix))
{
if (dirPrefix.Length() > 0)
if (dirPrefix[dirPrefix.Length() - 1] == '\\')
{
dirPrefix.Delete(dirPrefix.Length() - 1);
NFile::NFind::CFileInfoW fileInfo;
if (NFile::NFind::FindFile(dirPrefix, fileInfo))
resultName = fileInfo.Name;
}
}
}
else
{
NFile::NFind::CFileInfoW fileInfo;
if (!NFile::NFind::FindFile(srcName, fileInfo))
return ::GetLastError();
resultName = fileInfo.Name;
if (!fileInfo.IsDirectory() && !keepName)
{
int dotPos = resultName.ReverseFind('.');
if (dotPos >= 0)
{
UString archiveName2 = resultName.Left(dotPos);
if (archiveName2.ReverseFind('.') < 0)
resultName = archiveName2;
}
}
}
return resultName;
}

12
7zip/UI/Common/ArchiveName.h Executable file
View File

@@ -0,0 +1,12 @@
// ArchiveName.h
#pragma once
#ifndef __ARCHIVENAME_H
#define __ARCHIVENAME_H
#include "Common/String.h"
UString CreateArchiveName(const UString &srcName, bool fromPrev, bool keepName);
#endif

308
7zip/UI/Common/ArchiverInfo.cpp Executable file
View File

@@ -0,0 +1,308 @@
// ArchiverInfo.cpp
#include "StdAfx.h"
#include "ArchiverInfo.h"
#ifndef EXCLUDE_COM
#include "Common/StringConvert.h"
#include "Windows/FileFind.h"
#include "Windows/FileName.h"
#include "Windows/DLL.h"
#include "Windows/Registry.h"
#include "Windows/PropVariant.h"
#include "../../Archive/IArchive.h"
using namespace NWindows;
using namespace NFile;
#endif
extern HINSTANCE g_hInstance;
#ifndef EXCLUDE_COM
static void SplitString(const UString &srcString, UStringVector &destStrings)
{
destStrings.Clear();
UString string;
int len = srcString.Length();
if (len == 0)
return;
for (int i = 0; i < len; i++)
{
wchar_t c = srcString[i];
if (c == L' ')
{
if (!string.IsEmpty())
{
destStrings.Add(string);
string.Empty();
}
}
else
string += c;
}
if (!string.IsEmpty())
destStrings.Add(string);
}
typedef UINT32 (WINAPI * GetHandlerPropertyFunc)(
PROPID propID, PROPVARIANT *value);
/*
UString GetCurrentModulePath()
{
TCHAR fullPath[MAX_PATH + 1];
::GetModuleFileName(g_hInstance, fullPath, MAX_PATH);
return fullPath;
}
*/
static UString GetModuleFolderPrefix()
{
UString path;
NDLL::MyGetModuleFileName(g_hInstance, path);
int pos = path.ReverseFind(L'\\');
return path.Left(pos + 1);
}
static wchar_t *kFormatFolderName = L"Formats";
static LPCTSTR kRegistryPath = TEXT("Software\\7-zip");
static LPCTSTR kProgramPathValue = TEXT("Path");
UString GetBaseFolderPrefix()
{
UString moduleFolderPrefix = GetModuleFolderPrefix();
NFind::CFileInfoW fileInfo;
if (NFind::FindFile(moduleFolderPrefix + kFormatFolderName, fileInfo))
if (fileInfo.IsDirectory())
return moduleFolderPrefix;
CSysString pathSys;
{
NRegistry::CKey key;
if(key.Open(HKEY_CURRENT_USER, kRegistryPath, KEY_READ) == ERROR_SUCCESS)
if (key.QueryValue(kProgramPathValue, pathSys) == ERROR_SUCCESS)
{
UString path = GetUnicodeString(pathSys);
NName::NormalizeDirPathPrefix(path);
return path;
}
}
{
NRegistry::CKey key;
if(key.Open(HKEY_LOCAL_MACHINE, kRegistryPath, KEY_READ) == ERROR_SUCCESS)
if (key.QueryValue(kProgramPathValue, pathSys) == ERROR_SUCCESS)
{
UString path = GetUnicodeString(pathSys);
NName::NormalizeDirPathPrefix(path);
return path;
}
}
return moduleFolderPrefix;
}
typedef UINT32 (WINAPI *CreateObjectPointer)(
const GUID *clsID,
const GUID *interfaceID,
void **outObject);
#endif
void ReadArchiverInfoList(CObjectVector<CArchiverInfo> &archivers)
{
archivers.Clear();
#ifdef EXCLUDE_COM
#ifdef FORMAT_7Z
{
CArchiverInfo item;
item.UpdateEnabled = true;
item.KeepName = false;
item.Name = L"7z";
item.Extensions.Add(CArchiverExtInfo(L"7z"));
archivers.Add(item);
}
#endif
#ifdef FORMAT_BZIP2
{
CArchiverInfo item;
item.UpdateEnabled = true;
item.KeepName = true;
item.Name = L"BZip2";
item.Extensions.Add(CArchiverExtInfo(L"bz2"));
item.Extensions.Add(CArchiverExtInfo(L"tbz2", L".tar"));
archivers.Add(item);
}
#endif
#ifdef FORMAT_GZIP
{
CArchiverInfo item;
item.UpdateEnabled = true;
item.KeepName = false;
item.Name = L"GZip";
item.Extensions.Add(CArchiverExtInfo(L"gz"));
item.Extensions.Add(CArchiverExtInfo(L"tgz", L".tar"));
archivers.Add(item);
}
#endif
#ifdef FORMAT_TAR
{
CArchiverInfo item;
item.UpdateEnabled = true;
item.KeepName = false;
item.Name = L"Tar";
item.Extensions.Add(CArchiverExtInfo(L"tar"));
archivers.Add(item);
}
#endif
#ifdef FORMAT_ZIP
{
CArchiverInfo item;
item.UpdateEnabled = true;
item.KeepName = false;
item.Name = L"Zip";
item.Extensions.Add(CArchiverExtInfo(L"zip"));
archivers.Add(item);
}
#endif
#ifdef FORMAT_CPIO
{
CArchiverInfo item;
item.UpdateEnabled = false;
item.Name = L"Cpio";
item.Extensions.Add(CArchiverExtInfo(L"cpio"));
archivers.Add(item);
}
#endif
#ifdef FORMAT_RPM
{
CArchiverInfo item;
item.UpdateEnabled = false;
item.Name = L"Rpm";
item.Extensions.Add(CArchiverExtInfo(L"rpm", L".cpio.gz"));
archivers.Add(item);
}
#endif
#ifdef FORMAT_ARJ
{
CArchiverInfo item;
item.UpdateEnabled = false;
item.Name = L"Arj";
item.Extensions.Add(CArchiverExtInfo(L"arj"));
archivers.Add(item);
}
#endif
#else
UString folderPath = GetBaseFolderPrefix() +
kFormatFolderName + L"\\";
NFind::CEnumeratorW enumerator(folderPath + L"*");
NFind::CFileInfoW fileInfo;
while (enumerator.Next(fileInfo))
{
if (fileInfo.IsDirectory())
continue;
UString filePath = folderPath + fileInfo.Name;
{
NDLL::CLibrary library;
if (!library.LoadEx(filePath, LOAD_LIBRARY_AS_DATAFILE))
continue;
}
NDLL::CLibrary library;
if (!library.Load(filePath))
continue;
GetHandlerPropertyFunc getHandlerProperty = (GetHandlerPropertyFunc)
library.GetProcAddress("GetHandlerProperty");
if (getHandlerProperty == NULL)
continue;
CArchiverInfo item;
item.FilePath = filePath;
NWindows::NCOM::CPropVariant prop;
if (getHandlerProperty(NArchive::kName, &prop) != S_OK)
continue;
if (prop.vt != VT_BSTR)
continue;
item.Name = prop.bstrVal;
prop.Clear();
if (getHandlerProperty(NArchive::kClassID, &prop) != S_OK)
continue;
if (prop.vt != VT_BSTR)
continue;
item.ClassID = *(const GUID *)prop.bstrVal;
prop.Clear();
if (getHandlerProperty(NArchive::kExtension, &prop) != S_OK)
continue;
if (prop.vt != VT_BSTR)
continue;
UString ext = prop.bstrVal;
// item.Extension = prop.bstrVal;
UString addExt;
if (getHandlerProperty(NArchive::kAddExtension, &prop) != S_OK)
continue;
if (prop.vt == VT_BSTR)
{
addExt = prop.bstrVal;
}
else if (prop.vt != VT_EMPTY)
continue;
prop.Clear();
UStringVector exts, addExts;
SplitString(ext, exts);
SplitString(addExt, addExts);
prop.Clear();
for (int i = 0; i < exts.Size(); i++)
{
CArchiverExtInfo extInfo;
extInfo.Extension = exts[i];
if (addExts.Size() > 0)
extInfo.AddExtension = addExts[i];
if (extInfo.AddExtension == L"*")
extInfo.AddExtension.Empty();
item.Extensions.Add(extInfo);
}
if (getHandlerProperty(NArchive::kUpdate, &prop) != S_OK)
continue;
if (prop.vt != VT_BOOL)
continue;
item.UpdateEnabled = VARIANT_BOOLToBool(prop.boolVal);
prop.Clear();
if (item.UpdateEnabled)
{
if (getHandlerProperty(NArchive::kKeepName, &prop) != S_OK)
continue;
if (prop.vt != VT_BOOL)
continue;
item.KeepName = VARIANT_BOOLToBool(prop.boolVal);
prop.Clear();
}
archivers.Add(item);
}
#endif
}

58
7zip/UI/Common/ArchiverInfo.h Executable file
View File

@@ -0,0 +1,58 @@
// ArchiverInfo.h
#pragma once
#ifndef __ARCHIVERINFO_H
#define __ARCHIVERINFO_H
#include "Common/String.h"
#include "Common/Types.h"
struct CArchiverExtInfo
{
UString Extension;
UString AddExtension;
CArchiverExtInfo() {}
CArchiverExtInfo(const UString &extension):
Extension(extension) {}
CArchiverExtInfo(const UString &extension, const UString &addExtension):
Extension(extension), AddExtension(addExtension) {}
};
struct CArchiverInfo
{
#ifndef EXCLUDE_COM
UString FilePath;
CLSID ClassID;
#endif
UString Name;
CObjectVector<CArchiverExtInfo> Extensions;
int FindExtension(const UString &ext) const
{
for (int i = 0; i < Extensions.Size(); i++)
if (ext.CollateNoCase(Extensions[i].Extension) == 0)
return i;
return -1;
}
UString GetAllExtensions() const
{
UString s;
for (int i = 0; i < Extensions.Size(); i++)
{
if (i > 0)
s += ' ';
s += Extensions[i].Extension;
}
return s;
}
const UString &GetMainExtension() const
{
return Extensions[0].Extension;
}
bool UpdateEnabled;
bool KeepName;
};
void ReadArchiverInfoList(CObjectVector<CArchiverInfo> &archivers);
#endif

229
7zip/UI/Common/CompressCall.cpp Executable file
View File

@@ -0,0 +1,229 @@
// CompressCall.cpp
#include "StdAfx.h"
#include "CompressCall.h"
#include "Common/Random.h"
#include "Common/IntToString.h"
#include "Common/MyCom.h"
#include "Common/StringConvert.h"
#include "Windows/Synchronization.h"
#include "Windows/FileMapping.h"
#include "../../FileManager/ProgramLocation.h"
using namespace NWindows;
static LPCWSTR kShowDialogSwitch = L" -ad";
static LPCWSTR kEmailSwitch = L" -seml";
static LPCWSTR kMapSwitch = L" -i#";
static bool IsItWindowsNT()
{
OSVERSIONINFO versionInfo;
versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);
if (!::GetVersionEx(&versionInfo))
return false;
return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);
}
HRESULT MyCreateProcess(const UString &params,
NWindows::NSynchronization::CEvent *event)
{
STARTUPINFO startupInfo;
startupInfo.cb = sizeof(startupInfo);
startupInfo.lpReserved = 0;
startupInfo.lpDesktop = 0;
startupInfo.lpTitle = 0;
startupInfo.dwFlags = 0;
startupInfo.cbReserved2 = 0;
startupInfo.lpReserved2 = 0;
PROCESS_INFORMATION processInformation;
BOOL result = ::CreateProcess(NULL, (TCHAR *)(const TCHAR *)
GetSystemString(params),
NULL, NULL, FALSE, 0, NULL, NULL,
&startupInfo, &processInformation);
if (result == 0)
return ::GetLastError();
else
{
if (event != NULL)
{
HANDLE handles[] = {processInformation.hProcess, *event };
::WaitForMultipleObjects(sizeof(handles) / sizeof(handles[0]),
handles, FALSE, INFINITE);
}
::CloseHandle(processInformation.hThread);
::CloseHandle(processInformation.hProcess);
}
return S_OK;
}
static UString GetQuotedString(const UString &s)
{
return UString(L"\"") + s + UString(L"\"");
}
static UString Get7zGuiPath()
{
UString path = L"\"";
UString folder;
if (GetProgramFolderPath(folder))
path += folder;
if (IsItWindowsNT())
path += L"7zgn.exe";
else
path += L"7zg.exe";
path += L"\"";
return path;
}
HRESULT CompressFiles(
const UString &archiveName,
const UStringVector &names,
// const UString &outFolder,
bool email,
bool showDialog)
{
UString params;
params = Get7zGuiPath();
params += L" a";
params += kMapSwitch;
// params += _fileNames[0];
UINT32 extraSize = 2;
UINT32 dataSize = 0;
for (int i = 0; i < names.Size(); i++)
dataSize += (names[i].Length() + 1) * sizeof(wchar_t);
UINT32 totalSize = extraSize + dataSize;
UString mappingName;
UString eventName;
CFileMapping fileMapping;
CRandom random;
random.Init(GetTickCount());
while(true)
{
int number = random.Generate();
wchar_t temp[32];
ConvertUINT64ToString(UINT32(number), temp);
mappingName = L"7zCompressMapping";
mappingName += temp;
if (!fileMapping.Create(INVALID_HANDLE_VALUE, NULL,
PAGE_READWRITE, totalSize, GetSystemString(mappingName)))
{
// MyMessageBox(IDS_ERROR, 0x02000605);
return E_FAIL;
}
if (::GetLastError() != ERROR_ALREADY_EXISTS)
break;
fileMapping.Close();
}
NSynchronization::CEvent event;
while(true)
{
int number = random.Generate();
wchar_t temp[32];
ConvertUINT64ToString(UINT32(number), temp);
eventName = L"7zCompressMappingEndEvent";
eventName += temp;
if (!event.Create(true, false, GetSystemString(eventName)))
{
// MyMessageBox(IDS_ERROR, 0x02000605);
return E_FAIL;
}
if (::GetLastError() != ERROR_ALREADY_EXISTS)
break;
event.Close();
}
params += mappingName;
params += L":";
wchar_t string[10];
ConvertUINT64ToString(totalSize, string);
params += string;
params += L":";
params += eventName;
if (email)
params += kEmailSwitch;
if (showDialog)
params += kShowDialogSwitch;
params += L" ";
params += GetQuotedString(archiveName);
LPVOID data = fileMapping.MapViewOfFile(FILE_MAP_WRITE, 0, totalSize);
if (data == NULL)
{
// MyMessageBox(IDS_ERROR, 0x02000605);
return E_FAIL;
}
try
{
wchar_t *curData = (wchar_t *)data;
*curData = 0;
curData++;
for (int i = 0; i < names.Size(); i++)
{
const UString &unicodeString = names[i];
memcpy(curData, (const wchar_t *)unicodeString ,
unicodeString .Length() * sizeof(wchar_t));
curData += unicodeString .Length();
*curData++ = L'\0';
}
// MessageBox(0, params, 0, 0);
RINOK(MyCreateProcess(params, &event));
}
catch(...)
{
UnmapViewOfFile(data);
throw;
}
UnmapViewOfFile(data);
/*
CThreadCompressMain *compressor = new CThreadCompressMain();;
compressor->FileNames = _fileNames;
CThread thread;
if (!thread.Create(CThreadCompressMain::MyThreadFunction, compressor))
throw 271824;
*/
return S_OK;
}
HRESULT ExtractArchive(const UString &archiveName,
const UString &outFolder, bool showDialog)
{
UString params;
params = Get7zGuiPath();
params += L" x ";
params += GetQuotedString(archiveName);
if (!outFolder.IsEmpty())
{
params += L" -o";
params += GetQuotedString(outFolder);
}
if (showDialog)
params += kShowDialogSwitch;
return MyCreateProcess(params);
}
HRESULT TestArchive(const UString &archiveName)
{
UString params;
params = Get7zGuiPath();
params += L" t ";
params += GetQuotedString(archiveName);
return MyCreateProcess(params);
}

22
7zip/UI/Common/CompressCall.h Executable file
View File

@@ -0,0 +1,22 @@
// CompressCall.h
#ifndef __COMPRESSCALL_H
#define __COMPRESSCALL_H
#include "Common/String.h"
#include "Windows/Synchronization.h"
HRESULT MyCreateProcess(const UString &params,
NWindows::NSynchronization::CEvent *event = NULL);
HRESULT CompressFiles(const UString &archiveName,
const UStringVector &names,
// const UString &outFolder,
bool email, bool showDialog);
HRESULT ExtractArchive(const UString &archiveName,
const UString &outFolder, bool showDialog);
HRESULT TestArchive(const UString &archiveName);
#endif

33
7zip/UI/Common/DefaultName.cpp Executable file
View File

@@ -0,0 +1,33 @@
// DefaultName.cpp
#include "StdAfx.h"
#include "Windows/FileDir.h"
#include "Common/StringConvert.h"
#include "DefaultName.h"
const wchar_t *kEmptyFileAlias = L"[Content]";
using namespace NWindows;
using namespace NFile;
using namespace NDirectory;
UString GetDefaultName(const UString &fullFileName,
const UString &extension, const UString &addSubExtension)
{
UString fileName;
if (!GetOnlyName(fullFileName, fileName))
throw 5011749;
int extLength = extension.Length();
int fileNameLength = fileName.Length();
if (fileNameLength <= extLength + 1)
return kEmptyFileAlias;
int dotPos = fileNameLength - (extLength + 1);
if (fileName[dotPos] != '.')
return kEmptyFileAlias;
if (extension.CollateNoCase(fileName.Mid(dotPos + 1)) == 0)
return fileName.Left(dotPos) + addSubExtension;
return kEmptyFileAlias;
}

13
7zip/UI/Common/DefaultName.h Executable file
View File

@@ -0,0 +1,13 @@
// DefaultName.h
#pragma once
#ifndef __DEFAULTNAME_H
#define __DEFAULTNAME_H
#include "Common/String.h"
UString GetDefaultName(const UString &fullFileName,
const UString &extension, const UString &addSubExtension);
#endif

37
7zip/UI/Common/DirItem.h Executable file
View File

@@ -0,0 +1,37 @@
// DirItem.h
#pragma once
#ifndef __DIR_ITEM_H
#define __DIR_ITEM_H
// #include "Common/Types.h"
#include "Common/String.h"
// #include "Windows/PropVariant.h"
struct CDirItem
{
UINT32 Attributes;
FILETIME CreationTime;
FILETIME LastAccessTime;
FILETIME LastWriteTime;
UINT64 Size;
UString Name;
UString FullPath;
bool IsDirectory() const { return (Attributes & FILE_ATTRIBUTE_DIRECTORY) != 0 ; }
};
struct CArchiveItem
{
bool IsDirectory;
// DWORD Attributes;
// NWindows::NCOM::CPropVariant LastWriteTime;
FILETIME LastWriteTime;
bool SizeIsDefined;
UINT64 Size;
UString Name;
bool Censored;
int IndexInServer;
};
#endif

71
7zip/UI/Common/EnumDirItems.cpp Executable file
View File

@@ -0,0 +1,71 @@
// EnumDirItems.cpp
#include "StdAfx.h"
#include "EnumDirItems.h"
#include "Common/StringConvert.h"
using namespace NWindows;
using namespace NFile;
using namespace NName;
// using namespace NUpdateArchive;
void AddDirFileInfo(
const UString &prefix,
const UString &fullPathName,
NFind::CFileInfoW &fileInfo,
CObjectVector<CDirItem> &dirItems)
{
CDirItem item;
item.Attributes = fileInfo.Attributes;
item.Size = fileInfo.Size;
item.CreationTime = fileInfo.CreationTime;
item.LastAccessTime = fileInfo.LastAccessTime;
item.LastWriteTime = fileInfo.LastWriteTime;
item.Name = prefix + fileInfo.Name;
item.FullPath = fullPathName;
dirItems.Add(item);
}
static void EnumerateDirectory(
const UString &baseFolderPrefix,
const UString &directory,
const UString &prefix,
CObjectVector<CDirItem> &dirItems)
{
NFind::CEnumeratorW enumerator(baseFolderPrefix + directory + wchar_t(kAnyStringWildcard));
NFind::CFileInfoW fileInfo;
while (enumerator.Next(fileInfo))
{
AddDirFileInfo(prefix, directory + fileInfo.Name, fileInfo,
dirItems);
if (fileInfo.IsDirectory())
{
EnumerateDirectory(baseFolderPrefix, directory + fileInfo.Name + wchar_t(kDirDelimiter),
prefix + fileInfo.Name + wchar_t(kDirDelimiter), dirItems);
}
}
}
void EnumerateDirItems(
const UString &baseFolderPrefix,
const UStringVector &fileNames,
const UString &archiveNamePrefix,
CObjectVector<CDirItem> &dirItems)
{
for(int i = 0; i < fileNames.Size(); i++)
{
const UString &fileName = fileNames[i];
NFind::CFileInfoW fileInfo;
if (!NFind::FindFile(baseFolderPrefix + fileName, fileInfo))
throw 1081736;
AddDirFileInfo(archiveNamePrefix, fileName, fileInfo, dirItems);
if (fileInfo.IsDirectory())
{
EnumerateDirectory(baseFolderPrefix, fileName + wchar_t(kDirDelimiter),
archiveNamePrefix + fileInfo.Name + wchar_t(kDirDelimiter),
dirItems);
}
}
}

33
7zip/UI/Common/EnumDirItems.h Executable file
View File

@@ -0,0 +1,33 @@
// EnumDirItems.h
#pragma once
#ifndef __ENUM_DIR_ITEMS_H
#define __ENUM_DIR_ITEMS_H
#include "Common/String.h"
#include "Common/Vector.h"
#include "DirItem.h"
// #include "UpdatePairBasic.h"
#include "Windows/FileFind.h"
void AddDirFileInfo(
const UString &prefix,
const UString &fullPathName,
NWindows::NFile::NFind::CFileInfoW &fileInfo,
CObjectVector<CDirItem> &dirItems);
void EnumerateDirItems(
const UString &baseFolderPrefix,
const UStringVector &fileNames,
const UString &archiveNamePrefix,
CObjectVector<CDirItem> &dirItems);
/*
void EnumerateItems(const CSysStringVector &filePaths,
const UString &archiveNamePrefix,
CArchiveStyleDirItemInfoVector &dirFileInfoVector, UINT codePage);
*/
#endif

View File

@@ -0,0 +1,54 @@
// ExtractingFilePath.cpp
#include "StdAfx.h"
#include "ExtractingFilePath.h"
UString GetCorrectFileName(const UString &path)
{
UString result = path;
result.Trim();
result.Replace(L"..\\", L"");
result.Replace(L"../", L"");
if (result.Length() > 1)
{
if (result[1] == L':')
{
result.Delete(1);
// result.Insert(first + 1, L'_');
}
}
return result;
}
UString GetCorrectPath(const UString &path)
{
UString result = path;
int first;
for (first = 0; first < result.Length(); first++)
if (result[first] != ' ')
break;
while(result.Length() > first)
{
if (result[first] == L'\\' || result[first] == L'/')
{
result.Delete(first);
continue;
}
break;
}
result.Replace(L"..\\", L"");
result.Replace(L"../", L"");
if (result.Length() > 1)
{
if (result[first + 1] == L':')
{
result.Delete(first + 1);
// result.Insert(first + 1, L'_');
}
}
return result;
}

View File

@@ -0,0 +1,13 @@
// ExtractingFilePath.h
#pragma once
#ifndef __EXTRACTINGFILEPATH_H
#define __EXTRACTINGFILEPATH_H
#include "Common/String.h"
UString GetCorrectFileName(const UString &path);
UString GetCorrectPath(const UString &path);
#endif

42
7zip/UI/Common/HandlerLoader.h Executable file
View File

@@ -0,0 +1,42 @@
// HandlerLoader.h
#pragma once
#ifndef __HANDLERLOADER_H
#define __HANDLERLOADER_H
#include "../../ICoder.h"
#include "Windows/DLL.h"
typedef UINT32 (WINAPI * CreateObjectFunc)(
const GUID *clsID,
const GUID *interfaceID,
void **outObject);
class CHandlerLoader: public NWindows::NDLL::CLibrary
{
public:
HRESULT CreateHandler(LPCWSTR filepath, REFGUID clsID,
void **archive, bool outHandler)
{
if (!Load(filepath))
return GetLastError();
CreateObjectFunc createObject = (CreateObjectFunc)
GetProcAddress("CreateObject");
if (createObject == NULL)
{
HRESULT res = ::GetLastError();
Free();
return res;
}
HRESULT res = createObject(&clsID,
outHandler ? &IID_IOutArchive : &IID_IInArchive, (void **)archive);
if (res != 0)
Free();
return res;
}
};
#endif

171
7zip/UI/Common/OpenArchive.cpp Executable file
View File

@@ -0,0 +1,171 @@
// OpenArchive.cpp
#include "StdAfx.h"
#include "OpenArchive.h"
#include "Windows/FileName.h"
#include "Windows/FileDir.h"
#include "Windows/Defs.h"
#include "../../Common/FileStreams.h"
#include "Common/StringConvert.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 "HandlerLoader.h"
#endif
using namespace NWindows;
const UINT64 kMaxCheckStartPosition = 1 << 20;
HRESULT ReOpenArchive(IInArchive *archive,
const UString &fileName)
{
CInFileStream *inStreamSpec = new CInFileStream;
CMyComPtr<IInStream> inStream(inStreamSpec);
inStreamSpec->Open(fileName);
return archive->Open(inStream, &kMaxCheckStartPosition, NULL);
}
HRESULT OpenArchive(const UString &fileName,
#ifndef EXCLUDE_COM
HMODULE *module,
#endif
IInArchive **archiveResult,
CArchiverInfo &archiverInfoResult,
int &subExtIndex,
IArchiveOpenCallback *openArchiveCallback)
{
CInFileStream *inStreamSpec = new CInFileStream;
CMyComPtr<IInStream> inStream(inStreamSpec);
if (!inStreamSpec->Open(fileName))
return GetLastError();
*archiveResult = NULL;
CObjectVector<CArchiverInfo> archiverInfoList;
ReadArchiverInfoList(archiverInfoList);
UString extension;
{
UString name, pureName, dot;
if(!NFile::NDirectory::GetOnlyName(fileName, name))
return E_FAIL;
NFile::NName::SplitNameToPureNameAndExtension(name, pureName, dot, extension);
}
CIntVector orderIndices;
int firstArchiverIndex;
for(firstArchiverIndex = 0;
firstArchiverIndex < archiverInfoList.Size(); firstArchiverIndex++)
{
int subIndex = archiverInfoList[firstArchiverIndex].FindExtension(extension);
if (subIndex >= 0)
break;
}
if(firstArchiverIndex < archiverInfoList.Size())
orderIndices.Add(firstArchiverIndex);
for(int j = 0; j < archiverInfoList.Size(); j++)
if(j != firstArchiverIndex)
orderIndices.Add(j);
HRESULT badResult = S_OK;
for(int i = 0; i < orderIndices.Size(); i++)
{
inStreamSpec->Seek(0, STREAM_SEEK_SET, NULL);
const CArchiverInfo &archiverInfo = archiverInfoList[orderIndices[i]];
#ifndef EXCLUDE_COM
CHandlerLoader loader;
#endif
CMyComPtr<IInArchive> archive;
#ifdef FORMAT_7Z
if (archiverInfo.Name.CompareNoCase(L"7z") == 0)
archive = new NArchive::N7z::CHandler;
#endif
#ifdef FORMAT_BZIP2
if (archiverInfo.Name.CompareNoCase(L"BZip2") == 0)
archive = new NArchive::NBZip2::CHandler;
#endif
#ifdef FORMAT_GZIP
if (archiverInfo.Name.CompareNoCase(L"GZip") == 0)
archive = new NArchive::NGZip::CHandler;
#endif
#ifdef FORMAT_TAR
if (archiverInfo.Name.CompareNoCase(L"Tar") == 0)
archive = new NArchive::NTar::CHandler;
#endif
#ifdef FORMAT_ZIP
if (archiverInfo.Name.CompareNoCase(L"Zip") == 0)
archive = new NArchive::NZip::CHandler;
#endif
#ifndef EXCLUDE_COM
if (!archive)
{
HRESULT result = loader.CreateHandler(archiverInfo.FilePath,
archiverInfo.ClassID, (void **)&archive, false);
if (result != S_OK)
continue;
}
#endif EXCLUDE_COM
if (!archive)
return E_FAIL;
HRESULT result = archive->Open(inStream, &kMaxCheckStartPosition, openArchiveCallback);
if(result == S_FALSE)
continue;
if(result != S_OK)
{
badResult = result;
continue;
// return result;
}
*archiveResult = archive.Detach();
#ifndef EXCLUDE_COM
*module = loader.Detach();
#endif
archiverInfoResult = archiverInfo;
subExtIndex = archiverInfo.FindExtension(extension);
if (subExtIndex < 0)
subExtIndex = 0;
return S_OK;
}
if (badResult != S_OK)
return badResult;
return S_FALSE;
/*
#else
return S_FALSE;
#endif
#endif
*/
}

24
7zip/UI/Common/OpenArchive.h Executable file
View File

@@ -0,0 +1,24 @@
// OpenArchive.h
#ifndef __OPENARCHIVE_H
#define __OPENARCHIVE_H
#include "Common/String.h"
#include "../../Archive/IArchive.h"
#include "ArchiverInfo.h"
HRESULT OpenArchive(const UString &fileName,
#ifndef EXCLUDE_COM
HMODULE *module,
#endif
IInArchive **archive,
CArchiverInfo &archiverInfoResult,
int &subExtIndex,
IArchiveOpenCallback *openArchiveCallback);
HRESULT ReOpenArchive(IInArchive *archive,
const UString &fileName);
#endif

79
7zip/UI/Common/PropIDUtils.cpp Executable file
View File

@@ -0,0 +1,79 @@
// PropIDUtils.cpp
#include "StdAfx.h"
#include "PropIDUtils.h"
#include "Common/IntToString.h"
#include "Common/StringConvert.h"
#include "Windows/FileFind.h"
#include "Windows/PropVariantConversions.h"
#include "../../PropID.h"
using namespace NWindows;
static UString ConvertUINT32ToString(UINT32 value)
{
wchar_t buffer[32];
ConvertUINT64ToString(value, buffer);
return buffer;
}
UString ConvertPropertyToString(const PROPVARIANT &propVariant,
PROPID propID, bool full)
{
switch(propID)
{
case kpidCreationTime:
case kpidLastWriteTime:
case kpidLastAccessTime:
{
if (propVariant.vt != VT_FILETIME)
return UString(); // It is error;
FILETIME localFileTime;
if (propVariant.filetime.dwHighDateTime == 0 &&
propVariant.filetime.dwLowDateTime == 0)
return UString();
if (!::FileTimeToLocalFileTime(&propVariant.filetime, &localFileTime))
return UString(); // It is error;
return ConvertFileTimeToString2(localFileTime, true, full);
}
case kpidCRC:
{
if(propVariant.vt != VT_UI4)
break;
TCHAR temp[17];
wsprintf(temp, TEXT("%08X"), propVariant.ulVal);
return GetUnicodeString(temp);
}
case kpidAttributes:
{
if(propVariant.vt != VT_UI4)
break;
UString result;
UINT32 attributes = propVariant.ulVal;
if (NFile::NFind::NAttributes::IsReadOnly(attributes)) result += L'R';
if (NFile::NFind::NAttributes::IsHidden(attributes)) result += L'H';
if (NFile::NFind::NAttributes::IsSystem(attributes)) result += L'S';
if (NFile::NFind::NAttributes::IsDirectory(attributes)) result += L'D';
if (NFile::NFind::NAttributes::IsArchived(attributes)) result += L'A';
if (NFile::NFind::NAttributes::IsCompressed(attributes)) result += L'C';
if (NFile::NFind::NAttributes::IsEncrypted(attributes)) result += L'E';
return result;
}
case kpidDictionarySize:
{
if(propVariant.vt != VT_UI4)
break;
UINT32 size = propVariant.ulVal;
if (size % (1 << 20) == 0)
return ConvertUINT32ToString(size >> 20) + L"MB";
if (size % (1 << 10) == 0)
return ConvertUINT32ToString(size >> 10) + L"KB";
return ConvertUINT32ToString(size);
}
}
return ConvertPropVariantToString(propVariant);
}

13
7zip/UI/Common/PropIDUtils.h Executable file
View File

@@ -0,0 +1,13 @@
// PropIDUtils.h
#pragma once
#ifndef __PROPIDUTILS_H
#define __PROPIDUTILS_H
#include "Common/String.h"
UString ConvertPropertyToString(const PROPVARIANT &aPropVariant,
PROPID aPropID, bool aFull = true);
#endif

30
7zip/UI/Common/SortUtils.cpp Executable file
View File

@@ -0,0 +1,30 @@
// SortUtils.cpp
#include "StdAfx.h"
#include "SortUtils.h"
static int __cdecl CompareStrings(const void *a1, const void *a2)
{
const UString &s1 = *(*(*((const UString ***)a1)));
const UString &s2 = *(*(*((const UString ***)a2)));
return s1.CompareNoCase(s2);
}
void SortStringsToIndices(UStringVector &strings, CIntVector &indices)
{
indices.Clear();
if (strings.IsEmpty())
return;
int numItems = strings.Size();
CPointerVector pointers;
pointers.Reserve(numItems);
indices.Reserve(numItems);
int i;
for(i = 0; i < numItems; i++)
pointers.Add(&strings.CPointerVector::operator[](i));
void **stringsBase = (void **)pointers[0];
qsort(&pointers[0], numItems, sizeof(void *), CompareStrings);
for(i = 0; i < numItems; i++)
indices.Add((void **)pointers[i] - stringsBase);
}

12
7zip/UI/Common/SortUtils.h Executable file
View File

@@ -0,0 +1,12 @@
// SortUtils.h
#pragma once
#ifndef __SORTUTLS_H
#define __SORTUTLS_H
#include "Common/String.h"
void SortStringsToIndices(UStringVector &strings, CIntVector &indices);
#endif

8
7zip/UI/Common/StdAfx.h Executable file
View File

@@ -0,0 +1,8 @@
// stdafx.h
#ifndef __STDAFX_H
#define __STDAFX_H
#include <windows.h>
#endif

64
7zip/UI/Common/UpdateAction.cpp Executable file
View File

@@ -0,0 +1,64 @@
// UpdateAction.cpp
#include "StdAfx.h"
#include "UpdateAction.h"
namespace NUpdateArchive {
const CActionSet kAddActionSet =
{
NPairAction::kCopy,
NPairAction::kCopy,
NPairAction::kCompress,
NPairAction::kCompress,
NPairAction::kCompress,
NPairAction::kCompress,
NPairAction::kCompress
};
const CActionSet kUpdateActionSet =
{
NPairAction::kCopy,
NPairAction::kCopy,
NPairAction::kCompress,
NPairAction::kCopy,
NPairAction::kCompress,
NPairAction::kCopy,
NPairAction::kCompress
};
const CActionSet kFreshActionSet =
{
NPairAction::kCopy,
NPairAction::kCopy,
NPairAction::kIgnore,
NPairAction::kCopy,
NPairAction::kCompress,
NPairAction::kCopy,
NPairAction::kCompress
};
const CActionSet kSynchronizeActionSet =
{
NPairAction::kCopy,
NPairAction::kIgnore,
NPairAction::kCompress,
NPairAction::kCopy,
NPairAction::kCompress,
NPairAction::kCopy,
NPairAction::kCompress,
};
const CActionSet kDeleteActionSet =
{
NPairAction::kCopy,
NPairAction::kIgnore,
NPairAction::kIgnore,
NPairAction::kIgnore,
NPairAction::kIgnore,
NPairAction::kIgnore,
NPairAction::kIgnore
};
}

48
7zip/UI/Common/UpdateAction.h Executable file
View File

@@ -0,0 +1,48 @@
// UpdateAction.h
#pragma once
#ifndef __UPDATE_ACTION_H
#define __UPDATE_ACTION_H
namespace NUpdateArchive {
namespace NPairState
{
const int kNumValues = 7;
enum EEnum
{
kNotMasked = 0,
kOnlyInArchive,
kOnlyOnDisk,
kNewInArchive,
kOldInArchive,
kSameFiles,
kUnknowNewerFiles
};
}
namespace NPairAction
{
enum EEnum
{
kIgnore = 0,
kCopy,
kCompress,
kCompressAsAnti
};
}
struct CActionSet
{
NPairAction::EEnum StateActions[NPairState::kNumValues];
};
extern const CActionSet kAddActionSet;
extern const CActionSet kUpdateActionSet;
extern const CActionSet kFreshActionSet;
extern const CActionSet kSynchronizeActionSet;
extern const CActionSet kDeleteActionSet;
};
#endif

157
7zip/UI/Common/UpdatePair.cpp Executable file
View File

@@ -0,0 +1,157 @@
// UpdatePair.cpp
#include "StdAfx.h"
#include <time.h>
#include "Common/Defs.h"
#include "Windows/Time.h"
#include "UpdatePair.h"
#include "SortUtils.h"
using namespace NWindows;
// using namespace NCOM;
using namespace NTime;
static int MyCompareTime(NFileTimeType::EEnum fileTimeType,
const FILETIME &time1, const FILETIME &time2)
{
switch(fileTimeType)
{
case NFileTimeType::kWindows:
return ::CompareFileTime(&time1, &time2);
case NFileTimeType::kUnix:
{
time_t unixTime1, unixTime2;
if (!FileTimeToUnixTime(time1, unixTime1))
throw 4191614;
if (!FileTimeToUnixTime(time2, unixTime2))
throw 4191615;
return MyCompare(unixTime1, unixTime2);
}
case NFileTimeType::kDOS:
{
UINT32 dosTime1, dosTime2;
if (!FileTimeToDosTime(time1, dosTime1))
throw 4191616;
if (!FileTimeToDosTime(time2, dosTime2))
throw 4191617;
return MyCompare(dosTime1, dosTime2);
}
}
throw 4191618;
}
static const wchar_t *kDuplicateFileNameMessage = L"Duplicate filename:";
/*
static const char *kNotCensoredCollisionMessaged = "Internal file name collision:\n";
static const char *kSameTimeChangedSizeCollisionMessaged =
"Collision between files with same date/time and different sizes:\n";
*/
static void TestDuplicateString(const UStringVector &strings,
const CIntVector &indices)
{
for(int i = 0; i + 1 < indices.Size(); i++)
if (strings[indices[i]].CollateNoCase(strings[indices[i + 1]]) == 0)
{
UString message = kDuplicateFileNameMessage;
message += L"\n";
message += strings[indices[i]];
message += L"\n";
message += strings[indices[i+1]];
throw message;
}
}
void GetUpdatePairInfoList(
const CObjectVector<CDirItem> &dirItems,
const CObjectVector<CArchiveItem> &archiveItems,
NFileTimeType::EEnum fileTimeType,
CObjectVector<CUpdatePair> &updatePairs)
{
CIntVector dirIndices, archiveIndices;
UStringVector dirNames, archiveNames;
int numDirItems = dirItems.Size();
int i;
for(i = 0; i < numDirItems; i++)
dirNames.Add(dirItems[i].Name);
SortStringsToIndices(dirNames, dirIndices);
TestDuplicateString(dirNames, dirIndices);
int numArchiveItems = archiveItems.Size();
for(i = 0; i < numArchiveItems; i++)
archiveNames.Add(archiveItems[i].Name);
SortStringsToIndices(archiveNames, archiveIndices);
TestDuplicateString(archiveNames, archiveIndices);
int dirItemIndex = 0, archiveItemIndex = 0;
CUpdatePair pair;
while(dirItemIndex < numDirItems && archiveItemIndex < numArchiveItems)
{
int dirItemIndex2 = dirIndices[dirItemIndex],
archiveItemIndex2 = archiveIndices[archiveItemIndex];
const CDirItem &dirItem = dirItems[dirItemIndex2];
const CArchiveItem &archiveItem = archiveItems[archiveItemIndex2];
int compareResult = dirItem.Name.CollateNoCase(archiveItem.Name);
if (compareResult < 0)
{
pair.State = NUpdateArchive::NPairState::kOnlyOnDisk;
pair.DirItemIndex = dirItemIndex2;
dirItemIndex++;
}
else if (compareResult > 0)
{
pair.State = archiveItem.Censored ?
NUpdateArchive::NPairState::kOnlyInArchive: NUpdateArchive::NPairState::kNotMasked;
pair.ArchiveItemIndex = archiveItemIndex2;
archiveItemIndex++;
}
else
{
if (!archiveItem.Censored)
throw 1082022;; // TTString(kNotCensoredCollisionMessaged + dirItem.Name);
pair.DirItemIndex = dirItemIndex2;
pair.ArchiveItemIndex = archiveItemIndex2;
switch (MyCompareTime(fileTimeType, dirItem.LastWriteTime, archiveItem.LastWriteTime))
{
case -1:
pair.State = NUpdateArchive::NPairState::kNewInArchive;
break;
case 1:
pair.State = NUpdateArchive::NPairState::kOldInArchive;
break;
default:
if (archiveItem.SizeIsDefined)
if (dirItem.Size != archiveItem.Size)
// throw 1082034; // kSameTimeChangedSizeCollisionMessaged;
pair.State = NUpdateArchive::NPairState::kUnknowNewerFiles;
else
pair.State = NUpdateArchive::NPairState::kSameFiles;
else
pair.State = NUpdateArchive::NPairState::kUnknowNewerFiles;
}
dirItemIndex++;
archiveItemIndex++;
}
updatePairs.Add(pair);
}
for(;dirItemIndex < numDirItems; dirItemIndex++)
{
pair.State = NUpdateArchive::NPairState::kOnlyOnDisk;
pair.DirItemIndex = dirIndices[dirItemIndex];
updatePairs.Add(pair);
}
for(;archiveItemIndex < numArchiveItems; archiveItemIndex++)
{
int archiveItemIndex2 = archiveIndices[archiveItemIndex];
const CArchiveItem &archiveItem = archiveItems[archiveItemIndex2];
pair.State = archiveItem.Censored ?
NUpdateArchive::NPairState::kOnlyInArchive: NUpdateArchive::NPairState::kNotMasked;
pair.ArchiveItemIndex = archiveItemIndex2;
updatePairs.Add(pair);
}
}

26
7zip/UI/Common/UpdatePair.h Executable file
View File

@@ -0,0 +1,26 @@
// UpdatePair.h
#pragma once
#ifndef __UPDATEPAIR_H
#define __UPDATEPAIR_H
#include "DirItem.h"
#include "UpdateAction.h"
#include "../../Archive/IArchive.h"
struct CUpdatePair
{
NUpdateArchive::NPairState::EEnum State;
int ArchiveItemIndex;
int DirItemIndex;
};
void GetUpdatePairInfoList(
const CObjectVector<CDirItem> &dirItems,
const CObjectVector<CArchiveItem> &archiveItems,
NFileTimeType::EEnum fileTimeType,
CObjectVector<CUpdatePair> &updatePairs);
#endif

View File

@@ -0,0 +1,65 @@
// UpdateProduce.cpp
#include "StdAfx.h"
#include "UpdateProduce.h"
using namespace NUpdateArchive;
static const char *kUpdateActionSetCollision =
"Internal collision in update action set";
void UpdateProduce(
const CObjectVector<CDirItem> &dirItems,
const CObjectVector<CArchiveItem> &archiveItems,
const CObjectVector<CUpdatePair> &updatePairs,
const NUpdateArchive::CActionSet &actionSet,
CObjectVector<CUpdatePair2> &operationChain)
{
for(int i = 0; i < updatePairs.Size(); i++)
{
// CUpdateArchiveRange aRange;
const CUpdatePair &pair = updatePairs[i];
CUpdatePair2 pair2;
pair2.IsAnti = false;
pair2.ArchiveItemIndex = pair.ArchiveItemIndex;
pair2.DirItemIndex = pair.DirItemIndex;
pair2.ExistInArchive = (pair.State != NPairState::kOnlyOnDisk);
pair2.ExistOnDisk = (pair.State != NPairState::kOnlyInArchive);
switch(actionSet.StateActions[pair.State])
{
case NPairAction::kIgnore:
/*
if (pair.State != NPairState::kOnlyOnDisk)
IgnoreArchiveItem(m_ArchiveItems[pair.ArchiveItemIndex]);
// cout << "deleting";
*/
break;
case NPairAction::kCopy:
{
if (pair.State == NPairState::kOnlyOnDisk)
throw kUpdateActionSetCollision;
pair2.NewData = pair2.NewProperties = false;
operationChain.Add(pair2);
break;
}
case NPairAction::kCompress:
{
if (pair.State == NPairState::kOnlyInArchive ||
pair.State == NPairState::kNotMasked)
throw kUpdateActionSetCollision;
pair2.NewData = pair2.NewProperties = true;
operationChain.Add(pair2);
break;
}
case NPairAction::kCompressAsAnti:
{
pair2.IsAnti = true;
pair2.NewData = pair2.NewProperties = true;
operationChain.Add(pair2);
break;
}
}
}
}

35
7zip/UI/Common/UpdateProduce.h Executable file
View File

@@ -0,0 +1,35 @@
// UpdateProduce.h
#pragma once
#ifndef __UPDATEPRODUCE_H
#define __UPDATEPRODUCE_H
#include "UpdatePair.h"
struct CUpdatePair2
{
// bool OperationIsCompress;
bool NewData;
bool NewProperties;
bool ExistInArchive;
bool ExistOnDisk;
bool IsAnti;
int ArchiveItemIndex;
int DirItemIndex;
bool NewNameIsDefined;
UString NewName;
CUpdatePair2(): NewNameIsDefined(false) {}
};
void UpdateProduce(
const CObjectVector<CDirItem> &dirItems,
const CObjectVector<CArchiveItem> &archiveItems,
const CObjectVector<CUpdatePair> &updatePairs,
const NUpdateArchive::CActionSet &actionSet,
CObjectVector<CUpdatePair2> &operationChain);
#endif

73
7zip/UI/Common/WorkDir.cpp Executable file
View File

@@ -0,0 +1,73 @@
// WorkDir.cpp
#include "StdAfx.h"
#include "WorkDir.h"
#include "Common/StringConvert.h"
#include "Windows/FileName.h"
#include "Windows/FileDir.h"
static inline UINT GetCurrentCodePage()
{ return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }
using namespace NWindows;
using namespace NFile;
using namespace NName;
static UString GetContainingDir(const UString &path)
{
UString resultPath;
int pos;
if(!NFile::NDirectory::MyGetFullPathName(path, resultPath, pos))
throw 141716;
return resultPath.Left(pos);
}
UString GetWorkDir(const NWorkDir::CInfo &workDirInfo,
const UString &archiveName)
{
NWorkDir::NMode::EEnum mode = workDirInfo.Mode;
if (workDirInfo.ForRemovableOnly)
{
mode = NWorkDir::NMode::kCurrent;
UString prefix = archiveName.Left(3);
if (prefix[1] == L':' && prefix[2] == L'\\')
{
UINT driveType = GetDriveType(GetSystemString(prefix, GetCurrentCodePage()));
if (driveType == DRIVE_CDROM || driveType == DRIVE_REMOVABLE)
mode = workDirInfo.Mode;
}
/*
CParsedPath parsedPath;
parsedPath.ParsePath(archiveName);
UINT driveType = GetDriveType(parsedPath.Prefix);
if ((driveType != DRIVE_CDROM) && (driveType != DRIVE_REMOVABLE))
mode = NZipSettings::NWorkDir::NMode::kCurrent;
*/
}
switch(mode)
{
case NWorkDir::NMode::kCurrent:
{
return GetContainingDir(archiveName);
}
case NWorkDir::NMode::kSpecified:
{
UString tempDir = workDirInfo.Path;
NormalizeDirPathPrefix(tempDir);
return tempDir;
}
default: // NZipSettings::NWorkDir::NMode::kSystem:
{
UString tempDir;
if(!NFile::NDirectory::MyGetTempPath(tempDir))
throw 141717;
return tempDir;
}
}
}

14
7zip/UI/Common/WorkDir.h Executable file
View File

@@ -0,0 +1,14 @@
// WorkDir.h
#pragma once
#ifndef __WORKDIR_H
#define __WORKDIR_H
#include "../Common/ZipRegistry.h"
UString GetWorkDir(const NWorkDir::CInfo &workDirInfo,
const UString &archiveName);
#endif

404
7zip/UI/Common/ZipRegistry.cpp Executable file
View File

@@ -0,0 +1,404 @@
// ZipRegistry.cpp
#include "StdAfx.h"
#include "ZipRegistry.h"
#include "Common/IntToString.h"
#include "Common/StringConvert.h"
#include "Windows/Synchronization.h"
#include "Windows/Registry.h"
#include "Windows/FileDir.h"
using namespace NWindows;
using namespace NRegistry;
static const TCHAR *kCUBasePath = TEXT("Software\\7-ZIP");
// static const TCHAR *kArchiversKeyName = TEXT("Archivers");
static NSynchronization::CCriticalSection g_RegistryOperationsCriticalSection;
//////////////////////
// ExtractionInfo
static const TCHAR *kExtractionKeyName = TEXT("Extraction");
static const TCHAR *kExtractionPathHistoryKeyName = TEXT("PathHistory");
static const TCHAR *kExtractionExtractModeValueName = TEXT("ExtarctMode");
static const TCHAR *kExtractionOverwriteModeValueName = TEXT("OverwriteMode");
static const TCHAR *kExtractionShowPasswordValueName = TEXT("ShowPassword");
static CSysString GetKeyPath(const CSysString &path)
{
return CSysString(kCUBasePath) + CSysString('\\') + CSysString(path);
}
void SaveExtractionInfo(const NExtraction::CInfo &info)
{
NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection);
CKey extractionKey;
extractionKey.Create(HKEY_CURRENT_USER, GetKeyPath(kExtractionKeyName));
extractionKey.RecurseDeleteKey(kExtractionPathHistoryKeyName);
{
CKey pathHistoryKey;
pathHistoryKey.Create(extractionKey, kExtractionPathHistoryKeyName);
for(int i = 0; i < info.Paths.Size(); i++)
{
TCHAR numberString[16];
ConvertUINT64ToString(i, numberString);
pathHistoryKey.SetValue(numberString, info.Paths[i]);
}
}
extractionKey.SetValue(kExtractionExtractModeValueName, UINT32(info.PathMode));
extractionKey.SetValue(kExtractionOverwriteModeValueName, UINT32(info.OverwriteMode));
extractionKey.SetValue(kExtractionShowPasswordValueName, info.ShowPassword);
}
void ReadExtractionInfo(NExtraction::CInfo &info)
{
info.Paths.Clear();
info.PathMode = NExtraction::NPathMode::kFullPathnames;
info.OverwriteMode = NExtraction::NOverwriteMode::kAskBefore;
info.ShowPassword = false;
NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection);
CKey extractionKey;
if(extractionKey.Open(HKEY_CURRENT_USER, GetKeyPath(kExtractionKeyName), KEY_READ) != ERROR_SUCCESS)
return;
{
CKey pathHistoryKey;
if(pathHistoryKey.Open(extractionKey, kExtractionPathHistoryKeyName, KEY_READ) ==
ERROR_SUCCESS)
{
while(true)
{
TCHAR numberString[16];
ConvertUINT64ToString(info.Paths.Size(), numberString);
CSysString path;
if (pathHistoryKey.QueryValue(numberString, path) != ERROR_SUCCESS)
break;
info.Paths.Add(path);
}
}
}
UINT32 extractModeIndex;
if (extractionKey.QueryValue(kExtractionExtractModeValueName, extractModeIndex) == ERROR_SUCCESS)
{
switch (extractModeIndex)
{
case NExtraction::NPathMode::kFullPathnames:
case NExtraction::NPathMode::kCurrentPathnames:
case NExtraction::NPathMode::kNoPathnames:
info.PathMode = NExtraction::NPathMode::EEnum(extractModeIndex);
break;
}
}
UINT32 overwriteModeIndex;
if (extractionKey.QueryValue(kExtractionOverwriteModeValueName, overwriteModeIndex) == ERROR_SUCCESS)
{
switch (overwriteModeIndex)
{
case NExtraction::NOverwriteMode::kAskBefore:
case NExtraction::NOverwriteMode::kWithoutPrompt:
case NExtraction::NOverwriteMode::kSkipExisting:
case NExtraction::NOverwriteMode::kAutoRename:
case NExtraction::NOverwriteMode::kAutoRenameExisting:
info.OverwriteMode = NExtraction::NOverwriteMode::EEnum(overwriteModeIndex);
break;
}
}
if (extractionKey.QueryValue(kExtractionShowPasswordValueName,
info.ShowPassword) != ERROR_SUCCESS)
info.ShowPassword = false;
}
///////////////////////////////////
// CompressionInfo
static const TCHAR *kCompressionKeyName = TEXT("Compression");
static const TCHAR *kCompressionHistoryArchivesKeyName = TEXT("ArcHistory");
static const TCHAR *kCompressionLevelValueName = TEXT("Level");
static const TCHAR *kCompressionLastFormatValueName = TEXT("Archiver");
static const TCHAR *kCompressionShowPasswordValueName = TEXT("ShowPassword");
static const TCHAR *kCompressionEncryptHeadersValueName = TEXT("EncryptHeaders");
// static const TCHAR *kCompressionMaximizeValueName = TEXT("Maximize");
static const TCHAR *kCompressionOptionsKeyName = TEXT("Options");
static const TCHAR *kSolid = TEXT("Solid");
static const TCHAR *kMultiThread = TEXT("Multithread");
static const TCHAR *kCompressionOptions = TEXT("Options");
static const TCHAR *kCompressionLevel = TEXT("Level");
static const TCHAR *kCompressionMethod = TEXT("Method");
static const TCHAR *kCompressionDictionary = TEXT("Dictionary");
static const TCHAR *kCompressionOrder = TEXT("Order");
void SaveCompressionInfo(const NCompression::CInfo &info)
{
NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection);
CKey compressionKey;
compressionKey.Create(HKEY_CURRENT_USER, GetKeyPath(kCompressionKeyName));
compressionKey.RecurseDeleteKey(kCompressionHistoryArchivesKeyName);
{
CKey historyArchivesKey;
historyArchivesKey.Create(compressionKey, kCompressionHistoryArchivesKeyName);
for(int i = 0; i < info.HistoryArchives.Size(); i++)
{
TCHAR numberString[16];
ConvertUINT64ToString(i, numberString);
historyArchivesKey.SetValue(numberString, info.HistoryArchives[i]);
}
}
compressionKey.SetValue(kSolid, info.Solid);
compressionKey.SetValue(kMultiThread, info.MultiThread);
compressionKey.RecurseDeleteKey(kCompressionOptionsKeyName);
{
CKey optionsKey;
optionsKey.Create(compressionKey, kCompressionOptionsKeyName);
for(int i = 0; i < info.FormatOptionsVector.Size(); i++)
{
const NCompression::CFormatOptions &fo = info.FormatOptionsVector[i];
CKey formatKey;
formatKey.Create(optionsKey, fo.FormatID);
if (fo.Options.IsEmpty())
formatKey.DeleteValue(kCompressionOptions);
else
formatKey.SetValue(kCompressionOptions, fo.Options);
if (fo.Level == UINT32(-1))
formatKey.DeleteValue(kCompressionLevel);
else
formatKey.SetValue(kCompressionLevel, fo.Level);
if (fo.Method.IsEmpty())
formatKey.DeleteValue(kCompressionMethod);
else
formatKey.SetValue(kCompressionMethod, fo.Method);
if (fo.Dictionary == UINT32(-1))
formatKey.DeleteValue(kCompressionDictionary);
else
formatKey.SetValue(kCompressionDictionary, fo.Dictionary);
if (fo.Order == UINT32(-1))
formatKey.DeleteValue(kCompressionOrder);
else
formatKey.SetValue(kCompressionOrder, fo.Order);
}
}
compressionKey.SetValue(kCompressionLevelValueName, UINT32(info.Level));
compressionKey.SetValue(kCompressionLastFormatValueName,
GetSystemString(info.ArchiveType));
compressionKey.SetValue(kCompressionShowPasswordValueName, info.ShowPassword);
compressionKey.SetValue(kCompressionEncryptHeadersValueName, info.EncryptHeaders);
// compressionKey.SetValue(kCompressionMaximizeValueName, info.Maximize);
}
static bool IsMultiProcessor()
{
SYSTEM_INFO systemInfo;
GetSystemInfo(&systemInfo);
return systemInfo.dwNumberOfProcessors > 1;
}
void ReadCompressionInfo(NCompression::CInfo &info)
{
info.HistoryArchives.Clear();
info.Solid = true;
info.MultiThread = IsMultiProcessor();
info.FormatOptionsVector.Clear();
info.Level = 5;
info.ArchiveType = L"7z";
// definedStatus.Maximize = false;
info.ShowPassword = false;
info.EncryptHeaders = false;
NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection);
CKey compressionKey;
if(compressionKey.Open(HKEY_CURRENT_USER,
GetKeyPath(kCompressionKeyName), KEY_READ) != ERROR_SUCCESS)
return;
{
CKey historyArchivesKey;
if(historyArchivesKey.Open(compressionKey, kCompressionHistoryArchivesKeyName, KEY_READ) ==
ERROR_SUCCESS)
{
while(true)
{
TCHAR numberString[16];
ConvertUINT64ToString(info.HistoryArchives.Size(), numberString);
CSysString path;
if (historyArchivesKey.QueryValue(numberString, path) != ERROR_SUCCESS)
break;
info.HistoryArchives.Add(path);
}
}
}
bool solid = false;
if (compressionKey.QueryValue(kSolid, solid) == ERROR_SUCCESS)
info.Solid = solid;
bool multiThread = false;
if (compressionKey.QueryValue(kMultiThread, multiThread) == ERROR_SUCCESS)
info.MultiThread = multiThread;
{
CKey optionsKey;
if(optionsKey.Open(compressionKey, kCompressionOptionsKeyName, KEY_READ) ==
ERROR_SUCCESS)
{
CSysStringVector formatIDs;
optionsKey.EnumKeys(formatIDs);
for(int i = 0; i < formatIDs.Size(); i++)
{
CKey formatKey;
NCompression::CFormatOptions fo;
fo.FormatID = formatIDs[i];
if(formatKey.Open(optionsKey, fo.FormatID, KEY_READ) == ERROR_SUCCESS)
{
if (formatKey.QueryValue(kCompressionOptions, fo.Options) != ERROR_SUCCESS)
fo.Options.Empty();
if (formatKey.QueryValue(kCompressionLevel, fo.Level) != ERROR_SUCCESS)
fo.Level = UINT32(-1);
if (formatKey.QueryValue(kCompressionMethod, fo.Method) != ERROR_SUCCESS)
fo.Method.Empty();;
if (formatKey.QueryValue(kCompressionDictionary, fo.Dictionary) != ERROR_SUCCESS)
fo.Dictionary = UINT32(-1);
if (formatKey.QueryValue(kCompressionOrder, fo.Order) != ERROR_SUCCESS)
fo.Order = UINT32(-1);
info.FormatOptionsVector.Add(fo);
}
}
}
}
UINT32 level;
if (compressionKey.QueryValue(kCompressionLevelValueName, level) == ERROR_SUCCESS)
info.Level = level;
CSysString archiveType;
if (compressionKey.QueryValue(kCompressionLastFormatValueName, archiveType) == ERROR_SUCCESS)
info.ArchiveType = GetUnicodeString(archiveType);
if (compressionKey.QueryValue(kCompressionShowPasswordValueName,
info.ShowPassword) != ERROR_SUCCESS)
info.ShowPassword = false;
if (compressionKey.QueryValue(kCompressionEncryptHeadersValueName,
info.EncryptHeaders) != ERROR_SUCCESS)
info.EncryptHeaders = false;
/*
if (compressionKey.QueryValue(kCompressionLevelValueName, info.Maximize) == ERROR_SUCCESS)
definedStatus.Maximize = true;
*/
}
///////////////////////////////////
// WorkDirInfo
static const TCHAR *kOptionsInfoKeyName = TEXT("Options");
static const TCHAR *kWorkDirTypeValueName = TEXT("WorkDirType");
static const TCHAR *kWorkDirPathValueName = TEXT("WorkDirPath");
static const TCHAR *kTempRemovableOnlyValueName = TEXT("TempRemovableOnly");
static const TCHAR *kCascadedMenuValueName = TEXT("CascadedMenu");
static const TCHAR *kContextMenuValueName = TEXT("ContextMenu");
void SaveWorkDirInfo(const NWorkDir::CInfo &info)
{
NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection);
CKey optionsKey;
optionsKey.Create(HKEY_CURRENT_USER, GetKeyPath(kOptionsInfoKeyName));
optionsKey.SetValue(kWorkDirTypeValueName, UINT32(info.Mode));
optionsKey.SetValue(kWorkDirPathValueName, GetSystemString(info.Path));
optionsKey.SetValue(kTempRemovableOnlyValueName, info.ForRemovableOnly);
}
void ReadWorkDirInfo(NWorkDir::CInfo &info)
{
info.SetDefault();
NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection);
CKey optionsKey;
if(optionsKey.Open(HKEY_CURRENT_USER, GetKeyPath(kOptionsInfoKeyName), KEY_READ) != ERROR_SUCCESS)
return;
UINT32 dirType;
if (optionsKey.QueryValue(kWorkDirTypeValueName, dirType) != ERROR_SUCCESS)
return;
switch (dirType)
{
case NWorkDir::NMode::kSystem:
case NWorkDir::NMode::kCurrent:
case NWorkDir::NMode::kSpecified:
info.Mode = NWorkDir::NMode::EEnum(dirType);
}
CSysString sysWorkDir;
if (optionsKey.QueryValue(kWorkDirPathValueName, sysWorkDir) != ERROR_SUCCESS)
{
info.Path.Empty();
if (info.Mode == NWorkDir::NMode::kSpecified)
info.Mode = NWorkDir::NMode::kSystem;
}
info.Path = GetUnicodeString(sysWorkDir);
if (optionsKey.QueryValue(kTempRemovableOnlyValueName, info.ForRemovableOnly) != ERROR_SUCCESS)
info.SetForRemovableOnlyDefault();
}
static void SaveOption(const TCHAR *value, bool enabled)
{
NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection);
CKey optionsKey;
optionsKey.Create(HKEY_CURRENT_USER, GetKeyPath(kOptionsInfoKeyName));
optionsKey.SetValue(value, enabled);
}
static bool ReadOption(const TCHAR *value, bool defaultValue)
{
NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection);
CKey optionsKey;
if(optionsKey.Open(HKEY_CURRENT_USER, GetKeyPath(kOptionsInfoKeyName), KEY_READ) != ERROR_SUCCESS)
return defaultValue;
bool enabled;
if (optionsKey.QueryValue(value, enabled) != ERROR_SUCCESS)
return defaultValue;
return enabled;
}
void SaveCascadedMenu(bool show)
{ SaveOption(kCascadedMenuValueName, show); }
bool ReadCascadedMenu()
{ return ReadOption(kCascadedMenuValueName, false); }
static void SaveValue(const TCHAR *value, UINT32 valueToWrite)
{
NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection);
CKey optionsKey;
optionsKey.Create(HKEY_CURRENT_USER, GetKeyPath(kOptionsInfoKeyName));
optionsKey.SetValue(value, valueToWrite);
}
static bool ReadValue(const TCHAR *value, UINT32 &result)
{
NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection);
CKey optionsKey;
if(optionsKey.Open(HKEY_CURRENT_USER, GetKeyPath(kOptionsInfoKeyName), KEY_READ) != ERROR_SUCCESS)
return false;
return (optionsKey.QueryValue(value, result) == ERROR_SUCCESS);
}
void SaveContextMenuStatus(UINT32 value)
{ SaveValue(kContextMenuValueName, value); }
bool ReadContextMenuStatus(UINT32 &value)
{ return ReadValue(kContextMenuValueName, value); }

119
7zip/UI/Common/ZipRegistry.h Executable file
View File

@@ -0,0 +1,119 @@
// ZipRegistry.h
#pragma once
#ifndef __ZIPREGISTRY_H
#define __ZIPREGISTRY_H
#include "Common/String.h"
namespace NExtraction {
namespace NPathMode
{
enum EEnum
{
kFullPathnames,
kCurrentPathnames,
kNoPathnames
};
}
namespace NOverwriteMode
{
enum EEnum
{
kAskBefore,
kWithoutPrompt,
kSkipExisting,
kAutoRename,
kAutoRenameExisting
};
}
struct CInfo
{
NPathMode::EEnum PathMode;
NOverwriteMode::EEnum OverwriteMode;
CSysStringVector Paths;
bool ShowPassword;
};
}
namespace NCompression {
struct CFormatOptions
{
CSysString FormatID;
CSysString Options;
UINT32 Level;
CSysString Method;
UINT32 Dictionary;
UINT32 Order;
void Init()
{
Level = Dictionary = Order = UINT32(-1);
Method.Empty();
// Options.Empty();
}
CFormatOptions() { Init(); }
};
struct CInfo
{
CSysStringVector HistoryArchives;
// bool LevelIsDefined;
UINT32 Level;
UString ArchiveType;
bool Solid;
bool MultiThread;
CObjectVector<CFormatOptions> FormatOptionsVector;
bool ShowPassword;
bool EncryptHeaders;
};
}
namespace NWorkDir{
namespace NMode
{
enum EEnum
{
kSystem,
kCurrent,
kSpecified
};
}
struct CInfo
{
NMode::EEnum Mode;
UString Path;
bool ForRemovableOnly;
void SetForRemovableOnlyDefault() { ForRemovableOnly = true; }
void SetDefault()
{
Mode = NMode::kSystem;
Path.Empty();
SetForRemovableOnlyDefault();
}
};
}
void SaveExtractionInfo(const NExtraction::CInfo &info);
void ReadExtractionInfo(NExtraction::CInfo &info);
void SaveCompressionInfo(const NCompression::CInfo &info);
void ReadCompressionInfo(NCompression::CInfo &info);
void SaveWorkDirInfo(const NWorkDir::CInfo &info);
void ReadWorkDirInfo(NWorkDir::CInfo &info);
void SaveCascadedMenu(bool enabled);
bool ReadCascadedMenu();
void SaveContextMenuStatus(UINT32 value);
bool ReadContextMenuStatus(UINT32 &value);
#endif

64
7zip/UI/Console/ArError.h Executable file
View File

@@ -0,0 +1,64 @@
// 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

View File

@@ -0,0 +1,28 @@
// 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

581
7zip/UI/Console/Console.dsp Executable file
View File

@@ -0,0 +1,581 @@
# Microsoft Developer Studio Project File - Name="Console" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=Console - Win32 DebugU
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "Console.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "Console.mak" CFG="Console - Win32 DebugU"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "Console - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "Console - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE "Console - Win32 ReleaseU" (based on "Win32 (x86) Console Application")
!MESSAGE "Console - Win32 DebugU" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "Console - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I "../../../" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"StdAfx.h" /FD /c
# ADD BASE RSC /l 0x419 /d "NDEBUG"
# ADD RSC /l 0x419 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"C:\UTIL\7z.exe"
!ELSEIF "$(CFG)" == "Console - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /Gz /W3 /Gm /GX /ZI /Od /I "../../../" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"StdAfx.h" /FD /GZ /c
# ADD BASE RSC /l 0x419 /d "_DEBUG"
# ADD RSC /l 0x419 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"C:\UTIL\7z.exe" /pdbtype:sept
!ELSEIF "$(CFG)" == "Console - Win32 ReleaseU"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Console___Win32_ReleaseU"
# PROP BASE Intermediate_Dir "Console___Win32_ReleaseU"
# PROP BASE Ignore_Export_Lib 0
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "ReleaseU"
# PROP Intermediate_Dir "ReleaseU"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /Gz /MD /W3 /GX /O1 /I "../../../" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"StdAfx.h" /FD /c
# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I "../../../" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Yu"StdAfx.h" /FD /c
# ADD BASE RSC /l 0x419 /d "NDEBUG"
# ADD RSC /l 0x419 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"C:\UTIL\7z.exe"
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"C:\UTIL\7zn.exe"
!ELSEIF "$(CFG)" == "Console - Win32 DebugU"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Console___Win32_DebugU"
# PROP BASE Intermediate_Dir "Console___Win32_DebugU"
# PROP BASE Ignore_Export_Lib 0
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "DebugU"
# PROP Intermediate_Dir "DebugU"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /Gz /W3 /Gm /GX /ZI /Od /I "../../../" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"StdAfx.h" /FD /GZ /c
# ADD CPP /nologo /Gz /W3 /Gm /GX /ZI /Od /I "../../../" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Yu"StdAfx.h" /FD /GZ /c
# ADD BASE RSC /l 0x419 /d "_DEBUG"
# ADD RSC /l 0x419 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"C:\UTIL\7z.exe" /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"C:\UTIL\7z.exe" /pdbtype:sept
!ENDIF
# Begin Target
# Name "Console - Win32 Release"
# Name "Console - Win32 Debug"
# Name "Console - Win32 ReleaseU"
# Name "Console - Win32 DebugU"
# Begin Group "Spec"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\resource.rc
# End Source File
# Begin Source File
SOURCE=.\StdAfx.cpp
# ADD CPP /Yc"StdAfx.h"
# End Source File
# Begin Source File
SOURCE=.\StdAfx.h
# End Source File
# End Group
# Begin Group "Console"
# 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
SOURCE=.\ConsoleClose.h
# End Source File
# Begin Source File
SOURCE=.\Extract.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
# End Source File
# Begin Source File
SOURCE=.\List.cpp
# End Source File
# Begin Source File
SOURCE=.\List.h
# End Source File
# Begin Source File
SOURCE=.\Main.cpp
# End Source File
# Begin Source File
SOURCE=.\MainAr.cpp
# End Source File
# Begin Source File
SOURCE=.\OpenCallback.cpp
# End Source File
# Begin Source File
SOURCE=.\OpenCallback.h
# End Source File
# Begin Source File
SOURCE=.\PercentPrinter.cpp
# End Source File
# Begin Source File
SOURCE=.\PercentPrinter.h
# End Source File
# Begin Source File
SOURCE=.\TempFiles.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
# End Source File
# Begin Source File
SOURCE=.\UserInputUtils.cpp
# End Source File
# Begin Source File
SOURCE=.\UserInputUtils.h
# End Source File
# End Group
# Begin Group "Windows"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\..\..\Windows\DLL.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\DLL.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\Error.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\Error.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\FileDir.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\FileDir.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\FileFind.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\FileFind.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\FileIO.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\FileIO.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\FileName.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\FileName.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\PropVariant.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\PropVariant.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\PropVariantConversions.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\PropVariantConversions.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\Registry.cpp
# End Source File
# Begin Source File
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\CommandLineParser.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\CommandLineParser.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\ComTry.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\Defs.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\Exception.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\IntToString.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\IntToString.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\ListFileUtils.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\ListFileUtils.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\MyCom.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\NewHandler.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\NewHandler.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\StdInStream.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\StdInStream.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\StdOutStream.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\StdOutStream.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\String.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\String.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\StringConvert.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\StringConvert.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\UTFConvert.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\UTFConvert.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\Vector.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\Vector.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\Wildcard.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\Wildcard.h
# End Source File
# End Group
# Begin Group "UI Common"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\Common\ArchiverInfo.cpp
# End Source File
# Begin Source File
SOURCE=..\Common\ArchiverInfo.h
# End Source File
# Begin Source File
SOURCE=..\Common\DefaultName.cpp
# End Source File
# Begin Source File
SOURCE=..\Common\DefaultName.h
# End Source File
# Begin Source File
SOURCE=..\Common\DirItem.h
# End Source File
# Begin Source File
SOURCE=..\Common\EnumDirItems.cpp
# End Source File
# Begin Source File
SOURCE=..\Common\EnumDirItems.h
# End Source File
# Begin Source File
SOURCE=..\Common\ExtractingFilePath.cpp
# End Source File
# Begin Source File
SOURCE=..\Common\ExtractingFilePath.h
# End Source File
# Begin Source File
SOURCE=..\Common\HandlerLoader.h
# End Source File
# Begin Source File
SOURCE=..\Common\OpenArchive.cpp
# End Source File
# Begin Source File
SOURCE=..\Common\OpenArchive.h
# End Source File
# Begin Source File
SOURCE=..\Common\PropIDUtils.cpp
# End Source File
# Begin Source File
SOURCE=..\Common\PropIDUtils.h
# End Source File
# Begin Source File
SOURCE=..\Common\SortUtils.cpp
# End Source File
# Begin Source File
SOURCE=..\Common\SortUtils.h
# End Source File
# Begin Source File
SOURCE=..\Common\UpdateAction.cpp
# End Source File
# Begin Source File
SOURCE=..\Common\UpdateAction.h
# End Source File
# Begin Source File
SOURCE=..\Common\UpdatePair.cpp
# End Source File
# Begin Source File
SOURCE=..\Common\UpdatePair.h
# End Source File
# Begin Source File
SOURCE=..\Common\UpdateProduce.cpp
# End Source File
# Begin Source File
SOURCE=..\Common\UpdateProduce.h
# End Source File
# Begin Source File
SOURCE=..\Common\WorkDir.cpp
# End Source File
# Begin Source File
SOURCE=..\Common\WorkDir.h
# End Source File
# End Group
# Begin Group "7-zip Common"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\..\Common\FilePathAutoRename.cpp
# End Source File
# Begin Source File
SOURCE=..\..\Common\FilePathAutoRename.h
# End Source File
# Begin Source File
SOURCE=..\..\Common\FileStreams.cpp
# End Source File
# Begin Source File
SOURCE=..\..\Common\FileStreams.h
# End Source File
# End Group
# Begin Group "Compress"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\..\Compress\Copy\CopyCoder.cpp
# End Source File
# Begin Source File
SOURCE=..\..\Compress\Copy\CopyCoder.h
# End Source File
# End Group
# End Target
# End Project

29
7zip/UI/Console/Console.dsw Executable file
View File

@@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "Console"=".\Console.dsp" - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View File

@@ -0,0 +1,57 @@
// ConsoleClose.cpp
#include "StdAfx.h"
#include "ConsoleClose.h"
static int g_BreakCounter = 0;
static const int kBreakAbortThreshold = 2;
namespace NConsoleClose {
static BOOL WINAPI HandlerRoutine(DWORD aCtrlType)
{
g_BreakCounter++;
if (g_BreakCounter < kBreakAbortThreshold)
return TRUE;
return FALSE;
/*
switch(aCtrlType)
{
case CTRL_C_EVENT:
case CTRL_BREAK_EVENT:
if (g_BreakCounter < kBreakAbortThreshold)
return TRUE;
}
return FALSE;
*/
}
bool TestBreakSignal()
{
/*
if (g_BreakCounter > 0)
return true;
*/
return (g_BreakCounter > 0);
}
void CheckCtrlBreak()
{
if (TestBreakSignal())
throw CCtrlBreakException();
}
CCtrlHandlerSetter::CCtrlHandlerSetter()
{
if(!SetConsoleCtrlHandler(HandlerRoutine, TRUE))
throw "SetConsoleCtrlHandler fails";
}
CCtrlHandlerSetter::~CCtrlHandlerSetter()
{
if(!SetConsoleCtrlHandler(HandlerRoutine, FALSE))
throw "SetConsoleCtrlHandler fails";
}
}

27
7zip/UI/Console/ConsoleClose.h Executable file
View File

@@ -0,0 +1,27 @@
// ConsoleCloseUtils.h
#pragma once
#ifndef __CONSOLECLOSEUTILS_H
#define __CONSOLECLOSEUTILS_H
namespace NConsoleClose {
bool TestBreakSignal();
class CCtrlHandlerSetter
{
public:
CCtrlHandlerSetter();
virtual ~CCtrlHandlerSetter();
};
class CCtrlBreakException
{};
void CheckCtrlBreak();
}
#endif

94
7zip/UI/Console/Extract.cpp Executable file
View File

@@ -0,0 +1,94 @@
// 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;
}

65
7zip/UI/Console/Extract.h Executable file
View File

@@ -0,0 +1,65 @@
// 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

View File

@@ -0,0 +1,405 @@
// 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;
}

View File

@@ -0,0 +1,77 @@
// 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

381
7zip/UI/Console/List.cpp Executable file
View File

@@ -0,0 +1,381 @@
// List.cpp
#include "StdAfx.h"
#include "List.h"
#include "ConsoleClose.h"
#include "Common/StringConvert.h"
#include "Common/StdOutStream.h"
#include "Common/IntToString.h"
#include "Common/MyCom.h"
#include "Windows/PropVariant.h"
#include "Windows/Defs.h"
#include "Windows/PropVariantConversions.h"
#include "../Common/PropIDUtils.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)
{
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;
}
enum EAdjustment
{
kLeft,
kCenter,
kRight
};
struct CFieldInfo
{
PROPID PropID;
UString Name;
EAdjustment TitleAdjustment;
EAdjustment TextAdjustment;
int PrefixSpacesWidth;
int Width;
};
struct CFieldInfoInit
{
PROPID PropID;
const wchar_t *Name;
EAdjustment TitleAdjustment;
EAdjustment TextAdjustment;
int PrefixSpacesWidth;
int Width;
};
CFieldInfoInit kStandardFieldTable[] =
{
{ kpidLastWriteTime, L" Date Time", kLeft, kLeft, 0, 19 },
{ kpidAttributes, L"Attr", kRight, kCenter, 1, 5 },
{ kpidSize, L"Size", kRight, kRight, 1, 12 },
{ kpidPackedSize, L"Compressed", kRight, kRight, 1, 12 },
{ kpidPath, L"Name", kLeft, kLeft, 2, 12 }
};
void PrintSpaces(int numSpaces)
{
for (int i = 0; i < numSpaces; i++)
g_StdOut << ' ';
}
void PrintString(EAdjustment adjustment, int width, const UString &textString)
{
const int numSpaces = width - textString.Length();
int numLeftSpaces;
switch (adjustment)
{
case kLeft:
numLeftSpaces = 0;
break;
case kCenter:
numLeftSpaces = numSpaces / 2;
break;
case kRight:
numLeftSpaces = numSpaces;
break;
}
PrintSpaces(numLeftSpaces);
g_StdOut << textString;
PrintSpaces(numSpaces - numLeftSpaces);
}
class CFieldPrinter
{
CObjectVector<CFieldInfo> _fields;
public:
void Init(const CFieldInfoInit *standardFieldTable, int numItems);
void PrintTitle();
void PrintTitleLines();
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);
};
void CFieldPrinter::Init(const CFieldInfoInit *standardFieldTable, int numItems)
{
for (int i = 0; i < numItems; i++)
{
CFieldInfo fieldInfo;
const CFieldInfoInit &fieldInfoInit = standardFieldTable[i];
fieldInfo.PropID = fieldInfoInit.PropID;
fieldInfo.Name = fieldInfoInit.Name;
fieldInfo.TitleAdjustment = fieldInfoInit.TitleAdjustment;
fieldInfo.TextAdjustment = fieldInfoInit.TextAdjustment;
fieldInfo.PrefixSpacesWidth = fieldInfoInit.PrefixSpacesWidth;
fieldInfo.Width = fieldInfoInit.Width;
_fields.Add(fieldInfo);
}
}
void CFieldPrinter::PrintTitle()
{
for (int i = 0; i < _fields.Size(); i++)
{
const CFieldInfo &fieldInfo = _fields[i];
PrintSpaces(fieldInfo.PrefixSpacesWidth);
PrintString(fieldInfo.TitleAdjustment, fieldInfo.Width, fieldInfo.Name);
}
}
void CFieldPrinter::PrintTitleLines()
{
for (int i = 0; i < _fields.Size(); i++)
{
const CFieldInfo &fieldInfo = _fields[i];
PrintSpaces(fieldInfo.PrefixSpacesWidth);
for (int i = 0; i < fieldInfo.Width; i++)
g_StdOut << '-';
}
}
BOOL IsFileTimeZero(CONST FILETIME *lpFileTime)
{
return (lpFileTime->dwLowDateTime == 0) && (lpFileTime->dwHighDateTime == 0);
}
const char *kEmptyTimeString = " ";
void PrintTime(const NCOM::CPropVariant &propVariant)
{
if (propVariant.vt != VT_FILETIME)
throw "incorrect item";
if (IsFileTimeZero(&propVariant.filetime))
g_StdOut << kEmptyTimeString;
else
{
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);
g_StdOut << s;
}
else
g_StdOut << kEmptyTimeString;
}
}
HRESULT CFieldPrinter::PrintItemInfo(IInArchive *archive,
const UString &defaultItemName,
const NWindows::NFile::NFind::CFileInfoW &archiveFileInfo,
UINT32 index)
{
for (int i = 0; i < _fields.Size(); i++)
{
const CFieldInfo &fieldInfo = _fields[i];
PrintSpaces(fieldInfo.PrefixSpacesWidth);
NCOM::CPropVariant propVariant;
RINOK(archive->GetProperty(index,
fieldInfo.PropID, &propVariant));
if (propVariant.vt == VT_EMPTY)
{
switch(fieldInfo.PropID)
{
case kpidPath:
propVariant = defaultItemName;
break;
case kpidLastWriteTime:
propVariant = archiveFileInfo.LastWriteTime;
break;
default:
PrintSpaces(fieldInfo.Width);
continue;
}
}
if (fieldInfo.PropID == kpidLastWriteTime)
{
PrintTime(propVariant);
continue;
}
if (fieldInfo.PropID == kpidAttributes)
{
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));
continue;
}
if (propVariant.vt == VT_BSTR)
{
PrintString(fieldInfo.TextAdjustment, fieldInfo.Width, propVariant.bstrVal);
continue;
}
PrintString(fieldInfo.TextAdjustment, fieldInfo.Width,
ConvertPropertyToString(propVariant, fieldInfo.PropID));
}
return S_OK;
}
void PrintNumberString(EAdjustment adjustment, int width, const UINT64 *value)
{
wchar_t textString[32] = { 0 };
if (value != NULL)
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)
{
for (int i = 0; i < _fields.Size(); i++)
{
const CFieldInfo &fieldInfo = _fields[i];
PrintSpaces(fieldInfo.PrefixSpacesWidth);
NCOM::CPropVariant propVariant;
if (fieldInfo.PropID == kpidSize)
PrintNumberString(fieldInfo.TextAdjustment, fieldInfo.Width, size);
else if (fieldInfo.PropID == kpidPackedSize)
PrintNumberString(fieldInfo.TextAdjustment, fieldInfo.Width, compressedSize);
else if (fieldInfo.PropID == kpidPath)
{
wchar_t textString[32];
ConvertUINT64ToString(numFiles, textString);
UString temp = textString;
temp += L" ";
temp += kFilesMessage;
PrintString(fieldInfo.TextAdjustment, fieldInfo.Width, temp);
}
else
PrintString(fieldInfo.TextAdjustment, fieldInfo.Width, L"");
}
return S_OK;
}
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);
return true;
}
HRESULT ListArchive(IInArchive *archive,
const UString &defaultItemName,
const NWindows::NFile::NFind::CFileInfoW &archiveFileInfo,
const NWildcard::CCensor &wildcardCensor/*, bool fullPathMode,
NListMode::EEnum mode*/)
{
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++)
{
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
{
if(propVariant.vt != VT_BSTR)
return E_FAIL;
filePath = propVariant.bstrVal;
}
if (!wildcardCensor.CheckName(filePath))
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;
}
fieldPrinter.PrintTitleLines();
g_StdOut << endl;
/*
if(numFiles == 0)
g_StdOut << kNoFilesMessage);
else
*/
fieldPrinter.PrintSummaryInfo(numFiles, totalUnPackSizePointer, totalPackSizePointer);
g_StdOut << endl;
return S_OK;
}

31
7zip/UI/Console/List.h Executable file
View File

@@ -0,0 +1,31 @@
// 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*/);
#endif

934
7zip/UI/Console/Main.cpp Executable file
View File

@@ -0,0 +1,934 @@
// Main.cpp
#include "StdAfx.h"
#include <initguid.h>
#include <io.h>
#include "Common/CommandLineParser.h"
#include "Common/StdOutStream.h"
#include "Common/Wildcard.h"
#include "Common/ListFileUtils.h"
#include "Common/StringConvert.h"
#include "Windows/FileDir.h"
#include "Windows/FileName.h"
#include "Windows/Defs.h"
#include "../../IPassword.h"
#include "../../ICoder.h"
#include "../../Compress/LZ/IMatchFinder.h"
#include "../Common/DefaultName.h"
#include "../Common/OpenArchive.h"
#include "../Common/ArchiverInfo.h"
#include "../Common/UpdateAction.h"
#include "List.h"
#include "Extract.h"
#include "Update.h"
#include "ArError.h"
#include "OpenCallback.h"
#ifndef EXCLUDE_COM
#include "Windows/DLL.h"
#endif
using namespace NWindows;
using namespace NFile;
using namespace NCommandLineParser;
HINSTANCE g_hInstance = 0;
static const char *kCopyrightString = "\n7-Zip"
#ifdef EXCLUDE_COM
" (A)"
#endif
#ifdef UNICODE
" [NT]"
#endif
" 3.12 Copyright (c) 1999-2003 Igor Pavlov 2003-12-10\n";
const wchar_t *kDefaultArchiveType = L"7z";
const wchar_t *kDefaultSfxModule = L"7zCon.sfx";
const wchar_t *kSFXExtension = L"exe";
static const int kNumSwitches = 15;
namespace NKey {
enum Enum
{
kHelp1 = 0,
kHelp2,
kDisablePercents,
kArchiveType,
kYes,
kPassword,
kProperty,
kOutputDir,
kWorkingDir,
kInclude,
kExclude,
kUpdate,
kRecursed,
kSfx,
kOverwrite
};
}
namespace NRecursedType {
enum EEnum
{
kRecursed,
kWildCardOnlyRecursed,
kNonRecursed,
};
}
static const wchar_t kRecursedIDChar = 'R';
static const wchar_t *kRecursedPostCharSet = L"0-";
namespace NRecursedPostCharIndex {
enum EEnum
{
kWildCardRecursionOnly = 0,
kNoRecursion = 1
};
}
static const char kFileListID = '@';
static const char kImmediateNameID = '!';
static const char kSomeCludePostStringMinSize = 2; // at least <@|!><N>ame must be
static const char kSomeCludeAfterRecursedPostStringMinSize = 2; // at least <@|!><N>ame must be
static const wchar_t *kOverwritePostCharSet = L"asut";
NExtraction::NOverwriteMode::EEnum k_OverwriteModes[] =
{
NExtraction::NOverwriteMode::kWithoutPrompt,
NExtraction::NOverwriteMode::kSkipExisting,
NExtraction::NOverwriteMode::kAutoRename,
NExtraction::NOverwriteMode::kAutoRenameExisting
};
static const CSwitchForm kSwitchForms[kNumSwitches] =
{
{ L"?", NSwitchType::kSimple, false },
{ L"H", NSwitchType::kSimple, false },
{ L"BD", NSwitchType::kSimple, false },
{ L"T", NSwitchType::kUnLimitedPostString, false, 1 },
{ L"Y", NSwitchType::kSimple, false },
{ L"P", NSwitchType::kUnLimitedPostString, false, 0 },
{ L"M", NSwitchType::kUnLimitedPostString, true, 1 },
{ L"O", NSwitchType::kUnLimitedPostString, false, 1 },
{ L"W", NSwitchType::kUnLimitedPostString, false, 0 },
{ L"I", NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},
{ L"X", NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},
{ L"U", NSwitchType::kUnLimitedPostString, true, 1},
{ L"R", NSwitchType::kPostChar, false, 0, 0, kRecursedPostCharSet },
{ L"SFX", NSwitchType::kUnLimitedPostString, false, 0 },
{ L"AO", NSwitchType::kPostChar, false, 1, 1, kOverwritePostCharSet}
};
static const int kNumCommandForms = 7;
namespace NCommandType {
enum EEnum
{
kAdd = 0,
kUpdate,
kDelete,
kTest,
kExtract,
kFullExtract,
kList
};
}
static const CCommandForm g_CommandForms[kNumCommandForms] =
{
{ L"A", false },
{ L"U", false },
{ L"D", false },
{ L"T", false },
{ L"E", false },
{ L"X", false },
{ L"L", false }
// { "L", true }
};
static const NRecursedType::EEnum kCommandRecursedDefault[kNumCommandForms] =
{
NRecursedType::kNonRecursed,
NRecursedType::kNonRecursed,
NRecursedType::kNonRecursed,
NRecursedType::kRecursed,
NRecursedType::kRecursed,
NRecursedType::kRecursed,
NRecursedType::kRecursed
};
// -------------------------------------------------
// Update area
const UString kUpdatePairStateIDSet = L"PQRXYZW";
const int kUpdatePairStateNotSupportedActions[] = {2, 2, 1, -1, -1, -1, -1};
const UString kUpdatePairActionIDSet = L"0123"; //Ignore, Copy, Compress
const wchar_t *kUpdateIgnoreItselfPostStringID = L"-";
const wchar_t kUpdateNewArchivePostCharID = '!';
static const bool kTestExtractRecursedDefault = true;
static const bool kAddRecursedDefault = false;
static const int kMaxCmdLineSize = 1000;
static const wchar_t *kUniversalWildcard = L"*";
static const int kMinNonSwitchWords = 2;
static const int kCommandIndex = 0;
static const int kArchiveNameIndex = kCommandIndex + 1;
static const int kFirstFileNameIndex = kArchiveNameIndex + 1;
static const char *kHelpString =
"\nUsage: 7z <command> [<switches>...] <archive_name> [<file_names>...]\n"
" [<@listfiles...>]\n"
"\n"
"<Commands>\n"
" a: Add files to archive\n"
" d: Delete files from archive\n"
" e: Extract files from archive\n"
" l: List contents of archive\n"
// " l[a|t][f]: List contents of archive\n"
// " a - with Additional fields\n"
// " t - with all fields\n"
// " f - with Full pathnames\n"
" t: Test integrity of archive\n"
" u: Update files to archive\n"
" x: eXtract files with full pathname\n"
"<Switches>\n"
" -bd Disable percentage indicator\n"
" -i[r[-|0]]{@listfile|!wildcard}: Include filenames\n"
" -m{Parameters}: set compression Method\n"
// " -m0: store (no compression)\n"
// " -md<#>[b|k|m]: set Dictionary Size\n"
// " -mx: maXimize compression\n"
" -o{Directory}: set Output directory\n"
" -p{Password}: set Password\n"
" -r[-|0]: Recurse subdirectories\n"
" -sfx[{name}]: Create SFX archive\n"
" -t{Type}: Set type of archive\n"
" -u[-][p#][q#][r#][x#][y#][z#][!newArchiveName]: Update options\n"
" -w[{path}]: assign Work directory. Empty path means a temporary directory\n"
" -x[r[-|0]]]{@listfile|!wildcard}: eXclude filenames\n"
" -y: assume Yes on all queries\n";
// ---------------------------
// exception messages
static const char *kUserErrorMessage = "Incorrect command line"; // NExitCode::kUserError
static const char *kIncorrectListFile = "Incorrect wildcard in listfile";
static const char *kIncorrectWildCardInListFile = "Incorrect wildcard in listfile";
static const char *kIncorrectWildCardInCommandLine = "Incorrect wildcard in command line";
static const char *kProcessArchiveMessage = " archive: ";
// ---------------------------
static const AString kExtractGroupProcessMessage = "Processing";
static const AString kListingProcessMessage = "Listing";
static const AString kDefaultWorkingDirectory = ""; // test it maybemust be "."
struct CArchiveCommand
{
NCommandType::EEnum CommandType;
NRecursedType::EEnum DefaultRecursedType() const;
bool IsFromExtractGroup(NExtractMode::EEnum &extractMode) const;
bool IsFromUpdateGroup() const;
};
NRecursedType::EEnum CArchiveCommand::DefaultRecursedType() const
{
return kCommandRecursedDefault[CommandType];
}
bool CArchiveCommand::IsFromExtractGroup(NExtractMode::EEnum &extractMode) const
{
switch(CommandType)
{
case NCommandType::kTest:
extractMode = NExtractMode::kTest;
return true;
case NCommandType::kExtract:
extractMode = NExtractMode::kExtractToOne;
return true;
case NCommandType::kFullExtract:
extractMode = NExtractMode::kFullPath;
return true;
default:
return false;
}
}
bool CArchiveCommand::IsFromUpdateGroup() const
{
return (CommandType == NCommandType::kAdd ||
CommandType == NCommandType::kUpdate ||
CommandType == NCommandType::kDelete);
}
static NRecursedType::EEnum GetRecursedTypeFromIndex(int index)
{
switch (index)
{
case NRecursedPostCharIndex::kWildCardRecursionOnly:
return NRecursedType::kWildCardOnlyRecursed;
case NRecursedPostCharIndex::kNoRecursion:
return NRecursedType::kNonRecursed;
default:
return NRecursedType::kRecursed;
}
}
void PrintHelp(void)
{
g_StdOut << kHelpString;
}
static void ShowMessageAndThrowException(LPCSTR message, NExitCode::EEnum code)
{
g_StdOut << message << endl;
throw code;
}
static void PrintHelpAndExit() // yyy
{
PrintHelp();
ShowMessageAndThrowException(kUserErrorMessage, NExitCode::kUserError);
}
static void PrintProcessTitle(const AString &processTitle, const UString &archiveName)
{
g_StdOut << endl << processTitle <<
kProcessArchiveMessage << archiveName << endl << endl;
}
bool ParseArchiveCommand(const UString &commandString, CArchiveCommand &command)
{
UString commandStringUpper = commandString;
commandStringUpper.MakeUpper();
UString postString;
int commandIndex = ParseCommand(kNumCommandForms, g_CommandForms, commandStringUpper,
postString) ;
if (commandIndex < 0)
return false;
command.CommandType = (NCommandType::EEnum)commandIndex;
return true;
}
// ------------------------------------------------------------------
// filenames functions
static bool TestIsPathLegal(const UString &name)
{
if (name.Length() == 0)
return false;
if (name[0] == L'\\' || name[0] == L'/')
return false;
if (name.Length() < 3)
return true;
if (name[1] == L':' && name[2] == L'\\')
return false;
return true;
}
static bool AddNameToCensor(NWildcard::CCensor &wildcardCensor,
const UString &name, bool include, NRecursedType::EEnum type)
{
if (!TestIsPathLegal(name))
throw "Can't use absolute paths";
bool isWildCard = DoesNameContainWildCard(name);
bool recursed;
switch (type)
{
case NRecursedType::kWildCardOnlyRecursed:
recursed = isWildCard;
break;
case NRecursedType::kRecursed:
recursed = true;
break;
case NRecursedType::kNonRecursed:
recursed = false;
break;
}
wildcardCensor.AddItem(name, include, recursed, isWildCard);
return true;
}
static inline UINT GetCurrentCodePage()
{ return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }
void AddToCensorFromListFile(NWildcard::CCensor &wildcardCensor,
LPCWSTR fileName, bool include, NRecursedType::EEnum type)
{
UStringVector names;
if (!ReadNamesFromListFile(GetSystemString(fileName,
GetCurrentCodePage()), names))
ShowMessageAndThrowException(kIncorrectListFile, NExitCode::kUserError);
for (int i = 0; i < names.Size(); i++)
if (!AddNameToCensor(wildcardCensor, names[i], include, type))
ShowMessageAndThrowException(kIncorrectWildCardInListFile, NExitCode::kUserError);
}
void AddCommandLineWildCardToCensr(NWildcard::CCensor &wildcardCensor,
const UString &name, bool include, NRecursedType::EEnum type)
{
if (!AddNameToCensor(wildcardCensor, name, include, type))
ShowMessageAndThrowException(kIncorrectWildCardInCommandLine, NExitCode::kUserError);
}
void AddToCensorFromNonSwitchesStrings(NWildcard::CCensor &wildcardCensor,
const UStringVector &nonSwitchStrings, NRecursedType::EEnum type,
bool thereAreSwitchIncludeWildCards)
{
int numNonSwitchStrings = nonSwitchStrings.Size();
if(numNonSwitchStrings == kMinNonSwitchWords && (!thereAreSwitchIncludeWildCards))
AddCommandLineWildCardToCensr(wildcardCensor, kUniversalWildcard, true, type);
for(int i = kFirstFileNameIndex; i < numNonSwitchStrings; i++)
{
const UString &s = nonSwitchStrings[i];
if (s[0] == kFileListID)
AddToCensorFromListFile(wildcardCensor, s.Mid(1), true, type);
else
AddCommandLineWildCardToCensr(wildcardCensor, s, true, type);
}
}
void AddSwitchWildCardsToCensor(NWildcard::CCensor &wildcardCensor,
const UStringVector &strings, bool include,
NRecursedType::EEnum commonRecursedType)
{
for(int i = 0; i < strings.Size(); i++)
{
const UString &name = strings[i];
NRecursedType::EEnum recursedType;
int pos = 0;
if (name.Length() < kSomeCludePostStringMinSize)
PrintHelpAndExit();
if (::MyCharUpper(name[pos]) == kRecursedIDChar)
{
pos++;
int index = UString(kRecursedPostCharSet).Find(name[pos]);
recursedType = GetRecursedTypeFromIndex(index);
if (index >= 0)
pos++;
}
else
recursedType = commonRecursedType;
if (name.Length() < pos + kSomeCludeAfterRecursedPostStringMinSize)
PrintHelpAndExit();
UString tail = name.Mid(pos + 1);
if (name[pos] == kImmediateNameID)
AddCommandLineWildCardToCensr(wildcardCensor, tail, include, recursedType);
else if (name[pos] == kFileListID)
AddToCensorFromListFile(wildcardCensor, tail, include, recursedType);
else
PrintHelpAndExit();
}
}
// ------------------------------------------------------
// AddCommand functions
static NUpdateArchive::NPairAction::EEnum GetUpdatePairActionType(int i)
{
switch(i)
{
case NUpdateArchive::NPairAction::kIgnore: return NUpdateArchive::NPairAction::kIgnore;
case NUpdateArchive::NPairAction::kCopy: return NUpdateArchive::NPairAction::kCopy;
case NUpdateArchive::NPairAction::kCompress: return NUpdateArchive::NPairAction::kCompress;
case NUpdateArchive::NPairAction::kCompressAsAnti: return NUpdateArchive::NPairAction::kCompressAsAnti;
}
throw 98111603;
}
bool ParseUpdateCommandString2(const UString &command,
NUpdateArchive::CActionSet &actionSet, UString &postString)
{
for(int i = 0; i < command.Length();)
{
char c = MyCharUpper(command[i]);
int statePos = kUpdatePairStateIDSet.Find(c);
if (statePos < 0)
{
postString = command.Mid(i);
return true;
}
i++;
if (i >= command.Length())
return false;
int actionPos = kUpdatePairActionIDSet.Find(::MyCharUpper(command[i]));
if (actionPos < 0)
return false;
actionSet.StateActions[statePos] = GetUpdatePairActionType(actionPos);
if (kUpdatePairStateNotSupportedActions[statePos] == actionPos)
return false;
i++;
}
postString.Empty();
return true;
}
UString MakeFullArchiveName(const UString &name, const UString &extension)
{
if (extension.IsEmpty())
return name;
if (name.IsEmpty())
return name;
if (name[name.Length() - 1] == L'.')
return name.Left(name.Length() - 1);
int slash1Pos = name.ReverseFind(L'\\');
int slash2Pos = name.ReverseFind(L'/');
int slashPos = MyMax(slash1Pos, slash2Pos);
int dotPos = name.ReverseFind(L'.');
if (dotPos >= 0 && (dotPos > slashPos || slashPos < 0))
return name;
return name + L'.' + extension;
}
void ParseUpdateCommandString(CUpdateArchiveOptions &options,
const UStringVector &updatePostStrings,
const NUpdateArchive::CActionSet &defaultActionSet,
const UString &extension)
{
for(int i = 0; i < updatePostStrings.Size(); i++)
{
const UString &updateString = updatePostStrings[i];
if(updateString.CompareNoCase(kUpdateIgnoreItselfPostStringID) == 0)
{
if(options.UpdateArchiveItself)
{
options.UpdateArchiveItself = false;
options.Commands.Delete(0);
}
}
else
{
NUpdateArchive::CActionSet actionSet = defaultActionSet;
UString postString;
if (!ParseUpdateCommandString2(updateString, actionSet, postString))
PrintHelpAndExit();
if(postString.IsEmpty())
{
if(options.UpdateArchiveItself)
{
options.Commands[0].ActionSet = actionSet;
}
}
else
{
if(MyCharUpper(postString[0]) != kUpdateNewArchivePostCharID)
PrintHelpAndExit();
CUpdateArchiveCommand updateCommand;
UString archivePath = postString.Mid(1);
if (archivePath.IsEmpty())
PrintHelpAndExit();
updateCommand.ArchivePath = MakeFullArchiveName(archivePath, extension);
updateCommand.ActionSet = actionSet;
options.Commands.Add(updateCommand);
}
}
}
}
static void SetAddCommandOptions(NCommandType::EEnum commandType,
const CParser &parser,
const UString &archivePath,
CUpdateArchiveOptions &options, UString &workingDir,
const UString &extension)
{
NUpdateArchive::CActionSet defaultActionSet;
switch(commandType)
{
case NCommandType::kAdd:
defaultActionSet = NUpdateArchive::kAddActionSet;
break;
case NCommandType::kDelete:
defaultActionSet = NUpdateArchive::kDeleteActionSet;
break;
default:
defaultActionSet = NUpdateArchive::kUpdateActionSet;
}
options.ArchivePath = archivePath;
options.UpdateArchiveItself = true;
options.Commands.Clear();
CUpdateArchiveCommand updateMainCommand;
updateMainCommand.ActionSet = defaultActionSet;
options.Commands.Add(updateMainCommand);
// options.ItselfActionSet = defaultActionSet;
if(parser[NKey::kUpdate].ThereIs)
ParseUpdateCommandString(options, parser[NKey::kUpdate].PostStrings,
defaultActionSet, extension);
if(parser[NKey::kWorkingDir].ThereIs)
{
const UString &postString = parser[NKey::kWorkingDir].PostStrings[0];
if (postString.IsEmpty())
NDirectory::MyGetTempPath(workingDir);
else
workingDir = postString;
}
else
{
if (!NDirectory::GetOnlyDirPrefix(archivePath, workingDir))
throw "bad archive name";
if (workingDir.IsEmpty())
workingDir = L".\\";
}
if(options.SfxMode = parser[NKey::kSfx].ThereIs)
{
UString moduleName = parser[NKey::kSfx].PostStrings[0];
if (moduleName.IsEmpty())
moduleName = kDefaultSfxModule;
if (!NDirectory::MySearchPath(NULL, moduleName, NULL, options.SfxModule))
throw "can't find specified sfx module";
}
}
static const char kByteSymbol = 'B';
static const char kKiloByteSymbol = 'K';
static const char kMegaByteSymbol = 'M';
static void SetMethodOptions(const CParser &parser,
CUpdateArchiveOptions &options)
{
if (parser[NKey::kProperty].ThereIs)
{
// options.MethodMode.Properties.Clear();
for(int i = 0; i < parser[NKey::kProperty].PostStrings.Size(); i++)
{
CProperty property;
const UString &postString = parser[NKey::kProperty].PostStrings[i];
int index = postString.Find(L'=');
if (index < 0)
property.Name = postString;
else
{
property.Name = postString.Left(index);
property.Value = postString.Mid(index + 1);
}
options.MethodMode.Properties.Add(property);
}
}
}
static void MyOpenArhive(const UString &archiveName,
const NFind::CFileInfoW &archiveFileInfo,
#ifndef EXCLUDE_COM
HMODULE *module,
#endif
IInArchive **archiveHandler,
UString &defaultItemName,
bool &passwordEnabled,
UString &password)
{
COpenCallbackImp *openCallbackSpec = new COpenCallbackImp;
CMyComPtr<IArchiveOpenCallback> openCallback = openCallbackSpec;
if (passwordEnabled)
{
openCallbackSpec->PasswordIsDefined = passwordEnabled;
openCallbackSpec->Password = password;
}
UString fullName;
int fileNamePartStartIndex;
NFile::NDirectory::MyGetFullPathName(archiveName, fullName, fileNamePartStartIndex);
openCallbackSpec->LoadFileInfo(
fullName.Left(fileNamePartStartIndex),
fullName.Mid(fileNamePartStartIndex));
CArchiverInfo archiverInfo;
int subExtIndex;
HRESULT result = OpenArchive(archiveName,
#ifndef EXCLUDE_COM
module,
#endif
archiveHandler,
archiverInfo,
subExtIndex,
openCallback);
if (result == S_FALSE)
throw "file is not supported archive";
if (result != S_OK)
throw "error";
defaultItemName = GetDefaultName(archiveName,
archiverInfo.Extensions[subExtIndex].Extension,
archiverInfo.Extensions[subExtIndex].AddExtension);
passwordEnabled = openCallbackSpec->PasswordIsDefined;
password = openCallbackSpec->Password;
}
#ifndef EXCLUDE_COM
void SetArchiveType(const UString &archiveType,
UString &filePath, CLSID &classID, UString &archiveExtension)
#else
void SetArchiveType(const UString &archiveType,
UString &formatName, UString &archiveExtension)
#endif
{
CObjectVector<CArchiverInfo> archiverInfoVector;
ReadArchiverInfoList(archiverInfoVector);
if (archiverInfoVector.Size() == 0)
throw "There are no installed archive handlers";
if (archiveType.IsEmpty())
throw "Incorrect archive type was assigned";
for (int i = 0; i < archiverInfoVector.Size(); i++)
{
const CArchiverInfo &archiverInfo = archiverInfoVector[i];
if (archiverInfo.Name.CompareNoCase(archiveType) == 0)
{
#ifndef EXCLUDE_COM
classID = archiverInfo.ClassID;
filePath = archiverInfo.FilePath;
#else
formatName = archiverInfo.Name;
#endif
archiveExtension = archiverInfo.GetMainExtension();
return;
}
}
throw "Incorrect archive type was assigned";
}
// int Main2(int numArguments, const char *arguments[])
int Main2()
{
SetFileApisToOEM();
g_StdOut << kCopyrightString;
UStringVector commandStrings;
NCommandLineParser::SplitCommandLine(GetCommandLineW(), commandStrings);
if(commandStrings.Size() == 1)
{
PrintHelp();
return 0;
}
commandStrings.Delete(0);
CParser parser(kNumSwitches);
try
{
parser.ParseStrings(kSwitchForms, commandStrings);
}
catch(...)
{
PrintHelpAndExit();
}
if(parser[NKey::kHelp1].ThereIs || parser[NKey::kHelp2].ThereIs)
{
PrintHelp();
return 0;
}
const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;
int numNonSwitchStrings = nonSwitchStrings.Size();
if(numNonSwitchStrings < kMinNonSwitchWords)
PrintHelpAndExit();
CArchiveCommand command;
if (!ParseArchiveCommand(nonSwitchStrings[kCommandIndex], command))
PrintHelpAndExit();
NRecursedType::EEnum recursedType;
if (parser[NKey::kRecursed].ThereIs)
recursedType = GetRecursedTypeFromIndex(parser[NKey::kRecursed].PostCharIndex);
else
recursedType = command.DefaultRecursedType();
NWildcard::CCensor wildcardCensor;
bool thereAreSwitchIncludeWildCards;
if (parser[NKey::kInclude].ThereIs)
{
thereAreSwitchIncludeWildCards = true;
AddSwitchWildCardsToCensor(wildcardCensor, parser[NKey::kInclude].PostStrings,
true, recursedType);
}
else
thereAreSwitchIncludeWildCards = false;
if (parser[NKey::kExclude].ThereIs)
AddSwitchWildCardsToCensor(wildcardCensor, parser[NKey::kExclude].PostStrings,
false, recursedType);
AddToCensorFromNonSwitchesStrings(wildcardCensor, nonSwitchStrings, recursedType,
thereAreSwitchIncludeWildCards);
bool yesToAll = parser[NKey::kYes].ThereIs;
UString archiveName;
archiveName = nonSwitchStrings[kArchiveNameIndex];
NExtractMode::EEnum extractMode;
bool isExtractGroupCommand = command.IsFromExtractGroup(extractMode);
bool passwordEnabled = parser[NKey::kPassword].ThereIs;
UString password;
if(passwordEnabled)
password = parser[NKey::kPassword].PostStrings[0];
if(isExtractGroupCommand || command.CommandType == NCommandType::kList)
{
NFind::CFileInfoW archiveFileInfo;
if (!NFind::FindFile(archiveName, archiveFileInfo) || archiveFileInfo.IsDirectory())
throw "there is no such archive";
if (archiveFileInfo.IsDirectory())
throw "there is no such archive";
UString defaultItemName;
#ifndef EXCLUDE_COM
NDLL::CLibrary library;
#endif
CMyComPtr<IInArchive> archiveHandler;
CArchiverInfo archiverInfo;
MyOpenArhive(archiveName, archiveFileInfo,
#ifndef EXCLUDE_COM
&library,
#endif
&archiveHandler,
defaultItemName, passwordEnabled, password);
if(isExtractGroupCommand)
{
PrintProcessTitle(kExtractGroupProcessMessage, archiveName);
UString outputDir;
if(parser[NKey::kOutputDir].ThereIs)
{
outputDir = parser[NKey::kOutputDir].PostStrings[0]; // test this DirPath
NName::NormalizeDirPathPrefix(outputDir);
}
NExtraction::NOverwriteMode::EEnum overwriteMode =
NExtraction::NOverwriteMode::kAskBefore;
if(parser[NKey::kOverwrite].ThereIs)
overwriteMode = k_OverwriteModes[parser[NKey::kOverwrite].PostCharIndex];
CExtractOptions options(extractMode, outputDir, yesToAll,
passwordEnabled, password, overwriteMode);
options.DefaultItemName = defaultItemName;
options.ArchiveFileInfo = archiveFileInfo;
// options.ArchiveFileInfo = archiveFileInfo;
HRESULT result = DeCompressArchiveSTD(archiveHandler, wildcardCensor, options);
if (result != S_OK)
{
return NExitCode::kErrorsDuringDecompression;
}
}
else
{
PrintProcessTitle(kListingProcessMessage, archiveName);
ListArchive(archiveHandler, defaultItemName, archiveFileInfo,
wildcardCensor/*, command.ListFullPathes, command.ListMode*/);
}
}
else if(command.IsFromUpdateGroup())
{
CUpdateArchiveOptions options;
options.MethodMode.PasswordIsDefined = passwordEnabled && !password.IsEmpty();
options.MethodMode.AskPassword = passwordEnabled && password.IsEmpty();
options.MethodMode.Password = password;
UString workingDir;
UString archiveType;
if(parser[NKey::kArchiveType].ThereIs)
archiveType = parser[NKey::kArchiveType].PostStrings[0];
else
archiveType = kDefaultArchiveType;
UString extension;
if (!archiveType.IsEmpty())
{
#ifndef EXCLUDE_COM
SetArchiveType(archiveType, options.MethodMode.FilePath,
options.MethodMode.ClassID1, extension);
#else
SetArchiveType(archiveType, options.MethodMode.Name, extension);
#endif
}
if(parser[NKey::kSfx].ThereIs)
extension = kSFXExtension;
archiveName = MakeFullArchiveName(archiveName, extension);
SetAddCommandOptions(command.CommandType, parser, archiveName, options,
workingDir, extension);
SetMethodOptions(parser, options);
if (options.SfxMode)
{
CProperty property;
property.Name = L"rsfx";
property.Value = L"on";
options.MethodMode.Properties.Add(property);
}
NFind::CFileInfoW archiveFileInfo;
#ifndef EXCLUDE_COM
NDLL::CLibrary library;
#endif
CMyComPtr<IInArchive> archive;
UString defaultItemName;
if (NFind::FindFile(archiveName, archiveFileInfo))
{
if (archiveFileInfo.IsDirectory())
throw "there is no such archive";
MyOpenArhive(archiveName, archiveFileInfo,
#ifndef EXCLUDE_COM
&library,
#endif
&archive,
defaultItemName, passwordEnabled, password);
}
else
if (archiveType.IsEmpty())
throw "type of archive is not specified";
bool enableParcents = !parser[NKey::kDisablePercents].ThereIs;
if (enableParcents)
{
if (!isatty(fileno(stdout)))
enableParcents = false;
}
HRESULT result = UpdateArchiveStdMain(wildcardCensor, options, workingDir,
archive, &defaultItemName, &archiveFileInfo, enableParcents);
if (result != S_OK)
throw NExitCode::CSystemError(result);
}
else
PrintHelpAndExit();
return 0;
}

114
7zip/UI/Console/MainAr.cpp Executable file
View File

@@ -0,0 +1,114 @@
// MainAr.cpp
#include "StdAfx.h"
// #include <locale.h>
#include "Windows/COM.h"
#include "Windows/Error.h"
#include "Common/StdOutStream.h"
#include "Common/NewHandler.h"
#include "Common/StringConvert.h"
#include "ConsoleClose.h"
#include "ArError.h"
using namespace NWindows;
// extern int Main2(int numArguments, const char *arguments[]);
extern int Main2();
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 *kUnknownExceptionMessage = "\n\nUnknown Error\n";
static const char *kInternalExceptionMessage = "\n\nInternal Error #";
static inline bool IsItWindowsNT()
{
OSVERSIONINFO versionInfo;
versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);
if (!::GetVersionEx(&versionInfo))
return false;
return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);
}
int __cdecl main()
// int __cdecl main(int numArguments, const char *arguments[])
{
#ifdef UNICODE
if (!IsItWindowsNT())
{
g_StdOut << "This program requires Windows NT/2000/XP";
return NExitCode::kFatalError;
}
#endif
// setlocale(LC_COLLATE, ".OCP");
int result=1;
NCOM::CComInitializer comInitializer;
try
{
NConsoleClose::CCtrlHandlerSetter aCtrlHandlerSetter;
try
{
// result = Main2(numArguments, arguments);
result = Main2();
}
catch(const NConsoleClose::CCtrlBreakException &)
{
g_StdOut << endl << kUserBreak;
return (NExitCode::kUserBreak);
}
}
catch(const CNewException)
{
g_StdOut << kMemoryExceptionMessage;
return (NExitCode::kMemoryError);
}
catch(const CSystemException &e)
{
g_StdOut << "System Error: " << (UINT64)(e.ErrorCode);
return (NExitCode::kFatalError);
}
catch(NExitCode::EEnum &aExitCode)
{
g_StdOut << kInternalExceptionMessage << aExitCode << endl;
return (aExitCode);
}
catch(const NExitCode::CSystemError &systemError)
{
UString message;
NError::MyFormatMessage(systemError.ErrorValue, message);
g_StdOut << endl << endl << "System error:" << endl <<
message << endl;
return (NExitCode::kFatalError);
}
catch(const NExitCode::CMultipleErrors &multipleErrors)
{
g_StdOut << endl << multipleErrors.NumErrors << " errors" << endl;
return (NExitCode::kFatalError);
}
catch(const UString &s)
{
g_StdOut << kExceptionErrorMessage << s << endl;
return (NExitCode::kFatalError);
}
catch(const char *s)
{
g_StdOut << kExceptionErrorMessage << s << endl;
return (NExitCode::kFatalError);
}
catch(int t)
{
g_StdOut << kInternalExceptionMessage << t << endl;
return (NExitCode::kFatalError);
}
catch(...)
{
g_StdOut << kUnknownExceptionMessage;
return (NExitCode::kFatalError);
}
return result;
}

View File

@@ -0,0 +1,92 @@
// 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;
}

52
7zip/UI/Console/OpenCallback.h Executable file
View File

@@ -0,0 +1,52 @@
// 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

View File

@@ -0,0 +1,86 @@
// PercentPrinter.cpp
#include "StdAfx.h"
#include "Common/StdOutStream.h"
#include "Common/IntToString.h"
#include "Common/String.h"
#include "PercentPrinter.h"
static const char *kPrepareString = " ";
static const char *kCloseString = "\b\b\b\b \b\b\b\b";
// static const char *kPercentFormatString = "\b\b\b\b%3I64u%%";
static const char *kPercentFormatString1 = "\b\b\b\b";
static const int kNumDigits = 3;
CPercentPrinter::CPercentPrinter(UINT64 minStepSize):
m_MinStepSize(minStepSize),
m_ScreenPos(0),
m_StringIsPrinted(false)
{
for (int i = 0; i < kNumPercentSpaces; i++)
m_Spaces[i] = ' ';
m_Spaces[kNumPercentSpaces] = '\0';
}
void CPercentPrinter::PreparePrint()
{
if (m_ScreenPos < kNumPercentSpaces)
g_StdOut << (m_Spaces + m_ScreenPos);
m_ScreenPos = kNumPercentSpaces;
g_StdOut << kPrepareString;
}
void CPercentPrinter::ClosePrint()
{
g_StdOut << kCloseString;
m_StringIsPrinted = false;
}
void CPercentPrinter::PrintString(const char *s)
{
m_ScreenPos += MyStringLen(s);
g_StdOut << s;
}
void CPercentPrinter::PrintString(const wchar_t *s)
{
m_ScreenPos += MyStringLen(s);
g_StdOut << s;
}
void CPercentPrinter::PrintNewLine()
{
m_ScreenPos = 0;
g_StdOut << "\n";
m_StringIsPrinted = false;
}
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);
char temp[32 + kNumDigits] = " "; // for 4 digits;
ConvertUINT64ToString(ratio, temp + kNumDigits);
int len = lstrlenA(temp + kNumDigits);
lstrcatA(temp, "%");
int pos = (len > kNumDigits)? kNumDigits : len;
g_StdOut << kPercentFormatString1;
g_StdOut << (temp + pos);
m_PrevValue = m_CurValue;
m_StringIsPrinted = true;
}
void CPercentPrinter::PrintRatio()
{
if (m_CurValue < m_PrevValue + m_MinStepSize || !m_StringIsPrinted)
return;
RePrintRatio();
}

View File

@@ -0,0 +1,38 @@
// PercentPrinter.h
#pragma once
#ifndef __PERCENTPRINTER_H
#define __PERCENTPRINTER_H
#include "Common/Defs.h"
const int kNumPercentSpaces = 70;
class CPercentPrinter
{
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)
{
m_Total = total;
m_PrevValue = 0;
m_StringIsPrinted = false;
}
void PrintString(const char *s);
void PrintString(const wchar_t *s);
void PrintNewLine();
void PreparePrint();
void ClosePrint();
void SetRatio(UINT64 doneValue);
void RePrintRatio();
void PrintRatio();
};
#endif

3
7zip/UI/Console/StdAfx.cpp Executable file
View File

@@ -0,0 +1,3 @@
// StdAfx.cpp
#include "stdafx.h"

16
7zip/UI/Console/StdAfx.h Executable file
View File

@@ -0,0 +1,16 @@
// 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>
#endif

39
7zip/UI/Console/TempFiles.cpp Executable file
View File

@@ -0,0 +1,39 @@
// 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();
}
}

20
7zip/UI/Console/TempFiles.h Executable file
View File

@@ -0,0 +1,20 @@
// 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

503
7zip/UI/Console/Update.cpp Executable file
View File

@@ -0,0 +1,503 @@
// 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;
}

41
7zip/UI/Console/Update.h Executable file
View File

@@ -0,0 +1,41 @@
// 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

View File

@@ -0,0 +1,259 @@
// 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;
}

View File

@@ -0,0 +1,78 @@
// 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

View File

@@ -0,0 +1,51 @@
// UserInputUtils.cpp
#include "StdAfx.h"
#include "Common/StdInStream.h"
#include "Common/StdOutStream.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 *kFirstQuestionMessage = "?\n";
static const char *kHelpQuestionMessage =
"(Y)es / (N)o / (A)lways / (S)kip all / A(u)to rename / (Q)uit? ";
// return true if pressed Quite;
// in: anAll
// out: anAll, anYes;
NUserAnswerMode::EEnum ScanUserYesNoAllQuit()
{
g_StdOut << kFirstQuestionMessage;
do
{
g_StdOut << kHelpQuestionMessage;
AString scannedString = g_StdIn.ScanStringUntilNewLine();
scannedString.Trim();
if(!scannedString.IsEmpty())
switch(::MyCharUpper(scannedString[0]))
{
case kYes:
return NUserAnswerMode::kYes;
case kNo:
return NUserAnswerMode::kNo;
case kYesAll:
return NUserAnswerMode::kYesAll;
case kNoAll:
return NUserAnswerMode::kNoAll;
case kAutoRename:
return NUserAnswerMode::kAutoRename;
case kQuit:
return NUserAnswerMode::kQuit;
}
}
while(true);
}

View File

@@ -0,0 +1,23 @@
// UserInputUtils.h
#pragma once
#ifndef __USERINPUTUTILS_H
#define __USERINPUTUTILS_H
namespace NUserAnswerMode {
enum EEnum
{
kYes,
kNo,
kYesAll,
kNoAll,
kAutoRename,
kQuit,
};
}
NUserAnswerMode::EEnum ScanUserYesNoAllQuit();
#endif

1
7zip/UI/Console/afxres.h Executable file
View File

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

15
7zip/UI/Console/resource.h Executable file
View File

@@ -0,0 +1,15 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by resource.rc
//
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

121
7zip/UI/Console/resource.rc Executable file
View File

@@ -0,0 +1,121 @@
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// Russian resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)
#ifdef _WIN32
LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
#pragma code_page(1251)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
#endif // Russian resources
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
#ifndef _MAC
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,12,0,0
PRODUCTVERSION 3,12,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x40004L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "Comments", "\0"
VALUE "CompanyName", "Igor Pavlov\0"
VALUE "FileDescription", "7-Zip Console version\0"
VALUE "FileVersion", "3, 12, 0, 0\0"
VALUE "InternalName", "7z\0"
VALUE "LegalCopyright", "Copyright (C) 1999-2003 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 "SpecialBuild", "\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
#endif // !_MAC
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"><assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="7-Zip.7-Zip.7-zip" type="win32"/><description>7-Zip Extension.</description><dependency> <dependentAssembly><assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*"/></dependentAssembly></dependency></assembly>

686
7zip/UI/Explorer/ContextMenu.cpp Executable file
View File

@@ -0,0 +1,686 @@
// ContextMenu.cpp
#include "StdAfx.h"
#include "ContextMenu.h"
#include "Common/StringConvert.h"
#include "Common/MyCom.h"
#include "Windows/Shell.h"
#include "Windows/Memory.h"
#include "Windows/COM.h"
#include "Windows/FileFind.h"
#include "Windows/FileDir.h"
#include "Windows/FileName.h"
#include "Windows/System.h"
#include "Windows/Thread.h"
#include "Windows/Window.h"
#include "Windows/Menu.h"
#include "Windows/ResourceString.h"
#include "../../FileManager/FormatUtils.h"
#include "../../FileManager/ProgramLocation.h"
#include "../Common/ZipRegistry.h"
#include "../Common/ArchiveName.h"
#ifdef LANG
#include "../../FileManager/LangUtils.h"
#endif
#include "resource.h"
#include "ContextMenuFlags.h"
// #include "ExtractEngine.h"
// #include "TestEngine.h"
// #include "CompressEngine.h"
#include "MyMessages.h"
#include "../Resource/Extract/resource.h"
#include "../Common/CompressCall.h"
using namespace NWindows;
static LPCTSTR kFileClassIDString = TEXT("SevenZip");
///////////////////////////////
// IShellExtInit
HRESULT CZipContextMenu::GetFileNames(LPDATAOBJECT dataObject,
CSysStringVector &fileNames)
{
fileNames.Clear();
if(dataObject == NULL)
return E_FAIL;
FORMATETC fmte = {CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
NCOM::CStgMedium stgMedium;
HRESULT result = dataObject->GetData(&fmte, &stgMedium);
if (result != S_OK)
return result;
stgMedium._mustBeReleased = true;
NShell::CDrop drop(false);
NMemory::CGlobalLock globalLock(stgMedium->hGlobal);
drop.Attach((HDROP)globalLock.GetPointer());
drop.QueryFileNames(fileNames);
return S_OK;
}
STDMETHODIMP CZipContextMenu::Initialize(LPCITEMIDLIST pidlFolder,
LPDATAOBJECT dataObject, HKEY hkeyProgID)
{
/*
m_IsFolder = false;
if (pidlFolder == 0)
*/
// pidlFolder is NULL :(
CSysStringVector sysFileNames;
RINOK(GetFileNames(dataObject, sysFileNames));
_fileNames.Clear();
_fileNames.Reserve(sysFileNames.Size());
for (int i = 0; i < sysFileNames.Size(); i++)
_fileNames.Add(GetUnicodeString(sysFileNames[i]));
return S_OK;
}
STDMETHODIMP CZipContextMenu::InitContextMenu(const wchar_t *folder,
const wchar_t **names, UINT32 numFiles)
{
_fileNames.Clear();
for (UINT32 i = 0; i < numFiles; i++)
_fileNames.Add(names[i]);
return S_OK;
}
/////////////////////////////
// IContextMenu
static LPCWSTR kMainVerb = L"SevenZip";
/*
static LPCTSTR kOpenVerb = TEXT("SevenOpen");
static LPCTSTR kExtractVerb = TEXT("SevenExtract");
static LPCTSTR kExtractHereVerb = TEXT("SevenExtractHere");
static LPCTSTR kExtractToVerb = TEXT("SevenExtractTo");
static LPCTSTR kTestVerb = TEXT("SevenTest");
static LPCTSTR kCompressVerb = TEXT("SevenCompress");
static LPCTSTR kCompressToVerb = TEXT("SevenCompressTo");
static LPCTSTR kCompressEmailVerb = TEXT("SevenCompressEmail");
static LPCTSTR kCompressToEmailVerb = TEXT("SevenCompressToEmail");
*/
struct CContextMenuCommand
{
UINT32 flag;
CZipContextMenu::ECommandInternalID CommandInternalID;
LPCWSTR Verb;
UINT ResourceID;
UINT ResourceHelpID;
UINT32 LangID;
};
static CContextMenuCommand g_Commands[] =
{
{
NContextMenuFlags::kOpen,
CZipContextMenu::kOpen,
L"Open",
IDS_CONTEXT_OPEN,
IDS_CONTEXT_OPEN_HELP,
0x02000103
},
{
NContextMenuFlags::kExtract,
CZipContextMenu::kExtract,
L"Extract",
IDS_CONTEXT_EXTRACT,
IDS_CONTEXT_EXTRACT_HELP,
0x02000105
},
{
NContextMenuFlags::kExtractHere,
CZipContextMenu::kExtractHere,
L"ExtractHere",
IDS_CONTEXT_EXTRACT_HERE,
IDS_CONTEXT_EXTRACT_HERE_HELP,
0x0200010B
},
{
NContextMenuFlags::kExtractTo,
CZipContextMenu::kExtractTo,
L"ExtractTo",
IDS_CONTEXT_EXTRACT_TO,
IDS_CONTEXT_EXTRACT_TO_HELP,
0x0200010D
},
{
NContextMenuFlags::kTest,
CZipContextMenu::kTest,
L"Test",
IDS_CONTEXT_TEST,
IDS_CONTEXT_TEST_HELP,
0x02000109
},
{
NContextMenuFlags::kCompress,
CZipContextMenu::kCompress,
L"Compress",
IDS_CONTEXT_COMPRESS,
IDS_CONTEXT_COMPRESS_HELP,
0x02000107,
},
{
NContextMenuFlags::kCompressTo,
CZipContextMenu::kCompressTo,
L"CompressTo",
IDS_CONTEXT_COMPRESS_TO,
IDS_CONTEXT_COMPRESS_TO_HELP,
0x0200010F
},
{
NContextMenuFlags::kCompressEmail,
CZipContextMenu::kCompressEmail,
L"CompressEmail",
IDS_CONTEXT_COMPRESS_EMAIL,
IDS_CONTEXT_COMPRESS_EMAIL_HELP,
0x02000111
},
{
NContextMenuFlags::kCompressToEmail,
CZipContextMenu::kCompressToEmail,
L"CompressToEmail",
IDS_CONTEXT_COMPRESS_TO_EMAIL,
IDS_CONTEXT_COMPRESS_TO_EMAIL_HELP,
0x02000113
}
};
int FindCommand(CZipContextMenu::ECommandInternalID &id)
{
for (int i = 0; i < sizeof(g_Commands) / sizeof(g_Commands[0]); i++)
if (g_Commands[i].CommandInternalID == id)
return i;
return -1;
}
void CZipContextMenu::FillCommand(ECommandInternalID id,
UString &mainString, CCommandMapItem &commandMapItem)
{
int i = FindCommand(id);
if (i < 0)
return;
const CContextMenuCommand &command = g_Commands[i];
commandMapItem.CommandInternalID = command.CommandInternalID;
commandMapItem.Verb = command.Verb;
commandMapItem.HelpString = LangLoadStringW(command.ResourceHelpID, command.LangID + 1);
mainString = LangLoadStringW(command.ResourceID, command.LangID);
}
void CZipContextMenu::FillCommand2(ECommandInternalID id,
UString &mainString, CCommandMapItem &commandMapItem)
{
int i = FindCommand(id);
if (i < 0)
return;
const CContextMenuCommand &command = g_Commands[i];
commandMapItem.CommandInternalID = command.CommandInternalID;
commandMapItem.Verb = command.Verb;
commandMapItem.HelpString = LangLoadStringW(command.ResourceHelpID, command.LangID + 1);
mainString = LangLoadStringW(command.ResourceID, command.LangID);
}
/*
CSysString GetExtractPath(const CSysString &archiveName)
{
CSysString s;
int dotPos = s.ReverseFind('.');
if (dotPos < 0)
return archiveName;
return archiveName.Left(dotPos);
}
*/
static BOOL MyInsertMenu(HMENU hMenu, int pos, UINT id, LPCTSTR s)
{
MENUITEMINFO menuItem;
menuItem.cbSize = sizeof(menuItem);
menuItem.fType = MFT_STRING;
menuItem.fMask = MIIM_TYPE | MIIM_ID;
menuItem.wID = id;
menuItem.dwTypeData = (LPTSTR)(LPCTSTR)s;
return ::InsertMenuItem(hMenu, pos++, TRUE, &menuItem);
}
static UString GetSubFolderNameForExtract(const UString &archiveName)
{
int dotPos = archiveName.ReverseFind('.');
if (dotPos >= 0)
return archiveName.Left(dotPos);
return archiveName + UString(L"~");
}
STDMETHODIMP CZipContextMenu::QueryContextMenu(HMENU hMenu, UINT indexMenu,
UINT commandIDFirst, UINT commandIDLast, UINT flags)
{
if(_fileNames.Size() == 0)
return E_FAIL;
UINT currentCommandID = commandIDFirst;
if ((flags & 0x000F) != CMF_NORMAL &&
(flags & CMF_VERBSONLY) == 0 &&
(flags & CMF_EXPLORE) == 0)
return MAKE_HRESULT(SEVERITY_SUCCESS, 0, currentCommandID);
_commandMap.clear();
CMenu popupMenu;
CMenuDestroyer menuDestroyer;
bool cascadedMenu = ReadCascadedMenu();
MENUITEMINFO menuItem;
UINT subIndex = indexMenu;
if (cascadedMenu)
{
CCommandMapItem commandMapItem;
if(!popupMenu.CreatePopup())
throw 210503;
menuDestroyer.Attach(popupMenu);
commandMapItem.CommandInternalID = kCommandNULL;
commandMapItem.Verb = kMainVerb;
commandMapItem.HelpString = LangLoadStringW(IDS_CONTEXT_CAPTION_HELP, 0x02000102);
_commandMap.push_back(commandMapItem);
menuItem.wID = currentCommandID++;
subIndex = 0;
}
else
{
popupMenu.Attach(hMenu);
}
UINT32 contextMenuFlags;
if (!ReadContextMenuStatus(contextMenuFlags))
contextMenuFlags = NContextMenuFlags::GetDefaultFlags();
int subMenuIndex = 0;
UString mainString;
if(_fileNames.Size() == 1 && currentCommandID + 6 <= commandIDLast)
{
const UString &fileName = _fileNames.Front();
UString folderPrefix;
NFile::NDirectory::GetOnlyDirPrefix(fileName, folderPrefix);
NFile::NFind::CFileInfoW fileInfo;
if (!NFile::NFind::FindFile(fileName, fileInfo))
return E_FAIL;
if (!fileInfo.IsDirectory())
{
// Open
if ((contextMenuFlags & NContextMenuFlags::kOpen) != 0)
{
CCommandMapItem commandMapItem;
FillCommand(kOpen, mainString, commandMapItem);
MyInsertMenu(popupMenu, subIndex++, currentCommandID++, GetSystemString(mainString));
_commandMap.push_back(commandMapItem);
}
// Extract
if ((contextMenuFlags & NContextMenuFlags::kExtract) != 0)
{
CCommandMapItem commandMapItem;
FillCommand(kExtract, mainString, commandMapItem);
commandMapItem.Folder = folderPrefix +
GetSubFolderNameForExtract(fileInfo.Name) +
UString(L'\\');
MyInsertMenu(popupMenu, subIndex++, currentCommandID++, GetSystemString(mainString));
_commandMap.push_back(commandMapItem);
}
// Extract Here
if ((contextMenuFlags & NContextMenuFlags::kExtractHere) != 0)
{
CCommandMapItem commandMapItem;
FillCommand(kExtractHere, mainString, commandMapItem);
MyInsertMenu(popupMenu, subIndex++, currentCommandID++, GetSystemString(mainString));
commandMapItem.Folder = folderPrefix;
_commandMap.push_back(commandMapItem);
}
// Extract To
if ((contextMenuFlags & NContextMenuFlags::kExtractTo) != 0)
{
CCommandMapItem commandMapItem;
UString s;
FillCommand2(kExtractTo, s, commandMapItem);
UString folder = GetSubFolderNameForExtract(fileInfo.Name) +
UString(L'\\');
commandMapItem.Folder = folderPrefix + folder;
s = MyFormatNew(s, folder);
MyInsertMenu(popupMenu, subIndex++, currentCommandID++, GetSystemString(s));
_commandMap.push_back(commandMapItem);
}
// Test
if ((contextMenuFlags & NContextMenuFlags::kTest) != 0)
{
CCommandMapItem commandMapItem;
FillCommand(kTest, mainString, commandMapItem);
MyInsertMenu(popupMenu, subIndex++, currentCommandID++, GetSystemString(mainString));
_commandMap.push_back(commandMapItem);
}
}
}
if(_fileNames.Size() > 0 && currentCommandID + 6 <= commandIDLast)
{
const UString &fileName = _fileNames.Front();
UString archiveName = CreateArchiveName(fileName, _fileNames.Size() > 1, false);
UString archiveName7z = archiveName + L".7z";
UString archivePathPrefix;
NFile::NDirectory::GetOnlyDirPrefix(fileName, archivePathPrefix);
// Compress
if ((contextMenuFlags & NContextMenuFlags::kCompress) != 0)
{
CCommandMapItem commandMapItem;
commandMapItem.Archive = archivePathPrefix + archiveName;
FillCommand(kCompress, mainString, commandMapItem);
MyInsertMenu(popupMenu, subIndex++, currentCommandID++, GetSystemString(mainString));
_commandMap.push_back(commandMapItem);
}
// CompressTo
if (contextMenuFlags & NContextMenuFlags::kCompressTo)
{
CCommandMapItem commandMapItem;
UString s;
FillCommand2(kCompressTo, s, commandMapItem);
commandMapItem.Archive = archivePathPrefix + archiveName7z;
UString t = UString(L"\"") + archiveName7z + UString(L"\"");
s = MyFormatNew(s, t);
MyInsertMenu(popupMenu, subIndex++, currentCommandID++, GetSystemString(s));
_commandMap.push_back(commandMapItem);
}
// CompressEmail
if ((contextMenuFlags & NContextMenuFlags::kCompressEmail) != 0)
{
CCommandMapItem commandMapItem;
commandMapItem.Archive = archiveName;
FillCommand(kCompressEmail, mainString, commandMapItem);
MyInsertMenu(popupMenu, subIndex++, currentCommandID++, GetSystemString(mainString));
_commandMap.push_back(commandMapItem);
}
// CompressToEmail
if ((contextMenuFlags & NContextMenuFlags::kCompressToEmail) != 0)
{
CCommandMapItem commandMapItem;
UString s;
FillCommand2(kCompressToEmail, s, commandMapItem);
commandMapItem.Archive = archiveName7z;
UString t = UString(L"\"") + archiveName7z + UString(L"\"");
s = MyFormatNew(s, t);
MyInsertMenu(popupMenu, subIndex++, currentCommandID++, GetSystemString(s));
_commandMap.push_back(commandMapItem);
}
}
CSysString popupMenuCaption = LangLoadString(IDS_CONTEXT_POPUP_CAPTION, 0x02000101);
// don't use InsertMenu: See MSDN:
// PRB: Duplicate Menu Items In the File Menu For a Shell Context Menu Extension
// ID: Q214477
if (cascadedMenu)
{
MENUITEMINFO menuItem;
menuItem.cbSize = sizeof(menuItem);
menuItem.fType = MFT_STRING;
menuItem.fMask = MIIM_SUBMENU | MIIM_TYPE | MIIM_ID;
menuItem.wID = currentCommandID++;
menuItem.hSubMenu = popupMenu.Detach();
menuDestroyer.Disable();
menuItem.dwTypeData = (LPTSTR)(LPCTSTR)popupMenuCaption;
::InsertMenuItem(hMenu, indexMenu++, TRUE, &menuItem);
}
return MAKE_HRESULT(SEVERITY_SUCCESS, 0, currentCommandID - commandIDFirst);
}
UINT CZipContextMenu::FindVerb(const UString &verb)
{
for(int i = 0; i < _commandMap.size(); i++)
if(_commandMap[i].Verb.Compare(verb) == 0)
return i;
return -1;
}
extern const char *kShellFolderClassIDString;
/*
class CWindowDisable
{
bool m_WasEnabled;
CWindow m_Window;
public:
CWindowDisable(HWND aWindow): m_Window(aWindow)
{
m_WasEnabled = m_Window.IsEnabled();
if (m_WasEnabled)
m_Window.Enable(false);
}
~CWindowDisable()
{
if (m_WasEnabled)
m_Window.Enable(true);
}
};
*/
/*
struct CThreadCompressMain
{
CSysStringVector FileNames;
DWORD Process()
{
NCOM::CComInitializer comInitializer;
try
{
HRESULT result = CompressArchive(FileNames);
}
catch(...)
{
MyMessageBox(IDS_ERROR, 0x02000605);
}
return 0;
}
static DWORD WINAPI MyThreadFunction(void *param)
{
CThreadCompressMain *compressor = (CThreadCompressMain *)param;
return ((CThreadCompressMain *)param)->Process();
delete compressor;
}
};
*/
static bool IsItWindowsNT()
{
OSVERSIONINFO versionInfo;
versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);
if (!::GetVersionEx(&versionInfo))
return false;
return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);
}
static UString GetProgramCommand()
{
UString path = L"\"";
UString folder;
if (GetProgramFolderPath(folder))
path += folder;
if (IsItWindowsNT())
path += L"7zFMn.exe";
else
path += L"7zFM.exe";
path += L"\"";
return path;
}
STDMETHODIMP CZipContextMenu::InvokeCommand(LPCMINVOKECOMMANDINFO commandInfo)
{
int commandOffset;
if(HIWORD(commandInfo->lpVerb) == 0)
commandOffset = LOWORD(commandInfo->lpVerb);
else
commandOffset = FindVerb(GetUnicodeString(commandInfo->lpVerb));
/*
#ifdef _UNICODE
if(commandInfo->cbSize == sizeof(CMINVOKECOMMANDINFOEX))
{
if ((commandInfo->fMask & CMIC_MASK_UNICODE) != 0)
{
LPCMINVOKECOMMANDINFOEX aCommandInfoEx = (LPCMINVOKECOMMANDINFOEX)commandInfo;
if(HIWORD(aCommandInfoEx->lpVerb) == 0)
commandOffset = LOWORD(aCommandInfoEx->lpVerb);
else
{
MessageBox(0, TEXT("1"), TEXT("1"), 0);
return E_FAIL;
}
}
else
{
if(HIWORD(commandInfo->lpVerb) == 0)
commandOffset = LOWORD(commandInfo->lpVerb);
else
commandOffset = FindVerb(GetSystemString(commandInfo->lpVerb));
}
// return E_FAIL;
}
else
{
if(HIWORD(commandInfo->lpVerb) == 0)
commandOffset = LOWORD(commandInfo->lpVerb);
else
commandOffset = FindVerb(GetSystemString(commandInfo->lpVerb));
}
#else
{
if(HIWORD(commandInfo->lpVerb) == 0)
commandOffset = LOWORD(commandInfo->lpVerb);
else
commandOffset = FindVerb(commandInfo->lpVerb);
}
#endif
*/
if(commandOffset < 0 || commandOffset >= _commandMap.size())
return E_FAIL;
const CCommandMapItem commandMapItem = _commandMap[commandOffset];
ECommandInternalID commandInternalID = commandMapItem.CommandInternalID;
HWND aHWND = commandInfo->hwnd;
// CWindowDisable aWindowDisable(aHWND);
try
{
switch(commandInternalID)
{
case kOpen:
{
UString params;
params = GetProgramCommand();
params += L" \"";
params += _fileNames[0];
params += L"\"";
MyCreateProcess(params);
break;
}
case kExtract:
case kExtractHere:
case kExtractTo:
{
ExtractArchive(_fileNames[0], commandMapItem.Folder,
(commandInternalID == kExtract));
break;
}
case kTest:
{
TestArchive(_fileNames[0]);
break;
}
case kCompress:
case kCompressTo:
case kCompressEmail:
case kCompressToEmail:
{
bool email = (commandInternalID == kCompressEmail) ||
(commandInternalID == kCompressToEmail);
bool showDialog = (commandInternalID == kCompress) ||
(commandInternalID == kCompressEmail);
CompressFiles(commandMapItem.Archive, _fileNames, email, showDialog);
break;
}
}
}
catch(...)
{
MyMessageBox(IDS_ERROR, 0x02000605);
}
return S_OK;
}
static void MyCopyString(void *dest, const wchar_t *src, bool writeInUnicode)
{
if(writeInUnicode)
{
wcscpy((wchar_t *)dest, src);
}
else
lstrcpyA((char *)dest, GetAnsiString(src));
}
STDMETHODIMP CZipContextMenu::GetCommandString(UINT commandOffset, UINT uType,
UINT *pwReserved, LPSTR pszName, UINT cchMax)
{
switch(uType)
{
case GCS_VALIDATEA:
case GCS_VALIDATEW:
if(commandOffset < 0 || commandOffset >= (UINT)_commandMap.size())
return S_FALSE;
else
return S_OK;
}
if(commandOffset < 0 || commandOffset >= (UINT)_commandMap.size())
return E_FAIL;
if(uType == GCS_HELPTEXTA || uType == GCS_HELPTEXTW)
{
MyCopyString(pszName, _commandMap[commandOffset].HelpString,
uType == GCS_HELPTEXTW);
return NO_ERROR;
}
if(uType == GCS_VERBA || uType == GCS_VERBW)
{
MyCopyString(pszName, _commandMap[commandOffset].Verb,
uType == GCS_VERBW);
return NO_ERROR;
}
return E_FAIL;
}

92
7zip/UI/Explorer/ContextMenu.h Executable file
View File

@@ -0,0 +1,92 @@
// ContextMenu.h
#pragma once
#ifndef __CONTEXTMENU_H
#define __CONTEXTMENU_H
// {23170F69-40C1-278A-1000-000100020000}
DEFINE_GUID(CLSID_CZipContextMenu,
0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00);
#include "Common/String.h"
#include "../../FileManager/PluginInterface.h"
class CZipContextMenu:
public IContextMenu,
public IShellExtInit,
public IInitContextMenu,
public CComObjectRoot,
public CComCoClass<CZipContextMenu, &CLSID_CZipContextMenu>
{
public:
enum ECommandInternalID
{
kCommandNULL,
kOpen,
kExtract,
kExtractHere,
kExtractTo,
kTest,
kCompress,
kCompressTo,
kCompressEmail,
kCompressToEmail
};
struct CCommandMapItem
{
ECommandInternalID CommandInternalID;
UString Verb;
UString HelpString;
UString Folder;
UString Archive;
};
BEGIN_COM_MAP(CZipContextMenu)
COM_INTERFACE_ENTRY(IContextMenu)
COM_INTERFACE_ENTRY(IShellExtInit)
COM_INTERFACE_ENTRY(IInitContextMenu)
END_COM_MAP()
DECLARE_NOT_AGGREGATABLE(CZipContextMenu)
DECLARE_REGISTRY(CZipContextMenu,
// _T("SevenZip.ContextMenu.1"), _T("SevenZip.ContextMenu"),
TEXT("SevenZip.1"), TEXT("SevenZip"),
UINT(0), THREADFLAGS_APARTMENT)
///////////////////////////////
// IShellExtInit
STDMETHOD(Initialize)(LPCITEMIDLIST pidlFolder,
LPDATAOBJECT dataObject, HKEY hkeyProgID);
/////////////////////////////
// IContextMenu
STDMETHOD(QueryContextMenu)(HMENU hmenu, UINT indexMenu,
UINT idCmdFirst, UINT idCmdLast, UINT uFlags);
STDMETHOD(InvokeCommand)(LPCMINVOKECOMMANDINFO lpici);
STDMETHOD(GetCommandString)(UINT idCmd, UINT uType, UINT *pwReserved,
LPSTR pszName, UINT cchMax);
// IInitContextMenu
STDMETHOD(InitContextMenu)(const wchar_t *folder, const wchar_t **names, UINT32 numFiles);
private:
UStringVector _fileNames;
std::vector<CCommandMapItem> _commandMap;
HRESULT GetFileNames(LPDATAOBJECT dataObject, CSysStringVector &fileNames);
UINT FindVerb(const UString &verb);
void FillCommand(ECommandInternalID id, UString &mainString,
CCommandMapItem &commandMapItem);
void FillCommand2(ECommandInternalID id, UString &mainString,
CCommandMapItem &commandMapItem);
};
#endif

View File

@@ -0,0 +1,28 @@
// ContextMenuFlags.h
#pragma once
#ifndef __SEVENZIP_CONTEXTMENUFLAGS_H
#define __SEVENZIP_CONTEXTMENUFLAGS_H
namespace NContextMenuFlags
{
const UINT32 kExtract = 1 << 0;
const UINT32 kExtractHere = 1 << 1;
const UINT32 kExtractTo = 1 << 2;
// const UINT32 kExtractEach = 1 << 3;
const UINT32 kTest = 1 << 4;
const UINT32 kOpen = 1 << 5;
const UINT32 kCompress = 1 << 8;
const UINT32 kCompressTo = 1 << 9;
const UINT32 kCompressEmail = 1 << 10;
const UINT32 kCompressToEmail = 1 << 11;
inline UINT32 GetDefaultFlags() {
return kOpen | kExtract | kExtractHere | kCompress | kTest; }
}
#endif

152
7zip/UI/Explorer/DllExports.cpp Executable file
View File

@@ -0,0 +1,152 @@
// DLLExports.cpp : Implementation of DLL Exports.
#include "StdAfx.h"
// #include <locale.h>
#include <initguid.h>
#include <ShlGuid.h>
#include <windows.h>
// #include "../../Compress/Interface/CompressInterface.h"
#include "../../IPassword.h"
#include "../Agent/Agent.h"
#include "Common/ComTry.h"
#include "ContextMenu.h"
#include "OptionsDialog.h"
CComModule _Module;
BEGIN_OBJECT_MAP(ObjectMap)
// OBJECT_ENTRY(CLSID_CAgentArchiveHandler, CAgent)
OBJECT_ENTRY(CLSID_CZipContextMenu, CZipContextMenu)
// OBJECT_ENTRY(CLSID_CSevenZipOptions, CSevenZipOptions)
END_OBJECT_MAP()
/////////////////////////////////////////////////////////////////////////////
// DLL Entry Point
HINSTANCE g_hInstance;
static bool IsItWindowsNT()
{
OSVERSIONINFO aVersionInfo;
aVersionInfo.dwOSVersionInfoSize = sizeof(aVersionInfo);
if (!::GetVersionEx(&aVersionInfo))
return false;
return (aVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);
}
extern "C"
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID)
{
// setlocale(LC_COLLATE, ".ACP");
g_hInstance = hInstance;
if (dwReason == DLL_PROCESS_ATTACH)
{
#ifdef UNICODE
if (!IsItWindowsNT())
return FALSE;
#endif
_Module.Init(ObjectMap, hInstance);
//DisableThreadLibraryCalls(hInstance);
}
else if (dwReason == DLL_PROCESS_DETACH)
_Module.Term();
return TRUE; // ok
}
/////////////////////////////////////////////////////////////////////////////
// Used to determine whether the DLL can be unloaded by OLE
STDAPI DllCanUnloadNow(void)
{
return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
}
/////////////////////////////////////////////////////////////////////////////
// Returns a class factory to create an object of the requested type
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
return _Module.GetClassObject(rclsid, riid, ppv);
}
STDAPI DllRegisterServer(void)
{
return _Module.RegisterServer(FALSE);
}
/////////////////////////////////////////////////////////////////////////////
// DllUnregisterServer - Removes entries from the system registry
STDAPI DllUnregisterServer(void)
{
return _Module.UnregisterServer();
}
STDAPI CreateObject(
const GUID *classID,
const GUID *interfaceID,
void **outObject)
{
COM_TRY_BEGIN
*outObject = 0;
if (*classID == CLSID_CAgentArchiveHandler)
{
if (*interfaceID == IID_IFolderManager)
{
CMyComPtr<IFolderManager> manager = new CArchiveFolderManager;
*outObject = manager.Detach();
return S_OK;
}
return E_NOINTERFACE;
}
if (*classID == CLSID_CSevenZipOptions)
{
if (*interfaceID == IID_IPluginOptions)
{
CMyComPtr<IPluginOptions> options = new CSevenZipOptions;
*outObject = options.Detach();
return S_OK;
}
return E_NOINTERFACE;
}
return CLASS_E_CLASSNOTAVAILABLE;
COM_TRY_END
}
STDAPI GetPluginProperty(PROPID propID, PROPVARIANT *value)
{
::VariantClear((tagVARIANT *)value);
switch(propID)
{
case NPlugin::kName:
if ((value->bstrVal = ::SysAllocString(L"7-Zip")) != 0)
value->vt = VT_BSTR;
return S_OK;
case NPlugin::kClassID:
{
if ((value->bstrVal = ::SysAllocStringByteLen(
(const char *)&CLSID_CAgentArchiveHandler, sizeof(GUID))) != 0)
value->vt = VT_BSTR;
return S_OK;
}
case NPlugin::kOptionsClassID:
{
if ((value->bstrVal = ::SysAllocStringByteLen(
(const char *)&CLSID_CSevenZipOptions, sizeof(GUID))) != 0)
value->vt = VT_BSTR;
return S_OK;
}
/*
case NArchive::kType:
propVariant = UINT32(0);
break;
*/
}
return S_OK;
}

12
7zip/UI/Explorer/Explorer.def Executable file
View File

@@ -0,0 +1,12 @@
; 7-zip.def
LIBRARY "7-zip"
EXPORTS
DllCanUnloadNow PRIVATE
DllGetClassObject PRIVATE
DllRegisterServer PRIVATE
DllUnregisterServer PRIVATE
CreateObject PRIVATE
GetPluginProperty PRIVATE

807
7zip/UI/Explorer/Explorer.dsp Executable file
View File

@@ -0,0 +1,807 @@
# Microsoft Developer Studio Project File - Name="Explorer" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
CFG=Explorer - Win32 DebugU
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "Explorer.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "Explorer.mak" CFG="Explorer - Win32 DebugU"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "Explorer - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE "Explorer - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE "Explorer - Win32 ReleaseU" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE "Explorer - Win32 DebugU" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "Explorer - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 1
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXPLORER_EXPORTS" /YX /FD /c
# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I "..\..\..\\" /D "NDEBUG" /D "_MBCS" /D "WIN32" /D "_WINDOWS" /D "_USRDLL" /D "EXPLORER_EXPORTS" /D "LANG" /D "NEW_FOLDER_INTERFACE" /Yu"StdAfx.h" /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x419 /d "NDEBUG"
# ADD RSC /l 0x419 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib htmlhelp.lib /nologo /dll /machine:I386 /out:"C:\Program Files\7-ZIP\7-Zip.dll" /opt:NOWIN98
# SUBTRACT LINK32 /pdb:none
!ELSEIF "$(CFG)" == "Explorer - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 1
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXPLORER_EXPORTS" /YX /FD /GZ /c
# ADD CPP /nologo /Gz /MTd /W3 /Gm /GX /ZI /Od /I "..\..\..\\" /D "_DEBUG" /D "_MBCS" /D "WIN32" /D "_WINDOWS" /D "_USRDLL" /D "EXPLORER_EXPORTS" /D "LANG" /D "NEW_FOLDER_INTERFACE" /Yu"StdAfx.h" /FD /GZ /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x419 /d "_DEBUG"
# ADD RSC /l 0x419 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib htmlhelp.lib /nologo /dll /debug /machine:I386 /out:"C:\Program Files\7-ZIP\7-Zip.dll" /pdbtype:sept
!ELSEIF "$(CFG)" == "Explorer - Win32 ReleaseU"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "ReleaseU"
# PROP BASE Intermediate_Dir "ReleaseU"
# PROP BASE Ignore_Export_Lib 1
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "ReleaseU"
# PROP Intermediate_Dir "ReleaseU"
# PROP Ignore_Export_Lib 1
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_USRDLL" /D "EXPLORER_EXPORTS" /D "LANG" /D "_MBCS" /Yu"StdAfx.h" /FD /c
# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I "..\..\..\\" /D "NDEBUG" /D "_UNICODE" /D "UNICODE" /D "WIN32" /D "_WINDOWS" /D "_USRDLL" /D "EXPLORER_EXPORTS" /D "LANG" /D "NEW_FOLDER_INTERFACE" /Yu"StdAfx.h" /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x419 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib htmlhelp.lib /nologo /dll /machine:I386 /out:"C:\Program Files\7-ZIP\7-Zip.dll" /opt:NOWIN98
# SUBTRACT BASE LINK32 /pdb:none
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib htmlhelp.lib /nologo /dll /machine:I386 /out:"C:\Program Files\7-ZIP\7-Zipn.dll" /opt:NOWIN98
# SUBTRACT LINK32 /pdb:none
!ELSEIF "$(CFG)" == "Explorer - Win32 DebugU"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "DebugU"
# PROP BASE Intermediate_Dir "DebugU"
# PROP BASE Ignore_Export_Lib 1
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "DebugU"
# PROP Intermediate_Dir "DebugU"
# PROP Ignore_Export_Lib 1
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_USRDLL" /D "EXPLORER_EXPORTS" /D "LANG" /D "_MBCS" /Yu"StdAfx.h" /FD /GZ /c
# ADD CPP /nologo /Gz /MTd /W3 /Gm /GX /ZI /Od /I "..\..\..\\" /D "_DEBUG" /D "_UNICODE" /D "UNICODE" /D "WIN32" /D "_WINDOWS" /D "_USRDLL" /D "EXPLORER_EXPORTS" /D "LANG" /D "NEW_FOLDER_INTERFACE" /Yu"StdAfx.h" /FD /GZ /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x419 /d "_DEBUG"
# ADD RSC /l 0x419 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib htmlhelp.lib /nologo /dll /debug /machine:I386 /out:"C:\Program Files\7-ZIP\7-Zip.dll" /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib htmlhelp.lib /nologo /dll /debug /machine:I386 /out:"C:\Program Files\7-ZIP\7-Zipn.dll" /pdbtype:sept
!ENDIF
# Begin Target
# Name "Explorer - Win32 Release"
# Name "Explorer - Win32 Debug"
# Name "Explorer - Win32 ReleaseU"
# Name "Explorer - Win32 DebugU"
# Begin Group "Spec"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\DllExports.cpp
# End Source File
# Begin Source File
SOURCE=.\Explorer.def
# End Source File
# Begin Source File
SOURCE=.\resource.h
# End Source File
# Begin Source File
SOURCE=.\resource.rc
# End Source File
# Begin Source File
SOURCE=.\StdAfx.cpp
# ADD CPP /Yc"StdAfx.h"
# End Source File
# Begin Source File
SOURCE=.\StdAfx.h
# End Source File
# End Group
# Begin Group "UI Common"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\Common\ArchiveName.cpp
# End Source File
# Begin Source File
SOURCE=..\Common\ArchiveName.h
# End Source File
# Begin Source File
SOURCE=..\Common\ArchiverInfo.cpp
# End Source File
# Begin Source File
SOURCE=..\Common\ArchiverInfo.h
# End Source File
# Begin Source File
SOURCE=..\Common\CompressCall.cpp
# End Source File
# Begin Source File
SOURCE=..\Common\CompressCall.h
# End Source File
# Begin Source File
SOURCE=..\Common\DefaultName.cpp
# End Source File
# Begin Source File
SOURCE=..\Common\DefaultName.h
# End Source File
# Begin Source File
SOURCE=..\Common\EnumDirItems.cpp
# End Source File
# Begin Source File
SOURCE=..\Common\EnumDirItems.h
# End Source File
# Begin Source File
SOURCE=..\Common\ExtractingFilePath.cpp
# End Source File
# Begin Source File
SOURCE=..\Common\ExtractingFilePath.h
# End Source File
# Begin Source File
SOURCE=..\Common\HandlerLoader.h
# End Source File
# Begin Source File
SOURCE=..\Common\OpenArchive.cpp
# End Source File
# Begin Source File
SOURCE=..\Common\OpenArchive.h
# End Source File
# Begin Source File
SOURCE=..\Common\PropIDUtils.cpp
# End Source File
# Begin Source File
SOURCE=..\Common\PropIDUtils.h
# End Source File
# Begin Source File
SOURCE=..\Common\SortUtils.cpp
# End Source File
# Begin Source File
SOURCE=..\Common\SortUtils.h
# End Source File
# Begin Source File
SOURCE=..\Common\UpdateAction.cpp
# End Source File
# Begin Source File
SOURCE=..\Common\UpdateAction.h
# End Source File
# Begin Source File
SOURCE=..\Common\UpdatePair.cpp
# End Source File
# Begin Source File
SOURCE=..\Common\UpdatePair.h
# End Source File
# Begin Source File
SOURCE=..\Common\UpdateProduce.cpp
# End Source File
# Begin Source File
SOURCE=..\Common\UpdateProduce.h
# End Source File
# Begin Source File
SOURCE=..\Common\WorkDir.cpp
# End Source File
# Begin Source File
SOURCE=..\Common\WorkDir.h
# End Source File
# Begin Source File
SOURCE=..\Common\ZipRegistry.cpp
# End Source File
# Begin Source File
SOURCE=..\Common\ZipRegistry.h
# End Source File
# Begin Source File
SOURCE=..\Common\ZipSettings.h
# End Source File
# End Group
# Begin Group "Engine"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\ContextMenu.cpp
# End Source File
# Begin Source File
SOURCE=.\ContextMenu.h
# End Source File
# Begin Source File
SOURCE=.\MyMessages.cpp
# End Source File
# Begin Source File
SOURCE=.\MyMessages.h
# End Source File
# End Group
# Begin Group "Dialogs"
# PROP Default_Filter ""
# Begin Group "Options"
# PROP Default_Filter ""
# Begin Group "SystemPage"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\SystemPage\resource.h
# End Source File
# Begin Source File
SOURCE=.\SystemPage\resource.rc
# PROP Exclude_From_Build 1
# End Source File
# Begin Source File
SOURCE=.\SystemPage\SystemPage.cpp
# End Source File
# Begin Source File
SOURCE=.\SystemPage\SystemPage.h
# End Source File
# End Group
# Begin Group "FoldersPage"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\FoldersPage\FoldersPage.cpp
# End Source File
# Begin Source File
SOURCE=.\FoldersPage\FoldersPage.h
# End Source File
# Begin Source File
SOURCE=.\FoldersPage\resource.h
# End Source File
# Begin Source File
SOURCE=.\FoldersPage\resource.rc
# PROP Exclude_From_Build 1
# End Source File
# End Group
# End Group
# End Group
# Begin Group "Agent"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\Agent\Agent.cpp
# End Source File
# Begin Source File
SOURCE=..\Agent\Agent.h
# End Source File
# Begin Source File
SOURCE=..\Agent\AgentOut.cpp
# End Source File
# Begin Source File
SOURCE=..\Agent\AgentProxy.cpp
# End Source File
# Begin Source File
SOURCE=..\Agent\AgentProxy.h
# End Source File
# Begin Source File
SOURCE=..\Agent\ArchiveExtractCallback.cpp
# End Source File
# Begin Source File
SOURCE=..\Agent\ArchiveExtractCallback.h
# End Source File
# Begin Source File
SOURCE=..\Agent\ArchiveFolder.cpp
# End Source File
# Begin Source File
SOURCE=..\Agent\ArchiveFolderOpen.cpp
# End Source File
# Begin Source File
SOURCE=..\Agent\ArchiveFolderOut.cpp
# End Source File
# Begin Source File
SOURCE=..\Agent\ArchiveUpdateCallback.cpp
# End Source File
# Begin Source File
SOURCE=..\Agent\ArchiveUpdateCallback.h
# End Source File
# Begin Source File
SOURCE=..\Agent\IFolderArchive.h
# End Source File
# End Group
# Begin Group "Spec Interfaces"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\Format\Common\ArchiveInterface.h
# End Source File
# Begin Source File
SOURCE=..\Common\ArchiveStyleDirItemInfo.h
# End Source File
# Begin Source File
SOURCE=..\..\Compress\Interface\CompressInterface.h
# End Source File
# Begin Source File
SOURCE=..\Common\FolderArchiveInterface.h
# End Source File
# Begin Source File
SOURCE=..\Format\Common\FormatCryptoInterface.h
# End Source File
# End Group
# Begin Group "FileManager"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\..\FileManager\FormatUtils.cpp
# End Source File
# Begin Source File
SOURCE=..\..\FileManager\FormatUtils.h
# End Source File
# Begin Source File
SOURCE=..\..\FileManager\HelpUtils.cpp
# End Source File
# Begin Source File
SOURCE=..\..\FileManager\HelpUtils.h
# End Source File
# Begin Source File
SOURCE=..\..\FileManager\IFolder.h
# End Source File
# Begin Source File
SOURCE=..\..\FileManager\LangUtils.cpp
# End Source File
# Begin Source File
SOURCE=..\..\FileManager\LangUtils.h
# End Source File
# Begin Source File
SOURCE=..\..\FileManager\ProgramLocation.cpp
# End Source File
# Begin Source File
SOURCE=..\..\FileManager\ProgramLocation.h
# End Source File
# Begin Source File
SOURCE=..\..\FileManager\RegistryUtils.cpp
# End Source File
# Begin Source File
SOURCE=..\..\FileManager\RegistryUtils.h
# End Source File
# End Group
# Begin Group "SDK"
# PROP Default_Filter ""
# Begin Group "Common"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\..\..\Common\IntToString.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\IntToString.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\Lang.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\Lang.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\MyCom.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\NewHandler.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\NewHandler.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\Random.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\Random.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\StdInStream.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\StdInStream.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\String.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\String.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\StringConvert.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\StringConvert.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\TextConfig.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\TextConfig.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\Types.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\UTFConvert.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\UTFConvert.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\Vector.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\Vector.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\Wildcard.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\Wildcard.h
# End Source File
# End Group
# Begin Group "Windows"
# PROP Default_Filter ""
# Begin Group "Control"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\..\..\Windows\Control\Dialog.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\Control\Dialog.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\Control\PropertyPage.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\Control\PropertyPage.h
# End Source File
# End Group
# Begin Source File
SOURCE=..\..\..\Windows\DLL.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\DLL.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\Error.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\Error.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\FileDir.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\FileDir.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\FileFind.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\FileFind.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\FileIO.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\FileIO.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\FileMapping.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\FileMapping.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\FileName.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\FileName.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\Menu.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\PropVariant.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\PropVariant.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\PropVariantConversions.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\PropVariantConversions.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\Registry.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\Registry.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\ResourceString.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\ResourceString.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\Shell.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\Shell.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\Synchronization.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\System.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\System.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\Window.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\Window.h
# End Source File
# End Group
# End Group
# Begin Group "7-zip common"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\..\Common\FilePathAutoRename.cpp
# End Source File
# Begin Source File
SOURCE=..\..\Common\FilePathAutoRename.h
# End Source File
# Begin Source File
SOURCE=..\..\Common\FileStreams.cpp
# End Source File
# Begin Source File
SOURCE=..\..\Common\FileStreams.h
# End Source File
# End Group
# Begin Group "Compress"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\..\Compress\Copy\CopyCoder.cpp
# End Source File
# Begin Source File
SOURCE=..\..\Compress\Copy\CopyCoder.h
# End Source File
# End Group
# Begin Source File
SOURCE=".\7-zip.dll.manifest"
# End Source File
# Begin Source File
SOURCE=.\ContextMenuFlags.h
# End Source File
# Begin Source File
SOURCE=.\OptionsDialog.cpp
# End Source File
# Begin Source File
SOURCE=.\OptionsDialog.h
# End Source File
# Begin Source File
SOURCE=.\RegistryContextMenu..cpp
# End Source File
# Begin Source File
SOURCE=.\RegistryContextMenu.h
# End Source File
# End Target
# End Project

29
7zip/UI/Explorer/Explorer.dsw Executable file
View File

@@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "Explorer"=".\Explorer.dsp" - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View File

@@ -0,0 +1,161 @@
// FoldersDialog.cpp
#include "StdAfx.h"
#include "resource.h"
#include "FoldersPage.h"
#include "Common/StringConvert.h"
#include "Windows/Defs.h"
#include "Windows/Shell.h"
#include "Windows/ResourceString.h"
#include "../../../FileManager/HelpUtils.h"
#include "../../Common/ZipRegistry.h"
#include "../../../FileManager/LangUtils.h"
using namespace NWindows;
static CIDLangPair kIDLangPairs[] =
{
{ IDC_FOLDERS_STATIC_WORKING_FOLDER, 0x01000210 },
{ IDC_FOLDERS_WORK_RADIO_SYSTEM, 0x01000211 },
{ IDC_FOLDERS_WORK_RADIO_CURRENT, 0x01000212 },
{ IDC_FOLDERS_WORK_RADIO_SPECIFIED, 0x01000213 },
{ IDC_FOLDERS_WORK_CHECK_FOR_REMOVABLE, 0x01000214 }
};
static const int kWorkModeButtons[] =
{
IDC_FOLDERS_WORK_RADIO_SYSTEM,
IDC_FOLDERS_WORK_RADIO_CURRENT,
IDC_FOLDERS_WORK_RADIO_SPECIFIED
};
static const int kNumWorkModeButtons = sizeof(kWorkModeButtons) / sizeof(kWorkModeButtons[0]);
bool CFoldersPage::OnInit()
{
LangSetDlgItemsText(HWND(*this), kIDLangPairs, sizeof(kIDLangPairs) / sizeof(kIDLangPairs[0]));
// CZipRegistryManager aRegistryManager;
ReadWorkDirInfo(m_WorkDirInfo);
CheckButton(IDC_FOLDERS_WORK_CHECK_FOR_REMOVABLE, m_WorkDirInfo.ForRemovableOnly);
CheckRadioButton(kWorkModeButtons[0], kWorkModeButtons[kNumWorkModeButtons - 1],
kWorkModeButtons[m_WorkDirInfo.Mode]);
m_WorkPath.Init(*this, IDC_FOLDERS_WORK_EDIT_PATH);
m_ButtonSetWorkPath.Init(*this, IDC_FOLDERS_WORK_BUTTON_PATH);
m_WorkPath.SetText(m_WorkDirInfo.Path);
MyEnableControls();
return CPropertyPage::OnInit();
}
int CFoldersPage::GetWorkMode() const
{
for (int i = 0; i < kNumWorkModeButtons; i++)
if(IsButtonCheckedBool(kWorkModeButtons[i]))
return i;
throw 0;
}
void CFoldersPage::MyEnableControls()
{
bool anEnablePath = (GetWorkMode() == NWorkDir::NMode::kSpecified);
m_WorkPath.Enable(anEnablePath);
m_ButtonSetWorkPath.Enable(anEnablePath);
}
void CFoldersPage::GetWorkDir(NWorkDir::CInfo &aWorkDirInfo)
{
m_WorkPath.GetText(aWorkDirInfo.Path);
aWorkDirInfo.ForRemovableOnly = IsButtonCheckedBool(IDC_FOLDERS_WORK_CHECK_FOR_REMOVABLE);
aWorkDirInfo.Mode = NWorkDir::NMode::EEnum(GetWorkMode());
}
/*
bool CFoldersPage::WasChanged()
{
NWorkDir::CInfo aWorkDirInfo;
GetWorkDir(aWorkDirInfo);
return (aWorkDirInfo.Mode != m_WorkDirInfo.Mode ||
aWorkDirInfo.ForRemovableOnly != m_WorkDirInfo.ForRemovableOnly ||
aWorkDirInfo.Path.Compare(m_WorkDirInfo.Path) != 0);
}
*/
void CFoldersPage::ModifiedEvent()
{
Changed();
/*
if (WasChanged())
Changed();
else
UnChanged();
*/
}
bool CFoldersPage::OnButtonClicked(int aButtonID, HWND aButtonHWND)
{
for (int i = 0; i < kNumWorkModeButtons; i++)
if (aButtonID == kWorkModeButtons[i])
{
MyEnableControls();
ModifiedEvent();
return true;
}
switch(aButtonID)
{
case IDC_FOLDERS_WORK_BUTTON_PATH:
OnFoldersWorkButtonPath();
break;
case IDC_FOLDERS_WORK_CHECK_FOR_REMOVABLE:
break;
default:
return CPropertyPage::OnButtonClicked(aButtonID, aButtonHWND);
}
ModifiedEvent();
return true;
}
bool CFoldersPage::OnCommand(int aCode, int anItemID, LPARAM lParam)
{
if (aCode == EN_CHANGE && anItemID == IDC_FOLDERS_WORK_EDIT_PATH)
{
ModifiedEvent();
return true;
}
return CPropertyPage::OnCommand(aCode, anItemID, lParam);
}
void CFoldersPage::OnFoldersWorkButtonPath()
{
CSysString currentPath;
m_WorkPath.GetText(currentPath);
UString title = LangLoadStringW(IDS_FOLDERS_SET_WORK_PATH_TITLE, 0x01000281);
CSysString resultPath;
if (NShell::BrowseForFolder(HWND(*this), GetSystemString(title),
currentPath, resultPath))
m_WorkPath.SetText(resultPath);
}
LONG CFoldersPage::OnApply()
{
GetWorkDir(m_WorkDirInfo);
SaveWorkDirInfo(m_WorkDirInfo);
return PSNRET_NOERROR;
}
static LPCWSTR kFoldersTopic = L"fm/plugins/7-zip/options.htm#folders";
void CFoldersPage::OnNotifyHelp()
{
ShowHelpWindow(NULL, kFoldersTopic);
}

View File

@@ -0,0 +1,33 @@
// FoldersPage.h
#pragma once
#ifndef __FOLDERSPAGE_H
#define __FOLDERSPAGE_H
#include "Windows/Control/PropertyPage.h"
#include "../../Common/ZipRegistry.h"
class CFoldersPage : public NWindows::NControl::CPropertyPage
{
NWorkDir::CInfo m_WorkDirInfo;
void MyEnableControls();
void ModifiedEvent();
NWindows::NControl::CDialogChildControl m_WorkPath;
NWindows::NControl::CDialogChildControl m_ButtonSetWorkPath;
// int m_RadioWorkMode;
void OnFoldersWorkButtonPath();
int GetWorkMode() const;
void GetWorkDir(NWorkDir::CInfo &aWorkDirInfo);
// bool WasChanged();
public:
virtual bool OnInit();
virtual bool OnCommand(int aCode, int anItemID, LPARAM lParam);
virtual void OnNotifyHelp();
virtual LONG OnApply();
virtual bool OnButtonClicked(int aButtonID, HWND aButtonHWND);
};
#endif

View File

@@ -0,0 +1,27 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by resource.rc
//
#define IDD_FOLDERS 900
#define IDS_FOLDERS_SET_WORK_PATH_TITLE 103
#define IDC_FOLDERS_WORK_RADIO_SYSTEM 1002
#define IDC_FOLDERS_WORK_EDIT_PATH 1003
#define IDC_FOLDERS_WORK_BUTTON_PATH 1004
#define IDC_FOLDERS_WORK_RADIO_CURRENT 1005
#define IDC_FOLDERS_WORK_RADIO_SPECIFIED 1006
#define IDC_FOLDERS_WORK_CHECK_FOR_REMOVABLE 1007
#define IDC_FOLDERS_STATIC_WORKING_FOLDER 1019
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 135
#define _APS_NEXT_COMMAND_VALUE 32771
#define _APS_NEXT_CONTROL_VALUE 1020
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View File

@@ -0,0 +1,109 @@
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// Russian resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)
#ifdef _WIN32
LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
#pragma code_page(1251)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\0"
END
#endif // APSTUDIO_INVOKED
#endif // Russian resources
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_FOLDERS DIALOG DISCARDABLE 0, 0, 210, 154
STYLE DS_FIXEDSYS | WS_CHILD | WS_DISABLED | WS_CAPTION
CAPTION "Folders"
FONT 8, "MS Shell Dlg"
BEGIN
GROUPBOX "&Working folder",IDC_FOLDERS_STATIC_WORKING_FOLDER,7,7,
196,98
CONTROL "&System temp folder",IDC_FOLDERS_WORK_RADIO_SYSTEM,
"Button",BS_AUTORADIOBUTTON | WS_GROUP,19,20,150,10
CONTROL "&Current",IDC_FOLDERS_WORK_RADIO_CURRENT,"Button",
BS_AUTORADIOBUTTON,19,34,150,10
CONTROL "Specified:",IDC_FOLDERS_WORK_RADIO_SPECIFIED,"Button",
BS_AUTORADIOBUTTON,19,48,151,10
EDITTEXT IDC_FOLDERS_WORK_EDIT_PATH,39,63,130,14,ES_AUTOHSCROLL
PUSHBUTTON "...",IDC_FOLDERS_WORK_BUTTON_PATH,178,63,18,14
CONTROL "Use for removable drives only",
IDC_FOLDERS_WORK_CHECK_FOR_REMOVABLE,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,19,87,180,10
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO DISCARDABLE
BEGIN
IDD_FOLDERS, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 203
TOPMARGIN, 7
BOTTOMMARGIN, 147
END
END
#endif // APSTUDIO_INVOKED
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////

45
7zip/UI/Explorer/MyMessages.cpp Executable file
View File

@@ -0,0 +1,45 @@
// MyMessages.cpp
#include "StdAfx.h"
#include "MyMessages.h"
#include "Common/String.h"
#include "Common/StringConvert.h"
#include "Windows/Error.h"
#include "Windows/ResourceString.h"
#ifdef LANG
#include "../../FileManager/LangUtils.h"
#endif
using namespace NWindows;
void MyMessageBox(HWND window, LPCWSTR message)
{
::MessageBoxW(window, message, L"7-Zip", 0);
}
void MyMessageBox(UINT32 id
#ifdef LANG
,UINT32 langID
#endif
)
{
#ifdef LANG
MyMessageBox(LangLoadStringW(id, langID));
#else
MyMessageBox(MyLoadStringW(id));
#endif
}
void ShowErrorMessage(HWND window, DWORD message)
{
MyMessageBox(window, NError::MyFormatMessageW(message));
}
void ShowLastErrorMessage(HWND window)
{
ShowErrorMessage(window, ::GetLastError());
}

26
7zip/UI/Explorer/MyMessages.h Executable file
View File

@@ -0,0 +1,26 @@
// MyMessages.h
#pragma once
#ifndef __MYMESSAGES_H
#define __MYMESSAGES_H
#include "Common/String.h"
void MyMessageBox(HWND window, LPCWSTR message);
inline void MyMessageBox(LPCWSTR message)
{ MyMessageBox(0, message); }
void MyMessageBox(UINT32 id
#ifdef LANG
,UINT32 langID
#endif
);
void ShowErrorMessage(HWND window, DWORD errorMessage);
inline void ShowErrorMessage(DWORD errorMessage)
{ ShowErrorMessage(0, errorMessage); }
void ShowLastErrorMessage(HWND window = 0);
#endif

View File

@@ -0,0 +1,107 @@
// OptionsDialog.cpp
#include "StdAfx.h"
#include "resource.h"
#include "OptionsDialog.h"
#include "Common/StringConvert.h"
#include "Windows/Control/PropertyPage.h"
#include "../../FileManager/LangUtils.h"
#include "FoldersPage/FoldersPage.h"
#include "FoldersPage/resource.h"
#include "SystemPage/SystemPage.h"
#include "SystemPage/resource.h"
extern HINSTANCE g_hInstance;
static void FillInPropertyPage(PROPSHEETPAGE* page,
HINSTANCE instance,
int dialogID,
NWindows::NControl::CPropertyPage *propertyPage,
CSysString &title)
{
page->dwSize = sizeof(PROPSHEETPAGE);
page->dwFlags = PSP_HASHELP;
page->hInstance = instance;
page->pszTemplate = MAKEINTRESOURCE(dialogID);
page->pszIcon = NULL;
page->pfnDlgProc = NWindows::NControl::ProperyPageProcedure;
if (title.IsEmpty())
page->pszTitle = NULL;
else
{
page->dwFlags |= PSP_USETITLE;
page->pszTitle = title;
}
page->lParam = LPARAM(propertyPage);
}
int OptionsDialog(HWND hwndOwner, HINSTANCE hInstance)
{
const int kNumPages = 2;
PROPSHEETPAGE pages[kNumPages];
CSystemPage systemPage;
CFoldersPage foldersPage;
CSysStringVector titles;
UINT32 langIDs[] = { 0x01000300, 0x01000200};
for (int i = 0; i < sizeof(langIDs) / sizeof(langIDs[0]); i++)
titles.Add(GetSystemString(LangLoadString(langIDs[i])));
FillInPropertyPage(&pages[0], hInstance, IDD_SYSTEM, &systemPage, titles[0]);
FillInPropertyPage(&pages[1], hInstance, IDD_FOLDERS, &foldersPage, titles[1]);
PROPSHEETHEADER sheet;
sheet.dwSize = sizeof(PROPSHEETHEADER);
sheet.dwFlags = PSH_PROPSHEETPAGE;
sheet.hwndParent = hwndOwner;
sheet.hInstance = hInstance;
CSysString title = LangLoadString(IDS_CONFIG_DIALOG_CAPTION, 0x01000000);
sheet.pszCaption = title;
sheet.nPages = sizeof(pages) / sizeof(PROPSHEETPAGE);
sheet.nStartPage = 0;
sheet.ppsp = pages;
return (PropertySheet(&sheet));
}
STDMETHODIMP CSevenZipOptions::PluginOptions(HWND hWnd,
IPluginOptionsCallback *callback)
{
/*
CComBSTR programPath;
RETUEN_IF_NOT_S_OK(callback->GetProgramPath(programName)));
*/
OptionsDialog(hWnd, g_hInstance);
return S_OK;
}
STDMETHODIMP CSevenZipOptions::GetFileExtensions(BSTR *extensions)
{
/*
UString extStrings;
CObjectVector<NZipRootRegistry::CArchiverInfo> formats;
NZipRootRegistry::ReadArchiverInfoList(formats);
for(int i = 0; i < formats.Size(); i++)
{
if (i != 0)
extStrings += L' ';
extStrings += formats[i].Extension;
}
CComBSTR valueTemp = extStrings;
*extensions = valueTemp.Detach();
return S_OK;
*/
return E_NOTIMPL;
}

View File

@@ -0,0 +1,25 @@
// OptionsDialog.h
#pragma once
#ifndef __SEVENZIP_OPTIONSDIALOG_H
#define __SEVENZIP_OPTIONSDIALOG_H
#include "../../FileManager/PluginInterface.h"
#include "Common/MyCom.h"
// {23170F69-40C1-278D-1000-000100020000}
DEFINE_GUID(CLSID_CSevenZipOptions,
0x23170F69, 0x40C1, 0x278D, 0x10, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00);
class CSevenZipOptions:
public IPluginOptions,
public CMyUnknownImp
{
public:
MY_UNKNOWN_IMP
STDMETHOD(PluginOptions)(HWND hWnd, IPluginOptionsCallback *callback);
STDMETHOD(GetFileExtensions)(BSTR *extensions);
};
#endif

View File

@@ -0,0 +1,84 @@
// RegistryContextMenu.cpp
#include "StdAfx.h"
#include "RegistryContextMenu.h"
#include "Windows/COM.h"
#include "Windows/Synchronization.h"
#include "Windows/Registry.h"
#include "Windows/System.h"
#include "Windows/FileName.h"
using namespace NWindows;
using namespace NCOM;
using namespace NRegistry;
namespace NZipRootRegistry {
static NSynchronization::CCriticalSection g_RegistryOperationsCriticalSection;
///////////////////////////
// ContextMenu
static const TCHAR *kContextMenuKeyName = TEXT("\\shellex\\ContextMenuHandlers\\7-ZIP");
static const TCHAR *kContextMenuHandlerCLASSIDValue =
TEXT("{23170F69-40C1-278A-1000-000100020000}");
static const TCHAR *kRootKeyNameForFile = TEXT("*");
static const TCHAR *kRootKeyNameForFolder = TEXT("Folder");
static const TCHAR *kRootKeyNameForDirectory = TEXT("Directory");
static CSysString GetFullContextMenuKeyName(const CSysString &keyName)
{ return (keyName + kContextMenuKeyName); }
static bool CheckContextMenuHandlerCommon(const CSysString &keyName)
{
NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection);
CKey key;
if (key.Open(HKEY_CLASSES_ROOT, GetFullContextMenuKeyName(keyName), KEY_READ)
!= ERROR_SUCCESS)
return false;
CSysString value;
if (key.QueryValue(NULL, value) != ERROR_SUCCESS)
return false;
return (value.CollateNoCase(kContextMenuHandlerCLASSIDValue) == 0);
}
bool CheckContextMenuHandler()
{
return CheckContextMenuHandlerCommon(kRootKeyNameForFile) &&
CheckContextMenuHandlerCommon(kRootKeyNameForFolder) &&
CheckContextMenuHandlerCommon(kRootKeyNameForDirectory);
}
static void DeleteContextMenuHandlerCommon(const CSysString &keyName)
{
CKey rootKey;
rootKey.Attach(HKEY_CLASSES_ROOT);
rootKey.RecurseDeleteKey(GetFullContextMenuKeyName(keyName));
rootKey.Detach();
}
void DeleteContextMenuHandler()
{
DeleteContextMenuHandlerCommon(kRootKeyNameForFile);
DeleteContextMenuHandlerCommon(kRootKeyNameForFolder);
DeleteContextMenuHandlerCommon(kRootKeyNameForDirectory);
}
static void AddContextMenuHandlerCommon(const CSysString &keyName)
{
DeleteContextMenuHandlerCommon(keyName);
NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection);
CKey key;
key.Create(HKEY_CLASSES_ROOT, GetFullContextMenuKeyName(keyName));
key.SetValue(NULL, kContextMenuHandlerCLASSIDValue);
}
void AddContextMenuHandler()
{
AddContextMenuHandlerCommon(kRootKeyNameForFile);
AddContextMenuHandlerCommon(kRootKeyNameForFolder);
AddContextMenuHandlerCommon(kRootKeyNameForDirectory);
}
}

View File

@@ -0,0 +1,18 @@
// RegistryContextMenu.h
#pragma once
#ifndef __REGISTRYCONTEXTMENU_H
#define __REGISTRYCONTEXTMENU_H
namespace NZipRootRegistry {
bool CheckContextMenuHandler();
void AddContextMenuHandler();
void DeleteContextMenuHandler();
}
// bool GetProgramDirPrefix(CSysString &folder);
#endif

3
7zip/UI/Explorer/StdAfx.cpp Executable file
View File

@@ -0,0 +1,3 @@
// StdAfx.cpp
#include "stdafx.h"

40
7zip/UI/Explorer/StdAfx.h Executable file
View File

@@ -0,0 +1,40 @@
// stdafx.h : include file for standard system include files,
#ifndef __STDAFX_H
#define __STDAFX_H
// #define _WIN32_IE 0x0500
#include <windows.h>
#include <CommCtrl.h>
#include <shlobj.h>
#include <tchar.h>
#include <stddef.h>
#include <string.h>
#include <mbstring.h>
#include <wchar.h>
#define _ATL_APARTMENT_THREADED
#define _ATL_NO_UUIDOF
#include <atlbase.h>
extern CComModule _Module;
#include <atlcom.h>
#include <shlguid.h>
#include <regstr.h>
// #include <new.h>
#undef _MT
#include <vector>
#include <map>
#include <algorithm>
#define _MT
#endif

Some files were not shown because too many files have changed in this diff Show More