mirror of https://github.com/odrling/Aegisub
Cut down on FileNotFound exceptions thrown on startup
This commit is contained in:
parent
d08f4e73b4
commit
eec83bb32b
|
@ -25,8 +25,7 @@
|
|||
|
||||
#include <boost/interprocess/streams/bufferstream.hpp>
|
||||
|
||||
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<const char *, size_t> default_config) {
|
||||
try {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace json_util
|
||||
} // namespace agi
|
||||
} }
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -90,7 +90,7 @@ void HunspellSpellChecker::ReadUserDictionary() {
|
|||
|
||||
// Read the old contents of the user's dictionary
|
||||
try {
|
||||
std::unique_ptr<std::istream> stream(agi::io::Open(userDicPath));
|
||||
auto stream = agi::io::Open(userDicPath);
|
||||
copy_if(
|
||||
++agi::line_iterator<std::string>(*stream), agi::line_iterator<std::string>(),
|
||||
inserter(customWords, customWords.end()),
|
||||
|
|
Loading…
Reference in New Issue