mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Store load order in vectors, not lists
As getting by index is a useful operation for load orders.
This commit is contained in:
@@ -87,7 +87,7 @@ void Game::RedatePlugins() {
|
||||
if (Type() != GameType::tes5)
|
||||
return;
|
||||
|
||||
list<string> loadorder = GetLoadOrder();
|
||||
vector<string> loadorder = GetLoadOrder();
|
||||
if (!loadorder.empty()) {
|
||||
time_t lastTime = 0;
|
||||
for (const auto &pluginName : loadorder) {
|
||||
@@ -216,13 +216,13 @@ short Game::GetActiveLoadOrderIndex(const std::string & pluginName) const {
|
||||
|
||||
return -1;
|
||||
}
|
||||
std::list<std::string> Game::GetLoadOrder() const {
|
||||
std::vector<std::string> Game::GetLoadOrder() const {
|
||||
if (loadOrder_.empty())
|
||||
loadOrder_ = LoadOrderHandler::GetLoadOrder();
|
||||
|
||||
return loadOrder_;
|
||||
}
|
||||
void Game::SetLoadOrder(const std::list<std::string>& loadOrder) const {
|
||||
void Game::SetLoadOrder(const std::vector<std::string>& loadOrder) const {
|
||||
LoadOrderHandler::SetLoadOrder(loadOrder);
|
||||
loadOrder_ = loadOrder;
|
||||
}
|
||||
|
||||
@@ -53,12 +53,12 @@ public:
|
||||
bool IsPluginActive(const std::string& pluginName) const;
|
||||
short GetActiveLoadOrderIndex(const std::string & pluginName) const;
|
||||
|
||||
std::list<std::string> GetLoadOrder() const;
|
||||
void SetLoadOrder(const std::list<std::string>& loadOrder) const;
|
||||
std::vector<std::string> GetLoadOrder() const;
|
||||
void SetLoadOrder(const std::vector<std::string>& loadOrder) const;
|
||||
void SetLoadOrder(const char * const * const loadOrder, const size_t numPlugins) const;
|
||||
private:
|
||||
bool pluginsFullyLoaded_;
|
||||
mutable std::list<std::string> loadOrder_;
|
||||
mutable std::vector<std::string> loadOrder_;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ bool LoadOrderHandler::IsPluginActive(const std::string& pluginName) const {
|
||||
return result;
|
||||
}
|
||||
|
||||
std::list<std::string> LoadOrderHandler::GetLoadOrder() const {
|
||||
std::vector<std::string> LoadOrderHandler::GetLoadOrder() const {
|
||||
BOOST_LOG_TRIVIAL(debug) << "Getting load order.";
|
||||
|
||||
char ** pluginArr;
|
||||
@@ -140,7 +140,7 @@ std::list<std::string> LoadOrderHandler::GetLoadOrder() const {
|
||||
throw Error(Error::Code::liblo_error, err);
|
||||
}
|
||||
|
||||
std::list<string> loadOrder;
|
||||
std::vector<string> loadOrder;
|
||||
for (size_t i = 0; i < pluginArrSize; ++i) {
|
||||
loadOrder.push_back(string(pluginArr[i]));
|
||||
}
|
||||
@@ -167,7 +167,7 @@ void LoadOrderHandler::SetLoadOrder(const char * const * const loadOrder, const
|
||||
}
|
||||
}
|
||||
|
||||
void LoadOrderHandler::SetLoadOrder(const std::list<std::string>& loadOrder) const {
|
||||
void LoadOrderHandler::SetLoadOrder(const std::vector<std::string>& loadOrder) const {
|
||||
BOOST_LOG_TRIVIAL(info) << "Setting load order.";
|
||||
size_t pluginArrSize = loadOrder.size();
|
||||
char ** pluginArr = new char*[pluginArrSize];
|
||||
|
||||
@@ -42,13 +42,13 @@ public:
|
||||
|
||||
void Init(const GameSettings& game, const boost::filesystem::path& gameLocalAppData = "");
|
||||
|
||||
std::list<std::string> GetLoadOrder() const;
|
||||
std::vector<std::string> GetLoadOrder() const;
|
||||
|
||||
bool IsPluginActive(const std::string& pluginName) const;
|
||||
|
||||
//These modify game load order, even though const.
|
||||
void SetLoadOrder(const char * const * const loadOrder, const size_t numPlugins) const; // For API.
|
||||
void SetLoadOrder(const std::list<std::string>& loadOrder) const;
|
||||
void SetLoadOrder(const std::vector<std::string>& loadOrder) const;
|
||||
private:
|
||||
lo_game_handle gh_;
|
||||
};
|
||||
|
||||
@@ -98,8 +98,9 @@ private:
|
||||
vertex_t target;
|
||||
};
|
||||
|
||||
std::list<Plugin> PluginSorter::Sort(Game& game, const Language::Code language) {
|
||||
// Clear existing data.
|
||||
std::vector<Plugin> PluginSorter::Sort(Game& game, const Language::Code language) {
|
||||
using std::vector;
|
||||
// Clear existing data.
|
||||
graph_.clear();
|
||||
indexMap_.clear();
|
||||
oldLoadOrder_.clear();
|
||||
@@ -113,7 +114,7 @@ std::list<Plugin> PluginSorter::Sort(Game& game, const Language::Code language)
|
||||
// If there aren't any vertices, exit early, because sorting assumes
|
||||
// there is at least one plugin.
|
||||
if (boost::num_vertices(graph_) == 0)
|
||||
return list<Plugin>();
|
||||
return vector<Plugin>();
|
||||
|
||||
// Get the existing load order.
|
||||
oldLoadOrder_ = game.GetLoadOrder();
|
||||
@@ -155,7 +156,7 @@ std::list<Plugin> PluginSorter::Sort(Game& game, const Language::Code language)
|
||||
|
||||
// Output a plugin list using the sorted vertices.
|
||||
BOOST_LOG_TRIVIAL(info) << "Calculated order: ";
|
||||
list<Plugin> plugins;
|
||||
vector<Plugin> plugins;
|
||||
for (const auto &vertex : sortedVertices) {
|
||||
BOOST_LOG_TRIVIAL(info) << '\t' << graph_[vertex].Name();
|
||||
plugins.push_back(graph_[vertex]);
|
||||
|
||||
@@ -40,7 +40,7 @@ typedef boost::associative_property_map<std::map<vertex_t, size_t>> vertex_map_t
|
||||
|
||||
class PluginSorter {
|
||||
public:
|
||||
std::list<Plugin> Sort(Game& game, const Language::Code language);
|
||||
std::vector<Plugin> Sort(Game& game, const Language::Code language);
|
||||
private:
|
||||
bool GetVertexByName(const std::string& name, vertex_t& vertex) const;
|
||||
void CheckForCycles() const;
|
||||
@@ -61,7 +61,7 @@ private:
|
||||
PluginGraph graph_;
|
||||
std::map<vertex_t, size_t> indexMap_;
|
||||
vertex_map_t vertexIndexMap_;
|
||||
std::list<std::string> oldLoadOrder_;
|
||||
std::vector<std::string> oldLoadOrder_;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -270,7 +270,7 @@ bool QueryHandler::HandleComplexQuery(CefRefPtr<CefBrowser> browser,
|
||||
lootState_.decrementUnappliedChangeCounter();
|
||||
BOOST_LOG_TRIVIAL(trace) << "User has accepted sorted load order, applying it.";
|
||||
try {
|
||||
lootState_.getCurrentGame().SetLoadOrder(request["args"][0].as<list<string>>());
|
||||
lootState_.getCurrentGame().SetLoadOrder(request["args"][0].as<vector<string>>());
|
||||
callback->Success("");
|
||||
} catch (Error &e) {
|
||||
BOOST_LOG_TRIVIAL(error) << e.what();
|
||||
@@ -582,7 +582,7 @@ void QueryHandler::GetGameData(CefRefPtr<CefFrame> frame, CefRefPtr<Callback> ca
|
||||
|
||||
//Sort plugins into their load order.
|
||||
list<Plugin> installed;
|
||||
list<string> loadOrder = lootState_.getCurrentGame().GetLoadOrder();
|
||||
vector<string> loadOrder = lootState_.getCurrentGame().GetLoadOrder();
|
||||
for (const auto &pluginName : loadOrder) {
|
||||
try {
|
||||
const auto plugin = lootState_.getCurrentGame().GetPlugin(pluginName);
|
||||
@@ -851,7 +851,7 @@ void QueryHandler::SortPlugins(CefRefPtr<CefFrame> frame, CefRefPtr<Callback> ca
|
||||
//Sort plugins into their load order.
|
||||
SendProgressUpdate(frame, translate("Sorting load order..."));
|
||||
PluginSorter sorter;
|
||||
list<Plugin> plugins = sorter.Sort(lootState_.getCurrentGame(), lootState_.getLanguage().GetCode());
|
||||
vector<Plugin> plugins = sorter.Sort(lootState_.getCurrentGame(), lootState_.getLanguage().GetCode());
|
||||
|
||||
// If TESV or FO4, check if load order has been changed.
|
||||
if ((lootState_.getCurrentGame().Type() == GameType::tes5 || lootState_.getCurrentGame().Type() == GameType::fo4)
|
||||
@@ -860,7 +860,7 @@ void QueryHandler::SortPlugins(CefRefPtr<CefFrame> frame, CefRefPtr<Callback> ca
|
||||
// user input because there are no changes to accept and some
|
||||
// plugins' positions may only be inferred and not written to
|
||||
// loadorder.txt/plugins.txt.
|
||||
std::list<std::string> newLoadOrder;
|
||||
std::vector<std::string> newLoadOrder;
|
||||
std::transform(begin(plugins),
|
||||
end(plugins),
|
||||
back_inserter(newLoadOrder),
|
||||
|
||||
@@ -110,7 +110,7 @@ TEST_P(LoadOrderHandlerTest, getLoadOrderShouldReturnTheCurrentLoadOrder) {
|
||||
}
|
||||
|
||||
TEST_P(LoadOrderHandlerTest, setLoadOrderShouldThrowIfTheHandlerHasNotBeenInitialised) {
|
||||
std::list<std::string> loadOrder({
|
||||
std::vector<std::string> loadOrder({
|
||||
masterFile,
|
||||
blankEsm,
|
||||
blankMasterDependentEsm,
|
||||
@@ -124,7 +124,7 @@ TEST_P(LoadOrderHandlerTest, setLoadOrderShouldThrowIfTheHandlerHasNotBeenInitia
|
||||
blankPluginDependentEsp,
|
||||
});
|
||||
|
||||
EXPECT_THROW(loadOrderHandler_.SetLoadOrder(std::list<std::string>()), Error);
|
||||
EXPECT_THROW(loadOrderHandler_.SetLoadOrder(loadOrder), Error);
|
||||
}
|
||||
|
||||
TEST_P(LoadOrderHandlerTest, setLoadOrderShouldSetTheLoadOrder) {
|
||||
@@ -132,7 +132,7 @@ TEST_P(LoadOrderHandlerTest, setLoadOrderShouldSetTheLoadOrder) {
|
||||
game.SetGamePath(dataPath.parent_path());
|
||||
ASSERT_NO_THROW(loadOrderHandler_.Init(game, localPath));
|
||||
|
||||
std::list<std::string> loadOrder({
|
||||
std::vector<std::string> loadOrder({
|
||||
masterFile,
|
||||
blankEsm,
|
||||
blankMasterDependentEsm,
|
||||
|
||||
@@ -53,7 +53,7 @@ INSTANTIATE_TEST_CASE_P(,
|
||||
|
||||
TEST_P(PluginSorterTest, sortingWithNoLoadedPluginsShouldReturnAnEmptyList) {
|
||||
PluginSorter sorter;
|
||||
std::list<Plugin> sorted = sorter.Sort(game_, Language::Code::english);
|
||||
std::vector<Plugin> sorted = sorter.Sort(game_, Language::Code::english);
|
||||
|
||||
EXPECT_TRUE(sorted.empty());
|
||||
}
|
||||
@@ -62,9 +62,9 @@ TEST_P(PluginSorterTest, sortingShouldNotMakeUnnecessaryChangesToAnExistingLoadO
|
||||
ASSERT_NO_THROW(game_.LoadPlugins(false));
|
||||
|
||||
PluginSorter ps;
|
||||
std::list<std::string> expectedSortedOrder = getLoadOrder();
|
||||
std::vector<std::string> expectedSortedOrder = getLoadOrder();
|
||||
|
||||
std::list<Plugin> sorted = ps.Sort(game_, Language::Code::english);
|
||||
std::vector<Plugin> sorted = ps.Sort(game_, Language::Code::english);
|
||||
EXPECT_TRUE(std::equal(begin(sorted), end(sorted), begin(expectedSortedOrder)));
|
||||
|
||||
// Check stability.
|
||||
@@ -78,7 +78,7 @@ TEST_P(PluginSorterTest, sortingShouldClearExistingGameMessages) {
|
||||
ASSERT_FALSE(game_.GetMessages().empty());
|
||||
|
||||
PluginSorter ps;
|
||||
std::list<Plugin> sorted = ps.Sort(game_, Language::Code::english);
|
||||
std::vector<Plugin> sorted = ps.Sort(game_, Language::Code::english);
|
||||
EXPECT_TRUE(game_.GetMessages().empty());
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ TEST_P(PluginSorterTest, sortingShouldEvaluateRelativeGlobalPriorities) {
|
||||
game_.GetUserlist().AddPlugin(plugin);
|
||||
|
||||
PluginSorter ps;
|
||||
std::list<std::string> expectedSortedOrder({
|
||||
std::vector<std::string> expectedSortedOrder({
|
||||
masterFile,
|
||||
blankEsm,
|
||||
blankDifferentEsm,
|
||||
@@ -116,7 +116,7 @@ TEST_P(PluginSorterTest, sortingShouldEvaluateRelativeGlobalPriorities) {
|
||||
blankDifferentPluginDependentEsp,
|
||||
});
|
||||
|
||||
std::list<Plugin> sorted = ps.Sort(game_, Language::Code::english);
|
||||
std::vector<Plugin> sorted = ps.Sort(game_, Language::Code::english);
|
||||
EXPECT_TRUE(std::equal(begin(sorted), end(sorted), begin(expectedSortedOrder)));
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ TEST_P(PluginSorterTest, sortingWithGlobalPrioritiesShouldInheritRecursivelyRega
|
||||
game_.GetUserlist().AddPlugin(plugin);
|
||||
|
||||
PluginSorter ps;
|
||||
std::list<std::string> expectedSortedOrder({
|
||||
std::vector<std::string> expectedSortedOrder({
|
||||
masterFile,
|
||||
blankEsm,
|
||||
blankDifferentEsm,
|
||||
@@ -166,7 +166,7 @@ TEST_P(PluginSorterTest, sortingWithGlobalPrioritiesShouldInheritRecursivelyRega
|
||||
blankDifferentPluginDependentEsp,
|
||||
});
|
||||
|
||||
std::list<Plugin> sorted = ps.Sort(game_, Language::Code::english);
|
||||
std::vector<Plugin> sorted = ps.Sort(game_, Language::Code::english);
|
||||
EXPECT_TRUE(std::equal(begin(sorted), end(sorted), begin(expectedSortedOrder)));
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ TEST_P(PluginSorterTest, sortingShouldUseLoadAfterMetadataWhenDecidingRelativePl
|
||||
game_.GetUserlist().AddPlugin(plugin);
|
||||
|
||||
PluginSorter ps;
|
||||
std::list<std::string> expectedSortedOrder({
|
||||
std::vector<std::string> expectedSortedOrder({
|
||||
masterFile,
|
||||
blankEsm,
|
||||
blankDifferentEsm,
|
||||
@@ -194,7 +194,7 @@ TEST_P(PluginSorterTest, sortingShouldUseLoadAfterMetadataWhenDecidingRelativePl
|
||||
blankPluginDependentEsp,
|
||||
});
|
||||
|
||||
std::list<Plugin> sorted = ps.Sort(game_, Language::Code::english);
|
||||
std::vector<Plugin> sorted = ps.Sort(game_, Language::Code::english);
|
||||
EXPECT_TRUE(std::equal(begin(sorted), end(sorted), begin(expectedSortedOrder)));
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ TEST_P(PluginSorterTest, sortingShouldUseRequirementMetadataWhenDecidingRelative
|
||||
game_.GetUserlist().AddPlugin(plugin);
|
||||
|
||||
PluginSorter ps;
|
||||
std::list<std::string> expectedSortedOrder({
|
||||
std::vector<std::string> expectedSortedOrder({
|
||||
masterFile,
|
||||
blankEsm,
|
||||
blankDifferentEsm,
|
||||
@@ -222,7 +222,7 @@ TEST_P(PluginSorterTest, sortingShouldUseRequirementMetadataWhenDecidingRelative
|
||||
blankPluginDependentEsp,
|
||||
});
|
||||
|
||||
std::list<Plugin> sorted = ps.Sort(game_, Language::Code::english);
|
||||
std::vector<Plugin> sorted = ps.Sort(game_, Language::Code::english);
|
||||
EXPECT_TRUE(std::equal(begin(sorted), end(sorted), begin(expectedSortedOrder)));
|
||||
}
|
||||
|
||||
|
||||
@@ -99,8 +99,8 @@ protected:
|
||||
ASSERT_FALSE(boost::filesystem::exists(dataPath / (blankMasterDependentEsm + ".ghost")));
|
||||
}
|
||||
|
||||
std::list<std::string> getLoadOrder() {
|
||||
std::list<std::string> actual;
|
||||
std::vector<std::string> getLoadOrder() {
|
||||
std::vector<std::string> actual;
|
||||
if (isLoadOrderTimestampBased(gameType)) {
|
||||
std::map<time_t, std::string> loadOrder;
|
||||
for (boost::filesystem::directory_iterator it(dataPath); it != boost::filesystem::directory_iterator(); ++it) {
|
||||
|
||||
Reference in New Issue
Block a user