From fc7b7d7e66ea2c81014285fd153eba0a7229c36a Mon Sep 17 00:00:00 2001 From: JackLivio Date: Thu, 13 Aug 2020 16:05:32 -0400 Subject: Get filename from full path --- .../src/commands/hmi/on_ui_update_file_notification.cc | 7 +++++++ src/components/utils/include/utils/file_system.h | 8 ++++++++ src/components/utils/src/file_system.cc | 5 +++++ 3 files changed, 20 insertions(+) diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_ui_update_file_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_ui_update_file_notification.cc index dafb299524..4c6157c48d 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_ui_update_file_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_ui_update_file_notification.cc @@ -34,6 +34,7 @@ #include "application_manager/application_impl.h" #include "application_manager/rpc_service.h" #include "interfaces/MOBILE_API.h" +#include "utils/file_system.h" namespace sdl_rpc_plugin { using namespace application_manager; @@ -75,6 +76,12 @@ void OnUIUpdateFileNotification::Run() { (*message_)[strings::msg_params][strings::app_id]; (*message_)[strings::msg_params].erase(strings::app_id); + // Parse fileName in case the full path was sent by the HMI + auto fileName = + (*message_)[strings::msg_params][strings::file_name].asString(); + (*message_)[strings::msg_params][strings::file_name] = + file_system::GetFileName(fileName); + SendNotificationToMobile(message_); } diff --git a/src/components/utils/include/utils/file_system.h b/src/components/utils/include/utils/file_system.h index f575da129f..f06ca15281 100644 --- a/src/components/utils/include/utils/file_system.h +++ b/src/components/utils/include/utils/file_system.h @@ -297,6 +297,14 @@ bool CopyFile(const std::string& src, const std::string& dst); */ bool MoveFile(const std::string& src, const std::string& dst); +/** + * @brief Get filename from full path + * + * @param full_path Source file path + * @return parsed filename + */ +std::string GetFileName(const std::string& full_path); + } // namespace file_system #endif // SRC_COMPONENTS_UTILS_INCLUDE_UTILS_FILE_SYSTEM_H_ diff --git a/src/components/utils/src/file_system.cc b/src/components/utils/src/file_system.cc index 015dc25a22..9c619c8388 100644 --- a/src/components/utils/src/file_system.cc +++ b/src/components/utils/src/file_system.cc @@ -572,3 +572,8 @@ bool file_system::MoveFile(const std::string& src, const std::string& dst) { } return true; } + +std::string file_system::GetFileName(const std::string& full_path) { + fs::path p(full_path); + return p.filename().string(); +} \ No newline at end of file -- cgit v1.2.1