#endif
#endif
+#ifdef __EMX__
+#define MAX_PATH _MAX_PATH
+#endif
+
// ----------------------------------------------------------------------------
// private classes
// ----------------------------------------------------------------------------
m_hFile = ::CreateFile
(
filename, // name
- mode == Read ? GENERIC_READ // access mask
+ mode == Read ? GENERIC_READ // access mask
: GENERIC_WRITE,
0, // no sharing
NULL, // no secutity attr
if ( !volume.empty() )
{
+ format = wxFileName::GetFormat(format);
+
// Special Windows UNC paths hack, part 2: undo what we did in
// SplitPath() and make an UNC path if we have a drive which is not a
// single letter (hopefully the network shares can't be one letter only
wxString fullpath = fullpathOrig;
if ( !wxEndsWithPathSeparator(fullpath) )
{
- fullpath += GetPathSeparators(format)[0u];
+ fullpath += GetPathSeparator(format);
}
wxString volume, path, name, ext;
_T("the path shouldn't contain file name nor extension") );
#else // !__WXDEBUG__
- SplitPath(fullname, NULL /* no path */, &name, &ext, format);
+ SplitPath(fullname, NULL /* no path */, &name, &ext, format);
SplitPath(fullpath, &volume, &path, NULL, NULL, format);
#endif // __WXDEBUG__/!__WXDEBUG__
m_volume =
m_name =
m_ext = wxEmptyString;
+
+ // we don't have any absolute path for now
+ m_relative = TRUE;
}
/* static */
// 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__
// directory operations
// ----------------------------------------------------------------------------
-bool wxFileName::Mkdir( int perm, bool full )
+bool wxFileName::Mkdir( int perm, int flags )
{
- return wxFileName::Mkdir( GetFullPath(), perm, full );
+ return wxFileName::Mkdir( GetFullPath(), perm, flags );
}
-bool wxFileName::Mkdir( const wxString &dir, int perm, bool full )
+bool wxFileName::Mkdir( const wxString& dir, int perm, int flags )
{
- if (full)
+ if ( flags & wxPATH_MKDIR_FULL )
{
- wxFileName filename(dir);
- wxArrayString dirs = filename.GetDirs();
- dirs.Add(filename.GetName());
+ // split the path in components
+ wxFileName filename;
+ filename.AssignDir(dir);
- size_t count = dirs.GetCount();
- size_t i;
wxString currPath;
- int noErrors = 0;
- for ( i = 0; i < count; i++ )
+ if ( filename.HasVolume())
{
- currPath += dirs[i];
+ currPath << wxGetVolumeString(filename.GetVolume(), wxPATH_NATIVE);
+ }
- if (currPath.Last() == wxT(':'))
- {
- // Can't create a root directory so continue to next dir
+ wxArrayString dirs = filename.GetDirs();
+ size_t count = dirs.GetCount();
+ for ( size_t i = 0; i < count; i++ )
+ {
+ if ( i > 0 || filename.IsAbsolute() )
currPath += wxFILE_SEP_PATH;
- continue;
- }
+ currPath += dirs[i];
if (!DirExists(currPath))
+ {
if (!wxMkdir(currPath, perm))
- noErrors ++;
-
- if ( (i < (count-1)) )
- currPath += wxFILE_SEP_PATH;
+ {
+ // no need to try creating further directories
+ return FALSE;
+ }
+ }
}
- return (noErrors == 0);
+ return TRUE;
}
- else
- return ::wxMkdir( dir, perm );
+
+ return ::wxMkdir( dir, perm );
}
bool wxFileName::Rmdir()
m_ext.MakeLower();
}
+ // we do have the path now
+ //
+ // NB: need to do this before (maybe) calling Assign() below
+ m_relative = FALSE;
+
#if defined(__WIN32__)
if ( (flags & wxPATH_NORM_LONG) && (format == wxPATH_DOS) )
{
}
#endif // Win32
- // we do have the path now
- m_relative = FALSE;
-
return TRUE;
}
// 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);
if ( m_dirs.IsEmpty() && IsDir() )
{
m_dirs.Add(_T('.'));
- }
+ }
}
m_relative = TRUE;
// 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;
return fullname;
}
-wxString wxFileName::GetPath( bool add_separator, wxPathFormat format ) const
+wxString wxFileName::GetPath( int flags, wxPathFormat format ) const
{
format = GetFormat( format );
wxString fullpath;
- // the leading character
- if ( format == wxPATH_MAC && m_relative )
- {
- fullpath += wxFILE_SEP_PATH_MAC;
- }
- else if ( format == wxPATH_DOS )
+ // return the volume with the path as well if requested
+ if ( flags & wxPATH_GET_VOLUME )
{
- if (!m_relative)
- fullpath += wxFILE_SEP_PATH_DOS;
- }
- else if ( format == wxPATH_UNIX )
- {
- if (!m_relative)
- fullpath += wxFILE_SEP_PATH_UNIX;
+ fullpath += wxGetVolumeString(GetVolume(), format);
}
- // then concatenate all the path components using the path separator
- size_t dirCount = m_dirs.GetCount();
- if ( dirCount )
+ // the leading character
+ switch ( format )
{
- if ( format == wxPATH_VMS )
- {
- fullpath += wxT('[');
- }
+ case wxPATH_MAC:
+ if ( m_relative )
+ fullpath += wxFILE_SEP_PATH_MAC;
+ break;
+ case wxPATH_DOS:
+ if (!m_relative)
+ fullpath += wxFILE_SEP_PATH_DOS;
+ break;
- for ( size_t i = 0; i < dirCount; i++ )
- {
- // TODO: What to do with ".." under VMS
+ default:
+ wxFAIL_MSG( _T("unknown path format") );
+ // fall through
- switch (format)
+ case wxPATH_UNIX:
+ if ( !m_relative )
{
- case wxPATH_MAC:
- {
- if (m_dirs[i] == wxT("."))
- break;
- if (m_dirs[i] != wxT("..")) // convert back from ".." to nothing
- fullpath += m_dirs[i];
- fullpath += wxT(':');
- break;
- }
- case wxPATH_DOS:
- {
- fullpath += m_dirs[i];
- fullpath += wxT('\\');
- break;
- }
- case wxPATH_UNIX:
- {
- fullpath += m_dirs[i];
- fullpath += wxT('/');
- break;
- }
- case wxPATH_VMS:
- {
- if (m_dirs[i] != wxT("..")) // convert back from ".." to nothing
- fullpath += m_dirs[i];
- if (i == dirCount-1)
- fullpath += wxT(']');
- else
- fullpath += wxT('.');
- break;
- }
- default:
+ // normally the absolute file names starts with a slash with
+ // one exception: file names like "~/foo.bar" don't have it
+ if ( m_dirs.IsEmpty() || m_dirs[0u] != _T('~') )
{
- wxFAIL_MSG( wxT("error") );
+ fullpath += wxFILE_SEP_PATH_UNIX;
}
}
- }
- }
-
- if ( add_separator && !fullpath.empty() )
- {
- fullpath += GetPathSeparators(format)[0u];
- }
-
- return fullpath;
-}
-
-wxString wxFileName::GetFullPath( wxPathFormat format ) const
-{
- format = GetFormat(format);
-
- // first put the volume
- wxString fullpath = wxGetVolumeString(m_volume, format);
+ break;
- // the leading character
- if ( format == wxPATH_MAC )
- {
- if ( m_relative )
- fullpath += wxFILE_SEP_PATH_MAC;
- }
- else if ( format == wxPATH_DOS )
- {
- if ( !m_relative )
- fullpath += wxFILE_SEP_PATH_DOS;
- }
- else if ( format == wxPATH_UNIX )
- {
- if ( !m_relative )
- {
- // normally the absolute file names starts with a slash with one
- // exception: file names like "~/foo.bar" don't have it
- if ( m_dirs.IsEmpty() || m_dirs[0u] != _T('~') )
- {
- fullpath += wxFILE_SEP_PATH_UNIX;
- }
- }
+ case wxPATH_VMS:
+ // no leading character here but use this place to unset
+ // wxPATH_GET_SEPARATOR flag: under VMS it doesn't make sense as,
+ // if I understand correctly, there should never be a dot before
+ // the closing bracket
+ flags &= ~wxPATH_GET_SEPARATOR;
}
// then concatenate all the path components using the path separator
fullpath += wxT('[');
}
-
for ( size_t i = 0; i < dirCount; i++ )
{
- // TODO: What to do with ".." under VMS
-
switch (format)
{
case wxPATH_MAC:
- {
- if (m_dirs[i] == wxT("."))
- break;
- if (m_dirs[i] != wxT("..")) // convert back from ".." to nothing
+ if ( m_dirs[i] == wxT(".") )
+ {
+ // skip appending ':', this shouldn't be done in this
+ // case as "::" is interpreted as ".." under Unix
+ continue;
+ }
+
+ // convert back from ".." to nothing
+ if ( m_dirs[i] != wxT("..") )
fullpath += m_dirs[i];
- fullpath += wxT(':');
break;
- }
+
+ default:
+ wxFAIL_MSG( wxT("unexpected path format") );
+ // still fall through
+
case wxPATH_DOS:
- {
- fullpath += m_dirs[i];
- fullpath += wxT('\\');
- break;
- }
case wxPATH_UNIX:
- {
fullpath += m_dirs[i];
- fullpath += wxT('/');
break;
- }
+
case wxPATH_VMS:
- {
- if (m_dirs[i] != wxT("..")) // convert back from ".." to nothing
+ // TODO: What to do with ".." under VMS
+
+ // convert back from ".." to nothing
+ if ( m_dirs[i] != wxT("..") )
fullpath += m_dirs[i];
- if (i == dirCount-1)
- fullpath += wxT(']');
- else
- fullpath += wxT('.');
break;
- }
- default:
- {
- wxFAIL_MSG( wxT("error") );
- }
}
+
+ if ( (flags & wxPATH_GET_SEPARATOR) || (i != dirCount - 1) )
+ fullpath += GetPathSeparator(format);
+ }
+
+ if ( format == wxPATH_VMS )
+ {
+ fullpath += wxT(']');
}
}
- // finally add the file name and extension
+ return fullpath;
+}
+
+wxString wxFileName::GetFullPath( wxPathFormat format ) const
+{
+ // we already have a function to get the path
+ wxString fullpath = GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR,
+ format);
+
+ // now just add the file name and extension to it
fullpath += GetFullName();
return fullpath;
bool success = FALSE;
#if wxUSE_DYNAMIC_LOADER
- typedef DWORD (*GET_LONG_PATH_NAME)(const wxChar *, wxChar *, DWORD);
+ typedef DWORD (WINAPI *GET_LONG_PATH_NAME)(const wxChar *, wxChar *, DWORD);
static bool s_triedToLoad = FALSE;
if ( !s_triedToLoad )
{
+ // suppress the errors about missing GetLongPathName[AW]
+ wxLogNull noLog;
+
s_triedToLoad = TRUE;
wxDynamicLibrary dllKernel(_T("kernel32"));
if ( dllKernel.IsLoaded() )
}
}
}
+
if (success)
return pathOut;
#endif // wxUSE_DYNAMIC_LOADER
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;
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;
}
{
#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;
}
{
#if 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);
FILETIME ftAccess, ftCreate, ftWrite;
if ( ::GetFileTime(fh,
- dtMod ? &ftCreate : NULL,
+ dtCreate ? &ftCreate : NULL,
dtAccess ? &ftAccess : NULL,
- dtCreate ? &ftWrite : NULL) )
+ dtMod ? &ftWrite : NULL) )
{
- if ( dtMod )
- ConvertFileTimeToWx(dtMod, ftCreate);
+ if ( dtCreate )
+ ConvertFileTimeToWx(dtCreate, ftCreate);
if ( dtAccess )
ConvertFileTimeToWx(dtAccess, ftAccess);
- if ( dtCreate )
- ConvertFileTimeToWx(dtCreate, ftWrite);
+ if ( dtMod )
+ ConvertFileTimeToWx(dtMod, ftWrite);
return TRUE;
}
#ifdef __WXMAC__
const short kMacExtensionMaxLength = 16 ;
-typedef struct
+class MacDefaultExtensionRecord
{
+public :
+ MacDefaultExtensionRecord()
+ {
+ m_ext[0] = 0 ;
+ m_type = m_creator = NULL ;
+ }
+ MacDefaultExtensionRecord( const MacDefaultExtensionRecord& from )
+ {
+ strcpy( m_ext , from.m_ext ) ;
+ m_type = from.m_type ;
+ m_creator = from.m_creator ;
+ }
+ MacDefaultExtensionRecord( const char * extension , OSType type , OSType creator )
+ {
+ strncpy( m_ext , extension , kMacExtensionMaxLength ) ;
+ m_ext[kMacExtensionMaxLength] = 0 ;
+ m_type = type ;
+ m_creator = creator ;
+ }
char m_ext[kMacExtensionMaxLength] ;
OSType m_type ;
OSType m_creator ;
-} MacDefaultExtensionRecord ;
+} ;
#include "wx/dynarray.h"
WX_DECLARE_OBJARRAY(MacDefaultExtensionRecord, MacDefaultExtensionArray) ;
+
+bool gMacDefaultExtensionsInited = false ;
+
#include "wx/arrimpl.cpp"
-WX_DEFINE_OBJARRAY(MacDefaultExtensionArray) ;
+
+WX_DEFINE_EXPORTED_OBJARRAY(MacDefaultExtensionArray) ;
MacDefaultExtensionArray gMacDefaultExtensions ;
-bool gMacDefaultExtensionsInited = false ;
static void MacEnsureDefaultExtensionsLoaded()
{
if ( !gMacDefaultExtensionsInited )
{
+
// load the default extensions
- MacDefaultExtensionRecord defaults[] =
+ MacDefaultExtensionRecord defaults[1] =
{
- { "txt" , 'TEXT' , 'ttxt' } ,
-
+ MacDefaultExtensionRecord( "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] ) ;
- }
+ }
gMacDefaultExtensionsInited = true ;
}
}
-bool wxFileName::MacSetTypeAndCreator( wxUint32 type , wxUint32 creator )
+bool wxFileName::MacSetTypeAndCreator( wxUint32 type , wxUint32 creator )
{
FInfo fndrInfo ;
FSSpec spec ;
return true ;
}
-bool wxFileName::MacGetTypeAndCreator( wxUint32 *type , wxUint32 *creator )
+bool wxFileName::MacGetTypeAndCreator( wxUint32 *type , wxUint32 *creator )
{
FInfo fndrInfo ;
FSSpec spec ;
return false;
}
-bool wxFileName::MacFindDefaultTypeAndCreator( const wxString& ext , wxUint32 *type , wxUint32 *creator )
+bool wxFileName::MacFindDefaultTypeAndCreator( const wxString& ext , wxUint32 *type , wxUint32 *creator )
{
MacEnsureDefaultExtensionsLoaded() ;
wxString extl = ext.Lower() ;