From: Lukasz Wysocki Date: Fri, 8 Jan 2016 11:58:21 +0000 (+0100) Subject: Icons paths parametrization X-Git-Tag: accepted/tizen/mobile/20160115.010734^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fc0cf44be2c1aed40863503e7b48f4705ded223a;p=platform%2Fcore%2Fappfw%2Fapp-installers.git Icons paths parametrization This change is required to allow temporary copy icon into two destinations in Web apps. Associated chages: - https://review.tizen.org/gerrit/#/c/56489/ Change-Id: Id4a02ad34bbb3b8f58cdd229c63562442e178019 --- diff --git a/src/common/step/step_backup_icons.cc b/src/common/step/step_backup_icons.cc index 559fd58..717ff0a 100644 --- a/src/common/step/step_backup_icons.cc +++ b/src/common/step/step_backup_icons.cc @@ -20,25 +20,49 @@ namespace common_installer { namespace backup { Step::Status StepBackupIcons::process() { + std::vector paths { getIconPath(context_->uid.get()) }; + return MoveIcons(paths); +} + +Step::Status StepBackupIcons::clean() { + RemoveBackupIcons(); + LOG(DEBUG) << "Icons backup removed"; + return Status::OK; +} + +Step::Status StepBackupIcons::undo() { + for (auto& pair : icons_) { + if (!MoveFile(pair.second, pair.first)) { + LOG(ERROR) << "Cannot revert icon from backup: " << pair.first; + return Status::ICON_ERROR; + } + } + LOG(DEBUG) << "Icons reverted from backup"; + return Status::OK; +} + +Step::Status StepBackupIcons::MoveIcons( + const std::vector& sources) { // gather icon info for (application_x* app : GListRange( context_->old_manifest_data.get()->application)) { - bf::path app_icon = bf::path(getIconPath(context_->uid.get())) - / bf::path(app->appid); - if (app->icon) { - icon_x* icon = reinterpret_cast(app->icon->data); - if (!icon->text) { - LOG(ERROR) << "Icon text is not set"; - return Status::ICON_NOT_FOUND; + for (const auto& source : sources) { + bf::path source_path = source / bf::path(app->appid); + if (app->icon) { + icon_x* icon = reinterpret_cast(app->icon->data); + if (!icon->text) { + LOG(ERROR) << "Icon text is not set"; + return Status::ICON_NOT_FOUND; + } + source_path += bf::path(icon->text).extension(); + } else { + source_path += ".png"; } - app_icon += bf::path(icon->text).extension(); - } else { - app_icon += ".png"; + bf::path icon_backup = GetBackupPathForIconFile(source_path); + if (bf::exists(source_path)) + icons_.emplace_back(source_path, icon_backup); } - bf::path icon_backup = GetBackupPathForIconFile(app_icon); - if (bf::exists(app_icon)) - icons_.emplace_back(app_icon, icon_backup); } // backup @@ -53,23 +77,6 @@ Step::Status StepBackupIcons::process() { return Status::OK; } -Step::Status StepBackupIcons::clean() { - RemoveBackupIcons(); - LOG(DEBUG) << "Icons backup removed"; - return Status::OK; -} - -Step::Status StepBackupIcons::undo() { - for (auto& pair : icons_) { - if (!MoveFile(pair.second, pair.first)) { - LOG(ERROR) << "Cannot revert icon from backup: " << pair.first; - return Status::ICON_ERROR; - } - } - LOG(DEBUG) << "Icons reverted from backup"; - return Status::OK; -} - void StepBackupIcons::RemoveBackupIcons() { for (auto& pair : icons_) { bs::error_code error; diff --git a/src/common/step/step_backup_icons.h b/src/common/step/step_backup_icons.h index 49de070..6096c4d 100644 --- a/src/common/step/step_backup_icons.h +++ b/src/common/step/step_backup_icons.h @@ -52,6 +52,9 @@ class StepBackupIcons : public Step { */ Status precheck() override { return Status::OK; } + protected: + Status MoveIcons(const std::vector& sources); + private: void RemoveBackupIcons(); diff --git a/src/common/step/step_create_icons.cc b/src/common/step/step_create_icons.cc index 5cf1159..1e77c2f 100644 --- a/src/common/step/step_create_icons.cc +++ b/src/common/step/step_create_icons.cc @@ -17,39 +17,52 @@ namespace common_installer { namespace filesystem { Step::Status StepCreateIcons::process() { - bf::path icons_directory(getIconPath(context_->uid.get())); - if (!bf::exists(icons_directory)) { + std::vector paths { getIconPath(context_->uid.get()) }; + return CopyIcons(paths); +} + +Step::Status StepCreateIcons::undo() { + for (auto& icon : icons_) { bs::error_code error; - bf::create_directories(icons_directory, error); - if (error) { - LOG(ERROR) << "Cannot create directory of application icons"; - return Status::ICON_ERROR; - } + bf::remove_all(icon, error); } + return Status::OK; +} +Step::Status StepCreateIcons::CopyIcons( + const std::vector& destinations) { for (application_x* app : - GListRange(context_->manifest_data.get()->application)) { + GListRange(context_->manifest_data.get()->application)) { if (GetAppTypeForIcons() != app->type) continue; - // TODO(t.iwanek): this is ignoring icon locale as well as other steps // icons should be localized if (app->icon) { icon_x* icon = reinterpret_cast(app->icon->data); bf::path source = GetIconRoot() / icon->text; if (bf::exists(source)) { - bf::path destination = icons_directory / app->appid; - if (source.has_extension()) - destination += source.extension(); - else - destination += ".png"; - bs::error_code error; - bf::copy_file(source, destination, error); - if (error) { - LOG(ERROR) << "Cannot create package icon: " << destination; - return Status::ICON_ERROR; + for (const auto& destination : destinations) { + bs::error_code error; + if (!bf::exists(destination)) { + bf::create_directories(destination, error); + if (error) { + LOG(ERROR) << "Cannot create directory of application icons: " + << destination; + return Status::ERROR; + } + } + bf::path destination_path = destination / app->appid; + if (source.has_extension()) + destination_path += source.extension(); + else + destination_path += ".png"; + bf::copy_file(source, destination_path, error); + if (error) { + LOG(ERROR) << "Cannot create package icon: " << destination_path; + return Status::ICON_ERROR; + } + icons_.push_back(destination_path); } - icons_.push_back(destination); } } } @@ -57,14 +70,6 @@ Step::Status StepCreateIcons::process() { return Status::OK; } -Step::Status StepCreateIcons::undo() { - for (auto& icon : icons_) { - bs::error_code error; - bf::remove_all(icon, error); - } - return Status::OK; -} - boost::filesystem::path StepCreateIcons::GetIconRoot() const { // TODO(t.iwanek): shared/res is location of icons for tpk return context_->pkg_path.get() / "shared" / "res"; diff --git a/src/common/step/step_create_icons.h b/src/common/step/step_create_icons.h index 5be6045..f5aa0f1 100644 --- a/src/common/step/step_create_icons.h +++ b/src/common/step/step_create_icons.h @@ -56,6 +56,7 @@ class StepCreateIcons : public Step { Status precheck() override { return Status::OK; } protected: + Status CopyIcons(const std::vector& destinations); virtual boost::filesystem::path GetIconRoot() const; virtual std::string GetAppTypeForIcons() const; diff --git a/src/common/step/step_recover_icons.cc b/src/common/step/step_recover_icons.cc index c698232..8093358 100644 --- a/src/common/step/step_recover_icons.cc +++ b/src/common/step/step_recover_icons.cc @@ -51,22 +51,28 @@ Step::Status StepRecoverIcons::RecoveryUpdate() { return Status::OK; } +std::vector StepRecoverIcons::GetIconsPaths() { + std::vector paths { getIconPath(context_->uid.get()) }; + return paths; +} + bool StepRecoverIcons::TryGatherIcons() { if (!context_->manifest_data.get()) return false; for (application_x* app : GListRange(context_->manifest_data.get()->application)) { - bf::path app_icon = bf::path(getIconPath(context_->uid.get())) - / bf::path(app->appid); - if (app->icon) { - icon_x* icon = reinterpret_cast(app->icon->data); - app_icon += bf::path(icon->text).extension(); - } else { - app_icon += ".png"; + for (const auto& path : GetIconsPaths()) { + bf::path icon_path = path / bf::path(app->appid); + if (app->icon) { + icon_x* icon = reinterpret_cast(app->icon->data); + icon_path += bf::path(icon->text).extension(); + } else { + icon_path += ".png"; + } + bf::path icon_backup = GetBackupPathForIconFile(icon_path); + if (bf::exists(icon_backup) || bf::exists(icon_path)) + icons_.emplace_back(icon_path, icon_backup); } - bf::path icon_backup = GetBackupPathForIconFile(app_icon); - if (bf::exists(icon_backup) || bf::exists(app_icon)) - icons_.emplace_back(app_icon, icon_backup); } return true; } diff --git a/src/common/step/step_recover_icons.h b/src/common/step/step_recover_icons.h index ce41987..337c9d6 100644 --- a/src/common/step/step_recover_icons.h +++ b/src/common/step/step_recover_icons.h @@ -33,6 +33,9 @@ class StepRecoverIcons : public recovery::StepRecovery { Status RecoveryNew() override; Status RecoveryUpdate() override; + protected: + virtual std::vector GetIconsPaths(); + private: bool TryGatherIcons();