[Release] wrt-installer_0.1.114
[framework/web/wrt-installer.git] / src / jobs / widget_install / task_manifest_file.cpp
old mode 100755 (executable)
new mode 100644 (file)
index e320362..37d856e
@@ -36,6 +36,7 @@
 #include <web_provider_livebox_info.h>
 #include <web_provider_plugin_info.h>
 #include <dpl/wrt-dao-ro/global_config.h>
+#include <dpl/wrt-dao-ro/config_parser_data.h>
 #include <dpl/log/log.h>
 #include <dpl/file_input.h>
 #include <dpl/errno_string.h>
@@ -53,6 +54,7 @@
 #include <dpl/localization/LanguageTagsProvider.h>
 
 #define DEFAULT_ICON_NAME   "icon.png"
+#define DEFAULT_PREVIEW_NAME   "preview.png"
 
 using namespace WrtDB;
 
@@ -115,7 +117,6 @@ TaskManifestFile::TaskManifestFile(InstallerContext &inCont) :
         AddStep(&TaskManifestFile::stepCopyLiveboxFiles);
         AddStep(&TaskManifestFile::stepCreateExecFile);
         AddStep(&TaskManifestFile::stepGenerateManifest);
-        AddStep(&TaskManifestFile::stepParseManifest);
 
         AddAbortStep(&TaskManifestFile::stepAbortIconFiles);
     } else {
@@ -123,9 +124,6 @@ TaskManifestFile::TaskManifestFile(InstallerContext &inCont) :
         AddStep(&TaskManifestFile::stepCopyLiveboxFiles);
         AddStep(&TaskManifestFile::stepCreateExecFile);
         AddStep(&TaskManifestFile::stepGenerateManifest);
-        AddStep(&TaskManifestFile::stepParseManifest);
-
-        AddAbortStep(&TaskManifestFile::stepAbortParseManifest);
     }
 }
 
@@ -177,7 +175,7 @@ void TaskManifestFile::stepCreateExecFile()
     }
 #else
     //default widget
