mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-15 08:11:46 -06:00
3.13
This commit is contained in:
64
7zip/UI/Console/ArError.h
Executable file
64
7zip/UI/Console/ArError.h
Executable 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
|
||||
28
7zip/UI/Console/CompressionMode.h
Executable file
28
7zip/UI/Console/CompressionMode.h
Executable 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
581
7zip/UI/Console/Console.dsp
Executable 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
29
7zip/UI/Console/Console.dsw
Executable 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>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
57
7zip/UI/Console/ConsoleClose.cpp
Executable file
57
7zip/UI/Console/ConsoleClose.cpp
Executable 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
27
7zip/UI/Console/ConsoleClose.h
Executable 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
94
7zip/UI/Console/Extract.cpp
Executable 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
65
7zip/UI/Console/Extract.h
Executable 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
|
||||
405
7zip/UI/Console/ExtractCallback.cpp
Executable file
405
7zip/UI/Console/ExtractCallback.cpp
Executable 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;
|
||||
}
|
||||
|
||||
77
7zip/UI/Console/ExtractCallback.h
Executable file
77
7zip/UI/Console/ExtractCallback.h
Executable 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
381
7zip/UI/Console/List.cpp
Executable 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
31
7zip/UI/Console/List.h
Executable 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
934
7zip/UI/Console/Main.cpp
Executable 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
114
7zip/UI/Console/MainAr.cpp
Executable 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;
|
||||
}
|
||||
92
7zip/UI/Console/OpenCallback.cpp
Executable file
92
7zip/UI/Console/OpenCallback.cpp
Executable 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
52
7zip/UI/Console/OpenCallback.h
Executable 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
|
||||
86
7zip/UI/Console/PercentPrinter.cpp
Executable file
86
7zip/UI/Console/PercentPrinter.cpp
Executable 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();
|
||||
}
|
||||
38
7zip/UI/Console/PercentPrinter.h
Executable file
38
7zip/UI/Console/PercentPrinter.h
Executable 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
3
7zip/UI/Console/StdAfx.cpp
Executable file
@@ -0,0 +1,3 @@
|
||||
// StdAfx.cpp
|
||||
|
||||
#include "stdafx.h"
|
||||
16
7zip/UI/Console/StdAfx.h
Executable file
16
7zip/UI/Console/StdAfx.h
Executable 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
39
7zip/UI/Console/TempFiles.cpp
Executable 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
20
7zip/UI/Console/TempFiles.h
Executable 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
503
7zip/UI/Console/Update.cpp
Executable 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
41
7zip/UI/Console/Update.h
Executable 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
|
||||
259
7zip/UI/Console/UpdateCallback.cpp
Executable file
259
7zip/UI/Console/UpdateCallback.cpp
Executable 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;
|
||||
}
|
||||
78
7zip/UI/Console/UpdateCallback.h
Executable file
78
7zip/UI/Console/UpdateCallback.h
Executable 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
|
||||
51
7zip/UI/Console/UserInputUtils.cpp
Executable file
51
7zip/UI/Console/UserInputUtils.cpp
Executable 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);
|
||||
}
|
||||
23
7zip/UI/Console/UserInputUtils.h
Executable file
23
7zip/UI/Console/UserInputUtils.h
Executable 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
1
7zip/UI/Console/afxres.h
Executable file
@@ -0,0 +1 @@
|
||||
#include <winresrc.h>
|
||||
15
7zip/UI/Console/resource.h
Executable file
15
7zip/UI/Console/resource.h
Executable 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
121
7zip/UI/Console/resource.rc
Executable 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
|
||||
|
||||
Reference in New Issue
Block a user