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/filesystem/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/file_util.h"
12 #include "common/utils/glist_range.h"
14 namespace bf = boost::filesystem;
15 namespace bs = boost::system;
17 namespace common_installer {
18 namespace filesystem {
20 Step::Status StepCreateIcons::undo() {
21 for (auto& icon : icons_)
27 Step::Status StepCreateIcons::process() {
28 const char* extra_icon_path = getIconPath(context_->uid.get(),
29 context_->is_readonly_package.get());
33 bf::path destination = extra_icon_path;
35 if (!bf::exists(destination)) {
36 bf::create_directories(destination, error);
38 LOG(ERROR) << "Cannot create directory of application icons: "
44 for (application_x* app :
45 GListRange<application_x*>(context_->manifest_data.get()->application)) {
46 // TODO(t.iwanek): this ignores icon locale as well in same way as other
47 // steps -> icons should be localized
51 icon_x* icon = reinterpret_cast<icon_x*>(app->icon->data);
52 bf::path source(icon->text);
53 if (!bf::exists(source))
56 bf::path destination_path = destination / app->appid;
57 if (source.has_extension())
58 destination_path += source.extension();
60 destination_path += ".png";
61 bf::copy_file(source, destination_path,
62 bf::copy_option::overwrite_if_exists, error);
64 LOG(ERROR) << "Cannot create package icon: " << destination_path
65 << " , error: " << error;
66 return Status::ICON_ERROR;
68 icons_.push_back(destination_path);
70 LOG(DEBUG) << "Icon files created";
74 } // namespace filesystem
75 } // namespace common_installer