windows registration for device notif(thru hidden app) - windows doesnt need update now
This commit is contained in:
parent
b386eb45dc
commit
8f069e2d47
@ -273,7 +273,7 @@ bool GUI_App::on_init_inner()
|
|||||||
this->obj_manipul()->update_if_dirty();
|
this->obj_manipul()->update_if_dirty();
|
||||||
|
|
||||||
|
|
||||||
RemovableDriveManager::get_instance().update(wxGetLocalTime());
|
//RemovableDriveManager::get_instance().update(wxGetLocalTime());
|
||||||
|
|
||||||
|
|
||||||
// Preset updating & Configwizard are done after the above initializations,
|
// Preset updating & Configwizard are done after the above initializations,
|
||||||
@ -303,6 +303,7 @@ bool GUI_App::on_init_inner()
|
|||||||
preset_updater->slic3r_update_notify();
|
preset_updater->slic3r_update_notify();
|
||||||
preset_updater->sync(preset_bundle);
|
preset_updater->sync(preset_bundle);
|
||||||
});
|
});
|
||||||
|
RemovableDriveManager::get_instance().init();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -8,9 +8,9 @@
|
|||||||
#include <winioctl.h>
|
#include <winioctl.h>
|
||||||
#include <shlwapi.h>
|
#include <shlwapi.h>
|
||||||
|
|
||||||
//#include <Dbt.h>
|
#include <Dbt.h>
|
||||||
//GUID WceusbshGUID = { 0x25dbce51, 0x6c8f, 0x4a72,
|
GUID WceusbshGUID = { 0x25dbce51, 0x6c8f, 0x4a72,
|
||||||
// 0x8a,0x6d,0xb5,0x4c,0x2b,0x4f,0xc8,0x35 };
|
0x8a,0x6d,0xb5,0x4c,0x2b,0x4f,0xc8,0x35 };
|
||||||
|
|
||||||
#else
|
#else
|
||||||
//linux includes
|
//linux includes
|
||||||
@ -29,7 +29,7 @@ namespace GUI {
|
|||||||
|
|
||||||
|
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
//INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
|
INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
|
||||||
void RemovableDriveManager::search_for_drives()
|
void RemovableDriveManager::search_for_drives()
|
||||||
{
|
{
|
||||||
m_current_drives.clear();
|
m_current_drives.clear();
|
||||||
@ -136,13 +136,8 @@ std::string RemovableDriveManager::get_drive_from_path(const std::string& path)
|
|||||||
}
|
}
|
||||||
void RemovableDriveManager::register_window()
|
void RemovableDriveManager::register_window()
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
std::cout << "Registering for device notification\n";
|
std::cout << "Registering for device notification\n";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
WNDCLASSEX wndClass;
|
WNDCLASSEX wndClass;
|
||||||
|
|
||||||
wndClass.cbSize = sizeof(WNDCLASSEX);
|
wndClass.cbSize = sizeof(WNDCLASSEX);
|
||||||
wndClass.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
|
wndClass.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
|
||||||
wndClass.hInstance = reinterpret_cast<HINSTANCE>(GetModuleHandle(0));
|
wndClass.hInstance = reinterpret_cast<HINSTANCE>(GetModuleHandle(0));
|
||||||
@ -155,34 +150,41 @@ void RemovableDriveManager::register_window()
|
|||||||
wndClass.lpszClassName = L"PrusaSlicer_aux_class";
|
wndClass.lpszClassName = L"PrusaSlicer_aux_class";
|
||||||
wndClass.lpszMenuName = NULL;
|
wndClass.lpszMenuName = NULL;
|
||||||
wndClass.hIconSm = wndClass.hIcon;
|
wndClass.hIconSm = wndClass.hIcon;
|
||||||
|
if(!RegisterClassEx(&wndClass))
|
||||||
HINSTANCE hInstanceExe = GetModuleHandle(NULL);
|
{
|
||||||
|
DWORD err = GetLastError();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
HWND hWnd = CreateWindowEx(
|
HWND hWnd = CreateWindowEx(
|
||||||
WS_EX_CLIENTEDGE | WS_EX_APPWINDOW,
|
WS_EX_NOACTIVATE,
|
||||||
L"PrusaSlicer_aux_class",
|
L"PrusaSlicer_aux_class",
|
||||||
L"PrusaSlicer_aux_wnd",
|
L"PrusaSlicer_aux_wnd",
|
||||||
WS_OVERLAPPEDWINDOW, // style
|
WS_DISABLED, // style
|
||||||
CW_USEDEFAULT, 0,
|
CW_USEDEFAULT, 0,
|
||||||
640, 480,
|
640, 480,
|
||||||
NULL, NULL,
|
NULL, NULL,
|
||||||
hInstanceExe,
|
GetModuleHandle(NULL),
|
||||||
NULL);
|
NULL);
|
||||||
*/
|
if(hWnd == NULL)
|
||||||
|
{
|
||||||
|
DWORD err = GetLastError();
|
||||||
}
|
}
|
||||||
/*
|
//ShowWindow(hWnd, SW_SHOWNORMAL);
|
||||||
|
UpdateWindow(hWnd);
|
||||||
|
}
|
||||||
|
|
||||||
INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
LRESULT lRet = 1;
|
LRESULT lRet = 1;
|
||||||
static HDEVNOTIFY hDeviceNotify;
|
static HDEVNOTIFY hDeviceNotify;
|
||||||
|
|
||||||
static HWND hEditWnd;
|
static HWND hEditWnd;
|
||||||
static ULONGLONG msgCount = 0;
|
static ULONGLONG msgCount = 0;
|
||||||
|
|
||||||
switch (message)
|
switch (message)
|
||||||
{
|
{
|
||||||
case WM_CREATE:
|
case WM_CREATE:
|
||||||
|
|
||||||
|
|
||||||
DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;
|
DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;
|
||||||
|
|
||||||
ZeroMemory(&NotificationFilter, sizeof(NotificationFilter));
|
ZeroMemory(&NotificationFilter, sizeof(NotificationFilter));
|
||||||
@ -196,55 +198,13 @@ 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:
|
||||||
{
|
{
|
||||||
std::cout << "WM_DEVICECHANGE\n";
|
if(wParam == DBT_DEVICEREMOVECOMPLETE)
|
||||||
/*
|
|
||||||
// This is the actual message from the interface via Windows messaging.
|
|
||||||
// This code includes some additional decoding for this particular device type
|
|
||||||
// and some common validation checks.
|
|
||||||
//
|
|
||||||
// Note that not all devices utilize these optional parameters in the same
|
|
||||||
// way. Refer to the extended information for your particular device type
|
|
||||||
// specified by your GUID.
|
|
||||||
//
|
|
||||||
PDEV_BROADCAST_DEVICEINTERFACE b = (PDEV_BROADCAST_DEVICEINTERFACE)lParam;
|
|
||||||
TCHAR strBuff[256];
|
|
||||||
|
|
||||||
// Output some messages to the window.
|
|
||||||
switch (wParam)
|
|
||||||
{
|
{
|
||||||
case DBT_DEVICEARRIVAL:
|
std::cout << "WM_DEVICECHANGE\n";
|
||||||
msgCount++;
|
RemovableDriveManager::get_instance().on_drive_removed_callback();
|
||||||
StringCchPrintf(
|
|
||||||
strBuff, 256,
|
|
||||||
TEXT("Message %d: DBT_DEVICEARRIVAL\n"), msgCount);
|
|
||||||
break;
|
|
||||||
case DBT_DEVICEREMOVECOMPLETE:
|
|
||||||
msgCount++;
|
|
||||||
StringCchPrintf(
|
|
||||||
strBuff, 256,
|
|
||||||
TEXT("Message %d: DBT_DEVICEREMOVECOMPLETE\n"), msgCount);
|
|
||||||
break;
|
|
||||||
case DBT_DEVNODES_CHANGED:
|
|
||||||
msgCount++;
|
|
||||||
StringCchPrintf(
|
|
||||||
strBuff, 256,
|
|
||||||
TEXT("Message %d: DBT_DEVNODES_CHANGED\n"), msgCount);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
msgCount++;
|
|
||||||
StringCchPrintf(
|
|
||||||
strBuff, 256,
|
|
||||||
TEXT("Message %d: WM_DEVICECHANGE message received, value %d unhandled.\n"),
|
|
||||||
msgCount, wParam);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
OutputMessage(hEditWnd, wParam, (LPARAM)strBuff);
|
|
||||||
/
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -254,7 +214,7 @@ INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lP
|
|||||||
}
|
}
|
||||||
return lRet;
|
return lRet;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
#else
|
#else
|
||||||
void RemovableDriveManager::search_for_drives()
|
void RemovableDriveManager::search_for_drives()
|
||||||
{
|
{
|
||||||
@ -420,15 +380,16 @@ std::string RemovableDriveManager::get_drive_from_path(const std::string& path)
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
bool RemovableDriveManager::update(const long time)
|
void RemovableDriveManager::init()
|
||||||
{
|
|
||||||
if(m_last_update == 0)
|
|
||||||
{
|
{
|
||||||
add_callback([](void) { RemovableDriveManager::get_instance().print(); });
|
add_callback([](void) { RemovableDriveManager::get_instance().print(); });
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
//register_window();
|
register_window();
|
||||||
#endif
|
#endif
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
bool RemovableDriveManager::update(const long time)
|
||||||
|
{
|
||||||
if(time != 0) //time = 0 is forced update
|
if(time != 0) //time = 0 is forced update
|
||||||
{
|
{
|
||||||
long diff = m_last_update - time;
|
long diff = m_last_update - time;
|
||||||
@ -442,7 +403,6 @@ bool RemovableDriveManager::update(const long time)
|
|||||||
}
|
}
|
||||||
search_for_drives();
|
search_for_drives();
|
||||||
check_and_notify();
|
check_and_notify();
|
||||||
//eject_drive(m_current_drives.back().path);
|
|
||||||
return !m_current_drives.empty();
|
return !m_current_drives.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -523,6 +483,10 @@ void RemovableDriveManager::reset_last_save_path()
|
|||||||
{
|
{
|
||||||
m_last_save_path = "";
|
m_last_save_path = "";
|
||||||
}
|
}
|
||||||
|
void RemovableDriveManager::on_drive_removed_callback()
|
||||||
|
{
|
||||||
|
update();
|
||||||
|
}
|
||||||
void RemovableDriveManager::print()
|
void RemovableDriveManager::print()
|
||||||
{
|
{
|
||||||
//std::cout << "Removed Device: "<<(int)is_last_drive_removed()<<"\n";
|
//std::cout << "Removed Device: "<<(int)is_last_drive_removed()<<"\n";
|
||||||
|
@ -24,6 +24,7 @@ public:
|
|||||||
void operator=(RemovableDriveManager const&) = delete;
|
void operator=(RemovableDriveManager const&) = delete;
|
||||||
|
|
||||||
//update() searches for removable devices, returns false if empty.
|
//update() searches for removable devices, returns false if empty.
|
||||||
|
void init();
|
||||||
bool update(const long time = 0); //time = 0 is forced update, time expects wxGetLocalTime()
|
bool update(const long time = 0); //time = 0 is forced update, time expects wxGetLocalTime()
|
||||||
bool is_drive_mounted(const std::string &path);
|
bool is_drive_mounted(const std::string &path);
|
||||||
void eject_drive(const std::string &path);
|
void eject_drive(const std::string &path);
|
||||||
@ -36,6 +37,7 @@ public:
|
|||||||
bool is_last_drive_removed(); //if we dont need info about this drive, call reset_last_save_path();
|
bool is_last_drive_removed(); //if we dont need info about this drive, call reset_last_save_path();
|
||||||
bool is_last_drive_removed_with_update(const long time = 0); // param as update()
|
bool is_last_drive_removed_with_update(const long time = 0); // param as update()
|
||||||
void reset_last_save_path();
|
void reset_last_save_path();
|
||||||
|
void on_drive_removed_callback();
|
||||||
void print();
|
void print();
|
||||||
private:
|
private:
|
||||||
RemovableDriveManager():m_drives_count(0),m_last_update(0),m_last_save_path(""){}
|
RemovableDriveManager():m_drives_count(0),m_last_update(0),m_last_save_path(""){}
|
||||||
|
Loading…
Reference in New Issue
Block a user