Create fio wrapper for rename file

This commit is contained in:
Jonathan G Rennison 2023-07-09 12:42:35 +01:00
parent f190b9815a
commit f6e8ea059d
4 changed files with 11 additions and 2 deletions

View File

@ -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.

View File

@ -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();

View File

@ -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);
}
}

View File

@ -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);