📄 main.cpp
字号:
// Test Align for updating !!!!!!!!!!!!!!!!!!
#include "StdAfx.h"
// #include <locale.h>
#include <initguid.h>
#include "Plugin.h"
#include "Common/Wildcard.h"
#include "Common/DynamicBuffer.h"
#include "Common/StringConvert.h"
#include "Common/Defs.h"
#include "Windows/FileFind.h"
#include "Windows/FileIO.h"
#include "Windows/FileDir.h"
#include "Windows/Defs.h"
#include "../../IPassword.h"
#include "../../Common/FileStreams.h"
#include "../Common/DefaultName.h"
#include "../Common/OpenArchive.h"
#include "../Agent/Agent.h"
#include "ProgressBox.h"
#include "FarUtils.h"
#include "Messages.h"
using namespace NWindows;
using namespace NFar;
static const char *kCommandPrefix = "7-zip";
static const int kDescriptionMaxSize = 256;
static const char *kRegisrtryMainKeyName = "";
static const char *kRegisrtryValueNameEnabled = "UsedByDefault3";
static bool kPluginEnabledDefault = true;
static const char *kHelpTopicConfig = "Config";
extern "C"
{
void WINAPI SetStartupInfo(struct PluginStartupInfo *info);
HANDLE WINAPI OpenFilePlugin(char *name, const unsigned char *Data,
unsigned int DataSize);
HANDLE WINAPI OpenPlugin(int openFrom, int item);
void WINAPI ClosePlugin(HANDLE plugin);
int WINAPI GetFindData(HANDLE plugin, struct PluginPanelItem **panelItems,
int *itemsNumber, int OpMode);
void WINAPI FreeFindData(HANDLE plugin, struct PluginPanelItem *panelItems,
int itemsNumber);
int WINAPI GetFiles(HANDLE plugin, struct PluginPanelItem *panelItems,
int itemsNumber, int move, char *destPath, int opMode);
int WINAPI SetDirectory(HANDLE plugin, char *dir, int opMode);
void WINAPI GetPluginInfo(struct PluginInfo *info);
int WINAPI Configure(int itemNumber);
void WINAPI GetOpenPluginInfo(HANDLE plugin, struct OpenPluginInfo *info);
int WINAPI PutFiles(HANDLE plugin, struct PluginPanelItem *panelItems,
int itemsNumber, int move, int opMode);
int WINAPI DeleteFiles(HANDLE plugin, PluginPanelItem *panelItems,
int itemsNumber, int opMode);
int WINAPI ProcessKey(HANDLE plugin, int key, unsigned int controlState);
};
HINSTANCE g_hInstance;
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID)
{
if (dwReason == DLL_PROCESS_ATTACH)
{
g_hInstance = hInstance;
}
return TRUE;
}
static struct COptions
{
bool Enabled;
} g_Options;
static const char *kPliginNameForRegestry = "7-ZIP";
// #define MY_TRY_BEGIN MY_TRY_BEGIN NCOM::CComInitializer aComInitializer;
void WINAPI SetStartupInfo(struct PluginStartupInfo *info)
{
MY_TRY_BEGIN;
g_StartupInfo.Init(*info, kPliginNameForRegestry);
g_Options.Enabled = g_StartupInfo.QueryRegKeyValue(
HKEY_CURRENT_USER, kRegisrtryMainKeyName,
kRegisrtryValueNameEnabled, kPluginEnabledDefault);
MY_TRY_END1("SetStartupInfo");
}
class COpenArchiveCallback:
public IArchiveOpenCallback,
public IArchiveOpenVolumeCallback,
public IProgress,
public ICryptoGetTextPassword,
public CMyUnknownImp
{
DWORD m_StartTickValue;
bool m_MessageBoxIsShown;
CMessageBox *m_MessageBox;
UINT64 m_NumFiles;
UINT64 m_NumFilesMax;
UINT64 m_NumFilesPrev;
bool m_NumFilesDefined;
UINT64 m_NumBytes;
bool m_NumBytesDefined;
UINT32 m_PrevTickCount;
NWindows::NFile::NFind::CFileInfoW _fileInfo;
public:
bool PasswordIsDefined;
UString Password;
UString _folderPrefix;
public:
MY_UNKNOWN_IMP3(
IArchiveOpenVolumeCallback,
IProgress,
ICryptoGetTextPassword
)
// IProgress
STDMETHOD(SetTotal)(UINT64 total);
STDMETHOD(SetCompleted)(const UINT64 *aCompleteValue);
// IArchiveOpenCallback
STDMETHOD(SetTotal)(const UINT64 *numFiles, const UINT64 *numBytes);
STDMETHOD(SetCompleted)(const UINT64 *numFiles, const UINT64 *numBytes);
// IArchiveOpenVolumeCallback
STDMETHOD(GetProperty)(PROPID propID, PROPVARIANT *value);
STDMETHOD(GetStream)(const wchar_t *name, IInStream **inStream);
// ICryptoGetTextPassword
STDMETHOD(CryptoGetTextPassword)(BSTR *password);
void Init(CMessageBox *messageBox)
{
PasswordIsDefined = false;
m_NumFilesMax = 0;
m_MessageBoxIsShown = false;
m_PrevTickCount = GetTickCount();
m_MessageBox = messageBox;
}
void ShowMessage(const UINT64 *completed);
void LoadFileInfo(const UString &folderPrefix,
const UString &fileName)
{
_folderPrefix = folderPrefix;
if (!NWindows::NFile::NFind::FindFile(_folderPrefix + fileName, _fileInfo))
throw 1;
}
};
void COpenArchiveCallback::ShowMessage(const UINT64 *completed)
{
UINT32 currentTime = GetTickCount();
if (!m_MessageBoxIsShown)
{
if (currentTime - m_PrevTickCount < 400)
return;
m_MessageBox->Init(g_StartupInfo.GetMsgString(NMessageID::kWaitTitle),
g_StartupInfo.GetMsgString(NMessageID::kReading), 2, 30);
m_MessageBoxIsShown = true;
}
else
{
if (currentTime - m_PrevTickCount < 200)
return;
}
m_PrevTickCount = currentTime;
char aMessage[256];
sprintf(aMessage, "%5I64u", m_NumFilesMax);
char aMessage2[256];
aMessage2[0] = '\0';
if (completed != NULL)
sprintf(aMessage2, "%5I64u", *completed);
const char *aMessages[2] =
{aMessage, aMessage2 };
m_MessageBox->ShowProcessMessages(aMessages);
}
STDMETHODIMP COpenArchiveCallback::SetTotal(const UINT64 *numFiles, const UINT64 *numBytes)
{
if (WasEscPressed())
return E_ABORT;
m_NumFilesDefined = (numFiles != NULL);
if (m_NumFilesDefined)
m_NumFiles = *numFiles;
m_NumBytesDefined = (numBytes != NULL);
if (m_NumBytesDefined)
m_NumBytes = *numBytes;
return S_OK;
}
STDMETHODIMP COpenArchiveCallback::SetCompleted(const UINT64 *numFiles, const UINT64 *numBytes)
{
if (WasEscPressed())
return E_ABORT;
if (numFiles == NULL)
return S_OK;
m_NumFilesMax = *numFiles;
// if (*numFiles % 100 != 0)
// return S_OK;
ShowMessage(NULL);
return S_OK;
}
STDMETHODIMP COpenArchiveCallback::SetTotal(const UINT64 total)
{
if (WasEscPressed())
return E_ABORT;
/*
aNumFilesDefined = (numFiles != NULL);
if (aNumFilesDefined)
aNumFiles = *numFiles;
aNumBytesDefined = (numBytes != NULL);
if (aNumBytesDefined)
aNumBytes = *numBytes;
*/
return S_OK;
}
STDMETHODIMP COpenArchiveCallback::SetCompleted(const UINT64 *completed)
{
if (WasEscPressed())
return E_ABORT;
if (completed == NULL)
return S_OK;
// if (*completed % 100 != 0)
// return S_OK;
ShowMessage(completed);
return S_OK;
}
STDMETHODIMP COpenArchiveCallback::GetStream(const wchar_t *name,
IInStream **inStream)
{
if (WasEscPressed())
return E_ABORT;
*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 COpenArchiveCallback::GetProperty(PROPID propID, PROPVARIANT *value)
{
NWindows::NCOM::CPropVariant propVariant;
switch(propID)
{
case kpidName:
propVariant = GetUnicodeString(_fileInfo.Name, CP_OEMCP);
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;
}
HRESULT GetPassword(UString &password)
{
if (WasEscPressed())
return E_ABORT;
password.Empty();
CInitDialogItem initItems[]=
{
{ DI_DOUBLEBOX, 3, 1, 72, 4, false, false, 0, false, NMessageID::kGetPasswordTitle, NULL, NULL },
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -