Skip to content

Commit 6501f4c

Browse files
author
xia ning
authored
Merge pull request #223 from AgoraIO/dev/win-3.5.0.3
windows language ini file
2 parents 2d38300 + 20f5a3c commit 6501f4c

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

windows/APIExample/APIExample/CConfig.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,27 @@ CConfig* CConfig::GetInstance()
88

99
CConfig::CConfig()
1010
{
11-
::GetModuleFileName(NULL, m_szZhConfigFile, MAX_PATH);
12-
LPTSTR lpLastSlash = _tcsrchr(m_szZhConfigFile, _T('\\')) + 1;
13-
_tcscpy_s(lpLastSlash, MAX_PATH, _T("zh-cn.ini"));
14-
15-
if (::GetFileAttributes(m_szZhConfigFile) == INVALID_FILE_ATTRIBUTES) {
16-
HANDLE hFile = ::CreateFile(m_szZhConfigFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
11+
TCHAR szZhConfigFile[MAX_PATH] = { 0 };
12+
TCHAR szEnConfigFile[MAX_PATH] = { 0 };
13+
::GetModuleFileName(NULL, szZhConfigFile, MAX_PATH);
14+
LPTSTR lpLastSlash = _tcsrchr(szZhConfigFile, _T('\\')) + 1;
15+
*lpLastSlash = 0;
16+
m_strZhConfigFile = szZhConfigFile;
17+
m_strZhConfigFile += _T("zh-cn.ini");
18+
19+
if (::GetFileAttributes(m_strZhConfigFile) == INVALID_FILE_ATTRIBUTES) {
20+
HANDLE hFile = ::CreateFile(m_strZhConfigFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1721
::CloseHandle(hFile);
1822
}
1923

20-
::GetModuleFileName(NULL, m_szEnConfigFile, MAX_PATH);
21-
LPTSTR lpLastSlashEn = _tcsrchr(m_szEnConfigFile, _T('\\')) + 1;
22-
_tcscpy_s(lpLastSlashEn, MAX_PATH, _T("en.ini"));
24+
::GetModuleFileName(NULL, szEnConfigFile, MAX_PATH);
25+
LPTSTR lpLastSlashEn = _tcsrchr(szEnConfigFile, _T('\\')) + 1;
26+
*lpLastSlashEn = 0;
27+
m_strEnConfigFile = szEnConfigFile;
28+
m_strEnConfigFile += _T("en.ini");
2329

24-
if (::GetFileAttributes(m_szEnConfigFile) == INVALID_FILE_ATTRIBUTES) {
25-
HANDLE hFile = ::CreateFile(m_szEnConfigFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
30+
if (::GetFileAttributes(m_strEnConfigFile) == INVALID_FILE_ATTRIBUTES) {
31+
HANDLE hFile = ::CreateFile(m_strEnConfigFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
2632
::CloseHandle(hFile);
2733
}
2834
LCID lcid = GetUserDefaultLCID();//LCID https://www.science.co.il/language/Locale-codes.php
@@ -42,9 +48,9 @@ CString CConfig::GetStringValue(CString key)
4248
{
4349
CString strValue = _T("");
4450
if (m_bChinese)
45-
::GetPrivateProfileString(_T("General"), key, _T("Unknown"), strValue.GetBuffer(MAX_PATH), MAX_PATH, m_szZhConfigFile);
51+
::GetPrivateProfileString(_T("General"), key, _T("Unknown"), strValue.GetBuffer(MAX_PATH), MAX_PATH, m_strZhConfigFile);
4652
else
47-
::GetPrivateProfileString(_T("General"), key, _T("Unknown"), strValue.GetBuffer(MAX_PATH), MAX_PATH, m_szEnConfigFile);
53+
::GetPrivateProfileString(_T("General"), key, _T("Unknown"), strValue.GetBuffer(MAX_PATH), MAX_PATH, m_strEnConfigFile);
4854
return strValue;
4955
}
5056

windows/APIExample/APIExample/CConfig.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class CConfig
1616
CString GetAPP_ID();
1717
private:
1818

19-
TCHAR m_szZhConfigFile[MAX_PATH];
20-
TCHAR m_szEnConfigFile[MAX_PATH];
19+
CString m_strZhConfigFile;
20+
CString m_strEnConfigFile;
2121
bool m_bChinese = false;
2222

2323
int hashSize = 1000;

0 commit comments

Comments
 (0)