// Created: 28.12.2000
// RCS-ID: $Id$
// Copyright: (c) 2000 Robert Roebling
-// Licence: wxWindows license
+// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
/*
#endif
#ifdef __MWERKS__
+#ifdef __MACH__
+#include <sys/types.h>
+#include <utime.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#else
#include <stat.h>
#include <unistd.h>
#include <unix.h>
#endif
+#endif
#ifdef __WATCOMC__
#include <io.h>
#endif
#endif
+#ifdef __EMX__
+#define MAX_PATH _MAX_PATH
+#endif
+
// ----------------------------------------------------------------------------
// private classes
// ----------------------------------------------------------------------------
// private functions
// ----------------------------------------------------------------------------
-#if defined(__WIN32__) && !defined(__WXMICROWIN__)
+#if wxUSE_DATETIME && defined(__WIN32__) && !defined(__WXMICROWIN__)
// convert between wxDateTime and FILETIME which is a 64-bit value representing
// the number of 100-nanosecond intervals since January 1, 1601.
}
}
-#endif // __WIN32__
+#endif // wxUSE_DATETIME && __WIN32__
// return a string with the volume par
static wxString wxGetVolumeString(const wxString& volume, wxPathFormat format)
m_volume =
m_name =
m_ext = wxEmptyString;
+
+ // we don't have any absolute path for now
+ m_relative = TRUE;
}
/* static */
// existence tests
// ----------------------------------------------------------------------------
-bool wxFileName::FileExists()
+bool wxFileName::FileExists() const
{
return wxFileName::FileExists( GetFullPath() );
}
return ::wxFileExists( file );
}
-bool wxFileName::DirExists()
+bool wxFileName::DirExists() const
{
return wxFileName::DirExists( GetFullPath() );
}
// scratch space for mkstemp()
path += _T("XXXXXX");
- // can use the cast here because the length doesn't change and the string
- // is not shared
- int fdTemp = mkstemp((char *)path.mb_str());
+ // we need to copy the path to the buffer in which mkstemp() can modify it
+ wxCharBuffer buf( wxConvFile.cWX2MB( path ) );
+
+ // cast is safe because the string length doesn't change
+ int fdTemp = mkstemp( (char*)(const char*) buf );
if ( fdTemp == -1 )
{
// this might be not necessary as mkstemp() on most systems should have
}
else // mkstemp() succeeded
{
+ path = wxConvFile.cMB2WX( (const char*) buf );
+
// avoid leaking the fd
if ( fileTemp )
{
// same as above
path += _T("XXXXXX");
- if ( !mktemp((char *)path.mb_str()) )
+ wxCharBuffer buf = wxConvFile.cWX2MB( path );
+ if ( !mktemp( (const char*) buf ) )
{
path.clear();
}
+ else
+ {
+ path = wxConvFile.cMB2WX( (const char*) buf );
+ }
#else // !HAVE_MKTEMP (includes __DOS__)
// generate the unique file name ourselves
- #ifndef __DOS__
+ #if !defined(__DOS__) && (!defined(__MWERKS__) || defined(__DARWIN__) )
path << (unsigned int)getpid();
#endif
size_t count = dirs.GetCount();
for ( size_t i = 0; i < count; i++ )
{
- if ( i > 0 || filename.IsAbsolute() )
+ if ( i > 0 ||
+#if defined(__WXMAC__) && !defined(__DARWIN__)
+ // relative pathnames are exactely the other way round under mac...
+ !filename.IsAbsolute()
+#else
+ filename.IsAbsolute()
+#endif
+ )
currPath += wxFILE_SEP_PATH;
currPath += dirs[i];
// get cwd only once - small time saving
wxString cwd = wxGetCwd();
- Normalize(wxPATH_NORM_ALL, cwd, format);
- fnBase.Normalize(wxPATH_NORM_ALL, cwd, format);
+ Normalize(wxPATH_NORM_ALL & ~wxPATH_NORM_CASE, cwd, format);
+ fnBase.Normalize(wxPATH_NORM_ALL & ~wxPATH_NORM_CASE, cwd, format);
bool withCase = IsCaseSensitive(format);
// filename kind tests
// ----------------------------------------------------------------------------
-bool wxFileName::SameAs(const wxFileName &filepath, wxPathFormat format)
+bool wxFileName::SameAs(const wxFileName& filepath, wxPathFormat format) const
{
wxFileName fn1 = *this,
fn2 = filepath;
// get cwd only once - small time saving
wxString cwd = wxGetCwd();
- fn1.Normalize(wxPATH_NORM_ALL, cwd, format);
- fn2.Normalize(wxPATH_NORM_ALL, cwd, format);
+ fn1.Normalize(wxPATH_NORM_ALL & ~wxPATH_NORM_CASE, cwd, format);
+ fn2.Normalize(wxPATH_NORM_ALL & ~wxPATH_NORM_CASE, cwd, format);
if ( fn1.GetFullPath() == fn2.GetFullPath() )
return TRUE;
void wxFileName::RemoveDir( int pos )
{
- m_dirs.Remove( (size_t)pos );
+ m_dirs.RemoveAt( (size_t)pos );
}
// ----------------------------------------------------------------------------
WIN32_FIND_DATA findFileData;
HANDLE hFind;
- pathOut = wxEmptyString;
+
+ if ( HasVolume() )
+ pathOut = GetVolume() +
+ GetVolumeSeparator(wxPATH_DOS) +
+ GetPathSeparator(wxPATH_DOS);
+ else
+ pathOut = wxEmptyString;
wxArrayString dirs = GetDirs();
dirs.Add(GetFullName());
if ( tmpPath.empty() )
continue;
- if ( tmpPath.Last() == wxT(':') )
+ // can't see this being necessary? MF
+ if ( tmpPath.Last() == GetVolumeSeparator(wxPATH_DOS) )
{
// Can't pass a drive and root dir to FindFirstFile,
// so continue to next dir
hFind = ::FindFirstFile(tmpPath, &findFileData);
if (hFind == INVALID_HANDLE_VALUE)
{
- // Error: return immediately with the original path
- return path;
+ // Error: most likely reason is that path doesn't exist, so
+ // append any unprocessed parts and return
+ for ( i += 1; i < count; i++ )
+ tmpPath += wxFILE_SEP_PATH + dirs[i];
+
+ return tmpPath;
}
pathOut += findFileData.cFileName;
// time functions
// ----------------------------------------------------------------------------
+#if wxUSE_DATETIME
+
bool wxFileName::SetTimes(const wxDateTime *dtAccess,
const wxDateTime *dtMod,
const wxDateTime *dtCreate)
{
-#if defined(__UNIX_LIKE__) || (defined(__DOS__) && defined(__WATCOMC__))
+#if defined(__WIN32__)
+ if ( IsDir() )
+ {
+ // VZ: please let me know how to do this if you can
+ wxFAIL_MSG( _T("SetTimes() not implemented for the directories") );
+ }
+ else // file
+ {
+ wxFileHandle fh(GetFullPath(), wxFileHandle::Write);
+ if ( fh.IsOk() )
+ {
+ FILETIME ftAccess, ftCreate, ftWrite;
+
+ if ( dtCreate )
+ ConvertWxToFileTime(&ftCreate, *dtCreate);
+ if ( dtAccess )
+ ConvertWxToFileTime(&ftAccess, *dtAccess);
+ if ( dtMod )
+ ConvertWxToFileTime(&ftWrite, *dtMod);
+
+ if ( ::SetFileTime(fh,
+ dtCreate ? &ftCreate : NULL,
+ dtAccess ? &ftAccess : NULL,
+ dtMod ? &ftWrite : NULL) )
+ {
+ return TRUE;
+ }
+ }
+ }
+#elif defined(__UNIX_LIKE__) || (defined(__DOS__) && defined(__WATCOMC__))
if ( !dtAccess && !dtMod )
{
// can't modify the creation time anyhow, don't try
utimbuf utm;
utm.actime = dtAccess ? dtAccess->GetTicks() : dtMod->GetTicks();
utm.modtime = dtMod ? dtMod->GetTicks() : dtAccess->GetTicks();
- if ( utime(GetFullPath(), &utm) == 0 )
+ if ( utime(GetFullPath().fn_str(), &utm) == 0 )
{
return TRUE;
}
-#elif defined(__WIN32__)
- wxFileHandle fh(GetFullPath(), wxFileHandle::Write);
- if ( fh.IsOk() )
- {
- FILETIME ftAccess, ftCreate, ftWrite;
-
- if ( dtCreate )
- ConvertWxToFileTime(&ftCreate, *dtCreate);
- if ( dtAccess )
- ConvertWxToFileTime(&ftAccess, *dtAccess);
- if ( dtMod )
- ConvertWxToFileTime(&ftWrite, *dtMod);
-
- if ( ::SetFileTime(fh,
- dtCreate ? &ftCreate : NULL,
- dtAccess ? &ftAccess : NULL,
- dtMod ? &ftWrite : NULL) )
- {
- return TRUE;
- }
- }
#else // other platform
#endif // platforms
{
#if defined(__UNIX_LIKE__)
// under Unix touching file is simple: just pass NULL to utime()
- if ( utime(GetFullPath(), NULL) == 0 )
+ if ( utime(GetFullPath().fn_str(), NULL) == 0 )
{
return TRUE;
}
wxDateTime *dtMod,
wxDateTime *dtCreate) const
{
-#if defined(__UNIX_LIKE__) || defined(__WXMAC__) || (defined(__DOS__) && defined(__WATCOMC__))
+#if defined(__WIN32__)
+ // we must use different methods for the files and directories under
+ // Windows as CreateFile(GENERIC_READ) doesn't work for the directories and
+ // CreateFile(FILE_FLAG_BACKUP_SEMANTICS) works -- but only under NT and
+ // not 9x
+ bool ok;
+ FILETIME ftAccess, ftCreate, ftWrite;
+ if ( IsDir() )
+ {
+ // implemented in msw/dir.cpp
+ extern bool wxGetDirectoryTimes(const wxString& dirname,
+ FILETIME *, FILETIME *, FILETIME *);
+
+ // we should pass the path without the trailing separator to
+ // wxGetDirectoryTimes()
+ ok = wxGetDirectoryTimes(GetPath(wxPATH_GET_VOLUME),
+ &ftAccess, &ftCreate, &ftWrite);
+ }
+ else // file
+ {
+ wxFileHandle fh(GetFullPath(), wxFileHandle::Read);
+ if ( fh.IsOk() )
+ {
+ ok = ::GetFileTime(fh,
+ dtCreate ? &ftCreate : NULL,
+ dtAccess ? &ftAccess : NULL,
+ dtMod ? &ftWrite : NULL) != 0;
+ }
+ else
+ {
+ ok = FALSE;
+ }
+ }
+
+ if ( ok )
+ {
+ if ( dtCreate )
+ ConvertFileTimeToWx(dtCreate, ftCreate);
+ if ( dtAccess )
+ ConvertFileTimeToWx(dtAccess, ftAccess);
+ if ( dtMod )
+ ConvertFileTimeToWx(dtMod, ftWrite);
+
+ return TRUE;
+ }
+#elif defined(__UNIX_LIKE__) || defined(__WXMAC__) || (defined(__DOS__) && defined(__WATCOMC__))
wxStructStat stBuf;
- if ( wxStat(GetFullPath(), &stBuf) == 0 )
+ if ( wxStat( GetFullPath().c_str(), &stBuf) == 0 )
{
if ( dtAccess )
dtAccess->Set(stBuf.st_atime);
return TRUE;
}
-#elif defined(__WIN32__)
- wxFileHandle fh(GetFullPath(), wxFileHandle::Read);
- if ( fh.IsOk() )
- {
- FILETIME ftAccess, ftCreate, ftWrite;
-
- if ( ::GetFileTime(fh,
- dtCreate ? &ftCreate : NULL,
- dtAccess ? &ftAccess : NULL,
- dtMod ? &ftWrite : NULL) )
- {
- if ( dtCreate )
- ConvertFileTimeToWx(dtCreate, ftCreate);
- if ( dtAccess )
- ConvertFileTimeToWx(dtAccess, ftAccess);
- if ( dtMod )
- ConvertFileTimeToWx(dtMod, ftWrite);
-
- return TRUE;
- }
- }
#else // other platform
#endif // platforms
return FALSE;
}
+#endif // wxUSE_DATETIME
+
#ifdef __WXMAC__
const short kMacExtensionMaxLength = 16 ;
}
MacDefaultExtensionRecord( const MacDefaultExtensionRecord& from )
{
- strcpy( m_ext , from.m_ext ) ;
+ wxStrcpy( m_ext , from.m_ext ) ;
m_type = from.m_type ;
m_creator = from.m_creator ;
}
- MacDefaultExtensionRecord( char * extension , OSType type , OSType creator )
+ MacDefaultExtensionRecord( const wxChar * extension , OSType type , OSType creator )
{
- strncpy( m_ext , extension , kMacExtensionMaxLength ) ;
+ wxStrncpy( m_ext , extension , kMacExtensionMaxLength ) ;
m_ext[kMacExtensionMaxLength] = 0 ;
m_type = type ;
m_creator = creator ;
}
- char m_ext[kMacExtensionMaxLength] ;
+ wxChar m_ext[kMacExtensionMaxLength] ;
OSType m_type ;
OSType m_creator ;
} ;
{
if ( !gMacDefaultExtensionsInited )
{
-
+
// load the default extensions
MacDefaultExtensionRecord defaults[1] =
{
- MacDefaultExtensionRecord( "txt" , 'TEXT' , 'ttxt' ) ,
+ MacDefaultExtensionRecord( wxT("txt") , 'TEXT' , 'ttxt' ) ,
} ;
// we could load the pc exchange prefs here too
- for ( int i = 0 ; i < WXSIZEOF( defaults ) ; ++i )
+ for ( size_t i = 0 ; i < WXSIZEOF( defaults ) ; ++i )
{
gMacDefaultExtensions.Add( defaults[i] ) ;
}
MacDefaultExtensionRecord rec ;
rec.m_type = type ;
rec.m_creator = creator ;
- strncpy( rec.m_ext , ext.Lower().c_str() , kMacExtensionMaxLength ) ;
+ wxStrncpy( rec.m_ext , ext.Lower().c_str() , kMacExtensionMaxLength ) ;
gMacDefaultExtensions.Add( rec ) ;
}
#endif