https://git.reactos.org/?p=reactos.git;a=commitdiff;h=0654d60eef6afb7c0047c…
commit 0654d60eef6afb7c0047c7fad78e7684b61ea452
Author: Giannis Adamopoulos <gadamopoulos(a)reactos.org>
AuthorDate: Tue Nov 13 00:36:52 2018 +0200
Commit: Giannis Adamopoulos <gadamopoulos(a)reactos.org>
CommitDate: Sun Nov 18 14:01:54 2018 +0200
[NETSHELL] Move the implementation of the Disable button of the status dialog to
CNetConnection::Disconnect
---
dll/shellext/netshell/connectmanager.cpp | 128 +++++++++++++++++++++++++++++-
dll/shellext/netshell/lanstatusui.cpp | 132 +------------------------------
2 files changed, 130 insertions(+), 130 deletions(-)
diff --git a/dll/shellext/netshell/connectmanager.cpp
b/dll/shellext/netshell/connectmanager.cpp
index da733db2da..0ca8651e52 100644
--- a/dll/shellext/netshell/connectmanager.cpp
+++ b/dll/shellext/netshell/connectmanager.cpp
@@ -50,11 +50,137 @@ CNetConnection::Connect()
return E_NOTIMPL;
}
+BOOL
+FindNetworkAdapter(HDEVINFO hInfo, SP_DEVINFO_DATA *pDevInfo, LPWSTR pGuid)
+{
+ DWORD dwIndex, dwSize;
+ HKEY hSubKey;
+ WCHAR szNetCfg[50];
+ WCHAR szDetail[200] = L"SYSTEM\\CurrentControlSet\\Control\\Class\\";
+
+ dwIndex = 0;
+ do
+ {
+ ZeroMemory(pDevInfo, sizeof(SP_DEVINFO_DATA));
+ pDevInfo->cbSize = sizeof(SP_DEVINFO_DATA);
+
+ /* get device info */
+ if (!SetupDiEnumDeviceInfo(hInfo, dwIndex++, pDevInfo))
+ break;
+
+ /* get device software registry path */
+ if (!SetupDiGetDeviceRegistryPropertyW(hInfo, pDevInfo, SPDRP_DRIVER, NULL,
(LPBYTE)&szDetail[39], sizeof(szDetail)/sizeof(WCHAR) - 40, &dwSize))
+ break;
+
+ /* open device registry key */
+ if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szDetail, 0, KEY_READ, &hSubKey) !=
ERROR_SUCCESS)
+ break;
+
+ /* query NetCfgInstanceId for current device */
+ dwSize = sizeof(szNetCfg);
+ if (RegQueryValueExW(hSubKey, L"NetCfgInstanceId", NULL, NULL,
(LPBYTE)szNetCfg, &dwSize) != ERROR_SUCCESS)
+ {
+ RegCloseKey(hSubKey);
+ break;
+ }
+ RegCloseKey(hSubKey);
+ if (!_wcsicmp(pGuid, szNetCfg))
+ {
+ return TRUE;
+ }
+ } while (TRUE);
+
+ return FALSE;
+}
+
HRESULT
WINAPI
CNetConnection::Disconnect()
{
- return E_NOTIMPL;
+ HKEY hKey;
+ NETCON_PROPERTIES * pProperties;
+ LPOLESTR pDisplayName;
+ WCHAR szPath[200];
+ DWORD dwSize, dwType;
+ LPWSTR pPnp;
+ HDEVINFO hInfo;
+ SP_DEVINFO_DATA DevInfo;
+ SP_PROPCHANGE_PARAMS PropChangeParams;
+ HRESULT hr;
+
+ hr = GetProperties(&pProperties);
+ if (FAILED_UNEXPECTEDLY(hr))
+ return hr;
+
+ hInfo = SetupDiGetClassDevsW(&GUID_DEVCLASS_NET, NULL, NULL, DIGCF_PRESENT );
+ if (!hInfo)
+ {
+ NcFreeNetconProperties(pProperties);
+ return E_FAIL;
+ }
+
+ if (FAILED(StringFromCLSID((CLSID)pProperties->guidId, &pDisplayName)))
+ {
+ NcFreeNetconProperties(pProperties);
+ SetupDiDestroyDeviceInfoList(hInfo);
+ return E_FAIL;
+ }
+ NcFreeNetconProperties(pProperties);
+
+ if (FindNetworkAdapter(hInfo, &DevInfo, pDisplayName))
+ {
+ PropChangeParams.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
+ PropChangeParams.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE; //;
+ PropChangeParams.StateChange = DICS_DISABLE;
+ PropChangeParams.Scope = DICS_FLAG_CONFIGSPECIFIC;
+ PropChangeParams.HwProfile = 0;
+
+ if (SetupDiSetClassInstallParams(hInfo, &DevInfo,
&PropChangeParams.ClassInstallHeader, sizeof(SP_PROPCHANGE_PARAMS)))
+ {
+ SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, hInfo, &DevInfo);
+ }
+ }
+ SetupDiDestroyDeviceInfoList(hInfo);
+
+ swprintf(szPath,
L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection",
pDisplayName);
+ CoTaskMemFree(pDisplayName);
+
+ if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szPath, 0, KEY_READ, &hKey) !=
ERROR_SUCCESS)
+ return E_FAIL;
+
+ dwSize = 0;
+ if (RegQueryValueExW(hKey, L"PnpInstanceID", NULL, &dwType, NULL,
&dwSize) != ERROR_SUCCESS || dwType != REG_SZ)
+ {
+ RegCloseKey(hKey);
+ return E_FAIL;
+ }
+
+ pPnp = static_cast<PWSTR>(CoTaskMemAlloc(dwSize));
+ if (!pPnp)
+ {
+ RegCloseKey(hKey);
+ return E_FAIL;
+ }
+
+ if (RegQueryValueExW(hKey, L"PnpInstanceID", NULL, &dwType,
(LPBYTE)pPnp, &dwSize) != ERROR_SUCCESS)
+ {
+ CoTaskMemFree(pPnp);
+ RegCloseKey(hKey);
+ return E_FAIL;
+ }
+ RegCloseKey(hKey);
+
+ swprintf(szPath, L"System\\CurrentControlSet\\Hardware
Profiles\\Current\\System\\CurrentControlSet\\Enum\\%s", pPnp);
+ CoTaskMemFree(pPnp);
+
+ if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, szPath, 0, NULL, 0, KEY_WRITE, NULL,
&hKey, NULL) != ERROR_SUCCESS)
+ return E_FAIL;
+
+ dwSize = 1; /* enable = 0, disable = 1 */
+ RegSetValueExW(hKey, L"CSConfigFlags", 0, REG_DWORD, (LPBYTE)&dwSize,
sizeof(DWORD));
+ RegCloseKey(hKey);
+
+ return S_OK;
}
HRESULT
diff --git a/dll/shellext/netshell/lanstatusui.cpp
b/dll/shellext/netshell/lanstatusui.cpp
index 7a9be00ad7..a5b4144dca 100644
--- a/dll/shellext/netshell/lanstatusui.cpp
+++ b/dll/shellext/netshell/lanstatusui.cpp
@@ -544,140 +544,14 @@ LANStatusUiAdvancedDlg(
return FALSE;
}
-BOOL
-FindNetworkAdapter(HDEVINFO hInfo, SP_DEVINFO_DATA *pDevInfo, LPWSTR pGuid)
-{
- DWORD dwIndex, dwSize;
- HKEY hSubKey;
- WCHAR szNetCfg[50];
- WCHAR szDetail[200] = L"SYSTEM\\CurrentControlSet\\Control\\Class\\";
-
- dwIndex = 0;
- do
- {
-
- ZeroMemory(pDevInfo, sizeof(SP_DEVINFO_DATA));
- pDevInfo->cbSize = sizeof(SP_DEVINFO_DATA);
-
- /* get device info */
- if (!SetupDiEnumDeviceInfo(hInfo, dwIndex++, pDevInfo))
- break;
-
- /* get device software registry path */
- if (!SetupDiGetDeviceRegistryPropertyW(hInfo, pDevInfo, SPDRP_DRIVER, NULL,
(LPBYTE)&szDetail[39], sizeof(szDetail)/sizeof(WCHAR) - 40, &dwSize))
- break;
-
- /* open device registry key */
- if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szDetail, 0, KEY_READ, &hSubKey) !=
ERROR_SUCCESS)
- break;
-
- /* query NetCfgInstanceId for current device */
- dwSize = sizeof(szNetCfg);
- if (RegQueryValueExW(hSubKey, L"NetCfgInstanceId", NULL, NULL,
(LPBYTE)szNetCfg, &dwSize) != ERROR_SUCCESS)
- {
- RegCloseKey(hSubKey);
- break;
- }
- RegCloseKey(hSubKey);
- if (!_wcsicmp(pGuid, szNetCfg))
- {
- return TRUE;
- }
- } while (TRUE);
-
- return FALSE;
-}
-
VOID
DisableNetworkAdapter(INetConnection * pNet, LANSTATUSUI_CONTEXT * pContext, HWND
hwndDlg)
{
- HKEY hKey;
- NETCON_PROPERTIES * pProperties;
- LPOLESTR pDisplayName;
- WCHAR szPath[200];
- DWORD dwSize, dwType;
- LPWSTR pPnp;
- HDEVINFO hInfo;
- SP_DEVINFO_DATA DevInfo;
- SP_PROPCHANGE_PARAMS PropChangeParams;
- BOOL bClose = FALSE;
- NOTIFYICONDATAW nid;
-
- if (FAILED(pNet->GetProperties(&pProperties)))
- return;
-
-
- hInfo = SetupDiGetClassDevsW(&GUID_DEVCLASS_NET, NULL, NULL, DIGCF_PRESENT );
- if (!hInfo)
- {
- NcFreeNetconProperties(pProperties);
- return;
- }
-
- if (FAILED(StringFromCLSID((CLSID)pProperties->guidId, &pDisplayName)))
- {
- NcFreeNetconProperties(pProperties);
- SetupDiDestroyDeviceInfoList(hInfo);
- return;
- }
- NcFreeNetconProperties(pProperties);
-
- if (FindNetworkAdapter(hInfo, &DevInfo, pDisplayName))
- {
- PropChangeParams.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
- PropChangeParams.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE; //;
- PropChangeParams.StateChange = DICS_DISABLE;
- PropChangeParams.Scope = DICS_FLAG_CONFIGSPECIFIC;
- PropChangeParams.HwProfile = 0;
-
- if (SetupDiSetClassInstallParams(hInfo, &DevInfo,
&PropChangeParams.ClassInstallHeader, sizeof(SP_PROPCHANGE_PARAMS)))
- {
- if (SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, hInfo, &DevInfo))
- bClose = TRUE;
- }
- }
- SetupDiDestroyDeviceInfoList(hInfo);
-
- swprintf(szPath,
L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection",
pDisplayName);
- CoTaskMemFree(pDisplayName);
-
- if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szPath, 0, KEY_READ, &hKey) !=
ERROR_SUCCESS)
- return;
-
- dwSize = 0;
- if (RegQueryValueExW(hKey, L"PnpInstanceID", NULL, &dwType, NULL,
&dwSize) != ERROR_SUCCESS || dwType != REG_SZ)
- {
- RegCloseKey(hKey);
- return;
- }
-
- pPnp = static_cast<PWSTR>(CoTaskMemAlloc(dwSize));
- if (!pPnp)
- {
- RegCloseKey(hKey);
- return;
- }
-
- if (RegQueryValueExW(hKey, L"PnpInstanceID", NULL, &dwType,
(LPBYTE)pPnp, &dwSize) != ERROR_SUCCESS)
- {
- CoTaskMemFree(pPnp);
- RegCloseKey(hKey);
- return;
- }
- RegCloseKey(hKey);
-
- swprintf(szPath, L"System\\CurrentControlSet\\Hardware
Profiles\\Current\\System\\CurrentControlSet\\Enum\\%s", pPnp);
- CoTaskMemFree(pPnp);
-
- if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, szPath, 0, NULL, 0, KEY_WRITE, NULL,
&hKey, NULL) != ERROR_SUCCESS)
+ HRESULT hr = pNet->Disconnect();
+ if (FAILED_UNEXPECTEDLY(hr))
return;
- dwSize = 1; /* enable = 0, disable = 1 */
- RegSetValueExW(hKey, L"CSConfigFlags", 0, REG_DWORD, (LPBYTE)&dwSize,
sizeof(DWORD));
- RegCloseKey(hKey);
-
- if (!bClose)
- return;
+ NOTIFYICONDATAW nid;
PropSheet_PressButton(GetParent(hwndDlg), PSBTN_CANCEL);
ZeroMemory(&nid, sizeof(nid));