Return success boolean from FioRenameFile

This commit is contained in:
Jonathan G Rennison
2024-03-21 17:11:32 +00:00
parent 4d0af08aad
commit 5e87d95013
2 changed files with 10 additions and 4 deletions

View File

@@ -374,12 +374,18 @@ void FioCreateDirectory(const std::string &name)
#endif #endif
} }
void FioRenameFile(const std::string &oldname, const std::string &newname) /**
* Renames a file from oldname to newname.
* @param oldname file name to rename from
* @param newname file name to rename to
* @return true iff the operation succeeded
*/
bool FioRenameFile(const std::string &oldname, const std::string &newname)
{ {
#if defined(_WIN32) #if defined(_WIN32)
_wrename(OTTD2FS(oldname).c_str(), OTTD2FS(newname).c_str()); return _wrename(OTTD2FS(oldname).c_str(), OTTD2FS(newname).c_str()) == 0;
#else #else
rename(oldname.c_str(), newname.c_str()); return rename(oldname.c_str(), newname.c_str()) == 0;
#endif #endif
} }

View File

@@ -22,7 +22,7 @@ std::string FioFindFullPath(Subdirectory subdir, const std::string &filename);
std::string FioGetDirectory(Searchpath sp, Subdirectory subdir); std::string FioGetDirectory(Searchpath sp, Subdirectory subdir);
std::string FioFindDirectory(Subdirectory subdir); std::string FioFindDirectory(Subdirectory subdir);
void FioCreateDirectory(const std::string &name); void FioCreateDirectory(const std::string &name);
void FioRenameFile(const std::string &oldname, const std::string &newname); bool FioRenameFile(const std::string &oldname, const std::string &newname);
const char *FiosGetScreenshotDir(); const char *FiosGetScreenshotDir();