diff --git a/src/backend/graph.cpp b/src/backend/graph.cpp index 44982c9e..f1fa385f 100644 --- a/src/backend/graph.cpp +++ b/src/backend/graph.cpp @@ -265,6 +265,7 @@ namespace loot { void AddOverlapEdges(PluginGraph& graph) { loot::vertex_it vit, vitend; + // Add edges between plugins that conflict. for (boost::tie(vit, vitend) = boost::vertices(graph); vit != vitend; ++vit) { BOOST_LOG_TRIVIAL(trace) << "Adding overlap edges to vertex for \"" << graph[*vit].Name() << "\"."; @@ -289,7 +290,7 @@ namespace loot { parentVertex = *vit2; vertex = *vit; } - else if (graph[*vit].Name() < graph[*vit2].Name()) { //There needs to be an edge between the two, but direction cannot be decided using overlap size. Just use names. + else if (boost::locale::to_lower(graph[*vit].Name()) < boost::locale::to_lower(graph[*vit2].Name())) { //There needs to be an edge between the two, but direction cannot be decided using overlap size. Just use names. parentVertex = *vit; vertex = *vit2; } @@ -307,6 +308,35 @@ namespace loot { } } } + + // LOOT for Humans - add edges so that if nothing else, the plugins get sorted alphabetically. Meatbags find that appealing. + for (boost::tie(vit, vitend) = boost::vertices(graph); vit != vitend; ++vit) { + BOOST_LOG_TRIVIAL(trace) << "Adding lexicographical edges to vertex for \"" << graph[*vit].Name() << "\"."; + + loot::vertex_it vit2, vitend2; + for (boost::tie(vit2, vitend2) = boost::vertices(graph); vit2 != vitend2; ++vit2) { + if (vit == vit2 || boost::edge(*vit, *vit2, graph).second || boost::edge(*vit2, *vit, graph).second) + //Vertices are the same or are already linked. + continue; + + vertex_t vertex, parentVertex; + if (boost::locale::to_lower(graph[*vit].Name()) < boost::locale::to_lower(graph[*vit2].Name())) { + parentVertex = *vit; + vertex = *vit2; + } + else { + parentVertex = *vit2; + vertex = *vit; + } + + BOOST_LOG_TRIVIAL(trace) << "Checking edge validity between \"" << graph[*vit].Name() << "\" and \"" << graph[*vit2].Name() << "\"."; + if (!EdgeCreatesCycle(graph, parentVertex, vertex)) { //No edge going the other way, OK to add this edge. + BOOST_LOG_TRIVIAL(trace) << "Adding edge from \"" << graph[parentVertex].Name() << "\" to \"" << graph[vertex].Name() << "\"."; + + boost::add_edge(parentVertex, vertex, graph); + } + } + } } std::list Sort(PluginGraph& graph) { diff --git a/src/tests/api/api.h b/src/tests/api/api.h index 9606df96..29a6b5f8 100644 --- a/src/tests/api/api.h +++ b/src/tests/api/api.h @@ -215,17 +215,17 @@ TEST_F(OblivionAPIOperationsTest, SortPlugins) { // Expected order was obtained from running the API function once. std::list expectedOrder = { + "Blank - Different.esm", + "Blank - Different Master Dependent.esm", "Blank.esm", "Blank - Master Dependent.esm", "Oblivion.esm", - "Blank - Different.esm", - "Blank - Different Master Dependent.esm", + "Blank - Different Master Dependent.esp", + "Blank - Different.esp", + "Blank - Different Plugin Dependent.esp", "Blank - Master Dependent.esp", "Blank.esp", "Blank - Plugin Dependent.esp", - "Blank - Different Master Dependent.esp", - "Blank - Different.esp", - "Blank - Different Plugin Dependent.esp" }; std::list actualOrder; for (size_t i = 0; i < numPlugins; ++i) {