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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user