📄 compress.cpp
字号:
tempDirectory.Create(kTempFolderPrefix);
currentDirPrefix = tempDirectory.GetPath();
NormalizeDirPathPrefix(currentDirPrefix);
needTempFile = false;
}
if (showDialog)
{
bool oneFile = false;
NFind::CFileInfoW fileInfo;
if (!NFind::FindFile(fileNames.Front(), fileInfo))
return ::GetLastError();
if (fileNames.Size() == 1)
oneFile = !fileInfo.IsDirectory();
CCompressDialog dialog;
for(int i = 0; i < archivers.Size(); i++)
{
const CArchiverInfo &archiverInfo = archivers[i];
if (archiverInfo.UpdateEnabled &&
(oneFile || !archiverInfo.KeepName))
dialog.m_ArchiverInfoList.Add(archiverInfo);
}
if(dialog.m_ArchiverInfoList.Size() == 0)
{
MyMessageBox(L"No Update Engines");
return E_FAIL;
}
dialog.m_Info.ArchiveName = archiveName;
dialog.OriginalFileName = fileInfo.Name;
dialog.m_Info.CurrentDirPrefix = currentDirPrefix;
dialog.m_Info.SFXMode = false;
dialog.m_Info.Solid = true;
dialog.m_Info.MultiThread = false;
dialog.m_Info.KeepName = !oneFile;
if(dialog.Create(0) != IDOK)
return S_OK;
if (dialog.m_Info.VolumeSizeIsDefined)
{
MyMessageBox(L"Splitting to volumes is not supported");
return E_FAIL;
}
switch(dialog.m_Info.UpdateMode)
{
case NCompressDialog::NUpdateMode::kAdd:
actionSet = &NUpdateArchive::kAddActionSet;
break;
case NCompressDialog::NUpdateMode::kUpdate:
actionSet = &NUpdateArchive::kUpdateActionSet;
break;
case NCompressDialog::NUpdateMode::kFresh:
actionSet = &NUpdateArchive::kFreshActionSet;
break;
case NCompressDialog::NUpdateMode::kSynchronize:
actionSet = &NUpdateArchive::kSynchronizeActionSet;
break;
default:
throw 1091756;
}
archiverInfo = dialog.m_ArchiverInfoList[dialog.m_Info.ArchiverInfoIndex];
password = GetUnicodeString(dialog.Password);
encryptHeadersIsAllowed = dialog.EncryptHeadersIsAllowed;
encryptHeaders = dialog.EncryptHeaders;
compressInfo = dialog.m_Info;
compressInfo.ArchiveName = MakeFullArchiveName(
compressInfo.ArchiveName,
archiverInfo.GetMainExtension(), compressInfo.SFXMode);
}
else
{
int i;
for(i = 0; i < archivers.Size(); i++)
{
if (archivers[i].Name.CollateNoCase(archiveType) == 0)
{
archiverInfo = archivers[i];
break;
}
}
if (i == archivers.Size())
{
MyMessageBox(L"No archiver");
return E_FAIL;
}
actionSet = &NUpdateArchive::kAddActionSet;
bool is7z = (archiveType.CollateNoCase(L"7z") == 0);
compressInfo.SolidIsAllowed = is7z;
compressInfo.Solid = true;
compressInfo.MultiThreadIsAllowed = is7z;
compressInfo.MultiThread = false;
compressInfo.SFXMode = false;
compressInfo.KeepName = false;
compressInfo.ArchiveName = archiveName;
compressInfo.CurrentDirPrefix = currentDirPrefix;
compressInfo.Level = 5;
}
UString arcPath;
if (!compressInfo.GetFullPathName(arcPath))
{
MyMessageBox(L"Incorrect archive path");
return E_FAIL;
}
if (compressInfo.ArchiveName.Find('\\') >= 0)
{
needTempFile = true;
}
// MessageBox(0, arcPath, 0, 0);
NWorkDir::CInfo workDirInfo;
ReadWorkDirInfo(workDirInfo);
UString workDir = GetWorkDir(workDirInfo, arcPath);
NFile::NDirectory::CreateComplexDirectory(workDir);
NFile::NDirectory::CTempFileW tempFile;
UString tempFileName;
if (needTempFile)
{
if (tempFile.Create(workDir, kTempArchivePrefix, tempFileName) == 0)
return E_FAIL;
}
else
tempFileName = arcPath;
/*
const CLSID &classID =
dialog.m_ArchiverInfoList[dialog.m_Info.ArchiverInfoIndex].ClassID;
*/
NFind::CFileInfoW fileInfo;
CMyComPtr<IOutFolderArchive> outArchive;
CMyComPtr<IInFolderArchive> archiveHandler;
if(NFind::FindFile(arcPath, fileInfo))
{
if (fileInfo.IsDirectory())
{
MyMessageBox(L"There is a folder with such name");
return E_FAIL;
}
CAgent *agentSpec = new CAgent;
archiveHandler = agentSpec;
// CLSID realClassID;
CMyComBSTR archiveType;
HRESULT result = agentSpec->Open(
GetUnicodeString(arcPath), &archiveType, NULL);
if (result == S_FALSE)
{
MyMessageBox(IDS_OPEN_IS_NOT_SUPORTED_ARCHIVE, 0x02000604);
return E_FAIL;
}
/*
HRESULT result = OpenArchive(arcPath, &archiveHandler,
archiverInfoResult, defaultName, NULL);
if (result == S_FALSE)
{
MyMessageBox(IDS_OPEN_IS_NOT_SUPORTED_ARCHIVE, 0x02000604);
return E_FAIL;
}
*/
if (result != S_OK)
{
MyMessageBox(L"Open error");
return E_FAIL;
}
if (archiverInfo.Name.CollateNoCase((const wchar_t *)archiveType) != 0)
{
MyMessageBox(L"Type of existing archive differs from specified type");
return E_FAIL;
}
result = archiveHandler.QueryInterface(IID_IOutFolderArchive, &outArchive);
if(result != S_OK)
{
MyMessageBox(MyFormatNew(IDS_CANT_UPDATE_ARCHIVE, 0x02000602,
GetUnicodeString(arcPath)));
return E_FAIL;
}
}
else
{
CAgent *agentSpec = new CAgent;
outArchive = agentSpec;
}
CRecordVector<const wchar_t *> fileNamePointers;
fileNamePointers.Reserve(fileNames.Size());
int i;
for(i = 0; i < fileNames.Size(); i++)
fileNamePointers.Add(fileNames[i]);
outArchive->SetFolder(NULL);
// Don't uses CurrentFolder here, since files are absolute paths;
// MyGetCurrentDirectory(aCurrentFolder);
UINT codePage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
outArchive->SetFiles(L"",
&fileNamePointers.Front(), fileNamePointers.Size());
CThreadUpdateCompress updater;
for (i = 0; i < NUpdateArchive::NPairState::kNumValues; i++)
updater.ActionSetByte[i] = actionSet->StateActions[i];
updater.UpdateCallbackSpec = new CUpdateCallback100Imp;
updater.UpdateCallback = updater.UpdateCallbackSpec;
updater.OutArchive = outArchive;
// updater.SrcFolderPrefix = srcPanel._currentFolderPrefix;
UString title = LangLoadStringW(IDS_PROGRESS_COMPRESSING, 0x02000DC0);
updater.UpdateCallbackSpec->Init(0, !password.IsEmpty(), password);
// UINT32 level = MyMin(compressInfo.Level, UINT32(9));
UINT32 level = compressInfo.Level;
HRESULT result = SetOutProperties(outArchive,
archiverInfo.Name.CompareNoCase(L"7z") == 0,
level,
compressInfo.Method,
compressInfo.Dictionary,
compressInfo.OrderMode, compressInfo.Order,
compressInfo.SolidIsAllowed, compressInfo.Solid,
compressInfo.MultiThreadIsAllowed, compressInfo.MultiThread,
encryptHeadersIsAllowed, encryptHeaders,
compressInfo.SFXMode,
GetUnicodeString(compressInfo.Options));
if (result != S_OK)
{
if (result != E_ABORT)
ShowErrorMessage(result);
return result;
}
UString sfxModule;
if (compressInfo.SFXMode)
{
UString sfxModule2;
LPCWSTR path = NULL;
UString sfxModule3;
if (GetProgramFolderPath(sfxModule3))
path = sfxModule3;
if (!NDirectory::MySearchPath(path, kDefaultSfxModule, NULL, sfxModule2))
{
MyMessageBox(L"can't find sfx module");
return E_FAIL;
}
sfxModule = sfxModule2;
}
updater.OutArchivePath = GetUnicodeString(tempFileName, codePage);
updater.SfxMode = compressInfo.SFXMode;
updater.SfxModule = sfxModule;
updater.LibPath = GetUnicodeString(archiverInfo.FilePath);
updater.ClassID = archiverInfo.ClassID;
CThread thread;
if (!thread.Create(CThreadUpdateCompress::MyThreadFunction, &updater))
throw 271824;
updater.UpdateCallbackSpec->StartProgressDialog(title);
result = updater.Result;
updater.UpdateCallback.Release();
updater.OutArchive.Release();
outArchive.Release();
if (result != S_OK)
{
if (result != E_ABORT)
ShowErrorMessage(result);
return result;
}
if(archiveHandler)
{
archiveHandler->Close();
if (!DeleteFileAlways(arcPath))
{
ShowLastErrorMessage();
return E_FAIL;
}
}
if (needTempFile)
{
tempFile.DisableDeleting();
if (!NDirectory::MyMoveFile(tempFileName, arcPath))
{
ShowLastErrorMessage();
return E_FAIL;
}
}
if (email)
{
NDLL::CLibrary mapiLib;
if (!mapiLib.Load(TEXT("Mapi32.dll")))
return E_FAIL;
LPMAPISENDDOCUMENTS fnSend = (LPMAPISENDDOCUMENTS)
mapiLib.GetProcAddress("MAPISendDocuments");
if (fnSend == 0)
return E_FAIL;
UString fileName;
GetOnlyName(arcPath, fileName);
AString path = GetAnsiString(arcPath);
AString name = GetAnsiString(fileName);
fnSend(0, ";", (LPSTR)(LPCSTR)path, (LPSTR)(LPCSTR)name, 0);
}
return S_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -