FileSystem: Add ReplaceExtension() helper
This commit is contained in:
parent
6624df1e8c
commit
288b680e07
|
@ -3,8 +3,8 @@
|
||||||
#include "cd_subchannel_replacement.h"
|
#include "cd_subchannel_replacement.h"
|
||||||
#include "file_system.h"
|
#include "file_system.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include <libcue/libcue.h>
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <libcue/libcue.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
Log_SetChannel(CDImageCueSheet);
|
Log_SetChannel(CDImageCueSheet);
|
||||||
|
|
||||||
|
@ -32,17 +32,6 @@ CDImageCueSheet::~CDImageCueSheet()
|
||||||
cd_delete(m_cd);
|
cd_delete(m_cd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string ReplaceExtension(std::string_view path, std::string_view new_extension)
|
|
||||||
{
|
|
||||||
std::string_view::size_type pos = path.rfind('.');
|
|
||||||
if (pos == std::string::npos)
|
|
||||||
return std::string(path);
|
|
||||||
|
|
||||||
std::string ret(path, 0, pos + 1);
|
|
||||||
ret.append(new_extension);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CDImageCueSheet::OpenAndParse(const char* filename)
|
bool CDImageCueSheet::OpenAndParse(const char* filename)
|
||||||
{
|
{
|
||||||
std::FILE* cue_fp = FileSystem::OpenCFile(filename, "rb");
|
std::FILE* cue_fp = FileSystem::OpenCFile(filename, "rb");
|
||||||
|
@ -202,7 +191,7 @@ bool CDImageCueSheet::OpenAndParse(const char* filename)
|
||||||
|
|
||||||
m_lba_count = disc_lba;
|
m_lba_count = disc_lba;
|
||||||
|
|
||||||
m_sbi.LoadSBI(ReplaceExtension(filename, "sbi").c_str());
|
m_sbi.LoadSBI(FileSystem::ReplaceExtension(filename, "sbi").c_str());
|
||||||
|
|
||||||
return Seek(1, Position{0, 0, 0});
|
return Seek(1, Position{0, 0, 0});
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,6 +222,17 @@ void SanitizeFileName(String& Destination, bool StripSlashes /* = true */)
|
||||||
return SanitizeFileName(Destination, Destination, StripSlashes);
|
return SanitizeFileName(Destination, Destination, StripSlashes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string ReplaceExtension(std::string_view path, std::string_view new_extension)
|
||||||
|
{
|
||||||
|
std::string_view::size_type pos = path.rfind('.');
|
||||||
|
if (pos == std::string::npos)
|
||||||
|
return std::string(path);
|
||||||
|
|
||||||
|
std::string ret(path, 0, pos + 1);
|
||||||
|
ret.append(new_extension);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
std::string GetPathDirectory(const char* path)
|
std::string GetPathDirectory(const char* path)
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
|
|
@ -134,6 +134,9 @@ void SanitizeFileName(char* Destination, u32 cbDestination, const char* FileName
|
||||||
void SanitizeFileName(String& Destination, const char* FileName, bool StripSlashes = true);
|
void SanitizeFileName(String& Destination, const char* FileName, bool StripSlashes = true);
|
||||||
void SanitizeFileName(String& Destination, bool StripSlashes = true);
|
void SanitizeFileName(String& Destination, bool StripSlashes = true);
|
||||||
|
|
||||||
|
/// Replaces the extension of a filename with another.
|
||||||
|
std::string ReplaceExtension(std::string_view path, std::string_view new_extension);
|
||||||
|
|
||||||
/// Returns the directory component of a filename.
|
/// Returns the directory component of a filename.
|
||||||
std::string GetPathDirectory(const char* path);
|
std::string GetPathDirectory(const char* path);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue