X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a2b772607a87ffe6fe9af8c0b64b7259ef10a4a4..df1f4832e5e08438255594172b4c2b31b34f6453:/src/common/filename.cpp diff --git a/src/common/filename.cpp b/src/common/filename.cpp index 84af36bbf2..18b8b2759e 100644 --- a/src/common/filename.cpp +++ b/src/common/filename.cpp @@ -87,6 +87,9 @@ // For GetShort/LongPathName #ifdef __WIN32__ #include "wx/msw/wrapwin.h" +#if defined(__MINGW32__) +#include "wx/msw/gccpriv.h" +#endif #endif #ifdef __WXWINCE__ @@ -234,8 +237,8 @@ static void ConvertWxToFileTime(FILETIME *ft, const wxDateTime& dt) { SYSTEMTIME st; st.wDay = dt.GetDay(); - st.wMonth = dt.GetMonth() + 1; - st.wYear = dt.GetYear(); + st.wMonth = (WORD)(dt.GetMonth() + 1); + st.wYear = (WORD)dt.GetYear(); st.wHour = dt.GetHour(); st.wMinute = dt.GetMinute(); st.wSecond = dt.GetSecond(); @@ -450,6 +453,18 @@ void wxFileName::Assign(const wxString& fullpathOrig, Assign(volume, path, name, ext, format); } +void wxFileName::Assign(const wxString& pathOrig, + const wxString& name, + const wxString& ext, + wxPathFormat format) +{ + wxString volume, + path; + SplitVolume(pathOrig, &volume, &path, format); + + Assign(volume, path, name, ext, format); +} + void wxFileName::AssignDir(const wxString& dir, wxPathFormat format) { Assign(dir, _T(""), format); @@ -677,7 +692,7 @@ wxFileName::CreateTempFileName(const wxString& prefix, wxFile *fileTemp) else // mkstemp() succeeded { path = wxConvFile.cMB2WX( (const char*) buf ); - + // avoid leaking the fd if ( fileTemp ) { @@ -794,12 +809,12 @@ bool wxFileName::Mkdir( const wxString& dir, int perm, int flags ) size_t count = dirs.GetCount(); for ( size_t i = 0; i < count; i++ ) { - if ( i > 0 || + if ( i > 0 || #if defined(__WXMAC__) && !defined(__DARWIN__) - // relative pathnames are exactely the other way round under mac... - !filename.IsAbsolute() + // relative pathnames are exactely the other way round under mac... + !filename.IsAbsolute() #else - filename.IsAbsolute() + filename.IsAbsolute() #endif ) currPath += wxFILE_SEP_PATH; @@ -951,7 +966,7 @@ bool wxFileName::Normalize(int flags, m_dirs.Add(dir); } - + #if defined(__WIN32__) && !defined(__WXWINCE__) && wxUSE_OLE if ( (flags & wxPATH_NORM_SHORTCUT) ) { @@ -1021,49 +1036,54 @@ bool wxFileName::GetShortcutTarget(const wxString& shortcutPath, wxString& targe { wxString path, file, ext; wxSplitPath(shortcutPath, & path, & file, & ext); - - HRESULT hres; - IShellLink* psl; - bool success = FALSE; + + HRESULT hres; + IShellLink* psl; + bool success = false; // Assume it's not a shortcut if it doesn't end with lnk if (ext.Lower() != wxT("lnk")) - return FALSE; - - // create a ShellLink object - hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, - IID_IShellLink, (LPVOID*) &psl); - - if (SUCCEEDED(hres)) - { - IPersistFile* ppf; - hres = psl->QueryInterface( IID_IPersistFile, (LPVOID *) &ppf); - if (SUCCEEDED(hres)) - { - WCHAR wsz[MAX_PATH]; - - MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, shortcutPath.mb_str(), -1, wsz, - MAX_PATH); - - hres = ppf->Load(wsz, 0); - if (SUCCEEDED(hres)) - { + return false; + + // create a ShellLink object + hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, + IID_IShellLink, (LPVOID*) &psl); + + if (SUCCEEDED(hres)) + { + IPersistFile* ppf; + hres = psl->QueryInterface( IID_IPersistFile, (LPVOID *) &ppf); + if (SUCCEEDED(hres)) + { + WCHAR wsz[MAX_PATH]; + + MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, shortcutPath.mb_str(), -1, wsz, + MAX_PATH); + + hres = ppf->Load(wsz, 0); + if (SUCCEEDED(hres)) + { wxChar buf[2048]; - psl->GetPath(buf, 2048, NULL, SLGP_UNCPRIORITY); - targetFilename = wxString(buf); + // Wrong prototype in early versions +#if defined(__MINGW32__) && !wxCHECK_W32API_VERSION(2, 2) + psl->GetPath((CHAR*) buf, 2048, NULL, SLGP_UNCPRIORITY); +#else + psl->GetPath(buf, 2048, NULL, SLGP_UNCPRIORITY); +#endif + targetFilename = wxString(buf); success = (shortcutPath != targetFilename); - psl->GetArguments(buf, 2048); + psl->GetArguments(buf, 2048); wxString args(buf); if (!args.IsEmpty() && arguments) { *arguments = args; - } - } - } - } - psl->Release(); - return success; + } + } + } + } + psl->Release(); + return success; } #endif @@ -1269,10 +1289,8 @@ wxString wxFileName::GetPathTerminators(wxPathFormat format) bool wxFileName::IsPathSeparator(wxChar ch, wxPathFormat format) { // wxString::Find() doesn't work as expected with NUL - it will always find - // it, so it is almost surely a bug if this function is called with NUL arg - wxASSERT_MSG( ch != _T('\0'), _T("shouldn't be called with NUL") ); - - return GetPathSeparators(format).Find(ch) != wxNOT_FOUND; + // it, so test for it separately + return ch != _T('\0') && GetPathSeparators(format).Find(ch) != wxNOT_FOUND; } // ---------------------------------------------------------------------------- @@ -2040,14 +2058,14 @@ bool wxFileName::MacSetTypeAndCreator( wxUint32 type , wxUint32 creator ) if ( wxMacPathToFSRef( GetFullPath() , &fsRef ) == noErr ) { - if ( FSGetCatalogInfo (&fsRef, kFSCatInfoFinderInfo, &catInfo, NULL, NULL, NULL) == noErr ) - { - finfo = (FileInfo*)&catInfo.finderInfo; - finfo->fileType = type ; - finfo->fileCreator = creator ; - FSSetCatalogInfo( &fsRef, kFSCatInfoFinderInfo, &catInfo ) ; + if ( FSGetCatalogInfo (&fsRef, kFSCatInfoFinderInfo, &catInfo, NULL, NULL, NULL) == noErr ) + { + finfo = (FileInfo*)&catInfo.finderInfo; + finfo->fileType = type ; + finfo->fileCreator = creator ; + FSSetCatalogInfo( &fsRef, kFSCatInfoFinderInfo, &catInfo ) ; return true ; - } + } } return false ; } @@ -2060,13 +2078,13 @@ bool wxFileName::MacGetTypeAndCreator( wxUint32 *type , wxUint32 *creator ) if ( wxMacPathToFSRef( GetFullPath() , &fsRef ) == noErr ) { - if ( FSGetCatalogInfo (&fsRef, kFSCatInfoFinderInfo, &catInfo, NULL, NULL, NULL) == noErr ) - { - finfo = (FileInfo*)&catInfo.finderInfo; - *type = finfo->fileType ; - *creator = finfo->fileCreator ; + if ( FSGetCatalogInfo (&fsRef, kFSCatInfoFinderInfo, &catInfo, NULL, NULL, NULL) == noErr ) + { + finfo = (FileInfo*)&catInfo.finderInfo; + *type = finfo->fileType ; + *creator = finfo->fileCreator ; return true ; - } + } } return false ; }