X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e75491071dbefcada61175e3eb89ce4edf335983..1a8557b1430ee9e30e1cb4fb355f3be6fa38d234:/src/common/filefn.cpp?ds=sidebyside diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index cef3b561f0..e5b536b0a6 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -112,7 +112,7 @@ #define _MAXPATHLEN 500 -extern char *wxBuffer; +extern wxChar *wxBuffer; #ifdef __WXMAC__ @@ -122,9 +122,7 @@ extern char *wxBuffer; #include "fspcompa.h" #endif -#if !USE_SHARED_LIBRARIES IMPLEMENT_DYNAMIC_CLASS(wxPathList, wxStringList) -#endif // ---------------------------------------------------------------------------- // private globals @@ -612,7 +610,6 @@ wxChar *wxExpandPath(wxChar *buf, const wxChar *name) return wxRealPath(buf); } - /* Contract Paths to be build upon an environment variable component: @@ -893,7 +890,7 @@ wxString wxUnix2MacFilename (const char *str) return wxString (sMacFileNameConversion) ; } -wxString wxMacFSSpec2MacFilename( const FSSpec *spec ) +wxString wxMacFSSpec2MacFilename( const FSSpec *spec ) { Handle myPath ; short length ; @@ -945,10 +942,10 @@ wxDos2UnixFilename (char *s) } void -#ifdef __WXMSW__ +#if defined(__WXMSW__) || defined(__WXPM__) wxUnix2DosFilename (char *s) #else -wxUnix2DosFilename (char *WXUNUSED(s) ) +wxUnix2DosFilename (char *WXUNUSED(s) ) #endif { // Yes, I really mean this to happen under DOS only! JACS @@ -978,9 +975,9 @@ wxConcatFiles (const wxString& file1, const wxString& file2, const wxString& fil (fp2 = fopen (wxUnix2MacFilename( file2 ), "rb")) == NULL || (fp3 = fopen (wxUnix2MacFilename( outfile ), "wb")) == NULL) #else - if ((fp1 = fopen (WXSTRINGCAST file1, "rb")) == NULL || - (fp2 = fopen (WXSTRINGCAST file2, "rb")) == NULL || - (fp3 = fopen (outfile, "wb")) == NULL) + if ((fp1 = wxFopen (WXSTRINGCAST file1, wxT("rb"))) == NULL || + (fp2 = wxFopen (WXSTRINGCAST file2, wxT("rb"))) == NULL || + (fp3 = wxFopen (outfile, wxT("wb"))) == NULL) #endif { if (fp1) @@ -1020,9 +1017,9 @@ wxCopyFile (const wxString& file1, const wxString& file2) return FALSE; if ((fd2 = fopen (wxUnix2MacFilename( file2 ), "wb")) == NULL) #else - if ((fd1 = fopen (WXSTRINGCAST file1, "rb")) == NULL) + if ((fd1 = wxFopen (WXSTRINGCAST file1, wxT("rb"))) == NULL) return FALSE; - if ((fd2 = fopen (WXSTRINGCAST file2, "wb")) == NULL) + if ((fd2 = wxFopen (WXSTRINGCAST file2, wxT("wb"))) == NULL) #endif { fclose (fd1); @@ -1096,7 +1093,7 @@ bool wxMkdir(const wxString& dir, int perm) bool wxRmdir(const wxString& dir, int WXUNUSED(flags)) { #ifdef __VMS__ - return FALSE; + return FALSE; //to be changed since rmdir exists in VMS7.x #elif defined( __WXMAC__ ) return (rmdir(wxUnix2MacFilename( dir )) == 0); #else @@ -1114,7 +1111,7 @@ bool wxRmdir(const wxString& dir, int WXUNUSED(flags)) bool wxDirExists(const wxString& dir) { #ifdef __VMS__ - return FALSE; + return FALSE; //To be changed since stat exists in VMS7.x #elif !defined(__WXMSW__) struct stat sbuf; return (stat(dir.fn_str(), &sbuf) != -1) && S_ISDIR(sbuf.st_mode) ? TRUE : FALSE; @@ -1220,6 +1217,18 @@ wxChar *wxGetTempFileName(const wxString& prefix, wxChar *buf) #endif } +bool wxGetTempFileName(const wxString& prefix, wxString& buf) +{ + wxChar buf2[512]; + if (wxGetTempFileName(prefix, buf2) != (wxChar*) NULL) + { + buf = buf2; + return TRUE; + } + else + return FALSE; +} + // Get first file name matching given wild card. #ifdef __UNIX__ @@ -1227,7 +1236,7 @@ wxChar *wxGetTempFileName(const wxString& prefix, wxChar *buf) // Get first file name matching given wild card. // Flags are reserved for future use. -#ifndef __VMS__ +#if !defined( __VMS__ ) || ( __VMS_VER >= 70000000 ) static DIR *gs_dirStream = (DIR *) NULL; static wxString gs_strFileSpec; static int gs_findFlags = 0; @@ -1237,7 +1246,7 @@ wxString wxFindFirstFile(const wxChar *spec, int flags) { wxString result; -#ifndef __VMS__ +#if !defined( __VMS__ ) || ( __VMS_VER >= 70000000 ) if (gs_dirStream) closedir(gs_dirStream); // edz 941103: better housekeping @@ -1266,7 +1275,7 @@ wxString wxFindFirstFile(const wxChar *spec, int flags) { result = wxFindNextFile(); } -#endif // !VMS +#endif // !VMS6.x or earlier return result; } @@ -1275,7 +1284,7 @@ wxString wxFindNextFile() { wxString result; -#ifndef __VMS__ +#if !defined( __VMS__ ) || ( __VMS_VER >= 70000000 ) wxCHECK_MSG( gs_dirStream, result, wxT("must call wxFindFirstFile first") ); // Find path only so we can concatenate @@ -1293,7 +1302,9 @@ wxString wxFindNextFile() nextDir != NULL; nextDir = readdir(gs_dirStream) ) { - if (wxMatchWild(name, nextDir->d_name)) + if (wxMatchWild(name, nextDir->d_name, FALSE) && // RR: added FALSE to find hidden files + strcmp(nextDir->d_name, ".") && + strcmp(nextDir->d_name, "..") ) { result.Empty(); if ( !path.IsEmpty() ) @@ -1332,11 +1343,89 @@ wxString wxFindNextFile() closedir(gs_dirStream); gs_dirStream = (DIR *) NULL; -#endif // !VMS +#endif // !VMS6.2 or earlier return result; } +#elif defined(__WXMAC__) + +struct MacDirectoryIterator +{ + CInfoPBRec m_CPB ; + wxInt16 m_index ; + long m_dirId ; + Str255 m_name ; +} ; + +static int g_iter_flags ; + +static MacDirectoryIterator g_iter ; + +wxString wxFindFirstFile(const wxChar *spec, int flags) +{ + wxString result; + + g_iter_flags = flags; /* MATTHEW: [5] Remember flags */ + + // Find path only so we can concatenate found file onto path + wxString path(wxPathOnly(spec)); + if ( !path.IsEmpty() ) + result << path << wxT('\\'); + + FSSpec fsspec ; + + wxUnixFilename2FSSpec( result , &fsspec ) ; + g_iter.m_CPB.hFileInfo.ioVRefNum = fsspec.vRefNum ; + g_iter.m_CPB.hFileInfo.ioNamePtr = g_iter.m_name ; + g_iter.m_index = 0 ; + + Boolean isDir ; + FSpGetDirectoryID( &fsspec , &g_iter.m_dirId , &isDir ) ; + if ( !isDir ) + return wxEmptyString ; + + return wxFindNextFile( ) ; +} + +wxString wxFindNextFile() +{ + wxString result; + + short err = noErr ; + + while ( err == noErr ) + { + g_iter.m_index++ ; + g_iter.m_CPB.dirInfo.ioFDirIndex = g_iter.m_index; + g_iter.m_CPB.dirInfo.ioDrDirID = g_iter.m_dirId; /* we need to do this every time */ + err = PBGetCatInfoSync((CInfoPBPtr)&g_iter.m_CPB); + if ( err != noErr ) + break ; + + if ( ( g_iter.m_CPB.dirInfo.ioFlAttrib & ioDirMask) != 0 && (g_iter_flags & wxDIR) ) // we have a directory + break ; + + if ( ( g_iter.m_CPB.dirInfo.ioFlAttrib & ioDirMask) == 0 && !(g_iter_flags & wxFILE ) ) + continue ; + + // hit ! + break ; + } + if ( err != noErr ) + { + return wxEmptyString ; + } + FSSpec spec ; + + FSMakeFSSpecCompat(g_iter.m_CPB.hFileInfo.ioVRefNum, + g_iter.m_dirId, + g_iter.m_name, + &spec) ; + + return wxMacFSSpec2UnixFilename( &spec ) ; +} + #elif defined(__WXMSW__) #ifdef __WIN32__ @@ -1512,23 +1601,34 @@ wxChar *wxGetWorkingDirectory(wxChar *buf, int sz) #ifdef _MSC_VER if (_getcwd(cbuf, sz) == NULL) { #elif defined( __WXMAC__) - enum - { - SFSaveDisk = 0x214, CurDirStore = 0x398 + enum + { + SFSaveDisk = 0x214, CurDirStore = 0x398 }; FSSpec cwdSpec ; FSMakeFSSpec( - *(short *) SFSaveDisk , *(long *) CurDirStore , NULL , &cwdSpec ) ; wxString res = wxMacFSSpec2UnixFilename( &cwdSpec ) ; strcpy( buf , res ) ; - if (0) + if (0) { #else if (getcwd(cbuf, sz) == NULL) { #endif delete [] cbuf; -#else +#else // wxUnicode #ifdef _MSC_VER if (_getcwd(buf, sz) == NULL) { +#elif defined( __WXMAC__) + enum + { + SFSaveDisk = 0x214, CurDirStore = 0x398 + }; + FSSpec cwdSpec ; + + FSMakeFSSpec( - *(short *) SFSaveDisk , *(long *) CurDirStore , NULL , &cwdSpec ) ; + wxString res = wxMacFSSpec2UnixFilename( &cwdSpec ) ; + strcpy( buf , res ) ; + if (0) { #else if (getcwd(buf, sz) == NULL) { #endif