[STOBJECT] Remove obsolete code and use string resources instead of hard-coded strings
authorEric Kohl <eric.kohl@reactos.org>
Sun, 22 Mar 2020 10:31:56 +0000 (11:31 +0100)
committerEric Kohl <eric.kohl@reactos.org>
Sun, 22 Mar 2020 10:32:35 +0000 (11:32 +0100)
dll/shellext/stobject/hotplug.cpp

index 5df143d..a57976a 100644 (file)
 
 #define DISPLAY_NAME_LEN 40
 
-//BOOL WINAPI UnregisterDeviceNotification(HDEVNOTIFY Handle);
-
 CSimpleArray<DEVINST> g_devList;
-/*static HDEVNOTIFY g_hDevNotify = NULL;*/
+CString g_strHotplugTooltip;
 static HICON g_hIconHotplug = NULL;
-static LPCWSTR g_strTooltip = L"Safely Remove Hardware and Eject Media";
 static WCHAR g_strMenuSel[DISPLAY_NAME_LEN];
 static BOOL g_IsRemoving = FALSE;
 
@@ -48,14 +45,11 @@ HRESULT EnumHotpluggedDevices(CSimpleArray<DEVINST> &devList)
     for (int idev = 0; SetupDiEnumDeviceInfo(hdev, idev, &did); idev++)
     {
         DWORD dwCapabilities = 0, dwSize = sizeof(dwCapabilities);
-        WCHAR dispName[DISPLAY_NAME_LEN];
-        ULONG ulStatus = 0, ulPnum = 0, ulLength = DISPLAY_NAME_LEN * sizeof(WCHAR);
-        CONFIGRET cr = CM_Get_DevNode_Status(&ulStatus, &ulPnum, did.DevInst, 0);
-        if (cr != CR_SUCCESS)
-            continue;
-        cr = CM_Get_DevNode_Registry_Property(did.DevInst, CM_DRP_DEVICEDESC, NULL, dispName, &ulLength, 0);
+        ULONG ulStatus = 0, ulProblem = 0;
+        CONFIGRET cr = CM_Get_DevNode_Status(&ulStatus, &ulProblem, did.DevInst, 0);
         if (cr != CR_SUCCESS)
             continue;
+
         cr = CM_Get_DevNode_Registry_Property(did.DevInst, CM_DRP_CAPABILITIES, NULL, &dwCapabilities, &dwSize, 0);
         if (cr != CR_SUCCESS)
             continue;
@@ -65,7 +59,7 @@ HRESULT EnumHotpluggedDevices(CSimpleArray<DEVINST> &devList)
             !(dwCapabilities & CM_DEVCAP_DOCKDEVICE) &&
             !(dwCapabilities & CM_DEVCAP_SURPRISEREMOVALOK) &&
             ((dwCapabilities & CM_DEVCAP_EJECTSUPPORTED) || (ulStatus & DN_DISABLEABLE)) &&
-            !ulPnum)
+            !ulProblem)
         {
             devList.Add(did.DevInst);
         }
@@ -132,13 +126,14 @@ HRESULT STDMETHODCALLTYPE Hotplug_Init(_In_ CSysTray * pSysTray)
     TRACE("Hotplug_Init\n");
 
     g_hIconHotplug = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_HOTPLUG_OK));
+    g_strHotplugTooltip.LoadStringW(IDS_HOTPLUG_REMOVE_1);
 
     EnumHotpluggedDevices(g_devList);
 
     if (g_devList.GetSize() > 0)
-        return pSysTray->NotifyIcon(NIM_ADD, ID_ICON_HOTPLUG, g_hIconHotplug, g_strTooltip);
+        return pSysTray->NotifyIcon(NIM_ADD, ID_ICON_HOTPLUG, g_hIconHotplug, g_strHotplugTooltip);
     else
