📄 lang.cpp
字号:
}
//void CLang::SetRtlLocale(LCID lcid)
//{
// const SLanguage* pLangs = _aLanguages;
// while (pLangs->lid)
// {
// if (pLangs->lid == LANGIDFROMLCID(lcid))
// {
// if (pLangs->uCodepage)
// {
// CString strCodepage;
// strCodepage.Format(_T(".%u"), pLangs->uCodepage);
// _tsetlocale(LC_CTYPE, strCodepage);
// }
// break;
// }
// pLangs++;
// }
//}
//void CLang::InitThreadLocale()
//{
// ASSERT( m_wLanguageID != 0 );
//
// // NOTE: This function is for testing multi language support only.
// // NOTE: This function is *NOT* to be enabled in release builds nor to be offered by any Mod!
// if (theApp.GetProfileInt(_T("eMule"), _T("SetLanguageACP"), 0) != 0)
// {
// //LCID lcidUser = GetUserDefaultLCID(); // Installation, or altered by user in control panel (WinXP)
//
// // get the ANSI code page which is to be used for all non-Unicode conversions.
// LANGID lidSystem = m_wLanguageID;
//
// // get user's sorting preferences
// //UINT uSortIdUser = SORTIDFROMLCID(lcidUser);
// //UINT uSortVerUser = SORTVERSIONFROMLCID(lcidUser);
// // we can't use the same sorting paramters for 2 different Languages..
// UINT uSortIdUser = SORT_DEFAULT;
// UINT uSortVerUser = 0;
//
// // set thread locale, this is used for:
// // - MBCS->Unicode conversions (e.g. search results).
// // - Unicode->MBCS conversions (e.g. publishing local files (names) in network, or savint text files on local disk)...
// LCID lcid = MAKESORTLCID(lidSystem, uSortIdUser, uSortVerUser);
// SetThreadLocale(lcid);
//
// // if we set the thread locale (see comments above) we also have to specify the proper
// // code page for the C-RTL, otherwise we may not be able to store some strings as MBCS
// // (Unicode->MBCS conversion may fail)
// SetRtlLocale(lcid);
// }
// else if (theApp.GetProfileInt(_T("eMule"), _T("SetSystemACP"), 0) != 0)
// {
// LCID lcidSystem = GetSystemDefaultLCID(); // Installation, or altered by user in control panel (WinXP)
// //LCID lcidUser = GetUserDefaultLCID(); // Installation, or altered by user in control panel (WinXP)
//
// // get the ANSI code page which is to be used for all non-Unicode conversions.
// LANGID lidSystem = LANGIDFROMLCID(lcidSystem);
//
// // get user's sorting preferences
// //UINT uSortIdUser = SORTIDFROMLCID(lcidUser);
// //UINT uSortVerUser = SORTVERSIONFROMLCID(lcidUser);
// // we can't use the same sorting paramters for 2 different Languages..
// UINT uSortIdUser = SORT_DEFAULT;
// UINT uSortVerUser = 0;
//
// // create a thread locale which gives full backward compability for users which had run ANSI emule on
// // a system where the system's code page did not match the user's language..
// LCID lcid = MAKESORTLCID(lidSystem, uSortIdUser, uSortVerUser);
// LCID lcidThread = GetThreadLocale();
// if (lcidThread != lcid)
// {
// TRACE("+++ Setting thread locale: 0x%08x\n", lcid);
// SetThreadLocale(lcid);
//
// // if we set the thread locale (see comments above) we also have to specify the proper
// // code page for the C-RTL, otherwise we may not be able to store some strings as MBCS
// // (Unicode->MBCS conversion may fail)
// SetRtlLocale(lcid);
// }
// }
//}
//
//void InitThreadLocale()
//{
// theLang.InitThreadLocale();
//}
CString GetCodePageNameForLocale(LCID lcid)
{
CString strCodePage;
int iResult = GetLocaleInfo(lcid, LOCALE_IDEFAULTANSICODEPAGE, strCodePage.GetBuffer(6), 6);
strCodePage.ReleaseBuffer();
if (iResult > 0 && !strCodePage.IsEmpty())
{
UINT uCodePage = _tcstoul(strCodePage, NULL, 10);
if (uCodePage != ULONG_MAX)
{
CPINFOEXW CPInfoEx = {0};
BOOL (WINAPI *pfnGetCPInfoEx)(UINT, DWORD, LPCPINFOEXW);
(FARPROC&)pfnGetCPInfoEx = GetProcAddress(GetModuleHandle(_T("kernel32")), "GetCPInfoExW");
if (pfnGetCPInfoEx&& (*pfnGetCPInfoEx)(uCodePage, 0, &CPInfoEx))
strCodePage = CPInfoEx.CodePageName;
}
}
return strCodePage;
}
//
//bool CheckThreadLocale()
//{
// if (theApp.GetProfileInt(_T("eMule"), _T("SetLanguageACP"), 0) != 0)
// return true;
// int iSetSysACP = theApp.GetProfileInt(_T("eMule"), _T("SetSystemACP"), -1);
// if (iSetSysACP != -1)
// return true;
// iSetSysACP = 0;
//
// LCID lcidSystem = GetSystemDefaultLCID(); // Installation, or altered by user in control panel (WinXP)
// //LCID lcidUser = GetUserDefaultLCID(); // Installation, or altered by user in control panel (WinXP)
//
// // get the ANSI code page which is to be used for all non-Unicode conversions.
// LANGID lidSystem = LANGIDFROMLCID(lcidSystem);
//
// // get user's sorting preferences
// //UINT uSortIdUser = SORTIDFROMLCID(lcidUser);
// //UINT uSortVerUser = SORTVERSIONFROMLCID(lcidUser);
// // we can't use the same sorting paramters for 2 different Languages..
// UINT uSortIdUser = SORT_DEFAULT;
// UINT uSortVerUser = 0;
//
// // create a thread locale which gives full backward compability for users which had run ANSI emule on
// // a system where the system's code page did not match the user's language..
// LCID lcidSys = MAKESORTLCID(lidSystem, uSortIdUser, uSortVerUser);
// LCID lcidUsr = GetThreadLocale();
// if (lcidUsr != lcidSys)
// {
// CString strUsrCP = GetCodePageNameForLocale(lcidUsr);
// if (!strUsrCP.IsEmpty())
// strUsrCP = _T(" \"") + strUsrCP + _T('\"');
//
// CString strSysCP = GetCodePageNameForLocale(lcidSys);
// if (!strSysCP.IsEmpty())
// strSysCP = _T(" \"") + strSysCP + _T('\"');
//
// static const TCHAR szMsg[] =
// _T("eMule has detected that your current code page%s is not the same as your system's code page%s. For converting non-Unicode data to Unicode, you need to specify which code page to use.\r\n")
// _T("\r\n")
// _T("If you want eMule to use your current code page for converting non-Unicode data, click 'Yes'. (If you are using eMule for the first time or if you don't care about this issue at all, choose this option. This is the recommended setting.)\r\n")
// _T("\r\n")
// _T("If you want eMule to use your system's code page for converting non-Unicode data, click 'No'. (This will give you more backward compatibility when reading older *.met files created with non-Unicode eMule versions.)\r\n")
// _T("\r\n")
// _T("If you want to cancel and create backup of all your configuration files or visit our forum to learn more about this issue, click 'Cancel'.\r\n")
// ;
// CString strFullMsg;
// strFullMsg.Format(szMsg, strUsrCP, strSysCP);
// int iAnswer = AfxMessageBox(strFullMsg, MB_ICONSTOP | MB_YESNOCANCEL | MB_DEFBUTTON1);
// if (iAnswer == IDCANCEL)
// return false;
// if (iAnswer == IDNO)
// iSetSysACP = 1;
// }
// VERIFY( theApp.WriteProfileInt(_T("eMule"), _T("SetSystemACP"), iSetSysACP) );
// return true;
//}
//
//CString CLang::GetHtmlCharset()
//{
// ASSERT( m_wLanguageID != 0 );
//
// LPCTSTR pszHtmlCharset = NULL;
// const SLanguage* pLangs = _aLanguages;
// while (pLangs->lid)
// {
// if (pLangs->lid == m_wLanguageID)
// {
// pszHtmlCharset = pLangs->pszHtmlCharset;
// break;
// }
// pLangs++;
// }
//
// if (pszHtmlCharset == NULL || pszHtmlCharset[0] == _T('\0'))
// {
// ASSERT(0); // should never come here
//
// // try to get charset from code page
// LPCTSTR pszLcLocale = _tsetlocale(LC_CTYPE, NULL);
// if (pszLcLocale)
// {
// TCHAR szLocaleID[128];
// UINT uCodepage = 0;
// if (_stscanf(pszLcLocale, _T("%[a-zA-Z_].%u"), szLocaleID, &uCodepage) == 2 && uCodepage != 0)
// {
// CString strHtmlCodepage;
// strHtmlCodepage.Format(_T("windows-%u"), uCodepage);
// return strHtmlCodepage;
// }
// }
// }
//
// return pszHtmlCharset;
//}
//
//static HHOOK s_hRTLWindowsLayoutOldCbtFilterHook = NULL;
//
//LRESULT CALLBACK RTLWindowsLayoutCbtFilterHook(int code, WPARAM wParam, LPARAM lParam)
//{
// if (code == HCBT_CREATEWND)
// {
// //LPCREATESTRUCT lpcs = ((LPCBT_CREATEWND)lParam)->lpcs;
//
// //if ((lpcs->style & WS_CHILD) == 0)
// // lpcs->dwExStyle |= WS_EX_LAYOUTRTL; // doesn't seem to have any effect, but shouldn't hurt
//
// HWND hWnd = (HWND)wParam;
// if ((GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD) == 0) {
// SetWindowLong(hWnd, GWL_EXSTYLE, GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_LAYOUTRTL);
// }
// }
// return CallNextHookEx(s_hRTLWindowsLayoutOldCbtFilterHook, code, wParam, lParam);
//}
//
//void CemuleApp::EnableRTLWindowsLayout()
//{
// BOOL (WINAPI *pfnSetProcessDefaultLayout)(DWORD dwFlags);
// (FARPROC&)pfnSetProcessDefaultLayout = GetProcAddress(GetModuleHandle(_T("user32")), "SetProcessDefaultLayout");
// if (pfnSetProcessDefaultLayout)
// (*pfnSetProcessDefaultLayout)(LAYOUT_RTL);
//
// s_hRTLWindowsLayoutOldCbtFilterHook = SetWindowsHookEx(WH_CBT, RTLWindowsLayoutCbtFilterHook, NULL, GetCurrentThreadId());
//}
//
//void CemuleApp::DisableRTLWindowsLayout()
//{
// if (s_hRTLWindowsLayoutOldCbtFilterHook)
// {
// VERIFY( UnhookWindowsHookEx(s_hRTLWindowsLayoutOldCbtFilterHook) );
// s_hRTLWindowsLayoutOldCbtFilterHook = NULL;
//
// BOOL (WINAPI *pfnSetProcessDefaultLayout)(DWORD dwFlags);
// (FARPROC&)pfnSetProcessDefaultLayout = GetProcAddress(GetModuleHandle(_T("user32")), "SetProcessDefaultLayout");
// if (pfnSetProcessDefaultLayout)
// (*pfnSetProcessDefaultLayout)(0);
// }
//}
CString CLang::GetDefaultDirectory(eDefaultDirectory eDirectory, bool bCreate)
{
if (m_astrDefaultDirs[0].IsEmpty())
{
// Get out exectuable starting directory which was our default till Vista
TCHAR tchBuffer[490];
::GetModuleFileName(0,tchBuffer, 490); //get the path.
//pszFileName is the address of last '\' ;
LPTSTR pszFileName = _tcsrchr(tchBuffer, L'\\') + 1;
*pszFileName = L'\0';
m_astrDefaultDirs[EXECUTABLEDIR] = tchBuffer;
// set our results to old default / fallback values
// those 3 dirs are the base for all others
CString strSelectedDataBaseDirectory = m_astrDefaultDirs[EXECUTABLEDIR];
CString strSelectedConfigBaseDirectory = m_astrDefaultDirs[EXECUTABLEDIR];
CString strSelectedExpansionBaseDirectory = m_astrDefaultDirs[EXECUTABLEDIR];
// the use of ending backslashes is inconsitent, would need a rework throughout the code to fix this
m_astrDefaultDirs[CONFIGDIR] = strSelectedConfigBaseDirectory + _T("config\\");
m_astrDefaultDirs[TEMPDIR] = strSelectedDataBaseDirectory + _T("Temp");
m_astrDefaultDirs[INCOMINGDIR] = strSelectedDataBaseDirectory + _T("Incoming");
m_astrDefaultDirs[LOGDIR] = strSelectedConfigBaseDirectory + _T("logs\\");
m_astrDefaultDirs[INSTALLLANGDIR] = strSelectedExpansionBaseDirectory + _T("lang\\");
m_astrDefaultDirs[USERLANGDIR] = m_astrDefaultDirs[EXECUTABLEDIR] + _T("lang\\");
m_astrDefaultDirs[WEBSERVERDIR] = m_astrDefaultDirs[EXECUTABLEDIR] + _T("webserver\\");
m_astrDefaultDirs[SKINDIR] = strSelectedExpansionBaseDirectory + _T("skins");
m_astrDefaultDirs[DATABASEDIR] = strSelectedDataBaseDirectory; // has ending backslashes
m_astrDefaultDirs[CONFIGBASEDIR] = strSelectedConfigBaseDirectory; // has ending backslashes
// EXECUTABLEDIR
m_astrDefaultDirs[TOOLBARDIR] = strSelectedExpansionBaseDirectory + _T("skins");
m_astrDefaultDirs[EXPANSIONDIR] = strSelectedExpansionBaseDirectory; // has ending backslashes
m_astrDefaultDirs[UPDATEDIR] = m_astrDefaultDirs[EXECUTABLEDIR] + _T("update");
}
if (bCreate && ! m_astrDefaultDirs[eDirectory].IsEmpty())
{
switch (eDirectory)
{ // create the underlying directory first - be sure to adjust this if changing default directories
case CONFIGDIR:
case LOGDIR:
::CreateDirectory(m_astrDefaultDirs[CONFIGBASEDIR], NULL);
break;
case TEMPDIR:
case INCOMINGDIR:
::CreateDirectory(m_astrDefaultDirs[DATABASEDIR], NULL);
break;
case INSTALLLANGDIR:
::CreateDirectory(m_astrDefaultDirs[INSTALLLANGDIR],NULL);
break;
case USERLANGDIR:
::CreateDirectory(m_astrDefaultDirs[USERLANGDIR],NULL);
break;
case SKINDIR:
case TOOLBARDIR:
::CreateDirectory(m_astrDefaultDirs[EXPANSIONDIR], NULL);
break;
}
// ::CreateDirectory(m_astrDefaultDirs[eDirectory], NULL);
// m_abDefaultDirsCreated[eDirectory] = true;
}
return m_astrDefaultDirs[eDirectory];
}
CString CLang::GetDirectory(eDefaultDirectory eDirectory, bool bCreate)
{
switch (eDirectory)
{
case INSTALLLANGDIR:
if (m_astrDefaultDirs[INSTALLLANGDIR].IsEmpty())
return GetDefaultDirectory(eDirectory, TRUE);
else
return(m_astrDefaultDirs[INSTALLLANGDIR]);
case USERLANGDIR:
if (m_astrDefaultDirs[USERLANGDIR].IsEmpty())
return GetDefaultDirectory(eDirectory, TRUE);
else
return(m_astrDefaultDirs[USERLANGDIR]);
//case INCOMINGDIR:
// return m_strIncomingDir;
//case TEMPDIR:
// ASSERT( false ); // use GetTempDir() instead! This function can only return the first tempdirectory
// return GetTempDir(0);
//case SKINDIR:
// return m_strSkinProfileDir;
//case TOOLBARDIR:
// return m_sToolbarBitmapFolder;
//case UPDATEDIR:
// return m_strUpdateDir;
default:
return GetDefaultDirectory(eDirectory, bCreate);
}
}
void CLang::SetDirectory(eDefaultDirectory eDirectory, CString strNewDir)
{
m_astrDefaultDirs[eDirectory] = strNewDir;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -