diff --git a/src/openrct2/core/FileStream.hpp b/src/openrct2/core/FileStream.hpp index c683f84401..529fd41e90 100644 --- a/src/openrct2/core/FileStream.hpp +++ b/src/openrct2/core/FileStream.hpp @@ -12,6 +12,7 @@ #include "../common.h" #include "../localisation/Language.h" #include "IStream.hpp" +#include "Path.hpp" #include "String.hpp" #include @@ -81,6 +82,16 @@ namespace OpenRCT2 throw; } + // Make sure the directory exists before writing to a file inside it + if (_canWrite) + { + std::string directory = Path::GetDirectory(path); + if (!Path::DirectoryExists(directory)) + { + Path::CreateDirectory(directory); + } + } + #ifdef _WIN32 auto pathW = String::ToWideChar(path); auto modeW = String::ToWideChar(mode);