// 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
- if ( wxStat(file1, &fbuf) != 0 )
+ if ( wxStat(OS_FILENAME(file1), &fbuf) != 0 )
{
// the file probably doesn't exist or we haven't the rights to read
// from it anyhow
// 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());
// 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__
return FALSE;
}
-#if !defined(__VISAGECPP__) && !defined(__WXMAC__)
-// no chmod in VA. SHould be some permission API for HPFS386 partitions however
- if ( chmod(file2, fbuf.st_mode) != 0 )
+#if !defined(__VISAGECPP__) && !defined(__WXMAC__) || defined(__UNIX__)
+ // 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
wxRenameFile (const wxString& file1, const wxString& file2)
{
// Normal system call
- if ( wxRename (OS_FILENAME(file1), OS_FILENAME(file2)) == 0 )
+ if ( wxRename (file1, file2) == 0 )
return TRUE;
// Try to copy
bool wxMkdir(const wxString& dir, int perm)
{
-#if defined( __WXMAC__ )
+#if defined(__WXMAC__) && !defined(__UNIX__)
return (mkdir(wxUnix2MacFilename( dir ) , 0 ) == 0);
#else // !Mac
const wxChar *dirname = dir.c_str();
char *cbuf = new char[sz+1];
#ifdef _MSC_VER
if (_getcwd(cbuf, sz) == NULL) {
-#elif defined( __WXMAC__)
+#elif defined(__WXMAC__) && !defined(__UNIX__)
enum
{
SFSaveDisk = 0x214, CurDirStore = 0x398
#else // wxUnicode
#ifdef _MSC_VER
if (_getcwd(buf, sz) == NULL) {
-#elif defined( __WXMAC__)
+#elif defined(__WXMAC__) && !defined(__UNIX__)
FSSpec cwdSpec ;
FCBPBRec pb;
OSErr error;