namespace {
const char kVconfLanguageKey[] = "db/menu_widget/language";
-const std::vector<std::string> kEntries = {
- "shared/res",
- "tizen-manifest.xml"
-};
-
-bool ExtractPackageArchive(const char* file_path, const bf::path& tmp_dir) {
- for (auto& entry : kEntries) {
- if (!ci::ExtractToTmpDir(file_path, tmp_dir, entry)) {
- LOG(ERROR) << "Failed to extract";
- return false;
- }
+const char kManifestFileName[] = "tizen-manifest.xml";
+const char kSharedResDir[] = "shared/res";
+
+bool ExtractPackageArchive(const char* archive_path, const char* file,
+ const bf::path& tmp_dir) {
+ if (!ci::ExtractToTmpDir(archive_path, tmp_dir, file)) {
+ LOG(ERROR) << "Failed to extract";
+ return false;
}
return true;
}
bool ReadIcon(const bf::path& icon, const bf::path& tmp_dir,
package_manager_pkg_detail_info_t* info) {
- bf::path icon_path;
- if (icon.is_absolute())
- icon_path = icon;
- else
- icon_path = tmp_dir / "shared/res" / icon;
+ bf::path icon_path = tmp_dir / icon;
LOG(INFO) << "Icon file path: " << icon_path;
}
template <typename T>
-bool GetAppIcon(const tpk::parse::TPKConfigParser& parser,
- const std::string& key, const char* locale, const bf::path tmp_dir,
- package_manager_pkg_detail_info_t* info) {
+std::string GetAppIcon(const tpk::parse::TPKConfigParser& parser,
+ const std::string& key, const char* locale) {
auto apps = std::static_pointer_cast<const T>(parser.GetManifestData(key));
if (!apps)
- return false;
+ return {};
for (auto& icon : apps->items[0].app_icons.icons()) {
if (icon.lang().empty())
continue;
if (!strcmp(icon.lang().c_str(), locale))
- return ReadIcon(bf::path(icon.path()), tmp_dir, info);
+ return std::string(icon.path());
}
for (auto& icon : apps->items[0].app_icons.icons()) {
if (icon.lang().empty())
- return ReadIcon(bf::path(icon.path()), tmp_dir, info);
+ return std::string(icon.path());
}
- return false;
+ return {};
}
-bool GetIconInfo(const tpk::parse::TPKConfigParser& parser, const char* locale,
- const bf::path tmp_dir, package_manager_pkg_detail_info_t* info) {
+std::string GetIconInfo(const tpk::parse::TPKConfigParser& parser,
+ const char* locale) {
// get icon from ui application
- if (GetAppIcon<tpk::parse::UIApplicationInfoList>(parser,
- tpk::application_keys::kUIApplicationKey, locale, tmp_dir, info))
- return true;
- if (GetAppIcon<tpk::parse::ServiceApplicationInfoList>(parser,
- tpk::application_keys::kServiceApplicationKey, locale, tmp_dir, info))
- return true;
- if (GetAppIcon<tpk::parse::WidgetApplicationInfoList>(parser,
- tpk::application_keys::kWidgetApplicationKey, locale, tmp_dir, info))
- return true;
- if (GetAppIcon<tpk::parse::WatchApplicationInfoList>(parser,
- tpk::application_keys::kWatchApplicationKey, locale, tmp_dir, info))
- return true;
- return false;
+ std::string icon;
+ icon = GetAppIcon<tpk::parse::UIApplicationInfoList>(parser,
+ tpk::application_keys::kUIApplicationKey, locale);
+ if (!icon.empty())
+ return icon;
+ icon = GetAppIcon<tpk::parse::ServiceApplicationInfoList>(parser,
+ tpk::application_keys::kServiceApplicationKey, locale);
+ if (!icon.empty())
+ return icon;
+ icon = GetAppIcon<tpk::parse::WidgetApplicationInfoList>(parser,
+ tpk::application_keys::kWidgetApplicationKey, locale);
+ if (!icon.empty())
+ return icon;
+ icon = GetAppIcon<tpk::parse::WatchApplicationInfoList>(parser,
+ tpk::application_keys::kWatchApplicationKey, locale);
+ if (!icon.empty())
+ return icon;
+ return {};
}
} // namespace
if (!ci::CreateDir(tmp_dir))
return false;
LOG(DEBUG) << "Unpack at temporary dir: " << tmp_dir;
- if (!ExtractPackageArchive(file_path, tmp_dir))
+ if (!ExtractPackageArchive(file_path, kManifestFileName, tmp_dir))
return false;
tpk::parse::TPKConfigParser parser;
- bf::path manifest_path = tmp_dir / "tizen-manifest.xml";
+ bf::path manifest_path = tmp_dir / kManifestFileName;
if (!parser.ParseManifest(manifest_path)) {
LOG(ERROR) << "Failed to parse";
return false;
LOG(WARNING) << "Failed to get label info";
if (!GetDescriptionInfo(parser, locale, info))
LOG(WARNING) << "Failed to get description info";
- if (!GetIconInfo(parser, locale, tmp_dir, info))
- LOG(WARNING) << "Failed to get icon info";
+ std::string icon = GetIconInfo(parser, locale);
+ if (!icon.empty()) {
+ bf::path icon_path = bf::path(kSharedResDir) / icon;
+ if (!ExtractPackageArchive(file_path, icon_path.string().c_str(), tmp_dir))
+ return false;
+ if (!ReadIcon(icon_path, tmp_dir, info)) {
+ LOG(WARNING) << "Failed to get icon info";
+ return false;
+ }
+ }
free(locale);
bf::remove_all(tmp_dir);