diff --git a/src/fileio.cpp b/src/fileio.cpp index 3d2e6dc11a..2a5c042c22 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -360,6 +360,15 @@ void FioCreateDirectory(const std::string &name) #endif } +void FioRenameFile(const std::string &oldname, const std::string &newname) +{ +#if defined(_WIN32) + _wrename(OTTD2FS(oldname).c_str(), OTTD2FS(newname).c_str()); +#else + rename(oldname.c_str(), newname.c_str()); +#endif +} + /** * Appends, if necessary, the path separator character to the end of the string. * It does not add the path separator to zero-sized strings. diff --git a/src/fileio_func.h b/src/fileio_func.h index 9684650dcf..add5d43200 100644 --- a/src/fileio_func.h +++ b/src/fileio_func.h @@ -22,6 +22,7 @@ std::string FioFindFullPath(Subdirectory subdir, const std::string &filename); std::string FioGetDirectory(Searchpath sp, Subdirectory subdir); std::string FioFindDirectory(Subdirectory subdir); void FioCreateDirectory(const std::string &name); +void FioRenameFile(const std::string &oldname, const std::string &newname); const char *FiosGetScreenshotDir(); diff --git a/src/sl/saveload.cpp b/src/sl/saveload.cpp index ddd674ac05..aaa9f153b3 100644 --- a/src/sl/saveload.cpp +++ b/src/sl/saveload.cpp @@ -3735,7 +3735,7 @@ void DoAutoOrNetsave(FiosNumberedSaveName &counter, bool threaded, FiosNumberedS std::string lt_path = lt_counter->FilenameUsingMaxSaves(_settings_client.gui.max_num_lt_autosaves); DEBUG(sl, 2, "Renaming autosave '%s' to long-term file '%s'", buf, lt_path.c_str()); std::string dir = FioFindDirectory(AUTOSAVE_DIR); - rename((dir + buf).c_str(), (dir + lt_path).c_str()); + FioRenameFile(dir + buf, dir + lt_path); } } diff --git a/src/stdafx.h b/src/stdafx.h index e859993ce2..6d96d82c51 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -220,7 +220,6 @@ # define fopen(file, mode) _wfopen(OTTD2FS(file).c_str(), _T(mode)) # define unlink(file) _wunlink(OTTD2FS(file).c_str()) -# define rename(oldname, newname) _wrename(OTTD2FS(oldname).c_str(), OTTD2FS(newname).c_str()) std::string FS2OTTD(const std::wstring &name); std::wstring OTTD2FS(const std::string &name);