1 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache 2.0 license that can be
3 // found in the LICENSE file.
5 #include "wgt/wgt_app_query_interface.h"
10 #include <boost/filesystem/operations.hpp>
11 #include <boost/filesystem/path.hpp>
12 #include <boost/system/error_code.hpp>
14 #include <common/pkgmgr_registration.h>
15 #include <common/request.h>
16 #include <common/utils/file_util.h>
18 #include <manifest_handlers/application_manifest_constants.h>
19 #include <manifest_handlers/tizen_application_handler.h>
20 #include <manifest_handlers/widget_handler.h>
21 #include <manifest_parser/manifest_parser.h>
22 #include <manifest_parser/utils/logging.h>
29 namespace bf = boost::filesystem;
30 namespace bs = boost::system;
31 namespace ci = common_installer;
35 const char kHybridConfigLocation[] = "res/wgt/config.xml";
36 const char kTizenManifestLocation[] = "tizen-manifest.xml";
38 std::string GetInstallationRequestInfo(int argc, char** argv) {
40 for (int i = 0; i < argc; ++i) {
41 if (!strcmp(argv[i], "-i") || !strcmp(argv[i], "-r") ||
42 !strcmp(argv[i], "-d") || !strcmp(argv[i], "-b")) {
52 std::string GetPkgIdFromPath(const std::string& path) {
53 if (!bf::exists(path))
55 bf::path tmp_path = common_installer::GenerateTmpDir("/tmp");
57 bf::create_directories(tmp_path, code);
60 if (!common_installer::ExtractToTmpDir(path.c_str(), tmp_path,
62 bf::remove_all(tmp_path, code);
65 bf::path config_path = tmp_path / "config.xml";
66 std::vector<parser::ManifestHandler*> handlers = {
67 new wgt::parse::WidgetHandler(),
68 new wgt::parse::TizenApplicationHandler()
70 std::unique_ptr<parser::ManifestHandlerRegistry> registry(
71 new parser::ManifestHandlerRegistry(handlers));
72 std::unique_ptr<parser::ManifestParser> parser(
73 new parser::ManifestParser(std::move(registry)));
74 if (!parser->ParseManifest(config_path)) {
75 bf::remove_all(tmp_path, code);
78 auto info = std::static_pointer_cast<const wgt::parse::TizenApplicationInfo>(
79 parser->GetManifestData(
80 wgt::application_widget_keys::kTizenApplicationKey));
82 bf::remove_all(tmp_path, code);
85 std::string pkg_id = info->package();
87 bf::remove_all(tmp_path, code);
95 bool WgtAppQueryInterface::IsAppInstalledByArgv(int argc, char** argv) {
96 std::string path = GetInstallationRequestInfo(argc, argv);
99 std::string pkg_id = GetPkgIdFromPath(path);
102 return ci::IsPackageInstalled(pkg_id, ci::GetRequestMode());
105 bool WgtAppQueryInterface::IsHybridApplication(int argc, char** argv) {
106 std::string arg = GetInstallationRequestInfo(argc, argv);
107 if (ci::IsPackageInstalled(arg, ci::GetRequestMode())) {
108 bf::path package_directory(ci::GetRootAppPath());
109 if (bf::exists(package_directory / kTizenManifestLocation) &&
110 bf::exists(package_directory / kHybridConfigLocation))
113 bool tizen_manifest_found = false;
114 bool config_xml_found = false;
115 if (!ci::CheckPathInZipArchive(arg.c_str(), kTizenManifestLocation,
116 &tizen_manifest_found))
118 if (!ci::CheckPathInZipArchive(arg.c_str(), kHybridConfigLocation,
121 if (tizen_manifest_found && config_xml_found)