Something went wrong. Try again.
Reactos
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196/* * ReactOS Device Manager Applet * Copyright (C) 2004 - 2005 ReactOS Team * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *//* * * PROJECT: ReactOS devmgr.dll * FILE: lib/devmgr/advprop.c * PURPOSE: ReactOS Device Manager * PROGRAMMER: Thomas Weidenmueller <w3seek@reactos.com> * Ged Murphy <gedmurphy@reactos.org> * UPDATE HISTORY: * 04-04-2004 Created */
#include "precomp.h"#include "properties.h"#include "resource.h"
#include <winver.h>
#define PDCAP_D0_SUPPORTED 0x00000001#define PDCAP_D1_SUPPORTED 0x00000002#define PDCAP_D2_SUPPORTED 0x00000004#define PDCAP_D3_SUPPORTED 0x00000008#define PDCAP_WAKE_FROM_D0_SUPPORTED 0x00000010#define PDCAP_WAKE_FROM_D1_SUPPORTED 0x00000020#define PDCAP_WAKE_FROM_D2_SUPPORTED 0x00000040#define PDCAP_WAKE_FROM_D3_SUPPORTED 0x00000080#define PDCAP_WARM_EJECT_SUPPORTED 0x00000100
typedef struct CM_Power_Data_s{ ULONG PD_Size; DEVICE_POWER_STATE PD_MostRecentPowerState; ULONG PD_Capabilities; ULONG PD_D1Latency; ULONG PD_D2Latency; ULONG PD_D3Latency; DEVICE_POWER_STATE PD_PowerStateMapping[PowerSystemMaximum]; SYSTEM_POWER_STATE PD_DeepestSystemWake;} CM_POWER_DATA, *PCM_POWER_DATA;
static UINT WINAPIEnumDeviceDriverFilesCallback(IN PVOID Context, IN UINT Notification, IN UINT_PTR Param1, IN UINT_PTR Param2){ LVITEM li; PENUMDRIVERFILES_CONTEXT EnumDriverFilesContext = (PENUMDRIVERFILES_CONTEXT)Context;
li.mask = LVIF_TEXT | LVIF_STATE; li.iItem = EnumDriverFilesContext->nCount++; li.iSubItem = 0; li.state = (li.iItem == 0 ? LVIS_SELECTED : 0); li.stateMask = LVIS_SELECTED; li.pszText = (LPWSTR)Param1; (void)ListView_InsertItem(EnumDriverFilesContext->hDriversListView, &li); return NO_ERROR;}
static VOIDUpdateDriverDetailsDlg(IN HWND hwndDlg, IN HWND hDriversListView, IN PDEVADVPROP_INFO dap){ HDEVINFO DeviceInfoSet; PSP_DEVINFO_DATA DeviceInfoData; SP_DRVINFO_DATA DriverInfoData; ENUMDRIVERFILES_CONTEXT EnumDriverFilesContext;
if (dap->CurrentDeviceInfoSet != INVALID_HANDLE_VALUE) { DeviceInfoSet = dap->CurrentDeviceInfoSet; DeviceInfoData = &dap->CurrentDeviceInfoData; } else { DeviceInfoSet = dap->DeviceInfoSet; DeviceInfoData = &dap->DeviceInfoData; }
/* set the device image */ SendDlgItemMessage(hwndDlg, IDC_DEVICON, STM_SETICON, (WPARAM)dap->hDevIcon, 0);
/* set the device name edit control text */ SetDlgItemText(hwndDlg, IDC_DEVNAME, dap->szDevName);
/* fill the driver files list view */ EnumDriverFilesContext.hDriversListView = hDriversListView; EnumDriverFilesContext.nCount = 0;
(void)ListView_DeleteAllItems(EnumDriverFilesContext.hDriversListView); DriverInfoData.cbSize = sizeof(SP_DRVINFO_DATA); if (FindCurrentDriver(DeviceInfoSet, DeviceInfoData, &DriverInfoData) && SetupDiSetSelectedDriver(DeviceInfoSet, DeviceInfoData, &DriverInfoData)) { HSPFILEQ queueHandle;
queueHandle = SetupOpenFileQueue(); if (queueHandle != (HSPFILEQ)INVALID_HANDLE_VALUE) { SP_DEVINSTALL_PARAMS DeviceInstallParams = {0}; DeviceInstallParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS); if (SetupDiGetDeviceInstallParams(DeviceInfoSet, DeviceInfoData, &DeviceInstallParams)) { DeviceInstallParams.FileQueue = queueHandle; DeviceInstallParams.Flags |= DI_NOVCP;
if (SetupDiSetDeviceInstallParams(DeviceInfoSet, DeviceInfoData, &DeviceInstallParams) && SetupDiCallClassInstaller(DIF_INSTALLDEVICEFILES, DeviceInfoSet, DeviceInfoData)) { DWORD scanResult; RECT rcClient; LVCOLUMN lvc;
/* enumerate the driver files */ SetupScanFileQueue(queueHandle, SPQ_SCAN_USE_CALLBACK, NULL, EnumDeviceDriverFilesCallback, &EnumDriverFilesContext, &scanResult);
/* update the list view column width */ GetClientRect(hDriversListView, &rcClient); lvc.mask = LVCF_WIDTH; lvc.cx = rcClient.right; (void)ListView_SetColumn(hDriversListView, 0, &lvc);
/* highlight the first item from list */ if (ListView_GetSelectedCount(hDriversListView) != 0) { ListView_SetItemState(hDriversListView, 0, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); } } }
SetupCloseFileQueue(queueHandle); } }}
static VOIDUpdateDriverVersionInfoDetails(IN HWND hwndDlg, IN LPCWSTR lpszDriverPath){ DWORD dwHandle; DWORD dwVerInfoSize; LPVOID lpData = NULL; LPVOID lpInfo; UINT uInfoLen; DWORD dwLangId; WCHAR szLangInfo[255]; WCHAR szLangPath[MAX_PATH]; LPWSTR lpCompanyName = NULL; LPWSTR lpFileVersion = NULL; LPWSTR lpLegalCopyright = NULL; LPWSTR lpDigitalSigner = NULL; UINT uBufLen; WCHAR szNotAvailable[255];
/* extract version info from selected file */ dwVerInfoSize = GetFileVersionInfoSize(lpszDriverPath, &dwHandle); if (!dwVerInfoSize) goto done;
lpData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwVerInfoSize); if (!lpData) goto done;
if (!GetFileVersionInfo(lpszDriverPath, dwHandle, dwVerInfoSize, lpData)) goto done;
if (!VerQueryValue(lpData, L"\\VarFileInfo\\Translation", &lpInfo, &uInfoLen)) goto done;
dwLangId = *(LPDWORD)lpInfo; swprintf(szLangInfo, L"\\StringFileInfo\\%04x%04x\\", LOWORD(dwLangId), HIWORD(dwLangId));
/* read CompanyName */ wcscpy(szLangPath, szLangInfo); wcscat(szLangPath, L"CompanyName");
VerQueryValue(lpData, szLangPath, (void **)&lpCompanyName, (PUINT)&uBufLen);
/* read FileVersion */ wcscpy(szLangPath, szLangInfo); wcscat(szLangPath, L"FileVersion");
VerQueryValue(lpData, szLangPath, (void **)&lpFileVersion, (PUINT)&uBufLen);
/* read LegalTrademarks */ wcscpy(szLangPath, szLangInfo); wcscat(szLangPath, L"LegalCopyright");
VerQueryValue(lpData, szLangPath, (void **)&lpLegalCopyright, (PUINT)&uBufLen);
/* TODO: read digital signer info */
done: if (!LoadString(hDllInstance, IDS_NOTAVAILABLE, szNotAvailable, sizeof(szNotAvailable) / sizeof(WCHAR))) { wcscpy(szNotAvailable, L"n/a"); }
/* update labels */ if (!lpCompanyName) lpCompanyName = szNotAvailable; SetDlgItemText(hwndDlg, IDC_FILEPROVIDER, lpCompanyName);
if (!lpFileVersion) lpFileVersion = szNotAvailable; SetDlgItemText(hwndDlg, IDC_FILEVERSION, lpFileVersion);
if (!lpLegalCopyright) lpLegalCopyright = szNotAvailable; SetDlgItemText(hwndDlg, IDC_FILECOPYRIGHT, lpLegalCopyright);
if (!lpDigitalSigner) lpDigitalSigner = szNotAvailable; SetDlgItemText(hwndDlg, IDC_DIGITALSIGNER, lpDigitalSigner);
/* release version info */ if (lpData) HeapFree(GetProcessHeap(), 0, lpData);}
static INT_PTRCALLBACKDriverDetailsDlgProc(IN HWND hwndDlg, IN UINT uMsg, IN WPARAM wParam, IN LPARAM lParam){ PDEVADVPROP_INFO dap; INT_PTR Ret = FALSE;
dap = (PDEVADVPROP_INFO)GetWindowLongPtr(hwndDlg, DWLP_USER);
if (dap != NULL || uMsg == WM_INITDIALOG) { switch (uMsg) { case WM_COMMAND: { switch (LOWORD(wParam)) { case IDOK: case IDCANCEL: { EndDialog(hwndDlg, IDOK); break; } } break; }
case WM_CLOSE: { EndDialog(hwndDlg, IDCANCEL); break; }
case WM_INITDIALOG: { LV_COLUMN lvc; HWND hDriversListView; WCHAR szBuffer[260];
dap = (PDEVADVPROP_INFO)lParam; if (dap != NULL) { SetWindowLongPtr(hwndDlg, DWLP_USER, (DWORD_PTR)dap);
hDriversListView = GetDlgItem(hwndDlg, IDC_DRIVERFILES);
/* add a column to the list view control */ lvc.mask = LVCF_FMT | LVCF_WIDTH; lvc.fmt = LVCFMT_LEFT; lvc.cx = 0; (void)ListView_InsertColumn(hDriversListView, 0, &lvc);
UpdateDriverDetailsDlg(hwndDlg, hDriversListView, dap);
if (ListView_GetItemCount(hDriversListView) == 0) { if (LoadStringW(hDllInstance, IDS_NODRIVERS, szBuffer, _countof(szBuffer))) MessageBoxW(hwndDlg, szBuffer, dap->szDevName, MB_OK); EndDialog(hwndDlg, IDCANCEL); } }
Ret = TRUE; break; }
case WM_NOTIFY: { LPNMHDR pnmhdr = (LPNMHDR)lParam;
switch (pnmhdr->code) { case LVN_ITEMCHANGED: { LPNMLISTVIEW pnmv = (LPNMLISTVIEW)lParam; HWND hDriversListView = GetDlgItem(hwndDlg, IDC_DRIVERFILES);
if (ListView_GetSelectedCount(hDriversListView) == 0) { /* nothing is selected - empty the labels */ SetDlgItemText(hwndDlg, IDC_FILEPROVIDER, NULL); SetDlgItemText(hwndDlg, IDC_FILEVERSION, NULL); SetDlgItemText(hwndDlg, IDC_FILECOPYRIGHT, NULL); SetDlgItemText(hwndDlg, IDC_DIGITALSIGNER, NULL); } else if (pnmv->uNewState != 0) { /* extract version info and update the labels */ WCHAR szDriverPath[MAX_PATH];
ListView_GetItemText(hDriversListView, pnmv->iItem, pnmv->iSubItem, szDriverPath, _countof(szDriverPath));
UpdateDriverVersionInfoDetails(hwndDlg, szDriverPath); } } } break; } } }
return Ret;}
staticINT_PTRCALLBACKUninstallDriverDlgProc(IN HWND hwndDlg, IN UINT uMsg, IN WPARAM wParam, IN LPARAM lParam){ PDEVADVPROP_INFO dap; INT_PTR Ret = FALSE;
dap = (PDEVADVPROP_INFO)GetWindowLongPtr(hwndDlg, DWLP_USER);
if (dap != NULL || uMsg == WM_INITDIALOG) { switch (uMsg) { case WM_INITDIALOG: dap = (PDEVADVPROP_INFO)lParam; if (dap != NULL) { SetWindowLongPtr(hwndDlg, DWLP_USER, (DWORD_PTR)dap);
/* Set the device image */ SendDlgItemMessage(hwndDlg, IDC_DEVICON, STM_SETICON, (WPARAM)dap->hDevIcon, 0);
/* Set the device name */ SetDlgItemText(hwndDlg, IDC_DEVNAME, dap->szDevName); }
Ret = TRUE; break;
case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: EndDialog(hwndDlg, IDOK); break;
case IDCANCEL: EndDialog(hwndDlg, IDCANCEL); break; } break;
case WM_CLOSE: EndDialog(hwndDlg, IDCANCEL); break; } }
return Ret;}
staticVOIDUninstallDriver( _In_ HWND hwndDlg, _In_ PDEVADVPROP_INFO dap){ SP_REMOVEDEVICE_PARAMS RemoveDevParams;
if (DialogBoxParam(hDllInstance, MAKEINTRESOURCE(IDD_UNINSTALLDRIVER), hwndDlg, UninstallDriverDlgProc, (ULONG_PTR)dap) == IDCANCEL) return;
RemoveDevParams.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER); RemoveDevParams.ClassInstallHeader.InstallFunction = DIF_REMOVE; RemoveDevParams.Scope = DI_REMOVEDEVICE_GLOBAL; RemoveDevParams.HwProfile = 0;
SetupDiSetClassInstallParamsW(dap->DeviceInfoSet, &dap->DeviceInfoData, &RemoveDevParams.ClassInstallHeader, sizeof(SP_REMOVEDEVICE_PARAMS));
SetupDiCallClassInstaller(DIF_REMOVE, dap->DeviceInfoSet, &dap->DeviceInfoData);
SetupDiSetClassInstallParamsW(dap->DeviceInfoSet, &dap->DeviceInfoData, NULL, 0);}
staticVOIDUpdateDriver( IN HWND hwndDlg, IN PDEVADVPROP_INFO dap){ TOKEN_PRIVILEGES Privileges; HANDLE hToken; DWORD dwReboot; BOOL NeedReboot = FALSE;
// Better use InstallDevInst: // BOOL // WINAPI // InstallDevInst( // HWND hWnd, // LPWSTR wszDeviceId, // BOOL bUpdate, // DWORD *dwReboot); // See: http://comp.os.ms-windows.programmer.win32.narkive.com/J8FTd4KK/signature-of-undocumented-installdevinstex
if (!InstallDevInst(hwndDlg, dap->szDeviceID, TRUE, &dwReboot)) return;
if (NeedReboot == FALSE) return;
//FIXME: load text from resource file if (MessageBoxW(hwndDlg, L"Reboot now?", L"Reboot required", MB_YESNO | MB_ICONQUESTION) != IDYES) return;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken)) { ERR("OpenProcessToken failed\n"); return; }
/* Get the LUID for the Shutdown privilege */ if (!LookupPrivilegeValueW(NULL, SE_SHUTDOWN_NAME, &Privileges.Privileges[0].Luid)) { ERR("LookupPrivilegeValue failed\n"); CloseHandle(hToken); return; }
/* Assign the Shutdown privilege to our process */ Privileges.PrivilegeCount = 1; Privileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if (!AdjustTokenPrivileges(hToken, FALSE, &Privileges, 0, NULL, NULL)) { ERR("AdjustTokenPrivileges failed\n"); CloseHandle(hToken); return; }
/* Finally shut down the system */ if (!ExitWindowsEx(EWX_REBOOT, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER | SHTDN_REASON_FLAG_PLANNED)) { ERR("ExitWindowsEx failed\n"); CloseHandle(hToken); }}
static VOIDUpdateDriverDlg(IN HWND hwndDlg, IN PDEVADVPROP_INFO dap){ HDEVINFO DeviceInfoSet; PSP_DEVINFO_DATA DeviceInfoData; DWORD dwStatus = 0; DWORD dwProblem = 0; CONFIGRET cr;
if (dap->CurrentDeviceInfoSet != INVALID_HANDLE_VALUE) { DeviceInfoSet = dap->CurrentDeviceInfoSet; DeviceInfoData = &dap->CurrentDeviceInfoData; } else { DeviceInfoSet = dap->DeviceInfoSet; DeviceInfoData = &dap->DeviceInfoData; }
/* set the device image */ SendDlgItemMessage(hwndDlg, IDC_DEVICON, STM_SETICON, (WPARAM)dap->hDevIcon, 0);
/* set the device name edit control text */ SetDlgItemText(hwndDlg, IDC_DEVNAME, dap->szDevName);
/* query the driver provider */ if (GetDriverProviderString(DeviceInfoSet, DeviceInfoData, dap->szTemp, sizeof(dap->szTemp) / sizeof(dap->szTemp[0]))) { SetDlgItemText(hwndDlg, IDC_DRVPROVIDER, dap->szTemp); }
/* query the driver date */ if (GetDriverDateString(DeviceInfoSet, DeviceInfoData, dap->szTemp, sizeof(dap->szTemp) / sizeof(dap->szTemp[0]))) { SetDlgItemText(hwndDlg, IDC_DRVDATE, dap->szTemp); }
/* query the driver version */ if (GetDriverVersionString(DeviceInfoSet, DeviceInfoData, dap->szTemp, sizeof(dap->szTemp) / sizeof(dap->szTemp[0]))) { SetDlgItemText(hwndDlg, IDC_DRVVERSION, dap->szTemp); }
/* Disable the Uninstall button if the driver cannot be removed */ cr = CM_Get_DevNode_Status_Ex(&dwStatus, &dwProblem, dap->DeviceInfoData.DevInst, 0, dap->hMachine); if (cr == CR_SUCCESS) { if ((dwStatus & DN_ROOT_ENUMERATED) != 0 && (dwStatus & DN_DISABLEABLE) == 0) EnableWindow(GetDlgItem(hwndDlg, IDC_UNINSTALLDRIVER), FALSE); }}
static INT_PTRCALLBACKAdvProcDriverDlgProc(IN HWND hwndDlg, IN UINT uMsg, IN WPARAM wParam, IN LPARAM lParam){ PDEVADVPROP_INFO dap; INT_PTR Ret = FALSE;
dap = (PDEVADVPROP_INFO)GetWindowLongPtr(hwndDlg, DWLP_USER);
if (dap != NULL || uMsg == WM_INITDIALOG) { switch (uMsg) { case WM_COMMAND: { switch (LOWORD(wParam)) { case IDC_DRIVERDETAILS: DialogBoxParam(hDllInstance, MAKEINTRESOURCE(IDD_DRIVERDETAILS), hwndDlg, DriverDetailsDlgProc, (ULONG_PTR)dap); break;
case IDC_UPDATEDRIVER: UpdateDriver(hwndDlg, dap); break;
case IDC_ROLLBACKDRIVER: // FIXME break;
case IDC_UNINSTALLDRIVER: UninstallDriver(hwndDlg, dap); break; } break; }
case WM_NOTIFY: { NMHDR *hdr = (NMHDR*)lParam; switch (hdr->code) { case PSN_APPLY: break; } break; }
case WM_INITDIALOG: { dap = (PDEVADVPROP_INFO)((LPPROPSHEETPAGE)lParam)->lParam; if (dap != NULL) { SetWindowLongPtr(hwndDlg, DWLP_USER, (DWORD_PTR)dap);
UpdateDriverDlg(hwndDlg, dap); } EnableWindow(GetDlgItem(hwndDlg, IDC_ROLLBACKDRIVER), FALSE); Ret = TRUE; break; } } }
return Ret;}
static VOIDSetListViewText(HWND hwnd, INT iItem, LPCWSTR lpText){ LVITEM li;
li.mask = LVIF_TEXT | LVIF_STATE; li.iItem = iItem; li.iSubItem = 0; li.state = 0; //(li.iItem == 0 ? LVIS_SELECTED : 0); li.stateMask = LVIS_SELECTED; li.pszText = (LPWSTR)lpText; (void)ListView_InsertItem(hwnd, &li);}
static VOIDUpdateDetailsDlg(IN HWND hwndDlg, IN PDEVADVPROP_INFO dap){ HWND hwndComboBox; HWND hwndListView; LV_COLUMN lvc; RECT rcClient;
UINT i; UINT Properties[] = { IDS_PROP_DEVICEID, IDS_PROP_HARDWAREIDS, IDS_PROP_COMPATIBLEIDS, IDS_PROP_MATCHINGDEVICEID, IDS_PROP_SERVICE, IDS_PROP_ENUMERATOR, IDS_PROP_CAPABILITIES, IDS_PROP_DEVNODEFLAGS, IDS_PROP_CONFIGFLAGS, IDS_PROP_CSCONFIGFLAGS, IDS_PROP_EJECTIONRELATIONS, IDS_PROP_REMOVALRELATIONS, IDS_PROP_BUSRELATIONS, IDS_PROP_DEVUPPERFILTERS, IDS_PROP_DEVLOWERFILTERS, IDS_PROP_CLASSUPPERFILTERS, IDS_PROP_CLASSLOWERFILTERS, IDS_PROP_CLASSINSTALLER, IDS_PROP_CLASSCOINSTALLER, IDS_PROP_DEVICECOINSTALLER, IDS_PROP_FIRMWAREREVISION, IDS_PROP_CURRENTPOWERSTATE, IDS_PROP_POWERCAPABILITIES, IDS_PROP_POWERSTATEMAPPINGS };
/* set the device image */ SendDlgItemMessage(hwndDlg, IDC_DEVICON, STM_SETICON, (WPARAM)dap->hDevIcon, 0);
/* set the device name edit control text */ SetDlgItemText(hwndDlg, IDC_DEVNAME, dap->szDevName);
hwndComboBox = GetDlgItem(hwndDlg, IDC_DETAILSPROPNAME);
hwndListView = GetDlgItem(hwndDlg, IDC_DETAILSPROPVALUE);
for (i = 0; i != sizeof(Properties) / sizeof(Properties[0]); i++) { /* fill in the device usage combo box */ if (LoadString(hDllInstance, Properties[i], dap->szTemp, sizeof(dap->szTemp) / sizeof(dap->szTemp[0]))) { SendMessage(hwndComboBox, CB_ADDSTRING, 0, (LPARAM)dap->szTemp); } }
GetClientRect(hwndListView, &rcClient);
/* add a column to the list view control */ lvc.mask = LVCF_FMT | LVCF_WIDTH; lvc.fmt = LVCFMT_LEFT; lvc.cx = rcClient.right; (void)ListView_InsertColumn(hwndListView, 0, &lvc);
SendMessage(hwndComboBox, CB_SETCURSEL, 0, 0);
SetListViewText(hwndListView, 0, dap->szDeviceID);
SetFocus(hwndComboBox);}
static VOIDDisplayDevicePropertyText(IN PDEVADVPROP_INFO dap, IN HWND hwndListView, IN DWORD dwProperty){ HDEVINFO DeviceInfoSet; PSP_DEVINFO_DATA DeviceInfoData; DWORD dwType; DWORD dwSize; DWORD dwValue; LPBYTE lpBuffer; LPWSTR lpStr; INT len; INT index;
if (dap->CurrentDeviceInfoSet != INVALID_HANDLE_VALUE) { DeviceInfoSet = dap->CurrentDeviceInfoSet; DeviceInfoData = &dap->CurrentDeviceInfoData; } else { DeviceInfoSet = dap->DeviceInfoSet; DeviceInfoData = &dap->DeviceInfoData; }
dwSize = 0; SetupDiGetDeviceRegistryProperty(DeviceInfoSet, DeviceInfoData, dwProperty, &dwType, NULL, 0, &dwSize); if (dwSize == 0) { if (GetLastError() != ERROR_FILE_NOT_FOUND) { swprintf(dap->szTemp, L"Error: Getting the size failed! (Error: %ld)", GetLastError()); SetListViewText(hwndListView, 0, dap->szTemp); } return; }
if (dwType == REG_SZ) dwSize += sizeof(WCHAR);
lpBuffer = (LPBYTE)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize); if (lpBuffer == NULL) { SetListViewText(hwndListView, 0, L"Error: Allocating the buffer failed!"); return; }
if (SetupDiGetDeviceRegistryProperty(DeviceInfoSet, DeviceInfoData, dwProperty, &dwType, lpBuffer, dwSize, &dwSize)) { if (dwType == REG_SZ) { SetListViewText(hwndListView, 0, (LPWSTR)lpBuffer); } else if (dwType == REG_MULTI_SZ) { lpStr = (LPWSTR)lpBuffer; index = 0; while (*lpStr != 0) { len = wcslen(lpStr) + 1;
SetListViewText(hwndListView, index, lpStr);
lpStr += len; index++; } } else if (dwType == REG_DWORD) { dwValue = *(DWORD *) lpBuffer;
switch (dwProperty) { case SPDRP_CAPABILITIES: index = 0; swprintf(dap->szTemp, L"%08lx", dwValue); SetListViewText(hwndListView, index++, dap->szTemp); if (dwValue & CM_DEVCAP_LOCKSUPPORTED) SetListViewText(hwndListView, index++, L"CM_DEVCAP_LOCKSUPPORTED"); if (dwValue & CM_DEVCAP_EJECTSUPPORTED) SetListViewText(hwndListView, index++, L"CM_DEVCAP_EJECTSUPPORTED"); if (dwValue & CM_DEVCAP_REMOVABLE) SetListViewText(hwndListView, index++, L"CM_DEVCAP_REMOVABLE"); if (dwValue & CM_DEVCAP_DOCKDEVICE) SetListViewText(hwndListView, index++, L"CM_DEVCAP_DOCKDEVICE"); if (dwValue & CM_DEVCAP_UNIQUEID) SetListViewText(hwndListView, index++, L"CM_DEVCAP_UNIQUEID"); if (dwValue & CM_DEVCAP_SILENTINSTALL) SetListViewText(hwndListView, index++, L"CM_DEVCAP_SILENTINSTALL"); if (dwValue & CM_DEVCAP_RAWDEVICEOK) SetListViewText(hwndListView, index++, L"CM_DEVCAP_RAWDEVICEOK"); if (dwValue & CM_DEVCAP_SURPRISEREMOVALOK) SetListViewText(hwndListView, index++, L"CM_DEVCAP_SURPRISEREMOVALOK"); if (dwValue & CM_DEVCAP_HARDWAREDISABLED) SetListViewText(hwndListView, index++, L"CM_DEVCAP_HARDWAREDISABLED"); if (dwValue & CM_DEVCAP_NONDYNAMIC) SetListViewText(hwndListView, index++, L"CM_DEVCAP_NONDYNAMIC"); break;
case SPDRP_CONFIGFLAGS: index = 0; swprintf(dap->szTemp, L"%08lx", dwValue); SetListViewText(hwndListView, index++, dap->szTemp); if (dwValue & CONFIGFLAG_DISABLED) SetListViewText(hwndListView, index++, L"CONFIGFLAG_DISABLED"); if (dwValue & CONFIGFLAG_REMOVED) SetListViewText(hwndListView, index++, L"CONFIGFLAG_REMOVED"); if (dwValue & CONFIGFLAG_MANUAL_INSTALL) SetListViewText(hwndListView, index++, L"CONFIGFLAG_MANUAL_INSTALL"); if (dwValue & CONFIGFLAG_IGNORE_BOOT_LC) SetListViewText(hwndListView, index++, L"CONFIGFLAG_IGNORE_BOOT_LC"); if (dwValue & CONFIGFLAG_NET_BOOT) SetListViewText(hwndListView, index++, L"CONFIGFLAG_NET_BOOT"); if (dwValue & CONFIGFLAG_REINSTALL) SetListViewText(hwndListView, index++, L"CONFIGFLAG_REINSTALL"); if (dwValue & CONFIGFLAG_FAILEDINSTALL) SetListViewText(hwndListView, index++, L"CONFIGFLAG_FAILEDINSTALL"); if (dwValue & CONFIGFLAG_CANTSTOPACHILD) SetListViewText(hwndListView, index++, L"CONFIGFLAG_CANTSTOPACHILD"); if (dwValue & CONFIGFLAG_OKREMOVEROM) SetListViewText(hwndListView, index++, L"CONFIGFLAG_OKREMOVEROM"); if (dwValue & CONFIGFLAG_NOREMOVEEXIT) SetListViewText(hwndListView, index++, L"CONFIGFLAG_NOREMOVEEXIT"); break;
default: swprintf(dap->szTemp, L"0x%08lx", dwValue); SetListViewText(hwndListView, 0, dap->szTemp); break; } } else { SetListViewText(hwndListView, 0, L"Error: Unsupported value type!");
} } else { SetListViewText(hwndListView, 0, L"Error: Retrieving the value failed!"); }
HeapFree(GetProcessHeap(), 0, lpBuffer);}
static VOIDDisplayDevNodeFlags(IN PDEVADVPROP_INFO dap, IN HWND hwndListView){ DWORD dwStatus = 0; DWORD dwProblem = 0; INT index;
CM_Get_DevNode_Status_Ex(&dwStatus, &dwProblem, dap->DeviceInfoData.DevInst, 0, dap->hMachine);
index = 0; swprintf(dap->szTemp, L"%08lx", dwStatus); SetListViewText(hwndListView, index++, dap->szTemp); if (dwStatus & DN_ROOT_ENUMERATED) SetListViewText(hwndListView, index++, L"DN_ROOT_ENUMERATED"); if (dwStatus & DN_DRIVER_LOADED) SetListViewText(hwndListView, index++, L"DN_DRIVER_LOADED"); if (dwStatus & DN_ENUM_LOADED) SetListViewText(hwndListView, index++, L"DN_ENUM_LOADED"); if (dwStatus & DN_STARTED) SetListViewText(hwndListView, index++, L"DN_STARTED"); if (dwStatus & DN_MANUAL) SetListViewText(hwndListView, index++, L"DN_MANUAL"); if (dwStatus & DN_NEED_TO_ENUM) SetListViewText(hwndListView, index++, L"DN_NEED_TO_ENUM"); if (dwStatus & DN_DRIVER_BLOCKED) SetListViewText(hwndListView, index++, L"DN_DRIVER_BLOCKED"); if (dwStatus & DN_HARDWARE_ENUM) SetListViewText(hwndListView, index++, L"DN_HARDWARE_ENUM"); if (dwStatus & DN_NEED_RESTART) SetListViewText(hwndListView, index++, L"DN_NEED_RESTART"); if (dwStatus & DN_CHILD_WITH_INVALID_ID) SetListViewText(hwndListView, index++, L"DN_CHILD_WITH_INVALID_ID"); if (dwStatus & DN_HAS_PROBLEM) SetListViewText(hwndListView, index++, L"DN_HAS_PROBLEM"); if (dwStatus & DN_FILTERED) SetListViewText(hwndListView, index++, L"DN_FILTERED"); if (dwStatus & DN_LEGACY_DRIVER) SetListViewText(hwndListView, index++, L"DN_LEGACY_DRIVER"); if (dwStatus & DN_DISABLEABLE) SetListViewText(hwndListView, index++, L"DN_DISABLEABLE"); if (dwStatus & DN_REMOVABLE) SetListViewText(hwndListView, index++, L"DN_REMOVABLE"); if (dwStatus & DN_PRIVATE_PROBLEM) SetListViewText(hwndListView, index++, L"DN_PRIVATE_PROBLEM"); if (dwStatus & DN_MF_PARENT) SetListViewText(hwndListView, index++, L"DN_MF_PARENT"); if (dwStatus & DN_MF_CHILD) SetListViewText(hwndListView, index++, L"DN_MF_CHILD"); if (dwStatus & DN_WILL_BE_REMOVED) SetListViewText(hwndListView, index++, L"DN_WILL_BE_REMOVED");
if (dwStatus & DN_NOT_FIRST_TIMEE) SetListViewText(hwndListView, index++, L"DN_NOT_FIRST_TIMEE"); if (dwStatus & DN_STOP_FREE_RES) SetListViewText(hwndListView, index++, L"DN_STOP_FREE_RES"); if (dwStatus & DN_REBAL_CANDIDATE) SetListViewText(hwndListView, index++, L"DN_REBAL_CANDIDATE"); if (dwStatus & DN_BAD_PARTIAL) SetListViewText(hwndListView, index++, L"DN_BAD_PARTIAL"); if (dwStatus & DN_NT_ENUMERATOR) SetListViewText(hwndListView, index++, L"DN_NT_ENUMERATOR"); if (dwStatus & DN_NT_DRIVER) SetListViewText(hwndListView, index++, L"DN_NT_DRIVER");
if (dwStatus & DN_NEEDS_LOCKING) SetListViewText(hwndListView, index++, L"DN_NEEDS_LOCKING"); if (dwStatus & DN_ARM_WAKEUP) SetListViewText(hwndListView, index++, L"DN_ARM_WAKEUP"); if (dwStatus & DN_APM_ENUMERATOR) SetListViewText(hwndListView, index++, L"DN_APM_ENUMERATOR"); if (dwStatus & DN_APM_DRIVER) SetListViewText(hwndListView, index++, L"DN_APM_DRIVER"); if (dwStatus & DN_SILENT_INSTALL) SetListViewText(hwndListView, index++, L"DN_SILENT_INSTALL"); if (dwStatus & DN_NO_SHOW_IN_DM) SetListViewText(hwndListView, index++, L"DN_NO_SHOW_IN_DM"); if (dwStatus & DN_BOOT_LOG_PROB) SetListViewText(hwndListView, index++, L"DN_BOOT_LOG_PROB");}
static VOIDDisplayDevNodeEnumerator(IN PDEVADVPROP_INFO dap, IN HWND hwndListView){ PSP_DEVINFO_DATA DeviceInfoData;
DWORD dwType = 0; WCHAR szBuffer[256]; DWORD dwSize = 256 * sizeof(WCHAR);
if (dap->CurrentDeviceInfoSet != INVALID_HANDLE_VALUE) { DeviceInfoData = &dap->CurrentDeviceInfoData; } else { DeviceInfoData = &dap->DeviceInfoData; }
CM_Get_DevNode_Registry_Property_ExW(DeviceInfoData->DevInst, CM_DRP_ENUMERATOR_NAME, &dwType, &szBuffer, &dwSize, 0, dap->hMachine);
SetListViewText(hwndListView, 0, szBuffer);}
static VOIDDisplayCsFlags(IN PDEVADVPROP_INFO dap, IN HWND hwndListView){ DWORD dwValue = 0; INT index;
CM_Get_HW_Prof_Flags_Ex(dap->szDevName, 0, /* current hardware profile */ &dwValue, 0, dap->hMachine);
index = 0; swprintf(dap->szTemp, L"%08lx", dwValue); SetListViewText(hwndListView, index++, dap->szTemp);
if (dwValue & CSCONFIGFLAG_DISABLED) SetListViewText(hwndListView, index++, L"CSCONFIGFLAG_DISABLED");
if (dwValue & CSCONFIGFLAG_DO_NOT_CREATE) SetListViewText(hwndListView, index++, L"CSCONFIGFLAG_DO_NOT_CREATE");
if (dwValue & CSCONFIGFLAG_DO_NOT_START) SetListViewText(hwndListView, index++, L"CSCONFIGFLAG_DO_NOT_START");}
static VOIDDisplayMatchingDeviceId(IN PDEVADVPROP_INFO dap, IN HWND hwndListView){ HDEVINFO DeviceInfoSet; PSP_DEVINFO_DATA DeviceInfoData; WCHAR szBuffer[256]; HKEY hKey; DWORD dwSize; DWORD dwType;
if (dap->CurrentDeviceInfoSet != INVALID_HANDLE_VALUE) { DeviceInfoSet = dap->CurrentDeviceInfoSet; DeviceInfoData = &dap->CurrentDeviceInfoData; } else { DeviceInfoSet = dap->DeviceInfoSet; DeviceInfoData = &dap->DeviceInfoData; }
hKey = SetupDiOpenDevRegKey(DeviceInfoSet, DeviceInfoData, DICS_FLAG_GLOBAL, 0, DIREG_DRV, KEY_QUERY_VALUE); if (hKey != INVALID_HANDLE_VALUE) { dwSize = 256 * sizeof(WCHAR); if (RegQueryValueEx(hKey, L"MatchingDeviceId", NULL, &dwType, (LPBYTE)szBuffer, &dwSize) == ERROR_SUCCESS) { SetListViewText(hwndListView, 0, szBuffer); }
RegCloseKey(hKey); }}
static VOIDDisplayClassCoinstallers(IN PDEVADVPROP_INFO dap, IN HWND hwndListView){ HDEVINFO DeviceInfoSet; PSP_DEVINFO_DATA DeviceInfoData; WCHAR szClassGuid[45]; HKEY hKey = (HKEY)INVALID_HANDLE_VALUE; DWORD dwSize; DWORD dwType; LPBYTE lpBuffer = NULL; LPWSTR lpStr; INT index; INT len; LONG lError;
if (dap->CurrentDeviceInfoSet != INVALID_HANDLE_VALUE) { DeviceInfoSet = dap->CurrentDeviceInfoSet; DeviceInfoData = &dap->CurrentDeviceInfoData; } else { DeviceInfoSet = dap->DeviceInfoSet; DeviceInfoData = &dap->DeviceInfoData; }
dwSize = 45 * sizeof(WCHAR); if (!SetupDiGetDeviceRegistryProperty(DeviceInfoSet, DeviceInfoData, SPDRP_CLASSGUID, &dwType, (LPBYTE)szClassGuid, dwSize, &dwSize)) return;
lError = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\CoDeviceInstallers", 0, GENERIC_READ, &hKey); if (lError != ERROR_SUCCESS) return;
dwSize = 0; lError = RegQueryValueEx(hKey, szClassGuid, NULL, &dwType, NULL, &dwSize); if (lError != ERROR_SUCCESS) goto done;
if (dwSize == 0) goto done;
lpBuffer = (LPBYTE)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize);
RegQueryValueEx(hKey, szClassGuid, NULL, &dwType, lpBuffer, &dwSize);
lpStr = (LPWSTR)lpBuffer; index = 0; while (*lpStr != 0) { len = wcslen(lpStr) + 1;
SetListViewText(hwndListView, index, lpStr);
lpStr += len; index++; }
done: if (lpBuffer != NULL) HeapFree(GetProcessHeap(), 0, lpBuffer);
if (hKey != INVALID_HANDLE_VALUE) RegCloseKey(hKey);}
static VOIDDisplayDeviceCoinstallers(IN PDEVADVPROP_INFO dap, IN HWND hwndListView){ HDEVINFO DeviceInfoSet; PSP_DEVINFO_DATA DeviceInfoData; HKEY hKey; DWORD dwSize; DWORD dwType; LPBYTE lpBuffer; LPWSTR lpStr; INT index; INT len;
if (dap->CurrentDeviceInfoSet != INVALID_HANDLE_VALUE) { DeviceInfoSet = dap->CurrentDeviceInfoSet; DeviceInfoData = &dap->CurrentDeviceInfoData; } else { DeviceInfoSet = dap->DeviceInfoSet; DeviceInfoData = &dap->DeviceInfoData; }
hKey = SetupDiOpenDevRegKey(DeviceInfoSet, DeviceInfoData, DICS_FLAG_GLOBAL, 0, DIREG_DRV, KEY_QUERY_VALUE); if (hKey != INVALID_HANDLE_VALUE) { dwSize = 0; if (RegQueryValueEx(hKey, L"CoInstallers32", NULL, &dwType, NULL, &dwSize) == ERROR_SUCCESS && dwSize > 0) {
lpBuffer = (LPBYTE)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize);
RegQueryValueEx(hKey, L"CoInstallers32", NULL, &dwType, lpBuffer, &dwSize);
lpStr = (LPWSTR)lpBuffer; index = 0; while (*lpStr != 0) { len = wcslen(lpStr) + 1;
SetListViewText(hwndListView, index, lpStr);
lpStr += len; index++; }
HeapFree(GetProcessHeap(), 0, lpBuffer); }
RegCloseKey(hKey); }}
static VOIDDisplayClassProperties(IN PDEVADVPROP_INFO dap, IN HWND hwndListView, IN LPCWSTR lpProperty){ HDEVINFO DeviceInfoSet; PSP_DEVINFO_DATA DeviceInfoData; WCHAR szClassGuid[45]; DWORD dwSize; DWORD dwType; HKEY hKey; GUID ClassGuid; LPBYTE lpBuffer; LPWSTR lpStr; INT index = 0; INT len;
if (dap->CurrentDeviceInfoSet != INVALID_HANDLE_VALUE) { DeviceInfoSet = dap->CurrentDeviceInfoSet; DeviceInfoData = &dap->CurrentDeviceInfoData; } else { DeviceInfoSet = dap->DeviceInfoSet; DeviceInfoData = &dap->DeviceInfoData; }
dwSize = 45 * sizeof(WCHAR); if (!SetupDiGetDeviceRegistryProperty(DeviceInfoSet, DeviceInfoData, SPDRP_CLASSGUID, &dwType, (LPBYTE)szClassGuid, dwSize, &dwSize)) return;
pSetupGuidFromString(szClassGuid, &ClassGuid);
hKey = SetupDiOpenClassRegKey(&ClassGuid, KEY_QUERY_VALUE); if (hKey != INVALID_HANDLE_VALUE) { dwSize = 0; if (RegQueryValueEx(hKey, lpProperty, NULL, &dwType, NULL, &dwSize) == ERROR_SUCCESS && dwSize > 0) { lpBuffer = (LPBYTE)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize);
RegQueryValueEx(hKey, lpProperty, NULL, &dwType, lpBuffer, &dwSize);
if (dwType == REG_SZ) { SetListViewText(hwndListView, 0, (LPWSTR)lpBuffer); } else if (dwType == REG_MULTI_SZ) { lpStr = (LPWSTR)lpBuffer; index = 0; while (*lpStr != 0) { len = wcslen(lpStr) + 1;
SetListViewText(hwndListView, index, lpStr);
lpStr += len; index++; } }
HeapFree(GetProcessHeap(), 0, lpBuffer); }
RegCloseKey(hKey); }}
static VOIDDisplayDeviceRelations( IN PDEVADVPROP_INFO dap, IN HWND hwndListView, IN ULONG ulFlags){ ULONG ulLength = 0; LPWSTR pszBuffer = NULL, pszStr; INT index = 0, len; CONFIGRET ret;
ret = CM_Get_Device_ID_List_Size_ExW(&ulLength, dap->szDeviceID, ulFlags, NULL); if (ret != CR_SUCCESS) return;
pszBuffer = (LPWSTR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ulLength * sizeof(WCHAR)); if (pszBuffer == NULL) return;
ret = CM_Get_Device_ID_List_ExW(dap->szDeviceID, pszBuffer, ulLength, ulFlags, NULL); if (ret != CR_SUCCESS) { HeapFree(GetProcessHeap(), 0, pszBuffer); return; }
pszStr = pszBuffer; index = 0; while (*pszStr != 0) { len = wcslen(pszStr) + 1;
SetListViewText(hwndListView, index, pszStr);
pszStr += len; index++; }
HeapFree(GetProcessHeap(), 0, pszBuffer);}
static VOIDDisplayCurrentPowerState( IN PDEVADVPROP_INFO dap, IN HWND hwndListView){ HDEVINFO DeviceInfoSet; PSP_DEVINFO_DATA DeviceInfoData; CM_POWER_DATA PowerData; DWORD dwSize, dwType; PCWSTR lpText = NULL;
if (dap->CurrentDeviceInfoSet != INVALID_HANDLE_VALUE) { DeviceInfoSet = dap->CurrentDeviceInfoSet; DeviceInfoData = &dap->CurrentDeviceInfoData; } else { DeviceInfoSet = dap->DeviceInfoSet; DeviceInfoData = &dap->DeviceInfoData; }
dwSize = sizeof(CM_POWER_DATA); if (!SetupDiGetDeviceRegistryProperty(DeviceInfoSet, DeviceInfoData, SPDRP_DEVICE_POWER_DATA, &dwType, (LPBYTE)&PowerData, dwSize, &dwSize)) return;
switch (PowerData.PD_MostRecentPowerState) {// case PowerDeviceUnspecified:
case PowerDeviceD0: lpText = L"D0"; break;
case PowerDeviceD1: lpText = L"D1"; break;
case PowerDeviceD2: lpText = L"D2"; break;
case PowerDeviceD3: lpText = L"D3"; break;
default: break; }
if (lpText != NULL) SetListViewText(hwndListView, 0, lpText);}
static VOIDDisplayPowerCapabilities( IN PDEVADVPROP_INFO dap, IN HWND hwndListView){ HDEVINFO DeviceInfoSet; PSP_DEVINFO_DATA DeviceInfoData; CM_POWER_DATA PowerData; DWORD dwSize, dwType; INT index = 0;
if (dap->CurrentDeviceInfoSet != INVALID_HANDLE_VALUE) { DeviceInfoSet = dap->CurrentDeviceInfoSet; DeviceInfoData = &dap->CurrentDeviceInfoData; } else { DeviceInfoSet = dap->DeviceInfoSet; DeviceInfoData = &dap->DeviceInfoData; }
dwSize = sizeof(CM_POWER_DATA); if (!SetupDiGetDeviceRegistryProperty(DeviceInfoSet, DeviceInfoData, SPDRP_DEVICE_POWER_DATA, &dwType, (LPBYTE)&PowerData, dwSize, &dwSize)) return;
if (PowerData.PD_Capabilities & PDCAP_D0_SUPPORTED) SetListViewText(hwndListView, index++, L"PDCAP_D0_SUPPORTED");
if (PowerData.PD_Capabilities & PDCAP_D1_SUPPORTED) SetListViewText(hwndListView, index++, L"PDCAP_D1_SUPPORTED");
if (PowerData.PD_Capabilities & PDCAP_D2_SUPPORTED) SetListViewText(hwndListView, index++, L"PDCAP_D2_SUPPORTED");
if (PowerData.PD_Capabilities & PDCAP_D3_SUPPORTED) SetListViewText(hwndListView, index++, L"PDCAP_D3_SUPPORTED");
if (PowerData.PD_Capabilities & PDCAP_WAKE_FROM_D0_SUPPORTED) SetListViewText(hwndListView, index++, L"PDCAP_WAKE_FROM_D0_SUPPORTED");
if (PowerData.PD_Capabilities & PDCAP_WAKE_FROM_D1_SUPPORTED) SetListViewText(hwndListView, index++, L"PDCAP_WAKE_FROM_D1_SUPPORTED");
if (PowerData.PD_Capabilities & PDCAP_WAKE_FROM_D2_SUPPORTED) SetListViewText(hwndListView, index++, L"PDCAP_WAKE_FROM_D2_SUPPORTED");
if (PowerData.PD_Capabilities & PDCAP_WAKE_FROM_D3_SUPPORTED) SetListViewText(hwndListView, index++, L"PDCAP_WAKE_FROM_D3_SUPPORTED");
if (PowerData.PD_Capabilities & PDCAP_WARM_EJECT_SUPPORTED) SetListViewText(hwndListView, index++, L"PDCAP_WARM_EJECT_SUPPORTED");}
static VOIDDisplayPowerStateMappings( IN PDEVADVPROP_INFO dap, IN HWND hwndListView){ HDEVINFO DeviceInfoSet; PSP_DEVINFO_DATA DeviceInfoData; CM_POWER_DATA PowerData; DWORD dwSize, dwType; INT i; DEVICE_POWER_STATE PowerState; WCHAR szSystemStateBuffer[40]; WCHAR szDeviceStateBuffer[40]; WCHAR szOutBuffer[100];
if (dap->CurrentDeviceInfoSet != INVALID_HANDLE_VALUE) { DeviceInfoSet = dap->CurrentDeviceInfoSet; DeviceInfoData = &dap->CurrentDeviceInfoData; } else { DeviceInfoSet = dap->DeviceInfoSet; DeviceInfoData = &dap->DeviceInfoData; }
dwSize = sizeof(CM_POWER_DATA); if (!SetupDiGetDeviceRegistryProperty(DeviceInfoSet, DeviceInfoData, SPDRP_DEVICE_POWER_DATA, &dwType, (LPBYTE)&PowerData, dwSize, &dwSize)) return;
for (i = PowerSystemWorking; i < PowerSystemMaximum; i++) { PowerState = PowerData.PD_PowerStateMapping[i]; if ((PowerState >= PowerDeviceUnspecified) && (PowerState <= PowerDeviceD3)) { swprintf(szSystemStateBuffer, L"S%u", i - 1);
switch (PowerState) { case PowerDeviceUnspecified: wcscpy(szDeviceStateBuffer, L"Not specified"); break;
case PowerDeviceD0: wcscpy(szDeviceStateBuffer, L"D0"); break;
case PowerDeviceD1: wcscpy(szDeviceStateBuffer, L"D1"); break;
case PowerDeviceD2: wcscpy(szDeviceStateBuffer, L"D2"); break;
case PowerDeviceD3: wcscpy(szDeviceStateBuffer, L"D3"); break;
default: break; }
swprintf(szOutBuffer, L"%s -> %s", szSystemStateBuffer, szDeviceStateBuffer); SetListViewText(hwndListView, i, szOutBuffer); } }}
static VOIDDisplayDeviceProperties(IN PDEVADVPROP_INFO dap, IN HWND hwndComboBox, IN HWND hwndListView){ INT Index;
Index = (INT)SendMessage(hwndComboBox, CB_GETCURSEL, 0, 0); if (Index == CB_ERR) return;
(void)ListView_DeleteAllItems(hwndListView);
switch (Index) { case 0: /* Device ID */ SetListViewText(hwndListView, 0, dap->szDeviceID); break;
case 1: /* Hardware ID */ DisplayDevicePropertyText(dap, hwndListView, SPDRP_HARDWAREID); break;
case 2: /* Compatible IDs */ DisplayDevicePropertyText(dap, hwndListView, SPDRP_COMPATIBLEIDS); break;
case 3: /* Matching ID */ DisplayMatchingDeviceId(dap, hwndListView); break;
case 4: /* Service */ DisplayDevicePropertyText(dap, hwndListView, SPDRP_SERVICE); break;
case 5: /* Enumerator */ DisplayDevNodeEnumerator(dap, hwndListView); break;
case 6: /* Capabilities */ DisplayDevicePropertyText(dap, hwndListView, SPDRP_CAPABILITIES); break;
case 7: /* Devnode Flags */ DisplayDevNodeFlags(dap, hwndListView); break;
case 8: /* Config Flags */ DisplayDevicePropertyText(dap, hwndListView, SPDRP_CONFIGFLAGS); break;
case 9: /* CSConfig Flags */ DisplayCsFlags(dap, hwndListView); break;
case 10: /* Ejection relation */ DisplayDeviceRelations(dap, hwndListView, CM_GETIDLIST_FILTER_EJECTRELATIONS); break;
case 11: /* Removal relations */ DisplayDeviceRelations(dap, hwndListView, CM_GETIDLIST_FILTER_REMOVALRELATIONS); break;
case 12: /* Bus relation */ DisplayDeviceRelations(dap, hwndListView, CM_GETIDLIST_FILTER_BUSRELATIONS); break;
case 13: /* Device Upper Filters */ DisplayDevicePropertyText(dap, hwndListView, SPDRP_UPPERFILTERS); break;
case 14: /* Device Lower Filters */ DisplayDevicePropertyText(dap, hwndListView, SPDRP_LOWERFILTERS); break;
case 15: /* Class Upper Filters */ DisplayClassProperties(dap, hwndListView, L"UpperFilters"); break;
case 16: /* Class Lower Filters */ DisplayClassProperties(dap, hwndListView, L"LowerFilters"); break;
case 17: /* Class Installer */ DisplayClassProperties(dap, hwndListView, L"Installer32"); break;
case 18: /* Class Coinstaller */ DisplayClassCoinstallers(dap, hwndListView); break;
case 19: /* Device Coinstaller */ DisplayDeviceCoinstallers(dap, hwndListView); break;
#if 0 case 20: /* Firmware Revision */ break;#endif
case 21: /* Current Power State */ DisplayCurrentPowerState(dap, hwndListView); break;
case 22: /* Power Capabilities */ DisplayPowerCapabilities(dap, hwndListView); break;
case 23: /* Power State Mappings */ DisplayPowerStateMappings(dap, hwndListView); break;
default: SetListViewText(hwndListView, 0, L"<Not implemented yet>"); break; }}
static INT_PTRCALLBACKAdvProcDetailsDlgProc(IN HWND hwndDlg, IN UINT uMsg, IN WPARAM wParam, IN LPARAM lParam){ PDEVADVPROP_INFO dap; INT_PTR Ret = FALSE;
dap = (PDEVADVPROP_INFO)GetWindowLongPtr(hwndDlg, DWLP_USER);
if (dap != NULL || uMsg == WM_INITDIALOG) { switch (uMsg) { case WM_CONTEXTMENU: { if ((HWND)wParam == GetDlgItem(hwndDlg, IDC_DETAILSPROPVALUE)) { WCHAR szColName[255];
if (!LoadStringW(hDllInstance, IDS_COPY, szColName, _countof(szColName))) break;
INT nSelectedItems = ListView_GetSelectedCount((HWND)wParam); POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; HMENU hPopup = CreatePopupMenu();
AppendMenuW(hPopup, MF_STRING, IDS_MENU_COPY, szColName);
if (nSelectedItems <= 0) EnableMenuItem(hPopup, IDS_MENU_COPY, MF_BYCOMMAND | MF_GRAYED);
TrackPopupMenu(hPopup, TPM_LEFTALIGN, pt.x, pt.y, 0, hwndDlg, NULL); DestroyMenu(hPopup); Ret = TRUE; } break; }
case WM_COMMAND: { switch (LOWORD(wParam)) { case IDC_DETAILSPROPNAME: if (HIWORD(wParam) == CBN_SELCHANGE) { DisplayDeviceProperties(dap, GetDlgItem(hwndDlg, IDC_DETAILSPROPNAME), GetDlgItem(hwndDlg, IDC_DETAILSPROPVALUE)); } break;
case IDS_MENU_COPY: { HWND hwndListView = GetDlgItem(hwndDlg, IDC_DETAILSPROPVALUE); INT nSelectedItems = ListView_GetSelectedCount(hwndListView); INT nSelectedId = ListView_GetSelectionMark(hwndListView);
if (nSelectedId < 0 || nSelectedItems <= 0) break;
HGLOBAL hGlobal; LPWSTR pszBuffer; SIZE_T cchSize = MAX_PATH + 1;
hGlobal = GlobalAlloc(GHND, cchSize * sizeof(WCHAR)); if (!hGlobal) break; pszBuffer = (LPWSTR)GlobalLock(hGlobal); if (!pszBuffer) { GlobalFree(hGlobal); break; }
ListView_GetItemText(hwndListView, nSelectedId, 0, pszBuffer, cchSize); /* Ensure NULL-termination */ pszBuffer[cchSize - 1] = UNICODE_NULL;
GlobalUnlock(hGlobal);
if (OpenClipboard(NULL)) { EmptyClipboard(); SetClipboardData(CF_UNICODETEXT, hGlobal); CloseClipboard(); Ret = TRUE; } else { GlobalFree(hGlobal); } break; } } break; }
case WM_NOTIFY: { NMHDR *hdr = (NMHDR*)lParam; switch (hdr->code) { case PSN_APPLY: break; } break; }
case WM_INITDIALOG: { dap = (PDEVADVPROP_INFO)((LPPROPSHEETPAGE)lParam)->lParam; if (dap != NULL) { SetWindowLongPtr(hwndDlg, DWLP_USER, (DWORD_PTR)dap);
UpdateDetailsDlg(hwndDlg, dap); } Ret = TRUE; break; } } }
return Ret;}
static VOIDInitDevUsageActions(IN HWND hwndDlg, IN HWND hComboBox, IN PDEVADVPROP_INFO dap){ INT Index; UINT i; UINT Actions[] = { IDS_ENABLEDEVICE, IDS_DISABLEDEVICE, };
for (i = 0; i != sizeof(Actions) / sizeof(Actions[0]); i++) { /* fill in the device usage combo box */ if (LoadString(hDllInstance, Actions[i], dap->szTemp, sizeof(dap->szTemp) / sizeof(dap->szTemp[0]))) { Index = (INT)SendMessage(hComboBox, CB_ADDSTRING, 0, (LPARAM)dap->szTemp); if (Index != CB_ERR) { SendMessage(hComboBox, CB_SETITEMDATA, (WPARAM)Index, (LPARAM)Actions[i]);
switch (Actions[i]) { case IDS_ENABLEDEVICE: if (dap->DeviceStarted) { SendMessage(hComboBox, CB_SETCURSEL, (WPARAM)Index, 0); } break;
case IDS_DISABLEDEVICE: if (!dap->DeviceStarted) { SendMessage(hComboBox, CB_SETCURSEL, (WPARAM)Index, 0); } break;
default: break; } } } }}
static UINTGetSelectedUsageAction(IN HWND hComboBox){ INT Index; UINT Ret = 0;
Index = (INT)SendMessage(hComboBox, CB_GETCURSEL, 0, 0); if (Index != CB_ERR) { INT iRet = (INT) SendMessage(hComboBox, CB_GETITEMDATA, (WPARAM)Index, 0); if (iRet != CB_ERR) { Ret = (UINT)iRet; } }
return Ret;}
static BOOLApplyGeneralSettings(IN HWND hwndDlg, IN PDEVADVPROP_INFO dap){ BOOL Ret = FALSE;
if (dap->DeviceUsageChanged && dap->IsAdmin && dap->CanDisable) { UINT SelectedUsageAction; BOOL NeedReboot = FALSE;
SelectedUsageAction = GetSelectedUsageAction(GetDlgItem(hwndDlg, IDC_DEVUSAGE)); switch (SelectedUsageAction) { case IDS_ENABLEDEVICE: if (!dap->DeviceStarted) { Ret = EnableDevice(dap->DeviceInfoSet, &dap->DeviceInfoData, TRUE, 0, &NeedReboot); } break;
case IDS_DISABLEDEVICE: if (dap->DeviceStarted) { Ret = EnableDevice(dap->DeviceInfoSet, &dap->DeviceInfoData, FALSE, 0, &NeedReboot); } break;
default: break; }
if (Ret) { if (NeedReboot) { /* make PropertySheet() return PSM_REBOOTSYSTEM */ PropSheet_RebootSystem(hwndDlg); } } else { /* FIXME - display an error message */ FIXME("Failed to enable/disable device! LastError: %d\n", GetLastError()); } } else Ret = !dap->DeviceUsageChanged;
/* disable the apply button */ PropSheet_UnChanged(GetParent(hwndDlg), hwndDlg); dap->DeviceUsageChanged = FALSE; return Ret;}
static VOIDUpdateDevInfo(IN HWND hwndDlg, IN PDEVADVPROP_INFO dap, IN BOOL ReOpen){ HWND hDevUsage, hPropSheetDlg, hDevProbBtn; CONFIGRET cr; ULONG Status, ProblemNumber; SP_DEVINSTALL_PARAMS_W InstallParams; UINT TroubleShootStrId = IDS_TROUBLESHOOTDEV; BOOL bFlag, bDevActionAvailable = TRUE; BOOL bDrvInstalled = FALSE; DWORD iPage; HDEVINFO DeviceInfoSet = NULL; PSP_DEVINFO_DATA DeviceInfoData = NULL; PROPSHEETHEADER psh; DWORD nDriverPages = 0; BOOL RecalcPages = FALSE;
hPropSheetDlg = GetParent(hwndDlg);
if (dap->PageInitialized) { /* switch to the General page */ PropSheet_SetCurSelByID(hPropSheetDlg, IDD_DEVICEGENERAL);
/* remove and destroy the existing device property sheet pages */ if (dap->DevPropSheets != NULL) { for (iPage = 0; iPage != dap->nDevPropSheets; iPage++) { if (dap->DevPropSheets[iPage] != NULL) { PropSheet_RemovePage(hPropSheetDlg, (WPARAM) -1, dap->DevPropSheets[iPage]); RecalcPages = TRUE; } } } }
iPage = 0;
if (dap->FreeDevPropSheets) { /* don't free the array if it's the one allocated in DisplayDeviceAdvancedProperties */ HeapFree(GetProcessHeap(), 0, dap->DevPropSheets);
dap->FreeDevPropSheets = FALSE; }
dap->DevPropSheets = NULL; dap->nDevPropSheets = 0;
if (ReOpen) { /* create a new device info set and re-open the device */ if (dap->CurrentDeviceInfoSet != INVALID_HANDLE_VALUE) { SetupDiDestroyDeviceInfoList(dap->CurrentDeviceInfoSet); }
dap->ParentDevInst = 0; dap->CurrentDeviceInfoSet = SetupDiCreateDeviceInfoListEx(NULL, hwndDlg, dap->lpMachineName, NULL); if (dap->CurrentDeviceInfoSet != INVALID_HANDLE_VALUE) { if (SetupDiOpenDeviceInfo(dap->CurrentDeviceInfoSet, dap->szDeviceID, hwndDlg, 0, &dap->CurrentDeviceInfoData)) { if (dap->CloseDevInst) { SetupDiDestroyDeviceInfoList(dap->DeviceInfoSet); }
dap->CloseDevInst = TRUE; dap->DeviceInfoSet = dap->CurrentDeviceInfoSet; dap->DeviceInfoData = dap->CurrentDeviceInfoData; dap->CurrentDeviceInfoSet = INVALID_HANDLE_VALUE; } else goto GetParentNode; } else {GetParentNode: /* get the parent node from the initial devinst */ CM_Get_Parent_Ex(&dap->ParentDevInst, dap->DeviceInfoData.DevInst, 0, dap->hMachine); }
if (dap->CurrentDeviceInfoSet != INVALID_HANDLE_VALUE) { DeviceInfoSet = dap->CurrentDeviceInfoSet; DeviceInfoData = &dap->CurrentDeviceInfoData; } else { DeviceInfoSet = dap->DeviceInfoSet; DeviceInfoData = &dap->DeviceInfoData; } } else { DeviceInfoSet = dap->DeviceInfoSet; DeviceInfoData = &dap->DeviceInfoData; }
dap->HasDriverPage = TRUE; dap->HasResourcePage = TRUE; dap->HasPowerPage = TRUE; if (IsDriverInstalled(DeviceInfoData->DevInst, dap->hMachine, &bDrvInstalled) && bDrvInstalled) { if (SetupDiCallClassInstaller((dap->ShowRemotePages ? DIF_ADDREMOTEPROPERTYPAGE_ADVANCED : DIF_ADDPROPERTYPAGE_ADVANCED), DeviceInfoSet, DeviceInfoData)) { /* get install params */ InstallParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS_W); if (!SetupDiGetDeviceInstallParamsW(DeviceInfoSet, DeviceInfoData, &InstallParams)) { /* zero the flags */ InstallParams.Flags = 0; InstallParams.FlagsEx = 0; }
dap->HasDriverPage = !(InstallParams.Flags & DI_DRIVERPAGE_ADDED); dap->HasResourcePage = !(InstallParams.Flags & DI_RESOURCEPAGE_ADDED); dap->HasPowerPage = !(InstallParams.FlagsEx & DI_FLAGSEX_POWERPAGE_ADDED); } }
/* get the device icon */ if (dap->hDevIcon != NULL) { DestroyIcon(dap->hDevIcon); dap->hDevIcon = NULL; } if (!SetupDiLoadClassIcon(&DeviceInfoData->ClassGuid, &dap->hDevIcon, NULL)) { dap->hDevIcon = NULL; }
/* get the device name */ if (GetDeviceDescriptionString(DeviceInfoSet, DeviceInfoData, dap->szDevName, sizeof(dap->szDevName) / sizeof(dap->szDevName[0]))) { PropSheet_SetTitle(hPropSheetDlg, PSH_PROPTITLE, dap->szDevName); }
/* set the device image */ SendDlgItemMessage(hwndDlg, IDC_DEVICON, STM_SETICON, (WPARAM)dap->hDevIcon, 0);
/* set the device name edit control text */ SetDlgItemText(hwndDlg, IDC_DEVNAME, dap->szDevName);
/* set the device type edit control text */ if (GetDeviceTypeString(DeviceInfoData, dap->szTemp, sizeof(dap->szTemp) / sizeof(dap->szTemp[0]))) { SetDlgItemText(hwndDlg, IDC_DEVTYPE, dap->szTemp); }
/* set the device manufacturer edit control text */ if (GetDeviceManufacturerString(DeviceInfoSet, DeviceInfoData, dap->szTemp, sizeof(dap->szTemp) / sizeof(dap->szTemp[0]))) { SetDlgItemText(hwndDlg, IDC_DEVMANUFACTURER, dap->szTemp); }
/* set the device location edit control text */ if (GetDeviceLocationString(DeviceInfoSet, DeviceInfoData, dap->ParentDevInst, dap->szTemp, sizeof(dap->szTemp) / sizeof(dap->szTemp[0]))) { SetDlgItemText(hwndDlg, IDC_DEVLOCATION, dap->szTemp); }
/* set the device status edit control text */ if (GetDeviceStatusString(DeviceInfoData->DevInst, dap->hMachine, dap->szTemp, sizeof(dap->szTemp) / sizeof(dap->szTemp[0]))) { SetDlgItemText(hwndDlg, IDC_DEVSTATUS, dap->szTemp); }
/* set the device troubleshoot button text and disable it if necessary */ hDevProbBtn = GetDlgItem(hwndDlg, IDC_DEVPROBLEM); cr = CM_Get_DevNode_Status_Ex(&Status, &ProblemNumber, DeviceInfoData->DevInst, 0, dap->hMachine); if (cr == CR_SUCCESS && (Status & DN_HAS_PROBLEM)) { switch (ProblemNumber) { case CM_PROB_DEVLOADER_FAILED: { /* FIXME - only if it's not a root bus devloader, disable the button otherwise */ TroubleShootStrId = IDS_UPDATEDRV; break; }
case CM_PROB_OUT_OF_MEMORY: case CM_PROB_ENTRY_IS_WRONG_TYPE: case CM_PROB_LACKED_ARBITRATOR: case CM_PROB_FAILED_START: case CM_PROB_LIAR: case CM_PROB_UNKNOWN_RESOURCE: { TroubleShootStrId = IDS_UPDATEDRV; break; }
case CM_PROB_BOOT_CONFIG_CONFLICT: case CM_PROB_NORMAL_CONFLICT: case CM_PROB_REENUMERATION: { /* FIXME - Troubleshoot conflict */ break; }
case CM_PROB_FAILED_FILTER: case CM_PROB_REINSTALL: case CM_PROB_FAILED_INSTALL: { TroubleShootStrId = IDS_REINSTALLDRV; break; }
case CM_PROB_DEVLOADER_NOT_FOUND: { /* FIXME - 4 cases: 1) if it's a missing system devloader: - disable the button (Reinstall Driver) 2) if it's not a system devloader but still missing: - Reinstall Driver 3) if it's not a system devloader but the file can be found: - Update Driver 4) if it's a missing or empty software key - Update Driver */ break; }
case CM_PROB_INVALID_DATA: case CM_PROB_PARTIAL_LOG_CONF: case CM_PROB_NO_VALID_LOG_CONF: case CM_PROB_HARDWARE_DISABLED: case CM_PROB_CANT_SHARE_IRQ: case CM_PROB_TRANSLATION_FAILED: case CM_PROB_SYSTEM_SHUTDOWN: case CM_PROB_PHANTOM: bDevActionAvailable = FALSE; break;
case CM_PROB_NOT_VERIFIED: case CM_PROB_DEVICE_NOT_THERE: /* FIXME - search hardware */ break;
case CM_PROB_NEED_RESTART: case CM_PROB_WILL_BE_REMOVED: case CM_PROB_MOVED: case CM_PROB_TOO_EARLY: case CM_PROB_DISABLED_SERVICE: TroubleShootStrId = IDS_REBOOT; break;
case CM_PROB_REGISTRY: /* FIXME - check registry? */ break;
case CM_PROB_DISABLED: /* if device was disabled by the user: */ TroubleShootStrId = IDS_ENABLEDEV; /* FIXME - otherwise disable button because the device was disabled by the system*/ break;
case CM_PROB_DEVLOADER_NOT_READY: /* FIXME - if it's a graphics adapter: - if it's a a secondary adapter and the main adapter couldn't be found - disable button - else - Properties - else - Update driver */ break;
case CM_PROB_FAILED_ADD: TroubleShootStrId = IDS_PROPERTIES; break; } }
if (LoadString(hDllInstance, TroubleShootStrId, dap->szTemp, sizeof(dap->szTemp) / sizeof(dap->szTemp[0])) != 0) { SetWindowText(hDevProbBtn, dap->szTemp); } EnableWindow(hDevProbBtn, dap->IsAdmin && bDevActionAvailable);
/* check if the device can be enabled/disabled */ hDevUsage = GetDlgItem(hwndDlg, IDC_DEVUSAGE);
dap->CanDisable = FALSE; dap->DeviceStarted = FALSE;
if (CanDisableDevice(DeviceInfoData->DevInst, dap->hMachine, &bFlag)) { dap->CanDisable = bFlag; }
if (IsDeviceStarted(DeviceInfoData->DevInst, dap->hMachine, &bFlag)) { dap->DeviceStarted = bFlag; }
/* enable/disable the device usage controls */ EnableWindow(GetDlgItem(hwndDlg, IDC_DEVUSAGELABEL), dap->CanDisable && dap->IsAdmin); EnableWindow(hDevUsage, dap->CanDisable && dap->IsAdmin);
/* clear the combobox */ SendMessage(hDevUsage, CB_RESETCONTENT, 0, 0); if (dap->CanDisable) { InitDevUsageActions(hwndDlg, hDevUsage, dap); }
/* find out how many new device property sheets to add. fake a PROPSHEETHEADER structure, we don't plan to call PropertySheet again!*/ psh.dwSize = sizeof(PROPSHEETHEADER); psh.dwFlags = 0; psh.nPages = 0;
/* get the number of device property sheets for the device */ if (!SetupDiGetClassDevPropertySheets(DeviceInfoSet, DeviceInfoData, &psh, 0, &nDriverPages, dap->PropertySheetType) && nDriverPages != 0 && GetLastError() == ERROR_INSUFFICIENT_BUFFER) { dap->nDevPropSheets += nDriverPages; } else { nDriverPages = 0; }
dap->pResourceList = GetResourceList(dap->szDeviceID);
/* include the driver page */ if (dap->HasDriverPage) dap->nDevPropSheets++;
/* include the details page */ if (dap->Extended) dap->nDevPropSheets++;
if (dap->HasResourcePage && dap->pResourceList != NULL) dap->nDevPropSheets++;
/* add the device property sheets */ if (dap->nDevPropSheets != 0) { dap->DevPropSheets = (HPROPSHEETPAGE *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dap->nDevPropSheets * sizeof(HPROPSHEETPAGE)); if (dap->DevPropSheets != NULL) { if (nDriverPages != 0) { psh.phpage = dap->DevPropSheets;
/* query the device property sheet pages to add */ if (SetupDiGetClassDevPropertySheets(DeviceInfoSet, DeviceInfoData, &psh, dap->nDevPropSheets, NULL, dap->PropertySheetType)) { /* add the property sheets */ for (iPage = 0; iPage < nDriverPages; iPage++) { if (PropSheet_AddPage(hPropSheetDlg, dap->DevPropSheets[iPage])) { RecalcPages = TRUE; } }
dap->FreeDevPropSheets = TRUE; } else { /* cleanup, we were unable to get the device property sheets */ iPage = nDriverPages; dap->nDevPropSheets -= nDriverPages; nDriverPages = 0; } } else iPage = 0;
/* add the driver page if necessary */ if (dap->HasDriverPage) { PROPSHEETPAGE pspDriver = {0}; pspDriver.dwSize = sizeof(PROPSHEETPAGE); pspDriver.dwFlags = PSP_DEFAULT; pspDriver.hInstance = hDllInstance; pspDriver.pszTemplate = (LPCWSTR)MAKEINTRESOURCE(IDD_DEVICEDRIVER); pspDriver.pfnDlgProc = AdvProcDriverDlgProc; pspDriver.lParam = (LPARAM)dap; dap->DevPropSheets[iPage] = dap->pCreatePropertySheetPageW(&pspDriver); if (dap->DevPropSheets[iPage] != NULL) { if (PropSheet_AddPage(hPropSheetDlg, dap->DevPropSheets[iPage])) { iPage++; RecalcPages = TRUE; } else { dap->pDestroyPropertySheetPage(dap->DevPropSheets[iPage]); dap->DevPropSheets[iPage] = NULL; } } }
if (dap->Extended) { /* Add the details page */ PROPSHEETPAGE pspDetails = {0}; pspDetails.dwSize = sizeof(PROPSHEETPAGE); pspDetails.dwFlags = PSP_DEFAULT; pspDetails.hInstance = hDllInstance; pspDetails.pszTemplate = (LPCWSTR)MAKEINTRESOURCE(IDD_DEVICEDETAILS); pspDetails.pfnDlgProc = AdvProcDetailsDlgProc; pspDetails.lParam = (LPARAM)dap; dap->DevPropSheets[iPage] = dap->pCreatePropertySheetPageW(&pspDetails); if (dap->DevPropSheets[iPage] != NULL) { if (PropSheet_AddPage(hPropSheetDlg, dap->DevPropSheets[iPage])) { iPage++; RecalcPages = TRUE; } else { dap->pDestroyPropertySheetPage(dap->DevPropSheets[iPage]); dap->DevPropSheets[iPage] = NULL; } } }
if (dap->HasResourcePage && dap->pResourceList) { PROPSHEETPAGE pspDriver = {0}; pspDriver.dwSize = sizeof(PROPSHEETPAGE); pspDriver.dwFlags = PSP_DEFAULT; pspDriver.hInstance = hDllInstance; pspDriver.pszTemplate = (LPCWSTR)MAKEINTRESOURCE(IDD_DEVICERESOURCES); pspDriver.pfnDlgProc = ResourcesProcDriverDlgProc; pspDriver.lParam = (LPARAM)dap; dap->DevPropSheets[iPage] = dap->pCreatePropertySheetPageW(&pspDriver); if (dap->DevPropSheets[iPage] != NULL) { if (PropSheet_AddPage(hPropSheetDlg, dap->DevPropSheets[iPage])) { iPage++; RecalcPages = TRUE; } else { dap->pDestroyPropertySheetPage(dap->DevPropSheets[iPage]); dap->DevPropSheets[iPage] = NULL; } } } /* FIXME: Add the power page */ } else dap->nDevPropSheets = 0; }
if (RecalcPages) { PropSheet_RecalcPageSizes(hPropSheetDlg); }
/* finally, disable the apply button */ PropSheet_UnChanged(hPropSheetDlg, hwndDlg); dap->DeviceUsageChanged = FALSE;}
static LRESULTCALLBACKDlgParentSubWndProc(IN HWND hwnd, IN UINT uMsg, IN WPARAM wParam, IN LPARAM lParam){ PDEVADVPROP_INFO dap;
dap = (PDEVADVPROP_INFO)GetProp(hwnd, L"DevMgrDevChangeSub"); if (dap != NULL) { if (uMsg == WM_DEVICECHANGE && !IsWindowVisible(dap->hWndGeneralPage)) { SendMessage(dap->hWndGeneralPage, WM_DEVICECHANGE, wParam, lParam); }
/* pass the message the the old window proc */ return CallWindowProc(dap->ParentOldWndProc, hwnd, uMsg, wParam, lParam); } else { /* this is not a good idea if the subclassed window was an ansi window, but we failed finding out the previous window proc so we can't use CallWindowProc. This should rarely - if ever - happen. */
return DefWindowProc(hwnd, uMsg, wParam, lParam); }}
static INT_PTRCALLBACKAdvPropGeneralDlgProc(IN HWND hwndDlg, IN UINT uMsg, IN WPARAM wParam, IN LPARAM lParam){ PDEVADVPROP_INFO dap; INT_PTR Ret = FALSE;
dap = (PDEVADVPROP_INFO)GetWindowLongPtr(hwndDlg, DWLP_USER);
if (dap != NULL || uMsg == WM_INITDIALOG) { switch (uMsg) { case WM_COMMAND: { switch (LOWORD(wParam)) { case IDC_DEVUSAGE: { if (HIWORD(wParam) == CBN_SELCHANGE) { PropSheet_Changed(GetParent(hwndDlg), hwndDlg); dap->DeviceUsageChanged = TRUE; } break; }
case IDC_DEVPROBLEM: { if (dap->IsAdmin) { /* display the device problem wizard */ ShowDeviceProblemWizard(hwndDlg, dap->DeviceInfoSet, &dap->DeviceInfoData, dap->hMachine); } break; } } break; }
case WM_NOTIFY: { NMHDR *hdr = (NMHDR*)lParam; switch (hdr->code) { case PSN_APPLY: ApplyGeneralSettings(hwndDlg, dap); break; } break; }
case WM_INITDIALOG: { dap = (PDEVADVPROP_INFO)((LPPROPSHEETPAGE)lParam)->lParam; if (dap != NULL) { HWND hWndParent;
dap->hWndGeneralPage = hwndDlg;
SetWindowLongPtr(hwndDlg, DWLP_USER, (DWORD_PTR)dap);
/* subclass the parent window to always receive WM_DEVICECHANGE messages */ hWndParent = GetParent(hwndDlg); if (hWndParent != NULL) { /* subclass the parent window. This is not safe if the parent window belongs to another thread! */ dap->ParentOldWndProc = (WNDPROC)SetWindowLongPtr(hWndParent, GWLP_WNDPROC, (LONG_PTR)DlgParentSubWndProc);
if (dap->ParentOldWndProc != NULL && SetProp(hWndParent, L"DevMgrDevChangeSub", (HANDLE)dap)) { dap->hWndParent = hWndParent; } }
/* do not call UpdateDevInfo directly in here because it modifies the pages of the property sheet! */ PostMessage(hwndDlg, PM_INITIALIZE, 0, 0); } Ret = TRUE; break; }
case WM_DEVICECHANGE: { /* FIXME - don't call UpdateDevInfo for all events */ UpdateDevInfo(hwndDlg, dap, TRUE); Ret = TRUE; break; }
case PM_INITIALIZE: { UpdateDevInfo(hwndDlg, dap, FALSE); dap->PageInitialized = TRUE; break; }
case WM_DESTROY: { /* restore the old window proc of the subclassed parent window */ if (dap->hWndParent != NULL && dap->ParentOldWndProc != NULL) { if (SetWindowLongPtr(dap->hWndParent, GWLP_WNDPROC, (LONG_PTR)dap->ParentOldWndProc) == (LONG_PTR)DlgParentSubWndProc) { RemoveProp(dap->hWndParent, L"DevMgrDevChangeSub"); } } break; } } }
return Ret;}
INT_PTRDisplayDeviceAdvancedProperties(IN HWND hWndParent, IN LPCWSTR lpDeviceID OPTIONAL, IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData, IN HINSTANCE hComCtl32, IN LPCWSTR lpMachineName, IN DWORD dwFlags){ PROPSHEETHEADER psh = {0}; PROPSHEETPAGE pspGeneral = {0}; PPROPERTYSHEETW pPropertySheetW; PCREATEPROPERTYSHEETPAGEW pCreatePropertySheetPageW; PDESTROYPROPERTYSHEETPAGE pDestroyPropertySheetPage; PDEVADVPROP_INFO DevAdvPropInfo; HMACHINE hMachine = NULL; DWORD DevIdSize = 0; INT_PTR Ret = -1;
/* we don't want to statically link against comctl32, so find the functions we need dynamically */ pPropertySheetW = (PPROPERTYSHEETW)GetProcAddress(hComCtl32, "PropertySheetW"); pCreatePropertySheetPageW = (PCREATEPROPERTYSHEETPAGEW)GetProcAddress(hComCtl32, "CreatePropertySheetPageW"); pDestroyPropertySheetPage = (PDESTROYPROPERTYSHEETPAGE)GetProcAddress(hComCtl32, "DestroyPropertySheetPage"); if (pPropertySheetW == NULL || pCreatePropertySheetPageW == NULL || pDestroyPropertySheetPage == NULL) { return -1; }
if (lpDeviceID == NULL) { /* find out how much size is needed for the device id */ if (SetupDiGetDeviceInstanceId(DeviceInfoSet, DeviceInfoData, NULL, 0, &DevIdSize)) { ERR("SetupDiGetDeviceInstanceId unexpectedly returned TRUE!\n"); return -1; }
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) { return -1; } } else { DevIdSize = (DWORD)wcslen(lpDeviceID) + 1; }
if (lpMachineName != NULL && lpMachineName[0] != L'\0') { CONFIGRET cr = CM_Connect_Machine(lpMachineName, &hMachine); if (cr != CR_SUCCESS) { return -1; } }
/* create the internal structure associated with the "General", "Driver", ... pages */ DevAdvPropInfo = (PDEVADVPROP_INFO)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, FIELD_OFFSET(DEVADVPROP_INFO, szDeviceID) + (DevIdSize * sizeof(WCHAR))); if (DevAdvPropInfo == NULL) { SetLastError(ERROR_NOT_ENOUGH_MEMORY); goto Cleanup; }
if (lpDeviceID == NULL) { /* read the device instance id */ if (!SetupDiGetDeviceInstanceId(DeviceInfoSet, DeviceInfoData, DevAdvPropInfo->szDeviceID, DevIdSize, NULL)) { goto Cleanup; } } else { /* copy the device instance id supplied by the caller */ wcscpy(DevAdvPropInfo->szDeviceID, lpDeviceID); }
DevAdvPropInfo->DeviceInfoSet = DeviceInfoSet; DevAdvPropInfo->DeviceInfoData = *DeviceInfoData; DevAdvPropInfo->CurrentDeviceInfoSet = INVALID_HANDLE_VALUE; DevAdvPropInfo->CurrentDeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
DevAdvPropInfo->ShowRemotePages = (lpMachineName != NULL && lpMachineName[0] != L'\0'); DevAdvPropInfo->hMachine = hMachine; DevAdvPropInfo->lpMachineName = lpMachineName; DevAdvPropInfo->szDevName[0] = L'\0'; DevAdvPropInfo->hComCtl32 = hComCtl32; DevAdvPropInfo->pCreatePropertySheetPageW = pCreatePropertySheetPageW; DevAdvPropInfo->pDestroyPropertySheetPage = pDestroyPropertySheetPage;
DevAdvPropInfo->IsAdmin = TRUE;// IsUserAdmin(); DevAdvPropInfo->DoDefaultDevAction = ((dwFlags & DPF_DEVICE_STATUS_ACTION) != 0); DevAdvPropInfo->Extended = ((dwFlags & DPF_EXTENDED) != 0);
psh.dwSize = sizeof(PROPSHEETHEADER); psh.dwFlags = PSH_PROPTITLE | PSH_NOAPPLYNOW; psh.hwndParent = hWndParent; psh.pszCaption = DevAdvPropInfo->szDevName;
DevAdvPropInfo->PropertySheetType = DevAdvPropInfo->ShowRemotePages ? DIGCDP_FLAG_REMOTE_ADVANCED : DIGCDP_FLAG_ADVANCED;
psh.phpage = (HPROPSHEETPAGE *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 1 * sizeof(HPROPSHEETPAGE)); if (psh.phpage == NULL) { goto Cleanup; }
/* add the "General" property sheet */ pspGeneral.dwSize = sizeof(PROPSHEETPAGE); pspGeneral.dwFlags = PSP_DEFAULT; pspGeneral.hInstance = hDllInstance; pspGeneral.pszTemplate = (LPCWSTR)MAKEINTRESOURCE(IDD_DEVICEGENERAL); pspGeneral.pfnDlgProc = AdvPropGeneralDlgProc; pspGeneral.lParam = (LPARAM)DevAdvPropInfo; psh.phpage[psh.nPages] = pCreatePropertySheetPageW(&pspGeneral); if (psh.phpage[psh.nPages] != NULL) { psh.nPages++; }
DevAdvPropInfo->nDevPropSheets = psh.nPages;
if (psh.nPages != 0) { Ret = pPropertySheetW(&psh);
/* NOTE: no need to destroy the property sheets anymore! */ } else { UINT i;
Cleanup: /* in case of failure the property sheets must be destroyed */ if (psh.phpage != NULL) { for (i = 0; i < psh.nPages; i++) { if (psh.phpage[i] != NULL) { pDestroyPropertySheetPage(psh.phpage[i]); } } } }
if (Ret != 1) { SP_DEVINSTALL_PARAMS_W DeviceInstallParams;
DeviceInstallParams.cbSize = sizeof(DeviceInstallParams); if (SetupDiGetDeviceInstallParamsW(DeviceInfoSet, DeviceInfoData, &DeviceInstallParams)) { SP_PROPCHANGE_PARAMS PropChangeParams; PropChangeParams.ClassInstallHeader.cbSize = sizeof(PropChangeParams.ClassInstallHeader); PropChangeParams.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE; PropChangeParams.Scope = DICS_FLAG_GLOBAL; PropChangeParams.StateChange = DICS_PROPCHANGE;
SetupDiSetClassInstallParamsW(DeviceInfoSet, DeviceInfoData, (PSP_CLASSINSTALL_HEADER)&PropChangeParams, sizeof(PropChangeParams));
SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, DeviceInfoSet, DeviceInfoData);
DeviceInstallParams.FlagsEx &= ~DI_FLAGSEX_PROPCHANGE_PENDING; SetupDiSetDeviceInstallParamsW(DeviceInfoSet, DeviceInfoData, &DeviceInstallParams); } }
if (DevAdvPropInfo != NULL) { if (DevAdvPropInfo->FreeDevPropSheets) { /* don't free the array if it's the one allocated in DisplayDeviceAdvancedProperties */ HeapFree(GetProcessHeap(), 0, DevAdvPropInfo->DevPropSheets); }
if (DevAdvPropInfo->CloseDevInst) { /* close the device info set in case a new one was created */ SetupDiDestroyDeviceInfoList(DevAdvPropInfo->DeviceInfoSet); }
if (DevAdvPropInfo->CurrentDeviceInfoSet != INVALID_HANDLE_VALUE) { SetupDiDestroyDeviceInfoList(DevAdvPropInfo->CurrentDeviceInfoSet); }
if (DevAdvPropInfo->hDevIcon != NULL) { DestroyIcon(DevAdvPropInfo->hDevIcon); }
if (DevAdvPropInfo->pResourceList != NULL) HeapFree(GetProcessHeap(), 0, DevAdvPropInfo->pResourceList);
HeapFree(GetProcessHeap(), 0, DevAdvPropInfo); }
if (psh.phpage != NULL) { HeapFree(GetProcessHeap(), 0, psh.phpage); }
if (hMachine != NULL) { CM_Disconnect_Machine(hMachine); }
return Ret;}