From b54574fe19e2e496da77d5755ca123713d8859a0 Mon Sep 17 00:00:00 2001 From: Hielke Morsink Date: Thu, 8 Feb 2018 01:49:45 +0100 Subject: [PATCH 1/2] Ensure path exists for writable filestreams --- src/openrct2/core/FileStream.hpp | 11 +++++++++++ 1 file changed, 11 insertions(+) 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); From 22755857958a7fcc7375dda50db4cbbd3271f8a8 Mon Sep 17 00:00:00 2001 From: Hielke Morsink Date: Sat, 24 Oct 2020 17:30:20 +0200 Subject: [PATCH 2/2] Undef Windows.h macros that cause conflicts This caused errors on calls to Path::CreateDirectory in source files that include OpenGLAPI.h. --- src/openrct2-ui/drawing/engines/opengl/OpenGLAPI.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/openrct2-ui/drawing/engines/opengl/OpenGLAPI.h b/src/openrct2-ui/drawing/engines/opengl/OpenGLAPI.h index ded0e1dc03..dd9a3f1370 100644 --- a/src/openrct2-ui/drawing/engines/opengl/OpenGLAPI.h +++ b/src/openrct2-ui/drawing/engines/opengl/OpenGLAPI.h @@ -42,8 +42,10 @@ #endif #include -// OpenRCT2: SDL_opengl.h includes windows.h, which defines the CreateWindow macro and causes conflicts +// OpenRCT2: SDL_opengl.h includes windows.h, which defines some macros that can cause conflicts #undef CreateWindow +#undef CreateDirectory +#undef GetMessage #ifdef OPENGL_NO_LINK