Implemented loot_apply_load_order.

Also improved constness of parameters.
This commit is contained in:
Oliver Hamlet
2014-09-26 17:09:21 +01:00
parent 4908f4d280
commit 840241c9f3
4 changed files with 52 additions and 24 deletions
+22 -3
View File
@@ -365,13 +365,26 @@ LOOT_API unsigned int loot_eval_lists(loot_db db, const unsigned int language) {
LOOT_API unsigned int loot_sort_plugins(loot_db db,
char *** const sortedPlugins,
size_t * numPlugins) {
size_t * const numPlugins) {
if (db == nullptr || sortedPlugins == nullptr || numPlugins == nullptr)
return c_error(loot_error_invalid_args, "Null pointer passed.");
return loot_ok;
}
LOOT_API unsigned int loot_apply_load_order(loot_db db,
const char ** const loadOrder,
size_t numPlugins) {
const char * const * const loadOrder,
const size_t numPlugins) {
if (db == nullptr || loadOrder == nullptr)
return c_error(loot_error_invalid_args, "Null pointer passed.");
try {
db->SetLoadOrder(loadOrder, numPlugins);
}
catch (loot::error &e) {
return c_error(e);
}
return loot_ok;
}
@@ -380,6 +393,9 @@ LOOT_API unsigned int loot_update_masterlist(loot_db db,
const char * const remoteURL,
const char * const remoteBranch,
bool * const updated) {
if (db == nullptr || masterlistPath == nullptr || remoteURL == nullptr || remoteBranch == nullptr || updated == nullptr)
return c_error(loot_error_invalid_args, "Null pointer passed.");
return loot_ok;
}
@@ -388,6 +404,9 @@ LOOT_API unsigned int loot_get_masterlist_revision(const char * const masterlist
char ** const revisionID,
char ** const revisionDate,
bool * const isModified) {
if (masterlistPath == nullptr || revisionID == nullptr || revisionDate == nullptr || isModified == nullptr)
return c_error(loot_error_invalid_args, "Null pointer passed.");
return loot_ok;
}
+3 -3
View File
@@ -404,7 +404,7 @@ extern "C"
*/
LOOT_API unsigned int loot_sort_plugins(loot_db db,
char *** const sortedPlugins,
size_t * numPlugins);
size_t * const numPlugins);
/**
* @brief Applies the given load order.
@@ -417,8 +417,8 @@ extern "C"
* @returns A return code.
*/
LOOT_API unsigned int loot_apply_load_order(loot_db db,
const char ** const loadOrder,
size_t numPlugins);
const char * const * const loadOrder,
const size_t numPlugins);
/**
* @brief Update the given masterlist.
+26 -18
View File
@@ -620,12 +620,10 @@ namespace loot {
lo_destroy_handle(gh);
}
void Game::SetLoadOrder(const std::list<std::string>& loadOrder) const {
void Game::SetLoadOrder(const char * const * const loadOrder, const size_t numPlugins) const {
BOOST_LOG_TRIVIAL(debug) << "Setting load order for game: " << _name;
lo_game_handle gh = nullptr;
char ** pluginArr = nullptr;
size_t pluginArrSize = 0;
int ret;
if (Id() == Game::tes4)
ret = lo_create_handle(&gh, LIBLO_GAME_TES4, gamePath.string().c_str());
@@ -670,19 +668,7 @@ namespace loot {
throw error(error::liblo_error, err);
}
pluginArrSize = loadOrder.size();
pluginArr = new char*[pluginArrSize];
int i = 0;
for (const auto &plugin : loadOrder) {
pluginArr[i] = new char[plugin.length() + 1];
strcpy(pluginArr[i], plugin.c_str());
++i;
}
if (lo_set_load_order(gh, pluginArr, pluginArrSize) != LIBLO_OK) {
for (size_t i = 0; i < pluginArrSize; i++)
delete[] pluginArr[i];
delete[] pluginArr;
if (lo_set_load_order(gh, loadOrder, numPlugins) != LIBLO_OK) {
const char * e = nullptr;
string err;
lo_get_error_message(&e);
@@ -699,11 +685,33 @@ namespace loot {
throw error(error::liblo_error, err);
}
lo_destroy_handle(gh);
}
void Game::SetLoadOrder(const std::list<std::string>& loadOrder) const {
size_t pluginArrSize = loadOrder.size();
char ** pluginArr = new char*[pluginArrSize];
int i = 0;
for (const auto &plugin : loadOrder) {
pluginArr[i] = new char[plugin.length() + 1];
strcpy(pluginArr[i], plugin.c_str());
++i;
}
try {
SetLoadOrder(pluginArr, pluginArrSize);
}
catch (error &e) {
for (size_t i = 0; i < pluginArrSize; i++)
delete[] pluginArr[i];
delete[] pluginArr;
throw e;
}
for (size_t i = 0; i < pluginArrSize; i++)
delete[] pluginArr[i];
delete[] pluginArr;
lo_destroy_handle(gh);
}
void Game::RedatePlugins() {
+1
View File
@@ -131,6 +131,7 @@ namespace loot {
void GetLoadOrder(std::list<std::string>& loadOrder) const;
void SetLoadOrder(const std::list<std::string>& loadOrder) const; //Modifies game load order, even though const.
void SetLoadOrder(const char * const * const loadOrder, const size_t numPlugins) const; // For API.
void RefreshActivePluginsList();
void RedatePlugins(); //Change timestamps to match load order (Skyrim only).