Skip to content

Commit

Permalink
Remove unused plugin-specific PDB config code (ServersHub#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
MolluskARK authored Nov 29, 2023
1 parent 97f1657 commit f4c07e2
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 130 deletions.
66 changes: 0 additions & 66 deletions AsaApi/Core/Private/Helpers.cpp
Original file line number Diff line number Diff line change
@@ -1,73 +1,7 @@
#include "Helpers.h"

#include <algorithm>
#include <cctype>
#include <locale>

namespace API
{
void MergePdbConfig(nlohmann::json& left, const nlohmann::json& right)
{
nlohmann::json pdb_config_result({});

pdb_config_result["structures"] = MergeStringArrays(left.value("structures", std::vector<std::string>{}),
right.value("structures", std::vector<std::string>{}));
pdb_config_result["functions"] = MergeStringArrays(left.value("functions", std::vector<std::string>{}),
right.value("functions", std::vector<std::string>{}));
pdb_config_result["globals"] = MergeStringArrays(left.value("globals", std::vector<std::string>{}),
right.value("globals", std::vector<std::string>{}));

left = pdb_config_result;
}

std::vector<std::string> MergeStringArrays(std::vector<std::string> first, std::vector<std::string> second)
{
std::vector<std::string> merged, unique;
std::sort(first.begin(), first.end());
std::sort(second.begin(), second.end());
std::set_union(
first.begin(),
first.end(),
second.begin(),
second.end(),
std::back_inserter(merged),
[](std::string s1, std::string s2)
{
return std::lexicographical_compare(
s1.begin(),
s1.end(),
s2.begin(),
s2.end(),
[](char c1, char c2)
{
return std::tolower(c1) < std::tolower(c2);
}
);
}
);

std::unique_copy(
merged.begin(),
merged.end(),
std::back_inserter(unique),
[](std::string s1, std::string s2)
{
return std::equal(
s1.begin(),
s1.end(),
s2.begin(),
s2.end(),
[](char c1, char c2)
{
return std::tolower(c1) == std::tolower(c2);
}
);
}
);

return unique;
}

/*std::string ReplaceString(std::string subject, const std::string& search, const std::string& replace)
{
size_t pos = 0;
Expand Down
7 changes: 1 addition & 6 deletions AsaApi/Core/Private/Helpers.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
#pragma once

#include <vector>

#include "json.hpp"
#include <string>

namespace API
{
void MergePdbConfig(nlohmann::json& left, const nlohmann::json& right);
std::vector<std::string> MergeStringArrays(std::vector<std::string> first, std::vector<std::string> second);

__forceinline std::string ReplaceString(std::string subject, const std::string& search, const std::string& replace)
{
size_t pos = 0;
Expand Down
52 changes: 0 additions & 52 deletions AsaApi/Core/Private/PluginManager/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <Logger/Logger.h>
#include "Tools.h"

#include "../Helpers.h"
#include "../IBaseApi.h"
#include <Timer.h>

Expand All @@ -19,57 +18,6 @@ namespace API
return instance;
}

nlohmann::json PluginManager::GetAllPDBConfigs()
{
namespace fs = std::filesystem;

const std::string dir_path = Tools::GetCurrentDir() + "/" + game_api->GetApiName() + "/Plugins";

auto result = nlohmann::json({});

for (const auto& dir_name : fs::directory_iterator(dir_path))
{
const auto& path = dir_name.path();
const auto filename = path.filename().stem().generic_string();

try
{
const auto plugin_pdb_config = ReadPluginPDBConfig(filename);
MergePdbConfig(result, plugin_pdb_config);
}
catch (const std::exception& error)
{
Log::GetLog()->warn("({}) {}", __FUNCTION__, error.what());
}
}

return result;
}

nlohmann::json PluginManager::ReadPluginPDBConfig(const std::string& plugin_name)
{
namespace fs = std::filesystem;

auto plugin_pdb_config = nlohmann::json({});

const std::string dir_path = Tools::GetCurrentDir() + "/" + game_api->GetApiName() + "/Plugins/" + plugin_name;
const std::string config_path = dir_path + "/PdbConfig.json";

if (!fs::exists(config_path))
{
return plugin_pdb_config;
}

std::ifstream file{ config_path };
if (file.is_open())
{
file >> plugin_pdb_config;
file.close();
}

return plugin_pdb_config;
}

nlohmann::json PluginManager::ReadSettingsConfig()
{
nlohmann::json config = nlohmann::json::object({});
Expand Down
6 changes: 0 additions & 6 deletions AsaApi/Core/Private/PluginManager/PluginManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ namespace API
PluginManager& operator=(const PluginManager&) = delete;
PluginManager& operator=(PluginManager&&) = delete;

/**
* \brief Get all plugin pdb configs
*/
static nlohmann::json GetAllPDBConfigs();

/**
* \brief Find and load all plugins
*/
Expand Down Expand Up @@ -89,7 +84,6 @@ namespace API
~PluginManager() = default;

static nlohmann::json ReadPluginInfo(const std::string& plugin_name);
static nlohmann::json ReadPluginPDBConfig(const std::string& plugin_name);
static nlohmann::json ReadSettingsConfig();

void CheckPluginsDependencies();
Expand Down

0 comments on commit f4c07e2

Please sign in to comment.