1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-16 17:02:37 +01:00

Codechange: Introduce FioRemove() to remove files. (#12491)

New function FioRemove() handles OTTD2FS conversion, and uses std::filesystem::remove instead of unlink, all in one location.
This commit is contained in:
Peter Nelson
2024-04-14 23:43:50 +01:00
committed by GitHub
parent 29e932e087
commit 4eaeccdaeb
7 changed files with 25 additions and 14 deletions

View File

@@ -368,6 +368,23 @@ void FioCreateDirectory(const std::string &name)
#endif
}
/**
* Remove a file.
* @param filename Filename to remove.
* @return true iff the file was removed.
*/
bool FioRemove(const std::string &filename)
{
std::filesystem::path path = OTTD2FS(filename);
std::error_code error_code;
std::filesystem::remove(path, error_code);
if (error_code) {
Debug(misc, 0, "Removing {} failed: {}", filename, error_code.message());
return false;
}
return true;
}
/**
* Appends, if necessary, the path separator character to the end of the string.
* It does not add the path separator to zero-sized strings.