added a fix for cygwin and cleaned up wxGetWorkingDirectory()
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@13584 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
ab2a521063
commit
13b1f8a7e6
@ -123,11 +123,18 @@
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// TODO: Borland probably has _wgetcwd as well?
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#define HAVE_WGETCWD
|
||||||
|
#endif
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// constants
|
// constants
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
#define _MAXPATHLEN 500
|
#ifndef _MAXPATHLEN
|
||||||
|
#define _MAXPATHLEN 1024
|
||||||
|
#endif
|
||||||
|
|
||||||
extern wxChar *wxBuffer;
|
extern wxChar *wxBuffer;
|
||||||
|
|
||||||
@ -274,8 +281,8 @@ wxString wxPathList::FindAbsoluteValidPath (const wxString& file)
|
|||||||
return f;
|
return f;
|
||||||
|
|
||||||
wxString buf;
|
wxString buf;
|
||||||
wxGetWorkingDirectory(buf.GetWriteBuf(_MAXPATHLEN), _MAXPATHLEN - 1);
|
wxGetWorkingDirectory(wxStringBuffer(buf, _MAXPATHLEN), _MAXPATHLEN);
|
||||||
buf.UngetWriteBuf();
|
|
||||||
if ( !wxEndsWithPathSeparator(buf) )
|
if ( !wxEndsWithPathSeparator(buf) )
|
||||||
{
|
{
|
||||||
buf += wxFILE_SEP_PATH;
|
buf += wxFILE_SEP_PATH;
|
||||||
@ -1369,31 +1376,27 @@ wxString wxFindNextFile()
|
|||||||
// copies into buf.
|
// copies into buf.
|
||||||
wxChar *wxGetWorkingDirectory(wxChar *buf, int sz)
|
wxChar *wxGetWorkingDirectory(wxChar *buf, int sz)
|
||||||
{
|
{
|
||||||
if (!buf)
|
if ( !buf )
|
||||||
buf = new wxChar[sz+1];
|
|
||||||
#if wxUSE_UNICODE
|
|
||||||
char *cbuf = new char[sz+1];
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
if (_getcwd(cbuf, sz) == NULL) {
|
|
||||||
#elif defined(__WXMAC__) && !defined(__DARWIN__)
|
|
||||||
enum
|
|
||||||
{
|
{
|
||||||
SFSaveDisk = 0x214, CurDirStore = 0x398
|
buf = new wxChar[sz + 1];
|
||||||
};
|
}
|
||||||
FSSpec cwdSpec ;
|
|
||||||
|
|
||||||
FSMakeFSSpec( - *(short *) SFSaveDisk , *(long *) CurDirStore , NULL , &cwdSpec ) ;
|
bool ok;
|
||||||
wxString res = wxMacFSSpec2UnixFilename( &cwdSpec ) ;
|
|
||||||
strcpy( buf , res ) ;
|
// for the compilers which have Unicode version of _getcwd(), call it
|
||||||
if (0) {
|
// directly, for the others call the ANSI version and do the translation
|
||||||
#else
|
#if wxUSE_UNICODE
|
||||||
if (getcwd(cbuf, sz) == NULL) {
|
#ifdef HAVE_WGETCWD
|
||||||
#endif
|
ok = _wgetcwd(buf, sz) != NULL;
|
||||||
delete [] cbuf;
|
#else // !HAVE_WGETCWD
|
||||||
#else // wxUnicode
|
wxCharBuffer cbuf(sz);
|
||||||
#ifdef _MSC_VER
|
#endif
|
||||||
if (_getcwd(buf, sz) == NULL) {
|
#endif //
|
||||||
#elif defined(__WXMAC__) && !defined(__DARWIN__)
|
|
||||||
|
#if !wxUSE_UNICODE || !defined(HAVE_WGETCWD)
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
ok = _getcwd(buf, sz) != NULL;
|
||||||
|
#elif defined(__WXMAC__) && !defined(__DARWIN__)
|
||||||
FSSpec cwdSpec ;
|
FSSpec cwdSpec ;
|
||||||
FCBPBRec pb;
|
FCBPBRec pb;
|
||||||
OSErr error;
|
OSErr error;
|
||||||
@ -1412,60 +1415,66 @@ wxChar *wxGetWorkingDirectory(wxChar *buf, int sz)
|
|||||||
|
|
||||||
strcpy( buf , res ) ;
|
strcpy( buf , res ) ;
|
||||||
buf[res.length()]=0 ;
|
buf[res.length()]=0 ;
|
||||||
|
|
||||||
|
ok = TRUE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
buf[0] = 0 ;
|
|
||||||
/*
|
|
||||||
this version will not always give back the application directory on mac
|
|
||||||
enum
|
|
||||||
{
|
{
|
||||||
SFSaveDisk = 0x214, CurDirStore = 0x398
|
ok = FALSE;
|
||||||
};
|
}
|
||||||
FSSpec cwdSpec ;
|
#elif defined(__VISAGECPP__) || (defined (__OS2__) && defined (__WATCOMC__))
|
||||||
|
|
||||||
FSMakeFSSpec( - *(short *) SFSaveDisk , *(long *) CurDirStore , NULL , &cwdSpec ) ;
|
|
||||||
wxString res = wxMacFSSpec2UnixFilename( &cwdSpec ) ;
|
|
||||||
strcpy( buf , res ) ;
|
|
||||||
*/
|
|
||||||
if (0) {
|
|
||||||
#elif defined(__VISAGECPP__) || (defined (__OS2__) && defined (__WATCOMC__))
|
|
||||||
APIRET rc;
|
APIRET rc;
|
||||||
rc = ::DosQueryCurrentDir( 0 // current drive
|
rc = ::DosQueryCurrentDir( 0 // current drive
|
||||||
,buf
|
,buf
|
||||||
,(PULONG)&sz
|
,(PULONG)&sz
|
||||||
);
|
);
|
||||||
if (rc != 0) {
|
ok = rc != 0;
|
||||||
#else
|
#else // !Win32/VC++ !Mac !OS2
|
||||||
if (getcwd(buf, sz) == NULL) {
|
ok = getcwd(buf, sz) != NULL;
|
||||||
#endif
|
#endif // platform
|
||||||
#endif
|
#endif // !wxUSE_UNICODE || !HAVE_WGETCWD
|
||||||
buf[0] = wxT('.');
|
|
||||||
buf[1] = wxT('\0');
|
|
||||||
}
|
|
||||||
#if wxUSE_UNICODE
|
|
||||||
else {
|
|
||||||
wxConvFile.MB2WC(buf, cbuf, sz);
|
|
||||||
delete [] cbuf;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
if ( !ok )
|
||||||
|
{
|
||||||
|
wxLogSysError(_("Failed to get the working directory"));
|
||||||
|
|
||||||
|
// VZ: the old code used to return "." on error which didn't make any
|
||||||
|
// sense at all to me - empty string is a better error indicator
|
||||||
|
// (NULL might be even better but I'm afraid this could lead to
|
||||||
|
// problems with the old code assuming the return is never NULL)
|
||||||
|
buf[0] = _T('\0');
|
||||||
|
}
|
||||||
|
else // ok, but we might need to massage the path into the right format
|
||||||
|
{
|
||||||
#ifdef __DJGPP__
|
#ifdef __DJGPP__
|
||||||
// VS: DJGPP is a strange mix of DOS and UNIX API and returns paths with
|
// VS: DJGPP is a strange mix of DOS and UNIX API and returns paths
|
||||||
// / deliminers. We don't like that.
|
// with / deliminers. We don't like that.
|
||||||
for (wxChar *ch = buf; *ch; ch++)
|
for (wxChar *ch = buf; *ch; ch++)
|
||||||
if (*ch == wxT('/')) *ch = wxT('\\');
|
{
|
||||||
#endif
|
if (*ch == wxT('/'))
|
||||||
|
*ch = wxT('\\');
|
||||||
|
}
|
||||||
|
#endif // __DJGPP__
|
||||||
|
|
||||||
|
#ifdef __CYGWIN10__
|
||||||
|
// another example of DOS/Unix mix
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString wxGetCwd()
|
wxString wxGetCwd()
|
||||||
{
|
{
|
||||||
static const size_t maxPathLen = 1024;
|
|
||||||
|
|
||||||
wxString str;
|
wxString str;
|
||||||
wxGetWorkingDirectory(str.GetWriteBuf(maxPathLen), maxPathLen);
|
wxGetWorkingDirectory(wxStringBuffer(str, _MAXPATHLEN), _MAXPATHLEN);
|
||||||
str.UngetWriteBuf();
|
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user