namespace backup {
Step::Status StepBackupIcons::process() {
+ std::vector<bf::path> 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<boost::filesystem::path>& sources) {
// gather icon info
for (application_x* app :
GListRange<application_x*>(
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<icon_x*>(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<icon_x*>(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
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;
*/
Status precheck() override { return Status::OK; }
+ protected:
+ Status MoveIcons(const std::vector<boost::filesystem::path>& sources);
+
private:
void RemoveBackupIcons();
namespace filesystem {
Step::Status StepCreateIcons::process() {
- bf::path icons_directory(getIconPath(context_->uid.get()));
- if (!bf::exists(icons_directory)) {
+ std::vector<bf::path> 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<bf::path>& destinations) {
for (application_x* app :
- GListRange<application_x*>(context_->manifest_data.get()->application)) {
+ GListRange<application_x*>(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<icon_x*>(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);
}
}
}
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";
Status precheck() override { return Status::OK; }
protected:
+ Status CopyIcons(const std::vector<boost::filesystem::path>& destinations);
virtual boost::filesystem::path GetIconRoot() const;
virtual std::string GetAppTypeForIcons() const;
return Status::OK;
}
+std::vector<boost::filesystem::path> StepRecoverIcons::GetIconsPaths() {
+ std::vector<bf::path> paths { getIconPath(context_->uid.get()) };
+ return paths;
+}
+
bool StepRecoverIcons::TryGatherIcons() {
if (!context_->manifest_data.get())
return false;
for (application_x* app :
GListRange<application_x*>(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<icon_x*>(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<icon_x*>(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;
}
Status RecoveryNew() override;
Status RecoveryUpdate() override;
+ protected:
+ virtual std::vector<boost::filesystem::path> GetIconsPaths();
+
private:
bool TryGatherIcons();