mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-17 07:18:37 +00:00
[File Paths] Implement Path Manager (#2440)
* Push up branch for testing * Path manager * Tweaks * Changes * More path work * Update paths for eqemu_server.pl * More path work * Import and export client files * Path remove * More path work * Update eqemu_config.h * Fix tests * Tests disable temp * Update eqemu_config.h * Update .drone.yml * Hook tests back up * Update main.cpp * Platform tests * Fix include * Use std::filesystem on windows * Fix IPCMutex name on windows * std::filesystem changes * Update path_manager.cpp * Explicit string cast * Explicit string cast * Update path_manager.cpp * Windows fixes * Mapped files * Relative fixes * Use relative paths off of cwd * Update Debian image to Debian 11 (updates GCC) Co-authored-by: hg <4683435+hgtw@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,133 @@
|
||||
#include "path_manager.h"
|
||||
#include "file.h"
|
||||
#include "eqemu_logsys.h"
|
||||
#include "eqemu_config.h"
|
||||
#include "strings.h"
|
||||
|
||||
#include <filesystem>
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
inline std::string striptrailingslash(const std::string &file_path)
|
||||
{
|
||||
if (file_path.back() == '/' || file_path.back() == '\\') {
|
||||
return file_path.substr(0, file_path.length() - 1);
|
||||
}
|
||||
|
||||
return file_path;
|
||||
}
|
||||
|
||||
void PathManager::LoadPaths()
|
||||
{
|
||||
m_server_path = File::FindEqemuConfigPath();
|
||||
|
||||
std::filesystem::current_path(m_server_path);
|
||||
|
||||
LogInfo("[PathManager] server [{}]", m_server_path);
|
||||
|
||||
if (!EQEmuConfig::LoadConfig()) {
|
||||
LogError("[PathManager] Failed to load eqemu config");
|
||||
return;
|
||||
}
|
||||
|
||||
const auto c = EQEmuConfig::get();
|
||||
|
||||
// maps
|
||||
if (File::Exists(fs::path{m_server_path + "/" + c->MapDir}.string())) {
|
||||
m_maps_path = fs::relative(fs::path{m_server_path + "/" + c->MapDir}).string();
|
||||
}
|
||||
else if (File::Exists(fs::path{m_server_path + "/maps"}.string())) {
|
||||
m_maps_path = fs::relative(fs::path{m_server_path + "/maps"}).string();
|
||||
}
|
||||
else if (File::Exists(fs::path{m_server_path + "/Maps"}.string())) {
|
||||
m_maps_path = fs::relative(fs::path{m_server_path + "/Maps"}).string();
|
||||
}
|
||||
|
||||
// quests
|
||||
if (File::Exists(fs::path{m_server_path + "/" + c->QuestDir}.string())) {
|
||||
m_quests_path = fs::relative(fs::path{m_server_path + "/" + c->QuestDir}).string();
|
||||
}
|
||||
|
||||
// plugins
|
||||
if (File::Exists(fs::path{m_server_path + "/" + c->PluginDir}.string())) {
|
||||
m_plugins_path = fs::relative(fs::path{m_server_path + "/" + c->PluginDir}).string();
|
||||
}
|
||||
|
||||
// lua_modules
|
||||
if (File::Exists(fs::path{m_server_path + "/" + c->LuaModuleDir}.string())) {
|
||||
m_lua_modules_path = fs::relative(fs::path{m_server_path + "/" + c->LuaModuleDir}).string();
|
||||
}
|
||||
|
||||
// lua mods
|
||||
if (File::Exists(fs::path{ m_server_path + "/mods" }.string())) {
|
||||
m_lua_mods_path = fs::relative(fs::path{ m_server_path + "/mods" }).string();
|
||||
}
|
||||
|
||||
// patches
|
||||
if (File::Exists(fs::path{m_server_path + "/" + c->PatchDir}.string())) {
|
||||
m_patch_path = fs::relative(fs::path{m_server_path + "/" + c->PatchDir}).string();
|
||||
}
|
||||
|
||||
// shared_memory_path
|
||||
if (File::Exists(fs::path{m_server_path + "/" + c->SharedMemDir}.string())) {
|
||||
m_shared_memory_path = fs::relative(fs::path{ m_server_path + "/" + c->SharedMemDir }).string();
|
||||
}
|
||||
|
||||
// logging path
|
||||
if (File::Exists(fs::path{m_server_path + "/" + c->LogDir}.string())) {
|
||||
m_log_path = fs::relative(fs::path{m_server_path + "/" + c->LogDir}).string();
|
||||
}
|
||||
|
||||
LogInfo("[PathManager] logs [{}]", m_log_path);
|
||||
LogInfo("[PathManager] lua mods [{}]", m_lua_mods_path);
|
||||
LogInfo("[PathManager] lua_modules [{}]", m_lua_modules_path);
|
||||
LogInfo("[PathManager] maps [{}]", m_maps_path);
|
||||
LogInfo("[PathManager] patches [{}]", m_patch_path);
|
||||
LogInfo("[PathManager] plugins [{}]", m_plugins_path);
|
||||
LogInfo("[PathManager] quests [{}]", m_quests_path);
|
||||
LogInfo("[PathManager] shared_memory [{}]", m_shared_memory_path);
|
||||
}
|
||||
|
||||
const std::string &PathManager::GetServerPath() const
|
||||
{
|
||||
return m_server_path;
|
||||
}
|
||||
|
||||
const std::string &PathManager::GetMapsPath() const
|
||||
{
|
||||
return m_maps_path;
|
||||
}
|
||||
|
||||
const std::string &PathManager::GetQuestsPath() const
|
||||
{
|
||||
return m_quests_path;
|
||||
}
|
||||
|
||||
const std::string &PathManager::GetPluginsPath() const
|
||||
{
|
||||
return m_plugins_path;
|
||||
}
|
||||
|
||||
const std::string &PathManager::GetSharedMemoryPath() const
|
||||
{
|
||||
return m_shared_memory_path;
|
||||
}
|
||||
|
||||
const std::string &PathManager::GetLogPath() const
|
||||
{
|
||||
return m_log_path;
|
||||
}
|
||||
|
||||
const std::string &PathManager::GetPatchPath() const
|
||||
{
|
||||
return m_patch_path;
|
||||
}
|
||||
|
||||
const std::string &PathManager::GetLuaModulesPath() const
|
||||
{
|
||||
return m_lua_modules_path;
|
||||
}
|
||||
|
||||
const std::string &PathManager::GetLuaModsPath() const
|
||||
{
|
||||
return m_lua_mods_path;
|
||||
}
|
||||
Reference in New Issue
Block a user