From faad79479fd39967979c02948ec7bafb3e353644 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Mon, 31 Dec 2012 07:50:17 -0800 Subject: [PATCH] Handle FileNotFound errors when the user dictionary file doesn't exist --- aegisub/src/spellchecker_hunspell.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/aegisub/src/spellchecker_hunspell.cpp b/aegisub/src/spellchecker_hunspell.cpp index 018c9c1b1..468f54a80 100644 --- a/aegisub/src/spellchecker_hunspell.cpp +++ b/aegisub/src/spellchecker_hunspell.cpp @@ -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 stream(agi::io::Open(from_wx(userDicPath))); copy_if( ++agi::line_iterator(*stream), agi::line_iterator(), 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));