From eec83bb32be2da5bd170af139809479b39e86dd0 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Mon, 26 May 2014 19:44:33 -0700 Subject: [PATCH] Cut down on FileNotFound exceptions thrown on startup --- libaegisub/common/json.cpp | 17 ++++++----------- libaegisub/lua/script_reader.cpp | 3 +++ src/spellchecker_hunspell.cpp | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/libaegisub/common/json.cpp b/libaegisub/common/json.cpp index d1fd1613e..af7798e0a 100644 --- a/libaegisub/common/json.cpp +++ b/libaegisub/common/json.cpp @@ -25,8 +25,7 @@ #include -namespace agi { - namespace json_util { +namespace agi { namespace json_util { json::UnknownElement parse(std::istream &stream) { try { @@ -48,24 +47,20 @@ json::UnknownElement file(agi::fs::path const& file) { json::UnknownElement file(agi::fs::path const& file, std::pair default_config) { try { - return parse(*io::Open(file)); + if (fs::FileExists(file)) + return parse(*io::Open(file)); } catch (fs::FileNotFound const&) { // Not an error - boost::interprocess::ibufferstream stream(default_config.first, default_config.second); - return parse(stream); } catch (json::Exception&) { // Already logged in parse - boost::interprocess::ibufferstream stream(default_config.first, default_config.second); - return parse(stream); } catch (agi::Exception& e) { LOG_E("json/file") << "Unexpected error when reading config file " << file << ": " << e.GetMessage(); - boost::interprocess::ibufferstream stream(default_config.first, default_config.second); - return parse(stream); } + boost::interprocess::ibufferstream stream(default_config.first, default_config.second); + return parse(stream); } - } // namespace json_util -} // namespace agi +} } diff --git a/libaegisub/lua/script_reader.cpp b/libaegisub/lua/script_reader.cpp index 7e49909a7..5045b2608 100644 --- a/libaegisub/lua/script_reader.cpp +++ b/libaegisub/lua/script_reader.cpp @@ -97,6 +97,9 @@ namespace agi { namespace lua { path = moonpath; } + if (!agi::fs::FileExists(path)) + continue; + try { if (!LoadFile(L, path)) return error(L, "Error loading Lua module \"%s\":\n%s", path.string().c_str(), check_string(L, 1).c_str()); diff --git a/src/spellchecker_hunspell.cpp b/src/spellchecker_hunspell.cpp index d58d92435..f03dd2447 100644 --- a/src/spellchecker_hunspell.cpp +++ b/src/spellchecker_hunspell.cpp @@ -90,7 +90,7 @@ void HunspellSpellChecker::ReadUserDictionary() { // Read the old contents of the user's dictionary try { - std::unique_ptr stream(agi::io::Open(userDicPath)); + auto stream = agi::io::Open(userDicPath); copy_if( ++agi::line_iterator(*stream), agi::line_iterator(), inserter(customWords, customWords.end()),