mirror of
https://github.com/reactos/reactos.git
synced 2024-07-07 21:25:05 +00:00
[DEVMGR]
- Implement very basic uninstall functionality - Move device action code into the DeviceView class svn path=/trunk/; revision=68344
This commit is contained in:
parent
8fdb754153
commit
e399ab4063
|
@ -344,6 +344,40 @@ CDeviceNode::EnableDevice(
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
CDeviceNode::UninstallDevice()
|
||||||
|
{
|
||||||
|
|
||||||
|
if (CanUninstall() == false)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
SP_REMOVEDEVICE_PARAMS RemoveDevParams;
|
||||||
|
RemoveDevParams.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
|
||||||
|
RemoveDevParams.ClassInstallHeader.InstallFunction = DIF_REMOVE;
|
||||||
|
RemoveDevParams.Scope = DI_REMOVEDEVICE_GLOBAL;
|
||||||
|
RemoveDevParams.HwProfile = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
// We probably need to walk all the siblings of this
|
||||||
|
// device and ask if they're happy with the uninstall
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
// Remove it
|
||||||
|
SetupDiSetClassInstallParamsW(m_hDevInfo,
|
||||||
|
&m_DevinfoData,
|
||||||
|
&RemoveDevParams.ClassInstallHeader,
|
||||||
|
sizeof(SP_REMOVEDEVICE_PARAMS));
|
||||||
|
SetupDiCallClassInstaller(DIF_REMOVE, m_hDevInfo, &m_DevinfoData);
|
||||||
|
|
||||||
|
// Clear the install params
|
||||||
|
SetupDiSetClassInstallParamsW(m_hDevInfo,
|
||||||
|
&m_DevinfoData,
|
||||||
|
NULL,
|
||||||
|
0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/* PRIVATE METHODS ******************************************************/
|
/* PRIVATE METHODS ******************************************************/
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -38,6 +38,9 @@ public:
|
||||||
_Out_ bool &NeedsReboot
|
_Out_ bool &NeedsReboot
|
||||||
);
|
);
|
||||||
|
|
||||||
|
bool UninstallDevice(
|
||||||
|
);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Cleanup(
|
void Cleanup(
|
||||||
);
|
);
|
||||||
|
|
|
@ -229,6 +229,68 @@ CDeviceView::Refresh(
|
||||||
if (hThread) CloseHandle(hThread);
|
if (hThread) CloseHandle(hThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LRESULT
|
||||||
|
CDeviceView::OnAction(
|
||||||
|
_In_ UINT Action
|
||||||
|
)
|
||||||
|
{
|
||||||
|
switch (Action)
|
||||||
|
{
|
||||||
|
case IDC_PROPERTIES:
|
||||||
|
{
|
||||||
|
DisplayPropertySheet();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case IDC_SCAN_HARDWARE:
|
||||||
|
{
|
||||||
|
Refresh(GetCurrentView(),
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
NULL);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case IDC_ENABLE_DRV:
|
||||||
|
{
|
||||||
|
bool NeedsReboot;
|
||||||
|
if (EnableSelectedDevice(true, NeedsReboot) &&
|
||||||
|
NeedsReboot)
|
||||||
|
{
|
||||||
|
MessageBox(m_hMainWnd, L"Rebooting", L"Enable", MB_OK);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case IDC_DISABLE_DRV:
|
||||||
|
{
|
||||||
|
bool NeedsReboot;
|
||||||
|
EnableSelectedDevice(false, NeedsReboot);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case IDC_UPDATE_DRV:
|
||||||
|
{
|
||||||
|
MessageBox(m_hMainWnd, L"Not yet implemented", L"Update Driver", MB_OK);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case IDC_UNINSTALL_DRV:
|
||||||
|
{
|
||||||
|
UninstallSelectedDevice();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case IDC_ADD_HARDWARE:
|
||||||
|
{
|
||||||
|
MessageBox(m_hMainWnd, L"Not yet implemented", L"Add Hardware", MB_OK);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CDeviceView::DisplayPropertySheet()
|
CDeviceView::DisplayPropertySheet()
|
||||||
{
|
{
|
||||||
|
@ -286,77 +348,14 @@ CDeviceView::CreateActionMenu(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
CNode*
|
||||||
CDeviceView::HasProperties(
|
CDeviceView::GetSelectedNode()
|
||||||
_In_ LPTV_ITEMW TvItem
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
CNode *Node = GetNode(TvItem);
|
TV_ITEM TvItem;
|
||||||
if (Node)
|
TvItem.hItem = TreeView_GetSelection(m_hTreeView);
|
||||||
{
|
return GetNode(&TvItem);
|
||||||
return Node->HasProperties();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
|
||||||
CDeviceView::IsDisabled(
|
|
||||||
_In_ LPTV_ITEMW TvItem
|
|
||||||
)
|
|
||||||
{
|
|
||||||
CDeviceNode *Node = dynamic_cast<CDeviceNode *>(GetNode(TvItem));
|
|
||||||
if (Node)
|
|
||||||
{
|
|
||||||
return Node->IsDisabled();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
CDeviceView::CanDisable(
|
|
||||||
_In_ LPTV_ITEMW TvItem
|
|
||||||
)
|
|
||||||
{
|
|
||||||
CDeviceNode *Node = dynamic_cast<CDeviceNode *>(GetNode(TvItem));
|
|
||||||
if (Node)
|
|
||||||
{
|
|
||||||
return Node->CanDisable();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
CDeviceView::EnableSelectedDevice(
|
|
||||||
_In_ bool Enable,
|
|
||||||
_Out_ bool &NeedsReboot
|
|
||||||
)
|
|
||||||
{
|
|
||||||
CDeviceNode *Node = dynamic_cast<CDeviceNode *>(GetSelectedNode());
|
|
||||||
if (Node == nullptr) return false;
|
|
||||||
|
|
||||||
if (Enable == false)
|
|
||||||
{
|
|
||||||
CAtlStringW str;
|
|
||||||
if (str.LoadStringW(g_hInstance, IDS_CONFIRM_DISABLE))
|
|
||||||
{
|
|
||||||
if (MessageBoxW(m_hMainWnd,
|
|
||||||
str,
|
|
||||||
Node->GetDisplayName(),
|
|
||||||
MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2) != IDYES)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Node->EnableDevice(Enable, NeedsReboot))
|
|
||||||
{
|
|
||||||
Refresh(m_ViewType, true, true, Node->GetDeviceId());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// PRIVATE METHODS *******************************************/
|
// PRIVATE METHODS *******************************************/
|
||||||
|
@ -709,6 +708,49 @@ CDeviceView::RecurseChildDevices(
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
CDeviceView::EnableSelectedDevice(
|
||||||
|
_In_ bool Enable,
|
||||||
|
_Out_ bool &NeedsReboot
|
||||||
|
)
|
||||||
|
{
|
||||||
|
CDeviceNode *Node = dynamic_cast<CDeviceNode *>(GetSelectedNode());
|
||||||
|
if (Node == nullptr) return false;
|
||||||
|
|
||||||
|
if (Enable == false)
|
||||||
|
{
|
||||||
|
CAtlStringW str;
|
||||||
|
if (str.LoadStringW(g_hInstance, IDS_CONFIRM_DISABLE))
|
||||||
|
{
|
||||||
|
if (MessageBoxW(m_hMainWnd,
|
||||||
|
str,
|
||||||
|
Node->GetDisplayName(),
|
||||||
|
MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2) != IDYES)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Node->EnableDevice(Enable, NeedsReboot))
|
||||||
|
{
|
||||||
|
Refresh(m_ViewType, true, true, Node->GetDeviceId());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
CDeviceView::UninstallSelectedDevice(
|
||||||
|
)
|
||||||
|
{
|
||||||
|
CDeviceNode *Node = dynamic_cast<CDeviceNode *>(GetSelectedNode());
|
||||||
|
if (Node == nullptr) return false;
|
||||||
|
|
||||||
|
return Node->UninstallDevice();
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
CDeviceView::GetChildDevice(
|
CDeviceView::GetChildDevice(
|
||||||
_In_ DEVINST ParentDevInst,
|
_In_ DEVINST ParentDevInst,
|
||||||
|
@ -1034,13 +1076,6 @@ CNode* CDeviceView::GetNode(
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
CNode* CDeviceView::GetSelectedNode()
|
|
||||||
{
|
|
||||||
TV_ITEM TvItem;
|
|
||||||
TvItem.hItem = TreeView_GetSelection(m_hTreeView);
|
|
||||||
return GetNode(&TvItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CDeviceView::EmptyLists()
|
CDeviceView::EmptyLists()
|
||||||
{
|
{
|
||||||
|
|
|
@ -51,6 +51,10 @@ public:
|
||||||
_In_ LPARAM lParam
|
_In_ LPARAM lParam
|
||||||
);
|
);
|
||||||
|
|
||||||
|
LRESULT OnAction(
|
||||||
|
UINT Action
|
||||||
|
);
|
||||||
|
|
||||||
VOID Refresh(
|
VOID Refresh(
|
||||||
_In_ ViewType Type,
|
_In_ ViewType Type,
|
||||||
_In_ bool ScanForChanges,
|
_In_ bool ScanForChanges,
|
||||||
|
@ -73,20 +77,7 @@ public:
|
||||||
_In_ bool MainMenu
|
_In_ bool MainMenu
|
||||||
);
|
);
|
||||||
|
|
||||||
bool HasProperties(
|
CNode* GetSelectedNode(
|
||||||
_In_ LPTV_ITEMW TvItem
|
|
||||||
);
|
|
||||||
//bool SelDeviceIsHidden();
|
|
||||||
bool CanDisable(
|
|
||||||
_In_ LPTV_ITEMW TvItem
|
|
||||||
);
|
|
||||||
bool IsDisabled(
|
|
||||||
_In_ LPTV_ITEMW TvItem
|
|
||||||
);
|
|
||||||
|
|
||||||
bool EnableSelectedDevice(
|
|
||||||
_In_ bool Enable,
|
|
||||||
_Out_ bool &NeedsReboot
|
|
||||||
);
|
);
|
||||||
|
|
||||||
bool SelDeviceIsStarted();
|
bool SelDeviceIsStarted();
|
||||||
|
@ -117,6 +108,14 @@ private:
|
||||||
_In_ HTREEITEM hParentTreeItem
|
_In_ HTREEITEM hParentTreeItem
|
||||||
);
|
);
|
||||||
|
|
||||||
|
bool EnableSelectedDevice(
|
||||||
|
_In_ bool Enable,
|
||||||
|
_Out_ bool &NeedsReboot
|
||||||
|
);
|
||||||
|
|
||||||
|
bool UninstallSelectedDevice(
|
||||||
|
);
|
||||||
|
|
||||||
bool GetChildDevice(
|
bool GetChildDevice(
|
||||||
_In_ DEVINST ParentDevInst,
|
_In_ DEVINST ParentDevInst,
|
||||||
_Out_ PDEVINST DevInst
|
_Out_ PDEVINST DevInst
|
||||||
|
@ -153,7 +152,6 @@ private:
|
||||||
CNode* GetNode(
|
CNode* GetNode(
|
||||||
_In_ LPTV_ITEMW TvItem
|
_In_ LPTV_ITEMW TvItem
|
||||||
);
|
);
|
||||||
CNode* GetSelectedNode();
|
|
||||||
|
|
||||||
CClassNode* GetClassNode(
|
CClassNode* GetClassNode(
|
||||||
_In_ LPGUID ClassGuid
|
_In_ LPGUID ClassGuid
|
||||||
|
|
|
@ -234,17 +234,6 @@ CMainWindow::RefreshView(ViewType Type)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
|
||||||
CMainWindow::ScanForHardwareChanges()
|
|
||||||
{
|
|
||||||
// Refresh the cache and and display
|
|
||||||
m_DeviceView->Refresh(m_DeviceView->GetCurrentView(),
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
NULL);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
CMainWindow::CreateToolBar()
|
CMainWindow::CreateToolBar()
|
||||||
{
|
{
|
||||||
|
@ -323,12 +312,14 @@ CMainWindow::CreateStatusBar()
|
||||||
return bRet;
|
return bRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMainWindow::UpdateUiContext(_In_ LPTV_ITEMW TvItem)
|
void CMainWindow::UpdateToolbar(_In_ LPTV_ITEMW TvItem)
|
||||||
{
|
{
|
||||||
WORD State;
|
WORD State;
|
||||||
|
|
||||||
|
CNode *Node = m_DeviceView->GetSelectedNode();
|
||||||
|
|
||||||
// properties button
|
// properties button
|
||||||
if (m_DeviceView->HasProperties(TvItem))
|
if (Node->HasProperties())
|
||||||
{
|
{
|
||||||
State = TBSTATE_ENABLED;
|
State = TBSTATE_ENABLED;
|
||||||
}
|
}
|
||||||
|
@ -340,8 +331,11 @@ void CMainWindow::UpdateUiContext(_In_ LPTV_ITEMW TvItem)
|
||||||
SendMessageW(m_hToolBar, TB_SETSTATE, IDC_UPDATE_DRV, MAKELPARAM(State, 0)); //hack
|
SendMessageW(m_hToolBar, TB_SETSTATE, IDC_UPDATE_DRV, MAKELPARAM(State, 0)); //hack
|
||||||
SendMessageW(m_hToolBar, TB_SETSTATE, IDC_UNINSTALL_DRV, MAKELPARAM(State, 0)); // hack
|
SendMessageW(m_hToolBar, TB_SETSTATE, IDC_UNINSTALL_DRV, MAKELPARAM(State, 0)); // hack
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// enable driver button
|
// enable driver button
|
||||||
if (m_DeviceView->IsDisabled(TvItem))
|
if (Node->GetNodeType() == DeviceNode &&
|
||||||
|
dynamic_cast<CDeviceNode *>(Node)->IsDisabled())
|
||||||
{
|
{
|
||||||
State = TBSTATE_ENABLED;
|
State = TBSTATE_ENABLED;
|
||||||
}
|
}
|
||||||
|
@ -352,7 +346,9 @@ void CMainWindow::UpdateUiContext(_In_ LPTV_ITEMW TvItem)
|
||||||
SendMessageW(m_hToolBar, TB_SETSTATE, IDC_ENABLE_DRV, MAKELPARAM(State, 0));
|
SendMessageW(m_hToolBar, TB_SETSTATE, IDC_ENABLE_DRV, MAKELPARAM(State, 0));
|
||||||
|
|
||||||
// disable driver button
|
// disable driver button
|
||||||
if (m_DeviceView->CanDisable(TvItem) && !m_DeviceView->IsDisabled(TvItem))
|
if (Node->GetNodeType() == DeviceNode &&
|
||||||
|
dynamic_cast<CDeviceNode *>(Node)->CanDisable() &&
|
||||||
|
!dynamic_cast<CDeviceNode *>(Node)->IsDisabled())
|
||||||
{
|
{
|
||||||
State = TBSTATE_ENABLED;
|
State = TBSTATE_ENABLED;
|
||||||
}
|
}
|
||||||
|
@ -411,7 +407,10 @@ CMainWindow::OnCreate(HWND hwnd)
|
||||||
if (m_DeviceView->Initialize())
|
if (m_DeviceView->Initialize())
|
||||||
{
|
{
|
||||||
// Do the initial scan
|
// Do the initial scan
|
||||||
ScanForHardwareChanges();
|
m_DeviceView->Refresh(m_DeviceView->GetCurrentView(),
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
NULL);
|
||||||
|
|
||||||
// Display the window according to the user request
|
// Display the window according to the user request
|
||||||
ShowWindow(hwnd, m_CmdShow);
|
ShowWindow(hwnd, m_CmdShow);
|
||||||
|
@ -468,7 +467,7 @@ CMainWindow::OnNotify(LPARAM lParam)
|
||||||
case TVN_SELCHANGED:
|
case TVN_SELCHANGED:
|
||||||
{
|
{
|
||||||
LPNMTREEVIEW NmTreeView = (LPNMTREEVIEW)lParam;
|
LPNMTREEVIEW NmTreeView = (LPNMTREEVIEW)lParam;
|
||||||
UpdateUiContext(&NmTreeView->itemNew);
|
UpdateToolbar(&NmTreeView->itemNew);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -543,50 +542,14 @@ CMainWindow::OnCommand(WPARAM wParam,
|
||||||
switch (Msg)
|
switch (Msg)
|
||||||
{
|
{
|
||||||
case IDC_PROPERTIES:
|
case IDC_PROPERTIES:
|
||||||
{
|
|
||||||
m_DeviceView->DisplayPropertySheet();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case IDC_SCAN_HARDWARE:
|
case IDC_SCAN_HARDWARE:
|
||||||
{
|
|
||||||
ScanForHardwareChanges();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case IDC_ENABLE_DRV:
|
case IDC_ENABLE_DRV:
|
||||||
{
|
|
||||||
bool NeedsReboot;
|
|
||||||
if (m_DeviceView->EnableSelectedDevice(true, NeedsReboot) &&
|
|
||||||
NeedsReboot)
|
|
||||||
{
|
|
||||||
MessageBox(m_hMainWnd, L"Rebooting", L"Enable", MB_OK);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case IDC_DISABLE_DRV:
|
case IDC_DISABLE_DRV:
|
||||||
{
|
|
||||||
bool NeedsReboot;
|
|
||||||
m_DeviceView->EnableSelectedDevice(false, NeedsReboot);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case IDC_UPDATE_DRV:
|
case IDC_UPDATE_DRV:
|
||||||
{
|
|
||||||
MessageBox(m_hMainWnd, L"Not yet implemented", L"Update Driver", MB_OK);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case IDC_UNINSTALL_DRV:
|
case IDC_UNINSTALL_DRV:
|
||||||
{
|
|
||||||
MessageBox(m_hMainWnd, L"Not yet implemented", L"Uninstall Driver", MB_OK);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case IDC_ADD_HARDWARE:
|
case IDC_ADD_HARDWARE:
|
||||||
{
|
{
|
||||||
MessageBox(m_hMainWnd, L"Not yet implemented", L"Add Hardware", MB_OK);
|
m_DeviceView->OnAction(Msg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,9 @@ private:
|
||||||
bool CreateToolBar();
|
bool CreateToolBar();
|
||||||
bool CreateStatusBar();
|
bool CreateStatusBar();
|
||||||
|
|
||||||
void UpdateUiContext(_In_ LPTV_ITEMW TvItem);
|
void UpdateToolbar(
|
||||||
|
_In_ LPTV_ITEMW TvItem
|
||||||
|
);
|
||||||
|
|
||||||
bool StatusBarLoadString(
|
bool StatusBarLoadString(
|
||||||
HWND hStatusBar,
|
HWND hStatusBar,
|
||||||
|
@ -68,8 +70,5 @@ private:
|
||||||
bool RefreshView(
|
bool RefreshView(
|
||||||
ViewType Type
|
ViewType Type
|
||||||
);
|
);
|
||||||
|
|
||||||
bool ScanForHardwareChanges(
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue