]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/mimetype.cpp
use SetMenuItemInfo() to update the item label to avoid reseting its bitmap and so...
[wxWidgets.git] / src / msw / mimetype.cpp
index 4720084cba385a5c37038760939a3b9ce709b5dc..a7d29114c96519a84e8bfbe9be04b28d86840bc2 100644 (file)
@@ -25,6 +25,7 @@
     #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"
@@ -44,7 +45,7 @@
 #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.
 //
@@ -199,16 +200,47 @@ bool wxFileTypeImpl::EnsureExtKeyExists()
 // 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 )
     {
@@ -701,7 +733,7 @@ bool wxFileTypeImpl::SetMimeType(const wxString& mimeTypeOrig)
     {
         // make up a default value for it
         wxString cmd;
-        wxSplitPath(GetCommand(_T("open")), NULL, &cmd, NULL);
+        wxFileName::SplitPath(GetCommand(_T("open")), NULL, &cmd, NULL);
         mimeType << _T("application/x-") << cmd;
     }
     else