-    LogInfo("link -s " << clientExeStr << " " << exec);
+    LogDebug("link -s " << clientExeStr << " " << exec);
     errno = 0;
     if (symlink(clientExeStr.c_str(), exec.c_str()) != 0)
     {
@@ -208,21 +206,30 @@ void TaskManifestFile::stepCopyIconFiles()
     WrtDB::WidgetRegisterInfo::LocalizedIconList & icons =
         m_context.widgetConfig.localizationData.icons;
 
-    //reversed: last <icon> has highest priority to be copied if it has given
-    // locale (TODO: why was that working that way?)
-    for (WrtDB::WidgetRegisterInfo::LocalizedIconList::const_reverse_iterator
-         icon = icons.rbegin();
-         icon != icons.rend();
+    for (WrtDB::WidgetRegisterInfo::LocalizedIconList::const_iterator
+         icon = icons.begin();
+         icon != icons.end();
          ++icon)
     {
+        DPL::String src = icon->src;
         FOREACH(locale, icon->availableLocales)
         {
-            DPL::String src = icon->src;
-            LogDebug("Icon for locale: " << *locale << "is : " << src);
+            LogDebug("Icon for locale: " << *locale << "is: " << src);
 
             if (std::find(generatedLocales.begin(), generatedLocales.end(),
-                          *locale) != generatedLocales.end())
+                    *locale) != generatedLocales.end())
             {
+                if (icon->src == L"icon.jpg") {
+                    generatedLocales.push_back(*locale);
+                } else if (icon->src == L"icon.gif") {
+                    generatedLocales.push_back(*locale);
+                } else if (icon->src == L"icon.png") {
+                    generatedLocales.push_back(*locale);
+                } else if (icon->src == L"icon.ico") {
+                    generatedLocales.push_back(*locale);
+                } else if (icon->src == L"icon.svg") {
+                    generatedLocales.push_back(*locale);
+                }
                 LogDebug("Skipping - has that locale");
                 continue;
             } else {
@@ -315,22 +322,20 @@ void TaskManifestFile::stepCopyLiveboxFiles()
     std::ostringstream targetFile;
 
     FOREACH (boxIt, liveBoxList) {
-        boxSizeType boxSizeList = (**boxIt).m_boxInfo.m_boxSize;
+        ConfigParserData::LiveboxInfo::BoxSizeList boxSizeList =
+            (**boxIt).m_boxInfo.m_boxSize;
         FOREACH (sizeIt, boxSizeList) {
-            std::string preview = DPL::ToUTF8String((*sizeIt).second);
+            std::string preview = DPL::ToUTF8String((*sizeIt).m_preview);
             if (preview.empty()) {
                 continue;
             }
-            // copy preview image to shared directory
             sourceFile << m_context.locations->getSourceDir() << "/";
             sourceFile << preview;
             targetFile << m_context.locations->getSharedDataDir() << "/";
             targetFile << (**boxIt).m_liveboxId << ".";
-            targetFile << DPL::ToUTF8String((*sizeIt).first) << ".preview.png";
+            targetFile << DPL::ToUTF8String((*sizeIt).m_size) << "." << DEFAULT_PREVIEW_NAME;
 
-            DPL::FileInput input(sourceFile.str());
-            DPL::FileOutput output(targetFile.str());
-            DPL::Copy(&input, &output);
+            DynamicBoxFileCopy(sourceFile.str(), targetFile.str());
 
             // clear stream objects
             sourceFile.str("");
@@ -341,26 +346,39 @@ void TaskManifestFile::stepCopyLiveboxFiles()
         if (icon.empty()) {
             continue;
         }
-        // copy icon to shared directory
         sourceFile << m_context.locations->getSourceDir() << "/";
         sourceFile << icon;
         targetFile << m_context.locations->getSharedDataDir() << "/";
-        targetFile << (**boxIt).m_liveboxId << ".icon.png";
+        targetFile << (**boxIt).m_liveboxId << "." << DEFAULT_ICON_NAME;
 
-        DPL::FileInput input(sourceFile.str());
-        DPL::FileOutput output(targetFile.str());
-        DPL::Copy(&input, &output);
+        DynamicBoxFileCopy(sourceFile.str(), targetFile.str());
 
         // clear stream objects
         sourceFile.str("");
         targetFile.str("");
     }
-
     m_context.job->UpdateProgress(
         InstallerContext::INSTALL_COPY_LIVEBOX_FILES,
         "Livebox files copy Finished");
 }
 
+void TaskManifestFile::DynamicBoxFileCopy(const std::string& sourceFile,
+                                          const std::string& targetFile)
+{
+    Try
+    {
+        DPL::FileInput input(sourceFile);
+        DPL::FileOutput output(targetFile);
+        DPL::Copy(&input, &output);
+    }
+    Catch(DPL::Exception)
+    {
+        LogError("Copying Dynamic Box File Failed. " << sourceFile
+                                                     << " to " << targetFile);
+        ReThrowMsg(Exceptions::DynamicBoxFailed, "Dynamic Box File Copy Failed.");
+    }
+}
+
 void TaskManifestFile::stepBackupIconFiles()
 {
     LogDebug("Backup Icon Files");
@@ -467,7 +485,7 @@ void TaskManifestFile::saveLocalizedKey(std::ofstream &file,
 
 void TaskManifestFile::backupIconFiles()
 {
-    LogInfo("Backup Icon Files");
+    LogDebug("Backup Icon Files");
 
     std::ostringstream b_icon_dir;
     b_icon_dir << backup_dir.str() << "icons";
@@ -577,51 +595,11 @@ void TaskManifestFile::stepGenerateManifest()
     commit_manifest = destFile.str();
     LogDebug("Commiting manifest file : " << commit_manifest);
 
-    m_context.job->UpdateProgress(
-        InstallerContext::INSTALL_CREATE_MANIFEST,
-        "Widget Manifest Creation Finished");
-}
-
-void TaskManifestFile::stepParseManifest()
-{
-    int code = 0;
-    char* updateTags[3] = {NULL, };
-
-    if (!m_context.mode.removable) {
-        updateTags[0] = "preload=false";
-        updateTags[1] = "removable=false";
-        updateTags[2] = NULL;
-
-    }
-
     commitManifest();
 
-    if (m_context.isUpdateMode || (
-                m_context.mode.rootPath == InstallMode::RootPath::RO
-                && m_context.mode.installTime == InstallMode::InstallTime::PRELOAD
-                && m_context.mode.extension == InstallMode::ExtensionType::DIR)) {
-
-        code = pkgmgr_parser_parse_manifest_for_upgrade(
-                commit_manifest.c_str(), (updateTags[0] == NULL) ? NULL : updateTags);
-
-        if (code != 0) {
-            LogError("Manifest parser error: " << code);
-            ThrowMsg(Exceptions::ManifestInvalid, "Parser returncode: " << code);
-        }
-    } else {
-        code = pkgmgr_parser_parse_manifest_for_installation(
-                commit_manifest.c_str(), (updateTags[0] == NULL) ? NULL : updateTags);
-
-        if (code != 0) {
-            LogError("Manifest parser error: " << code);
-            ThrowMsg(Exceptions::ManifestInvalid, "Parser returncode: " << code);
-        }
-    }
-
     m_context.job->UpdateProgress(
-            InstallerContext::INSTALL_CREATE_MANIFEST,
-            "Widget Manifest Parsing Finished");
-    LogDebug("Manifest parsed");
+        InstallerContext::INSTALL_CREATE_MANIFEST,
+        "Widget Manifest Creation Finished");
 }
 
 void TaskManifestFile::commitManifest()
@@ -630,7 +608,7 @@ void TaskManifestFile::commitManifest()
     if (!(m_context.mode.rootPath == InstallMode::RootPath::RO &&
                 m_context.mode.installTime == InstallMode::InstallTime::PRELOAD
                 && m_context.mode.extension == InstallMode::ExtensionType::DIR)) {
-        LogInfo("cp " << manifest_file << " " << commit_manifest);
+        LogDebug("cp " << manifest_file << " " << commit_manifest);
 
         DPL::FileInput input(DPL::ToUTF8String(manifest_file));
         DPL::FileOutput output(commit_manifest);
@@ -931,6 +909,10 @@ void TaskManifestFile::setWidgetManifest(Manifest & manifest)
     DPL::String name = (!!m_context.widgetConfig.configInfo.authorName ?
                         *m_context.widgetConfig.configInfo.authorName : L"");
     manifest.addAuthor(Author(email, href, L"", name));
+
+    if (!m_context.callerPkgId.empty()) {
+        manifest.setStoreClientId(m_context.callerPkgId);
+    }
 }
 
 void TaskManifestFile::setWidgetOtherInfo(UiApplication & uiApp)
@@ -961,7 +943,7 @@ void TaskManifestFile::setAppControlsInfo(UiApplication & uiApp)
         m_context.widgetConfig.configInfo.appControlList;
 
     if (appControlList.empty()) {
-        LogInfo("Widget doesn't contain app control");
+        LogDebug("Widget doesn't contain app control");
         return;
     }
 
@@ -998,7 +980,7 @@ void TaskManifestFile::setAppCategory(UiApplication &uiApp)
         m_context.widgetConfig.configInfo.categoryList;
 
     if (categoryList.empty()) {
-        LogInfo("Widget doesn't contain application category");
+        LogDebug("Widget doesn't contain application category");
         return;
     }
     FOREACH(it, categoryList) {
@@ -1014,7 +996,7 @@ void TaskManifestFile::setMetadata(UiApplication &uiApp)
         m_context.widgetConfig.configInfo.metadataList;
 
     if (metadataList.empty()) {
-        LogInfo("Web application doesn't contain metadata");
+        LogDebug("Web application doesn't contain metadata");
         return;
     }
     FOREACH(it, metadataList) {
@@ -1023,27 +1005,10 @@ void TaskManifestFile::setMetadata(UiApplication &uiApp)
     }
 }
 
-void TaskManifestFile::stepAbortParseManifest()
-{
-    LogError("[Parse Manifest] Abroting....");
-
-    int code = pkgmgr_parser_parse_manifest_for_uninstallation(
-            DPL::ToUTF8String(manifest_file).c_str(), NULL);
-
-    if (0 != code) {
-        LogWarning("Manifest parser error: " << code);
-        ThrowMsg(Exceptions::ManifestInvalid, "Parser returncode: " << code);
-    }
-    int ret = unlink(DPL::ToUTF8String(manifest_file).c_str());
-    if (0 != ret) {
-        LogWarning("No manifest file found: " << manifest_file);
-    }
-}
-
 void TaskManifestFile::setLiveBoxInfo(Manifest& manifest)
 {
     FOREACH(it, m_context.widgetConfig.configInfo.m_livebox) {
-        LogInfo("setLiveBoxInfo");
+        LogDebug("setLiveBoxInfo");
         LiveBoxInfo liveBox;
         DPL::Optional<WrtDB::ConfigParserData::LiveboxInfo> ConfigInfo = *it;
         DPL::String appid = m_context.widgetConfig.tzAppid;
@@ -1105,7 +1070,7 @@ void TaskManifestFile::setLiveBoxInfo(Manifest& manifest)
         if (ConfigInfo->m_boxInfo.m_boxSrc.empty() ||
             ConfigInfo->m_boxInfo.m_boxSize.empty())
         {
-            LogInfo("Widget doesn't contain box");
+            LogDebug("Widget doesn't contain box");
             return;
         } else {
             BoxInfoType box;
@@ -1147,18 +1112,17 @@ void TaskManifestFile::setLiveBoxInfo(Manifest& manifest)
                 box.boxTouchEffect= L"false";
             }
 
-            std::list<std::pair<DPL::String, DPL::String> > BoxSizeList
-                = ConfigInfo->m_boxInfo.m_boxSize;
-            FOREACH(im, BoxSizeList) {
-                std::pair<DPL::String, DPL::String> boxSize = *im;
-                if (!boxSize.second.empty()) {
-                    boxSize.second =
+            ConfigParserData::LiveboxInfo::BoxSizeList boxSizeList =
+                ConfigInfo->m_boxInfo.m_boxSize;
+            FOREACH(it, boxSizeList) {
+                if (!(*it).m_preview.empty()) {
+                    (*it).m_preview =
                         DPL::FromUTF8String(m_context.locations->getSharedDataDir()) +
                         DPL::String(L"/") +
                         ConfigInfo->m_liveboxId + DPL::String(L".") +
-                        boxSize.first + DPL::String(L".preview.png");
+                        (*it).m_size + DPL::String(L".preview.png");
                 }
-                box.boxSize.push_back(boxSize);
+                box.boxSize.push_back((*it));
             }
 
             if (!ConfigInfo->m_boxInfo.m_pdSrc.empty()
@@ -1189,11 +1153,11 @@ void TaskManifestFile::setAccount(Manifest& manifest)
     AccountProviderType provider;
 
     if (account.m_iconSet.empty()) {
-        LogInfo("Widget doesn't contain Account");
+        LogDebug("Widget doesn't contain Account");
         return;
     }
     if (account.m_multiAccountSupport) {
-        provider.multiAccount = L"ture";
+        provider.multiAccount = L"true";
     } else {
         provider.multiAccount = L"false";
     }
@@ -1240,5 +1204,14 @@ void TaskManifestFile::setPrivilege(Manifest& manifest)
     manifest.addPrivileges(privilege);
 }
 
+void TaskManifestFile::StartStep()
+{
+
+}
+
+void TaskManifestFile::EndStep()
+{
+
+}
 } //namespace WidgetInstall
 } //namespace Jobs