Skip to content

Commit 04e2825

Browse files
committed
HardwareDevices: Add disk queue length and split count, Add device uninstall option, Fix imagelist disposal
1 parent 4798807 commit 04e2825

File tree

8 files changed

+88
-22
lines changed

8 files changed

+88
-22
lines changed

plugins/HardwareDevices/HardwareDevices.rc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ BEGIN
107107
RTEXT "Disk name",IDC_DISKNAME,107,4,207,16,SS_WORDELLIPSIS
108108
END
109109

110-
IDD_DISKDRIVE_PANEL DIALOGEX 0, 0, 330, 50
110+
IDD_DISKDRIVE_PANEL DIALOGEX 0, 0, 416, 50
111111
STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD | WS_SYSMENU
112112
FONT 8, "MS Shell Dlg", 400, 0, 0x1
113113
BEGIN
@@ -122,10 +122,15 @@ BEGIN
122122
LTEXT "Response time",IDC_STATIC,8,22,64,8,SS_ENDELLIPSIS
123123
LTEXT "Bytes delta",IDC_STATIC,8,33,57,8,SS_ENDELLIPSIS
124124
GROUPBOX "Disk",IDC_STATIC,0,0,135,46
125-
PUSHBUTTON "Details",IDC_DETAILS,278,32,50,14
125+
PUSHBUTTON "Details",IDC_DETAILS,278,35,50,14
126126
RTEXT "Static",IDC_STAT_ACTIVE,65,11,62,8,SS_ENDELLIPSIS
127127
RTEXT "Static",IDC_STAT_RESPONSETIME,65,22,62,8,SS_ENDELLIPSIS
128128
RTEXT "Static",IDC_STAT_BYTESDELTA,65,33,62,8,SS_ENDELLIPSIS
129+
GROUPBOX "Statistics",IDC_STATIC,278,0,136,33
130+
LTEXT "Queue depth",IDC_STATIC,287,11,48,8
131+
LTEXT "Split count",IDC_STATIC,287,22,45,8
132+
RTEXT "Static",IDC_STAT_QUEUELENGTH,344,11,62,8,SS_ENDELLIPSIS
133+
RTEXT "Static",IDC_STAT_SPLITCOUNT,344,22,62,8,SS_ENDELLIPSIS
129134
END
130135

131136
IDD_DISKDRIVE_DETAILS_SMART DIALOGEX 0, 0, 309, 265
@@ -242,7 +247,7 @@ BEGIN
242247

243248
IDD_DISKDRIVE_PANEL, DIALOG
244249
BEGIN
245-
RIGHTMARGIN, 329
250+
RIGHTMARGIN, 415
246251
BOTTOMMARGIN, 49
247252
END
248253

plugins/HardwareDevices/devices.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ typedef struct _DV_NETADAPTER_DETAILS_CONTEXT
182182
typedef struct _DV_NETADAPTER_CONTEXT
183183
{
184184
HWND ListViewHandle;
185-
HIMAGELIST ImageList;
186185
BOOLEAN OptionsChanged;
187186
BOOLEAN UseAlternateMethod;
188187
PH_LAYOUT_MANAGER LayoutManager;
@@ -466,7 +465,6 @@ typedef struct _DV_DISK_SYSINFO_CONTEXT
466465
typedef struct _DV_DISK_OPTIONS_CONTEXT
467466
{
468467
HWND ListViewHandle;
469-
HIMAGELIST ImageList;
470468
BOOLEAN OptionsChanged;
471469
PH_LAYOUT_MANAGER LayoutManager;
472470
} DV_DISK_OPTIONS_CONTEXT, *PDV_DISK_OPTIONS_CONTEXT;
@@ -991,7 +989,6 @@ typedef struct _DV_RAPL_SYSINFO_CONTEXT
991989
typedef struct _DV_RAPL_OPTIONS_CONTEXT
992990
{
993991
HWND ListViewHandle;
994-
HIMAGELIST ImageList;
995992
BOOLEAN OptionsChanged;
996993
PH_LAYOUT_MANAGER LayoutManager;
997994
} DV_RAPL_OPTIONS_CONTEXT, *PDV_RAPL_OPTIONS_CONTEXT;

plugins/HardwareDevices/diskgraph.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,20 @@ VOID DiskDriveUpdatePanel(
8585
PhSetWindowText(Context->DiskDrivePanelBytesLabel, formatBuffer);
8686
else
8787
PhSetWindowText(Context->DiskDrivePanelBytesLabel, PhaFormatString(L"%s/s", PhaFormatSize(Context->DiskEntry->BytesReadDelta.Delta + Context->DiskEntry->BytesWrittenDelta.Delta, ULONG_MAX)->Buffer)->Buffer);
88+
89+
PhInitFormatI64UGroupDigits(&format[0], Context->DiskEntry->QueueDepth);
90+
91+
if (PhFormatToBuffer(format, 1, formatBuffer, sizeof(formatBuffer), NULL))
92+
PhSetWindowText(GetDlgItem(Context->PanelWindowHandle, IDC_STAT_QUEUELENGTH), formatBuffer);
93+
else
94+
PhSetWindowText(GetDlgItem(Context->PanelWindowHandle, IDC_STAT_QUEUELENGTH), PhaFormatString(L"%lu", Context->DiskEntry->QueueDepth)->Buffer);
95+
96+
PhInitFormatI64UGroupDigits(&format[0], Context->DiskEntry->SplitCount);
97+
98+
if (PhFormatToBuffer(format, 1, formatBuffer, sizeof(formatBuffer), NULL))
99+
PhSetWindowText(GetDlgItem(Context->PanelWindowHandle, IDC_STAT_SPLITCOUNT), formatBuffer);
100+
else
101+
PhSetWindowText(GetDlgItem(Context->PanelWindowHandle, IDC_STAT_SPLITCOUNT), PhaFormatString(L"%lu", Context->DiskEntry->SplitCount)->Buffer);
88102
}
89103

90104
VOID DiskDriveUpdateTitle(

plugins/HardwareDevices/diskoptions.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -648,18 +648,18 @@ VOID LoadDiskDriveImages(
648648

649649
if (PhExtractIconEx(deviceIconPath, FALSE, (INT)index, &smallIcon, NULL))
650650
{
651-
Context->ImageList = PhImageListCreate(
651+
HIMAGELIST imageList = PhImageListCreate(
652652
24, // GetSystemMetrics(SM_CXSMICON)
653653
24, // GetSystemMetrics(SM_CYSMICON)
654654
ILC_MASK | ILC_COLOR32,
655655
1,
656656
1
657657
);
658658

659-
PhImageListAddIcon(Context->ImageList, smallIcon);
659+
PhImageListAddIcon(imageList, smallIcon);
660660
DestroyIcon(smallIcon);
661661

662-
ListView_SetImageList(Context->ListViewHandle, Context->ImageList, LVSIL_SMALL);
662+
ListView_SetImageList(Context->ListViewHandle, imageList, LVSIL_SMALL);
663663
}
664664

665665
PhDereferenceObject(deviceIconPath);
@@ -724,7 +724,6 @@ INT_PTR CALLBACK DiskDriveOptionsDlgProc(
724724
DiskDrivesSaveList();
725725

726726
FreeListViewDiskDriveEntries(context);
727-
if (context->ImageList) PhImageListDestroy(context->ImageList);
728727

729728
PhRemoveWindowContext(hwndDlg, PH_WINDOW_CONTEXT_DEFAULT);
730729
PhFree(context);
@@ -790,6 +789,10 @@ INT_PTR CALLBACK DiskDriveOptionsDlgProc(
790789
{
791790
ShowDeviceMenu(hwndDlg, deviceInstance);
792791
PhDereferenceObject(deviceInstance);
792+
793+
FreeListViewDiskDriveEntries(context);
794+
ListView_DeleteAllItems(context->ListViewHandle);
795+
FindDiskDrives(context);
793796
}
794797
}
795798
}

plugins/HardwareDevices/main.c

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,37 @@ BOOLEAN HardwareDeviceRestart(
300300
return TRUE;
301301
}
302302

303+
BOOLEAN HardwareDeviceUninstall(
304+
_In_ HWND ParentWindow,
305+
_In_ PPH_STRING DeviceInstance
306+
)
307+
{
308+
CONFIGRET result;
309+
DEVINST deviceInstanceHandle;
310+
311+
result = CM_Locate_DevNode(
312+
&deviceInstanceHandle,
313+
DeviceInstance->Buffer,
314+
CM_LOCATE_DEVNODE_PHANTOM
315+
);
316+
317+
if (result != CR_SUCCESS)
318+
{
319+
PhShowStatus(ParentWindow, L"Failed to uninstall the device.", 0, CM_MapCrToWin32Err(result, ERROR_UNKNOWN_PROPERTY));
320+
return FALSE;
321+
}
322+
323+
result = CM_Uninstall_DevInst(deviceInstanceHandle, 0);
324+
325+
if (result != CR_SUCCESS)
326+
{
327+
PhShowStatus(ParentWindow, L"Failed to uninstall the device.", 0, CM_MapCrToWin32Err(result, ERROR_UNKNOWN_PROPERTY));
328+
return FALSE;
329+
}
330+
331+
return TRUE;
332+
}
333+
303334
BOOLEAN HardwareDeviceShowProperties(
304335
_In_ HWND WindowHandle,
305336
_In_ PPH_STRING DeviceInstance
@@ -449,6 +480,7 @@ VOID ShowDeviceMenu(
449480
PhInsertEMenuItem(menu, PhCreateEMenuItem(0, 0, L"Enable", NULL, NULL), ULONG_MAX);
450481
PhInsertEMenuItem(menu, PhCreateEMenuItem(0, 1, L"Disable", NULL, NULL), ULONG_MAX);
451482
PhInsertEMenuItem(menu, PhCreateEMenuItem(0, 2, L"Restart", NULL, NULL), ULONG_MAX);
483+
PhInsertEMenuItem(menu, PhCreateEMenuItem(0, 3, L"Uninstall", NULL, NULL), ULONG_MAX);
452484
PhInsertEMenuItem(menu, PhCreateEMenuSeparator(), ULONG_MAX);
453485
subMenu = PhCreateEMenuItem(0, 0, L"Open key", NULL, NULL);
454486
PhInsertEMenuItem(subMenu, PhCreateEMenuItem(0, 4, L"Hardware", NULL, NULL), ULONG_MAX);
@@ -457,7 +489,7 @@ VOID ShowDeviceMenu(
457489
PhInsertEMenuItem(subMenu, PhCreateEMenuItem(0, 7, L"Config", NULL, NULL), ULONG_MAX);
458490
PhInsertEMenuItem(menu, subMenu, ULONG_MAX);
459491
PhInsertEMenuItem(menu, PhCreateEMenuSeparator(), ULONG_MAX);
460-
PhInsertEMenuItem(menu, PhCreateEMenuItem(0, 3, L"Properties", NULL, NULL), ULONG_MAX);
492+
PhInsertEMenuItem(menu, PhCreateEMenuItem(0, 10, L"Properties", NULL, NULL), ULONG_MAX);
461493

462494
selectedItem = PhShowEMenu(
463495
menu,
@@ -480,14 +512,22 @@ VOID ShowDeviceMenu(
480512
HardwareDeviceRestart(ParentWindow, DeviceInstance);
481513
break;
482514
case 3:
483-
HardwareDeviceShowProperties(ParentWindow, DeviceInstance);
515+
{
516+
if (HardwareDeviceUninstall(ParentWindow, DeviceInstance))
517+
{
518+
NOTHING;
519+
}
520+
}
484521
break;
485522
case 4:
486523
case 5:
487524
case 6:
488525
case 7:
489526
HardwareDeviceOpenKey(ParentWindow, DeviceInstance, selectedItem->Id);
490527
break;
528+
case 10:
529+
HardwareDeviceShowProperties(ParentWindow, DeviceInstance);
530+
break;
491531
}
492532
}
493533

plugins/HardwareDevices/netoptions.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -763,16 +763,16 @@ VOID LoadNetworkAdapterImages(
763763
{
764764
if (PhExtractIconEx(dllIconPath, FALSE, (INT)index, &smallIcon, NULL))
765765
{
766-
Context->ImageList = PhImageListCreate(
766+
HIMAGELIST imageList = PhImageListCreate(
767767
24, // GetSystemMetrics(SM_CXSMICON)
768768
24, // GetSystemMetrics(SM_CYSMICON)
769769
ILC_MASK | ILC_COLOR32,
770770
1,
771771
1
772772
);
773773

774-
PhImageListAddIcon(Context->ImageList, smallIcon);
775-
ListView_SetImageList(Context->ListViewHandle, Context->ImageList, LVSIL_SMALL);
774+
PhImageListAddIcon(imageList, smallIcon);
775+
ListView_SetImageList(Context->ListViewHandle, imageList, LVSIL_SMALL);
776776
DestroyIcon(smallIcon);
777777
}
778778

@@ -844,7 +844,6 @@ INT_PTR CALLBACK NetworkAdapterOptionsDlgProc(
844844
NetAdaptersSaveList();
845845

846846
FreeListViewAdapterEntries(context);
847-
if (context->ImageList) PhImageListDestroy(context->ImageList);
848847

849848
PhRemoveWindowContext(hwndDlg, PH_WINDOW_CONTEXT_DEFAULT);
850849
PhFree(context);
@@ -876,7 +875,6 @@ INT_PTR CALLBACK NetworkAdapterOptionsDlgProc(
876875

877876
FreeListViewAdapterEntries(context);
878877
ListView_DeleteAllItems(context->ListViewHandle);
879-
880878
FindNetworkAdapters(context);
881879

882880
ExtendedListView_SetColumnWidth(context->ListViewHandle, 0, ELVSCW_AUTOSIZE_REMAININGSPACE);
@@ -938,6 +936,10 @@ INT_PTR CALLBACK NetworkAdapterOptionsDlgProc(
938936
{
939937
ShowDeviceMenu(hwndDlg, deviceInstance);
940938
PhDereferenceObject(deviceInstance);
939+
940+
FreeListViewAdapterEntries(context);
941+
ListView_DeleteAllItems(context->ListViewHandle);
942+
FindNetworkAdapters(context);
941943
}
942944
}
943945
}

plugins/HardwareDevices/poweroptions.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -682,18 +682,18 @@ VOID LoadRaplDeviceImages(
682682

683683
if (PhExtractIconEx(deviceIconPath, FALSE, (INT)index, &smallIcon, NULL))
684684
{
685-
Context->ImageList = PhImageListCreate(
685+
HIMAGELIST imageList = PhImageListCreate(
686686
24, // GetSystemMetrics(SM_CXSMICON)
687687
24, // GetSystemMetrics(SM_CYSMICON)
688688
ILC_MASK | ILC_COLOR32,
689689
1,
690690
1
691691
);
692692

693-
PhImageListAddIcon(Context->ImageList, smallIcon);
693+
PhImageListAddIcon(imageList, smallIcon);
694694
DestroyIcon(smallIcon);
695695

696-
ListView_SetImageList(Context->ListViewHandle, Context->ImageList, LVSIL_SMALL);
696+
ListView_SetImageList(Context->ListViewHandle, imageList, LVSIL_SMALL);
697697
}
698698

699699
PhDereferenceObject(deviceIconPath);
@@ -758,7 +758,6 @@ INT_PTR CALLBACK RaplDeviceOptionsDlgProc(
758758
RaplDevicesSaveList();
759759

760760
FreeListViewRaplDeviceEntries(context);
761-
if (context->ImageList) PhImageListDestroy(context->ImageList);
762761

763762
PhRemoveWindowContext(hwndDlg, PH_WINDOW_CONTEXT_DEFAULT);
764763
PhFree(context);
@@ -824,6 +823,10 @@ INT_PTR CALLBACK RaplDeviceOptionsDlgProc(
824823
{
825824
ShowDeviceMenu(hwndDlg, deviceInstance);
826825
PhDereferenceObject(deviceInstance);
826+
827+
FreeListViewRaplDeviceEntries(context);
828+
ListView_DeleteAllItems(context->ListViewHandle);
829+
FindRaplDevices(context);
827830
}
828831
}
829832
}

plugins/HardwareDevices/resource.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
#define IDC_STAT_RESPONSETIME 1029
3838
#define IDC_GPUDISCRETE_L 1030
3939
#define IDC_CPUCOMP_L 1031
40+
#define IDC_STAT_QUEUELENGTH 1031
4041
#define IDC_TOTALPOWER_L 1032
42+
#define IDC_STAT_SPLITCOUNT 1032
4143
#define IDC_TITLE 1033
4244
#define IDC_DISKNAME 1034
4345
#define IDC_DEVICENAME 1035
@@ -51,7 +53,7 @@
5153
//
5254
#ifdef APSTUDIO_INVOKED
5355
#ifndef APSTUDIO_READONLY_SYMBOLS
54-
#define _APS_NEXT_RESOURCE_VALUE 111
56+
#define _APS_NEXT_RESOURCE_VALUE 112
5557
#define _APS_NEXT_COMMAND_VALUE 40001
5658
#define _APS_NEXT_CONTROL_VALUE 1041
5759
#define _APS_NEXT_SYMED_VALUE 109

0 commit comments

Comments
 (0)