Fix file saving on Windows.

Originally committed to SVN as r4333.
This commit is contained in:
Thomas Goyne 2010-05-21 03:07:48 +00:00
parent cd8305987b
commit d3c33d5e7c
3 changed files with 6 additions and 6 deletions

View file

@ -10,7 +10,9 @@
#include <time.h> #include <time.h>
// Windows C // Windows C
#ifdef _MSC_VER #ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <io.h> #include <io.h>
#endif #endif

View file

@ -60,7 +60,6 @@ Save::Save(const std::string& file): file_name(file) {
// util::Rename will find it, and to let users know something went // util::Rename will find it, and to let users know something went
// wrong by leaving a 0 byte file. // wrong by leaving a 0 byte file.
std::ofstream fp_touch(file.c_str()); std::ofstream fp_touch(file.c_str());
fp_touch.close();
} }
/// @todo This is a temp hack, proper implementation needs to come after /// @todo This is a temp hack, proper implementation needs to come after
@ -75,9 +74,8 @@ Save::Save(const std::string& file): file_name(file) {
Save::~Save() { Save::~Save() {
const std::string tmp(file_name + "_tmp"); const std::string tmp(file_name + "_tmp");
util::Rename(tmp, file_name);
delete fp; delete fp;
fp = 0; // to avoid any silly errors. util::Rename(tmp, file_name);
} }
std::ofstream& Save::Get() { std::ofstream& Save::Get() {

View file

@ -34,7 +34,7 @@ namespace agi {
const std::string DirName(const std::string& path) { const std::string DirName(const std::string& path) {
if (path.find('/') == std::string::npos) { if (path.find('/') == std::string::npos) {
const std::string cwd("."); const std::string cwd(".");
return cwd; return cwd;
} }
@ -52,7 +52,7 @@ void Rename(const std::string& from, const std::string& to) {
acs::CheckDirWrite(DirName(to)); acs::CheckDirWrite(DirName(to));
} }
rename(from.c_str(), to.c_str()); MoveFileExA(from.c_str(), to.c_str(), MOVEFILE_REPLACE_EXISTING);
} }
} // namespace io } // namespace io