[Release] wrt-installer_0.0.89
[framework/web/wrt-installer.git] / src / misc / widget_location.cpp
index b899bec..35a8026 100644 (file)
@@ -42,7 +42,9 @@ WidgetLocation::DirectoryDeletor::DirectoryDeletor(std::string tempPath)
 WidgetLocation::DirectoryDeletor::~DirectoryDeletor()
 {
     LogDebug("Removing widget installation temporary directory: " << m_dirpath.c_str());
-    WrtUtilRemove(m_dirpath);
+    if(!WrtUtilRemove(m_dirpath)){
+        LogError("Fail at removing directory: " << m_dirpath.c_str());
+    }
 }
 
 std::string WidgetLocation::DirectoryDeletor::getTempPath() const
@@ -65,47 +67,58 @@ WidgetLocation::~WidgetLocation()
 
 WidgetLocation::WidgetLocation(const std::string & widgetname,
                                std::string sourcePath,
-                               WrtDB::PackagingType t):
+                               WrtDB::PackagingType t,
+                               InstallLocationType locationType):
                                     m_pkgname(widgetname),
                                     m_widgetSource(sourcePath),
                                     m_type(t),
                                     m_temp(new WidgetLocation::DirectoryDeletor())
 {
+    if (INSTALL_LOCATION_TYPE_PRELOAD == locationType) {
+        m_installedPath += WrtDB::GlobalConfig::GetUserPreloadedWidgetPath();
+    } else {
+        m_installedPath += WrtDB::GlobalConfig::GetUserInstalledWidgetPath();
+    }
 }
 
 WidgetLocation::WidgetLocation(const std::string & widgetname,
                                std::string sourcePath,
                                std::string dirPath,
-                               WrtDB::PackagingType t):
+                               WrtDB::PackagingType t,
+                               InstallLocationType locationType):
                                     m_pkgname(widgetname),
                                     m_widgetSource(sourcePath),
                                     m_type(t),
                                     m_temp(new
                                             WidgetLocation::DirectoryDeletor(dirPath))
 {
+    if (INSTALL_LOCATION_TYPE_PRELOAD == locationType) {
+        m_installedPath += WrtDB::GlobalConfig::GetUserPreloadedWidgetPath();
+    } else {
+        m_installedPath += WrtDB::GlobalConfig::GetUserInstalledWidgetPath();
+    }
 }
 
 // TODO cache all these paths
 std::string WidgetLocation::getInstallationDir() const
 {
-    return std::string(WrtDB::GlobalConfig::GetUserInstalledWidgetPath());
+    return m_installedPath;
 }
 
 std::string WidgetLocation::getPackageInstallationDir() const
 {
-    return std::string(WrtDB::GlobalConfig::GetUserInstalledWidgetPath()) + "/"
-            + m_pkgname;
+    return m_installedPath + "/" + m_pkgname;
 }
 
 std::string WidgetLocation::getSourceDir() const
 {
-    return std::string(WrtDB::GlobalConfig::GetUserInstalledWidgetPath()) + "/"
+    return m_installedPath + "/"
             + m_pkgname + WrtDB::GlobalConfig::GetWidgetSrcPath();
 }
 
 std::string WidgetLocation::getBinaryDir() const
 {
-    return std::string(WrtDB::GlobalConfig::GetUserInstalledWidgetPath()) + "/"
+    return m_installedPath + "/"
             + m_pkgname + WrtDB::GlobalConfig::GetUserWidgetExecPath();
 }
 
@@ -134,6 +147,24 @@ std::string WidgetLocation::getBackupExecFile() const
     return getBackupBinaryDir() + "/" + m_pkgname;
 }
 
+std::string WidgetLocation::getUserDataRootDir() const
+{
+    return std::string(WrtDB::GlobalConfig::GetWidgetUserDataPath()) +
+        "/" + m_pkgname;
+}
+
+std::string WidgetLocation::getPrivateStorageDir() const
+{
+    return getUserDataRootDir() + "/" +
+        WrtDB::GlobalConfig::GetWidgetPrivateStoragePath();
+}
+
+std::string WidgetLocation::getShareDir() const
+{
+    return std::string(WrtDB::GlobalConfig::GetUserInstalledWidgetPath()) + "/"
+            + m_pkgname + "/" + WrtDB::GlobalConfig::GetWidgetSharePath();
+}
+
 std::string WidgetLocation::getTemporaryPackageDir() const
 {
     return m_temp->getTempPath();
@@ -141,6 +172,9 @@ std::string WidgetLocation::getTemporaryPackageDir() const
 
 std::string WidgetLocation::getTemporaryRootDir() const
 {
+    if (m_type == WrtDB::PKG_TYPE_DIRECTORY_WEB_APP) {
+        return getWidgetSource();
+    }
     if(m_type == WrtDB::PKG_TYPE_HYBRID_WEB_APP)
     {
         return getTemporaryPackageDir() + WrtDB::GlobalConfig::GetWidgetSrcPath();
@@ -153,7 +187,7 @@ std::string WidgetLocation::getTemporaryRootDir() const
 
 std::string WidgetLocation::getConfigurationDir() const
 {
-    if(m_type ==  WrtDB::PKG_TYPE_HOSTED_WEB_APP)
+    if(m_type == WrtDB::PKG_TYPE_HOSTED_WEB_APP)
     {
         std::string path = ".";
         int index = m_widgetSource.find_last_of("\\/");
@@ -163,7 +197,10 @@ std::string WidgetLocation::getConfigurationDir() const
         }
         return path;
     }
-    else
+    else if (m_type == WrtDB::PKG_TYPE_DIRECTORY_WEB_APP)
+    {
+        return getWidgetSource() + WrtDB::GlobalConfig::GetWidgetSrcPath();
+    } else
     {
         return getTemporaryRootDir();
     }