-        return pSysTray->NotifyIcon(NIM_ADD, ID_ICON_HOTPLUG, g_hIconHotplug, g_strTooltip, NIS_HIDDEN);
+        return pSysTray->NotifyIcon(NIM_ADD, ID_ICON_HOTPLUG, g_hIconHotplug, g_strHotplugTooltip, NIS_HIDDEN);
 }
 
 HRESULT STDMETHODCALLTYPE Hotplug_Update(_In_ CSysTray * pSysTray)
@@ -174,12 +169,13 @@ static void _ShowContextMenu(CSysTray * pSysTray)
 
     for (INT index = 0; index < g_devList.GetSize(); index++)
     {
-        WCHAR dispName[DISPLAY_NAME_LEN], menuName[DISPLAY_NAME_LEN + 10];
+        WCHAR dispName[DISPLAY_NAME_LEN];
+        CString menuName;
         CONFIGRET cr = CM_Get_DevNode_Registry_Property(g_devList[index], CM_DRP_DEVICEDESC, NULL, dispName, &ulLength, 0);
         if (cr != CR_SUCCESS)
             StrCpyW(dispName, L"Unknown Device");
 
-        swprintf(menuName, L"Eject %wS", dispName);
+        menuName.Format(IDS_HOTPLUG_REMOVE_3, dispName);
         AppendMenuW(hPopup, MF_STRING, index+1, menuName);
     }
 
@@ -253,9 +249,9 @@ HotplugDeviceTimer(
     EnumHotpluggedDevices(g_devList);
 
     if (g_devList.GetSize() > 0)
-        pSysTray->NotifyIcon(NIM_MODIFY, ID_ICON_HOTPLUG, g_hIconHotplug, g_strTooltip);
+        pSysTray->NotifyIcon(NIM_MODIFY, ID_ICON_HOTPLUG, g_hIconHotplug, g_strHotplugTooltip);
     else
-        pSysTray->NotifyIcon(NIM_MODIFY, ID_ICON_HOTPLUG, g_hIconHotplug, g_strTooltip, NIS_HIDDEN);
+        pSysTray->NotifyIcon(NIM_MODIFY, ID_ICON_HOTPLUG, g_hIconHotplug, g_strHotplugTooltip, NIS_HIDDEN);
 }
 
 
@@ -265,22 +261,6 @@ HRESULT STDMETHODCALLTYPE Hotplug_Message(_In_ CSysTray * pSysTray, UINT uMsg, W
 
     switch (uMsg)
     {
-        /*case WM_CREATE:
-            TRACE("Hotplug_Message: WM_CREATE\n");
-            DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;
-
-            ZeroMemory(&NotificationFilter, sizeof(NotificationFilter));
-            NotificationFilter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
-            NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
-
-            g_hDevNotify = RegisterDeviceNotification(pSysTray->GetHWnd(), &NotificationFilter, DEVICE_NOTIFY_WINDOW_HANDLE | DEVICE_NOTIFY_ALL_INTERFACE_CLASSES);
-            if (g_hDevNotify != NULL)
-            {
-                lResult = true;
-                return S_OK;
-            }
-            return S_FALSE;*/
-
         case WM_USER + 220:
             TRACE("Hotplug_Message: WM_USER+220\n");
             if (wParam == HOTPLUG_SERVICE_FLAG)
@@ -321,8 +301,6 @@ HRESULT STDMETHODCALLTYPE Hotplug_Message(_In_ CSysTray * pSysTray, UINT uMsg, W
             break;
 
         case ID_ICON_HOTPLUG:
-            Hotplug_Update(pSysTray);
-
             switch (lParam)
             {
                 case WM_LBUTTONDOWN:
@@ -379,13 +357,6 @@ HRESULT STDMETHODCALLTYPE Hotplug_Message(_In_ CSysTray * pSysTray, UINT uMsg, W
             }
             return S_OK;
 
-        /*case WM_CLOSE:
-            if (!UnregisterDeviceNotification(hDeviceNotify))
-            {
-                return S_FALSE;
-            }
-            return S_OK;*/
-
         default:
             TRACE("Hotplug_Message received for unknown ID %d, ignoring.\n");
             return S_FALSE;