From 7ab0ccea9d218444ff11eb654f8ad94fe14a862a Mon Sep 17 00:00:00 2001 From: WrinklyNinja Date: Sun, 19 Jan 2014 07:45:13 +0000 Subject: [PATCH] Fixed API issues if a file to be loaded doesn't exist. --- src/api/api.cpp | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/api/api.cpp b/src/api/api.cpp index b3f315d9..1098c3f3 100644 --- a/src/api/api.cpp +++ b/src/api/api.cpp @@ -257,13 +257,16 @@ BOSS_API unsigned int boss_load_lists (boss_db db, const char * const masterlist std::list userTemp; try { - if (boost::algorithm::iends_with(masterlistPath, ".yaml")) { - YAML::Node tempNode = YAML::LoadFile(masterlistPath); - temp = tempNode["plugins"].as< std::list >(); - } else { - boost::filesystem::path p(masterlistPath); - std::list filler; - Loadv2Masterlist(p, temp, filler); + if (boost::filesystem::exists(masterlistPath)) { + if (boost::algorithm::iends_with(masterlistPath, ".yaml")) { + YAML::Node tempNode = YAML::LoadFile(masterlistPath); + temp = tempNode["plugins"].as< std::list >(); + } + else { + boost::filesystem::path p(masterlistPath); + std::list filler; + Loadv2Masterlist(p, temp, filler); + } } } catch (YAML::Exception& e) { extMessageStr = e.what(); @@ -273,17 +276,18 @@ BOSS_API unsigned int boss_load_lists (boss_db db, const char * const masterlist return boss_error_parse_fail; } - if (userlistPath != NULL) { - try { - if (boost::algorithm::iends_with(userlistPath, ".yaml")) { - YAML::Node tempNode = YAML::LoadFile(userlistPath); - userTemp = tempNode["plugins"].as< std::list >(); + try { + if (userlistPath != NULL) { + if (boost::filesystem::exists(userlistPath)) { + if (boost::algorithm::iends_with(userlistPath, ".yaml")) { + YAML::Node tempNode = YAML::LoadFile(userlistPath); + userTemp = tempNode["plugins"].as< std::list >(); + } } } - catch (YAML::Exception& e) { - extMessageStr = e.what(); - return boss_error_parse_fail; - } + } catch (YAML::Exception& e) { + extMessageStr = e.what(); + return boss_error_parse_fail; } //Also free memory.