From 9cb88728511c314695731d92cb4ab16c8e3b051e Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Mon, 23 Apr 2012 21:20:32 +0000 Subject: Anvil storage writing (Basic storage is working, NO entities except for chests are working! Don't use for real servers) git-svn-id: http://mc-server.googlecode.com/svn/trunk@475 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cFile.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'source/cFile.cpp') diff --git a/source/cFile.cpp b/source/cFile.cpp index 5ea71107a..cd61800e2 100644 --- a/source/cFile.cpp +++ b/source/cFile.cpp @@ -69,7 +69,7 @@ bool cFile::Open(const AString & iFileName, EMode iMode) { case fmRead: Mode = "rb"; break; case fmWrite: Mode = "wb"; break; - case fmReadWrite: Mode = "ab+"; break; + case fmReadWrite: Mode = "rb+"; break; default: { ASSERT(!"Unhandled file mode"); @@ -77,6 +77,14 @@ bool cFile::Open(const AString & iFileName, EMode iMode) } } m_File = fopen(iFileName.c_str(), Mode); + if ((m_File == NULL) && (iMode == fmReadWrite)) + { + // Fix for MS not following C spec, opening "a" mode files for writing at the end only + // The file open operation has been tried with "read update", fails if file not found + // So now we know either the file doesn't exist or we don't have rights, no need to worry about file contents. + // Simply re-open for read-writing, erasing existing contents: + m_File = fopen(iFileName.c_str(), "wb+"); + } return (m_File != NULL); } @@ -251,3 +259,13 @@ int cFile::ReadRestOfFile(AString & a_Contents) + +bool cFile::Exists(const AString & a_FileName) +{ + cFile test(a_FileName, fmRead); + return test.IsOpen(); +} + + + + -- cgit v1.2.3