From: j-h.choi Date: Wed, 9 Jun 2021 01:24:38 +0000 (+0900) Subject: Change the extension of a path or file X-Git-Tag: accepted/tizen/unified/20210623.125232~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9e7498640854cf8f9b30219179b1ccb589f94095;hp=b5b18d2a0819d7cd8d8b83f962f9b547a5abf52d;p=platform%2Fcore%2Fdotnet%2Flauncher.git Change the extension of a path or file Change-Id: I2b0f5d2c00d2f84b5e2af25102ba50d29b7bee74 --- diff --git a/NativeLauncher/inc/utils.h b/NativeLauncher/inc/utils.h index 505fba9..a6b1d2d 100644 --- a/NativeLauncher/inc/utils.h +++ b/NativeLauncher/inc/utils.h @@ -101,6 +101,15 @@ std::string getAppType(const std::string& pkgId); std::string getMetadataValue(const std::string& pkgId, const std::string& key); /** + * @brief change the extension of a path or file + * @param[in] source path or file + * @param[in] from extension + * @param[in] to extension + * @return std::string path or file with changed extension + */ +std::string changeExtension(const std::string& path, const std::string& from, const std::string& to); + +/** * @brief check the package is 'readonly' or not * @param[in] package id * @return bool package readonly value diff --git a/NativeLauncher/tool/ni_common.cc b/NativeLauncher/tool/ni_common.cc index c2d9c54..8302c77 100644 --- a/NativeLauncher/tool/ni_common.cc +++ b/NativeLauncher/tool/ni_common.cc @@ -613,14 +613,14 @@ ni_error_e createNIUnderDirs(const std::string& rootPaths, DWORD flags) } // if there is symlink and original file for native image, skip generation - std::string symNIPath = symPath.substr(0, symPath.rfind(".dll")) + ".ni.dll"; + std::string symNIPath = changeExtension(symPath, "dll", "ni.dll"); if (isFile(symNIPath)) { continue; } // if original native image not exist, generate native image std::string originPath = bf::read_symlink(symPath).string(); - std::string originNIPath = originPath.substr(0, originPath.rfind(".dll")) + ".ni.dll"; + std::string originNIPath = changeExtension(originPath, "dll", "ni.dll"); if (!isFile(originNIPath)) { if (!crossgen(originPath, path.c_str(), flags)) { waitInterval(); diff --git a/NativeLauncher/tool/tac_common.cc b/NativeLauncher/tool/tac_common.cc index 9335325..ca666f0 100644 --- a/NativeLauncher/tool/tac_common.cc +++ b/NativeLauncher/tool/tac_common.cc @@ -300,9 +300,9 @@ tac_error_e enableTACPackage(const std::string& pkgId) for (auto& originPath : enableNuget) { if (exist(originPath)) { std::string fileName = originPath.substr(originPath.rfind('/') + 1); - std::string NIFileName = fileName.substr(0, fileName.rfind(".dll")) + ".ni.dll"; + std::string NIFileName = changeExtension(fileName, "dll", "ni.dll"); if (exist(binNIDir)) { - std::string originNIPath = originPath.substr(0, originPath.rfind(".dll")) + ".ni.dll"; + std::string originNIPath = changeExtension(originPath, "dll", "ni.dll"); if (exist(originNIPath)) { bf::create_symlink(originNIPath, concatPath(tacDir, NIFileName)); fprintf(stdout, "%s symbolic link file generated successfully.\n", concatPath(tacDir, NIFileName).c_str()); @@ -341,7 +341,7 @@ tac_error_e enableTACPackage(const std::string& pkgId) std::vector depsJsonParser(const std::string& rootPath, const std::string& execName) { std::vector parserData; - std::string depsJsonName = execName.substr(0, execName.rfind(".dll")) + ".deps.json"; + std::string depsJsonName = changeExtension(execName, "dll", "deps.json"); std::string depsJsonPath = concatPath(rootPath, depsJsonName); try { if (exist(depsJsonPath)) { diff --git a/NativeLauncher/util/utils.cc b/NativeLauncher/util/utils.cc index 00cb0c8..6611f6e 100644 --- a/NativeLauncher/util/utils.cc +++ b/NativeLauncher/util/utils.cc @@ -293,6 +293,11 @@ std::string replaceAll(const std::string& str, const std::string& pattern, const return result; } +std::string changeExtension(const std::string& path, const std::string& from, const std::string& to) +{ + return path.substr(0, path.rfind(from)) + to; +} + bool isFile(const std::string& path) { struct stat sb;