options.cpp
来自「一个FTP下载的源代码。代码质量非常高」· C++ 代码 · 共 1,782 行 · 第 1/4 页
CPP
1,782 行
if (IsWindow((*iter)->GetSafeHwnd()))
if (!(*iter)->UpdateData(TRUE))
return;
if (m_OptionsPage2.m_UseKeepAlive)
{
int low=_ttoi(m_OptionsPage2.m_IntervalLow);
int high=_ttoi(m_OptionsPage2.m_IntervalHigh);
if ((low<15)||(low>500))
{
ShowPage(&m_OptionsPage2);
m_OptionsPage2.GetDlgItem(IDC_INTERVALLOW)->SetFocus();
CString str;
str.Format(IDS_OPTIONS_KEEPALIVEBORDERLOW,15,500);
AfxMessageBox(str,MB_ICONEXCLAMATION);
return;
}
if ((high<15)||(high>500))
{
ShowPage(&m_OptionsPage2);
m_OptionsPage2.GetDlgItem(IDC_INTERVALHIGH)->SetFocus();
CString str;
str.Format(IDS_OPTIONS_KEEPALIVEBORDERHIGH,15,500);
AfxMessageBox(str,MB_ICONEXCLAMATION);
return;
}
if (low>high)
{
ShowPage(&m_OptionsPage2);
m_OptionsPage2.GetDlgItem(IDC_INTERVALLOW)->SetFocus();
CString str;
str.Format(IDS_OPTIONS_KEEPALIVEBORDERDIFF);
AfxMessageBox(str,MB_ICONEXCLAMATION);
return;
}
}
int val=_ttoi(m_OptionsPage2.m_NumRetries);
if ((val<0)||(val>999))
{
ShowPage(&m_OptionsPage2);
m_OptionsPage2.GetDlgItem(IDC_NUMRETRY)->SetFocus();
CString str;
str.Format(IDS_OPTIONS_NUMRETRIES,0,999);
AfxMessageBox(str,MB_ICONEXCLAMATION);
return;
}
val=_ttoi(m_OptionsPage2.m_Delay);
if ((val<0)||(val>999))
{
ShowPage(&m_OptionsPage2);
m_OptionsPage2.GetDlgItem(IDC_DELAY)->SetFocus();
CString str;
str.Format(IDS_OPTIONS_RETRYDELAY,0,999);
AfxMessageBox(str,MB_ICONEXCLAMATION);
return;
}
if (m_OptionsProxyPage.m_Type)
{
if (m_OptionsProxyPage.m_Host=="")
{
ShowPage(&m_OptionsProxyPage);
m_OptionsProxyPage.m_HostCtrl.SetFocus();
AfxMessageBox(IDS_OPTIONS_PROXYHOST,MB_ICONEXCLAMATION);
return;
}
val=_ttoi(m_OptionsProxyPage.m_Port);
if (val<=0 || val>=65535)
{
ShowPage(&m_OptionsProxyPage);
m_OptionsProxyPage.m_PortCtrl.SetFocus();
AfxMessageBox(IDS_OPTIONS_PROXYPORT,MB_ICONEXCLAMATION);
return;
}
}
if (m_OptionsTypePage.m_AsciiFiles=="")
{
m_OptionsTypePage.m_AsciiFiles="";
for (int i=0;i<m_OptionsTypePage.m_cTypeList.GetCount();i++)
{
CString tmp;
m_OptionsTypePage.m_cTypeList.GetText(i,tmp);
m_OptionsTypePage.m_AsciiFiles+=tmp+";";
}
m_OptionsTypePage.m_AsciiFiles.TrimRight( _T(";") );
m_OptionsTypePage.m_AsciiFiles+=";";
}
if (m_OptionsGssPage.m_GssServers=="")
{
m_OptionsGssPage.m_GssServers="";
for (int i=0;i<m_OptionsGssPage.m_cServerList.GetCount();i++)
{
CString tmp;
m_OptionsGssPage.m_cServerList.GetText(i,tmp);
m_OptionsGssPage.m_GssServers+=tmp+";";
}
m_OptionsGssPage.m_GssServers.TrimRight( _T(";") );
m_OptionsGssPage.m_GssServers+=";";
}
if (m_OptionsFirewallPage.m_bLimitPortRange)
{
int low=_ttoi(m_OptionsFirewallPage.m_PortRangeLow);
int high=_ttoi(m_OptionsFirewallPage.m_PortRangeHigh);
if ((low<1)||(low>65534))
{
ShowPage(&m_OptionsFirewallPage);
m_OptionsFirewallPage.m_cPortRangeLow.SetFocus();
CString str;
str.Format(IDS_OPTIONS_LIMITPORTRANGELOW,1,65534);
AfxMessageBox(str,MB_ICONEXCLAMATION);
return;
}
if ((high<2)||(high>65535))
{
ShowPage(&m_OptionsFirewallPage);
m_OptionsFirewallPage.m_cPortRangeLow.SetFocus();
CString str;
str.Format(IDS_OPTIONS_LIMITPORTRANGEHIGH,2,65535);
AfxMessageBox(str,MB_ICONEXCLAMATION);
return;
}
if (low>=high)
{
ShowPage(&m_OptionsFirewallPage);
m_OptionsFirewallPage.m_cPortRangeLow.SetFocus();
CString str;
str.Format(IDS_OPTIONS_LIMITPORTRANGEDIFF);
AfxMessageBox(str,MB_ICONEXCLAMATION);
return;
}
}
CString str=m_OptionsViewEditPage.m_Custom;
m_OptionsViewEditPage.m_Custom2="";
CString line;
for (int i=0;i<=str.GetLength();i++)
{
if (i==str.GetLength() || str[i]=='\r' || str[i]=='\n')
{
if (i!=str.GetLength())
{
line=str.Left(i);
str=str.Mid(i+1);
i=-1;
}
else
line=str;
line.TrimLeft( _T(" ") );
line.TrimRight( _T(" ") );
if (line=="")
continue;
CString ext;
int spos=line.Find(_T(" "));
int qpos=line.Find(_T("\""));
if (spos==-1)
continue;
if (spos<qpos || qpos==-1)
{
ext=line.Left(spos);
ext.Replace( _T(";"), _T("; "));
line=line.Mid(spos);
line.TrimLeft( _T(" ") );
line.Replace( _T(";"), _T("; "));
if (line=="")
continue;
m_OptionsViewEditPage.m_Custom2+=ext + _T(";") + line + _T(";");
continue;
}
else if (qpos!=0)
continue;
line=line.Mid(1);
qpos=line.Find( _T("\"") );
if (qpos==-1)
continue;
ext=line.Left(qpos);
ext.TrimLeft( _T(" ") );
ext.TrimRight( _T(" ") );
ext.Replace( _T(";"), _T("; "));
line=line.Mid(qpos+1);
line.TrimLeft( _T(" ") );
line.Replace( _T(";"), _T("; "));
if (line=="")
continue;
m_OptionsViewEditPage.m_Custom2+=ext + _T(";") + line + _T(";");
continue;
}
}
m_OptionsViewEditPage.m_Custom2.TrimRight( _T(";") );
if(m_OptionsIdentPage.m_bIdent)
{
if(m_OptionsIdentPage.m_UserID.IsEmpty())
{
ShowPage(&m_OptionsIdentPage);
m_OptionsIdentPage.m_cUserID.SetFocus();
AfxMessageBox(IDS_OPTIONS_IDENTUSERID, MB_ICONEXCLAMATION);
return;
}
if(m_OptionsIdentPage.m_System.IsEmpty())
{
ShowPage(&m_OptionsIdentPage);
m_OptionsIdentPage.m_cSystem.SetFocus();
AfxMessageBox(IDS_OPTIONS_IDENTSYSTEM, MB_ICONEXCLAMATION);
return;
}
}
CSAPrefsDialog::OnOK();
}
void COptions::InitLanguagePage()
{
m_OptionsLanguagePage.m_LanguageStringList.insert("English");
CFileFind find;
if (find.FindFile(((CFileZillaApp *)AfxGetApp())->m_appPath+"\\*.dll"))
{
BOOL bFind=TRUE;
while(bFind)
{
bFind=find.FindNextFile();
CString fn=find.GetFileName();
DWORD tmp=0;
LPTSTR str=new TCHAR[fn.GetLength()+1];
_tcscpy(str,fn);
DWORD len=GetFileVersionInfoSize(str,&tmp);
LPVOID pBlock=new char[len];
if (GetFileVersionInfo(str,0,len,pBlock))
{
LPVOID ptr=0;
UINT ptrlen;
TCHAR SubBlock[50];
// Structure used to store enumerated languages and code pages.
struct LANGANDCODEPAGE {
WORD wLanguage;
WORD wCodePage;
} *lpTranslate;
UINT cbTranslate;
// Read the list of languages and code pages.
if (VerQueryValue(pBlock,
TEXT("\\VarFileInfo\\Translation"),
(LPVOID*)&lpTranslate,
&cbTranslate))
{
// Read the file description for each language and code page.
_stprintf( SubBlock,
_T("\\StringFileInfo\\%04x%04x\\ProductName"),
lpTranslate[0].wLanguage,
lpTranslate[0].wCodePage);
// Retrieve file description for language and code page "0".
if (VerQueryValue(pBlock,
SubBlock,
&ptr,
&ptrlen))
{
LPTSTR pname=(LPTSTR)ptr;
CString productname=pname;
if ( productname==_T("FileZilla Language DLL") )
{
_stprintf( SubBlock,
_T("\\StringFileInfo\\%04x%04x\\Comments"),
lpTranslate[0].wLanguage,
lpTranslate[0].wCodePage);
if (VerQueryValue(pBlock,
SubBlock,
&ptr,
&ptrlen))
{
LPTSTR comment=(LPTSTR)ptr;
if (m_OptionsLanguagePage.m_LanguageStringList.find(comment)==m_OptionsLanguagePage.m_LanguageStringList.end())
m_OptionsLanguagePage.m_LanguageStringList.insert(comment);
}
}
}
}
}
delete [] str;
delete [] pBlock;
}
}
}
#include "mainfrm.h"
void COptions::ProcessLanguagePage()
{
unsigned __int64 version=0;
CString lang=GetOption(OPTION_LANGUAGE);
if (lang=="")
lang="English";
if (lang==m_OptionsLanguagePage.m_selLang)
return; // No language selected, don't change current one
if (m_OptionsLanguagePage.m_selLang==_T(""))
return;
if (m_OptionsLanguagePage.m_selLang==_T("English"))
{
//Set the new language
SetOption(OPTION_LANGUAGE,"English");
if (((CFileZillaApp *)AfxGetApp())->m_bLangSet)
FreeLibrary(AfxGetResourceHandle());
((CFileZillaApp *)AfxGetApp())->m_bLangSet=FALSE;
AfxSetResourceHandle(AfxGetInstanceHandle());
CMainFrame *pMainFrame=DYNAMIC_DOWNCAST(CMainFrame,GetParentFrame());
return;
}
CFileFind find;
if (find.FindFile(((CFileZillaApp *)AfxGetApp())->m_appPath+"\\*.dll"))
{
BOOL bFind=TRUE;
while(bFind)
{
bFind=find.FindNextFile();
CString fn=find.GetFileName();
DWORD tmp=0;
LPTSTR str=new TCHAR[fn.GetLength()+1];
_tcscpy(str,fn);
DWORD len=GetFileVersionInfoSize(str,&tmp);
LPVOID pBlock=new char[len];
if (GetFileVersionInfo(str,0,len,pBlock))
{
LPVOID ptr=0;
UINT ptrlen;
TCHAR SubBlock[50];
// Structure used to store enumerated languages and code pages.
struct LANGANDCODEPAGE {
WORD wLanguage;
WORD wCodePage;
} *lpTranslate;
UINT cbTranslate;
// Read the list of languages and code pages.
if (VerQueryValue(pBlock,
TEXT("\\VarFileInfo\\Translation"),
(LPVOID*)&lpTranslate,
&cbTranslate))
{
// Read the file description for each language and code page.
_stprintf( SubBlock,
_T("\\StringFileInfo\\%04x%04x\\ProductName"),
lpTranslate[0].wLanguage,
lpTranslate[0].wCodePage);
// Retrieve file description for language and code page "0".
if (VerQueryValue(pBlock,
SubBlock,
&ptr,
&ptrlen))
{
LPTSTR pname=(LPTSTR)ptr;
CString productname=pname;
if ( productname==("FileZilla Language DLL") )
{
_stprintf( SubBlock,
_T("\\StringFileInfo\\%04x%04x\\Comments"),
lpTranslate[0].wLanguage,
lpTranslate[0].wCodePage);
if (VerQueryValue(pBlock,
SubBlock,
&ptr,
&ptrlen))
{
LPTSTR comment=(LPTSTR)ptr;
CString Comment=comment;
if (Comment.Find(m_OptionsLanguagePage.m_selLang) != -1)
{
if (VerQueryValue(pBlock, _T("\\"), &ptr, &ptrlen))
{
VS_FIXEDFILEINFO *fi=(VS_FIXEDFILEINFO*)ptr;
unsigned __int64 curver=(((__int64)fi->dwFileVersionMS)<<32)+fi->dwFileVersionLS;
if (curver>version)
{
version=curver;
if (version>=MINVALIDDLLVERSION)
{
//Set the new language
SetOption(OPTION_LANGUAGE,m_OptionsLanguagePage.m_selLang);
m_OptionsLanguagePage.m_LanguageStringList.insert(comment);
if (((CFileZillaApp *)AfxGetApp())->m_bLangSet)
FreeLibrary(AfxGetResourceHandle());
((CFileZillaApp *)AfxGetApp())->m_bLangSet=TRUE;
HINSTANCE dll=LoadLibrary(fn);
if (dll)
AfxSetResourceHandle(dll);
}
}
}
}
}
}
}
}
}
delete [] str;
delete [] pBlock;
}
}
if (!version)
return;
if (version<MINVALIDDLLVERSION)
AfxMessageBox(IDS_ERRORMSG_LANGUAGEDLLVERSIONINVALID);
else if (version<MINDLLVERSION)
AfxMessageBox(IDS_STATUSMSG_LANGUAGEVERSIONDIFFERENT);
}
CSAPrefsSubDlg* COptions::GetCurPage()
{
int iPage=m_iCurPage;
// show the new one
if ((iPage >= 0) && (iPage < static_cast<int>(m_pages.size())))
{
pageStruct *pPS = (pageStruct *)m_pages[iPage];
ASSERT(pPS);
if (pPS)
{
ASSERT(pPS->pDlg);
if (pPS->pDlg)
{
return pPS->pDlg;
}
}
}
return NULL;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?