From 1b6dea5de110cd0c5695949d351436048e84e7f8 Mon Sep 17 00:00:00 2001 From: Michael Bedward Date: Tue, 7 Mar 2000 10:02:25 +0000 Subject: [PATCH] Added Create functions. They return TRUE if the file was successfully created; FALSE if it couldn't be created (or already exists - is that ok?). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6495 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/textfile.h | 4 ++++ src/common/textfile.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/wx/textfile.h b/include/wx/textfile.h index 6c617bb624..0f9ec816a3 100644 --- a/include/wx/textfile.h +++ b/include/wx/textfile.h @@ -73,6 +73,10 @@ public: // file operations // file exists? bool Exists() const; + // create the file if it doesn't already exist + bool Create(); + // same as Create() but with (another) file name + bool Create(const wxString& strFile); // Open() also loads file in memory on success bool Open(); // same as Open() but with (another) file name diff --git a/src/common/textfile.cpp b/src/common/textfile.cpp index f10d5de576..89a8e94033 100644 --- a/src/common/textfile.cpp +++ b/src/common/textfile.cpp @@ -159,6 +159,32 @@ bool wxTextFile::Exists() const return wxFile::Exists(m_strFile); } +bool wxTextFile::Create(const wxString& strFile) +{ + m_strFile = strFile; + + return Create(); +} + +bool wxTextFile::Create() +{ + // file name must be either given in ctor or in Create(const wxString&) + wxASSERT( !m_strFile.IsEmpty() ); + + // if the file already exists do nothing + if ( Exists() ) return FALSE; + + if ( m_file.Open(m_strFile, wxFile::write) ) + { + m_file.Close(); + return TRUE; + } + else + { + return FALSE; + } +} + bool wxTextFile::Open(const wxString& strFile) { m_strFile = strFile;