eject button functionality

This commit is contained in:
David Kocik 2019-12-11 17:02:12 +01:00
parent a01eec34f9
commit b267e986fb
2 changed files with 7 additions and 5 deletions

View file

@ -275,7 +275,7 @@ bool GUI_App::on_init_inner()
this->obj_manipul()->update_if_dirty(); this->obj_manipul()->update_if_dirty();
RemovableDriveManager::get_instance().update(wxGetLocalTime(), true); //RemovableDriveManager::get_instance().update(wxGetLocalTime(), true);
// Preset updating & Configwizard are done after the above initializations, // Preset updating & Configwizard are done after the above initializations,

View file

@ -96,14 +96,16 @@ void RemovableDriveManager::eject_drive(const std::string &path)
return; return;
} }
DWORD deviceControlRetVal(0); DWORD deviceControlRetVal(0);
DeviceIoControl(handle, FSCTL_LOCK_VOLUME, nullptr, 0, nullptr, 0, &deviceControlRetVal, nullptr);
DeviceIoControl(handle, FSCTL_DISMOUNT_VOLUME, nullptr, 0, nullptr, 0, &deviceControlRetVal, nullptr);
BOOL error = DeviceIoControl(handle, IOCTL_STORAGE_EJECT_MEDIA, nullptr, 0, nullptr, 0, &deviceControlRetVal, nullptr); BOOL error = DeviceIoControl(handle, IOCTL_STORAGE_EJECT_MEDIA, nullptr, 0, nullptr, 0, &deviceControlRetVal, nullptr);
CloseHandle(handle);
if (error == 0) if (error == 0)
{ {
CloseHandle(handle);
std::cerr << "Ejecting " << mpath << " failed " << deviceControlRetVal << " " << GetLastError() << " \n"; std::cerr << "Ejecting " << mpath << " failed " << deviceControlRetVal << " " << GetLastError() << " \n";
return; return;
} }
CloseHandle(handle);
m_current_drives.erase(it); m_current_drives.erase(it);
break; break;
@ -198,7 +200,7 @@ INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lP
DEVICE_NOTIFY_WINDOW_HANDLE // type of recipient handle DEVICE_NOTIFY_WINDOW_HANDLE // type of recipient handle
); );
break; break;
/*
case WM_DEVICECHANGE: case WM_DEVICECHANGE:
{ {
if(wParam == DBT_DEVICEREMOVECOMPLETE) if(wParam == DBT_DEVICEREMOVECOMPLETE)
@ -207,7 +209,7 @@ INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lP
} }
} }
break; break;
*/
default: default:
// Send all other messages on to the default windows handler. // Send all other messages on to the default windows handler.
lRet = DefWindowProc(hWnd, message, wParam, lParam); lRet = DefWindowProc(hWnd, message, wParam, lParam);