Handle FileNotFound errors when the user dictionary file doesn't exist

This commit is contained in:
Thomas Goyne 2012-12-31 07:50:17 -08:00
parent 3e5ba4fd98
commit faad79479f
1 changed files with 9 additions and 6 deletions

View File

@ -95,22 +95,25 @@ void HunspellSpellChecker::RemoveWord(std::string const& word) {
void HunspellSpellChecker::ReadUserDictionary() {
customWords.clear();
// Ensure that the path exists
wxFileName fn(userDicPath);
if (!fn.DirExists()) {
wxFileName::Mkdir(fn.GetPath());
}
// Read the old contents of the user's dictionary
else {
try {
agi::scoped_ptr<std::istream> stream(agi::io::Open(from_wx(userDicPath)));
copy_if(
++agi::line_iterator<std::string>(*stream), agi::line_iterator<std::string>(),
inserter(customWords, customWords.end()),
[](std::string const& str) { return !str.empty(); });
}
catch (agi::FileNotFoundError const&) {
// Not an error; user dictionary just doesn't exist
}
}
void HunspellSpellChecker::WriteUserDictionary() {
// Ensure that the path exists
wxFileName fn(userDicPath);
if (!fn.DirExists())
wxFileName::Mkdir(fn.GetPath());
// Write the new dictionary
{
agi::io::Save writer(from_wx(userDicPath));