From c628fa98d8ccbabf891017496f880cd97e764e6a Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Fri, 25 Jan 2019 19:04:05 +0000 Subject: [PATCH] Remove log statements that don't add much --- src/api/game/game.cpp | 15 ++--- src/api/game/load_order_handler.cpp | 10 +-- src/api/metadata/plugin_cleaning_data.cpp | 4 -- src/api/metadata/plugin_metadata.cpp | 10 --- src/api/plugin.cpp | 81 +++++++++-------------- src/api/plugin.h | 2 +- 6 files changed, 40 insertions(+), 82 deletions(-) diff --git a/src/api/game/game.cpp b/src/api/game/game.cpp index 3cbb2095..1f70e5c3 100644 --- a/src/api/game/game.cpp +++ b/src/api/game/game.cpp @@ -141,11 +141,6 @@ void Game::LoadPlugins(const std::vector& plugins, currentGroup = 0; } - if (logger) { - logger->trace( - "Adding plugin {} to loading group {}", plugin.second, currentGroup); - } - pluginGroups[currentGroup].push_back(plugin.second); ++currentGroup; } @@ -167,13 +162,11 @@ void Game::LoadPlugins(const std::vector& plugins, vector& pluginGroup = pluginGroups[threads.size()]; threads.push_back(thread([&]() { for (auto pluginName : pluginGroup) { - if (logger) { - logger->trace("Loading {}", pluginName); - } - auto pluginPath = DataPath() / u8path(pluginName); - const bool loadHeader = - loadHeadersOnly || loot::equivalent(pluginPath, masterPath); try { + auto pluginPath = DataPath() / u8path(pluginName); + const bool loadHeader = + loadHeadersOnly || loot::equivalent(pluginPath, masterPath); + cache_->AddPlugin(Plugin( Type(), cache_, pluginPath, loadHeader)); } catch (std::exception& e) { diff --git a/src/api/game/load_order_handler.cpp b/src/api/game/load_order_handler.cpp index cf64efd8..6354533c 100644 --- a/src/api/game/load_order_handler.cpp +++ b/src/api/game/load_order_handler.cpp @@ -84,7 +84,7 @@ void LoadOrderHandler::Init(const GameType& gameType, void LoadOrderHandler::LoadCurrentState() { auto logger = getLogger(); if (logger) { - logger->debug("Loading the current load order state."); + logger->info("Loading the current load order state."); } unsigned int ret = lo_load_current_state(gh_); @@ -95,7 +95,7 @@ void LoadOrderHandler::LoadCurrentState() { bool LoadOrderHandler::IsPluginActive(const std::string& pluginName) const { auto logger = getLogger(); if (logger) { - logger->debug("Checking if plugin \"{}\" is active.", pluginName); + logger->trace("Checking if plugin \"{}\" is active.", pluginName); } bool result = false; @@ -109,7 +109,7 @@ bool LoadOrderHandler::IsPluginActive(const std::string& pluginName) const { std::vector LoadOrderHandler::GetLoadOrder() const { auto logger = getLogger(); if (logger) { - logger->debug("Getting load order."); + logger->trace("Getting load order."); } char** pluginArr; @@ -128,7 +128,7 @@ std::vector LoadOrderHandler::GetLoadOrder() const { std::vector LoadOrderHandler::GetActivePlugins() const { auto logger = getLogger(); if (logger) { - logger->debug("Getting active plugins."); + logger->trace("Getting active plugins."); } char** pluginArr; @@ -148,7 +148,7 @@ std::vector LoadOrderHandler::GetActivePlugins() const { std::vector LoadOrderHandler::GetImplicitlyActivePlugins() const { auto logger = getLogger(); if (logger) { - logger->debug("Getting implicitly active plugins."); + logger->trace("Getting implicitly active plugins."); } char** pluginArr; diff --git a/src/api/metadata/plugin_cleaning_data.cpp b/src/api/metadata/plugin_cleaning_data.cpp index 0055153e..cad06bf8 100644 --- a/src/api/metadata/plugin_cleaning_data.cpp +++ b/src/api/metadata/plugin_cleaning_data.cpp @@ -78,10 +78,6 @@ std::vector PluginCleaningData::GetInfo() const { MessageContent PluginCleaningData::ChooseInfo( const std::string& language) const { - auto logger = getLogger(); - if (logger) { - logger->trace("Choosing dirty info content."); - } return MessageContent::Choose(info_, language); } } diff --git a/src/api/metadata/plugin_metadata.cpp b/src/api/metadata/plugin_metadata.cpp index 4b6a0c26..f29aa379 100644 --- a/src/api/metadata/plugin_metadata.cpp +++ b/src/api/metadata/plugin_metadata.cpp @@ -52,11 +52,6 @@ PluginMetadata::PluginMetadata(const std::string& n) : } void PluginMetadata::MergeMetadata(const PluginMetadata& plugin) { - auto logger = getLogger(); - if (logger) { - logger->trace("Merging metadata for: {}", name_); - } - if (plugin.HasNameOnly()) return; @@ -96,11 +91,6 @@ void PluginMetadata::MergeMetadata(const PluginMetadata& plugin) { PluginMetadata PluginMetadata::NewMetadata(const PluginMetadata& plugin) const { using std::set_difference; - auto logger = getLogger(); - if (logger) { - logger->trace("Comparing new metadata for: {}", name_); - } - PluginMetadata p(*this); if (p.group_ == plugin.group_) { diff --git a/src/api/plugin.cpp b/src/api/plugin.cpp index e22261b8..0bd9b5df 100644 --- a/src/api/plugin.cpp +++ b/src/api/plugin.cpp @@ -60,35 +60,20 @@ Plugin::Plugin(const GameType gameType, auto ret = esp_plugin_is_empty(esPlugin.get(), &isEmpty_); if (ret != ESP_OK) { - throw FileAccessError(name_ + - " : esplugin error code: " + std::to_string(ret)); + throw FileAccessError("Error checking if \"" + name_ + "\" is empty. esplugin error code: " + std::to_string(ret)); } if (!headerOnly) { - if (logger) { - logger->trace("{}: Caching CRC value.", name_); - } crc_ = GetCrc32(pluginPath); - if (logger) { - logger->trace("{}: Counting override FormIDs.", name_); - } ret = esp_plugin_count_override_records(esPlugin.get(), &numOverrideRecords_); if (ret != ESP_OK) { - throw FileAccessError(name_ + - " : esplugin error code: " + std::to_string(ret)); + throw FileAccessError("Error counting override records in \"" + name_ + "\". esplugin error code: " + std::to_string(ret)); } } - // Also read Bash Tags applied and version string in description. - if (logger) { - logger->trace("{}: Attempting to extract Bash Tags from the description.", - name_); - } - tags_ = ExtractBashTags(GetDescription()); - loadsArchive_ = LoadsArchive(gameType, gameCache, pluginPath); } catch (std::exception& e) { if (logger) { @@ -97,10 +82,6 @@ Plugin::Plugin(const GameType gameType, } throw FileAccessError("Cannot read \"" + name_ + "\". Details: " + e.what()); } - - if (logger) { - logger->trace("{}: Plugin loading complete.", name_); - } } std::string Plugin::GetName() const { return name_; } @@ -206,41 +187,35 @@ size_t Plugin::NumOverrideFormIDs() const { return numOverrideRecords_; } bool Plugin::IsValid(const GameType gameType, const std::filesystem::path& pluginPath) { - auto logger = getLogger(); - if (logger) { - logger->trace("Checking to see if \"{}\" is a valid plugin.", pluginPath.filename().u8string()); - } - - // If the filename passed ends in '.ghost', that should be trimmed. - std::string trimmedFilename = pluginPath.filename().u8string(); - if (boost::iends_with(trimmedFilename, ".ghost")) { - trimmedFilename = trimmedFilename.substr(0, trimmedFilename.length() - 6); - } - // Check that the file has a valid extension. - if (!hasPluginFileExtension(trimmedFilename, gameType)) - return false; + if (hasPluginFileExtension(pluginPath.filename().u8string(), gameType)) { + bool isValid; + int returnCode = esp_plugin_is_valid(GetEspluginGameId(gameType), + pluginPath.u8string().c_str(), + true, + &isValid); - bool isValid; - int ret = esp_plugin_is_valid( - GetEspluginGameId(gameType), pluginPath.u8string().c_str(), true, &isValid); + if (returnCode != ESP_OK || !isValid) { + // Try adding .ghost extension. + auto ghostedFilename = pluginPath.u8string() + ".ghost"; + returnCode = esp_plugin_is_valid(GetEspluginGameId(gameType), + ghostedFilename.c_str(), + true, + &isValid); + } - if (ret != ESP_OK || !isValid) { - // Try adding .ghost extension. - auto ghostedPath = pluginPath; - ghostedPath += ".ghost"; - - ret = esp_plugin_is_valid( - GetEspluginGameId(gameType), ghostedPath.u8string().c_str(), true, &isValid); - } - - if (ret != ESP_OK || !isValid) { - if (logger) { - logger->warn("The file \"{}\" is not a valid plugin.", pluginPath.filename().u8string()); + if (returnCode == ESP_OK && isValid) { + return true; } } - return ret == ESP_OK && isValid; + auto logger = getLogger(); + if (logger) { + logger->info("The file \"{}\" is not a valid plugin.", + pluginPath.filename().u8string()); + } + + return false; } uintmax_t Plugin::GetFileSize(std::filesystem::path pluginPath) { @@ -380,7 +355,11 @@ unsigned int Plugin::GetEspluginGameId(GameType gameType) { } } -bool hasPluginFileExtension(const std::string& filename, GameType gameType) { +bool hasPluginFileExtension(std::string filename, GameType gameType) { + if (boost::iends_with(filename, ".ghost")) { + filename = filename.substr(0, filename.length() - 6); + } + bool espOrEsm = boost::iends_with(filename, ".esp") || boost::iends_with(filename, ".esm"); bool lightMaster = diff --git a/src/api/plugin.h b/src/api/plugin.h index 66ec55fc..2dfe9137 100644 --- a/src/api/plugin.h +++ b/src/api/plugin.h @@ -99,7 +99,7 @@ private: std::string GetArchiveFileExtension(const GameType gameType); -bool hasPluginFileExtension(const std::string& filename, GameType gameType); +bool hasPluginFileExtension(std::string filename, GameType gameType); bool equivalent(const std::filesystem::path& path1, const std::filesystem::path& path2);