Skip to content

Commit

Permalink
[7.1.0]Return active plugins in plugins.txt order HACK:
Browse files Browse the repository at this point in the history
Under #4.
Under #5 - notice we need a valid LO passed in for TESV.
ActivePlugins should be a vector but I can't go into this now - wait till
the code is clean.
Note that I also inversed the order of the if for usual case to come first.
This should be a method of game (readPluginsTxt) - see #9.
  • Loading branch information
Utumno committed Jun 27, 2015
1 parent b2a5c5d commit c34973d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 23 deletions.
5 changes: 3 additions & 2 deletions src/api/activeplugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ LIBLO unsigned int lo_get_active_plugins(lo_game_handle gh, char *** const plugi
return LIBLO_OK;

//Allocate memory.
gh->extStringArraySize = gh->activePlugins.size();
gh->extStringArraySize = gh->activePlugins.Ordered().size();
try {
gh->extStringArray = new char*[gh->extStringArraySize];
size_t i = 0;
for (const auto &activePlugin : gh->activePlugins) {
for (const auto &activePlugin : gh->activePlugins.Ordered()) {
gh->extStringArray[i] = ToNewCString(activePlugin.Name());
i++;
}
Expand Down Expand Up @@ -112,6 +112,7 @@ LIBLO unsigned int lo_set_active_plugins(lo_game_handle gh, const char * const *
return c_error(e);
}
gh->activePlugins.insert(plugin);
gh->activePlugins.Ordered().push_back(plugin);
}
}

Expand Down
4 changes: 2 additions & 2 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 = 0;
const unsigned int LIBLO_VERSION_PATCH = 1;
const unsigned int LIBLO_VERSION_MINOR = 1;
const unsigned int LIBLO_VERSION_PATCH = 0;

/* Returns whether this version of libloadorder is compatible with the given
version of libloadorder. */
Expand Down
50 changes: 31 additions & 19 deletions src/backend/plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,30 +483,30 @@ namespace liblo {

void ActivePlugins::Load(const _lo_game_handle_int& parentGame) {
clear();

if (fs::exists(parentGame.ActivePluginsFile())) {
string line;
try {
liblo::ifstream in(parentGame.ActivePluginsFile());
in.exceptions(std::ios_base::badbit);

if (parentGame.Id() == LIBLO_GAME_TES3) { //Morrowind's active file list is stored in Morrowind.ini, and that has a different format from plugins.txt.
regex reg = regex("GameFile[0-9]{1,3}=.+\\.es(m|p)", regex::ECMAScript | regex::icase);
if (!(parentGame.Id() == LIBLO_GAME_TES3)) {
while (getline(in, line)) {
if (line.empty() || !regex_match(line, reg))
// Check if it's a valid plugin line. The stream doesn't filter out '\r' line endings, hence the check.
if (line.empty() || line[0] == '#' || line[0] == '\r')
continue;

//Now cut off everything up to and including the = sign.
insert(Plugin(ToUTF8(line.substr(line.find('=') + 1))));
Plugin plug = Plugin(ToUTF8(line));
activeOrdered.push_back(plug);
insert(plug);
}
}
else {
} else { //Morrowind's active file list is stored in Morrowind.ini, and that has a different format from plugins.txt.
regex reg = regex("GameFile[0-9]{1,3}=.+\\.es(m|p)", regex::ECMAScript | regex::icase);
while (getline(in, line)) {
// Check if it's a valid plugin line. The stream doesn't filter out '\r' line endings, hence the check.
if (line.empty() || line[0] == '#' || line[0] == '\r')
if (line.empty() || !regex_match(line, reg))
continue;

insert(Plugin(ToUTF8(line)));
//Now cut off everything up to and including the = sign.
Plugin plug = Plugin(ToUTF8(line.substr(line.find('=') + 1)));
activeOrdered.push_back(plug);
insert(plug);
}
}
in.close();
Expand All @@ -515,13 +515,22 @@ namespace liblo {
throw error(LIBLO_ERROR_FILE_READ_FAIL, "\"" + parentGame.ActivePluginsFile().string() + "\" could not be read. Details: " + e.what());
}
}

//Add skyrim.esm, update.esm if missing.
// Add skyrim.esm, update.esm if missing. Note that we do not check if loaded list is valid,
// nevertheless we do stive to keep the list valid if originally was - TODO: check at this point
// and rewrite plugins txt - this requires passing a valid load order in - liblo 8
if (parentGame.Id() == LIBLO_GAME_TES5) {
if (find(Plugin(parentGame.MasterFile())) == end())
insert(Plugin(parentGame.MasterFile()));
if (Plugin("Update.esm").Exists(parentGame) && find(Plugin("Update.esm")) == end())
insert(Plugin("Update.esm"));
Plugin plug = Plugin(parentGame.MasterFile());
if (find(plug) == end()){
insert(plug);
activeOrdered.insert(activeOrdered.begin(), plug); // insert first
}
plug = Plugin("Update.esm");
if (plug.Exists(parentGame) && find(plug) == end()) { // FIXME: must resave plugins.txt
insert(plug);
auto firstEsp = find_if(activeOrdered.begin(), activeOrdered.end(),
[&parentGame](const Plugin& plugin) { return !plugin.IsMasterFile(parentGame); });
activeOrdered.insert(firstEsp, plug); // insert at last esm position
}
}
}

Expand Down Expand Up @@ -625,4 +634,7 @@ namespace liblo {
throw error(LIBLO_ERROR_TIMESTAMP_READ_FAIL, e.what());
}
}

std::vector<Plugin> &ActivePlugins::Ordered() { return activeOrdered; }
void ActivePlugins::clear() { std::unordered_set<Plugin>::clear(); activeOrdered.clear(); }
}
4 changes: 4 additions & 0 deletions src/backend/plugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,12 @@ namespace liblo {
void CheckValidity(const _lo_game_handle_int& parentGame) const; //not more than 255 plugins active (254 for Skyrim), plugins all exist.

bool HasChanged(const _lo_game_handle_int& parentGame) const;

std::vector<Plugin> &Ordered();
void clear();
private:
time_t mtime;
std::vector<Plugin> activeOrdered;
};
}

Expand Down

0 comments on commit c34973d

Please sign in to comment.