Get the add-on ID from the file path if possible. (#7981)
Co-authored-by: Gunter Labes <soliton@wesnoth.org>
This commit is contained in:
parent
81bbcabe13
commit
6b9a7627b9
4 changed files with 27 additions and 2 deletions
|
@ -29,7 +29,6 @@ lg::log_domain log_editor("editor");
|
|||
|
||||
namespace editor {
|
||||
|
||||
// TODO: remember refreshing through F5
|
||||
std::string initialize_addon()
|
||||
{
|
||||
std::string addon_id = "";
|
||||
|
|
|
@ -915,7 +915,12 @@ void context_manager::load_map(const std::string& filename, bool new_context)
|
|||
|
||||
if(filesystem::ends_with(filename, ".cfg")) {
|
||||
if(editor_controller::current_addon_id_ == "") {
|
||||
editor_controller::current_addon_id_ = editor::initialize_addon();
|
||||
// if no addon id has been set and the file being loaded is from an addon
|
||||
// then use the file path to determine the addon rather than showing a dialog
|
||||
editor_controller::current_addon_id_ = filesystem::get_addon_id_from_path(filename);
|
||||
if(editor_controller::current_addon_id_ == "") {
|
||||
editor_controller::current_addon_id_ = editor::initialize_addon();
|
||||
}
|
||||
set_addon_id(editor_controller::current_addon_id_);
|
||||
}
|
||||
|
||||
|
|
|
@ -1776,4 +1776,19 @@ std::string get_localized_path(const std::string& file, const std::string& suff)
|
|||
return "";
|
||||
}
|
||||
|
||||
std::string get_addon_id_from_path(const std::string& location)
|
||||
{
|
||||
std::string full_path = normalize_path(location, true);
|
||||
std::string addons_path = normalize_path(get_addons_dir(), true);
|
||||
|
||||
if(full_path.find(addons_path) == 0) {
|
||||
bfs::path path(full_path.substr(addons_path.size()+1));
|
||||
if(path.size() > 0) {
|
||||
return path.begin()->string();
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
} // namespace filesystem
|
||||
|
|
|
@ -466,4 +466,10 @@ std::string get_program_invocation(const std::string &program_name);
|
|||
*/
|
||||
std::string get_localized_path(const std::string& file, const std::string& suff = "");
|
||||
|
||||
/**
|
||||
* Returns the add-on ID from a path.
|
||||
* aka the directory directly following the "add-ons" folder, or an empty string if none is found.
|
||||
*/
|
||||
std::string get_addon_id_from_path(const std::string& location);
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue