From: Vadim Zeitlin Date: Mon, 9 Apr 2001 00:10:21 +0000 (+0000) Subject: applied patch 410892 (wxCopyFile uses ::CopyFile under Win32, has overwrite parameter) X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/4658c44ec233e09db6f108f1ce01f06708907dd7 applied patch 410892 (wxCopyFile uses ::CopyFile under Win32, has overwrite parameter) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9685 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/latex/wx/function.tex b/docs/latex/wx/function.tex index a55b29525a..42b96d35f3 100644 --- a/docs/latex/wx/function.tex +++ b/docs/latex/wx/function.tex @@ -213,9 +213,12 @@ TRUE if successful. \membersection{::wxCopyFile} -\func{bool}{wxCopyFile}{\param{const wxString\& }{file1}, \param{const wxString\& }{file2}} +\func{bool}{wxCopyFile}{\param{const wxString\& }{file1}, \param{const wxString\& }{file2}, \param{bool }{overwrite = TRUE}} -Copies {\it file1} to {\it file2}, returning TRUE if successful. +Copies {\it file1} to {\it file2}, returning TRUE if successful. If +{\it overwrite} parameter is TRUE (default), the destination file is overwritten +if it exists, but if {\it overwrite} is FALSE, the functions failes in this +case. \membersection{::wxGetCwd}\label{wxgetcwd} diff --git a/include/wx/filefn.h b/include/wx/filefn.h index daa793f129..baccc0131f 100644 --- a/include/wx/filefn.h +++ b/include/wx/filefn.h @@ -220,7 +220,8 @@ WXDLLEXPORT bool wxMatchWild(const wxString& pattern, const wxString& text, boo WXDLLEXPORT bool wxConcatFiles(const wxString& file1, const wxString& file2, const wxString& file3); // Copy file1 to file2 -WXDLLEXPORT bool wxCopyFile(const wxString& file1, const wxString& file2); +WXDLLEXPORT bool wxCopyFile(const wxString& file1, const wxString& file2, + bool overwrite = TRUE); // Remove file WXDLLEXPORT bool wxRemoveFile(const wxString& file); diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index d06257478f..da2ce56b6f 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -996,8 +996,15 @@ wxConcatFiles (const wxString& file1, const wxString& file2, const wxString& fil // Copy files bool -wxCopyFile (const wxString& file1, const wxString& file2) +wxCopyFile (const wxString& file1, const wxString& file2, bool overwrite) { +#if defined(__WIN32__) + // CopyFile() copies file attributes and modification time too, so use it + // instead of our code if available + // + // NB: 3rd parameter is bFailIfExists i.e. the inverse of overwrite + return ::CopyFile(file1, file2, !overwrite); +#else // !Win32 wxStructStat fbuf; // get permissions of file1 @@ -1017,7 +1024,7 @@ wxCopyFile (const wxString& file1, const wxString& file2) // remove file2, if it exists. This is needed for creating // file2 with the correct permissions in the next step - if ( wxFileExists(file2) && !wxRemoveFile(file2) ) + if ( wxFileExists(file2) && (!overwrite || !wxRemoveFile(file2))) { wxLogSysError(_("Impossible to overwrite the file '%s'"), file2.c_str()); @@ -1033,7 +1040,7 @@ wxCopyFile (const wxString& file1, const wxString& file2) // create file2 with the same permissions than file1 and open it for // writing wxFile fileOut; - if ( !fileOut.Create(file2, TRUE, fbuf.st_mode & 0777) ) + if ( !fileOut.Create(file2, overwrite, fbuf.st_mode & 0777) ) return FALSE; #ifdef __UNIX__ @@ -1059,15 +1066,17 @@ wxCopyFile (const wxString& file1, const wxString& file2) } #if !defined(__VISAGECPP__) && !defined(__WXMAC__) || defined(__UNIX__) -// no chmod in VA. SHould be some permission API for HPFS386 partitions however + // no chmod in VA. SHould be some permission API for HPFS386 partitions however if ( chmod(OS_FILENAME(file2), fbuf.st_mode) != 0 ) { wxLogSysError(_("Impossible to set permissions for the file '%s'"), file2.c_str()); return FALSE; } -#endif +#endif // OS/2 || Mac + return TRUE; +#endif // __WXMSW__ && __WIN32__ } bool