From dd3b8ac0801d854f4fa896453a4f8afb7de9f978 Mon Sep 17 00:00:00 2001 From: "j-h.choi" Date: Mon, 22 Jul 2019 13:20:13 +0900 Subject: Code refactoring --- NativeLauncher/tool/tac_common.cc | 93 +++++++-------------------------------- 1 file changed, 16 insertions(+), 77 deletions(-) (limited to 'NativeLauncher/tool/tac_common.cc') diff --git a/NativeLauncher/tool/tac_common.cc b/NativeLauncher/tool/tac_common.cc index 2927857..7b3dfeb 100644 --- a/NativeLauncher/tool/tac_common.cc +++ b/NativeLauncher/tool/tac_common.cc @@ -24,6 +24,7 @@ #include "ni_common.h" #include "tac_common.h" #include "db_manager.h" +#include "path_manager.h" #ifdef LOG_TAG #undef LOG_TAG @@ -67,70 +68,6 @@ void cleanupDirectory() removeNuget.clear(); } -void depsJsonParser(std::string pkgId, std::string depsJsonPath, std::string execName, bool isRestore) -{ - std::ifstream ifs(depsJsonPath); - Json::CharReaderBuilder reader; - Json::Value root; - std::string error; - if (ifs.is_open()) { - if (!Json::parseFromStream(reader, ifs, &root, &error)) { - _INFO("Failed to parse of deps.json"); - ifs.close(); - return; - } - const Json::Value runtimeTargetName = root["runtimeTarget"]["name"]; - const Json::Value nugetPackages = root["targets"][runtimeTargetName.asString().c_str()]; - for (auto& nuget : nugetPackages.getMemberNames()) { - if (strstr(nuget.c_str(), TIZEN_DOTNET_NUGET) != NULL || - strstr(nuget.c_str(), TIZEN_DOTNET_SDK_NUGET) != NULL || - strstr(nuget.c_str(), (execName.substr(0, execName.find(".Tizen."))).c_str()) != NULL || - strstr(nuget.c_str(), (execName.substr(0, execName.find(".dll"))).c_str()) != NULL) { - continue; - } else { - const Json::Value assemblies = nugetPackages[nuget.c_str()]["runtime"]; - if (assemblies != Json::nullValue) { - const Json::Value dependencies = nugetPackages[nuget.c_str()]["dependencies"]; - bool isDependency = false; - for (auto& dependency : dependencies.getMemberNames()) { - if (strstr(dependency.c_str(), TIZEN_DOTNET_NUGET) != NULL || - strstr(dependency.c_str(), NET_STANDARD_LIBRARY_NUGET) != NULL) { - continue; - } else { - isDependency = true; - } - } - if (!isDependency) { - _INFO("PackageId : [%s] / Nuget package : [%s]", pkgId.c_str(), nuget.c_str()); - std::string name = nuget.substr(0, nuget.find('/')); - std::string version = nuget.substr(nuget.rfind('/') + 1); - std::string sql = "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \ - "VALUES ('" + pkgId + "', '" + nuget + "', '" + name + "', '" + version + "');"; - if (isRestore) { - if (tac_db) { - dbInsert(tac_db, TAC_APP_LIST_RESTORE_DB, sql); - restoreNuget.push_back(concatPath(__TAC_DIR, name)); - } - } else { - std::string nugetPath = concatPath(__TAC_DIR, nuget); - if (bf::exists(nugetPath)) { - for (auto& assembly : assemblies.getMemberNames()) { - std::string assemblyName = assembly.substr(assembly.rfind('/') + 1); - std::string originPath = concatPath(nugetPath, assemblyName); - if (bf::exists(originPath)) { - enableNuget.push_back(originPath); - } - } - } - } - } - } - } - } - ifs.close(); - } -} - // callback function of "pkgmgrinfo_appinfo_metadata_filter_foreach" static int restoreDBCb(pkgmgrinfo_appinfo_h handle, void *userData) { @@ -160,11 +97,7 @@ static int restoreDBCb(pkgmgrinfo_appinfo_h handle, void *userData) } execName = std::string(exec).substr(std::string(exec).rfind('/') + 1); - std::string depsJsonName = execName.substr(0, execName.rfind(".dll")) + ".deps.json"; - std::string depsJsonPath = concatPath(rootPath, depsJsonName); - if (bf::exists(depsJsonPath)) { - depsJsonParser(pkgId, depsJsonPath, execName, true); - } + restoreNuget = depsJsonParser(pkgId, rootPath, execName, getTPA(), true, tac_db); return 0; } @@ -181,6 +114,11 @@ tac_error_e restoreTACDB() return TAC_ERROR_UNKNOWN; } + if (initializePathManager(std::string(), std::string(), std::string())) { + fprintf(stderr, "Fail to initialize PathManger"); + return TAC_ERROR_UNKNOWN; + } + tac_db = dbCreate(TAC_APP_LIST_RESTORE_DB); if (tac_db) { if (!dbOpen(tac_db, TAC_APP_LIST_RESTORE_DB)) { @@ -372,8 +310,8 @@ tac_error_e disableTACPackage(const std::string& pkgId) tac_error_e enableTACPackage(const std::string& pkgId) { - std::string pkgRoot; - if (getRootPath(pkgId, pkgRoot) < 0) { + std::string rootPath; + if (getRootPath(pkgId, rootPath) < 0) { return TAC_ERROR_INVALID_PACKAGE; } @@ -387,8 +325,13 @@ tac_error_e enableTACPackage(const std::string& pkgId) return TAC_ERROR_INVALID_PACKAGE; } + if (initializePathManager(std::string(), std::string(), std::string())) { + fprintf(stderr, "Fail to initialize PathManger"); + return TAC_ERROR_UNKNOWN; + } + if (!strcmp(metaValue.c_str(), "true")) { - std::string binDir = concatPath(pkgRoot, "bin"); + std::string binDir = concatPath(rootPath, "bin"); std::string tacDir = concatPath(binDir, TAC_SYMLINK_SUB_DIR); std::string binNIDir = concatPath(binDir, APP_NI_SUB_DIR); if (!bf::exists(tacDir)) { @@ -398,11 +341,7 @@ tac_error_e enableTACPackage(const std::string& pkgId) } updateAssemblyInfo(binDir.c_str(), tacDir.c_str()); - std::string depsJsonName = execName.substr(0, execName.rfind(".dll")) + ".deps.json"; - std::string depsJsonPath = concatPath(pkgRoot, depsJsonName); - if (bf::exists(depsJsonPath)) { - depsJsonParser(pkgId, depsJsonPath, execName, false); - } + enableNuget = depsJsonParser(pkgId, rootPath, execName, getTPA(), true); for (auto& originPath : enableNuget) { if (bf::exists(originPath)) { -- cgit v1.2.3