From d5fc810c7536e34d3ecdcb70ae51cd6be7251346 Mon Sep 17 00:00:00 2001 From: WrinklyNinja Date: Tue, 18 Jun 2013 11:43:35 +0100 Subject: [PATCH] Improved some error messages, fixed sorting bugginess. --- src/backend/game.cpp | 40 +++++++++++++++++++++++----------------- src/backend/metadata.cpp | 6 ++++-- src/gui/main.cpp | 29 +++++++++++++++++++++-------- 3 files changed, 48 insertions(+), 27 deletions(-) diff --git a/src/backend/game.cpp b/src/backend/game.cpp index ad7c9ac7..f48fdfec 100644 --- a/src/backend/game.cpp +++ b/src/backend/game.cpp @@ -232,8 +232,9 @@ namespace boss { ret = lo_create_handle(&gh, LIBLO_GAME_FNV, gamePath.string().c_str()); if (ret != LIBLO_OK) { - const char * err; - lo_get_error_message(&err); + const char * e; + lo_get_error_message(&e); + string err = string("libloadorder failed to create a game handle. Details: ") + err; lo_cleanup(); throw error(ERROR_LIBLO_ERROR, err); } @@ -241,17 +242,19 @@ namespace boss { ret = lo_set_game_master(gh, _masterFile.c_str()); if (ret != LIBLO_OK) { - const char * err; - lo_get_error_message(&err); + const char * e; + lo_get_error_message(&e); lo_destroy_handle(gh); + string err = string("libloadorder total conversion support setup failed. Details: ") + e; lo_cleanup(); - throw error(ERROR_LIBLO_ERROR, "libloadorder total conversion support setup failed."); + throw error(ERROR_LIBLO_ERROR,err); } if (lo_get_active_plugins(gh, &pluginArr, &pluginArrSize) != LIBLO_OK) { - const char * err; - lo_get_error_message(&err); + const char * e; + lo_get_error_message(&e); lo_destroy_handle(gh); + string err = string("libloadorder failed to get the active plugins list. Details: ") + e; lo_cleanup(); throw error(ERROR_LIBLO_ERROR, err); } @@ -283,20 +286,22 @@ namespace boss { ret = lo_create_handle(&gh, LIBLO_GAME_FNV, gamePath.string().c_str()); if (ret != LIBLO_OK) { - const char * err; - lo_get_error_message(&err); + const char * e; + lo_get_error_message(&e); + string err = string("libloadorder game handle creation failed. Details: ") + e; lo_cleanup(); - throw error(ERROR_LIBLO_ERROR, "libloadorder game handle creation failed."); + throw error(ERROR_LIBLO_ERROR, err); } ret = lo_set_game_master(gh, _masterFile.c_str()); if (ret != LIBLO_OK) { - const char * err; - lo_get_error_message(&err); + const char * e; + lo_get_error_message(&e); lo_destroy_handle(gh); + string err = string("libloadorder total conversion support setup failed. Details: ") + e; lo_cleanup(); - throw error(ERROR_LIBLO_ERROR, "libloadorder total conversion support setup failed."); + throw error(ERROR_LIBLO_ERROR, err); } pluginArrSize = loadOrder.size(); @@ -312,11 +317,12 @@ namespace boss { for (size_t i=0; i < pluginArrSize; i++) delete [] pluginArr[i]; delete [] pluginArr; - const char * err; - lo_get_error_message(&err); + const char * e; + lo_get_error_message(&e); lo_destroy_handle(gh); + string err = string("libloadorder failed to set the load order. Details: ") + e; lo_cleanup(); - throw error(ERROR_LIBLO_ERROR, "Setting load order failed."); + throw error(ERROR_LIBLO_ERROR, err); } for (size_t i=0; i < pluginArrSize; i++) @@ -332,7 +338,7 @@ namespace boss { if (!fs::exists(g_path_local / bossFolderName)) fs::create_directory(g_path_local / bossFolderName); } catch (fs::filesystem_error& e) { - throw error(ERROR_PATH_WRITE_FAIL, "Could not create BOSS folder for game."); + throw error(ERROR_PATH_WRITE_FAIL, string("Could not create BOSS folder for game. Details: ") + e.what()); } } } diff --git a/src/backend/metadata.cpp b/src/backend/metadata.cpp index c0e7ed73..906c7570 100644 --- a/src/backend/metadata.cpp +++ b/src/backend/metadata.cpp @@ -547,7 +547,8 @@ namespace boss { } bool Plugin::MustLoadAfter(const Plugin& plugin) const { - if (find(masters.begin(), masters.end(), plugin) != masters.end() + if ((!isMaster && plugin.IsMaster()) + || find(masters.begin(), masters.end(), plugin) != masters.end() || find(requirements.begin(), requirements.end(), plugin) != requirements.end() || find(loadAfter.begin(), loadAfter.end(), plugin) != loadAfter.end()) return true; @@ -680,7 +681,8 @@ namespace boss { if (!lhs.OverlapFormIDs(rhs).empty() && lhs.FormIDs().size() != rhs.FormIDs().size()) return lhs.FormIDs().size() > rhs.FormIDs().size(); - return boost::ilexicographical_compare(lhs.Name(), rhs.Name()); + // return boost::ilexicographical_compare(lhs.Name(), rhs.Name()); + return false; } bool IsPlugin(const std::string& file) { diff --git a/src/gui/main.cpp b/src/gui/main.cpp index ced3199f..82ecfc8e 100644 --- a/src/gui/main.cpp +++ b/src/gui/main.cpp @@ -489,7 +489,7 @@ void Launcher::OnSortPlugins(wxCommandEvent& event) { if (!cyclicDependenciesExist) { out << "Sorting plugins..." << endl; - //std::sort doesn't compare each plugin to every other plugin, it seems to compare plugins until no movement is necessary, because it assumes that each plugin will be comparable on all tested data, which isn't the case when dealing with masters, etc. Therefore, loop through the list and move each plugin's dependencies directly before it, then apply std::sort. + //std::sort doesn't compare each plugin to every other plugin, it seems to compare plugins until no movement is necessary, because it assumes that each plugin will be comparable on all tested data, which isn't the case when dealing with masters, etc. list::iterator it=plugins.begin(); while (it != plugins.end()) { list::iterator jt=it; @@ -499,7 +499,11 @@ void Launcher::OnSortPlugins(wxCommandEvent& event) { list moved; while (jt != plugins.end()) { - if (it->MustLoadAfter(*jt)) { + /* if (it->MustLoadAfter(*jt) + || jt->Priority() < it->Priority()) { + || (!jt->OverlapFormIDs(*it).empty() && jt->FormIDs().size() != it->FormIDs().size() && jt->FormIDs().size() > it->FormIDs().size())) { + */ + if (load_order_sort(*jt, *it)) { moved.push_back(*jt); jt = plugins.erase(jt); } else @@ -515,9 +519,7 @@ void Launcher::OnSortPlugins(wxCommandEvent& event) { progDia->Pulse(); } - - plugins.sort(boss::load_order_sort); - + end = time(NULL); out << "Time taken to sort plugins: " << (end - start) << " seconds." << endl; @@ -584,14 +586,25 @@ void Launcher::OnSortPlugins(wxCommandEvent& event) { uout.close(); //Now set load order. - _game.SetLoadOrder(plugins); + try { + _game.SetLoadOrder(plugins); + } catch (boss::error& e) { + messages.push_back(boss::Message(boss::g_message_error, (format(loc::translate("Failed to set the load order. Details: %1%")) % e.what()).str())); + } } else messages.push_back(boss::Message(boss::g_message_warn, loc::translate("The load order displayed in the Details tab was not applied as sorting was canceled."))); cyclicDependenciesExist = true; out << "Set load order:" << endl; - for (list::iterator it=plugins.begin(), endIt = plugins.end(); it != endIt; ++it) + for (list::iterator it=plugins.begin(), endIt = plugins.end(); it != endIt; ++it) { out << '\t' << it->Name() << endl; + /*vector masters = it->Masters(); + if (!masters.empty()) { + out << "\t" << "Masters:" << endl; + for (size_t i=0, max=masters.size(); i < max; ++i) + out << "\t\t" << masters[i] << endl; + }*/ + } } out << "Generating report..." << endl; @@ -638,7 +651,7 @@ void Launcher::OnSortPlugins(wxCommandEvent& event) { progDia->Pulse(); - out << "Tester finished. Total time taken: " << time(NULL) - t0 << endl; + out << "Sorting finished. Total time taken: " << time(NULL) - t0 << endl; out.close(); //Now a results report definitely exists.