From 5a523cf212f24677dea0630f4119c8b8e2369d80 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Thu, 18 Apr 2024 00:04:45 +0100 Subject: [PATCH] Codechange: Simplify FioCreateDirectory. `std::filesystem` provides `create_directories()` as a cross-platform way to create a directory tree. --- src/fileio.cpp | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/src/fileio.cpp b/src/fileio.cpp index 79f16392ab..bcd8a530e0 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -348,24 +348,9 @@ FILE *FioFOpenFile(const std::string &filename, const char *mode, Subdirectory s */ void FioCreateDirectory(const std::string &name) { - auto p = name.find_last_of(PATHSEPCHAR); - if (p != std::string::npos) { - std::string dirname = name.substr(0, p); - DIR *dir = ttd_opendir(dirname.c_str()); - if (dir == nullptr) { - FioCreateDirectory(dirname); // Try creating the parent directory, if we couldn't open it - } else { - closedir(dir); - } - } - - /* Ignore directory creation errors; they'll surface later on, and most - * of the time they are 'directory already exists' errors anyhow. */ -#if defined(_WIN32) - CreateDirectory(OTTD2FS(name).c_str(), nullptr); -#else - mkdir(OTTD2FS(name).c_str(), 0755); -#endif + /* Ignore directory creation errors; they'll surface later on. */ + std::error_code error_code; + std::filesystem::create_directories(OTTD2FS(name), error_code); } /**