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