mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: Simplify FioCreateDirectory.
`std::filesystem` provides `create_directories()` as a cross-platform way to create a directory tree.
This commit is contained in:
parent
6458980413
commit
5a523cf212
|
@ -348,24 +348,9 @@ FILE *FioFOpenFile(const std::string &filename, const char *mode, Subdirectory s
|
||||||
*/
|
*/
|
||||||
void FioCreateDirectory(const std::string &name)
|
void FioCreateDirectory(const std::string &name)
|
||||||
{
|
{
|
||||||
auto p = name.find_last_of(PATHSEPCHAR);
|
/* Ignore directory creation errors; they'll surface later on. */
|
||||||
if (p != std::string::npos) {
|
std::error_code error_code;
|
||||||
std::string dirname = name.substr(0, p);
|
std::filesystem::create_directories(OTTD2FS(name), error_code);
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue