1 // TortoiseSVN - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2006, 2008 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "PersonalDictionary.h"
23 #include "PathUtils.h"
25 CPersonalDictionary::CPersonalDictionary(LONG lLanguage
/* = 0*/) :
28 m_lLanguage
= lLanguage
;
31 CPersonalDictionary::~CPersonalDictionary()
35 bool CPersonalDictionary::Load()
38 TCHAR line
[PDICT_MAX_WORD_LENGTH
+ 1];
42 TCHAR path
[MAX_PATH
]; //MAX_PATH ok here.
43 _tcscpy_s (path
, CPathUtils::GetAppDataDirectory());
46 m_lLanguage
= GetUserDefaultLCID();
49 _stprintf_s(sLang
, 10, _T("%ld"), m_lLanguage
);
50 _tcscat_s(path
, MAX_PATH
, sLang
);
51 _tcscat_s(path
, MAX_PATH
, _T(".dic"));
54 char filepath
[MAX_PATH
+1];
55 SecureZeroMemory(filepath
, sizeof(filepath
));
56 WideCharToMultiByte(CP_ACP
, NULL
, path
, -1, filepath
, MAX_PATH
, NULL
, NULL
);
62 std::vector
<std::wstring
> entry
;
65 File
.getline(line
, sizeof(line
)/sizeof(TCHAR
));
68 } while (File
.gcount() > 0);
74 bool CPersonalDictionary::AddWord(const CString
& sWord
)
78 if (sWord
.GetLength() >= PDICT_MAX_WORD_LENGTH
)
84 bool CPersonalDictionary::FindWord(const CString
& sWord
)
88 // even if the load failed for some reason, we mark it as loaded
89 // and just assume an empty personal dictionary
91 std::set
<CString
>::iterator it
;
92 it
= dict
.find(sWord
);
93 return (it
!= dict
.end());
96 bool CPersonalDictionary::Save()
100 TCHAR path
[MAX_PATH
]; //MAX_PATH ok here.
101 _tcscpy_s (path
, CPathUtils::GetAppDataDirectory());
104 m_lLanguage
= GetUserDefaultLCID();
107 _stprintf_s(sLang
, 10, _T("%ld"), m_lLanguage
);
108 _tcscat_s(path
, MAX_PATH
, sLang
);
109 _tcscat_s(path
, MAX_PATH
, _T(".dic"));
112 char filepath
[MAX_PATH
+1];
113 SecureZeroMemory(filepath
, sizeof(filepath
));
114 WideCharToMultiByte(CP_ACP
, NULL
, path
, -1, filepath
, MAX_PATH
, NULL
, NULL
);
115 File
.open(filepath
, std::ios_base::binary
);
116 for (std::set
<CString
>::iterator it
= dict
.begin(); it
!= dict
.end(); ++it
)
118 File
<< (LPCTSTR
)*it
<< _T("\n");