-
Notifications
You must be signed in to change notification settings - Fork 417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Filesystem] Path Manager Improvements #4557
Draft
Akkadius
wants to merge
3
commits into
master
Choose a base branch
from
akkadius/path-manager-improvements
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,16 +20,12 @@ void PathManager::LoadPaths() | |
{ | ||
m_server_path = File::FindEqemuConfigPath(); | ||
|
||
if (!m_server_path.empty()) { | ||
std::filesystem::current_path(m_server_path); | ||
} | ||
|
||
if (m_server_path.empty()) { | ||
LogInfo("Failed to load server path"); | ||
return; | ||
} | ||
|
||
LogInfo("server [{}]", m_server_path); | ||
std::filesystem::current_path(m_server_path); | ||
|
||
if (!EQEmuConfig::LoadConfig()) { | ||
LogError("Failed to load eqemu config"); | ||
|
@@ -38,66 +34,64 @@ void PathManager::LoadPaths() | |
|
||
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(); | ||
auto resolve_path = [&](const std::string& dir, const std::vector<std::string>& fallback_dirs = {}) -> std::string { | ||
// relative | ||
if (File::Exists(fs::path{m_server_path + "/" + dir}.string())) { | ||
return fs::relative(fs::path{m_server_path + "/" + dir}).lexically_normal().string(); | ||
} | ||
|
||
// absolute | ||
if (File::Exists(fs::path{dir}.string())) { | ||
return fs::absolute(fs::path{dir}).string(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using std::filesystem::path to join instead of string concatenation will handle both of these cases:
this can also be applied to the loop below. |
||
|
||
// fallback search options if specified | ||
for (const auto& fallback : fallback_dirs) { | ||
if (File::Exists(fs::path{m_server_path + "/" + fallback}.string())) { | ||
return fs::relative(fs::path{m_server_path + "/" + fallback}).lexically_normal().string(); | ||
} | ||
} | ||
|
||
// if all else fails, just set it to the config value | ||
return dir; | ||
}; | ||
|
||
m_maps_path = resolve_path(c->MapDir, {"maps", "Maps"}); | ||
m_quests_path = resolve_path(c->QuestDir); | ||
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"}); | ||
|
||
// Log all paths in a loop | ||
std::vector<std::pair<std::string, std::string>> paths = { | ||
{"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} | ||
}; | ||
|
||
constexpr int name_width = 15; | ||
constexpr int path_width = 0; | ||
constexpr int break_length = 70; | ||
|
||
std::cout << std::endl; | ||
LogInfo("{}", Strings::Repeat("-", break_length)); | ||
for (const auto& [name, in_path] : paths) { | ||
if (!in_path.empty()) { | ||
LogInfo("{:>{}} > [{:<{}}]", name, name_width, in_path, path_width); | ||
} | ||
} | ||
|
||
// 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(); | ||
} | ||
|
||
// patches | ||
if (File::Exists(fs::path{ m_server_path + "/" + c->OpcodeDir }.string())) { | ||
m_opcode_path = fs::relative(fs::path{ m_server_path + "/" + c->OpcodeDir }).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("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); | ||
LogInfo("{}", Strings::Repeat("-", break_length)); | ||
} | ||
|
||
const std::string &PathManager::GetServerPath() const | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This directory creation occurs too late, because path manager would have already passed on setting the directory (due to it not existing), so
path.GetLogPath()
will return empty string.