/////////////////////////////////////////////////////////////////////////////
-// Name: msw/mimetype.cpp
+// Name: src/msw/mimetype.cpp
// Purpose: classes and functions to manage MIME types
// Author: Vadim Zeitlin
// Modified by:
// Licence: wxWindows licence (part of wxExtra library)
/////////////////////////////////////////////////////////////////////////////
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
-#pragma implementation "mimetype.h"
-#endif
-
// for compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
- #pragma hdrstop
+ #pragma hdrstop
#endif
#if wxUSE_MIMETYPE
+#include "wx/msw/mimetype.h"
+
#ifndef WX_PRECOMP
+ #include "wx/dynarray.h"
#include "wx/string.h"
+ #include "wx/intl.h"
+ #include "wx/log.h"
+ #include "wx/crt.h"
#if wxUSE_GUI
#include "wx/icon.h"
#include "wx/msgdlg.h"
#endif
#endif //WX_PRECOMP
-#include "wx/log.h"
#include "wx/file.h"
#include "wx/iconloc.h"
-#include "wx/intl.h"
-#include "wx/dynarray.h"
#include "wx/confbase.h"
#ifdef __WXMSW__
#include "wx/msw/private.h"
#endif // OS
-#include "wx/msw/mimetype.h"
-
// other standard headers
#include <ctype.h>
// in case we're compiling in non-GUI mode
-class WXDLLEXPORT wxIcon;
+class WXDLLIMPEXP_FWD_CORE wxIcon;
// These classes use Windows registry to retrieve the required information.
//
// get the command to use
// ----------------------------------------------------------------------------
-wxString wxFileTypeImpl::GetCommand(const wxChar *verb) const
+static wxString wxFileTypeImplGetCurVer(const wxString& progId)
+{
+ wxRegKey key(wxRegKey::HKCR, progId + wxT("\\CurVer"));
+ if (key.Exists())
+ {
+ wxString value;
+ if (key.QueryValue(wxEmptyString, value))
+ return value;
+ }
+ return progId;
+}
+
+wxString wxFileTypeImpl::GetCommand(const wxString& verb) const
{
// suppress possible error messages
wxLogNull nolog;
wxString strKey;
- if ( wxRegKey(wxRegKey::HKCR, m_ext + _T("\\shell")).Exists() )
+ {
+ wxRegKey explorerKey(wxRegKey::HKCU, wxT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\") + m_ext);
+ if (explorerKey.Exists())
+ {
+ if (explorerKey.Open(wxRegKey::Read))
+ {
+ if (explorerKey.QueryValue(wxT("Progid"), strKey))
+ {
+ strKey = wxFileTypeImplGetCurVer(strKey);
+ }
+ }
+ }
+ }
+
+ if (!strKey && wxRegKey(wxRegKey::HKCR, m_ext + _T("\\shell")).Exists())
strKey = m_ext;
- if ( wxRegKey(wxRegKey::HKCR, m_strFileType + _T("\\shell")).Exists() )
- strKey = m_strFileType;
+
+ if ( !strKey && !m_strFileType.empty())
+ {
+ wxString fileType = wxFileTypeImplGetCurVer(m_strFileType);
+ if (wxRegKey(wxRegKey::HKCR, fileType + _T("\\shell")).Exists())
+ strKey = fileType;
+ }
if ( !strKey )
{
_T("Associate() needs extension") );
bool ok;
- int iExtCount = 0 ;
+ size_t iExtCount = 0;
wxString filetype;
wxString extWithDot;