#include "tpk/step/step_tpk_patch_icons.h"
-#include <boost/filesystem/path.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/system/error_code.hpp>
#include <common/utils/file_util.h>
namespace tpk {
namespace filesystem {
+common_installer::Step::Status StepTpkPatchIcons::ProcessIconOutsidePackage(
+ const bf::path& common_icon_location, const bf::path& icon_text,
+ application_x* app, icon_x* icon) {
+ bf::path destination = common_icon_location / app->appid;
+ if (!icon_text.extension().empty()) {
+ destination += icon_text.extension();
+ } else {
+ destination += ".png";
+ }
+ if (!common_installer::CopyFile(icon_text, destination)) {
+ return Status::ICON_ERROR;
+ }
+ free(const_cast<char*>(icon->text));
+ icon->text = strdup(destination.c_str());
+ return Status::OK;
+}
+
+common_installer::Step::Status StepTpkPatchIcons::FixIconLocation(
+ const bf::path& icon_text) {
+ bf::path source = LocateIcon(icon_text.filename(),
+ context_->pkgid.get(),
+ context_->root_application_path.get(),
+ context_->uid.get());
+ if (!source.empty()) {
+ LOG(DEBUG) << "Fix location of icon: " << source << " to: " << icon_text;
+ if (!common_installer::CopyFile(source, icon_text)) {
+ return Status::ICON_ERROR;
+ }
+ }
+ return Status::OK;
+}
+
common_installer::Step::Status StepTpkPatchIcons::process() {
bf::path common_icon_location = context_->pkg_path.get() / "shared" / "res";
bs::error_code error;
bf::create_directories(common_icon_location, error);
for (application_x* app :
GListRange<application_x*>(context_->manifest_data.get()->application)) {
- if (strcmp(app->type, "capp") != 0)
+ if (strcmp(app->type, "capp") != 0 && strcmp(app->type, "jsapp") != 0)
continue;
if (app->icon) {
icon_x* icon = reinterpret_cast<icon_x*>(app->icon->data);
bf::path icon_text(icon->text);
- if (!bf::exists(icon->text)) {
- bf::path source = LocateIcon(icon_text.filename(),
- context_->pkgid.get(),
- context_->root_application_path.get(),
- context_->uid.get());
- if (!source.empty()) {
- LOG(DEBUG) << "Fix location of icon: " << source << " to: "
- << icon_text;
- if (!common_installer::CopyFile(source, icon_text)) {
- return Status::ICON_ERROR;
- }
+ if (icon_text.parent_path() != common_icon_location) {
+ // if location of icon was absolute and icon is not in common icon
+ // location, we just need to copy it and replace icon->text to insert
+ // correct information into database
+ Status status = ProcessIconOutsidePackage(common_icon_location,
+ icon_text, app, icon);
+ if (status != Status::OK)
+ return status;
+ } else {
+ // look for icon in different location if it doesn't exist
+ if (!bf::exists(icon->text)) {
+ Status status = FixIconLocation(icon_text);
+ if (status != Status::OK)
+ return status;
}
}
}
#ifndef TPK_STEP_STEP_TPK_PATCH_ICONS_H_
#define TPK_STEP_STEP_TPK_PATCH_ICONS_H_
+#include <boost/filesystem/path.hpp>
+
#include <common/step/step.h>
#include <manifest_parser/utils/logging.h>
Status undo() override { return Status::OK; }
Status precheck() override { return Status::OK; }
+ private:
+ Status ProcessIconOutsidePackage(
+ const boost::filesystem::path& common_icon_location,
+ const boost::filesystem::path& icon_text,
+ application_x* app, icon_x* icon);
+ Status FixIconLocation(const boost::filesystem::path& icon_text);
+
SCOPE_LOG_TAG(TpkPatchIcons)
};
AddStep<ci::tpk::StepParsePreload>();
AddStep<ci::security::StepPrivilegeCompatibility>();
AddStep<tpk::security::StepCheckTpkBackgroundCategory>();
+ AddStep<tpk::filesystem::StepTpkPatchIcons>();
AddStep<ci::security::StepRollbackInstallationSecurity>();
AddStep<ci::security::StepRegisterSecurity>();
AddStep<ci::pkgmgr::StepRegisterApplication>();
AddStep<ci::tpk::StepParsePreload>();
AddStep<ci::security::StepPrivilegeCompatibility>();
AddStep<tpk::security::StepCheckTpkBackgroundCategory>();
+ AddStep<tpk::filesystem::StepTpkPatchIcons>();
AddStep<ci::pkgmgr::StepKillApps>();
AddStep<ci::security::StepRollbackInstallationSecurity>();
AddStep<ci::security::StepRegisterSecurity>();