From 2d0a99755f22cfd40c492aaa99369899f9cf56df Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Mon, 24 Mar 2014 08:12:52 +0000 Subject: [PATCH] =?UTF-8?q?Spremenil=20sem=20odstranitev=20profilov=20WLAN?= =?UTF-8?q?,=20da=20ne=20uporablja=20ve=C4=8D=20preimenovanja=20ampak=20iz?= =?UTF-8?q?voz.=20Ker=20preimenovanje=20ni=20delovalo=20(vsaj=20na=20Win7)?= =?UTF-8?q?.=20Zanimivo:=20preimenovanje=20ne=20deluje=20niti=20v=20uporab?= =?UTF-8?q?ni=C5=A1kem=20vmesniku=20Network=20and=20Sharing=20Center.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MSICA/MSICA.cpp | 4 +-- MSICALib/MSICALib.h | 52 ++++---------------------------- MSICALib/OpWLAN.cpp | 72 +++++++++------------------------------------ 3 files changed, 22 insertions(+), 106 deletions(-) diff --git a/MSICA/MSICA.cpp b/MSICA/MSICA.cpp index dba58e9..e68b9b7 100644 --- a/MSICA/MSICA.cpp +++ b/MSICA/MSICA.cpp @@ -573,7 +573,7 @@ UINT MSICA_API EvaluateWLANProfiles(MSIHANDLE hInstall) for (i = 0; i < pInterfaceList->dwNumberOfItems; i++) { // Check for not ready state in interface. if (pInterfaceList->InterfaceInfo[i].isState != wlan_interface_state_not_ready) { - olExecuteInstall.AddTail(new MSICA::COpWLANProfileSet(pInterfaceList->InterfaceInfo[i].InterfaceGuid, sName, sProfileXML, MSICA_WLAN_PROFILE_TICK_SIZE)); + olExecuteInstall.AddTail(new MSICA::COpWLANProfileSet(pInterfaceList->InterfaceInfo[i].InterfaceGuid, 0, sName, sProfileXML, MSICA_WLAN_PROFILE_TICK_SIZE)); iTick += MSICA_WLAN_PROFILE_TICK_SIZE; } } @@ -643,7 +643,7 @@ UINT MSICA_API EvaluateWLANProfiles(MSIHANDLE hInstall) UINT MSICA_API ExecuteSequence(MSIHANDLE hInstall) { - //::MessageBox(NULL, _T(__FUNCTION__), _T("MSICA"), MB_OK); + ::MessageBox(NULL, _T(__FUNCTION__), _T("MSICA"), MB_OK); return MSICA::ExecuteSequence(hInstall); } diff --git a/MSICALib/MSICALib.h b/MSICALib/MSICALib.h index e6d0223..4311b77 100644 --- a/MSICALib/MSICALib.h +++ b/MSICALib/MSICALib.h @@ -553,24 +553,6 @@ public: }; -//////////////////////////////////////////////////////////////////////////// -// COpWLANProfileRename -//////////////////////////////////////////////////////////////////////////// - -class COpWLANProfileRename : public COpWLANProfile -{ -public: - COpWLANProfileRename(const GUID &guidInterface = GUID_NULL, LPCWSTR pszProfileNameSrc = L"", LPCWSTR pszProfileNameDst = L"", int iTicks = 0); - virtual HRESULT Execute(CSession *pSession); - - friend inline HRESULT operator <<(ATL::CAtlFile &f, const COpWLANProfileRename &op); - friend inline HRESULT operator >>(ATL::CAtlFile &f, COpWLANProfileRename &op); - -protected: - ATL::CAtlStringW m_sProfileNameDst; -}; - - //////////////////////////////////////////////////////////////////////////// // COpWLANProfileSet //////////////////////////////////////////////////////////////////////////// @@ -578,13 +560,14 @@ protected: class COpWLANProfileSet : public COpWLANProfile { public: - COpWLANProfileSet(const GUID &guidInterface = GUID_NULL, LPCWSTR pszProfileName = L"", LPCWSTR pszProfileXML = L"", int iTicks = 0); + COpWLANProfileSet(const GUID &guidInterface = GUID_NULL, DWORD dwFlags = 0, LPCWSTR pszProfileName = L"", LPCWSTR pszProfileXML = L"", int iTicks = 0); virtual HRESULT Execute(CSession *pSession); friend inline HRESULT operator <<(ATL::CAtlFile &f, const COpWLANProfileSet &op); friend inline HRESULT operator >>(ATL::CAtlFile &f, COpWLANProfileSet &op); protected: + DWORD m_dwFlags; ATL::CAtlStringW m_sProfileXML; }; @@ -628,7 +611,6 @@ protected: OP_SVC_START, OP_SVC_STOP, OP_WLAN_PROFILE_DELETE, - OP_WLAN_PROFILE_RENAME, OP_WLAN_PROFILE_SET, OP_SUBLIST }; @@ -1621,33 +1603,12 @@ inline HRESULT operator >>(ATL::CAtlFile &f, COpWLANProfile &op) } -inline HRESULT operator <<(ATL::CAtlFile &f, const COpWLANProfileRename &op) -{ - HRESULT hr; - - hr = f << (const COpWLANProfile&)op; if (FAILED(hr)) return hr; - hr = f << op.m_sProfileNameDst; if (FAILED(hr)) return hr; - - return S_OK; -} - - -inline HRESULT operator >>(ATL::CAtlFile &f, COpWLANProfileRename &op) -{ - HRESULT hr; - - hr = f >> (COpWLANProfile&)op; if (FAILED(hr)) return hr; - hr = f >> op.m_sProfileNameDst; if (FAILED(hr)) return hr; - - return S_OK; -} - - inline HRESULT operator <<(ATL::CAtlFile &f, const COpWLANProfileSet &op) { HRESULT hr; hr = f << (const COpWLANProfile&)op; if (FAILED(hr)) return hr; + hr = f << (int)(op.m_dwFlags); if (FAILED(hr)) return hr; hr = f << op.m_sProfileXML; if (FAILED(hr)) return hr; return S_OK; @@ -1658,8 +1619,9 @@ inline HRESULT operator >>(ATL::CAtlFile &f, COpWLANProfileSet &op) { HRESULT hr; - hr = f >> (COpWLANProfile&)op; if (FAILED(hr)) return hr; - hr = f >> op.m_sProfileXML; if (FAILED(hr)) return hr; + hr = f >> (COpWLANProfile&)op; if (FAILED(hr)) return hr; + hr = f >> (int&)(op.m_dwFlags); if (FAILED(hr)) return hr; + hr = f >> op.m_sProfileXML; if (FAILED(hr)) return hr; return S_OK; } @@ -1697,7 +1659,6 @@ inline HRESULT operator <<(ATL::CAtlFile &f, const COpList &list) else if (dynamic_cast(pOp)) hr = list.Save(f, pOp); else if (dynamic_cast(pOp)) hr = list.Save(f, pOp); else if (dynamic_cast(pOp)) hr = list.Save(f, pOp); - else if (dynamic_cast(pOp)) hr = list.Save(f, pOp); else if (dynamic_cast(pOp)) hr = list.Save(f, pOp); else if (dynamic_cast(pOp)) hr = list.Save(f, pOp); else { @@ -1749,7 +1710,6 @@ inline HRESULT operator >>(ATL::CAtlFile &f, COpList &list) case COpList::OP_SVC_START: hr = list.LoadAndAddTail(f); break; case COpList::OP_SVC_STOP: hr = list.LoadAndAddTail(f); break; case COpList::OP_WLAN_PROFILE_DELETE: hr = list.LoadAndAddTail(f); break; - case COpList::OP_WLAN_PROFILE_RENAME: hr = list.LoadAndAddTail(f); break; case COpList::OP_WLAN_PROFILE_SET: hr = list.LoadAndAddTail(f); break; case COpList::OP_SUBLIST: hr = list.LoadAndAddTail(f); break; default: diff --git a/MSICALib/OpWLAN.cpp b/MSICALib/OpWLAN.cpp index b443307..c761c91 100644 --- a/MSICALib/OpWLAN.cpp +++ b/MSICALib/OpWLAN.cpp @@ -33,20 +33,19 @@ HRESULT COpWLANProfileDelete::Execute(CSession *pSession) dwError = ::WlanOpenHandle(2, NULL, &dwNegotiatedVersion, &hClientHandle); if (dwError == NO_ERROR) { if (pSession->m_bRollbackEnabled) { - ATL::CAtlStringW sBackupName; - UINT uiCount = 0; + LPWSTR pszProfileXML = NULL; + DWORD dwFlags = 0, dwGrantedAccess = 0; - do { - // Rename the profile to make a backup. - sBackupName.Format(L"%ls (orig %u)", (LPCWSTR)m_sValue, ++uiCount); - dwError = ::WlanRenameProfile(hClientHandle, &m_guidInterface, m_sValue, sBackupName, NULL); - } while (dwError == ERROR_ALREADY_EXISTS); + // Get profile settings as XML first. + dwError = ::WlanGetProfile(hClientHandle, &m_guidInterface, m_sValue, NULL, &pszProfileXML, &dwFlags, &dwGrantedAccess); if (dwError == NO_ERROR) { - // Order rollback action to restore from backup copy. - pSession->m_olRollback.AddHead(new COpWLANProfileRename(m_guidInterface, sBackupName, m_sValue)); - - // Order commit action to delete backup copy. - pSession->m_olCommit.AddTail(new COpWLANProfileDelete(m_guidInterface, sBackupName)); + // Delete the profile. + dwError = ::WlanDeleteProfile(hClientHandle, &m_guidInterface, m_sValue, NULL); + if (dwError == NO_ERROR) { + // Order rollback action to recreate it. + pSession->m_olRollback.AddHead(new COpWLANProfileSet(m_guidInterface, dwFlags, m_sValue, pszProfileXML)); + } + ::WlanFreeMemory(pszProfileXML); } } else { // Delete the profile. @@ -71,56 +70,13 @@ HRESULT COpWLANProfileDelete::Execute(CSession *pSession) } -//////////////////////////////////////////////////////////////////////////// -// COpWLANProfileRename -//////////////////////////////////////////////////////////////////////////// - -COpWLANProfileRename::COpWLANProfileRename(const GUID &guidInterface, LPCWSTR pszProfileNameSrc, LPCWSTR pszProfileNameDst, int iTicks) : - COpWLANProfile(guidInterface, pszProfileNameSrc, iTicks), - m_sProfileNameDst(pszProfileNameDst) -{ -} - - -HRESULT COpWLANProfileRename::Execute(CSession *pSession) -{ - DWORD dwError, dwNegotiatedVersion; - HANDLE hClientHandle; - - dwError = ::WlanOpenHandle(2, NULL, &dwNegotiatedVersion, &hClientHandle); - if (dwError == NO_ERROR) { - // Rename the profile. - dwError = ::WlanRenameProfile(hClientHandle, &m_guidInterface, m_sValue, m_sProfileNameDst, NULL); - if (dwError == NO_ERROR && pSession->m_bRollbackEnabled) { - // Order rollback action to rename it back. - pSession->m_olRollback.AddHead(new COpWLANProfileRename(m_guidInterface, m_sProfileNameDst, m_sValue)); - } - ::WlanCloseHandle(hClientHandle, NULL); - } - - if (dwError == NO_ERROR) - return S_OK; - else { - PMSIHANDLE hRecordProg = ::MsiCreateRecord(5); - ATL::CAtlStringW sGUID; - GuidToString(m_guidInterface, sGUID); - ::MsiRecordSetInteger(hRecordProg, 1, ERROR_INSTALL_WLAN_PROFILE_RENAME); - ::MsiRecordSetStringW(hRecordProg, 2, sGUID ); - ::MsiRecordSetStringW(hRecordProg, 3, m_sValue ); - ::MsiRecordSetStringW(hRecordProg, 4, m_sProfileNameDst ); - ::MsiRecordSetInteger(hRecordProg, 5, dwError ); - ::MsiProcessMessage(pSession->m_hInstall, INSTALLMESSAGE_ERROR, hRecordProg); - return AtlHresultFromWin32(dwError); - } -} - - //////////////////////////////////////////////////////////////////////////// // COpWLANProfileSet //////////////////////////////////////////////////////////////////////////// -COpWLANProfileSet::COpWLANProfileSet(const GUID &guidInterface, LPCWSTR pszProfileName, LPCWSTR pszProfileXML, int iTicks) : +COpWLANProfileSet::COpWLANProfileSet(const GUID &guidInterface, DWORD dwFlags, LPCWSTR pszProfileName, LPCWSTR pszProfileXML, int iTicks) : COpWLANProfile(guidInterface, pszProfileName, iTicks), + m_dwFlags(dwFlags), m_sProfileXML(pszProfileXML) { } @@ -144,7 +100,7 @@ HRESULT COpWLANProfileSet::Execute(CSession *pSession) dwError = ::WlanOpenHandle(2, NULL, &dwNegotiatedVersion, &hClientHandle); if (dwError == NO_ERROR) { // Set the profile. - dwError = ::WlanSetProfile(hClientHandle, &m_guidInterface, 0, m_sProfileXML, NULL, TRUE, NULL, &wlrc); + dwError = ::WlanSetProfile(hClientHandle, &m_guidInterface, m_dwFlags, m_sProfileXML, NULL, TRUE, NULL, &wlrc); if (dwError == NO_ERROR && pSession->m_bRollbackEnabled) { // Order rollback action to delete it. pSession->m_olRollback.AddHead(new COpWLANProfileDelete(m_guidInterface, m_sValue));