📄 compressdialog.cpp
字号:
}
}
SetArchiveName2(false); // it's for OnInit
}
}
void CCompressDialog::OnButtonSetArchive()
{
const int kBufferSize = MAX_PATH * 2;
TCHAR buffer[kBufferSize];
UString fileName;
m_ArchivePath.GetText(fileName);
fileName.TrimLeft();
fileName.TrimRight();
Info.ArchiveName = fileName;
UString fullFileName;
if (!Info.GetFullPathName(fullFileName))
{
fullFileName = Info.ArchiveName;
// throw "Incorrect archive path";
return;
}
lstrcpy(buffer, GetSystemString(fullFileName));
OPENFILENAME info;
info.lStructSize = sizeof(info);
info.hwndOwner = HWND(*this);
info.hInstance = 0;
const int kFilterBufferSize = MAX_PATH;
TCHAR filterBuffer[kFilterBufferSize];
CDoubleZeroStringList doubleZeroStringList;
// doubleZeroStringList.Add(TEXT("Zip Files (*.zip)"));
// doubleZeroStringList.Add(TEXT("*.zip"));
UString s = LangLoadStringW(IDS_OPEN_TYPE_ALL_FILES, 0x02000DB1);
s += L" (*.*)";
doubleZeroStringList.Add(GetSystemString(s));
doubleZeroStringList.Add(TEXT("*.*"));
doubleZeroStringList.SetForBuffer(filterBuffer);
info.lpstrFilter = filterBuffer;
info.lpstrCustomFilter = NULL;
info.nMaxCustFilter = 0;
info.nFilterIndex = 0;
info.lpstrFile = buffer;
info.nMaxFile = kBufferSize;
info.lpstrFileTitle = NULL;
info.nMaxFileTitle = 0;
info.lpstrInitialDir= NULL;
CSysString title = LangLoadString(IDS_COMPRESS_SET_ARCHIVE_DIALOG_TITLE, 0x02000D90);
info.lpstrTitle = title;
info.Flags = OFN_EXPLORER | OFN_HIDEREADONLY;
info.nFileOffset = 0;
info.nFileExtension = 0;
info.lpstrDefExt = NULL;
info.lCustData = 0;
info.lpfnHook = NULL;
info.lpTemplateName = NULL;
if(!GetOpenFileName(&info))
return;
m_ArchivePath.SetText(buffer);
}
// in ExtractDialog.cpp
extern void AddUniqueString(CSysStringVector &strings, const CSysString &srcString);
bool ParseVolumeSize(const CSysString &s, UInt64 &value)
{
const TCHAR *start = s;
const TCHAR *end;
value = ConvertStringToUInt64(start, &end);
if (start == end)
return false;
while (true)
{
TCHAR c = *end++;
c = MyCharUpper(c);
switch(c)
{
case TEXT('\0'):
case TEXT('B'):
return true;
case TEXT('K'):
value <<= 10;
return true;
case TEXT('M'):
value <<= 20;
return true;
case TEXT('G'):
value <<= 30;
return true;
case TEXT(' '):
continue;
default:
return true;
}
}
}
void CCompressDialog::OnOK()
{
_passwordControl.GetText(Info.Password);
SaveOptionsInMem();
int currentItem = m_ArchivePath.GetCurSel();
UString s;
if(currentItem == CB_ERR)
{
m_ArchivePath.GetText(s);
if(m_ArchivePath.GetCount() >= kHistorySize)
currentItem = m_ArchivePath.GetCount() - 1;
}
else
{
CSysString sTemp;
m_ArchivePath.GetLBText(currentItem, sTemp);
s = GetUnicodeString(sTemp);
}
s.Trim();
m_RegistryInfo.HistoryArchives.Clear();
AddUniqueString(m_RegistryInfo.HistoryArchives, GetSystemString(s));
Info.ArchiveName = s;
Info.UpdateMode = NCompressDialog::NUpdateMode::EEnum(m_UpdateMode.GetCurSel());
Info.Level = GetLevelSpec();
Info.Dictionary = GetDictionarySpec();
Info.Order = GetOrderSpec();
Info.OrderMode = GetOrderMode();
Info.Method = GetUnicodeString(GetMethodSpec());
Info.ArchiverInfoIndex = m_Format.GetCurSel();
Info.SFXMode = IsSFX();
m_RegistryInfo.Solid = Info.Solid = IsButtonCheckedBool(IDC_COMPRESS_SOLID);
m_RegistryInfo.MultiThread = Info.MultiThread = IsButtonCheckedBool(IDC_COMPRESS_MULTI_THREAD);
m_RegistryInfo.EncryptHeaders = Info.EncryptHeaders = IsButtonCheckedBool(IDC_COMPRESS_CHECK_ENCRYPT_FILE_NAMES);
m_Params.GetText(Info.Options);
CSysString volumeString;
m_Volume.GetText(volumeString);
volumeString.Trim();
Info.VolumeSizeIsDefined = ParseVolumeSize(volumeString, Info.VolumeSize);
/*
if (!Info.VolumeSizeIsDefined && !volumeString.IsEmpty())
MessageBox(0, TEXT("Incorrect volume size"), TEXT("7-Zip"), 0);
*/
for(int i = 0; i < m_ArchivePath.GetCount(); i++)
if(i != currentItem)
{
CSysString sTemp;
m_ArchivePath.GetLBText(i, sTemp);
sTemp.Trim();
AddUniqueString(m_RegistryInfo.HistoryArchives, sTemp);
}
////////////////////
// Method
m_RegistryInfo.Level = Info.Level;
m_RegistryInfo.ArchiveType = m_ArchiverInfoList[Info.ArchiverInfoIndex].Name;
m_RegistryInfo.ShowPassword = (IsButtonChecked(
IDC_COMPRESS_CHECK_SHOW_PASSWORD) == BST_CHECKED);
SaveCompressionInfo(m_RegistryInfo);
CModalDialog::OnOK();
}
static LPCWSTR kHelpTopic = L"fm/plugins/7-zip/add.htm";
void CCompressDialog::OnHelp()
{
ShowHelpWindow(NULL, kHelpTopic);
}
bool CCompressDialog::OnCommand(int code, int itemID, LPARAM lParam)
{
if (code == CBN_SELCHANGE)
{
switch(itemID)
{
case IDC_COMPRESS_COMBO_FORMAT:
{
OnChangeFormat();
return true;
}
case IDC_COMPRESS_COMBO_LEVEL:
{
const CArchiverInfo &ai = m_ArchiverInfoList[m_Format.GetCurSel()];
int index = FindRegistryFormatAlways(ai.Name);
NCompression::CFormatOptions &fo = m_RegistryInfo.FormatOptionsVector[index];
fo.Init();
SetMethod();
CheckSFXNameChange();
return true;
}
case IDC_COMPRESS_COMBO_METHOD:
{
SetDictionary();
SetOrder();
CheckSFXNameChange();
return true;
}
case IDC_COMPRESS_COMBO_DICTIONARY:
case IDC_COMPRESS_COMBO_ORDER:
{
SetMemoryUsage();
return true;
}
}
}
return CModalDialog::OnCommand(code, itemID, lParam);
}
void CCompressDialog::CheckSFXNameChange()
{
bool isSFX = IsSFX();
CheckSFXControlsEnable();
if (isSFX != IsSFX())
SetArchiveName2(isSFX);
}
void CCompressDialog::SetArchiveName2(bool prevWasSFX)
{
UString fileName;
m_ArchivePath.GetText(fileName);
const CArchiverInfo &prevArchiverInfo = m_ArchiverInfoList[m_PrevFormat];
if (prevArchiverInfo.KeepName || Info.KeepName)
{
UString prevExtension = prevArchiverInfo.GetMainExtension();
if (prevWasSFX)
prevExtension = kExeExt;
else
prevExtension = UString('.') + prevExtension;
const int prevExtensionLen = prevExtension.Length();
if (fileName.Length() >= prevExtensionLen)
if (fileName.Right(prevExtensionLen).CompareNoCase(prevExtension) == 0)
fileName = fileName.Left(fileName.Length() - prevExtensionLen);
}
SetArchiveName(fileName);
}
void CCompressDialog::OnChangeFormat()
{
bool isSFX = IsSFX();
SaveOptionsInMem();
SetLevel();
SetParams();
CheckControlsEnable();
SetArchiveName2(isSFX);
}
// if type.KeepName then use OriginalFileName
// else if !KeepName remove extension
// add new extension
void CCompressDialog::SetArchiveName(const UString &name)
{
UString fileName = name;
Info.ArchiverInfoIndex = m_Format.GetCurSel();
const CArchiverInfo &ai = m_ArchiverInfoList[Info.ArchiverInfoIndex];
m_PrevFormat = Info.ArchiverInfoIndex;
if (ai.KeepName)
{
fileName = OriginalFileName;
}
else
{
if (!Info.KeepName)
{
int dotPos = fileName.ReverseFind('.');
int slashPos = MyMax(fileName.ReverseFind('\\'), fileName.ReverseFind('/'));
if (dotPos > slashPos)
fileName = fileName.Left(dotPos);
}
}
if (IsSFX())
fileName += kExeExt;
else
{
fileName += L'.';
fileName += ai.GetMainExtension();
}
m_ArchivePath.SetText(fileName);
}
int CCompressDialog::FindRegistryFormat(const UString &name)
{
for (int i = 0; i < m_RegistryInfo.FormatOptionsVector.Size(); i++)
{
const NCompression::CFormatOptions &fo = m_RegistryInfo.FormatOptionsVector[i];
if (GetUnicodeString(fo.FormatID) == name)
return i;
}
return -1;
}
int CCompressDialog::FindRegistryFormatAlways(const UString &name)
{
int index = FindRegistryFormat(name);
if (index < 0)
{
NCompression::CFormatOptions fo;
fo.FormatID = GetSystemString(name);
index = m_RegistryInfo.FormatOptionsVector.Add(fo);
}
return index;
}
int CCompressDialog::GetStaticFormatIndex()
{
int formatIndex = m_Format.GetCurSel();
const CArchiverInfo &ai = m_ArchiverInfoList[formatIndex];
for (int i = 0; i < MY_SIZE_OF_ARRAY(g_Formats); i++)
if (ai.Name.CompareNoCase(g_Formats[i].Name) == 0)
return i;
return 0; // -1;
}
void CCompressDialog::SetNearestSelectComboBox(
NControl::CComboBox &comboBox, UInt32 value)
{
for (int i = comboBox.GetCount() - 1; i >= 0; i--)
if ((UInt32)comboBox.GetItemData(i) <= value)
{
comboBox.SetCurSel(i);
return;
}
if (comboBox.GetCount() > 0)
comboBox.SetCurSel(0);
}
void CCompressDialog::SetLevel()
{
m_Level.ResetContent();
const CFormatInfo &fi = g_Formats[GetStaticFormatIndex()];
const CArchiverInfo &ai = m_ArchiverInfoList[m_Format.GetCurSel()];
int index = FindRegistryFormat(ai.Name);
UInt32 level = kNormal;
if (index >= 0)
{
const NCompression::CFormatOptions &fo = m_RegistryInfo.FormatOptionsVector[index];
if (fo.Level <= kUltra)
level = fo.Level;
else
level = kUltra;
}
int i;
for (i = 0; i <= kUltra; i++)
{
if ((fi.LevelsMask & (1 << i)) != 0)
{
const CLevelInfo &levelInfo = g_Levels[i];
int index = m_Level.AddString(LangLoadString(levelInfo.ResourceID, levelInfo.LangID));
m_Level.SetItemData(index, i);
}
}
SetNearestSelectComboBox(m_Level, level);
SetMethod();
}
int CCompressDialog::GetLevel()
{
if (m_Level.GetCount() <= 0)
return -1;
return m_Level.GetItemData(m_Level.GetCurSel());
}
int CCompressDialog::GetLevelSpec()
{
if (m_Level.GetCount() <= 1)
return -1;
return GetLevel();
}
int CCompressDialog::GetLevel2()
{
int level = GetLevel();
if (level < 0)
level = 5;
return level;
}
void CCompressDialog::SetMethod()
{
m_Method.ResetContent();
if (GetLevel() <= 0)
{
SetDictionary();
SetOrder();
return;
}
const CFormatInfo &fi = g_Formats[GetStaticFormatIndex()];
const CArchiverInfo &ai = m_ArchiverInfoList[m_Format.GetCurSel()];
int index = FindRegistryFormat(ai.Name);
UString defaultMethod;
if (index >= 0)
{
const NCompression::CFormatOptions &fo = m_RegistryInfo.FormatOptionsVector[index];
defaultMethod = GetUnicodeString(fo.Method);
}
bool isSfx = IsSFX();
for(int m = 0; m < fi.NumMethods; m++)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -