Skip to content

Commit

Permalink
Use util::filepath utility
Browse files Browse the repository at this point in the history
  • Loading branch information
panos-lunarg committed Oct 21, 2024
1 parent 3e27aac commit 890f135
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
9 changes: 3 additions & 6 deletions framework/decode/file_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand Down
16 changes: 1 addition & 15 deletions framework/encode/capture_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
16 changes: 16 additions & 0 deletions framework/util/file_path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down
3 changes: 3 additions & 0 deletions framework/util/file_path.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 890f135

Please sign in to comment.