1 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache-2.0 license that can be
3 // found in the LICENSE file.
5 #include "common/step/step_create_icons.h"
7 #include <boost/filesystem/operations.hpp>
8 #include <boost/system/error_code.hpp>
9 #include <pkgmgr-info.h>
11 #include "common/utils/glist_range.h"
13 namespace bf = boost::filesystem;
14 namespace bs = boost::system;
16 namespace common_installer {
17 namespace filesystem {
19 Step::Status StepCreateIcons::process() {
20 bf::path icons_directory(getIconPath(context_->uid.get()));
21 if (!bf::exists(icons_directory)) {
23 bf::create_directories(icons_directory, error);
25 LOG(ERROR) << "Cannot create directory of application icons";
30 for (application_x* app :
31 GListRange<application_x*>(context_->manifest_data.get()->application)) {
32 if (strcmp(app->component_type, "uiapp") != 0)
35 // TODO(t.iwanek): this is ignoring icon locale as well as other steps
36 // icons should be localized
38 icon_x* icon = reinterpret_cast<icon_x*>(app->icon->data);
39 bf::path source = GetIconRoot() / icon->text;
40 if (bf::exists(source)) {
41 bf::path destination = icons_directory / app->appid;
42 if (source.has_extension())
43 destination += source.extension();
45 destination += ".png";
47 bf::copy_file(source, destination, error);
49 LOG(ERROR) << "Cannot create package icon: " << destination;
52 icons_.push_back(destination);
56 LOG(DEBUG) << "Icon files created";
60 Step::Status StepCreateIcons::undo() {
61 for (auto& icon : icons_) {
63 bf::remove_all(icon, error);
68 boost::filesystem::path StepCreateIcons::GetIconRoot() const {
69 // TODO(t.iwanek): shared/res is location of icons for tpk
70 return context_->pkg_path.get() / "shared" / "res";
73 } // namespace filesystem
74 } // namespace common_installer