From: Tomasz Iwanek Date: Thu, 28 Jan 2016 14:54:56 +0000 (+0100) Subject: Icon fix X-Git-Tag: submit/devel/ivi/20160202.111127^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Fdevel%2Fivi;p=platform%2Fcore%2Fappfw%2Ftpk-backend.git Icon fix Application icon will be copied to shared/res/ if application->icon refers to icon from outside of package (some preloaded apps may declare absolute path of icon). Requires to be submitted with: - https://review.tizen.org/gerrit/#/c/58360/ Change-Id: I7cfc8726565a9fb7e65a2d2a3eefe40d20d1edb3 --- diff --git a/src/tpk/step/step_tpk_patch_icons.cc b/src/tpk/step/step_tpk_patch_icons.cc index 756ca71..39ddb1e 100644 --- a/src/tpk/step/step_tpk_patch_icons.cc +++ b/src/tpk/step/step_tpk_patch_icons.cc @@ -4,7 +4,6 @@ #include "tpk/step/step_tpk_patch_icons.h" -#include #include #include #include @@ -47,28 +46,63 @@ bf::path LocateIcon(const bf::path& filename, const std::string& pkgid, 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(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(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(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; } } } diff --git a/src/tpk/step/step_tpk_patch_icons.h b/src/tpk/step/step_tpk_patch_icons.h index 10fd3c2..556da10 100644 --- a/src/tpk/step/step_tpk_patch_icons.h +++ b/src/tpk/step/step_tpk_patch_icons.h @@ -5,6 +5,8 @@ #ifndef TPK_STEP_STEP_TPK_PATCH_ICONS_H_ #define TPK_STEP_STEP_TPK_PATCH_ICONS_H_ +#include + #include #include @@ -25,6 +27,13 @@ class StepTpkPatchIcons : public common_installer::Step { 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) }; diff --git a/src/tpk/tpk_installer.cc b/src/tpk/tpk_installer.cc index feb6735..97674fb 100644 --- a/src/tpk/tpk_installer.cc +++ b/src/tpk/tpk_installer.cc @@ -215,6 +215,7 @@ void TpkInstaller::ManifestDirectInstallSteps() { AddStep(); AddStep(); AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -228,6 +229,7 @@ void TpkInstaller::ManifestDirectUpdateSteps() { AddStep(); AddStep(); AddStep(); + AddStep(); AddStep(); AddStep(); AddStep();