+
+//Parser the .deps.json file to get nuget information.
+std::vector<std::string> depsJsonParser(const std::string& rootPath, const std::string& execName)
+{
+ std::vector<std::string> parserData;
+ std::string depsJsonName = changeExtension(execName, "dll", "deps.json");
+ std::string depsJsonPath = concatPath(rootPath, depsJsonName);
+ try {
+ if (exist(depsJsonPath)) {
+ std::ifstream ifs(depsJsonPath);
+ Json::CharReaderBuilder reader;
+ Json::Value root;
+ std::string error;
+ if (ifs.is_open()) {
+ if (!Json::parseFromStream(reader, ifs, &root, &error)) {
+ _ERR("Failed to parse of deps.json");
+ ifs.close();
+ return parserData;
+ }
+ const Json::Value runtimeTargetName = root["runtimeTarget"]["name"];
+ const Json::Value nugetPackages = root["targets"][runtimeTargetName.asString().c_str()];
+ for (auto& nuget : nugetPackages.getMemberNames()) {
+ //Skip the nuget package related to Tizen
+ 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) {
+ const Json::Value assemblies = nugetPackages[nuget.c_str()]["runtime"];
+ if (assemblies != Json::nullValue) {
+ // handle assembly even though that is included in the TPA.
+ for (auto& assembly : assemblies.getMemberNames()) {
+ std::string assemblyName = assembly.substr(assembly.rfind('/') + 1);
+ parserData.push_back(nuget + ":" + assemblyName);
+ _INFO("Nuget : [%s] / Assembly : [%s]", nuget.c_str(), assemblyName.c_str());
+ }
+ }
+ }
+ }
+ ifs.close();
+ }
+ }
+ } catch (const Json::Exception& error) {
+ _ERR("Failed to parse Json: %s", error.what());
+ }
+ return parserData;
+}
+
+std::vector<std::string> getLibrariesInfo(const std::string& rootPath)
+{
+ std::vector<std::string> LibrariesInfo;
+ std::string binDir = concatPath(rootPath, "bin");
+ if (!exist(binDir))
+ return LibrariesInfo;
+
+ auto convert = [&LibrariesInfo](const std::string& filepath, const std::string& filename) {
+ if (filename.find(".so", filename.size() - 3) != std::string::npos || filepath.rfind(".so.") != std::string::npos) {
+ std::string buffer = SHA256(filepath);
+ LibrariesInfo.push_back(filepath + ":" + buffer);
+ _INFO("Library : [%s] / SHA256 : [%s]", filename.c_str(), buffer.c_str());
+ }
+ };
+ scanFilesInDirectory(binDir, convert, -1);
+
+ return LibrariesInfo;
+}
+
+// callback function of "pkgmgrinfo_appinfo_metadata_filter_foreach"
+static int tlc_restoreDBCb(pkgmgrinfo_appinfo_h handle, void *userData)
+{
+ char *pkgId = NULL;
+ char *root = NULL;
+ std::string rootPath;
+
+ int ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgId);
+ if (ret != PMINFO_R_OK) {
+ _SERR("Failed to get pkgid");
+ return -1;
+ }
+
+ ret = pkgmgrinfo_appinfo_get_root_path(handle, &root);
+ if (ret != PMINFO_R_OK) {
+ _SERR("Failed to get root path");
+ return -1;
+ }
+ rootPath = std::string(root);
+
+ for (auto& librarySha : getLibrariesInfo(rootPath)) {
+ std::string library = librarySha.substr(0, librarySha.find(':'));
+ if (exist(library)) {
+ std::string fileSha = library.substr(library.rfind('/') + 1) + ".." + librarySha.substr(librarySha.find(':') + 1);
+ char *sql = sqlite3_mprintf("INSERT INTO TLC (PKGID, LIBRARY) VALUES (%Q, %Q);", pkgId, fileSha.c_str());
+ insertDB(tlc_db, sql);
+ restore_library.push_back(fileSha);
+ sqlite3_free(sql);
+ }
+ }
+ return 0;
+}
+
+tac_error_e tlc_restoreDB()
+{
+ if (!removeFile(TLC_APP_LIST_RESTORE_DB)) {
+ _SERR("Failed to remove of %s", TLC_APP_LIST_RESTORE_DB);
+ return TAC_ERROR_UNKNOWN;
+ }
+
+ std::string dbRestoreJournal = TLC_APP_LIST_RESTORE_DB + std::string("-journal");
+ if (!removeFile(dbRestoreJournal)) {
+ _SERR("Failed to remove of %s", dbRestoreJournal.c_str());
+ return TAC_ERROR_UNKNOWN;
+ }
+
+ tlc_db = createDB(TLC_APP_LIST_RESTORE_DB, CREATE_TLC_DB_TABLE);
+ if (!tlc_db) {
+ _SERR("Sqlite create error");
+ return TAC_ERROR_UNKNOWN;
+ }
+ sqlite3_exec(tlc_db, "BEGIN;", NULL, NULL, NULL);
+
+ pkgmgrinfo_appinfo_metadata_filter_h handle;
+ int ret = pkgmgrinfo_appinfo_metadata_filter_create(&handle);
+ if (ret != PMINFO_R_OK) {
+ return TAC_ERROR_UNKNOWN;
+ }
+
+ ret = pkgmgrinfo_appinfo_metadata_filter_add(handle, TAC_METADATA_KEY, METADATA_VALUE_TRUE);
+ if (ret != PMINFO_R_OK) {
+ pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
+ return TAC_ERROR_UNKNOWN;
+ }
+
+ ret = pkgmgrMDFilterForeach(handle, tlc_restoreDBCb, NULL);
+ if (ret != 0) {
+ pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
+ return TAC_ERROR_UNKNOWN;
+ }
+
+ pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
+
+ if (tlc_db) {
+ closeDB(tlc_db);
+ tlc_db = NULL;
+ }
+
+ if (!copyFile(TLC_APP_LIST_RESTORE_DB, TLC_APP_LIST_DB)) {
+ _SERR("Failed to copy of %s", TLC_APP_LIST_DB);
+ return TAC_ERROR_UNKNOWN;
+ }
+ if (!removeFile(TLC_APP_LIST_RESTORE_DB)) {
+ _SERR("Failed to remove of %s", TLC_APP_LIST_RESTORE_DB);
+ return TAC_ERROR_UNKNOWN;
+ }
+
+ std::string dbJournal = TLC_APP_LIST_DB + std::string("-journal");
+ if (!copyFile(dbRestoreJournal, dbJournal)) {
+ _SERR("Failed to copy of %s", dbJournal.c_str());
+ return TAC_ERROR_UNKNOWN;
+ }
+ if (!removeFile(dbRestoreJournal)) {
+ _SERR("Failed to remove of %s", dbRestoreJournal.c_str());
+ return TAC_ERROR_UNKNOWN;
+ }
+
+ auto convert = [](const std::string& path, const std::string& filename) {
+ bool isExist = false;
+ for (auto& library : restore_library) {
+ if (!strcmp(filename.c_str(), library.c_str())) {
+ isExist = true;
+ break;
+ }
+ }
+ if (!isExist) {
+ if (!removeFile(path)) {
+ _ERR("Failed to remove of %s", path.c_str());
+ }
+ }
+ };
+
+ scanFilesInDirectory(concatPath(__DOTNET_DIR, TLC_LIBRARIES_DIR), convert, 0);
+
+ return TAC_ERROR_NONE;
+}