mirror of
https://github.com/odrling/Aegisub
synced 2025-04-11 22:56:02 +02:00
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>
|
#include <boost/interprocess/streams/bufferstream.hpp>
|
||||||
|
|
||||||
namespace agi {
|
namespace agi { namespace json_util {
|
||||||
namespace json_util {
|
|
||||||
|
|
||||||
json::UnknownElement parse(std::istream &stream) {
|
json::UnknownElement parse(std::istream &stream) {
|
||||||
try {
|
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) {
|
json::UnknownElement file(agi::fs::path const& file, std::pair<const char *, size_t> default_config) {
|
||||||
try {
|
try {
|
||||||
|
if (fs::FileExists(file))
|
||||||
return parse(*io::Open(file));
|
return parse(*io::Open(file));
|
||||||
}
|
}
|
||||||
catch (fs::FileNotFound const&) {
|
catch (fs::FileNotFound const&) {
|
||||||
// Not an error
|
// Not an error
|
||||||
boost::interprocess::ibufferstream stream(default_config.first, default_config.second);
|
|
||||||
return parse(stream);
|
|
||||||
}
|
}
|
||||||
catch (json::Exception&) {
|
catch (json::Exception&) {
|
||||||
// Already logged in parse
|
// Already logged in parse
|
||||||
boost::interprocess::ibufferstream stream(default_config.first, default_config.second);
|
|
||||||
return parse(stream);
|
|
||||||
}
|
}
|
||||||
catch (agi::Exception& e) {
|
catch (agi::Exception& e) {
|
||||||
LOG_E("json/file") << "Unexpected error when reading config file " << file << ": " << e.GetMessage();
|
LOG_E("json/file") << "Unexpected error when reading config file " << file << ": " << e.GetMessage();
|
||||||
|
}
|
||||||
boost::interprocess::ibufferstream stream(default_config.first, default_config.second);
|
boost::interprocess::ibufferstream stream(default_config.first, default_config.second);
|
||||||
return parse(stream);
|
return parse(stream);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace json_util
|
} }
|
||||||
} // namespace agi
|
|
||||||
|
@ -97,6 +97,9 @@ namespace agi { namespace lua {
|
|||||||
path = moonpath;
|
path = moonpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!agi::fs::FileExists(path))
|
||||||
|
continue;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!LoadFile(L, path))
|
if (!LoadFile(L, path))
|
||||||
return error(L, "Error loading Lua module \"%s\":\n%s", path.string().c_str(), check_string(L, 1).c_str());
|
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
|
// Read the old contents of the user's dictionary
|
||||||
try {
|
try {
|
||||||
std::unique_ptr<std::istream> stream(agi::io::Open(userDicPath));
|
auto stream = agi::io::Open(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()),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user