linux eject
This commit is contained in:
parent
82baaf291e
commit
0eb8cb3fa1
@ -271,6 +271,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,
|
||||||
// and after MainFrame is created & shown.
|
// and after MainFrame is created & shown.
|
||||||
// The extra CallAfter() is needed because of Mac, where this is the only way
|
// The extra CallAfter() is needed because of Mac, where this is the only way
|
||||||
|
@ -20,8 +20,7 @@ DEFINE_GUID(GUID_DEVINTERFACE_USB_DEVICE,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
//std::vector<DriveData> RemovableDriveManager::m_current_drives;
|
//std::vector<DriveData> RemovableDriveManager::m_current_drives;
|
||||||
//std::vector<std::function<void()>> RemovableDriveManager::m_callbacks;
|
//std::vector<std::function<void()>> RemovableDriveManager::m_callbacks;
|
||||||
|
|
||||||
@ -95,7 +94,10 @@ void RemovableDriveManager::eject_drive(const std::string &path)
|
|||||||
if (error == 0)
|
if (error == 0)
|
||||||
{
|
{
|
||||||
std::cerr << "Ejecting " << mpath << " failed " << deviceControlRetVal << " " << GetLastError() << " \n";
|
std::cerr << "Ejecting " << mpath << " failed " << deviceControlRetVal << " " << GetLastError() << " \n";
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
m_current_drives.erase(it);
|
m_current_drives.erase(it);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -179,7 +181,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)
|
||||||
{
|
{
|
||||||
@ -225,13 +227,16 @@ void RemovableDriveManager::eject_drive(const std::string &path)
|
|||||||
if((*it).path == path)
|
if((*it).path == path)
|
||||||
{
|
{
|
||||||
std::cout<<"Ejecting "<<(*it).name<<" from "<< (*it).path<<"\n";
|
std::cout<<"Ejecting "<<(*it).name<<" from "<< (*it).path<<"\n";
|
||||||
int error = umount2(path.c_str(),MNT_DETACH);
|
std::string command = "umount ";
|
||||||
if(error)
|
command += (*it).path;
|
||||||
|
int err = system(command.c_str());
|
||||||
|
if(err)
|
||||||
{
|
{
|
||||||
int errsv = errno;
|
std::cerr<<"Ejecting failed\n";
|
||||||
std::cerr<<"Ejecting failed Error "<< errsv<<"\n";
|
return;
|
||||||
}
|
}
|
||||||
m_current_drives.erase(it);
|
m_current_drives.erase(it);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,10 +277,8 @@ bool RemovableDriveManager::update(long time)
|
|||||||
return false; // return value shouldnt matter if update didnt run
|
return false; // return value shouldnt matter if update didnt run
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//std::cout << "RDM update " << last_update <<"\n";
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -310,15 +313,17 @@ std::vector<DriveData> RemovableDriveManager::get_all_drives()
|
|||||||
}
|
}
|
||||||
void RemovableDriveManager::check_and_notify()
|
void RemovableDriveManager::check_and_notify()
|
||||||
{
|
{
|
||||||
static size_t number_of_drives = 0;
|
//std::cout<<"drives count: "<<m_drives_count;
|
||||||
if(number_of_drives != m_current_drives.size())
|
if(m_drives_count != m_current_drives.size())
|
||||||
{
|
{
|
||||||
|
//std::cout<<" vs "<< m_current_drives.size();
|
||||||
for (auto it = m_callbacks.begin(); it != m_callbacks.end(); ++it)
|
for (auto it = m_callbacks.begin(); it != m_callbacks.end(); ++it)
|
||||||
{
|
{
|
||||||
(*it)();
|
(*it)();
|
||||||
}
|
}
|
||||||
number_of_drives = m_current_drives.size();
|
m_drives_count = m_current_drives.size();
|
||||||
}
|
}
|
||||||
|
//std::cout<<"\n";
|
||||||
}
|
}
|
||||||
void RemovableDriveManager::add_callback(std::function<void()> callback)
|
void RemovableDriveManager::add_callback(std::function<void()> callback)
|
||||||
{
|
{
|
||||||
|
@ -33,11 +33,12 @@ public:
|
|||||||
void add_callback(std::function<void()> callback);
|
void add_callback(std::function<void()> callback);
|
||||||
void print();
|
void print();
|
||||||
private:
|
private:
|
||||||
RemovableDriveManager(){}
|
RemovableDriveManager():m_drives_count(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;
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
void register_window();
|
void register_window();
|
||||||
#else
|
#else
|
||||||
|
Loading…
Reference in New Issue
Block a user