1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-24 00:03:11 +01:00

Merge pull request #13280 from Broxzier/bugfix/filestream-file-nonexisting-folder

Fix crash when using a writable FileStream to a file in non-existing folder
This commit is contained in:
Tulio Leao
2020-10-25 14:46:48 -03:00
committed by GitHub
2 changed files with 14 additions and 1 deletions

View File

@@ -42,8 +42,10 @@
#endif
#include <SDL_opengl.h>
// 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

View File

@@ -12,6 +12,7 @@
#include "../common.h"
#include "../localisation/Language.h"
#include "IStream.hpp"
#include "Path.hpp"
#include "String.hpp"
#include <algorithm>
@@ -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);