#endif
#endif
-#ifdef __GNUWIN32__
- #include <wchar.h>
- #ifndef __TWIN32__
- #include <sys/unistd.h>
- #endif
-#endif
-
#ifdef __BORLANDC__ // Please someone tell me which version of Borland needs
// this (3.1 I believe) and how to test for it.
// If this works for Borland 4.0 as well, then no worries.
#ifdef __WINDOWS__
#include <windows.h>
-#endif
+ #include "wx/msw/mslu.h"
+
+ // sys/cygwin.h is needed for cygwin_conv_to_full_win32_path()
+ //
+ // note that it must be included after <windows.h>
+ #ifdef __GNUWIN32__
+ #ifdef __CYGWIN__
+ #include <sys/cygwin.h>
+ #endif
+ #include <wchar.h>
+ #ifndef __TWIN32__
+ #include <sys/unistd.h>
+ #endif
+ #endif // __GNUWIN32__
+#endif // __WINDOWS__
// TODO: Borland probably has _wgetcwd as well?
#ifdef _MSC_VER
#define _MAXPATHLEN 1024
#endif
-extern wxChar *wxBuffer;
-
#ifdef __WXMAC__
# include "MoreFiles.h"
# include "MoreFilesExtras.h"
bool
wxFileExists (const wxString& filename)
{
-#if defined(__WINDOWS__) && !defined(__WXMICROWIN__)
- // GetFileAttributes can copy with network paths
- DWORD ret = GetFileAttributes(filename);
- DWORD isDir = (ret & FILE_ATTRIBUTE_DIRECTORY);
- return ((ret != 0xffffffff) && (isDir == 0));
+#if defined(__WIN32__) && !defined(__WXMICROWIN__)
+ // GetFileAttributes can copy with network paths unlike stat()
+ DWORD ret = ::GetFileAttributes(filename);
+
+ return (ret != (DWORD)-1) && !(ret & FILE_ATTRIBUTE_DIRECTORY);
#else
wxStructStat stbuf;
if ( !filename.empty() && wxStat (OS_FILENAME(filename), &stbuf) == 0 )
#if defined(__WXMAC__) && !defined(__DARWIN__)
// Classic or Carbon CodeWarrior like
// Carbon with Apple DevTools is Unix like
-
+
// This seems wrong to me, but there is no fix. since
// "MacOS:MyText.txt" is absolute whereas "MyDir:MyText.txt"
// is not. Or maybe ":MyDir:MyText.txt" has to be used? RR.
if (path)
{
register wxChar *tcp;
-
+
tcp = path + wxStrlen (path);
while (--tcp >= path)
{
{
wxChar *path = WXSTRINGCAST path1 ;
register wxChar *tcp;
-
+
tcp = path + wxStrlen (path);
while (--tcp >= path)
{
if (path && *path)
{
static wxChar buf[_MAXPATHLEN];
-
+
// Local copy
wxStrcpy (buf, path);
-
+
int l = wxStrlen(path);
int i = l - 1;
-
+
// Search backward for a backward or forward slash
while (i > -1)
{
#endif
i --;
}
-
+
#if defined(__WXMSW__) || defined(__WXPM__)
// Try Drive specifier
if (wxIsalpha (buf[0]) && buf[1] == wxT(':'))
if (path != wxT(""))
{
wxChar buf[_MAXPATHLEN];
-
+
// Local copy
wxStrcpy (buf, WXSTRINGCAST path);
-
+
int l = path.Length();
int i = l - 1;
#endif
i --;
}
-
+
#if defined(__WXMSW__) || defined(__WXPM__)
// Try Drive specifier
if (wxIsalpha (buf[0]) && buf[1] == wxT(':'))
wxString wxMacFSSpec2MacFilename( const FSSpec *spec )
{
#ifdef __DARWIN__
- FSRef theRef;
- char thePath[FILENAME_MAX];
-
- // convert the FSSpec to an FSRef
- (void) FSpMakeFSRef( spec, &theRef );
- // get the POSIX path associated with the FSRef
- (void) FSRefMakePath( &theRef, (UInt8 *)thePath, sizeof(thePath) );
+ int i;
+ int j;
+ OSErr theErr;
+ OSStatus theStatus;
+ Boolean isDirectory = false;
+ Str255 theParentPath = "\p";
+ FSSpec theParentSpec;
+ FSRef theParentRef;
+ char theFileName[FILENAME_MAX];
+ char thePath[FILENAME_MAX];
+
+ strcpy(thePath, "");
+
+ // GD: Separate file name from path and make a FSRef to the parent
+ // directory. This is necessary since FSRefs cannot reference files
+ // that have not yet been created.
+ // Based on example code from Apple Technical Note TN2022
+ // http://developer.apple.com/technotes/tn/tn2022.html
+
+ // check whether we are converting a directory
+ isDirectory = ((spec->name)[spec->name[0]] == ':');
+ // count length of file name
+ for (i = spec->name[0] - (isDirectory ? 1 : 0); ((spec->name[i] != ':') && (i > 0)); i--);
+ // copy file name
+ // prepend path separator since it will later be appended to the path
+ theFileName[0] = wxFILE_SEP_PATH;
+ for (j = i + 1; j <= spec->name[0] - (isDirectory ? 1 : 0); j++) {
+ theFileName[j - i] = spec->name[j];
+ }
+ theFileName[j - i] = '\0';
+ // copy path if any
+ for (j = 1; j <= i; j++) {
+ theParentPath[++theParentPath[0]] = spec->name[j];
+ }
+ theErr = FSMakeFSSpec(spec->vRefNum, spec->parID, theParentPath, &theParentSpec);
+ if (theErr == noErr) {
+ // convert the FSSpec to an FSRef
+ theErr = FSpMakeFSRef(&theParentSpec, &theParentRef);
+ }
+ if (theErr == noErr) {
+ // get the POSIX path associated with the FSRef
+ theStatus = FSRefMakePath(&theParentRef,
+ (UInt8 *)thePath, sizeof(thePath));
+ }
+ if (theStatus == noErr) {
+ // append file name to path
+ // includes previously prepended path separator
+ strcat(thePath, theFileName);
+ }
// create path string for return value
wxString result( thePath ) ;
(*myPath)[length] = 0 ;
if ((length > 0) && ((*myPath)[length-1] == ':'))
(*myPath)[length-1] = 0 ;
-
+
// create path string for return value
wxString result( (char*) *myPath ) ;
*s = '.' ;
else
*s = '/' ;
-
+
while (*s)
{
if (*s == ':')
// instead of our code if available
//
// NB: 3rd parameter is bFailIfExists i.e. the inverse of overwrite
- return ::CopyFile(file1, file2, !overwrite) != 0;
+ if ( !::CopyFile(file1, file2, !overwrite) )
+ {
+ wxLogSysError(_("Failed to copy the file '%s' to '%s'"),
+ file1.c_str(), file2.c_str());
+
+ return FALSE;
+ }
#elif defined(__WXPM__)
- if (::DosCopy(file2, file2, overwrite ? DCPY_EXISTING : 0) == 0)
- return TRUE;
- else
+ if ( ::DosCopy(file2, file2, overwrite ? DCPY_EXISTING : 0) != 0 )
return FALSE;
#else // !Win32
wxStructStat fbuf;
return FALSE;
}
#endif // OS/2 || Mac
+#endif // __WXMSW__ && __WIN32__
return TRUE;
-#endif // __WXMSW__ && __WIN32__
}
bool
bool wxPathExists(const wxChar *pszPathName)
{
wxString strPath(pszPathName);
+
#ifdef __WINDOWS__
// Windows fails to find directory named "c:\dir\" even if "c:\dir" exists,
// so remove all trailing backslashes from the path - but don't do this for
}
#endif // __WINDOWS__
-#if defined(__WINDOWS__) && !defined(__WXMICROWIN__)
- // Stat can't cope with network paths
- DWORD ret = GetFileAttributes(strPath.c_str());
- DWORD isDir = (ret & FILE_ATTRIBUTE_DIRECTORY);
- return ((ret != 0xffffffff) && (isDir != 0));
-#else
+#if defined(__WIN32__) && !defined(__WXMICROWIN__)
+ // stat() can't cope with network paths
+ DWORD ret = ::GetFileAttributes(strPath);
+
+ return (ret != (DWORD)-1) && (ret & FILE_ATTRIBUTE_DIRECTORY);
+#else // !__WIN32__
wxStructStat st;
#ifndef __VISAGECPP__
(st.st_mode == S_IFDIR);
#endif
-#endif
+#endif // __WIN32__/!__WIN32__
}
// Get a temporary filename, opening and closing the file.
wxString wxFindFirstFile(const wxChar *spec, int flags)
{
- gs_dirPath = wxPathOnly(spec);
+ wxSplitPath(spec, &gs_dirPath, NULL, NULL);
if ( gs_dirPath.IsEmpty() )
gs_dirPath = wxT(".");
if ( gs_dirPath.Last() != wxFILE_SEP_PATH )
if (gs_dir)
delete gs_dir;
gs_dir = new wxDir(gs_dirPath);
-
+
if ( !gs_dir->IsOpened() )
{
wxLogSysError(_("Can not enumerate files '%s'"), spec);
return wxEmptyString;
}
-
+
int dirFlags = 0;
switch (flags)
{
case wxFILE: dirFlags = wxDIR_FILES; break;
default: dirFlags = wxDIR_DIRS | wxDIR_FILES; break;
}
-
+
wxString result;
gs_dir->GetFirst(&result, wxFileNameFromPath(spec), dirFlags);
if ( result.IsEmpty() )
wxString result;
gs_dir->GetNext(&result);
-
+
if ( result.IsEmpty() )
{
wxDELETE(gs_dir);
return result;
}
-
+
return gs_dirPath + result;
}
buf = new wxChar[sz + 1];
}
- bool ok;
+ bool ok = FALSE;
// for the compilers which have Unicode version of _getcwd(), call it
// directly, for the others call the ANSI version and do the translation
-#if wxUSE_UNICODE
+#if !wxUSE_UNICODE
+ #define cbuf buf
+#else // wxUSE_UNICODE
+ bool needsANSI = TRUE;
+
+ #if !defined(HAVE_WGETCWD) || wxUSE_UNICODE_MSLU
+ wxCharBuffer c_buffer(sz);
+ char *cbuf = (char*)(const char*)c_buffer;
+ #endif
+
#ifdef HAVE_WGETCWD
- ok = _wgetcwd(buf, sz) != NULL;
- #else // !HAVE_WGETCWD
- wxCharBuffer cbuf(sz);
+ #if wxUSE_UNICODE_MSLU
+ if ( wxGetOsVersion() != wxWIN95 )
+ #else
+ char *cbuf = NULL; // never really used because needsANSI will always be FALSE
+ #endif
+ {
+ ok = _wgetcwd(buf, sz) != NULL;
+ needsANSI = FALSE;
+ }
#endif
-#endif //
-#if !wxUSE_UNICODE || !defined(HAVE_WGETCWD)
+ if ( needsANSI )
+#endif // wxUSE_UNICODE
+ {
#ifdef _MSC_VER
- ok = _getcwd(buf, sz) != NULL;
+ ok = _getcwd(cbuf, sz) != NULL;
#elif defined(__WXMAC__) && !defined(__DARWIN__)
FSSpec cwdSpec ;
FCBPBRec pb;
cwdSpec.name[0] = 0 ;
wxString res = wxMacFSSpec2MacFilename( &cwdSpec ) ;
- strcpy( buf , res ) ;
- buf[res.length()]=0 ;
+ strcpy( cbuf , res ) ;
+ cbuf[res.length()]=0 ;
ok = TRUE;
}
#elif defined(__VISAGECPP__) || (defined (__OS2__) && defined (__WATCOMC__))
APIRET rc;
rc = ::DosQueryCurrentDir( 0 // current drive
- ,buf
+ ,cbuf
,(PULONG)&sz
);
ok = rc != 0;
#else // !Win32/VC++ !Mac !OS2
- ok = getcwd(buf, sz) != NULL;
+ ok = getcwd(cbuf, sz) != NULL;
#endif // platform
-#endif // !wxUSE_UNICODE || !HAVE_WGETCWD
+
+ #if wxUSE_UNICODE
+ // finally convert the result to Unicode if needed
+ wxConvFile.MB2WC(buf, cbuf, sz);
+ #endif // wxUSE_UNICODE
+ }
if ( !ok )
{
}
#endif // __DJGPP__
-#ifdef __CYGWIN10__
- // another example of DOS/Unix mix
+#ifdef __CYGWIN__
+ // another example of DOS/Unix mix (Cygwin)
wxString pathUnix = buf;
cygwin_conv_to_full_win32_path(pathUnix, buf);
-#endif // __CYGWIN10__
-
- // finally convert the result to Unicode if needed
-#if wxUSE_UNICODE && !defined(HAVE_WGETCWD)
- wxConvFile.MB2WC(buf, cbuf, sz);
-#endif // wxUSE_UNICODE
+#endif // __CYGWIN__
}
return buf;
+
+#if !wxUSE_UNICODE
+ #undef cbuf
+#endif
}
wxString wxGetCwd()
#ifdef __VISUALC__
#pragma warning(default:4706) // assignment within conditional expression
#endif // VC++
-
-//------------------------------------------------------------------------
-// Missing functions in Unicode for Win9x
-//------------------------------------------------------------------------
-
-// NB: MSLU only covers Win32 API, it doesn't provide Unicode implementation of
-// libc functions. Unfortunately, some of MSVCRT wchar_t functions
-// (e.g. _wopen) don't work on Windows 9x, so we have to workaround it
-// by calling the char version. We still want to use wchar_t version on
-// NT/2000/XP, though, because they allow for Unicode file names.
-#if wxUSE_UNICODE_MSLU
-
- #if defined( __VISUALC__ ) \
- || ( defined(__MINGW32__) && wxCHECK_W32API_VERSION( 0, 5 ) ) \
- || ( defined(__MWERKS__) && defined(__WXMSW__) )
- WXDLLEXPORT int wxOpen(const wxChar *name, int flags, int mode)
- {
- if ( wxGetOsVersion() == wxWINDOWS_NT )
- return _wopen(name, flags, mode);
- else
- return _open(wxConvFile.cWX2MB(name), flags, mode);
- }
- #endif
-
-#endif // wxUSE_UNICODE_MSLU