X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9a83f860948059b0273b5cc6d9e43fadad3ebfca..87f0b1323b7ac77f02133b836c8dfee63b0fd387:/src/common/mimecmn.cpp?ds=sidebyside diff --git a/src/common/mimecmn.cpp b/src/common/mimecmn.cpp index 32430d97d2..930f70a31e 100644 --- a/src/common/mimecmn.cpp +++ b/src/common/mimecmn.cpp @@ -46,9 +46,9 @@ #include // implementation classes: -#if defined(__WXMSW__) +#if defined(__WINDOWS__) #include "wx/msw/mimetype.h" -#elif ( defined(__WXMAC__) && wxOSX_USE_CARBON ) +#elif ( defined(__DARWIN__) ) #include "wx/osx/mimetype.h" #elif defined(__WXPM__) || defined (__EMX__) #include "wx/os2/mimetype.h" @@ -192,22 +192,28 @@ wxString wxFileType::ExpandCommand(const wxString& command, { bool hasFilename = false; + // We consider that only the file names with spaces in them need to be + // handled specially. This is not perfect, but this can be done easily + // under all platforms while handling the file names with quotes in them, + // for example, needs to be done differently. + const bool needToQuoteFilename = params.GetFileName().find_first_of(" \t") + != wxString::npos; + wxString str; for ( const wxChar *pc = command.c_str(); *pc != wxT('\0'); pc++ ) { if ( *pc == wxT('%') ) { switch ( *++pc ) { case wxT('s'): - // '%s' expands into file name (quoted because it might - // contain spaces) - except if there are already quotes - // there because otherwise some programs may get confused - // by double double quotes -#if 0 - if ( *(pc - 2) == wxT('"') ) - str << params.GetFileName(); - else + // don't quote the file name if it's already quoted: notice + // that we check for a quote following it and not preceding + // it as at least under Windows we can have commands + // containing "file://%s" (with quotes) in them so the + // argument may be quoted even if there is no quote + // directly before "%s" itself + if ( needToQuoteFilename && pc[1] != '"' ) str << wxT('"') << params.GetFileName() << wxT('"'); -#endif - str << params.GetFileName(); + else + str << params.GetFileName(); hasFilename = true; break; @@ -264,8 +270,14 @@ wxString wxFileType::ExpandCommand(const wxString& command, #ifdef __UNIX__ && !str.StartsWith(wxT("test ")) #endif // Unix - ) { - str << wxT(" < '") << params.GetFileName() << wxT('\''); + ) + { + str << wxT(" < "); + if ( needToQuoteFilename ) + str << '"'; + str << params.GetFileName(); + if ( needToQuoteFilename ) + str << '"'; } return str; @@ -334,9 +346,9 @@ bool wxFileType::GetIcon(wxIconLocation *iconLoc) const if ( iconLoc ) { iconLoc->SetFileName(m_info->GetIconFile()); -#ifdef __WXMSW__ +#ifdef __WINDOWS__ iconLoc->SetIndex(m_info->GetIconIndex()); -#endif // __WXMSW__ +#endif // __WINDOWS__ } return true; @@ -432,9 +444,9 @@ size_t wxFileType::GetAllCommands(wxArrayString *verbs, if ( commands ) commands->Clear(); -#if defined (__WXMSW__) || defined(__UNIX__) +#if defined (__WINDOWS__) || defined(__UNIX__) return m_impl->GetAllCommands(verbs, commands, params); -#else // !__WXMSW__ || Unix +#else // !__WINDOWS__ || __UNIX__ // we don't know how to retrieve all commands, so just try the 2 we know // about size_t count = 0; @@ -459,12 +471,12 @@ size_t wxFileType::GetAllCommands(wxArrayString *verbs, } return count; -#endif // __WXMSW__/| __UNIX__ +#endif // __WINDOWS__/| __UNIX__ } bool wxFileType::Unassociate() { -#if defined(__WXMSW__) +#if defined(__WINDOWS__) return m_impl->Unassociate(); #elif defined(__UNIX__) return m_impl->Unassociate(this); @@ -478,7 +490,7 @@ bool wxFileType::SetCommand(const wxString& cmd, const wxString& verb, bool overwriteprompt) { -#if defined (__WXMSW__) || defined(__UNIX__) +#if defined (__WINDOWS__) || defined(__UNIX__) return m_impl->SetCommand(cmd, verb, overwriteprompt); #else wxUnusedVar(cmd); @@ -492,7 +504,7 @@ bool wxFileType::SetCommand(const wxString& cmd, bool wxFileType::SetDefaultIcon(const wxString& cmd, int index) { wxString sTmp = cmd; -#ifdef __WXMSW__ +#ifdef __WINDOWS__ // VZ: should we do this? // chris elliott : only makes sense in MS windows if ( sTmp.empty() ) @@ -500,7 +512,7 @@ bool wxFileType::SetDefaultIcon(const wxString& cmd, int index) #endif wxCHECK_MSG( !sTmp.empty(), false, wxT("need the icon file") ); -#if defined (__WXMSW__) || defined(__UNIX__) +#if defined (__WINDOWS__) || defined(__UNIX__) return m_impl->SetDefaultIcon (cmd, index); #else wxUnusedVar(index); @@ -598,7 +610,7 @@ wxMimeTypesManager::Associate(const wxFileTypeInfo& ftInfo) { EnsureImpl(); -#if defined(__WXMSW__) || defined(__UNIX__) +#if defined(__WINDOWS__) || defined(__UNIX__) return m_impl->Associate(ftInfo); #else // other platforms wxUnusedVar(ftInfo); @@ -737,8 +749,7 @@ public: if ( gs_mimeTypesManager.m_impl != NULL ) { - delete gs_mimeTypesManager.m_impl; - gs_mimeTypesManager.m_impl = NULL; + wxDELETE(gs_mimeTypesManager.m_impl); gs_mimeTypesManager.m_fallbacks.Clear(); } }