From 040f0110fc3aa931eff3c245518aabbbd934f3f5 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 7 Sep 1998 08:55:28 +0000 Subject: [PATCH] wxRegConfig now works again git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@696 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/regconf.cpp | 98 ++++++++++++++++++++++---------------------- src/msw/registry.cpp | 11 +++-- 2 files changed, 57 insertions(+), 52 deletions(-) diff --git a/src/msw/regconf.cpp b/src/msw/regconf.cpp index 22743d41a0..6e6d1da8d3 100644 --- a/src/msw/regconf.cpp +++ b/src/msw/regconf.cpp @@ -71,62 +71,60 @@ bool TryGetValue(const wxRegKey& key, const wxString& str, long *plVal) // ctor/dtor // ---------------------------------------------------------------------------- -#if 0 -wxRegConfig::wxRegConfig(const wxString& strRoot) - : m_keyLocalRoot(wxRegKey::HKCU, SOFTWARE_KEY + strRoot), - m_keyLocal(m_keyLocalRoot, ""), - m_keyGlobalRoot(wxRegKey::HKLM, SOFTWARE_KEY + strRoot), - m_keyGlobal(m_keyGlobalRoot, "") +// create the config object which stores its data under HKCU\vendor\app and, if +// style & wxCONFIG_USE_GLOBAL_FILE, under HKLM\vendor\app +wxRegConfig::wxRegConfig(const wxString& appName, const wxString& vendorName, + const wxString& strLocal, const wxString& strGlobal, + long style) + : wxConfigBase(appName, vendorName, strLocal, strGlobal, style) { - // Create() will Open() if key already exists - m_keyLocalRoot.Create(); - - // as it's the same key, Open() shouldn't fail (i.e. no need for Create()) - m_keyLocal.Open(); + wxString strRoot; - wxLogNull nolog; - m_keyGlobalRoot.Open(); -} -#endif + bool bDoUseGlobal = (style & wxCONFIG_USE_GLOBAL_FILE) != 0; -// TODO: vendor name is ignored, because we can't yet do the test for optional vendor -// name in the constructor body. We need a wxRegKey::Set that takes the same -// args as the constructor. Then we'll set m_keyLocalRoot etc. in the constructor body. - -wxRegConfig::wxRegConfig(const wxString& appName, const wxString& vendorName, - const wxString& strLocal, const wxString& strGlobal, long style) - : wxConfigBase(appName, vendorName, strLocal, strGlobal, style), + // the convention is to put the programs keys under \ + // (but it can be overriden by specifying the pathes explicitly in strLocal + // and/or strGlobal) + if ( strLocal.IsEmpty() || (strGlobal.IsEmpty() && bDoUseGlobal) ) + { + if ( vendorName.IsEmpty() ) + { + if ( wxTheApp ) + strRoot = wxTheApp->GetVendorName(); + } + else + { + strRoot = vendorName; + } - m_keyLocalRoot(wxRegKey::HKCU, SOFTWARE_KEY + appName), - m_keyLocal(m_keyLocalRoot, ""), - m_keyGlobalRoot(wxRegKey::HKLM, SOFTWARE_KEY + appName), - m_keyGlobal(m_keyGlobalRoot, "") -{ - // TODO: really, we should check and supply an app name if one isn't supplied. - // Unfortunately I don't know how to initialise the member wxRegKey - // variables from within the constructor body. -- JACS - // Vadim - we just need an implementation of wxRegKey::Set, - // and then we can uncomment this and remove the constructor lines above. -/* - wxString strRoot(appName); - if (appName.IsEmpty() && wxTheApp) + // no '\\' needed if no vendor name + if ( !strRoot.IsEmpty() ) { - strRoot = wxTheApp->GetAppName(); + strRoot += '\\'; } - wxASSERT( !strRoot.IsEmpty() ); - if (!vendorName.IsEmpty()) + if ( appName.IsEmpty() ) + { + wxCHECK_RET( wxTheApp, "No application name in wxRegConfig ctor!" ); + strRoot << wxTheApp->GetAppName(); + } + else { - strRoot += "\\"; - strRoot += vendorName; + strRoot << appName; } + } + //else: we don't need to do all the complicated stuff above - m_keyLocalRoot.Set(wxRegKey::HKCU, SOFTWARE_KEY + strRoot), - m_keyLocal.Set(m_keyLocalRoot, ""), + wxString str = strLocal.IsEmpty() ? strRoot : strLocal; + m_keyLocalRoot.SetName(wxRegKey::HKCU, SOFTWARE_KEY + str); + m_keyLocal.SetName(m_keyLocalRoot, ""); - m_keyGlobalRoot.Set(wxRegKey::HKLM, SOFTWARE_KEY + strRoot), - m_keyGlobal.Set(m_keyGlobalRoot, "") -*/ + if ( bDoUseGlobal ) + { + str = strGlobal.IsEmpty() ? strRoot : strGlobal; + m_keyGlobalRoot.SetName(wxRegKey::HKLM, SOFTWARE_KEY + str); + m_keyGlobal.SetName(m_keyGlobalRoot, ""); + } // Create() will Open() if key already exists m_keyLocalRoot.Create(); @@ -134,9 +132,13 @@ wxRegConfig::wxRegConfig(const wxString& appName, const wxString& vendorName, // as it's the same key, Open() shouldn't fail (i.e. no need for Create()) m_keyLocal.Open(); - wxLogNull nolog; - m_keyGlobalRoot.Open(); - + // OTOH, this key may perfectly not exist, so suppress error messages the call + // to Open() might generate + if ( bDoUseGlobal ) + { + wxLogNull nolog; + m_keyGlobalRoot.Open(); + } } wxRegConfig::~wxRegConfig() diff --git a/src/msw/registry.cpp b/src/msw/registry.cpp index b2650bcb6b..a2f1b268e9 100644 --- a/src/msw/registry.cpp +++ b/src/msw/registry.cpp @@ -887,11 +887,14 @@ bool GetFileTypeIcon(wxIcon *pIcon, const wxString& strFileType) // NB: icon index may be negative as well as positive and the full path // may contain the environment variables inside '%' wxString strFullPath = strIcon.Before(','), - strIndex = strIcon.After(','); + strIndex = strIcon.Right(','); - // unless I misunderstand the format (may be index may be ommited, I - // don't know) - wxASSERT( !(strFullPath.IsEmpty() || strIndex.IsEmpty()) ); + // index may be omitted, in which case Before(',') is empty and + // Right(',') is the whole string + if ( strFullPath.IsEmpty() ) { + strFullPath = strIndex; + strIndex = "0"; + } wxString strExpPath = wxExpandEnvVars(strFullPath); int nIndex = atoi(strIndex); -- 2.47.2