diff --git a/common/FileSystem.cpp b/common/FileSystem.cpp index b25545aa19..6ff7a9b31c 100644 --- a/common/FileSystem.cpp +++ b/common/FileSystem.cpp @@ -565,6 +565,15 @@ bool FileSystem::WriteFileToString(const char* filename, const std::string_view& return true; } +bool FileSystem::EnsureDirectoryExists(const char* path, bool recursive) +{ + if (FileSystem::DirectoryExists(path)) + return true; + + // if it fails to create, we're not going to be able to use it anyway + return FileSystem::CreateDirectoryPath(path, recursive); +} + #ifdef _WIN32 static u32 TranslateWin32Attributes(u32 Win32Attributes) diff --git a/common/FileSystem.h b/common/FileSystem.h index faee949fa1..44e7c40400 100644 --- a/common/FileSystem.h +++ b/common/FileSystem.h @@ -150,6 +150,10 @@ namespace FileSystem /// if they do not exist. bool CreateDirectoryPath(const char* path, bool recursive); + /// Creates a directory if it doesn't already exist. + /// Returns false if it does not exist and creation failed. + bool EnsureDirectoryExists(const char* path, bool recursive); + /// Returns the path to the current executable. std::string GetProgramPath();