From 85bd8555c0377421003228350d7591df89e7e635 Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Fri, 24 Dec 2021 17:48:52 -0500 Subject: [PATCH] common: add some file-path helpers to `Path` ns --- common/Path.h | 5 +++++ common/PathUtils.cpp | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/common/Path.h b/common/Path.h index a6858dd710..90738b95ae 100644 --- a/common/Path.h +++ b/common/Path.h @@ -18,6 +18,10 @@ #include #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 diff --git a/common/PathUtils.cpp b/common/PathUtils.cpp index a95f30a2c6..083ec927df 100644 --- a/common/PathUtils.cpp +++ b/common/PathUtils.cpp @@ -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 +} \ No newline at end of file