Skip to content

Commit

Permalink
[7.4.0]lo_set_load_order no more adds additional plugins + performance:
Browse files Browse the repository at this point in the history
When client requests a load order to be set we must set this - related
to #6: if the client's definition of invalid (in Bash 'corrupted') plugin
differs from liblo's, liblo will keep adding to the load order what client
will keep removing. Once #6 is closed consider adding the commented out
warn.

Performance monkey patch (_skip parameter) - Load performs all the tests
CheckValidity would reperform for timestamp load orders - ofc real
solution is a cache (#3).
  • Loading branch information
Utumno committed Jun 27, 2015
1 parent 4aa6aa8 commit 63122f7
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 38 deletions.
8 changes: 4 additions & 4 deletions src/api/libloadorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ using namespace liblo;
------------------------------*/

const unsigned int LIBLO_VERSION_MAJOR = 7;
const unsigned int LIBLO_VERSION_MINOR = 3;
const unsigned int LIBLO_VERSION_PATCH = 1;
const unsigned int LIBLO_VERSION_MINOR = 4;
const unsigned int LIBLO_VERSION_PATCH = 0;

/* Returns whether this version of libloadorder is compatible with the given
version of libloadorder. */
Expand Down Expand Up @@ -151,8 +151,8 @@ LIBLO unsigned int lo_create_handle(lo_game_handle * const gh,
}

try {
LoadOrderFileLO.CheckValidity(**gh);
PluginsFileLO.CheckValidity(**gh);
LoadOrderFileLO.CheckValidity(**gh, false);
PluginsFileLO.CheckValidity(**gh, false);
}
catch (error& e) {
return c_error(e);
Expand Down
20 changes: 15 additions & 5 deletions src/api/loadorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ LIBLO unsigned int lo_get_load_order(lo_game_handle gh, char *** const plugins,
if (gh->loadOrder.HasChanged(*gh)) {
gh->loadOrder.Load(*gh);
try {
gh->loadOrder.CheckValidity(*gh); // FIXME: repeats existence/validity/master checks !!!
gh->loadOrder.CheckValidity(*gh, true);
}
catch (error& e) {
successRetCode = c_error(e);
Expand Down Expand Up @@ -118,24 +118,34 @@ LIBLO unsigned int lo_set_load_order(lo_game_handle gh, const char * const * con

//Check to see if basic rules are being obeyed.
try {
gh->loadOrder.CheckValidity(*gh);
gh->loadOrder.CheckValidity(*gh, false);
}
catch (error& e) {
gh->loadOrder.clear();
return c_error(LIBLO_ERROR_INVALID_ARGS, string("Invalid load order supplied. Details: ") + e.what());
}

//Now add any additional plugins to the load order.
gh->loadOrder.LoadAdditionalFiles(*gh);
unsigned int successRetCode = LIBLO_OK;
//unordered_set<Plugin> added = gh->loadOrder.LoadAdditionalFiles(*gh);
//if (!added.empty()) {
// std::stringstream ss;
// std::for_each(
// added.cbegin(),
// added.cend(),
// [&ss](const Plugin c) {ss << c.Name() << " "; }
// );
// successRetCode = c_error(LIBLO_WARN_INVALID_LIST,
// "lo_set_load_order: the list you passed in does not contain the following plugins: " + ss.str());
//}

//Now save changes.
try {
gh->loadOrder.Save(*gh);
return successRetCode;
}
catch (error& e) {
gh->loadOrder.clear();
return c_error(e);
}

return LIBLO_OK;
}
57 changes: 30 additions & 27 deletions src/backend/plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ namespace liblo {
}
}

void LoadOrder::CheckValidity(const _lo_game_handle_int& parentGame) {
void LoadOrder::CheckValidity(const _lo_game_handle_int& parentGame, bool _skip) {
if (empty())
return;

Expand All @@ -357,29 +357,32 @@ namespace liblo {
if (at(0) != masterEsm)
msg += "\"" + masterEsm.Name() + "\" is not the first plugin in the load order. " +
at(0).Name() + " is first.\n";

bool wasMaster = false;
bool wasMasterSet = false;
unordered_set<Plugin> hashset; // check for duplicates
for (const auto plugin : *this) {
if (hashset.find(plugin) != hashset.end()) {
msg += "\"" + plugin.Name() + "\" is in the load order twice.\n";
if (plugin.exists()) wasMaster = plugin.esm();
continue;
} else hashset.insert(plugin);
if (!plugin.Exists(parentGame)){
msg += "\"" + plugin.Name() + "\" is not installed.\n";
continue;
}
// plugin exists
bool isMaster = wasMaster;
try {
isMaster = plugin.IsMasterFile(parentGame);
if (wasMasterSet && isMaster && !wasMaster)
msg += "Master plugin \"" + plugin.Name() + "\" loaded after a non-master plugin.\n";
wasMaster = isMaster; wasMasterSet = true;
} catch (std::exception& e) {
msg += "Plugin \"" + plugin.Name() + "\" is invalid - details: " + e.what() + "\n";
if (parentGame.LoadOrderMethod() != LIBLO_METHOD_TIMESTAMP || !_skip) { // we just loaded, performing all operations below on loading
bool wasMaster = false;
bool wasMasterSet = false;
unordered_set<Plugin> hashset; // check for duplicates
for (const auto plugin : *this) {
if (hashset.find(plugin) != hashset.end()) {
msg += "\"" + plugin.Name() + "\" is in the load order twice.\n";
if (plugin.exists()) wasMaster = plugin.esm();
continue;
}
else hashset.insert(plugin);
if (!plugin.Exists(parentGame)){
msg += "\"" + plugin.Name() + "\" is not installed.\n";
continue;
}
// plugin exists
bool isMaster = wasMaster;
try {
isMaster = plugin.IsMasterFile(parentGame);
if (wasMasterSet && isMaster && !wasMaster)
msg += "Master plugin \"" + plugin.Name() + "\" loaded after a non-master plugin.\n";
wasMaster = isMaster; wasMasterSet = true;
}
catch (std::exception& e) {
msg += "Plugin \"" + plugin.Name() + "\" is invalid - details: " + e.what() + "\n";
}
}
}
if (msg != "") throw error(LIBLO_WARN_INVALID_LIST, msg);
Expand Down Expand Up @@ -499,8 +502,8 @@ namespace liblo {
}
}

bool LoadOrder::LoadAdditionalFiles(const _lo_game_handle_int& parentGame) {
bool added = false;
unordered_set<Plugin> LoadOrder::LoadAdditionalFiles(const _lo_game_handle_int& parentGame) {
unordered_set<Plugin> added;
if (fs::is_directory(parentGame.PluginsFolder())) {
//Now scan through Data folder. Add any plugins that aren't already in loadorder
//to loadorder, at the end. // FIXME: TIMESTAMPS METHOD !WHY AT THE END ?
Expand Down Expand Up @@ -532,7 +535,7 @@ namespace liblo {
this->push_back(plugin);
firstNonMaster = this->begin() + firstNonMasterPos + 1;
}
added = true;
added.insert(plugin);
}
catch (std::exception& /*e*/) {
// LOG ! msg += "Plugin \"" + plugin.Name() + "\" is invalid - details: " + e.what() + "\n";
Expand Down
4 changes: 2 additions & 2 deletions src/backend/plugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace liblo {
void Load(const _lo_game_handle_int& parentGame);
void Save(_lo_game_handle_int& parentGame); //Also updates mtime and active plugins list.

void CheckValidity(const _lo_game_handle_int& parentGame); //Game master first, plugins all exist.
void CheckValidity(const _lo_game_handle_int& parentGame, bool _skip); //Game master first, plugins all exist.

bool HasChanged(const _lo_game_handle_int& parentGame) const; //Checks timestamp and also if LoadOrder is empty.

Expand All @@ -80,7 +80,7 @@ namespace liblo {
std::vector<Plugin>::iterator Find(const Plugin& plugin);
std::vector<Plugin>::iterator FindFirstNonMaster(const _lo_game_handle_int& parentGame);

bool LoadAdditionalFiles(const _lo_game_handle_int& parentGame); // HACK, scan plugins dir and load files not in parentGame.loadOrder
std::unordered_set<Plugin> LoadAdditionalFiles(const _lo_game_handle_int& parentGame); // HACK, scan plugins dir and load files not in parentGame.loadOrder

//Assumes that the content of the file is valid.
void LoadFromFile(const _lo_game_handle_int& parentGame, const boost::filesystem::path& file);
Expand Down

0 comments on commit 63122f7

Please sign in to comment.