]> git.saurik.com Git - wxWidgets.git/commitdiff
applied patch 410892 (wxCopyFile uses ::CopyFile under Win32, has overwrite parameter)
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 9 Apr 2001 00:10:21 +0000 (00:10 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 9 Apr 2001 00:10:21 +0000 (00:10 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9685 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/function.tex
include/wx/filefn.h
src/common/filefn.cpp

index a55b29525aa0b6d9531c7527125564df24fc8ead..42b96d35f33c6408dd755bcf619db9869558d007 100644 (file)
@@ -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}
 
index daa793f1296340b07a5b8ab743b52f6e09e11592..baccc0131f112823656fd0d74e08123f5664d65f 100644 (file)
@@ -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);
index d06257478f7773f8bc1683f3e34b8c996ab89d7a..da2ce56b6f787fc418c5afd0af10df56c6a47c3b 100644 (file)
@@ -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