[Release] wrt-installer_0.1.40
[framework/web/wrt-installer.git] / src / wrt-installer / wrt-installer.cpp
index 1184580..7d2cb52 100644 (file)
@@ -21,6 +21,7 @@
 #include "wrt-installer.h"
 #include "plugin_utils.h"
 
+#include <map>
 #include <string>
 #include <cstring>
 #include <cstdlib>
@@ -41,6 +42,7 @@
 #include <dpl/copy.h>
 #include <dpl/errno_string.h>
 #include <dpl/utils/wrt_global_settings.h>
+#include <dpl/utils/wrt_utility.h>
 #include <parser_runner.h>
 #include <widget_parser.h>
 #include <root_parser.h>
@@ -88,7 +90,6 @@ WrtInstaller::WrtInstaller(int argc, char **argv) :
     m_returnStatus(-1),
     m_installByPkgmgr(false),
     m_quiet(true),
-    m_popup(NULL),
     m_startupPluginInstallation(false)
 {
     Touch();
@@ -109,95 +110,6 @@ int WrtInstaller::getReturnStatus() const
     }
 }
 
-WrtInstaller::InstallerPopup::InstallerPopup() :
-    m_win(NULL),
-    m_popup(NULL),
-    m_progressbar(NULL)
-{}
-
-WrtInstaller::InstallerPopup::~InstallerPopup()
-{
-    LogDebug("App Finished");
-}
-
-void WrtInstaller::InstallerPopup::init()
-{
-    LogDebug("Window Init");
-
-    if (m_win == NULL) {
-        // create window
-        m_win = createWin("wrt-installer");
-
-        // create popup
-        m_popup = elm_popup_add(m_win);
-
-        // create progressbar
-        m_progressbar = elm_progressbar_add(m_popup);
-        elm_object_style_set(m_progressbar, "list_progress");
-        elm_progressbar_horizontal_set(m_progressbar, EINA_TRUE);
-        evas_object_size_hint_align_set(m_progressbar, EVAS_HINT_FILL,
-                                        EVAS_HINT_FILL);
-        evas_object_size_hint_weight_set(m_progressbar, EVAS_HINT_EXPAND,
-                                         EVAS_HINT_EXPAND);
-        elm_object_content_set(m_popup, m_progressbar);
-        elm_progressbar_value_set(m_progressbar, 0.0);
-        evas_object_show(m_progressbar);
-
-        evas_object_show(m_popup);
-        evas_object_show(m_win);
-    }
-}
-
-Evas_Object* WrtInstaller::InstallerPopup::createWin(const char *name)
-{
-    Evas_Object *win;
-    win = elm_win_add(NULL, name, ELM_WIN_DIALOG_BASIC);
-
-    int w, h;
-    if (!win) {
-        return NULL;
-    }
-
-    elm_win_alpha_set(win, EINA_TRUE);
-    elm_win_title_set(win, name);
-    elm_win_borderless_set(win, EINA_TRUE);
-    elm_win_raise(win);
-
-    ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
-    evas_object_resize(win, w, h);
-    return win;
-}
-
-void WrtInstaller::InstallerPopup::showPopup(void* userdata,
-                                             const DPL::String& pkgMsg,
-                                             ShowResultCallback callback)
-{
-    Evas_Object *btn;
-
-    LogDebug("Result Popup Created");
-    evas_object_del(m_popup);
-    m_popup = NULL;
-
-    m_popup = elm_popup_add(m_win);
-    if (!m_popup) {
-        return;
-    }
-
-    btn = elm_button_add(m_popup);
-    if (!btn) {
-        evas_object_del(m_popup);
-        return;
-    }
-    elm_object_text_set(btn, "OK");
-    evas_object_smart_callback_add(btn, "clicked", callback, userdata);
-    elm_object_part_content_set(m_popup, "button1", btn);
-    elm_object_part_text_set(m_popup, "title,text", "RESULT");
-    elm_object_text_set(m_popup, DPL::ToUTF8String(pkgMsg).c_str());
-
-    evas_object_show(m_popup);
-    evas_object_show(m_win);
-}
-
 void WrtInstaller::OnStop()
 {
     LogInfo("Stopping Dummy Client");
@@ -250,6 +162,7 @@ void WrtInstaller::OnCreate()
             if (m_argc != 2) {
                 return showHelpAndQuit();
             }
+
             if (!m_startupPluginInstallation) {
                 AddStep(&WrtInstaller::installPluginsStep);
             } else {
@@ -269,14 +182,57 @@ void WrtInstaller::OnCreate()
                 m_installMode = WRT_INSTALL_MODE_INSTALL_WGT;
             }
             m_packagePath = m_argv[2];
+
             AddStep(&WrtInstaller::installStep);
-        } else if (arg == "-il" || arg == "--install-preload") {
+        } else if (arg == "-ip" || arg == "--install-preload") {
+            LogDebug("Install preload web app");
             if (m_argc != 3) {
                 return showHelpAndQuit();
             }
             m_packagePath = m_argv[2];
             m_installMode = WRT_INSTALL_MODE_INSTALL_PRELOAD;
             AddStep(&WrtInstaller::installStep);
+        } else if (arg == "-c" || arg == "--csc-update") {
+            // "path=/opt/system/csc/Ozq2iEG15R-2.0.0-arm.wgt:op=install:removable=true"
+            LogDebug("Install & uninstall by csc configuration");
+            if (m_argc != 3) {
+                return showHelpAndQuit();
+            }
+            std::string configuration = m_argv[2];
+            m_CSCconfigurationMap = parseCSCConfiguration(configuration);
+
+            CSCConfiguration::dataMap::iterator it;
+            it = m_CSCconfigurationMap.find(CSCConfiguration::KEY_OP);
+            if (it == m_CSCconfigurationMap.end()) {
+                return showHelpAndQuit();
+            }
+
+            if (it->second == CSCConfiguration::VALUE_INSTALL) {
+                LogDebug("operation = " << it->second);
+                m_installMode = WRT_INSTALL_MODE_INSTALL_WGT;
+                it = m_CSCconfigurationMap.find(CSCConfiguration::KEY_PATH);
+                if (it == m_CSCconfigurationMap.end()) {
+                    return showHelpAndQuit();
+                }
+                m_packagePath = it->second;
+                AddStep(&WrtInstaller::installStep);
+                LogDebug("path      = " << m_packagePath);
+            } else if (it->second == CSCConfiguration::VALUE_UNINSTALL) {
+                LogDebug("operation = " << it->second);
+                // uninstall command isn't confirmed yet
+                it = m_CSCconfigurationMap.find(CSCConfiguration::KEY_PATH);
+                if (it == m_CSCconfigurationMap.end()) {
+                    return showHelpAndQuit();
+                }
+                m_packagePath = it->second;
+                AddStep(&WrtInstaller::unistallWgtFileStep);
+                LogDebug("operation = uninstall");
+                LogDebug("path      = " << m_packagePath);
+            } else {
+                LogError("Unknown operation : " << it->second);
+                LogDebug("operation = " << it->second);
+                return showHelpAndQuit();
+            }
         } else if (arg == "-un" || arg == "--uninstall-name") {
             if (m_argc != 3) {
                 return showHelpAndQuit();
@@ -359,11 +315,11 @@ void WrtInstaller::OnReset(bundle* /*b*/)
 void WrtInstaller::OnTerminate()
 {
     LogDebug("Wrt Shutdown now");
-    PluginUtils::unlockPluginInstallation();
+    PluginUtils::unlockPluginInstallation(m_installMode ==
+            WRT_INSTALL_MODE_INSTALL_PRELOAD);
     if (m_initialized) {
         wrt_installer_shutdown();
     }
-    delete m_popup;
 }
 
 void WrtInstaller::showHelpAndQuit()
@@ -380,6 +336,8 @@ void WrtInstaller::showHelpAndQuit()
            "  -p,    --install-plugins                      install plugins\n"
            "  -i,    --install                              "
            "install or update widget package for given path\n"
+           "  -c,    --csc-update                           "
+           "install or uninstall by CSC configuration \n"
            "  -un,   --uninstall-name                       "
            "uninstall widget for given package name\n"
            "  -up,   --uninstall-packagepath                "
@@ -460,7 +418,8 @@ void WrtInstaller::installPluginsStep()
 
     if (m_startupPluginInstallation) {
         LogInfo("Plugin installation started because new plugin package found");
-    } else if (!PluginUtils::lockPluginInstallation()) {
+    } else if (!PluginUtils::lockPluginInstallation(m_installMode ==
+                WRT_INSTALL_MODE_INSTALL_PRELOAD)) {
         LogError("Failed to open plugin installation lock file"
                  " Plugins are currently installed by other process");
         staticWrtPluginInstallationCallback(WRT_INSTALLER_ERROR_PLUGIN_INSTALLATION_FAILED,
@@ -646,11 +605,6 @@ void WrtInstaller::staticWrtInitCallback(WrtErrStatus status,
         This->m_initialized = true;
         This->m_returnStatus = 0;
 
-        if (This->popupsEnabled()) {
-            This->m_popup = new InstallerPopup;
-            This->m_popup->init();
-        }
-
         This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
             ::PostEvent(WRTInstallerNS::NextStepEvent());
     } else {
@@ -688,13 +642,8 @@ void WrtInstaller::staticWrtStatusCallback(std::string tizenId,
         LogError("Step failed");
         This->m_returnStatus = -1;
 
-        if (This->popupsEnabled()) {
-            resultMsg += L" : " + DPL::FromUTF8String(PKGMGR_END_FAILURE);
-            This->m_popup->showPopup(This, resultMsg, failResultCallback);
-        } else {
-            This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>
-                ::PostEvent(WRTInstallerNS::QuitEvent());
-        }
+        This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>
+            ::PostEvent(WRTInstallerNS::QuitEvent());
 
         switch (status) {
             case WRT_INSTALLER_ERROR_PACKAGE_NOT_FOUND:
@@ -888,13 +837,18 @@ void WrtInstaller::staticWrtStatusCallback(std::string tizenId,
         This->m_returnStatus = 0;
         resultMsg += L" : " + DPL::FromUTF8String(PKGMGR_END_SUCCESS);
 
-        if (This->popupsEnabled()) {
-            This->m_popup->showPopup(This, resultMsg, showResultCallback);
-        } else {
-            This->DPL::Event::ControllerEventHandler<WRTInstallerNS::
-                                                         NextStepEvent>
-                ::PostEvent(WRTInstallerNS::NextStepEvent());
+        if (This->m_installMode == WRT_INSTALL_MODE_INSTALL_PRELOAD &&
+                !This->m_packagePath.empty()) {
+            LogDebug("This widget is preloaded so it will be removed : "
+                    << This->m_packagePath);
+            if (!WrtUtilRemove(This->m_packagePath)) {
+                LogError("Failed to remove " << This->m_packagePath);
+            }
         }
+
+        This->DPL::Event::ControllerEventHandler<WRTInstallerNS::
+                                                     NextStepEvent>
+            ::PostEvent(WRTInstallerNS::NextStepEvent());
     }
 }
 
@@ -923,28 +877,14 @@ void WrtInstaller::staticWrtPluginInstallationCallback(WrtErrStatus status,
         }
 
         //remove lock file
-        if (!PluginUtils::unlockPluginInstallation()) {
+        if (!PluginUtils::unlockPluginInstallation(This->m_installMode ==
+                WRT_INSTALL_MODE_INSTALL_PRELOAD)) {
             LogInfo("Failed to remove installation lock");
         }
 
-        if (This->popupsEnabled()) {
-            This->m_popup->init();
-            elm_progressbar_value_set(This->m_popup->m_progressbar, 100.0);
-            evas_object_show(This->m_popup->m_popup);
-        }
-
         This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
             ::PostEvent(WRTInstallerNS::NextStepEvent());
     } else {
-        if (This->popupsEnabled()) {
-            This->m_popup->init();
-            float percent =
-                (This->m_totalPlugins -
-                 This->m_numPluginsToInstall) / (float)This->m_totalPlugins;
-            elm_progressbar_value_set(This->m_popup->m_progressbar, percent);
-            evas_object_show(This->m_popup->m_popup);
-        }
-
         This->DPL::Event::ControllerEventHandler<WRTInstallerNS::
                                                      InstallPluginEvent>::
             PostEvent(
@@ -992,31 +932,19 @@ void WrtInstaller::staticWrtPluginInstallProgressCb(float percent,
 
 void WrtInstaller::staticWrtInstallProgressCallback(float percent,
                                                     const char* description,
-                                                    void* userdata)
+                                                    void* /*userdata*/)
 {
-    WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
+    //WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
     LogInfo(" progress: " << percent <<
             " description: " << description);
-
-    if (This->popupsEnabled()) {
-        This->m_popup->init();
-        elm_progressbar_value_set(This->m_popup->m_progressbar, percent / 100.0);
-        evas_object_show(This->m_popup->m_popup);
-    }
 }
 void WrtInstaller::staticWrtUninstallProgressCallback(float percent,
                                                       const char* description,
-                                                      void* userdata)
+                                                      void* /*userdata*/)
 {
-    WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
+    //WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
     LogInfo(" progress: " << percent <<
             " description: " << description);
-
-    if (This->popupsEnabled()) {
-        This->m_popup->init();
-        elm_progressbar_value_set(This->m_popup->m_progressbar, percent / 100.0);
-        evas_object_show(This->m_popup->m_popup);
-    }
 }
 
 void WrtInstaller::showResultCallback(void *data, Evas_Object* /*obj*/,
@@ -1043,14 +971,16 @@ void WrtInstaller::installNewPlugins()
 {
     LogDebug("Install new plugins");
 
-    if (!PluginUtils::lockPluginInstallation()) {
+    if (!PluginUtils::lockPluginInstallation(m_installMode ==
+                WRT_INSTALL_MODE_INSTALL_PRELOAD)) {
         LogInfo("Lock NOT created");
         return;
     }
 
     if (!PluginUtils::checkPluginInstallationRequired()) {
         LogDebug("Plugin installation not required");
-        PluginUtils::unlockPluginInstallation();
+        PluginUtils::unlockPluginInstallation(m_installMode ==
+            WRT_INSTALL_MODE_INSTALL_PRELOAD);
         return;
     }
 
@@ -1058,9 +988,33 @@ void WrtInstaller::installNewPlugins()
     AddStep(&WrtInstaller::installPluginsStep);
 }
 
-bool WrtInstaller::popupsEnabled() const
+CSCConfiguration::dataMap WrtInstaller::parseCSCConfiguration(
+    std::string str)
 {
-    return !m_quiet && !GlobalSettings::PopupsTestModeEnabled();
+    // path=/opt/system/csc/Ozq2iEG15R-2.0.0-arm.wgt:op=install:removable=true
+    // parsing CSC configuration string
+    LogDebug("parseConfiguration");
+    CSCConfiguration::dataMap result;
+
+    if (str.empty()) {
+        LogDebug("Input argument is empty");
+        return result;
+    }
+
+    char* buf = strdup(str.c_str());
+    const char* ptr = strtok(buf,":");
+    while (ptr != NULL) {
+        std::string string = ptr;
+        size_t pos = string.find('=');
+        if (pos == std::string::npos) {
+            continue;
+        }
+        result.insert(
+            CSCConfiguration::dataPair(string.substr(0, pos),
+                                        string.substr(pos+1)));
+        ptr = strtok (NULL, ":");
+    }
+     return result;
 }
 
 int main(int argc, char *argv[])