diff --git a/src/FBX2glTF.cpp b/src/FBX2glTF.cpp index a689b93..2171c0a 100644 --- a/src/FBX2glTF.cpp +++ b/src/FBX2glTF.cpp @@ -264,7 +264,7 @@ int main(int argc, char* argv[]) { if (outputPath.empty()) { // if -o is not given, default to the basename of the .fbx - outputPath = "./" + FileUtils::GetFileBaseString(inputPath); + outputPath = "./" + FileUtils::GetFileBase(inputPath); } // the output folder in .gltf mode, not used for .glb std::string outputFolder; @@ -273,7 +273,7 @@ int main(int argc, char* argv[]) { std::string modelPath; if (gltfOptions.outputBinary) { const auto& suffix = FileUtils::GetFileSuffix(outputPath); - // add .glb to output path, unless it already ends in exactly that + // add .glb to output path, unless it already ends in exactly that if (suffix.has_value() && suffix.value() == "glb") { modelPath = outputPath; } else { @@ -282,7 +282,7 @@ int main(int argc, char* argv[]) { } else { // in gltf mode, we create a folder and write into that outputFolder = fmt::format("{}_out/", outputPath.c_str()); - modelPath = outputFolder + FileUtils::GetFileNameString(outputPath) + ".gltf"; + modelPath = outputFolder + FileUtils::GetFileName(outputPath) + ".gltf"; } if (!FileUtils::CreatePath(modelPath.c_str())) { fmt::fprintf(stderr, "ERROR: Failed to create folder: %s'\n", outputFolder.c_str()); diff --git a/src/fbx/Fbx2Raw.cpp b/src/fbx/Fbx2Raw.cpp index d99f2f7..6d78113 100644 --- a/src/fbx/Fbx2Raw.cpp +++ b/src/fbx/Fbx2Raw.cpp @@ -924,8 +924,7 @@ static std::string GetInferredFileName( return fbxFileName; } // Get the file name with file extension. - const std::string fileName = - FileUtils::GetFileNameString(FileUtils::GetCanonicalPath(fbxFileName)); + const std::string fileName = FileUtils::GetFileName(fbxFileName); // Try to find a match with extension. for (const auto& file : directoryFileList) { @@ -935,12 +934,12 @@ static std::string GetInferredFileName( } // Get the file name without file extension. - const std::string fileBase = FileUtils::GetFileBaseString(fileName); + const std::string fileBase = FileUtils::GetFileBase(fileName); // Try to find a match without file extension. for (const auto& file : directoryFileList) { // If the two extension-less base names match. - if (StringUtils::CompareNoCase(fileBase, FileUtils::GetFileBaseString(file)) == 0) { + if (StringUtils::CompareNoCase(fileBase, FileUtils::GetFileBase(file)) == 0) { // Return the name with extension of the file in the directory. return std::string(directory) + file; } @@ -964,10 +963,10 @@ static void FindFbxTextures( const std::set& extensions, std::map& textureLocations) { // Get the folder the FBX file is in. - const std::string folder = FileUtils::GetFolderString(fbxFileName); + const std::string folder = FileUtils::getFolder(fbxFileName); // Check if there is a filename.fbm folder to which embedded textures were extracted. - const std::string fbmFolderName = folder + FileUtils::GetFileBaseString(fbxFileName) + ".fbm/"; + const std::string fbmFolderName = folder + FileUtils::GetFileBase(fbxFileName) + ".fbm/"; // Search either in the folder with embedded textures or in the same folder as the FBX file. const std::string searchFolder = FileUtils::FolderExists(fbmFolderName) ? fbmFolderName : folder; diff --git a/src/gltf/TextureBuilder.cpp b/src/gltf/TextureBuilder.cpp index 2e8105e..c09393c 100644 --- a/src/gltf/TextureBuilder.cpp +++ b/src/gltf/TextureBuilder.cpp @@ -49,7 +49,7 @@ std::shared_ptr TextureBuilder::combine( if (rawTexIx >= 0) { const RawTexture& rawTex = raw.GetTexture(rawTexIx); const std::string& fileLoc = rawTex.fileLocation; - const std::string& name = FileUtils::GetFileBaseString(FileUtils::GetFileNameString(fileLoc)); + const std::string& name = FileUtils::GetFileBase(FileUtils::GetFileName(fileLoc)); if (!fileLoc.empty()) { info.pixels = stbi_load(fileLoc.c_str(), &info.width, &info.height, &info.channels, 0); if (!info.pixels) { @@ -179,8 +179,8 @@ std::shared_ptr TextureBuilder::simple(int rawTexIndex, const std:: } const RawTexture& rawTexture = raw.GetTexture(rawTexIndex); - const std::string textureName = FileUtils::GetFileBaseString(rawTexture.name); - const std::string relativeFilename = FileUtils::GetFileNameString(rawTexture.fileLocation); + const std::string textureName = FileUtils::GetFileBase(rawTexture.name); + const std::string relativeFilename = FileUtils::GetFileName(rawTexture.fileLocation); ImageData* image = nullptr; if (options.outputBinary) { @@ -202,7 +202,7 @@ std::shared_ptr TextureBuilder::simple(int rawTexIndex, const std:: } else if (!relativeFilename.empty()) { image = new ImageData(relativeFilename, relativeFilename); - std::string outputPath = FileUtils::GetCanonicalPath(outputFolder + "/" + relativeFilename); + std::string outputPath = outputFolder + "/" + relativeFilename; if (FileUtils::CopyFile(rawTexture.fileLocation, outputPath, true)) { if (verboseOutput) { fmt::printf("Copied texture '%s' to output folder: %s\n", textureName, outputPath); diff --git a/src/utils/File_Utils.hpp b/src/utils/File_Utils.hpp index 363115e..dbf53bb 100644 --- a/src/utils/File_Utils.hpp +++ b/src/utils/File_Utils.hpp @@ -46,24 +46,20 @@ inline bool FolderExists(const std::string& folderPath) { return std::filesystem::exists(folderPath) && std::filesystem::is_directory(folderPath); } -inline std::string GetFolderString(const std::string& path) { +inline std::string getFolder(const std::string& path) { return std::filesystem::path(path).parent_path().string(); } -inline std::string GetCanonicalPath(const std::string& path) { - return std::filesystem::canonical(path).string(); +inline std::string GetFileName(const std::string& path) { + return std::filesystem::path(path).filename().string(); } -inline std::string GetFileNameString(const std::string& path) { - return std::filesystem::canonical(path).filename().string(); -} - -inline std::string GetFileBaseString(const std::string& path) { - return std::filesystem::canonical(path).stem().string(); +inline std::string GetFileBase(const std::string& path) { + return std::filesystem::path(path).stem().string(); } inline std::optional GetFileSuffix(const std::string& path) { - const auto& extension = std::filesystem::canonical(path).extension(); + const auto& extension = std::filesystem::path(path).extension(); if (extension.empty()) { return std::nullopt; }