#include "message_attachment.h"
#include "common/logger.h"
+#include "common/virtual_fs.h"
namespace extension {
namespace messaging {
return m_filePath.substr(pos + 1);
}
-namespace {
-
-const std::unordered_map<std::string, std::string> virtualToReal = {
- { "downloads", "/opt/usr/media/Downloads" },
- { "documents", "/opt/usr/media/Documents" },
- { "music" , "/opt/usr/media/Sounds" },
- { "images" , "/opt/usr/media/Images" },
- { "videos" , "/opt/usr/media/Videos" },
- { "ringtones", "/opt/usr/share/settings/Ringtones" },
- { "camera" , "/opt/usr/media/DCIM/Camera" }
-};
-
-const char PATH_SEPARATOR = '/';
-
-} // namespace
-
void MessageAttachment::setFilePath(const std::string &value)
{
LoggerD("Entered");
- std::string tmp = value;
- // change to lower case
- for (int i = 0; i < tmp.length() && i < 4; i++) {
- tmp[i] = tolower(tmp[i]);
- }
- if (tmp.find("file://") != std::string::npos) {
- m_filePath = value.substr(7);
- } else {
- m_filePath = value;
- }
-
- if (PATH_SEPARATOR != m_filePath[0]) {
- auto pos = m_filePath.find(PATH_SEPARATOR);
-
- if (pos == std::string::npos) {
- pos = m_filePath.length();
- }
-
- auto path = virtualToReal.find(m_filePath.substr(0, pos));
-
- if (virtualToReal.end() != path) {
- m_filePath = path->second + m_filePath.substr(pos);
- }
- }
+ m_filePath = common::VirtualFs::GetInstance().GetRealPath(value);
m_isFilePathSet = true;
}