refactoring

This commit is contained in:
David Kocik 2019-12-04 15:27:33 +01:00
parent a6e10e8fa2
commit 1c8ca1aec1
2 changed files with 9 additions and 8 deletions

View file

@ -121,6 +121,7 @@ bool RemovableDriveManager::is_path_on_removable_drive(const std::string &path)
} }
void RemovableDriveManager::register_window() void RemovableDriveManager::register_window()
{ {
//std::cout << "Registering for device notification\n";
/* /*
WNDCLASSEX wndClass; WNDCLASSEX wndClass;
@ -137,6 +138,7 @@ void RemovableDriveManager::register_window()
wndClass.lpszMenuName = NULL; wndClass.lpszMenuName = NULL;
wndClass.hIconSm = wndClass.hIcon; wndClass.hIconSm = wndClass.hIcon;
*/ */
//std::cout << "Failed\n";
} }
#else #else
void RemovableDriveManager::search_for_drives() void RemovableDriveManager::search_for_drives()
@ -191,7 +193,7 @@ void RemovableDriveManager::search_for_drives()
} }
std::cout << "found drives:" <<m_current_drives.size() << "\n"; //std::cout << "found drives:" <<m_current_drives.size() << "\n";
} }
void RemovableDriveManager::search_path(const std::string &path,const std::string &parent_path) void RemovableDriveManager::search_path(const std::string &path,const std::string &parent_path)
{ {
@ -295,21 +297,19 @@ bool RemovableDriveManager::is_path_on_removable_drive(const std::string &path)
#endif #endif
bool RemovableDriveManager::update(long time) bool RemovableDriveManager::update(long time)
{ {
static long last_update = 0; if(m_last_update == 0)
if(last_update == 0)
{ {
//add_callback(std::bind(&RemovableDriveManager::print, RemovableDriveManager::getInstance())); //add_callback([](void) { RemovableDriveManager::get_instance().print(); });
add_callback([](void) { RemovableDriveManager::get_instance().print(); });
#if _WIN32 #if _WIN32
register_window(); register_window();
#endif #endif
} }
if(time != 0) //time = 0 is forced update if(time != 0) //time = 0 is forced update
{ {
long diff = last_update - time; long diff = m_last_update - time;
if(diff <= -2) if(diff <= -2)
{ {
last_update = time; m_last_update = time;
}else }else
{ {
return false; // return value shouldnt matter if update didnt run return false; // return value shouldnt matter if update didnt run

View file

@ -33,12 +33,13 @@ public:
void add_callback(std::function<void()> callback); void add_callback(std::function<void()> callback);
void print(); void print();
private: private:
RemovableDriveManager():m_drives_count(0){} RemovableDriveManager():m_drives_count(0),m_last_update(0){}
void search_for_drives(); void search_for_drives();
void check_and_notify(); void check_and_notify();
std::vector<DriveData> m_current_drives; std::vector<DriveData> m_current_drives;
std::vector<std::function<void()>> m_callbacks; std::vector<std::function<void()>> m_callbacks;
size_t m_drives_count; size_t m_drives_count;
long m_last_update;
#if _WIN32 #if _WIN32
void register_window(); void register_window();
#else #else