/* * Copyright (c) 2022 Winsider Seminars & Solutions, Inc. All rights reserved. * * This file is part of System Informer. * * Authors: * * dmex 2015-2026 * */ #include "devices.h" _Function_class_(PH_GRAPH_MESSAGE_CALLBACK) BOOLEAN DiskDeviceGraphMessageCallback( _In_ HWND WindowHandle, _In_ ULONG Message, _In_ PVOID Parameter1, _In_ PVOID Parameter2, _In_ PVOID Context ); VOID DiskDeviceUpdatePanel( _Inout_ PDV_DISK_SYSINFO_CONTEXT Context ) { PH_FORMAT format[3]; WCHAR formatBuffer[256]; PhInitFormatSize(&format[0], Context->DiskEntry->BytesReadDelta.Value); if (PhFormatToBuffer(format, 1, formatBuffer, sizeof(formatBuffer), NULL)) PhSetWindowText(Context->DiskDevicePanelReadLabel, formatBuffer); else PhSetWindowText(Context->DiskDevicePanelReadLabel, PhaFormatSize(Context->DiskEntry->BytesReadDelta.Value, ULONG_MAX)->Buffer); PhInitFormatSize(&format[0], Context->DiskEntry->BytesWrittenDelta.Value); if (PhFormatToBuffer(format, 1, formatBuffer, sizeof(formatBuffer), NULL)) PhSetWindowText(Context->DiskDevicePanelWriteLabel, formatBuffer); else PhSetWindowText(Context->DiskDevicePanelWriteLabel, PhaFormatSize(Context->DiskEntry->BytesWrittenDelta.Value, ULONG_MAX)->Buffer); PhInitFormatSize(&format[0], Context->DiskEntry->BytesReadDelta.Value + Context->DiskEntry->BytesWrittenDelta.Value); if (PhFormatToBuffer(format, 1, formatBuffer, sizeof(formatBuffer), NULL)) PhSetWindowText(Context->DiskDevicePanelTotalLabel, formatBuffer); else PhSetWindowText(Context->DiskDevicePanelTotalLabel, PhaFormatSize(Context->DiskEntry->BytesReadDelta.Value + Context->DiskEntry->BytesWrittenDelta.Value, ULONG_MAX)->Buffer); PhInitFormatF(&format[0], Context->DiskEntry->ActiveTime, 0); PhInitFormatC(&format[1], L'%'); if (PhFormatToBuffer(format, 2, formatBuffer, sizeof(formatBuffer), NULL)) PhSetWindowText(Context->DiskDevicePanelActiveLabel, formatBuffer); else PhSetWindowText(Context->DiskDevicePanelActiveLabel, PhaFormatString(L"%.0f%%", Context->DiskEntry->ActiveTime)->Buffer); PhInitFormatF(&format[0], Context->DiskEntry->ResponseTime / PH_TICKS_PER_MS, 1); PhInitFormatS(&format[1], L" ms"); if (PhFormatToBuffer(format, 2, formatBuffer, sizeof(formatBuffer), NULL)) PhSetWindowText(Context->DiskDevicePanelTimeLabel, formatBuffer); else PhSetWindowText(Context->DiskDevicePanelTimeLabel, PhaFormatString(L"%.1f ms", Context->DiskEntry->ResponseTime / PH_TICKS_PER_MS)->Buffer); PhInitFormatSize(&format[0], Context->DiskEntry->CurrentBytesRead + Context->DiskEntry->CurrentBytesWritten); PhInitFormatS(&format[1], L"/s"); if (PhFormatToBuffer(format, 2, formatBuffer, sizeof(formatBuffer), NULL)) PhSetWindowText(Context->DiskDevicePanelBytesLabel, formatBuffer); else PhSetWindowText(Context->DiskDevicePanelBytesLabel, PhaFormatString(L"%s/s", PhaFormatSize(Context->DiskEntry->CurrentBytesRead + Context->DiskEntry->CurrentBytesWritten, ULONG_MAX)->Buffer)->Buffer); PhInitFormatI64UGroupDigits(&format[0], Context->DiskEntry->QueueDepth); PhInitFormatS(&format[1], L" | "); PhInitFormatI64UGroupDigits(&format[2], Context->DiskEntry->ReadCountDelta.Delta + Context->DiskEntry->WriteCountDelta.Delta); if (PhFormatToBuffer(format, 3, formatBuffer, sizeof(formatBuffer), NULL)) PhSetWindowText(GetDlgItem(Context->PanelWindowHandle, IDC_STAT_QUEUELENGTH), formatBuffer); else PhSetWindowText(GetDlgItem(Context->PanelWindowHandle, IDC_STAT_QUEUELENGTH), PhaFormatString(L"%lu | %lu", Context->DiskEntry->QueueDepth, Context->DiskEntry->ReadCountDelta.Delta + Context->DiskEntry->WriteCountDelta.Delta)->Buffer); PhInitFormatI64UGroupDigits(&format[0], Context->DiskEntry->SplitCount); if (PhFormatToBuffer(format, 1, formatBuffer, sizeof(formatBuffer), NULL)) PhSetWindowText(GetDlgItem(Context->PanelWindowHandle, IDC_STAT_SPLITCOUNT), formatBuffer); else PhSetWindowText(GetDlgItem(Context->PanelWindowHandle, IDC_STAT_SPLITCOUNT), PhaFormatString(L"%lu", Context->DiskEntry->SplitCount)->Buffer); } VOID DiskDeviceUpdateTitle( _In_ PDV_DISK_SYSINFO_CONTEXT Context ) { if (Context->DiskEntry->PendingQuery) { if (Context->DiskPathLabel) PhSetWindowText(Context->DiskPathLabel, L"Pending..."); if (Context->DiskNameLabel) PhSetWindowText(Context->DiskNameLabel, L"Pending..."); } else { if (Context->DiskPathLabel) PhSetWindowText(Context->DiskPathLabel, PhGetStringOrDefault(Context->DiskEntry->DiskIndexName, L"Unknown")); if (Context->DiskNameLabel) PhSetWindowText(Context->DiskNameLabel, PhGetStringOrDefault(Context->DiskEntry->DiskName, L"Unknown")); } } VOID DiskDeviceUpdateDeviceMountPoints( _In_ PDV_DISK_ENTRY DiskEntry ) { DiskDeviceUpdateDeviceInfo(NULL, DiskEntry); if (DiskEntry->DiskIndex != ULONG_MAX) { // Query the disk DosDevices mount points. PPH_STRING diskMountPoints = PH_AUTO_T(PH_STRING, DiskDriveQueryDosMountPoints(DiskEntry->DiskIndex)); if (!PhIsNullOrEmptyString(diskMountPoints)) { PH_FORMAT format[5]; // Disk %lu (%s) PhInitFormatS(&format[0], L"Disk "); PhInitFormatU(&format[1], DiskEntry->DiskIndex); PhInitFormatS(&format[2], L" ("); PhInitFormatSR(&format[3], diskMountPoints->sr); PhInitFormatC(&format[4], L')'); PhMoveReference(&DiskEntry->DiskIndexName, PhFormat(format, RTL_NUMBER_OF(format), 0)); } else { PH_FORMAT format[2]; // Disk %lu PhInitFormatS(&format[0], L"Disk "); PhInitFormatU(&format[1], DiskEntry->DiskIndex); PhMoveReference(&DiskEntry->DiskIndexName, PhFormat(format, RTL_NUMBER_OF(format), 0)); } } } INT_PTR CALLBACK DiskDevicePanelDialogProc( _In_ HWND WindowHandle, _In_ UINT WindowMessage, _In_ WPARAM wParam, _In_ LPARAM lParam ) { PDV_DISK_SYSINFO_CONTEXT context = NULL; if (WindowMessage == WM_INITDIALOG) { context = (PDV_DISK_SYSINFO_CONTEXT)lParam; PhSetWindowContext(WindowHandle, PH_WINDOW_CONTEXT_DEFAULT, context); } else { context = PhGetWindowContext(WindowHandle, PH_WINDOW_CONTEXT_DEFAULT); } if (context == NULL) return FALSE; switch (WindowMessage) { case WM_INITDIALOG: { PhInitializeThemeWindowGroupBoxes(WindowHandle); context->DiskDevicePanelReadLabel = GetDlgItem(WindowHandle, IDC_STAT_BREAD); context->DiskDevicePanelWriteLabel = GetDlgItem(WindowHandle, IDC_STAT_BWRITE); context->DiskDevicePanelTotalLabel = GetDlgItem(WindowHandle, IDC_STAT_BTOTAL); context->DiskDevicePanelActiveLabel = GetDlgItem(WindowHandle, IDC_STAT_ACTIVE); context->DiskDevicePanelTimeLabel = GetDlgItem(WindowHandle, IDC_STAT_RESPONSETIME); context->DiskDevicePanelBytesLabel = GetDlgItem(WindowHandle, IDC_STAT_BYTESDELTA); } break; case WM_NCDESTROY: { PhRemoveWindowContext(WindowHandle, PH_WINDOW_CONTEXT_DEFAULT); } break; case WM_COMMAND: { switch (GET_WM_COMMAND_ID(wParam, lParam)) { case IDC_DETAILS: ShowDiskDeviceDetailsDialog(context); break; } } break; case WM_CTLCOLORBTN: return HANDLE_WM_CTLCOLORBTN(WindowHandle, wParam, lParam, PhWindowThemeControlColor); case WM_CTLCOLORDLG: return HANDLE_WM_CTLCOLORDLG(WindowHandle, wParam, lParam, PhWindowThemeControlColor); case WM_CTLCOLORSTATIC: return HANDLE_WM_CTLCOLORSTATIC(WindowHandle, wParam, lParam, PhWindowThemeControlColor); } return FALSE; } VOID DiskDeviceUpdateDialogDpi( _In_ PDV_DISK_SYSINFO_CONTEXT Context ) { Context->GraphPadding = PhScaleToDisplay(RAPL_GRAPH_PADDING, Context->SysinfoSection->Parameters->WindowDpi); } VOID DiskDeviceGetGraphRects( _In_ PDV_DISK_SYSINFO_CONTEXT Context, _Out_writes_(2) RECT LabelRects[2], _Out_writes_(2) RECT GraphRects[2] ) { RECT clientRect; RECT labelRect; RECT marginRect; LONG graphWidth; LONG graphHeight; LONG graphPadding; LONG y; marginRect = Context->GraphMarginScaled; graphPadding = Context->GraphPadding; PhGetClientRect(Context->WindowHandle, &clientRect); PhGetClientRect(Context->LabelWriteHandle, &labelRect); graphWidth = clientRect.right - marginRect.left - marginRect.right; graphHeight = (clientRect.bottom - marginRect.top - marginRect.bottom - labelRect.bottom * 2 - graphPadding * 3) / 2; y = marginRect.top; for (ULONG i = 0; i < 2; i++) { LabelRects[i].left = marginRect.left; LabelRects[i].top = y; LabelRects[i].right = marginRect.left + labelRect.right; LabelRects[i].bottom = y + labelRect.bottom; y += labelRect.bottom + graphPadding; GraphRects[i].left = marginRect.left; GraphRects[i].top = y; GraphRects[i].right = marginRect.left + graphWidth; GraphRects[i].bottom = y + graphHeight; y += graphHeight + graphPadding; } } VOID DiskDeviceCreateGraphs( _Inout_ PDV_DISK_SYSINFO_CONTEXT Context ) { PH_GRAPH_CREATEPARAMS graphCreateParams; RECT labelRects[2]; RECT graphRects[2]; Context->LabelReadHandle = GetDlgItem(Context->WindowHandle, IDC_UP_L); Context->LabelWriteHandle = GetDlgItem(Context->WindowHandle, IDC_DOWN_L); DiskDeviceGetGraphRects(Context, labelRects, graphRects); PhInitializeGraphState(&Context->GraphReadState); PhInitializeGraphState(&Context->GraphWriteState); memset(&graphCreateParams, 0, sizeof(PH_GRAPH_CREATEPARAMS)); graphCreateParams.Size = sizeof(PH_GRAPH_CREATEPARAMS); graphCreateParams.Callback = DiskDeviceGraphMessageCallback; graphCreateParams.Context = Context; Context->GraphReadHandle = PhCreateWindow( PH_GRAPH_CLASSNAME, NULL, WS_VISIBLE | WS_CHILD | WS_BORDER | WS_CLIPSIBLINGS, graphRects[0].left, graphRects[0].top, graphRects[0].right - graphRects[0].left, graphRects[0].bottom - graphRects[0].top, Context->WindowHandle, NULL, NULL, &graphCreateParams ); Graph_SetTooltip(Context->GraphReadHandle, TRUE); Context->GraphWriteHandle = PhCreateWindow( PH_GRAPH_CLASSNAME, NULL, WS_VISIBLE | WS_CHILD | WS_BORDER | WS_CLIPSIBLINGS, graphRects[1].left, graphRects[1].top, graphRects[1].right - graphRects[1].left, graphRects[1].bottom - graphRects[1].top, Context->WindowHandle, NULL, NULL, &graphCreateParams ); Graph_SetTooltip(Context->GraphWriteHandle, TRUE); } VOID DiskDeviceUpdateGraphs( _Inout_ PDV_DISK_SYSINFO_CONTEXT Context ) { Context->GraphReadState.Valid = FALSE; Context->GraphReadState.TooltipIndex = ULONG_MAX; Graph_Update(Context->GraphWriteHandle); Context->GraphWriteState.Valid = FALSE; Context->GraphWriteState.TooltipIndex = ULONG_MAX; Graph_Update(Context->GraphReadHandle); } VOID DiskDeviceLayoutGraphs( _Inout_ PDV_DISK_SYSINFO_CONTEXT Context ) { RECT labelRects[2]; RECT graphRects[2]; HDWP deferHandle; Context->GraphReadState.Valid = FALSE; Context->GraphReadState.TooltipIndex = ULONG_MAX; Context->GraphWriteState.Valid = FALSE; Context->GraphWriteState.TooltipIndex = ULONG_MAX; DiskDeviceGetGraphRects(Context, labelRects, graphRects); deferHandle = BeginDeferWindowPos(4); deferHandle = DeferWindowPos( deferHandle, Context->LabelReadHandle, NULL, labelRects[0].left, labelRects[0].top, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER ); deferHandle = DeferWindowPos( deferHandle, Context->GraphReadHandle, NULL, graphRects[0].left, graphRects[0].top, graphRects[0].right - graphRects[0].left, graphRects[0].bottom - graphRects[0].top, SWP_NOACTIVATE | SWP_NOZORDER ); deferHandle = DeferWindowPos( deferHandle, Context->LabelWriteHandle, NULL, labelRects[1].left, labelRects[1].top, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER ); deferHandle = DeferWindowPos( deferHandle, Context->GraphWriteHandle, NULL, graphRects[1].left, graphRects[1].top, graphRects[1].right - graphRects[1].left, graphRects[1].bottom - graphRects[1].top, SWP_NOACTIVATE | SWP_NOZORDER ); EndDeferWindowPos(deferHandle); } VOID DiskDeviceNotifyReadGraph( _Inout_ PDV_DISK_SYSINFO_CONTEXT Context, _In_ NMHDR *Header ) { switch (Header->code) { case GCN_GETDRAWINFO: { PPH_GRAPH_GETDRAWINFO getDrawInfo = (PPH_GRAPH_GETDRAWINFO)Header; PPH_GRAPH_DRAW_INFO drawInfo = getDrawInfo->DrawInfo; drawInfo->Flags = PH_GRAPH_USE_GRID_X | PH_GRAPH_USE_GRID_Y | PH_GRAPH_LABEL_MAX_Y; Context->SysinfoSection->Parameters->ColorSetupFunction(drawInfo, PhGetIntegerSetting(SETTING_COLOR_IO_READ_OTHER), 0, Context->SysinfoSection->Parameters->WindowDpi); PhGraphStateGetDrawInfo( &Context->GraphWriteState, getDrawInfo, Context->DiskEntry->ReadBuffer.Count ); if (!Context->GraphWriteState.Valid) { ULONG i; FLOAT max = 4 * 1024; // Minimum scaling 4KB for (i = 0; i < drawInfo->LineDataCount; i++) { FLOAT data1; Context->GraphWriteState.Data1[i] = data1 = (FLOAT)PhGetItemCircularBuffer_ULONG64(&Context->DiskEntry->ReadBuffer, i); if (max < data1) max = data1; } if (max != 0) { // Scale the data. PhDivideSinglesBySingle( Context->GraphWriteState.Data1, max, drawInfo->LineDataCount ); } drawInfo->LabelYFunction = PhSiSizeLabelYFunction; drawInfo->LabelYFunctionParameter = max; Context->GraphWriteState.Valid = TRUE; } } break; case GCN_GETTOOLTIPTEXT: { PPH_GRAPH_GETTOOLTIPTEXT getTooltipText = (PPH_GRAPH_GETTOOLTIPTEXT)Header; if (getTooltipText->Index < getTooltipText->TotalCount) { if (Context->GraphWriteState.TooltipIndex != getTooltipText->Index) { ULONG64 value; PH_FORMAT format[4]; value = PhGetItemCircularBuffer_ULONG64( &Context->DiskEntry->ReadBuffer, getTooltipText->Index ); // R: %s\nW: %s\n%s PhInitFormatS(&format[0], L"R: "); PhInitFormatSize(&format[1], value); PhInitFormatC(&format[2], L'\n'); PhInitFormatSR(&format[3], PH_AUTO_T(PH_STRING, PhGetStatisticsTimeString(NULL, getTooltipText->Index))->sr); PhMoveReference(&Context->GraphWriteState.TooltipText, PhFormat(format, RTL_NUMBER_OF(format), 0)); } getTooltipText->Text = PhGetStringRef(Context->GraphWriteState.TooltipText); } } break; } } VOID DiskDeviceNotifyWriteGraph( _Inout_ PDV_DISK_SYSINFO_CONTEXT Context, _In_ NMHDR *Header ) { switch (Header->code) { case GCN_GETDRAWINFO: { PPH_GRAPH_GETDRAWINFO getDrawInfo = (PPH_GRAPH_GETDRAWINFO)Header; PPH_GRAPH_DRAW_INFO drawInfo = getDrawInfo->DrawInfo; drawInfo->Flags = PH_GRAPH_USE_GRID_X | PH_GRAPH_USE_GRID_Y | PH_GRAPH_LABEL_MAX_Y; Context->SysinfoSection->Parameters->ColorSetupFunction(drawInfo, PhGetIntegerSetting(SETTING_COLOR_IO_WRITE), 0, Context->SysinfoSection->Parameters->WindowDpi); PhGraphStateGetDrawInfo( &Context->GraphReadState, getDrawInfo, Context->DiskEntry->WriteBuffer.Count ); if (!Context->GraphReadState.Valid) { ULONG i; FLOAT max = 4 * 1024; // Minimum scaling 4KB for (i = 0; i < drawInfo->LineDataCount; i++) { FLOAT data1; Context->GraphReadState.Data1[i] = data1 = (FLOAT)PhGetItemCircularBuffer_ULONG64(&Context->DiskEntry->WriteBuffer, i); if (max < data1) max = data1; } if (max != 0) { // Scale the data. PhDivideSinglesBySingle( Context->GraphReadState.Data1, max, drawInfo->LineDataCount ); } drawInfo->LabelYFunction = PhSiSizeLabelYFunction; drawInfo->LabelYFunctionParameter = max; Context->GraphReadState.Valid = TRUE; } } break; case GCN_GETTOOLTIPTEXT: { PPH_GRAPH_GETTOOLTIPTEXT getTooltipText = (PPH_GRAPH_GETTOOLTIPTEXT)Header; if (getTooltipText->Index < getTooltipText->TotalCount) { if (Context->GraphReadState.TooltipIndex != getTooltipText->Index) { ULONG64 value; PH_FORMAT format[4]; value = PhGetItemCircularBuffer_ULONG64( &Context->DiskEntry->WriteBuffer, getTooltipText->Index ); // R: %s\nW: %s\n%s PhInitFormatS(&format[0], L"W: "); PhInitFormatSize(&format[1], value); PhInitFormatC(&format[2], L'\n'); PhInitFormatSR(&format[3], PH_AUTO_T(PH_STRING, PhGetStatisticsTimeString(NULL, getTooltipText->Index))->sr); PhMoveReference(&Context->GraphReadState.TooltipText, PhFormat(format, RTL_NUMBER_OF(format), 0)); } getTooltipText->Text = PhGetStringRef(Context->GraphReadState.TooltipText); } } break; } } _Function_class_(PH_GRAPH_MESSAGE_CALLBACK) BOOLEAN DiskDeviceGraphMessageCallback( _In_ HWND WindowHandle, _In_ ULONG Message, _In_ PVOID Parameter1, _In_ PVOID Parameter2, _In_ PVOID Context ) { PDV_DISK_SYSINFO_CONTEXT context = (PDV_DISK_SYSINFO_CONTEXT)Context; NMHDR *header = (NMHDR *)Parameter1; if (WindowHandle == context->GraphReadHandle) { DiskDeviceNotifyReadGraph(context, header); } else if (WindowHandle == context->GraphWriteHandle) { DiskDeviceNotifyWriteGraph(context, header); } return TRUE; } VOID DiskDeviceTickDialog( _Inout_ PDV_DISK_SYSINFO_CONTEXT Context ) { DiskDeviceUpdateGraphs(Context); DiskDeviceUpdatePanel(Context); } INT_PTR CALLBACK DiskDeviceDialogProc( _In_ HWND WindowHandle, _In_ UINT WindowMessage, _In_ WPARAM wParam, _In_ LPARAM lParam ) { PDV_DISK_SYSINFO_CONTEXT context = NULL; if (WindowMessage == WM_INITDIALOG) { context = (PDV_DISK_SYSINFO_CONTEXT)lParam; PhSetWindowContext(WindowHandle, PH_WINDOW_CONTEXT_DEFAULT, context); } else { context = PhGetWindowContext(WindowHandle, PH_WINDOW_CONTEXT_DEFAULT); } if (context == NULL) return FALSE; switch (WindowMessage) { case WM_INITDIALOG: { PPH_LAYOUT_ITEM graphItem; PPH_LAYOUT_ITEM panelItem; context->WindowHandle = WindowHandle; context->DiskPathLabel = GetDlgItem(WindowHandle, IDC_TITLE); context->DiskNameLabel = GetDlgItem(WindowHandle, IDC_DEVICENAME); PhInitializeLayoutManager(&context->LayoutManager, WindowHandle); PhAddLayoutItem(&context->LayoutManager, context->DiskPathLabel, NULL, PH_ANCHOR_LEFT | PH_ANCHOR_TOP | PH_ANCHOR_RIGHT | PH_LAYOUT_FORCE_INVALIDATE); PhAddLayoutItem(&context->LayoutManager, context->DiskNameLabel, NULL, PH_ANCHOR_RIGHT | PH_ANCHOR_TOP | PH_LAYOUT_FORCE_INVALIDATE); graphItem = PhAddLayoutItem(&context->LayoutManager, GetDlgItem(WindowHandle, IDC_GRAPH_LAYOUT), NULL, PH_ANCHOR_ALL); panelItem = PhAddLayoutItem(&context->LayoutManager, GetDlgItem(WindowHandle, IDC_PANEL_LAYOUT), NULL, PH_ANCHOR_LEFT | PH_ANCHOR_RIGHT | PH_ANCHOR_BOTTOM); context->GraphMargin = graphItem->Margin; context->GraphMarginScaled = context->GraphMargin; PhGetMarginDpiValue(&context->GraphMarginScaled, context->SysinfoSection->Parameters->WindowDpi, TRUE); SetWindowFont(context->DiskPathLabel, context->SysinfoSection->Parameters->LargeFont, FALSE); SetWindowFont(context->DiskNameLabel, context->SysinfoSection->Parameters->MediumFont, FALSE); PhSetWindowText(context->DiskPathLabel, PhGetStringOrDefault(context->DiskEntry->DiskIndexName, L"Unknown")); PhSetWindowText(context->DiskNameLabel, PhGetStringOrDefault(context->DiskEntry->DiskName, L"Unknown")); context->PanelWindowHandle = PhCreateDialog(PluginInstance->DllBase, MAKEINTRESOURCE(IDD_DISKDRIVE_PANEL), WindowHandle, DiskDevicePanelDialogProc, context); ShowWindow(context->PanelWindowHandle, SW_SHOW); PhAddLayoutItemExLogical(&context->LayoutManager, context->PanelWindowHandle, NULL, PH_ANCHOR_LEFT | PH_ANCHOR_RIGHT | PH_ANCHOR_BOTTOM, &panelItem->Margin); DiskDeviceUpdateDialogDpi(context); DiskDeviceUpdateTitle(context); DiskDeviceCreateGraphs(context); DiskDeviceUpdateGraphs(context); DiskDeviceUpdatePanel(context); } break; case WM_DESTROY: { PhDeleteLayoutManager(&context->LayoutManager); PhDeleteGraphState(&context->GraphWriteState); PhDeleteGraphState(&context->GraphReadState); if (context->GraphReadHandle) DestroyWindow(context->GraphReadHandle); if (context->GraphWriteHandle) DestroyWindow(context->GraphWriteHandle); if (context->PanelWindowHandle) DestroyWindow(context->PanelWindowHandle); } break; case WM_NCDESTROY: { PhRemoveWindowContext(WindowHandle, PH_WINDOW_CONTEXT_DEFAULT); } break; case WM_DPICHANGED_AFTERPARENT: { DiskDeviceUpdateDialogDpi(context); context->GraphMarginScaled = context->GraphMargin; PhGetMarginDpiValue(&context->GraphMarginScaled, context->SysinfoSection->Parameters->WindowDpi, TRUE); if (context->SysinfoSection->Parameters->LargeFont) { SetWindowFont(context->DiskPathLabel, context->SysinfoSection->Parameters->LargeFont, FALSE); } if (context->SysinfoSection->Parameters->MediumFont) { SetWindowFont(context->DiskNameLabel, context->SysinfoSection->Parameters->MediumFont, FALSE); } PhLayoutManagerUpdate(&context->LayoutManager, context->SysinfoSection->Parameters->WindowDpi); PhLayoutManagerLayout(&context->LayoutManager); DiskDeviceLayoutGraphs(context); } break; case WM_SIZE: { PhLayoutManagerLayout(&context->LayoutManager); DiskDeviceLayoutGraphs(context); } break; case WM_CTLCOLORBTN: return HANDLE_WM_CTLCOLORBTN(WindowHandle, wParam, lParam, PhWindowThemeControlColor); case WM_CTLCOLORDLG: return HANDLE_WM_CTLCOLORDLG(WindowHandle, wParam, lParam, PhWindowThemeControlColor); case WM_CTLCOLORSTATIC: return HANDLE_WM_CTLCOLORSTATIC(WindowHandle, wParam, lParam, PhWindowThemeControlColor); } return FALSE; } _Function_class_(USER_THREAD_START_ROUTINE) NTSTATUS DiskDeviceQueryNameWorkQueueItem( _In_ PDV_DISK_ENTRY DiskEntry ) { // Update the device index and mount points (dmex) DiskDeviceUpdateDeviceMountPoints(DiskEntry); #ifdef FORCE_DELAY_LABEL_WORKQUEUE PhDelayExecution(4000); #endif InterlockedExchange((volatile LONG*)&DiskEntry->JustProcessed, TRUE); DiskEntry->PendingQuery = FALSE; PhDereferenceObject(DiskEntry); return STATUS_SUCCESS; } VOID DiskDeviceQueueNameUpdate( _In_ PDV_DISK_ENTRY DiskEntry ) { DiskEntry->PendingQuery = TRUE; PhReferenceObject(DiskEntry); PhQueueItemWorkQueue(PhGetGlobalWorkQueue(), DiskDeviceQueryNameWorkQueueItem, DiskEntry); } _Function_class_(PH_SYSINFO_SECTION_CALLBACK) BOOLEAN DiskDeviceSectionCallback( _In_ PPH_SYSINFO_SECTION Section, _In_ PH_SYSINFO_SECTION_MESSAGE Message, _In_ PVOID Parameter1, _In_ PVOID Parameter2 ) { PDV_DISK_SYSINFO_CONTEXT context = (PDV_DISK_SYSINFO_CONTEXT)Section->Context; switch (Message) { case SysInfoCreate: { DiskDeviceQueueNameUpdate(context->DiskEntry); } return TRUE; case SysInfoDestroy: { PhDereferenceObject(context->DiskEntry); PhFree(context); } return TRUE; case SysInfoTick: { if (context->WindowHandle) { if (InterlockedExchangeAcquire((volatile LONG*)&context->DiskEntry->JustProcessed, FALSE)) { DiskDeviceUpdateTitle(context); } DiskDeviceTickDialog(context); } } return TRUE; case SysInfoViewChanging: { PH_SYSINFO_VIEW_TYPE view = (PH_SYSINFO_VIEW_TYPE)PtrToUlong(Parameter1); PPH_SYSINFO_SECTION section = (PPH_SYSINFO_SECTION)Parameter2; if (view == SysInfoSummaryView || section != Section) return TRUE; if (context->GraphReadHandle) { context->GraphReadState.Valid = FALSE; context->GraphReadState.TooltipIndex = ULONG_MAX; Graph_Draw(context->GraphReadHandle); } if (context->GraphWriteHandle) { context->GraphWriteState.Valid = FALSE; context->GraphWriteState.TooltipIndex = ULONG_MAX; Graph_Draw(context->GraphWriteHandle); } } return TRUE; case SysInfoCreateDialog: { PPH_SYSINFO_CREATE_DIALOG createDialog = (PPH_SYSINFO_CREATE_DIALOG)Parameter1; createDialog->Instance = PluginInstance->DllBase; createDialog->Template = MAKEINTRESOURCE(IDD_DISKDRIVE_DIALOG); createDialog->DialogProc = DiskDeviceDialogProc; createDialog->Parameter = context; } return TRUE; case SysInfoGraphGetDrawInfo: { PPH_GRAPH_DRAW_INFO drawInfo = (PPH_GRAPH_DRAW_INFO)Parameter1; drawInfo->Flags = PH_GRAPH_USE_GRID_X | PH_GRAPH_USE_GRID_Y | PH_GRAPH_LABEL_MAX_Y | PH_GRAPH_USE_LINE_2; Section->Parameters->ColorSetupFunction(drawInfo, PhGetIntegerSetting(SETTING_COLOR_IO_READ_OTHER), PhGetIntegerSetting(SETTING_COLOR_IO_WRITE), context->SysinfoSection->Parameters->WindowDpi); PhGetDrawInfoGraphBuffers(&Section->GraphState.Buffers, drawInfo, context->DiskEntry->ReadBuffer.Count); if (!Section->GraphState.Valid) { FLOAT max = 1024 * 1024; // minimum scaling of 1 MB. for (ULONG i = 0; i < drawInfo->LineDataCount; i++) { FLOAT data1; FLOAT data2; Section->GraphState.Data1[i] = data1 = (FLOAT)PhGetItemCircularBuffer_ULONG64(&context->DiskEntry->ReadBuffer, i); Section->GraphState.Data2[i] = data2 = (FLOAT)PhGetItemCircularBuffer_ULONG64(&context->DiskEntry->WriteBuffer, i); if (max < data1 + data2) max = data1 + data2; } if (max != 0) { // Scale the data. PhDivideSinglesBySingle( Section->GraphState.Data1, max, drawInfo->LineDataCount ); // Scale the data. PhDivideSinglesBySingle( Section->GraphState.Data2, max, drawInfo->LineDataCount ); } drawInfo->LabelYFunction = PhSiSizeLabelYFunction; drawInfo->LabelYFunctionParameter = max; Section->GraphState.Valid = TRUE; } } return TRUE; case SysInfoGraphGetTooltipText: { PPH_SYSINFO_GRAPH_GET_TOOLTIP_TEXT getTooltipText = (PPH_SYSINFO_GRAPH_GET_TOOLTIP_TEXT)Parameter1; ULONG64 diskReadValue; ULONG64 diskWriteValue; PH_FORMAT format[6]; diskReadValue = PhGetItemCircularBuffer_ULONG64( &context->DiskEntry->ReadBuffer, getTooltipText->Index ); diskWriteValue = PhGetItemCircularBuffer_ULONG64( &context->DiskEntry->WriteBuffer, getTooltipText->Index ); // R: %s\nW: %s\n%s PhInitFormatS(&format[0], L"R: "); PhInitFormatSize(&format[1], diskReadValue); PhInitFormatS(&format[2], L"\nW: "); PhInitFormatSize(&format[3], diskWriteValue); PhInitFormatC(&format[4], L'\n'); PhInitFormatSR(&format[5], PH_AUTO_T(PH_STRING, PhGetStatisticsTimeString(NULL, getTooltipText->Index))->sr); PhMoveReference(&Section->GraphState.TooltipText, PhFormat(format, RTL_NUMBER_OF(format), 0)); getTooltipText->Text = PhGetStringRef(Section->GraphState.TooltipText); } return TRUE; case SysInfoGraphDrawPanel: { PPH_SYSINFO_DRAW_PANEL drawPanel = (PPH_SYSINFO_DRAW_PANEL)Parameter1; PH_FORMAT format[4]; if (context->DiskEntry->PendingQuery) PhMoveReference(&drawPanel->Title, PhCreateString(L"Pending...")); else PhSetReference(&drawPanel->Title, context->DiskEntry->DiskIndexName); if (!drawPanel->Title) drawPanel->Title = PhCreateString(L"Unknown"); // R: %s\nW: %s PhInitFormatS(&format[0], L"R: "); PhInitFormatSize(&format[1], context->DiskEntry->BytesReadDelta.Delta); PhInitFormatS(&format[2], L"\nW: "); PhInitFormatSize(&format[3], context->DiskEntry->BytesWrittenDelta.Delta); drawPanel->SubTitle = PhFormat(format, RTL_NUMBER_OF(format), 0); } return TRUE; } return FALSE; } VOID DiskDeviceSysInfoInitializing( _In_ PPH_PLUGIN_SYSINFO_POINTERS Pointers, _In_ _Assume_refs_(1) PDV_DISK_ENTRY DiskEntry ) { static CONST PH_STRINGREF text = PH_STRINGREF_INIT(L"Unknown"); PDV_DISK_SYSINFO_CONTEXT context; PH_SYSINFO_SECTION section; context = PhAllocateZero(sizeof(DV_DISK_SYSINFO_CONTEXT)); PhInitializeEvent(&context->DetailsWindowInitializedEvent); context->DiskEntry = PhReferenceObject(DiskEntry); context->DiskEntry->PendingQuery = TRUE; memset(§ion, 0, sizeof(PH_SYSINFO_SECTION)); section.Context = context; section.Callback = DiskDeviceSectionCallback; section.Name = text; context->SysinfoSection = Pointers->CreateSection(§ion); }