From 1880e45211e5652757f92db7eead7d928f76b0bf Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 22 Aug 1998 20:34:00 +0000 Subject: [PATCH] bug with checking the first character of possible empty string corrected git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@621 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/registry.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/src/msw/registry.cpp b/src/msw/registry.cpp index f6b5ea6cb9..bf05ac6648 100644 --- a/src/msw/registry.cpp +++ b/src/msw/registry.cpp @@ -759,7 +759,7 @@ bool wxRegKey::GetNextKey(wxString& strKeyName, long& lIndex) const } // ============================================================================ -// implementation of global functions +// implementation of global private functions // ============================================================================ bool KeyExists(HKEY hRootKey, const char *szKey) { @@ -787,3 +787,74 @@ void RemoveTrailingSeparator(wxString& str) if ( !str.IsEmpty() && str.Last() == REG_SEPARATOR ) str.Truncate(str.Len() - 1); } + +// ============================================================================ +// global public functions +// ============================================================================ + +bool GetExtensionFromMimeType(wxString *pExt, const wxString& strMimeType) +{ + // @@@ VZ: I don't know of any official documentation which mentions this + // location, but as a matter of fact IE uses it, so why not we? + static const char *szMimeDbase = "MIME\\Database\\Content Type\\"; + + wxString strKey = szMimeDbase; + strKey << strMimeType; + + // suppress possible error messages + wxLogNull nolog; + wxRegKey key(wxRegKey::HKCR, strKey); + if ( key.IsOpened() ) { + if ( key.QueryValue("Extension", *pExt) ) + return TRUE; + } + + // no such MIME type or no extension for it + return FALSE; +} + +bool GetMimeTypeFromExtension(wxString *pMimeType, const wxString& strExt) +{ + wxCHECK( !strExt.IsEmpty(), FALSE ); + + // add the leading point if necessary + wxString str; + if ( strExt[0] != '.' ) { + str = '.'; + } + str << strExt; + + // suppress possible error messages + wxLogNull nolog; + wxRegKey key(wxRegKey::HKCR, str); + if ( key.IsOpened() ) { + if ( key.QueryValue("Content Type", *pMimeType) ) + return TRUE; + } + + // no such extension or no content-type + return FALSE; +} + +bool GetFileTypeFromExtension(wxString *pFileType, const wxString& strExt) +{ + wxCHECK( !strExt.IsEmpty(), FALSE ); + + // add the leading point if necessary + wxString str; + if ( strExt[0] != '.' ) { + str = '.'; + } + str << strExt; + + // suppress possible error messages + wxLogNull nolog; + wxRegKey key(wxRegKey::HKCR, str); + if ( key.IsOpened() ) { + if ( key.QueryValue("", *pFileType) ) // it's the default value of the key + return TRUE; + } + + // no such extension or no value + return FALSE; +} \ No newline at end of file -- 2.45.2