mirror of
https://github.com/EQEmu/Server.git
synced 2026-04-11 17:12:25 +00:00
[Filesystem] Path Manager Improvements (#4557)
* [Filesystem] Path Manager Improvements * Update path_manager.cpp * Use native fs path building syntax
This commit is contained in:
parent
4493ebebab
commit
8a7d5e72cb
@ -25,6 +25,8 @@
|
|||||||
#include "repositories/discord_webhooks_repository.h"
|
#include "repositories/discord_webhooks_repository.h"
|
||||||
#include "repositories/logsys_categories_repository.h"
|
#include "repositories/logsys_categories_repository.h"
|
||||||
#include "termcolor/rang.hpp"
|
#include "termcolor/rang.hpp"
|
||||||
|
#include "path_manager.h"
|
||||||
|
#include "file.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -532,6 +534,11 @@ void EQEmuLogSys::StartFileLogs(const std::string &log_name)
|
|||||||
{
|
{
|
||||||
EQEmuLogSys::CloseFileLogs();
|
EQEmuLogSys::CloseFileLogs();
|
||||||
|
|
||||||
|
if (!File::Exists(path.GetLogPath())) {
|
||||||
|
LogInfo("Logs directory not found, creating [{}]", path.GetLogPath());
|
||||||
|
File::Makedir(path.GetLogPath());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When loading settings, we must have been given a reason in category based logging to output to a file in order to even create or open one...
|
* When loading settings, we must have been given a reason in category based logging to output to a file in order to even create or open one...
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -5,31 +5,19 @@
|
|||||||
#include "strings.h"
|
#include "strings.h"
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
||||||
namespace fs = std::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()
|
void PathManager::LoadPaths()
|
||||||
{
|
{
|
||||||
m_server_path = File::FindEqemuConfigPath();
|
m_server_path = File::FindEqemuConfigPath();
|
||||||
|
|
||||||
if (!m_server_path.empty()) {
|
|
||||||
std::filesystem::current_path(m_server_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_server_path.empty()) {
|
if (m_server_path.empty()) {
|
||||||
LogInfo("Failed to load server path");
|
LogInfo("Failed to load server path");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LogInfo("server [{}]", m_server_path);
|
std::filesystem::current_path(m_server_path);
|
||||||
|
|
||||||
if (!EQEmuConfig::LoadConfig()) {
|
if (!EQEmuConfig::LoadConfig()) {
|
||||||
LogError("Failed to load eqemu config");
|
LogError("Failed to load eqemu config");
|
||||||
@ -38,66 +26,64 @@ void PathManager::LoadPaths()
|
|||||||
|
|
||||||
const auto c = EQEmuConfig::get();
|
const auto c = EQEmuConfig::get();
|
||||||
|
|
||||||
// maps
|
auto resolve_path = [&](const std::string& dir, const std::vector<std::string>& fallback_dirs = {}) -> std::string {
|
||||||
if (File::Exists(fs::path{m_server_path + "/" + c->MapDir}.string())) {
|
// relative
|
||||||
m_maps_path = fs::relative(fs::path{m_server_path + "/" + c->MapDir}).string();
|
if (File::Exists((fs::path{m_server_path} / dir).string())) {
|
||||||
}
|
return fs::relative(fs::path{m_server_path} / dir).lexically_normal().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
|
// absolute
|
||||||
if (File::Exists(fs::path{m_server_path + "/" + c->QuestDir}.string())) {
|
if (File::Exists(fs::path{dir}.string())) {
|
||||||
m_quests_path = fs::relative(fs::path{m_server_path + "/" + c->QuestDir}).string();
|
return fs::absolute(fs::path{dir}).string();
|
||||||
}
|
}
|
||||||
|
|
||||||
// plugins
|
// fallback search options if specified
|
||||||
if (File::Exists(fs::path{m_server_path + "/" + c->PluginDir}.string())) {
|
for (const auto& fallback : fallback_dirs) {
|
||||||
m_plugins_path = fs::relative(fs::path{m_server_path + "/" + c->PluginDir}).string();
|
if (File::Exists((fs::path{m_server_path} / fallback).string())) {
|
||||||
}
|
return fs::relative(fs::path{m_server_path} / fallback).lexically_normal().string();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// lua_modules
|
// if all else fails, just set it to the config value
|
||||||
if (File::Exists(fs::path{m_server_path + "/" + c->LuaModuleDir}.string())) {
|
return dir;
|
||||||
m_lua_modules_path = fs::relative(fs::path{m_server_path + "/" + c->LuaModuleDir}).string();
|
};
|
||||||
}
|
|
||||||
|
|
||||||
// lua mods
|
m_maps_path = resolve_path(c->MapDir, {"maps", "Maps"});
|
||||||
if (File::Exists(fs::path{ m_server_path + "/mods" }.string())) {
|
m_quests_path = resolve_path(c->QuestDir);
|
||||||
m_lua_mods_path = fs::relative(fs::path{ m_server_path + "/mods" }).string();
|
m_plugins_path = resolve_path(c->PluginDir);
|
||||||
}
|
m_lua_modules_path = resolve_path(c->LuaModuleDir);
|
||||||
|
m_lua_mods_path = resolve_path("mods");
|
||||||
|
m_patch_path = resolve_path(c->PatchDir);
|
||||||
|
m_opcode_path = resolve_path(c->OpcodeDir);
|
||||||
|
m_shared_memory_path = resolve_path(c->SharedMemDir);
|
||||||
|
m_log_path = resolve_path(c->LogDir, {"logs"});
|
||||||
|
|
||||||
// patches
|
// Log all paths in a loop
|
||||||
if (File::Exists(fs::path{m_server_path + "/" + c->PatchDir}.string())) {
|
std::vector<std::pair<std::string, std::string>> paths = {
|
||||||
m_patch_path = fs::relative(fs::path{m_server_path + "/" + c->PatchDir}).string();
|
{"server", m_server_path},
|
||||||
}
|
{"logs", m_log_path},
|
||||||
|
{"lua mods", m_lua_mods_path},
|
||||||
|
{"lua_modules", m_lua_modules_path},
|
||||||
|
{"maps", m_maps_path},
|
||||||
|
{"patches", m_patch_path},
|
||||||
|
{"opcode", m_opcode_path},
|
||||||
|
{"plugins", m_plugins_path},
|
||||||
|
{"quests", m_quests_path},
|
||||||
|
{"shared_memory", m_shared_memory_path}
|
||||||
|
};
|
||||||
|
|
||||||
// patches
|
constexpr int name_width = 15;
|
||||||
if (File::Exists(fs::path{ m_server_path + "/" + c->OpcodeDir }.string())) {
|
constexpr int path_width = 0;
|
||||||
m_opcode_path = fs::relative(fs::path{ m_server_path + "/" + c->OpcodeDir }).string();
|
constexpr int break_length = 70;
|
||||||
}
|
|
||||||
|
|
||||||
// shared_memory_path
|
std::cout << std::endl;
|
||||||
if (File::Exists(fs::path{m_server_path + "/" + c->SharedMemDir}.string())) {
|
LogInfo("{}", Strings::Repeat("-", break_length));
|
||||||
m_shared_memory_path = fs::relative(fs::path{ m_server_path + "/" + c->SharedMemDir }).string();
|
for (const auto& [name, in_path] : paths) {
|
||||||
|
if (!in_path.empty()) {
|
||||||
|
LogInfo("{:>{}} > [{:<{}}]", name, name_width, in_path, path_width);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
LogInfo("{}", Strings::Repeat("-", break_length));
|
||||||
// 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("logs path [{}]", m_log_path);
|
|
||||||
LogInfo("lua mods path [{}]", m_lua_mods_path);
|
|
||||||
LogInfo("lua_modules path [{}]", m_lua_modules_path);
|
|
||||||
LogInfo("maps path [{}]", m_maps_path);
|
|
||||||
LogInfo("patches path [{}]", m_patch_path);
|
|
||||||
LogInfo("opcode path [{}]", m_opcode_path);
|
|
||||||
LogInfo("plugins path [{}]", m_plugins_path);
|
|
||||||
LogInfo("quests path [{}]", m_quests_path);
|
|
||||||
LogInfo("shared_memory path [{}]", m_shared_memory_path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string &PathManager::GetServerPath() const
|
const std::string &PathManager::GetServerPath() const
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user