common: add some file-path helpers to `Path` ns

This commit is contained in:
Tyler Wilding 2021-12-24 17:48:52 -05:00 committed by refractionpcsx2
parent 6920b4e366
commit 85bd8555c0
2 changed files with 14 additions and 1 deletions

View File

@ -18,6 +18,10 @@
#include <wx/filename.h>
#include "common/StringHelpers.h"
#include "ghc/filesystem.h"
namespace fs = ghc::filesystem;
#define g_MaxPath 255 // 255 is safer with antiquated Win32 ASCII APIs.
// --------------------------------------------------------------------------------------
@ -233,4 +237,5 @@ namespace Path
extern wxString GetDirectory(const wxString& src);
extern wxString GetFilenameWithoutExt(const wxString& src);
extern wxString GetRootDirectory(const wxString& src);
extern fs::path FromWxString(const wxString& path);
} // namespace Path

View File

@ -195,7 +195,6 @@ wxString Path::GetDirectory(const wxString& src)
return wxFileName(src).GetPath();
}
// returns the base/root directory of the given path.
// Example /this/that/something.txt -> dest == "/"
wxString Path::GetRootDirectory(const wxString& src)
@ -206,3 +205,12 @@ wxString Path::GetRootDirectory(const wxString& src)
else
return wxString(src.begin(), src.begin() + pos);
}
fs::path Path::FromWxString(const wxString& path)
{
#ifdef _WIN32
return fs::path(path.ToStdWstring());
#else
return fs::path(path.ToStdString());
#endif
}