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 <pkgmgr-info.h>
10 #include <system_error>
12 #include "common/utils/file_util.h"
13 #include "common/utils/glist_range.h"
15 namespace fs = std::filesystem;
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 fs::path destination = extra_icon_path;
34 std::error_code error;
35 if (!fs::exists(destination)) {
36 fs::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 fs::path source(icon->text);
53 if (!fs::exists(source))
56 fs::path destination_path = destination / app->appid;
57 if (source.has_extension())
58 destination_path += source.extension();
60 destination_path += ".png";
61 fs::copy_file(source, destination_path,
62 fs::copy_options::overwrite_existing, 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