Fix of icon files creation 56/45656/1
authorTomasz Iwanek <t.iwanek@samsung.com>
Fri, 7 Aug 2015 10:28:21 +0000 (12:28 +0200)
committerTomasz Iwanek <t.iwanek@samsung.com>
Fri, 7 Aug 2015 14:07:00 +0000 (16:07 +0200)
Additional steps for creating icons.

Change-Id: Ia5949dcef4f08b3941e0e819c2b973054859d788

src/common/CMakeLists.txt
src/common/step/step_backup_icons.cc
src/common/step/step_create_icons.cc [new file with mode: 0644]
src/common/step/step_create_icons.h [new file with mode: 0644]
src/common/step/step_generate_xml.cc
src/common/step/step_generate_xml.h
src/tpk/task.cc
src/wgt/CMakeLists.txt
src/wgt/step/step_wgt_create_icons.cc [new file with mode: 0644]
src/wgt/step/step_wgt_create_icons.h [new file with mode: 0644]
src/wgt/wgt_backend.cc

index b81d35f..4a46462 100644 (file)
@@ -9,6 +9,7 @@ SET(SRCS
   step/step_backup_icons.cc
   step/step_backup_manifest.cc
   step/step_unzip.cc
+  step/step_create_icons.cc
   step/step_check_old_certificate.cc
   step/step_check_signature.cc
   step/step_configure.cc
index 6988bbd..8e63a2f 100755 (executable)
@@ -53,7 +53,7 @@ Step::Status StepBackupIcons::undo() {
   for (auto& pair : icons_) {
     if (!MoveFile(pair.second, pair.first)) {
       LOG(ERROR) << "Cannot revert icon from backup: " << pair.first;
-//      return Status::ERROR; // undo cannot fail, so no break
+      // undo cannot fail, so no break
     }
   }
   LOG(DEBUG) << "Icons reverted from backup";
diff --git a/src/common/step/step_create_icons.cc b/src/common/step/step_create_icons.cc
new file mode 100644 (file)
index 0000000..eb8589b
--- /dev/null
@@ -0,0 +1,69 @@
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#include "common/step/step_create_icons.h"
+
+#include <boost/filesystem/operations.hpp>
+#include <boost/system/error_code.hpp>
+#include <pkgmgr-info.h>
+
+#include "common/utils/clist_helpers.h"
+
+namespace bf = boost::filesystem;
+namespace bs = boost::system;
+
+namespace common_installer {
+namespace filesystem {
+
+Step::Status StepCreateIcons::process() {
+  bf::path icons_directory(getIconPath(context_->uid.get()));
+  if (!bf::exists(icons_directory)) {
+    bs::error_code error;
+    bf::create_directories(icons_directory, error);
+    if (error) {
+      LOG(ERROR) << "Cannot create directory of application icons";
+      return Status::ERROR;
+    }
+  }
+
+  uiapplication_x* ui = nullptr;
+  PKGMGR_LIST_MOVE_NODE_TO_HEAD(context_->manifest_data.get()->uiapplication,
+                                ui);
+  for (; ui; ui = ui->next) {
+    // TODO(t.iwanek): this is ignoring icon locale as well as other steps
+    // icons should be localized
+    if (ui->icon && ui->icon->name) {
+      bf::path source = GetIconRoot() / ui->icon->name;
+      bf::path destination = icons_directory / ui->appid;
+      if (destination.has_extension())
+        destination += source.extension();
+      else
+        destination += ".png";
+      bs::error_code error;
+      bf::copy_file(source, destination, error);
+      if (error) {
+        LOG(ERROR) << "Cannot create package icon: " << destination;
+        return Status::ERROR;
+      }
+      icons_.push_back(destination);
+    }
+  }
+  LOG(DEBUG) << "Icon files created";
+  return Status::OK;
+}
+
+Step::Status StepCreateIcons::undo() {
+  for (auto& icon : icons_) {
+    bs::error_code error;
+    bf::remove_all(icon, error);
+  }
+  return Status::OK;
+}
+
+boost::filesystem::path StepCreateIcons::GetIconRoot() const {
+  return context_->pkg_path.get();
+}
+
+}  // namespace filesystem
+}  // namespace common_installer
diff --git a/src/common/step/step_create_icons.h b/src/common/step/step_create_icons.h
new file mode 100644 (file)
index 0000000..9e97b35
--- /dev/null
@@ -0,0 +1,40 @@
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef COMMON_STEP_STEP_CREATE_ICONS_H_
+#define COMMON_STEP_STEP_CREATE_ICONS_H_
+
+#include <boost/filesystem/path.hpp>
+#include <utility>
+#include <vector>
+
+#include "common/context_installer.h"
+#include "common/step/step.h"
+#include "common/utils/logging.h"
+
+namespace common_installer {
+namespace filesystem {
+
+class StepCreateIcons : public Step {
+ public:
+  using Step::Step;
+
+  Status process() override;
+  Status clean() override { return Status::OK; }
+  Status undo() override;
+  Status precheck() override { return Status::OK; }
+
+ protected:
+  virtual boost::filesystem::path GetIconRoot() const;
+
+ private:
+  std::vector<boost::filesystem::path> icons_;
+
+  SCOPE_LOG_TAG(CreateIcons)
+};
+
+}  // namespace filesystem
+}  // namespace common_installer
+
+#endif  // COMMON_STEP_STEP_CREATE_ICONS_H_
index c945f40..93dec52 100755 (executable)
@@ -5,6 +5,7 @@
 
 #include "common/step/step_generate_xml.h"
 
+#include <boost/filesystem/path.hpp>
 #include <boost/system/error_code.hpp>
 #include <libxml/parser.h>
 #include <libxml/xmlreader.h>
@@ -79,18 +80,16 @@ Step::Status StepGenerateXml::GenerateApplicationCommonXml(T* app,
     }
   }
 
-  // the icon is renamed to <appid.png>
-  icon_path_ = fs::path(getIconPath(context_->uid.get()));
-  CreateDir(icon_path_);
-  fs::path icon = fs::path(app->appid) += fs::path(".png");
-
+  // icon is renamed to <appid.png>
   if (app->icon->name) {
-    fs::path app_icon = fs::path(context_->pkg_path.get())
-      / fs::path(app->appid)
-      / fs::path(app->icon->name);
+    fs::path app_icon = context_->pkg_path.get() / app->icon->name;
+    fs::path icon = app->appid;
+    if (app_icon.has_extension())
+      icon += app_icon.extension();
+    else
+      icon += fs::path(".png");
+
     if (fs::exists(app_icon)) {
-      fs::copy_file(app_icon, icon_path_ /= icon,
-                        fs::copy_option::overwrite_if_exists);
       xmlTextWriterWriteFormatElement(writer, BAD_CAST "icon",
                                           "%s", BAD_CAST icon.c_str());
     }
@@ -306,8 +305,6 @@ Step::Status StepGenerateXml::process() {
 
 Step::Status StepGenerateXml::undo() {
   bs::error_code error;
-  if (fs::exists(icon_path_))
-    fs::remove_all(icon_path_, error);
   if (fs::exists(context_->xml_path.get()))
     fs::remove_all(context_->xml_path.get(), error);
   return Status::OK;
index c6ae644..19b46f0 100644 (file)
@@ -6,8 +6,6 @@
 #ifndef  COMMON_STEP_STEP_GENERATE_XML_H_
 #define  COMMON_STEP_STEP_GENERATE_XML_H_
 
-
-#include <boost/filesystem/path.hpp>
 #include <libxml/xmlwriter.h>
 
 #include "common/context_installer.h"
@@ -33,8 +31,6 @@ class StepGenerateXml : public Step {
   template <typename T>
   Step::Status GenerateApplicationCommonXml(T* app, xmlTextWriterPtr writer);
 
-  boost::filesystem::path icon_path_;
-
   SCOPE_LOG_TAG(GenerateXML)
 };
 
index 50166bd..96b21e0 100644 (file)
@@ -8,6 +8,7 @@
 #include "common/step/step_configure.h"
 #include "common/step/step_backup_icons.h"
 #include "common/step/step_backup_manifest.h"
+#include "common/step/step_create_icons.h"
 #include "common/step/step_copy.h"
 #include "common/step/step_copy_backup.h"
 #include "common/step/step_copy_storage_directories.h"
@@ -101,6 +102,7 @@ int Task::Install() {
   ai.AddStep<ci::filesystem::StepCopy>();
   ai.AddStep<ci::filesystem::StepCreateStorageDirectories>();
   ai.AddStep<tpk::filesystem::StepCreateSymbolicLink>();
+  ai.AddStep<ci::filesystem::StepCreateIcons>();
   ai.AddStep<ci::security::StepRegisterSecurity>();
   ai.AddStep<tpk::filesystem::StepCopyManifestXml>();
   ai.AddStep<ci::pkgmgr::StepRegisterApplication>();
@@ -122,6 +124,7 @@ int Task::Update() {
   ai.AddStep<ci::backup::StepCopyBackup>();
   ai.AddStep<ci::filesystem::StepCopyStorageDirectories>();
   ai.AddStep<tpk::filesystem::StepCreateSymbolicLink>();
+  ai.AddStep<ci::filesystem::StepCreateIcons>();
   ai.AddStep<ci::security::StepUpdateSecurity>();
   ai.AddStep<tpk::filesystem::StepCopyManifestXml>();
   ai.AddStep<ci::pkgmgr::StepUpdateApplication>();
index 98e2a92..92a359a 100644 (file)
@@ -6,6 +6,7 @@ SET(SRCS
   step/step_parse.cc
   step/step_rds_parse.cc
   step/step_rds_modify.cc
+  step/step_wgt_create_icons.cc
   step/step_wgt_create_storage_directories.cc
   step/step_wgt_copy_storage_directories.cc
   step/step_wgt_resource_directory.cc
diff --git a/src/wgt/step/step_wgt_create_icons.cc b/src/wgt/step/step_wgt_create_icons.cc
new file mode 100644 (file)
index 0000000..f62588c
--- /dev/null
@@ -0,0 +1,22 @@
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#include "wgt/step/step_wgt_create_icons.h"
+
+namespace {
+
+const char kResWgt[] = "res/wgt";
+
+}
+
+namespace wgt {
+namespace filesystem {
+
+boost::filesystem::path StepWgtCreateIcons::GetIconRoot() const {
+  return context_->pkg_path.get() / kResWgt;
+}
+
+}  // namespace filesystem
+}  // namespace wgt
+
diff --git a/src/wgt/step/step_wgt_create_icons.h b/src/wgt/step/step_wgt_create_icons.h
new file mode 100644 (file)
index 0000000..e032148
--- /dev/null
@@ -0,0 +1,27 @@
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef WGT_STEP_STEP_WGT_CREATE_ICONS_H_
+#define WGT_STEP_STEP_WGT_CREATE_ICONS_H_
+
+#include "common/utils/logging.h"
+#include "common/step/step_create_icons.h"
+
+namespace wgt {
+namespace filesystem {
+
+class StepWgtCreateIcons
+    : public common_installer::filesystem::StepCreateIcons {
+ public:
+  using StepCreateIcons::StepCreateIcons;
+
+  boost::filesystem::path GetIconRoot() const override;
+
+  SCOPE_LOG_TAG(WgtCreateIcons)
+};
+
+}  // namespace filesystem
+}  // namespace wgt
+
+#endif  // WGT_STEP_STEP_WGT_CREATE_ICONS_H_
index 9bef1a2..ca667c3 100644 (file)
@@ -33,6 +33,7 @@
 #include "wgt/step/step_parse.h"
 #include "wgt/step/step_rds_parse.h"
 #include "wgt/step/step_rds_modify.h"
+#include "wgt/step/step_wgt_create_icons.h"
 #include "wgt/step/step_wgt_create_storage_directories.h"
 #include "wgt/step/step_wgt_copy_storage_directories.h"
 #include "wgt/step/step_wgt_resource_directory.h"
@@ -63,6 +64,7 @@ int main(int argc, char** argv) {
       installer.AddStep<wgt::filesystem::StepWgtCreateStorageDirectories>();
       installer.AddStep<ci::filesystem::StepCreateStorageDirectories>();
       installer.AddStep<wgt::filesystem::StepCreateSymbolicLink>();
+      installer.AddStep<wgt::filesystem::StepWgtCreateIcons>();
       installer.AddStep<ci::pkgmgr::StepGenerateXml>();
       installer.AddStep<ci::pkgmgr::StepRegisterApplication>();
       installer.AddStep<ci::security::StepRegisterSecurity>();
@@ -82,6 +84,7 @@ int main(int argc, char** argv) {
       installer.AddStep<ci::backup::StepCopyBackup>();
       installer.AddStep<wgt::filesystem::StepWgtCopyStorageDirectories>();
       installer.AddStep<wgt::filesystem::StepCreateSymbolicLink>();
+      installer.AddStep<wgt::filesystem::StepWgtCreateIcons>();
       installer.AddStep<ci::security::StepUpdateSecurity>();
       installer.AddStep<ci::pkgmgr::StepGenerateXml>();
       installer.AddStep<ci::pkgmgr::StepUpdateApplication>();