From 890f1358725e45ea202ad3e838ff0fdf6e2289a0 Mon Sep 17 00:00:00 2001 From: Panagiotis Apostolou Date: Mon, 21 Oct 2024 14:49:48 +0300 Subject: [PATCH] Use util::filepath utility --- framework/decode/file_processor.cpp | 9 +++------ framework/encode/capture_manager.cpp | 16 +--------------- framework/util/file_path.cpp | 16 ++++++++++++++++ framework/util/file_path.h | 3 +++ 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/framework/decode/file_processor.cpp b/framework/decode/file_processor.cpp index c1072d5d7d..a3bb8ca699 100644 --- a/framework/decode/file_processor.cpp +++ b/framework/decode/file_processor.cpp @@ -28,6 +28,7 @@ #include "format/format.h" #include "format/format_util.h" #include "util/compressor.h" +#include "util/file_path.h" #include "util/logging.h" #include "util/platform.h" @@ -96,11 +97,7 @@ bool FileProcessor::Initialize(const std::string& filename) // Find absolute path of capture file if (success) { - size_t last_slash_pos = filename.find_last_of("\\/"); - if (last_slash_pos != std::string::npos) - { - absolute_path_ = filename.substr(0, last_slash_pos + 1); - } + absolute_path_ = util::filepath::GetBasedir(filename); } return success; @@ -1984,7 +1981,7 @@ bool FileProcessor::ProcessMetaData(const format::BlockHeader& block_header, for success = success && ReadBytes(filename_c_str.data(), exec_from_file.filename_length); if (success) { - std::string filename = ApplyAbsolutePath(filename_c_str); + std::string filename = util::filepath::Join(absolute_path_, filename_c_str); // Check for self references if (!filename.compare(file_stack_.top().filename)) diff --git a/framework/encode/capture_manager.cpp b/framework/encode/capture_manager.cpp index ecc89a9811..40a217ce23 100644 --- a/framework/encode/capture_manager.cpp +++ b/framework/encode/capture_manager.cpp @@ -1081,21 +1081,7 @@ std::string CommonCaptureManager::CreateAssetFile() std::string CommonCaptureManager::CreateAssetFilename(const std::string& base_filename) const { - std::string asset_filename = base_filename; - - size_t dot_pos = base_filename.rfind('.'); - if (dot_pos != std::string::npos) - { - if (base_filename.substr(dot_pos) == ".gfxr") - { - asset_filename.replace(dot_pos, 16, "_asset_file.gfxa"); - } - } - else - { - asset_filename += std::string("_asset_file.gfxa"); - } - + std::string asset_filename = util::filepath::InsertFilenamePostfix(base_filename, "_asset_file", ".gfxa"); return asset_filename; } diff --git a/framework/util/file_path.cpp b/framework/util/file_path.cpp index 494d7dfa9c..166c0b325e 100644 --- a/framework/util/file_path.cpp +++ b/framework/util/file_path.cpp @@ -169,6 +169,22 @@ std::string InsertFilenamePostfix(const std::string& filename, const std::string return filename + postfix; } +std::string +InsertFilenamePostfix(const std::string& filename, const std::string& postfix, const std::string& new_extension) +{ + std::string file_part; + size_t sep_index = filename.rfind('.'); + + if (sep_index != std::string::npos) + { + file_part = filename.substr(0, sep_index); + + return file_part + postfix + new_extension; + } + + return filename + postfix; +} + std::string GetBasedir(const std::string& path) { std::string basedir = ""; diff --git a/framework/util/file_path.h b/framework/util/file_path.h index 12c228d55a..b556757a31 100644 --- a/framework/util/file_path.h +++ b/framework/util/file_path.h @@ -83,6 +83,9 @@ std::string Join(const std::string& lhs, const std::string& rhs); std::string InsertFilenamePostfix(const std::string& filename, const std::string& postfix); +std::string +InsertFilenamePostfix(const std::string& filename, const std::string& postfix, const std::string& new_extension); + std::string GetBasedir(const std::string& path); std::string GetFilename(const std::string& path);