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

View file

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