+ return false;
+ }
+#elif defined(__OS2__)
+ if ( ::DosCopy(file1.c_str(), file2.c_str(), overwrite ? DCPY_EXISTING : 0) != 0 )
+ return false;
+#elif wxUSE_FILE // !Win32
+
+ wxStructStat fbuf;
+ // get permissions of file1
+ if ( wxStat( file1, &fbuf) != 0 )
+ {
+ // the file probably doesn't exist or we haven't the rights to read
+ // from it anyhow
+ wxLogSysError(_("Impossible to get permissions for file '%s'"),
+ file1.c_str());
+ return false;
+ }
+
+ // open file1 for reading
+ wxFile fileIn(file1, wxFile::read);
+ if ( !fileIn.IsOpened() )
+ return false;
+
+ // remove file2, if it exists. This is needed for creating
+ // file2 with the correct permissions in the next step
+ if ( wxFileExists(file2) && (!overwrite || !wxRemoveFile(file2)))
+ {
+ wxLogSysError(_("Impossible to overwrite the file '%s'"),
+ file2.c_str());
+ return false;
+ }
+
+ wxDoCopyFile(fileIn, fbuf, file2, overwrite);
+
+#if defined(__WXMAC__) || defined(__WXCOCOA__)
+ // copy the resource fork of the file too if it's present
+ wxString pathRsrcOut;
+ wxFile fileRsrcIn;
+
+ {
+ // suppress error messages from this block as resource forks don't have
+ // to exist
+ wxLogNull noLog;
+
+ // it's not enough to check for file existence: it always does on HFS
+ // but is empty for files without resources
+ if ( fileRsrcIn.Open(file1 + wxT("/..namedfork/rsrc")) &&
+ fileRsrcIn.Length() > 0 )
+ {
+ // we must be using HFS or another filesystem with resource fork
+ // support, suppose that destination file system also is HFS[-like]
+ pathRsrcOut = file2 + wxT("/..namedfork/rsrc");
+ }
+ else // check if we have resource fork in separate file (non-HFS case)
+ {
+ wxFileName fnRsrc(file1);
+ fnRsrc.SetName(wxT("._") + fnRsrc.GetName());
+
+ fileRsrcIn.Close();
+ if ( fileRsrcIn.Open( fnRsrc.GetFullPath() ) )
+ {
+ fnRsrc = file2;
+ fnRsrc.SetName(wxT("._") + fnRsrc.GetName());
+
+ pathRsrcOut = fnRsrc.GetFullPath();
+ }
+ }
+ }
+
+ if ( !pathRsrcOut.empty() )
+ {
+ if ( !wxDoCopyFile(fileRsrcIn, fbuf, pathRsrcOut, overwrite) )
+ return false;
+ }
+#endif // wxMac || wxCocoa
+
+#if !defined(__VISAGECPP__) && !defined(__WXMAC__) || defined(__UNIX__)
+ // no chmod in VA. Should be some permission API for HPFS386 partitions
+ // however
+ if ( chmod(file2.fn_str(), fbuf.st_mode) != 0 )
+ {
+ wxLogSysError(_("Impossible to set permissions for the file '%s'"),
+ file2.c_str());
+ return false;
+ }
+#endif // OS/2 || Mac
+
+#else // !Win32 && ! wxUSE_FILE
+
+ // impossible to simulate with wxWidgets API
+ wxUnusedVar(file1);
+ wxUnusedVar(file2);
+ wxUnusedVar(overwrite);
+ return false;
+
+#endif // __WINDOWS__ && __WIN32__
+
+ return true;
+}
+
+bool
+wxRenameFile(const wxString& file1, const wxString& file2, bool overwrite)
+{
+ if ( !overwrite && wxFileExists(file2) )
+ {
+ wxLogSysError
+ (
+ _("Failed to rename the file '%s' to '%s' because the destination file already exists."),
+ file1.c_str(), file2.c_str()
+ );
+
+ return false;
+ }
+
+#if !defined(__WXWINCE__)
+ // Normal system call
+ if ( wxRename (file1, file2) == 0 )
+ return true;