mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Lowercased error constants, made static members of the boss::error class.
Also updated API to reflect recent changes.
This commit is contained in:
+61
-57
@@ -44,32 +44,36 @@
|
||||
#include <boost/unordered_set.hpp>
|
||||
#include <boost/unordered_map.hpp>
|
||||
|
||||
const unsigned int BOSS_API_OK = boss::OK;
|
||||
const unsigned int BOSS_API_ERROR_LIBLO_ERROR = boss::ERROR_LIBLO_ERROR;
|
||||
const unsigned int BOSS_API_ERROR_FILE_WRITE_FAIL = boss::ERROR_PATH_WRITE_FAIL;
|
||||
const unsigned int BOSS_API_ERROR_PARSE_FAIL = boss::ERROR_PATH_READ_FAIL;
|
||||
const unsigned int BOSS_API_ERROR_CONDITION_EVAL_FAIL = boss::ERROR_CONDITION_EVAL_FAIL;
|
||||
const unsigned int BOSS_API_ERROR_REGEX_EVAL_FAIL = boss::ERROR_REGEX_EVAL_FAIL;
|
||||
const unsigned int BOSS_API_ERROR_NO_MEM = boss::ERROR_NO_MEM;
|
||||
const unsigned int BOSS_API_ERROR_INVALID_ARGS = boss::ERROR_INVALID_ARGS;
|
||||
const unsigned int BOSS_API_ERROR_NO_TAG_MAP = boss::ERROR_NO_TAG_MAP;
|
||||
const unsigned int BOSS_API_ERROR_PATH_NOT_FOUND = boss::ERROR_PATH_NOT_FOUND;
|
||||
const unsigned int BOSS_API_RETURN_MAX = BOSS_API_ERROR_PATH_NOT_FOUND;
|
||||
const unsigned int boss_ok = boss::error::ok;
|
||||
const unsigned int boss_error_liblo_error = boss::error::liblo_error;
|
||||
const unsigned int boss_error_file_write_fail = boss::error::path_write_fail;
|
||||
const unsigned int boss_error_parse_fail = boss::error::path_read_fail;
|
||||
const unsigned int boss_error_condition_eval_fail = boss::error::condition_eval_fail;
|
||||
const unsigned int boss_error_regex_eval_fail = boss::error::regex_eval_fail;
|
||||
const unsigned int boss_error_no_mem = boss::error::no_mem;
|
||||
const unsigned int boss_error_invalid_args = boss::error::invalid_args;
|
||||
const unsigned int boss_error_no_tag_map = boss::error::no_tag_map;
|
||||
const unsigned int boss_error_path_not_found = boss::error::path_not_found;
|
||||
const unsigned int boss_error_no_game_detected = boss::error::no_game_detected;
|
||||
const unsigned int boss_error_subversion_error = boss::error::subversion_error;
|
||||
const unsigned int boss_return_max = boss_error_subversion_error;
|
||||
|
||||
// The following are the games identifiers used by the API.
|
||||
const unsigned int BOSS_API_GAME_TES4 = boss::GAME_TES4;
|
||||
const unsigned int BOSS_API_GAME_TES5 = boss::GAME_TES5;
|
||||
const unsigned int BOSS_API_GAME_FO3 = boss::GAME_FO3;
|
||||
const unsigned int BOSS_API_GAME_FONV = boss::GAME_FONV;
|
||||
const unsigned int boss_game_tes4 = boss::g_game_tes4;
|
||||
const unsigned int boss_game_tes5 = boss::g_game_tes5;
|
||||
const unsigned int boss_game_fo3 = boss::g_game_fo3;
|
||||
const unsigned int boss_game_fonv = boss::g_game_fonv;
|
||||
|
||||
// BOSS message types.
|
||||
const unsigned int BOSS_API_MESSAGE_SAY = boss::MESSAGE_SAY;
|
||||
const unsigned int BOSS_API_MESSAGE_WARN = boss::MESSAGE_WARN;
|
||||
const unsigned int BOSS_API_MESSAGE_ERROR = boss::MESSAGE_ERROR;
|
||||
const unsigned int boss_message_say = boss::g_message_say;
|
||||
const unsigned int boss_message_warn = boss::g_message_warn;
|
||||
const unsigned int boss_message_error = boss::g_message_error;
|
||||
|
||||
// BOSS message languages.
|
||||
BOSS_API extern const unsigned int BOSS_API_LANG_AUTO = boss::LANG_AUTO;
|
||||
BOSS_API extern const unsigned int BOSS_API_LANG_ENG = boss::LANG_ENG;
|
||||
BOSS_API extern const unsigned int boss_lang_any = boss::g_lang_any;
|
||||
BOSS_API extern const unsigned int boss_lang_english = boss::g_lang_english;
|
||||
BOSS_API extern const unsigned int boss_lang_spanish = boss::g_lang_spanish;
|
||||
BOSS_API extern const unsigned int boss_lang_russian = boss::g_lang_russian;
|
||||
|
||||
|
||||
struct _boss_db_int {
|
||||
@@ -129,11 +133,11 @@ char * ToNewCString(std::string str) {
|
||||
// until this function is called again or until CleanUpAPI is called.
|
||||
BOSS_API unsigned int boss_get_error_message (const char ** const message) {
|
||||
if (message == NULL)
|
||||
return BOSS_API_ERROR_INVALID_ARGS;
|
||||
return boss_error_invalid_args;
|
||||
|
||||
*message = extMessageStr;
|
||||
|
||||
return BOSS_API_OK;
|
||||
return boss_ok;
|
||||
}
|
||||
|
||||
// Frees memory allocated to error string.
|
||||
@@ -149,7 +153,7 @@ BOSS_API void boss_cleanup () {
|
||||
// Returns whether this version of BOSS supports the API from the given
|
||||
// BOSS version. Abstracts BOSS API stability policy away from clients.
|
||||
BOSS_API bool boss_is_compatible (const unsigned int versionMajor, const unsigned int versionMinor, const unsigned int versionPatch) {
|
||||
return versionMajor == boss::VERSION_MAJOR && versionMinor == boss::VERSION_MINOR;
|
||||
return versionMajor == boss::g_version_major && versionMinor == boss::g_version_minor;
|
||||
}
|
||||
|
||||
// Returns the version string for this version of BOSS.
|
||||
@@ -157,13 +161,13 @@ BOSS_API bool boss_is_compatible (const unsigned int versionMajor, const unsigne
|
||||
// CleanUpAPI is called.
|
||||
BOSS_API unsigned int boss_get_version (unsigned int * const versionMajor, unsigned int * const versionMinor, unsigned int * const versionPatch) {
|
||||
if (versionMajor == NULL || versionMinor == NULL || versionPatch == NULL)
|
||||
return BOSS_API_ERROR_INVALID_ARGS;
|
||||
return boss_error_invalid_args;
|
||||
|
||||
*versionMajor = boss::VERSION_MAJOR;
|
||||
*versionMinor = boss::VERSION_MINOR;
|
||||
*versionPatch = boss::VERSION_PATCH;
|
||||
*versionMajor = boss::g_version_major;
|
||||
*versionMinor = boss::g_version_minor;
|
||||
*versionPatch = boss::g_version_patch;
|
||||
|
||||
return BOSS_API_OK;
|
||||
return boss_ok;
|
||||
}
|
||||
|
||||
|
||||
@@ -179,8 +183,8 @@ BOSS_API unsigned int boss_get_version (unsigned int * const versionMajor, unsig
|
||||
// dataPath == NULL then the API will attempt to detect the data path of
|
||||
// the specified game.
|
||||
BOSS_API unsigned int boss_create_db (boss_db * const db, const unsigned int clientGame, const char * const gamePath) {
|
||||
if (db == NULL || (clientGame != BOSS_API_GAME_TES4 && clientGame != BOSS_API_GAME_TES5 && clientGame != BOSS_API_GAME_FO3 && clientGame != BOSS_API_GAME_FONV))
|
||||
return BOSS_API_ERROR_INVALID_ARGS;
|
||||
if (db == NULL || (clientGame != boss_game_tes4 && clientGame != boss_game_tes5 && clientGame != boss_game_fo3 && clientGame != boss_game_fonv))
|
||||
return boss_error_invalid_args;
|
||||
|
||||
//Set the locale to get encoding conversions working correctly.
|
||||
std::setlocale(LC_CTYPE, "");
|
||||
@@ -205,12 +209,12 @@ BOSS_API unsigned int boss_create_db (boss_db * const db, const unsigned int cli
|
||||
retVal = new _boss_db_int;
|
||||
} catch (std::bad_alloc& e) {
|
||||
extMessageStr = e.what();
|
||||
return BOSS_API_ERROR_NO_MEM;
|
||||
return boss_error_no_mem;
|
||||
}
|
||||
retVal->game = game;
|
||||
*db = retVal;
|
||||
|
||||
return BOSS_API_OK;
|
||||
return boss_ok;
|
||||
}
|
||||
|
||||
// Destroys the given DB, freeing any memory allocated as part of its use.
|
||||
@@ -230,7 +234,7 @@ BOSS_API void boss_destroy_db (boss_db db) {
|
||||
BOSS_API unsigned int boss_load_lists (boss_db db, const char * const masterlistPath,
|
||||
const char * const userlistPath) {
|
||||
if (db == NULL || masterlistPath == NULL)
|
||||
return BOSS_API_ERROR_INVALID_ARGS;
|
||||
return boss_error_invalid_args;
|
||||
|
||||
std::list<boss::Plugin> temp;
|
||||
std::list<boss::Plugin> userTemp;
|
||||
@@ -242,7 +246,7 @@ BOSS_API unsigned int boss_load_lists (boss_db db, const char * const masterlist
|
||||
userTemp = tempNode["plugins"].as< std::list<boss::Plugin> >();
|
||||
} catch (YAML::Exception& e) {
|
||||
extMessageStr = e.what();
|
||||
return BOSS_API_ERROR_PARSE_FAIL;
|
||||
return boss_error_parse_fail;
|
||||
}
|
||||
|
||||
//Also free memory.
|
||||
@@ -267,7 +271,7 @@ BOSS_API unsigned int boss_load_lists (boss_db db, const char * const masterlist
|
||||
db->userMetadata = userTemp;
|
||||
db->rawUserMetadata = userTemp;
|
||||
|
||||
return BOSS_API_OK;
|
||||
return boss_ok;
|
||||
}
|
||||
|
||||
// Evaluates all conditional lines and regex mods the loaded masterlist.
|
||||
@@ -289,7 +293,7 @@ BOSS_API unsigned int boss_eval_lists (boss_db db, const unsigned int language)
|
||||
regex = boost::regex(it->Name(), boost::regex::extended|boost::regex::icase);
|
||||
} catch (boost::regex_error& e) {
|
||||
extMessageStr = e.what();
|
||||
return BOSS_API_ERROR_REGEX_EVAL_FAIL;
|
||||
return boss_error_regex_eval_fail;
|
||||
}
|
||||
|
||||
for (boost::filesystem::directory_iterator itr(db->game.DataPath()); itr != boost::filesystem::directory_iterator(); ++itr) {
|
||||
@@ -320,7 +324,7 @@ BOSS_API unsigned int boss_eval_lists (boss_db db, const unsigned int language)
|
||||
regex = boost::regex(it->Name(), boost::regex::extended|boost::regex::icase);
|
||||
} catch (boost::regex_error& e) {
|
||||
extMessageStr = e.what();
|
||||
return BOSS_API_ERROR_INVALID_ARGS;
|
||||
return boss_error_invalid_args;
|
||||
}
|
||||
|
||||
for (boost::filesystem::directory_iterator itr(db->game.DataPath()); itr != boost::filesystem::directory_iterator(); ++itr) {
|
||||
@@ -341,7 +345,7 @@ BOSS_API unsigned int boss_eval_lists (boss_db db, const unsigned int language)
|
||||
}
|
||||
db->userMetadata = temp;
|
||||
|
||||
return BOSS_API_OK;
|
||||
return boss_ok;
|
||||
}
|
||||
|
||||
|
||||
@@ -354,7 +358,7 @@ BOSS_API unsigned int boss_eval_lists (boss_db db, const unsigned int language)
|
||||
// its contents are static and should not be freed by the client.
|
||||
BOSS_API unsigned int boss_get_tag_map (boss_db db, char *** const tagMap, size_t * const numTags) {
|
||||
if (db == NULL || tagMap == NULL || numTags == NULL)
|
||||
return BOSS_API_ERROR_INVALID_ARGS;
|
||||
return boss_error_invalid_args;
|
||||
|
||||
//Clear existing array allocation.
|
||||
if (db->extTagMap != NULL) {
|
||||
@@ -384,13 +388,13 @@ BOSS_API unsigned int boss_get_tag_map (boss_db db, char *** const tagMap, size_
|
||||
}
|
||||
|
||||
if (allTags.empty())
|
||||
return BOSS_API_OK;
|
||||
return boss_ok;
|
||||
|
||||
try {
|
||||
db->extTagMap = new char*[allTags.size()];
|
||||
} catch (std::bad_alloc& e) {
|
||||
extMessageStr = e.what();
|
||||
return BOSS_API_ERROR_NO_MEM;
|
||||
return boss_error_no_mem;
|
||||
}
|
||||
|
||||
unsigned int UID = 0;
|
||||
@@ -403,13 +407,13 @@ BOSS_API unsigned int boss_get_tag_map (boss_db db, char *** const tagMap, size_
|
||||
}
|
||||
} catch (std::bad_alloc& e) {
|
||||
extMessageStr = e.what();
|
||||
return BOSS_API_ERROR_NO_MEM;
|
||||
return boss_error_no_mem;
|
||||
}
|
||||
|
||||
*tagMap = db->extTagMap;
|
||||
*numTags = allTags.size();
|
||||
|
||||
return BOSS_API_OK;
|
||||
return boss_ok;
|
||||
}
|
||||
|
||||
// Returns arrays of Bash Tag UIDs for Bash Tags suggested for addition and removal
|
||||
@@ -426,7 +430,7 @@ BOSS_API unsigned int boss_get_plugin_tags (boss_db db, const char * const plugi
|
||||
size_t * const numTags_removed,
|
||||
bool * const userlistModified) {
|
||||
if (db == NULL || plugin == NULL || tagIds_added == NULL || numTags_added == NULL || tagIds_removed == NULL || numTags_removed == NULL || userlistModified == NULL)
|
||||
return BOSS_API_ERROR_INVALID_ARGS;
|
||||
return boss_error_invalid_args;
|
||||
|
||||
|
||||
//Clear existing array allocations.
|
||||
@@ -441,7 +445,7 @@ BOSS_API unsigned int boss_get_plugin_tags (boss_db db, const char * const plugi
|
||||
*numTags_removed = 0;
|
||||
|
||||
if (db->bashTagMap.empty())
|
||||
return BOSS_API_ERROR_NO_TAG_MAP;
|
||||
return boss_error_no_tag_map;
|
||||
|
||||
boost::unordered_set<std::string> tagsAdded, tagsRemoved;
|
||||
std::list<boss::Plugin>::iterator pluginIt = std::find(db->metadata.begin(), db->metadata.end(), boss::Plugin(plugin));
|
||||
@@ -488,7 +492,7 @@ BOSS_API unsigned int boss_get_plugin_tags (boss_db db, const char * const plugi
|
||||
}
|
||||
} catch (std::bad_alloc& e) {
|
||||
extMessageStr = e.what();
|
||||
return BOSS_API_ERROR_NO_MEM;
|
||||
return boss_error_no_mem;
|
||||
}
|
||||
|
||||
//Set outputs.
|
||||
@@ -497,7 +501,7 @@ BOSS_API unsigned int boss_get_plugin_tags (boss_db db, const char * const plugi
|
||||
*numTags_added = numAdded;
|
||||
*numTags_removed = numRemoved;
|
||||
|
||||
return BOSS_API_OK;
|
||||
return boss_ok;
|
||||
}
|
||||
|
||||
// Returns the messages attached to the given plugin. Messages are valid until Load,
|
||||
@@ -507,7 +511,7 @@ BOSS_API unsigned int boss_get_plugin_messages (boss_db db, const char * const p
|
||||
boss_message ** const messages,
|
||||
size_t * const numMessages) {
|
||||
if (db == NULL || plugin == NULL || messages == NULL || numMessages == NULL)
|
||||
return BOSS_API_ERROR_INVALID_ARGS;
|
||||
return boss_error_invalid_args;
|
||||
|
||||
//Clear existing array allocation.
|
||||
if (db->extMessageArray != NULL) {
|
||||
@@ -537,17 +541,17 @@ BOSS_API unsigned int boss_get_plugin_messages (boss_db db, const char * const p
|
||||
int i = 0;
|
||||
for (std::list<boss::Message>::const_iterator it=pluginMessages.begin(), endIt=pluginMessages.end(); it != endIt; ++it) {
|
||||
db->extMessageArray[i].type = it->Type();
|
||||
db->extMessageArray[i].message = ToNewCString(it->Content());
|
||||
db->extMessageArray[i].message = ToNewCString(it->ChooseContent(boss::g_lang_any).Str());
|
||||
}
|
||||
} catch (std::bad_alloc& e) {
|
||||
extMessageStr = e.what();
|
||||
return BOSS_API_ERROR_NO_MEM;
|
||||
return boss_error_no_mem;
|
||||
}
|
||||
|
||||
*messages = db->extMessageArray;
|
||||
*numMessages = db->extMessageArraySize;
|
||||
|
||||
return BOSS_API_OK;
|
||||
return boss_ok;
|
||||
}
|
||||
|
||||
// Writes a minimal masterlist that only contains mods that have Bash Tag suggestions,
|
||||
@@ -556,10 +560,10 @@ BOSS_API unsigned int boss_get_plugin_messages (boss_db db, const char * const p
|
||||
// for output. If outputFile already exists, it will only be overwritten if overwrite is true.
|
||||
BOSS_API unsigned int boss_write_minimal_list (boss_db db, const char * const outputFile, const bool overwrite) {
|
||||
if (db == NULL || outputFile == NULL)
|
||||
return BOSS_API_ERROR_INVALID_ARGS;
|
||||
return boss_error_invalid_args;
|
||||
|
||||
if (boost::filesystem::exists(outputFile) && !overwrite)
|
||||
return BOSS_API_ERROR_INVALID_ARGS;
|
||||
return boss_error_invalid_args;
|
||||
|
||||
std::list<boss::Plugin> temp = db->metadata;
|
||||
for (std::list<boss::Plugin>::iterator it=temp.begin(), endIt=temp.end(); it != endIt; ++it) {
|
||||
@@ -568,8 +572,8 @@ BOSS_API unsigned int boss_write_minimal_list (boss_db db, const char * const ou
|
||||
|
||||
std::list<boss::Message> messages = it->Messages(), newMessages;
|
||||
for (std::list<boss::Message>::iterator messageIter = messages.begin(); messageIter != messages.end(); ++messageIter) {
|
||||
if (messageIter->Type() == BOSS_API_MESSAGE_WARN) {
|
||||
const std::string content = messageIter->Content();
|
||||
if (messageIter->Type() == boss_message_warn) {
|
||||
const std::string content = messageIter->ChooseContent(boss::g_lang_any).Str();
|
||||
if (boost::contains(content, "Do not clean"))
|
||||
newMessages.push_back(*messageIter);
|
||||
else if (boost::contains(content, "Contains dirty edits"))
|
||||
@@ -589,9 +593,9 @@ BOSS_API unsigned int boss_write_minimal_list (boss_db db, const char * const ou
|
||||
|
||||
std::ofstream out(outputFile);
|
||||
if (out.fail())
|
||||
return BOSS_API_ERROR_INVALID_ARGS;
|
||||
return boss_error_invalid_args;
|
||||
out << yout.c_str();
|
||||
out.close();
|
||||
|
||||
return BOSS_API_OK;
|
||||
return boss_ok;
|
||||
}
|
||||
|
||||
+25
-20
@@ -83,32 +83,37 @@ typedef struct {
|
||||
|
||||
|
||||
// The following are the possible codes that the API can return.
|
||||
BOSS_API extern const unsigned int BOSS_API_OK;
|
||||
BOSS_API extern const unsigned int BOSS_API_ERROR_LIBLO_ERROR;
|
||||
BOSS_API extern const unsigned int BOSS_API_ERROR_FILE_WRITE_FAIL;
|
||||
BOSS_API extern const unsigned int BOSS_API_ERROR_PARSE_FAIL;
|
||||
BOSS_API extern const unsigned int BOSS_API_ERROR_CONDITION_EVAL_FAIL;
|
||||
BOSS_API extern const unsigned int BOSS_API_ERROR_REGEX_EVAL_FAIL;
|
||||
BOSS_API extern const unsigned int BOSS_API_ERROR_NO_MEM;
|
||||
BOSS_API extern const unsigned int BOSS_API_ERROR_INVALID_ARGS;
|
||||
BOSS_API extern const unsigned int BOSS_API_ERROR_NO_TAG_MAP;
|
||||
BOSS_API extern const unsigned int BOSS_API_ERROR_PATH_NOT_FOUND;
|
||||
BOSS_API extern const unsigned int BOSS_API_RETURN_MAX;
|
||||
BOSS_API extern const unsigned int boss_ok;
|
||||
BOSS_API extern const unsigned int boss_error_liblo_error;
|
||||
BOSS_API extern const unsigned int boss_error_file_write_fail;
|
||||
BOSS_API extern const unsigned int boss_error_parse_fail;
|
||||
BOSS_API extern const unsigned int boss_error_condition_eval_fail;
|
||||
BOSS_API extern const unsigned int boss_error_regex_eval_fail;
|
||||
BOSS_API extern const unsigned int boss_error_no_mem;
|
||||
BOSS_API extern const unsigned int boss_error_invalid_args;
|
||||
BOSS_API extern const unsigned int boss_error_no_tag_map;
|
||||
BOSS_API extern const unsigned int boss_error_path_not_found;
|
||||
BOSS_API extern const unsigned int boss_error_no_game_detected;
|
||||
BOSS_API extern const unsigned int boss_error_subversion_error;
|
||||
BOSS_API extern const unsigned int boss_return_max;
|
||||
|
||||
// The following are the games identifiers used by the API.
|
||||
BOSS_API extern const unsigned int BOSS_API_GAME_TES4;
|
||||
BOSS_API extern const unsigned int BOSS_API_GAME_TES5;
|
||||
BOSS_API extern const unsigned int BOSS_API_GAME_FO3;
|
||||
BOSS_API extern const unsigned int BOSS_API_GAME_FONV;
|
||||
BOSS_API extern const unsigned int boss_game_tes4;
|
||||
BOSS_API extern const unsigned int boss_game_tes5;
|
||||
BOSS_API extern const unsigned int boss_game_fo3;
|
||||
BOSS_API extern const unsigned int boss_game_fonv;
|
||||
|
||||
// BOSS message types.
|
||||
BOSS_API extern const unsigned int BOSS_API_MESSAGE_SAY;
|
||||
BOSS_API extern const unsigned int BOSS_API_MESSAGE_WARN;
|
||||
BOSS_API extern const unsigned int BOSS_API_MESSAGE_ERROR;
|
||||
BOSS_API extern const unsigned int boss_message_say;
|
||||
BOSS_API extern const unsigned int boss_message_warn;
|
||||
BOSS_API extern const unsigned int boss_message_error;
|
||||
BOSS_API extern const unsigned int boss_message_tag;
|
||||
|
||||
// BOSS message languages.
|
||||
BOSS_API extern const unsigned int BOSS_API_LANG_AUTO;
|
||||
BOSS_API extern const unsigned int BOSS_API_LANG_ENG;
|
||||
BOSS_API extern const unsigned int boss_lang_any;
|
||||
BOSS_API extern const unsigned int boss_lang_english;
|
||||
BOSS_API extern const unsigned int boss_lang_spanish;
|
||||
BOSS_API extern const unsigned int boss_lang_russian;
|
||||
|
||||
|
||||
//////////////////////////////
|
||||
|
||||
+14
-13
@@ -29,19 +29,6 @@
|
||||
|
||||
namespace boss {
|
||||
|
||||
const unsigned int OK = 0;
|
||||
const unsigned int ERROR_LIBLO_ERROR = 1;
|
||||
const unsigned int ERROR_PATH_WRITE_FAIL = 2;
|
||||
const unsigned int ERROR_PATH_READ_FAIL = 3;
|
||||
const unsigned int ERROR_CONDITION_EVAL_FAIL = 4;
|
||||
const unsigned int ERROR_REGEX_EVAL_FAIL = 5;
|
||||
const unsigned int ERROR_NO_MEM = 6;
|
||||
const unsigned int ERROR_INVALID_ARGS = 7;
|
||||
const unsigned int ERROR_NO_TAG_MAP = 8;
|
||||
const unsigned int ERROR_PATH_NOT_FOUND = 9;
|
||||
const unsigned int ERROR_NO_GAME_DETECTED = 10;
|
||||
const unsigned int ERROR_SUBVERSION_ERROR = 11;
|
||||
|
||||
class error : public std::exception {
|
||||
public:
|
||||
error(const unsigned int code_arg, const std::string& what_arg) : _code(code_arg), _what(what_arg) {}
|
||||
@@ -49,6 +36,20 @@ namespace boss {
|
||||
|
||||
unsigned int code() const { return _code; }
|
||||
const char * what() const throw() { return _what.c_str(); }
|
||||
|
||||
|
||||
static const unsigned int ok = 0;
|
||||
static const unsigned int liblo_error = 1;
|
||||
static const unsigned int path_write_fail = 2;
|
||||
static const unsigned int path_read_fail = 3;
|
||||
static const unsigned int condition_eval_fail = 4;
|
||||
static const unsigned int regex_eval_fail = 5;
|
||||
static const unsigned int no_mem = 6;
|
||||
static const unsigned int invalid_args = 7;
|
||||
static const unsigned int no_tag_map = 8;
|
||||
static const unsigned int path_not_found = 9;
|
||||
static const unsigned int no_game_detected = 10;
|
||||
static const unsigned int subversion_error = 11;
|
||||
private:
|
||||
std::string _what;
|
||||
unsigned int _code;
|
||||
|
||||
+10
-10
@@ -92,7 +92,7 @@ namespace boss {
|
||||
libespmGame = "FalloutNV";
|
||||
_masterlistURL = "http://better-oblivion-sorting-software.googlecode.com/svn/data/boss-fallout-nv/masterlist.yaml";
|
||||
} else
|
||||
throw error(ERROR_INVALID_ARGS, "Invalid game ID supplied.");
|
||||
throw error(error::invalid_args, "Invalid game ID supplied.");
|
||||
|
||||
if (!folder.empty())
|
||||
bossFolderName = folder;
|
||||
@@ -100,7 +100,7 @@ namespace boss {
|
||||
if (fs::exists(g_path_libespm_settings))
|
||||
espm_settings = espm::Settings(g_path_libespm_settings.string(), libespmGame);
|
||||
else
|
||||
throw error(ERROR_PATH_NOT_FOUND, "Libespm settings file could not be found.");
|
||||
throw error(error::path_not_found, "Libespm settings file could not be found.");
|
||||
}
|
||||
|
||||
Game& Game::SetDetails(const std::string& name, const std::string& masterFile,
|
||||
@@ -142,7 +142,7 @@ namespace boss {
|
||||
}
|
||||
|
||||
if (gamePath.empty())
|
||||
throw error(ERROR_PATH_NOT_FOUND, "Game path could not be detected.");
|
||||
throw error(error::path_not_found, "Game path could not be detected.");
|
||||
|
||||
RefreshActivePluginsList();
|
||||
CreateBOSSGameFolder();
|
||||
@@ -236,7 +236,7 @@ namespace boss {
|
||||
lo_get_error_message(&e);
|
||||
string err = string("libloadorder failed to create a game handle. Details: ") + err;
|
||||
lo_cleanup();
|
||||
throw error(ERROR_LIBLO_ERROR, err);
|
||||
throw error(error::liblo_error, err);
|
||||
}
|
||||
|
||||
ret = lo_set_game_master(gh, _masterFile.c_str());
|
||||
@@ -247,7 +247,7 @@ namespace boss {
|
||||
lo_destroy_handle(gh);
|
||||
string err = string("libloadorder total conversion support setup failed. Details: ") + e;
|
||||
lo_cleanup();
|
||||
throw error(ERROR_LIBLO_ERROR,err);
|
||||
throw error(error::liblo_error, err);
|
||||
}
|
||||
|
||||
if (lo_get_active_plugins(gh, &pluginArr, &pluginArrSize) != LIBLO_OK) {
|
||||
@@ -256,7 +256,7 @@ namespace boss {
|
||||
lo_destroy_handle(gh);
|
||||
string err = string("libloadorder failed to get the active plugins list. Details: ") + e;
|
||||
lo_cleanup();
|
||||
throw error(ERROR_LIBLO_ERROR, err);
|
||||
throw error(error::liblo_error, err);
|
||||
}
|
||||
|
||||
for (size_t i=0; i < pluginArrSize; ++i) {
|
||||
@@ -290,7 +290,7 @@ namespace boss {
|
||||
lo_get_error_message(&e);
|
||||
string err = string("libloadorder game handle creation failed. Details: ") + e;
|
||||
lo_cleanup();
|
||||
throw error(ERROR_LIBLO_ERROR, err);
|
||||
throw error(error::liblo_error, err);
|
||||
}
|
||||
|
||||
ret = lo_set_game_master(gh, _masterFile.c_str());
|
||||
@@ -301,7 +301,7 @@ namespace boss {
|
||||
lo_destroy_handle(gh);
|
||||
string err = string("libloadorder total conversion support setup failed. Details: ") + e;
|
||||
lo_cleanup();
|
||||
throw error(ERROR_LIBLO_ERROR, err);
|
||||
throw error(error::liblo_error, err);
|
||||
}
|
||||
|
||||
pluginArrSize = loadOrder.size();
|
||||
@@ -322,7 +322,7 @@ namespace boss {
|
||||
lo_destroy_handle(gh);
|
||||
string err = string("libloadorder failed to set the load order. Details: ") + e;
|
||||
lo_cleanup();
|
||||
throw error(ERROR_LIBLO_ERROR, err);
|
||||
throw error(error::liblo_error, err);
|
||||
}
|
||||
|
||||
for (size_t i=0; i < pluginArrSize; i++)
|
||||
@@ -338,7 +338,7 @@ namespace boss {
|
||||
if (!fs::exists(g_path_local / bossFolderName))
|
||||
fs::create_directory(g_path_local / bossFolderName);
|
||||
} catch (fs::filesystem_error& e) {
|
||||
throw error(ERROR_PATH_WRITE_FAIL, string("Could not create BOSS folder for game. Details: ") + e.what());
|
||||
throw error(error::path_write_fail, string("Could not create BOSS folder for game. Details: ") + e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -477,7 +477,7 @@ namespace boss {
|
||||
AppendScripts(body);
|
||||
|
||||
if (!doc.save_file(file.c_str(), "\t", pugi::format_default | pugi::format_no_declaration))
|
||||
throw boss::error(ERROR_PATH_WRITE_FAIL, "Could not write BOSS report.");
|
||||
throw boss::error(boss::error::path_write_fail, "Could not write BOSS report.");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ namespace boss {
|
||||
} while (ifile);
|
||||
chksum = result.checksum();
|
||||
} else {
|
||||
throw error(ERROR_PATH_READ_FAIL, "Unable to open \"" + filename.string() + "\" for CRC calculation.");
|
||||
throw error(error::path_read_fail, "Unable to open \"" + filename.string() + "\" for CRC calculation.");
|
||||
}
|
||||
// LOG_DEBUG("CRC32('%s'): 0x%x", filename.string().c_str(), chksum);
|
||||
return chksum;
|
||||
|
||||
@@ -103,11 +103,11 @@ namespace boss {
|
||||
try {
|
||||
r = boost::spirit::qi::phrase_parse(begin, end, grammar, skipper, eval);
|
||||
} catch (boss::error& e) {
|
||||
throw boss::error(boss::ERROR_PATH_READ_FAIL, "Parsing of condition \"" + _condition + "\" failed: " + e.what());
|
||||
throw boss::error(boss::error::path_read_fail, "Parsing of condition \"" + _condition + "\" failed: " + e.what());
|
||||
}
|
||||
|
||||
if (!r || begin != end)
|
||||
throw boss::error(boss::ERROR_PATH_READ_FAIL, "Parsing of condition \"" + _condition + "\" failed!");
|
||||
throw boss::error(boss::error::path_read_fail, "Parsing of condition \"" + _condition + "\" failed!");
|
||||
|
||||
game.conditionCache.emplace(boost::to_lower_copy(_condition), eval);
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace boss {
|
||||
|
||||
//Create I/O pipes.
|
||||
if (!CreatePipe(&consoleRead, &consoleWrite, &saAttr, 0))
|
||||
throw error(ERROR_SUBVERSION_ERROR, "Could not create pipe for Subversion process.");
|
||||
throw error(error::subversion_error, "Could not create pipe for Subversion process.");
|
||||
|
||||
//Create a child process.
|
||||
ZeroMemory(&piProcInfo, sizeof(PROCESS_INFORMATION));
|
||||
@@ -94,15 +94,15 @@ namespace boss {
|
||||
delete [] cmdLine;
|
||||
|
||||
if (!result)
|
||||
throw error(ERROR_SUBVERSION_ERROR, "Could not create Subversion process.");
|
||||
throw error(error::subversion_error, "Could not create Subversion process.");
|
||||
|
||||
WaitForSingleObject(piProcInfo.hProcess, INFINITE);
|
||||
|
||||
if (!GetExitCodeProcess(piProcInfo.hProcess, &exitCode))
|
||||
throw error(ERROR_SUBVERSION_ERROR, "Could not get Subversion process exit code.");
|
||||
throw error(error::subversion_error, "Could not get Subversion process exit code.");
|
||||
|
||||
if (!ReadFile(consoleRead, chBuf, BUFSIZE, &dwRead, NULL))
|
||||
throw error(ERROR_SUBVERSION_ERROR, "Could not read Subversion process output.");
|
||||
throw error(error::subversion_error, "Could not read Subversion process output.");
|
||||
|
||||
output = string(chBuf, dwRead);
|
||||
|
||||
@@ -149,13 +149,13 @@ namespace boss {
|
||||
//Working copy not set up, perform a checkout.
|
||||
command = g_path_svn.string() + " co --depth empty " + game.URL().substr(0, game.URL().rfind('/')) + " \"" + game.MasterlistPath().parent_path().string() + "\\.\"";
|
||||
if (!RunCommand(command, output))
|
||||
throw error(ERROR_SUBVERSION_ERROR, "Subversion could not perform a checkout. Details: " + output);
|
||||
throw error(error::subversion_error, "Subversion could not perform a checkout. Details: " + output);
|
||||
}
|
||||
|
||||
//Now update masterlist.
|
||||
command = g_path_svn.string() + " update \"" + game.MasterlistPath().string() + "\"";
|
||||
if (!RunCommand(command, output))
|
||||
throw error(ERROR_SUBVERSION_ERROR, "Subversion could not update the masterlist. Details: " + output);
|
||||
throw error(error::subversion_error, "Subversion could not update the masterlist. Details: " + output);
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
@@ -163,7 +163,7 @@ namespace boss {
|
||||
//Now get the masterlist revision.
|
||||
command = g_path_svn.string() + " info \"" + game.MasterlistPath().string() + "\"";
|
||||
if (!RunCommand(command, output))
|
||||
throw error(ERROR_SUBVERSION_ERROR, "Subversion could not read the masterlist revision number. Details: " + output);
|
||||
throw error(error::subversion_error, "Subversion could not read the masterlist revision number. Details: " + output);
|
||||
|
||||
revision = GetRevision(output);
|
||||
|
||||
@@ -176,7 +176,7 @@ namespace boss {
|
||||
parsingErrors.push_back("Masterlist revision " + revision + ": " + e.what());
|
||||
command = g_path_svn.string() + " update --revision PREV \"" + game.MasterlistPath().string() + "\"";
|
||||
if (!RunCommand(command, output))
|
||||
throw error(ERROR_SUBVERSION_ERROR, "Subversion could not update the masterlist. Details: " + output);
|
||||
throw error(error::subversion_error, "Subversion could not update the masterlist. Details: " + output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -410,7 +410,7 @@ namespace boss {
|
||||
}
|
||||
|
||||
if (!IsSafePath(file))
|
||||
throw boss::error(boss::ERROR_INVALID_ARGS, "The file path \"" + file + "\" is invalid.");
|
||||
throw boss::error(boss::error::invalid_args, "The file path \"" + file + "\" is invalid.");
|
||||
|
||||
if (IsPlugin(file))
|
||||
result = boost::filesystem::exists(game->DataPath() / file) || boost::filesystem::exists(game->DataPath() / (file + ".ghost"));
|
||||
@@ -449,7 +449,7 @@ namespace boss {
|
||||
}
|
||||
|
||||
if (boost::contains(parent, "../../"))
|
||||
throw boss::error(boss::ERROR_INVALID_ARGS, "The folder path \"" + parent + "\" is invalid.");
|
||||
throw boss::error(boss::error::invalid_args, "The folder path \"" + parent + "\" is invalid.");
|
||||
|
||||
//Now we have a valid parent path and a regex filename. Check that
|
||||
//the parent path exists and is a directory.
|
||||
@@ -462,7 +462,7 @@ namespace boss {
|
||||
try {
|
||||
regex = boost::regex(filename, boost::regex::extended|boost::regex::icase);
|
||||
} catch (boost::regex_error& e) {
|
||||
throw boss::error(boss::ERROR_INVALID_ARGS, "The regex string \"" + filename + "\" is invalid.");
|
||||
throw boss::error(boss::error::invalid_args, "The regex string \"" + filename + "\" is invalid.");
|
||||
}
|
||||
|
||||
for (boost::filesystem::directory_iterator itr(parent_path); itr != boost::filesystem::directory_iterator(); ++itr) {
|
||||
@@ -476,7 +476,7 @@ namespace boss {
|
||||
void CheckSum(bool& result, const std::string& file, const uint32_t checksum) {
|
||||
|
||||
if (!IsSafePath(file))
|
||||
throw boss::error(boss::ERROR_INVALID_ARGS, "The file path \"" + file + "\" is invalid.");
|
||||
throw boss::error(boss::error::invalid_args, "The file path \"" + file + "\" is invalid.");
|
||||
|
||||
uint32_t crc;
|
||||
boost::unordered_map<std::string,uint32_t>::iterator it = game->crcCache.find(boost::to_lower_copy(file));
|
||||
@@ -538,7 +538,7 @@ namespace boss {
|
||||
std::string context(errorpos, min(errorpos +50, last));
|
||||
boost::trim(context);
|
||||
|
||||
throw boss::error(boss::ERROR_CONDITION_EVAL_FAIL, "Error parsing condition at \"" + context + "\", expected \"" + what.tag + "\"");
|
||||
throw boss::error(boss::error::condition_eval_fail, "Error parsing condition at \"" + context + "\", expected \"" + what.tag + "\"");
|
||||
}
|
||||
|
||||
//Checks that the path (not regex) doesn't go outside any game folders.
|
||||
|
||||
Reference in New Issue
Block a user