From ef12f355998ae929142afd164c524792c6a86d36 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Tue, 26 Nov 2019 14:19:29 +0100 Subject: [PATCH 01/50] removable drive manager - Windows part --- src/slic3r/GUI/AppConfig.cpp | 5 + src/slic3r/GUI/RemovableDriveManager.cpp | 149 +++++++++++++++++++++++ src/slic3r/GUI/RemovableDriveManager.hpp | 41 +++++++ 3 files changed, 195 insertions(+) create mode 100644 src/slic3r/GUI/RemovableDriveManager.cpp create mode 100644 src/slic3r/GUI/RemovableDriveManager.hpp diff --git a/src/slic3r/GUI/AppConfig.cpp b/src/slic3r/GUI/AppConfig.cpp index 60f4edf478..67d8bd8cf4 100644 --- a/src/slic3r/GUI/AppConfig.cpp +++ b/src/slic3r/GUI/AppConfig.cpp @@ -21,6 +21,7 @@ #include #include "I18N.hpp" +#include "RemovableDriveManager.hpp" namespace Slic3r { @@ -357,6 +358,10 @@ void AppConfig::update_skein_dir(const std::string &dir) std::string AppConfig::get_last_output_dir(const std::string &alt) const { + if (GUI::RemovableDriveManager::getInstance().update()) + { + return GUI::RemovableDriveManager::getInstance().getLastDrivePath(); + } const auto it = m_storage.find(""); if (it != m_storage.end()) { const auto it2 = it->second.find("last_output_path"); diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp new file mode 100644 index 0000000000..44d4181d1b --- /dev/null +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -0,0 +1,149 @@ +#include "RemovableDriveManager.hpp" + +#include +#include +#include +#include + +//#include +//#include "libslic3r/Utils.hpp" + +DEFINE_GUID(GUID_DEVINTERFACE_USB_DEVICE, + 0xA5DCBF10L, 0x6530, 0x11D2, 0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED); + +namespace Slic3r { +namespace GUI { + +std::vector RemovableDriveManager::currentDrives; + +bool RemovableDriveManager::update() +{ + searchForDrives(currentDrives); + return !currentDrives.empty(); +} +void RemovableDriveManager::searchForDrives(std::vector& newDrives) +{ + newDrives.clear(); + newDrives.reserve(26); + DWORD drivesMask = GetLogicalDrives(); + for (size_t i = 0; i < 26; i++) + { + if(drivesMask & (1 << i)) + { + std::string path (1,(char)('A' + i)); + path+=":"; + UINT driveType = GetDriveTypeA(path.c_str()); + //std::cout << "found drive" << (char)('A' + i) << ": type:" < 0) + { + newDrives.push_back(DriveData(volumeName, path)); + } + } + } + } + else if(driveType == 3)//disks and usb drives + { + } + } + } + +} + +void RemovableDriveManager::updateCurrentDrives(const std::vector& newDrives) +{ + currentDrives.clear(); + currentDrives.reserve(26); + for (auto it = newDrives.begin(); it != newDrives.end(); ++it) + { + currentDrives.push_back(*it); + } +} +void RemovableDriveManager::printDrivesToLog() +{ + //std::cout<<"current drives:"<< currentDrives.size() <<"\n"; + for (auto it = currentDrives.begin(); it != currentDrives.end(); ++it) + { + //BOOST_LOG_TRIVIAL(trace) << boost::format("found disk %1%:") % ('A' + i); + //std::cout << /*std::string((*it).name.begin(), (*it).name.end()) << "(" << */(*it).path << ":/, "; + } + //std::cout << "\n"; +} +bool RemovableDriveManager::isDriveMounted(std::string path) +{ + for (auto it = currentDrives.begin(); it != currentDrives.end(); ++it) + { + if ((*it).path == path) + { + return true; + } + } + return false; +} +void RemovableDriveManager::ejectDrive(std::string path) +{ + if (!update() || !isDriveMounted(path)) + return; + + path = "\\\\.\\"+path; + HANDLE handle = CreateFileA(path.c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, 0, nullptr); + if(handle == INVALID_HANDLE_VALUE) + { + std::cerr << "Ejecting " << path << " failed " << GetLastError() << " \n"; + return; + } + DWORD deviceControlRetVal(0); + BOOL error = DeviceIoControl(handle, IOCTL_STORAGE_EJECT_MEDIA, nullptr, 0,nullptr , 0, &deviceControlRetVal, nullptr); + CloseHandle(handle); + if(error != 0) + std::cout << "Ejected " << path << "\n"; + else + std::cerr << "Ejecting " << path << " failed "<< deviceControlRetVal << " " << GetLastError() <<" \n"; + + for (auto it = currentDrives.begin(); it != currentDrives.end(); ++it) + { + if ((*it).path == path) + { + currentDrives.erase(it); + break; + } + } +} +std::string RemovableDriveManager::getLastDrivePath() +{ + if (!currentDrives.empty()) + { + return currentDrives.back().path; + } + return ""; +} +void RemovableDriveManager::getAllDrives(std::vector& drives) +{ + drives.clear(); + drives.reserve(26); + for (auto it = currentDrives.begin(); it != currentDrives.end(); ++it) + { + drives.push_back(*it); + } +} +}} \ No newline at end of file diff --git a/src/slic3r/GUI/RemovableDriveManager.hpp b/src/slic3r/GUI/RemovableDriveManager.hpp new file mode 100644 index 0000000000..cab58fee6c --- /dev/null +++ b/src/slic3r/GUI/RemovableDriveManager.hpp @@ -0,0 +1,41 @@ +#ifndef slic3r_GUI_RemovableDriveManager_hpp_ +#define slic3r_GUI_RemovableDriveManager_hpp_ + +#include +#include + +namespace Slic3r { +namespace GUI { +struct DriveData +{ + std::wstring name; + std::string path; + DriveData(std::wstring n, std::string p):name(n),path(p){} +}; +class RemovableDriveManager +{ +public: + static RemovableDriveManager& getInstance() + { + static RemovableDriveManager instance; + return instance; + } + RemovableDriveManager(RemovableDriveManager const&) = delete; + void operator=(RemovableDriveManager const&) = delete; + + //update() searches for removable devices, returns false if empty. + static bool update(); + static bool isDriveMounted(std::string path); + static void ejectDrive(std::string path); + static std::string getLastDrivePath(); + static void getAllDrives(std::vector& drives); +private: + RemovableDriveManager(){} + static void searchForDrives(std::vector& newDrives); + static void printDrivesToLog(); + static void updateCurrentDrives(const std::vector& newDrives); + static std::vector currentDrives; + +}; +}} +#endif \ No newline at end of file From 4822b577d2af2c37c56ae0a012b59c3177ed7502 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Tue, 26 Nov 2019 15:52:18 +0100 Subject: [PATCH 02/50] removable drives manager linux part --- src/slic3r/CMakeLists.txt | 2 + src/slic3r/GUI/RemovableDriveManager.cpp | 166 +++++++++++++++++------ src/slic3r/GUI/RemovableDriveManager.hpp | 10 +- 3 files changed, 134 insertions(+), 44 deletions(-) diff --git a/src/slic3r/CMakeLists.txt b/src/slic3r/CMakeLists.txt index 6dcbc60b71..bb196d3fde 100644 --- a/src/slic3r/CMakeLists.txt +++ b/src/slic3r/CMakeLists.txt @@ -109,6 +109,8 @@ set(SLIC3R_GUI_SOURCES GUI/WipeTowerDialog.hpp GUI/RammingChart.cpp GUI/RammingChart.hpp + GUI/RemovableDriveManager.cpp + GUI/RemovableDriveManager.hpp GUI/BonjourDialog.cpp GUI/BonjourDialog.hpp GUI/ButtonsDescription.cpp diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 44d4181d1b..ae718b7d3a 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -1,26 +1,34 @@ #include "RemovableDriveManager.hpp" -#include -#include + + #include #include -//#include -//#include "libslic3r/Utils.hpp" +#if _WIN32 +#include +#include DEFINE_GUID(GUID_DEVINTERFACE_USB_DEVICE, 0xA5DCBF10L, 0x6530, 0x11D2, 0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED); +#else +//linux includes +#include +#include +#include +#include +#include +#endif namespace Slic3r { namespace GUI { std::vector RemovableDriveManager::currentDrives; -bool RemovableDriveManager::update() -{ - searchForDrives(currentDrives); - return !currentDrives.empty(); -} + + + +#if _WIN32 void RemovableDriveManager::searchForDrives(std::vector& newDrives) { newDrives.clear(); @@ -69,37 +77,6 @@ void RemovableDriveManager::searchForDrives(std::vector& newDrives) } } - -void RemovableDriveManager::updateCurrentDrives(const std::vector& newDrives) -{ - currentDrives.clear(); - currentDrives.reserve(26); - for (auto it = newDrives.begin(); it != newDrives.end(); ++it) - { - currentDrives.push_back(*it); - } -} -void RemovableDriveManager::printDrivesToLog() -{ - //std::cout<<"current drives:"<< currentDrives.size() <<"\n"; - for (auto it = currentDrives.begin(); it != currentDrives.end(); ++it) - { - //BOOST_LOG_TRIVIAL(trace) << boost::format("found disk %1%:") % ('A' + i); - //std::cout << /*std::string((*it).name.begin(), (*it).name.end()) << "(" << */(*it).path << ":/, "; - } - //std::cout << "\n"; -} -bool RemovableDriveManager::isDriveMounted(std::string path) -{ - for (auto it = currentDrives.begin(); it != currentDrives.end(); ++it) - { - if ((*it).path == path) - { - return true; - } - } - return false; -} void RemovableDriveManager::ejectDrive(std::string path) { if (!update() || !isDriveMounted(path)) @@ -129,6 +106,115 @@ void RemovableDriveManager::ejectDrive(std::string path) } } } +#else +void RemovableDriveManager::searchForDrives(std::vector& newDrives) +{ + struct stat buf; + std::string path(std::getenv("USER")); + std::string pp(path); + + newDrives.clear(); + newDrives.reserve(26); + + //search /media/* folder + stat("/media/",&buf); + std::cout << "/media ID: " <& newDrives,const std::string path, const dev_t parentDevID) +{ + glob_t globbuf; + globbuf.gl_offs = 2; + std::cout<<"searching "<& newDrives) +{ + currentDrives.clear(); + currentDrives.reserve(26); + for (auto it = newDrives.begin(); it != newDrives.end(); ++it) + { + currentDrives.push_back(*it); + } +} +bool RemovableDriveManager::isDriveMounted(std::string path) +{ + for (auto it = currentDrives.begin(); it != currentDrives.end(); ++it) + { + if ((*it).path == path) + { + return true; + } + } + return false; +} + std::string RemovableDriveManager::getLastDrivePath() { if (!currentDrives.empty()) diff --git a/src/slic3r/GUI/RemovableDriveManager.hpp b/src/slic3r/GUI/RemovableDriveManager.hpp index cab58fee6c..c503fdf187 100644 --- a/src/slic3r/GUI/RemovableDriveManager.hpp +++ b/src/slic3r/GUI/RemovableDriveManager.hpp @@ -8,9 +8,9 @@ namespace Slic3r { namespace GUI { struct DriveData { - std::wstring name; + std::string name; std::string path; - DriveData(std::wstring n, std::string p):name(n),path(p){} + DriveData(std::string n, std::string p):name(n),path(p){} }; class RemovableDriveManager { @@ -32,10 +32,12 @@ public: private: RemovableDriveManager(){} static void searchForDrives(std::vector& newDrives); - static void printDrivesToLog(); static void updateCurrentDrives(const std::vector& newDrives); static std::vector currentDrives; - +#if _WIN32 +#else + static void searchPath(std::vector& newDrives,const std::string path, const dev_t parentDevID); +#endif }; }} #endif \ No newline at end of file From fdf159af42919a7d07288559732e93641b7e2588 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Wed, 27 Nov 2019 11:33:36 +0100 Subject: [PATCH 03/50] refactoring --- src/slic3r/GUI/AppConfig.cpp | 2 +- src/slic3r/GUI/RemovableDriveManager.cpp | 116 ++++++++++------------- src/slic3r/GUI/RemovableDriveManager.hpp | 15 ++- 3 files changed, 58 insertions(+), 75 deletions(-) diff --git a/src/slic3r/GUI/AppConfig.cpp b/src/slic3r/GUI/AppConfig.cpp index 67d8bd8cf4..320f337515 100644 --- a/src/slic3r/GUI/AppConfig.cpp +++ b/src/slic3r/GUI/AppConfig.cpp @@ -360,7 +360,7 @@ std::string AppConfig::get_last_output_dir(const std::string &alt) const { if (GUI::RemovableDriveManager::getInstance().update()) { - return GUI::RemovableDriveManager::getInstance().getLastDrivePath(); + return GUI::RemovableDriveManager::getInstance().get_last_drive_path(); } const auto it = m_storage.find(""); if (it != m_storage.end()) { diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index ae718b7d3a..53515ccdcb 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -1,14 +1,12 @@ #include "RemovableDriveManager.hpp" - - - #include #include - +#include "boost/nowide/convert.hpp" #if _WIN32 #include #include +#include DEFINE_GUID(GUID_DEVINTERFACE_USB_DEVICE, 0xA5DCBF10L, 0x6530, 0x11D2, 0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED); #else @@ -23,16 +21,13 @@ DEFINE_GUID(GUID_DEVINTERFACE_USB_DEVICE, namespace Slic3r { namespace GUI { -std::vector RemovableDriveManager::currentDrives; - - - +std::vector RemovableDriveManager::m_current_drives; #if _WIN32 -void RemovableDriveManager::searchForDrives(std::vector& newDrives) +void RemovableDriveManager::search_for_drives() { - newDrives.clear(); - newDrives.reserve(26); + m_current_drives.clear(); + m_current_drives.reserve(26); DWORD drivesMask = GetLogicalDrives(); for (size_t i = 0; i < 26; i++) { @@ -65,7 +60,7 @@ void RemovableDriveManager::searchForDrives(std::vector& newDrives) //std::cout << std::string(volumeName.begin(), volumeName.end()) << " " << std::string(fileSystemName.begin(), fileSystemName.end()) << " " << freeSpace.QuadPart << "\n"; if (freeSpace.QuadPart > 0) { - newDrives.push_back(DriveData(volumeName, path)); + m_current_drives.push_back(DriveData(boost::nowide::narrow(volumeName), path)); } } } @@ -77,49 +72,51 @@ void RemovableDriveManager::searchForDrives(std::vector& newDrives) } } -void RemovableDriveManager::ejectDrive(std::string path) +void RemovableDriveManager::eject_drive(const std::string &path) { - if (!update() || !isDriveMounted(path)) - return; - path = "\\\\.\\"+path; - HANDLE handle = CreateFileA(path.c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, 0, nullptr); - if(handle == INVALID_HANDLE_VALUE) - { - std::cerr << "Ejecting " << path << " failed " << GetLastError() << " \n"; + //if (!update() || !is_drive_mounted(path)) + if(m_current_drives.empty()) return; - } - DWORD deviceControlRetVal(0); - BOOL error = DeviceIoControl(handle, IOCTL_STORAGE_EJECT_MEDIA, nullptr, 0,nullptr , 0, &deviceControlRetVal, nullptr); - CloseHandle(handle); - if(error != 0) - std::cout << "Ejected " << path << "\n"; - else - std::cerr << "Ejecting " << path << " failed "<< deviceControlRetVal << " " << GetLastError() <<" \n"; - - for (auto it = currentDrives.begin(); it != currentDrives.end(); ++it) + for (auto it = m_current_drives.begin(); it != m_current_drives.end(); ++it) { if ((*it).path == path) { - currentDrives.erase(it); + std::string mpath = "\\\\.\\" + path; + HANDLE handle = CreateFileA(mpath.c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, 0, nullptr); + if (handle == INVALID_HANDLE_VALUE) + { + std::cerr << "Ejecting " << mpath << " failed " << GetLastError() << " \n"; + return; + } + DWORD deviceControlRetVal(0); + BOOL error = DeviceIoControl(handle, IOCTL_STORAGE_EJECT_MEDIA, nullptr, 0, nullptr, 0, &deviceControlRetVal, nullptr); + CloseHandle(handle); + if (error != 0) + std::cout << "Ejected " << mpath << "\n"; + else + std::cerr << "Ejecting " << mpath << " failed " << deviceControlRetVal << " " << GetLastError() << " \n"; + + + m_current_drives.erase(it); break; } } } #else -void RemovableDriveManager::searchForDrives(std::vector& newDrives) +void RemovableDriveManager::search_for_drives() { struct stat buf; std::string path(std::getenv("USER")); std::string pp(path); - newDrives.clear(); - newDrives.reserve(26); + m_current_drives.clear(); + m_current_Drives.reserve(26); //search /media/* folder stat("/media/",&buf); std::cout << "/media ID: " <& newDrives) stat(pp.c_str() ,&buf); std::cout << pp <<" ID: " <& newDrives,const std::string path, const dev_t parentDevID) +void RemovableDriveManager::search_path(const std::string &path,const dev_t &parentDevID) { glob_t globbuf; globbuf.gl_offs = 2; @@ -159,17 +156,17 @@ void RemovableDriveManager::searchPath(std::vector& newDrives,const s std::cout << buf.st_dev << "\n"; if(buf.st_dev != parentDevID)// not same file system { - newDrives.push_back(DriveData(name,globbuf.gl_pathv[i])); + m_current_drives.push_back(DriveData(name,globbuf.gl_pathv[i])); } } globfree(&globbuf); } -void RemovableDriveManager::ejectDrive(std::string path) +void RemovableDriveManager::eject_drive(const std::string &path) { - if (currentDrives.empty()) + if (m_current_drives.empty()) return; - for (auto it = currentDrives.begin(); it != currentDrives.end(); ++it) + for (auto it = m_current_drives.begin(); it != m_current_drives.end(); ++it) { if((*it).path == path) { @@ -180,7 +177,7 @@ void RemovableDriveManager::ejectDrive(std::string path) int errsv = errno; std::cerr<<"Ejecting failed Error "<< errsv<<"\n"; } - currentDrives.erase(it); + m_current_drives.erase(it); break; } @@ -190,22 +187,14 @@ void RemovableDriveManager::ejectDrive(std::string path) #endif bool RemovableDriveManager::update() { - searchForDrives(currentDrives); - return !currentDrives.empty(); + search_for_drives(); + return !m_current_drives.empty(); } -void RemovableDriveManager::updateCurrentDrives(const std::vector& newDrives) + +bool RemovableDriveManager::is_drive_mounted(const std::string &path) { - currentDrives.clear(); - currentDrives.reserve(26); - for (auto it = newDrives.begin(); it != newDrives.end(); ++it) - { - currentDrives.push_back(*it); - } -} -bool RemovableDriveManager::isDriveMounted(std::string path) -{ - for (auto it = currentDrives.begin(); it != currentDrives.end(); ++it) + for (auto it = m_current_drives.begin(); it != m_current_drives.end(); ++it) { if ((*it).path == path) { @@ -215,21 +204,16 @@ bool RemovableDriveManager::isDriveMounted(std::string path) return false; } -std::string RemovableDriveManager::getLastDrivePath() +std::string RemovableDriveManager::get_last_drive_path() { - if (!currentDrives.empty()) + if (!m_current_drives.empty()) { - return currentDrives.back().path; + return m_current_drives.back().path; } return ""; } -void RemovableDriveManager::getAllDrives(std::vector& drives) +std::vector RemovableDriveManager::get_all_drives() { - drives.clear(); - drives.reserve(26); - for (auto it = currentDrives.begin(); it != currentDrives.end(); ++it) - { - drives.push_back(*it); - } + return m_current_drives; } }} \ No newline at end of file diff --git a/src/slic3r/GUI/RemovableDriveManager.hpp b/src/slic3r/GUI/RemovableDriveManager.hpp index c503fdf187..8270c0f0fb 100644 --- a/src/slic3r/GUI/RemovableDriveManager.hpp +++ b/src/slic3r/GUI/RemovableDriveManager.hpp @@ -25,18 +25,17 @@ public: //update() searches for removable devices, returns false if empty. static bool update(); - static bool isDriveMounted(std::string path); - static void ejectDrive(std::string path); - static std::string getLastDrivePath(); - static void getAllDrives(std::vector& drives); + static bool is_drive_mounted(const std::string &path); + static void eject_drive(const std::string &path); + static std::string get_last_drive_path(); + static std::vector get_all_drives(); private: RemovableDriveManager(){} - static void searchForDrives(std::vector& newDrives); - static void updateCurrentDrives(const std::vector& newDrives); - static std::vector currentDrives; + static void search_for_drives(); + static std::vector m_current_drives; #if _WIN32 #else - static void searchPath(std::vector& newDrives,const std::string path, const dev_t parentDevID); + static void search_path(const std::string &path, const dev_t &parentDevID); #endif }; }} From 97a9f245f96617dfd1fb74c1262911abf1b68108 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Wed, 27 Nov 2019 13:30:45 +0100 Subject: [PATCH 04/50] check if last path is on rem drive --- src/slic3r/GUI/AppConfig.cpp | 6 +---- src/slic3r/GUI/Plater.cpp | 9 ++++++- src/slic3r/GUI/RemovableDriveManager.cpp | 30 +++++++++++++++++++++++- src/slic3r/GUI/RemovableDriveManager.hpp | 1 + 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/slic3r/GUI/AppConfig.cpp b/src/slic3r/GUI/AppConfig.cpp index 320f337515..16f0459664 100644 --- a/src/slic3r/GUI/AppConfig.cpp +++ b/src/slic3r/GUI/AppConfig.cpp @@ -21,7 +21,6 @@ #include #include "I18N.hpp" -#include "RemovableDriveManager.hpp" namespace Slic3r { @@ -358,10 +357,7 @@ void AppConfig::update_skein_dir(const std::string &dir) std::string AppConfig::get_last_output_dir(const std::string &alt) const { - if (GUI::RemovableDriveManager::getInstance().update()) - { - return GUI::RemovableDriveManager::getInstance().get_last_drive_path(); - } + const auto it = m_storage.find(""); if (it != m_storage.end()) { const auto it2 = it->second.find("last_output_path"); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 789271581e..bbfa9d9328 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -77,6 +77,7 @@ #include "../Utils/FixModelByWin10.hpp" #include "../Utils/UndoRedo.hpp" #include "../Utils/Thread.hpp" +#include "RemovableDriveManager.hpp" #include // Needs to be last because reasons :-/ #include "WipeTowerDialog.hpp" @@ -4549,7 +4550,13 @@ void Plater::export_gcode() } default_output_file = fs::path(Slic3r::fold_utf8_to_ascii(default_output_file.string())); auto start_dir = wxGetApp().app_config->get_last_output_dir(default_output_file.parent_path().string()); - + if (GUI::RemovableDriveManager::getInstance().update()) + { + if (!RemovableDriveManager::getInstance().is_path_on_removable_drive(start_dir)) + { + start_dir = RemovableDriveManager::getInstance().get_last_drive_path(); + } + } wxFileDialog dlg(this, (printer_technology() == ptFFF) ? _(L("Save G-code file as:")) : _(L("Save SL1 file as:")), start_dir, from_path(default_output_file.filename()), diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 53515ccdcb..776334bf22 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -7,6 +7,7 @@ #include #include #include +#include DEFINE_GUID(GUID_DEVINTERFACE_USB_DEVICE, 0xA5DCBF10L, 0x6530, 0x11D2, 0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED); #else @@ -208,7 +209,11 @@ std::string RemovableDriveManager::get_last_drive_path() { if (!m_current_drives.empty()) { +#if _WIN32 + return m_current_drives.back().path + "\\"; +#else return m_current_drives.back().path; +#endif } return ""; } @@ -216,4 +221,27 @@ std::vector RemovableDriveManager::get_all_drives() { return m_current_drives; } -}} \ No newline at end of file +#if _WIN32 +bool RemovableDriveManager::is_path_on_removable_drive(const std::string& path) +{ + if (m_current_drives.empty()) + return false; + int letter = PathGetDriveNumberA(path.c_str()); + for (auto it = m_current_drives.begin(); it != m_current_drives.end(); ++it) + { + char drive = (*it).path[0]; + if (drive == ('A' + letter)) + return true; + } + return false; +} +#else +bool RemovableDriveManager::is_path_on_removable_drive(const std::string& path, const std::string& drive) +{ + if (m_current_drives.empty()) + return false; + + return false; +} +#endif +}}//namespace Slicer::Gui:: \ No newline at end of file diff --git a/src/slic3r/GUI/RemovableDriveManager.hpp b/src/slic3r/GUI/RemovableDriveManager.hpp index 8270c0f0fb..3de9d72cee 100644 --- a/src/slic3r/GUI/RemovableDriveManager.hpp +++ b/src/slic3r/GUI/RemovableDriveManager.hpp @@ -29,6 +29,7 @@ public: static void eject_drive(const std::string &path); static std::string get_last_drive_path(); static std::vector get_all_drives(); + static bool is_path_on_removable_drive(const std::string &path); private: RemovableDriveManager(){} static void search_for_drives(); From 1cd06e32675eea22253312629d2d1ef0b75850d4 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Wed, 27 Nov 2019 14:30:10 +0100 Subject: [PATCH 05/50] prev commit linux part --- src/slic3r/GUI/RemovableDriveManager.cpp | 139 ++++++++++++----------- 1 file changed, 75 insertions(+), 64 deletions(-) diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 776334bf22..2d1f4ba6f2 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -29,46 +29,43 @@ void RemovableDriveManager::search_for_drives() { m_current_drives.clear(); m_current_drives.reserve(26); - DWORD drivesMask = GetLogicalDrives(); + DWORD drives_mask = GetLogicalDrives(); for (size_t i = 0; i < 26; i++) { - if(drivesMask & (1 << i)) + if(drives_mask & (1 << i)) { std::string path (1,(char)('A' + i)); path+=":"; - UINT driveType = GetDriveTypeA(path.c_str()); + UINT drive_type = GetDriveTypeA(path.c_str()); //std::cout << "found drive" << (char)('A' + i) << ": type:" < 0) + if (free_space.QuadPart > 0) { - m_current_drives.push_back(DriveData(boost::nowide::narrow(volumeName), path)); + m_current_drives.push_back(DriveData(boost::nowide::narrow(volume_name), path)); } } } } - else if(driveType == 3)//disks and usb drives - { - } } } @@ -93,10 +90,10 @@ void RemovableDriveManager::eject_drive(const std::string &path) DWORD deviceControlRetVal(0); BOOL error = DeviceIoControl(handle, IOCTL_STORAGE_EJECT_MEDIA, nullptr, 0, nullptr, 0, &deviceControlRetVal, nullptr); CloseHandle(handle); - if (error != 0) - std::cout << "Ejected " << mpath << "\n"; - else + if (error == 0) + { std::cerr << "Ejecting " << mpath << " failed " << deviceControlRetVal << " " << GetLastError() << " \n"; + } m_current_drives.erase(it); @@ -104,6 +101,19 @@ void RemovableDriveManager::eject_drive(const std::string &path) } } } +bool RemovableDriveManager::is_path_on_removable_drive(const std::string &path) +{ + if (m_current_drives.empty()) + return false; + int letter = PathGetDriveNumberA(path.c_str()); + for (auto it = m_current_drives.begin(); it != m_current_drives.end(); ++it) + { + char drive = (*it).path[0]; + if (drive == ('A' + letter)) + return true; + } + return false; +} #else void RemovableDriveManager::search_for_drives() { @@ -112,11 +122,11 @@ void RemovableDriveManager::search_for_drives() std::string pp(path); m_current_drives.clear(); - m_current_Drives.reserve(26); + m_current_drives.reserve(26); //search /media/* folder stat("/media/",&buf); - std::cout << "/media ID: " < RemovableDriveManager::get_all_drives() return m_current_drives; } #if _WIN32 -bool RemovableDriveManager::is_path_on_removable_drive(const std::string& path) -{ - if (m_current_drives.empty()) - return false; - int letter = PathGetDriveNumberA(path.c_str()); - for (auto it = m_current_drives.begin(); it != m_current_drives.end(); ++it) - { - char drive = (*it).path[0]; - if (drive == ('A' + letter)) - return true; - } - return false; -} -#else -bool RemovableDriveManager::is_path_on_removable_drive(const std::string& path, const std::string& drive) -{ - if (m_current_drives.empty()) - return false; - return false; -} +#else + #endif }}//namespace Slicer::Gui:: \ No newline at end of file From 4337b65f52e3ed761481cfafbd5c0aeb2e034d42 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Wed, 27 Nov 2019 15:47:37 +0100 Subject: [PATCH 06/50] rdm update every 2 seconds --- src/slic3r/GUI/GUI_App.cpp | 2 ++ src/slic3r/GUI/RemovableDriveManager.cpp | 15 ++++++++++++++- src/slic3r/GUI/RemovableDriveManager.hpp | 3 ++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index a74c6b0c06..35c11f0211 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -46,6 +46,7 @@ #include "SysInfoDialog.hpp" #include "KBShortcutsDialog.hpp" #include "UpdateDialogs.hpp" +#include "RemovableDriveManager.hpp" #ifdef __WXMSW__ #include @@ -269,6 +270,7 @@ bool GUI_App::on_init_inner() this->obj_manipul()->update_if_dirty(); + RemovableDriveManager::getInstance().update(wxGetLocalTime()); // Preset updating & Configwizard are done after the above initializations, // and after MainFrame is created & shown. // The extra CallAfter() is needed because of Mac, where this is the only way diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 2d1f4ba6f2..235e1ccbe8 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -23,6 +23,7 @@ namespace Slic3r { namespace GUI { std::vector RemovableDriveManager::m_current_drives; +long RemovableDriveManager::m_last_update = 0; #if _WIN32 void RemovableDriveManager::search_for_drives() @@ -215,8 +216,20 @@ bool RemovableDriveManager::is_path_on_removable_drive(const std::string &path) return false; } #endif -bool RemovableDriveManager::update() +bool RemovableDriveManager::update(long time) { + if(time != 0) //time = 0 is forced update + { + long diff = m_last_update - time; + if(diff <= -2) + { + m_last_update = time; + }else + { + return false; // return value shouldnt matter if update didnt run + } + } + std::cout << "RDM update " << m_last_update <<"\n"; search_for_drives(); return !m_current_drives.empty(); } diff --git a/src/slic3r/GUI/RemovableDriveManager.hpp b/src/slic3r/GUI/RemovableDriveManager.hpp index 3de9d72cee..c83b8033c9 100644 --- a/src/slic3r/GUI/RemovableDriveManager.hpp +++ b/src/slic3r/GUI/RemovableDriveManager.hpp @@ -24,7 +24,7 @@ public: void operator=(RemovableDriveManager const&) = delete; //update() searches for removable devices, returns false if empty. - static bool update(); + static bool update(long time = 0); //time = 0 is forced update static bool is_drive_mounted(const std::string &path); static void eject_drive(const std::string &path); static std::string get_last_drive_path(); @@ -34,6 +34,7 @@ private: RemovableDriveManager(){} static void search_for_drives(); static std::vector m_current_drives; + static long m_last_update; #if _WIN32 #else static void search_path(const std::string &path, const dev_t &parentDevID); From b7a5020196ecb42179825eb3504604f2e99e802d Mon Sep 17 00:00:00 2001 From: David Kocik Date: Thu, 28 Nov 2019 13:38:08 +0100 Subject: [PATCH 07/50] add_callback function --- src/slic3r/GUI/RemovableDriveManager.cpp | 65 ++++++++++++++++++++---- src/slic3r/GUI/RemovableDriveManager.hpp | 6 ++- 2 files changed, 60 insertions(+), 11 deletions(-) diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 235e1ccbe8..a1a5d7dd92 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -23,7 +23,8 @@ namespace Slic3r { namespace GUI { std::vector RemovableDriveManager::m_current_drives; -long RemovableDriveManager::m_last_update = 0; +std::vector> RemovableDriveManager::m_callbacks; + #if _WIN32 void RemovableDriveManager::search_for_drives() @@ -69,7 +70,7 @@ void RemovableDriveManager::search_for_drives() } } } - + //std::cout << "found drives:" << m_current_drives.size() << "\n"; } void RemovableDriveManager::eject_drive(const std::string &path) { @@ -115,6 +116,25 @@ bool RemovableDriveManager::is_path_on_removable_drive(const std::string &path) } return false; } +void RemovableDriveManager::register_window() +{ + /* + WNDCLASSEX wndClass; + + wndClass.cbSize = sizeof(WNDCLASSEX); + wndClass.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; + wndClass.hInstance = reinterpret_cast(GetModuleHandle(0)); + wndClass.lpfnWndProc = reinterpret_cast(WinProcCallback); + wndClass.cbClsExtra = 0; + wndClass.cbWndExtra = 0; + wndClass.hIcon = LoadIcon(0, IDI_APPLICATION); + wndClass.hbrBackground = CreateSolidBrush(RGB(192, 192, 192)); + wndClass.hCursor = LoadCursor(0, IDC_ARROW); + wndClass.lpszClassName = L"SlicerWindowClass"; + wndClass.lpszMenuName = NULL; + wndClass.hIconSm = wndClass.hIcon; + */ +} #else void RemovableDriveManager::search_for_drives() { @@ -218,19 +238,29 @@ bool RemovableDriveManager::is_path_on_removable_drive(const std::string &path) #endif bool RemovableDriveManager::update(long time) { + static long last_update = 0; + if(last_update == 0) + { + //add_callback(std::bind(&RemovableDriveManager::print, RemovableDriveManager::getInstance())); + add_callback([](void) { print(); }); +#if _WIN32 + register_window(); +#endif + } if(time != 0) //time = 0 is forced update { - long diff = m_last_update - time; + long diff = last_update - time; if(diff <= -2) { - m_last_update = time; + last_update = time; }else { return false; // return value shouldnt matter if update didnt run } } - std::cout << "RDM update " << m_last_update <<"\n"; + //std::cout << "RDM update " << last_update <<"\n"; search_for_drives(); + check_and_notify(); return !m_current_drives.empty(); } @@ -263,9 +293,24 @@ std::vector RemovableDriveManager::get_all_drives() { return m_current_drives; } -#if _WIN32 - -#else - -#endif +void RemovableDriveManager::check_and_notify() +{ + static int number_of_drives = 0; + if(number_of_drives != m_current_drives.size()) + { + for (auto it = m_callbacks.begin(); it != m_callbacks.end(); ++it) + { + (*it)(); + } + number_of_drives = m_current_drives.size(); + } +} +void RemovableDriveManager::add_callback(std::function callback) +{ + m_callbacks.push_back(callback); +} +void RemovableDriveManager::print() +{ + std::cout << "notified\n"; +} }}//namespace Slicer::Gui:: \ No newline at end of file diff --git a/src/slic3r/GUI/RemovableDriveManager.hpp b/src/slic3r/GUI/RemovableDriveManager.hpp index c83b8033c9..9f3ebf326b 100644 --- a/src/slic3r/GUI/RemovableDriveManager.hpp +++ b/src/slic3r/GUI/RemovableDriveManager.hpp @@ -30,12 +30,16 @@ public: static std::string get_last_drive_path(); static std::vector get_all_drives(); static bool is_path_on_removable_drive(const std::string &path); + static void add_callback(std::function callback); + static void print(); private: RemovableDriveManager(){} static void search_for_drives(); + static void check_and_notify(); static std::vector m_current_drives; - static long m_last_update; + static std::vector> m_callbacks; #if _WIN32 + static void register_window(); #else static void search_path(const std::string &path, const dev_t &parentDevID); #endif From 7301b4f7dd59138e8a44f1cc68996083db0dda9c Mon Sep 17 00:00:00 2001 From: David Kocik Date: Thu, 28 Nov 2019 13:50:58 +0100 Subject: [PATCH 08/50] refactoring --- src/slic3r/GUI/GUI_App.cpp | 2 +- src/slic3r/GUI/Plater.cpp | 6 ++--- src/slic3r/GUI/RemovableDriveManager.cpp | 6 ++--- src/slic3r/GUI/RemovableDriveManager.hpp | 30 ++++++++++++------------ 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 35c11f0211..10eb4ab59b 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -270,7 +270,7 @@ bool GUI_App::on_init_inner() this->obj_manipul()->update_if_dirty(); - RemovableDriveManager::getInstance().update(wxGetLocalTime()); + RemovableDriveManager::get_instance().update(wxGetLocalTime()); // Preset updating & Configwizard are done after the above initializations, // and after MainFrame is created & shown. // The extra CallAfter() is needed because of Mac, where this is the only way diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index bbfa9d9328..74b2d12391 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -4550,11 +4550,11 @@ void Plater::export_gcode() } default_output_file = fs::path(Slic3r::fold_utf8_to_ascii(default_output_file.string())); auto start_dir = wxGetApp().app_config->get_last_output_dir(default_output_file.parent_path().string()); - if (GUI::RemovableDriveManager::getInstance().update()) + if (GUI::RemovableDriveManager::get_instance().update()) { - if (!RemovableDriveManager::getInstance().is_path_on_removable_drive(start_dir)) + if (!RemovableDriveManager::get_instance().is_path_on_removable_drive(start_dir)) { - start_dir = RemovableDriveManager::getInstance().get_last_drive_path(); + start_dir = RemovableDriveManager::get_instance().get_last_drive_path(); } } wxFileDialog dlg(this, (printer_technology() == ptFFF) ? _(L("Save G-code file as:")) : _(L("Save SL1 file as:")), diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index a1a5d7dd92..777085165d 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -22,8 +22,8 @@ DEFINE_GUID(GUID_DEVINTERFACE_USB_DEVICE, namespace Slic3r { namespace GUI { -std::vector RemovableDriveManager::m_current_drives; -std::vector> RemovableDriveManager::m_callbacks; +//std::vector RemovableDriveManager::m_current_drives; +//std::vector> RemovableDriveManager::m_callbacks; #if _WIN32 @@ -242,7 +242,7 @@ bool RemovableDriveManager::update(long time) if(last_update == 0) { //add_callback(std::bind(&RemovableDriveManager::print, RemovableDriveManager::getInstance())); - add_callback([](void) { print(); }); + add_callback([](void) { RemovableDriveManager::get_instance().print(); }); #if _WIN32 register_window(); #endif diff --git a/src/slic3r/GUI/RemovableDriveManager.hpp b/src/slic3r/GUI/RemovableDriveManager.hpp index 9f3ebf326b..f3abc42073 100644 --- a/src/slic3r/GUI/RemovableDriveManager.hpp +++ b/src/slic3r/GUI/RemovableDriveManager.hpp @@ -15,7 +15,7 @@ struct DriveData class RemovableDriveManager { public: - static RemovableDriveManager& getInstance() + static RemovableDriveManager& get_instance() { static RemovableDriveManager instance; return instance; @@ -24,24 +24,24 @@ public: void operator=(RemovableDriveManager const&) = delete; //update() searches for removable devices, returns false if empty. - static bool update(long time = 0); //time = 0 is forced update - static bool is_drive_mounted(const std::string &path); - static void eject_drive(const std::string &path); - static std::string get_last_drive_path(); - static std::vector get_all_drives(); - static bool is_path_on_removable_drive(const std::string &path); - static void add_callback(std::function callback); - static void print(); + bool update(long time = 0); //time = 0 is forced update + bool is_drive_mounted(const std::string &path); + void eject_drive(const std::string &path); + std::string get_last_drive_path(); + std::vector get_all_drives(); + bool is_path_on_removable_drive(const std::string &path); + void add_callback(std::function callback); + void print(); private: RemovableDriveManager(){} - static void search_for_drives(); - static void check_and_notify(); - static std::vector m_current_drives; - static std::vector> m_callbacks; + void search_for_drives(); + void check_and_notify(); + std::vector m_current_drives; + std::vector> m_callbacks; #if _WIN32 - static void register_window(); + void register_window(); #else - static void search_path(const std::string &path, const dev_t &parentDevID); + void search_path(const std::string &path, const dev_t &parentDevID); #endif }; }} From 82baaf291eaaaeeea061003602504c8c7f4ee7ea Mon Sep 17 00:00:00 2001 From: David Kocik Date: Thu, 28 Nov 2019 16:35:22 +0100 Subject: [PATCH 09/50] search for rd as root --- src/slic3r/GUI/RemovableDriveManager.cpp | 103 +++++++++++++---------- src/slic3r/GUI/RemovableDriveManager.hpp | 3 +- 2 files changed, 61 insertions(+), 45 deletions(-) diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 777085165d..4368d06b64 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -1,6 +1,5 @@ #include "RemovableDriveManager.hpp" #include -#include #include "boost/nowide/convert.hpp" #if _WIN32 @@ -17,6 +16,7 @@ DEFINE_GUID(GUID_DEVINTERFACE_USB_DEVICE, #include #include #include +#include #endif namespace Slic3r { @@ -96,8 +96,6 @@ void RemovableDriveManager::eject_drive(const std::string &path) { std::cerr << "Ejecting " << mpath << " failed " << deviceControlRetVal << " " << GetLastError() << " \n"; } - - m_current_drives.erase(it); break; } @@ -138,65 +136,85 @@ void RemovableDriveManager::register_window() #else void RemovableDriveManager::search_for_drives() { - struct stat buf; - std::string path(std::getenv("USER")); - std::string pp(path); - + m_current_drives.clear(); m_current_drives.reserve(26); //search /media/* folder - stat("/media/",&buf); - //std::cout << "/media ID: " <pw_name; + pp = path; + //search /media/USERNAME/* folder + pp = "/media/"+pp; + path = "/media/" + path + "/*"; + search_path(path, pp); - stat(pp.c_str() ,&buf); - //std::cout << pp <<" ID: " < RemovableDriveManager::get_all_drives() } void RemovableDriveManager::check_and_notify() { - static int number_of_drives = 0; + static size_t number_of_drives = 0; if(number_of_drives != m_current_drives.size()) { for (auto it = m_callbacks.begin(); it != m_callbacks.end(); ++it) diff --git a/src/slic3r/GUI/RemovableDriveManager.hpp b/src/slic3r/GUI/RemovableDriveManager.hpp index f3abc42073..43e47a0867 100644 --- a/src/slic3r/GUI/RemovableDriveManager.hpp +++ b/src/slic3r/GUI/RemovableDriveManager.hpp @@ -41,7 +41,8 @@ private: #if _WIN32 void register_window(); #else - void search_path(const std::string &path, const dev_t &parentDevID); + void search_path(const std::string &path, const std::string &parent_path); + bool compare_filesystem_id(const std::string &path_a, const std::string &path_b); #endif }; }} From 0eb8cb3fa159028f9ddfe3fd2428a864218b5782 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Tue, 3 Dec 2019 10:09:53 +0100 Subject: [PATCH 10/50] linux eject --- src/slic3r/GUI/GUI_App.cpp | 1 + src/slic3r/GUI/RemovableDriveManager.cpp | 29 ++++++++++++++---------- src/slic3r/GUI/RemovableDriveManager.hpp | 3 ++- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 10eb4ab59b..c36c2748dd 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -271,6 +271,7 @@ bool GUI_App::on_init_inner() this->obj_manipul()->update_if_dirty(); RemovableDriveManager::get_instance().update(wxGetLocalTime()); + // Preset updating & Configwizard are done after the above initializations, // and after MainFrame is created & shown. // The extra CallAfter() is needed because of Mac, where this is the only way diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 4368d06b64..ec730692fa 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -20,8 +20,7 @@ DEFINE_GUID(GUID_DEVINTERFACE_USB_DEVICE, #endif namespace Slic3r { -namespace GUI { - +namespace GUI { //std::vector RemovableDriveManager::m_current_drives; //std::vector> RemovableDriveManager::m_callbacks; @@ -95,7 +94,10 @@ void RemovableDriveManager::eject_drive(const std::string &path) if (error == 0) { std::cerr << "Ejecting " << mpath << " failed " << deviceControlRetVal << " " << GetLastError() << " \n"; + return; } + + m_current_drives.erase(it); break; } @@ -179,7 +181,7 @@ void RemovableDriveManager::search_for_drives() } - std::cout << "found drives:" < RemovableDriveManager::get_all_drives() } void RemovableDriveManager::check_and_notify() { - static size_t number_of_drives = 0; - if(number_of_drives != m_current_drives.size()) + //std::cout<<"drives count: "< callback) { diff --git a/src/slic3r/GUI/RemovableDriveManager.hpp b/src/slic3r/GUI/RemovableDriveManager.hpp index 43e47a0867..b465b1c1b8 100644 --- a/src/slic3r/GUI/RemovableDriveManager.hpp +++ b/src/slic3r/GUI/RemovableDriveManager.hpp @@ -33,11 +33,12 @@ public: void add_callback(std::function callback); void print(); private: - RemovableDriveManager(){} + RemovableDriveManager():m_drives_count(0){} void search_for_drives(); void check_and_notify(); std::vector m_current_drives; std::vector> m_callbacks; + size_t m_drives_count; #if _WIN32 void register_window(); #else From 55409b0e96e804c4733956f74a23ef70a1c3945b Mon Sep 17 00:00:00 2001 From: David Kocik Date: Tue, 3 Dec 2019 10:55:38 +0100 Subject: [PATCH 11/50] windows paths --- src/slic3r/GUI/RemovableDriveManager.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index ec730692fa..9b3020e79e 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -62,6 +62,7 @@ void RemovableDriveManager::search_for_drives() //std::cout << std::string(volumeName.begin(), volumeName.end()) << " " << std::string(fileSystemName.begin(), fileSystemName.end()) << " " << freeSpace.QuadPart << "\n"; if (free_space.QuadPart > 0) { + path += "\\"; m_current_drives.push_back(DriveData(boost::nowide::narrow(volume_name), path)); } } @@ -82,6 +83,8 @@ void RemovableDriveManager::eject_drive(const std::string &path) if ((*it).path == path) { std::string mpath = "\\\\.\\" + path; + mpath = mpath.substr(0, mpath.size() - 1); + std::cout << "Ejecting " << mpath << "\n"; HANDLE handle = CreateFileA(mpath.c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, 0, nullptr); if (handle == INVALID_HANDLE_VALUE) { @@ -299,11 +302,11 @@ std::string RemovableDriveManager::get_last_drive_path() { if (!m_current_drives.empty()) { -#if _WIN32 - return m_current_drives.back().path + "\\"; -#else +//#if _WIN32 +// return m_current_drives.back().path + "\\"; +//#else return m_current_drives.back().path; -#endif +//#endif } return ""; } From 14fdf429ea3bb30ef9f1622912cab81efe696785 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Wed, 4 Dec 2019 10:05:18 +0100 Subject: [PATCH 12/50] osx search for drives --- src/slic3r/GUI/RemovableDriveManager.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 9b3020e79e..bdc1727403 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -148,6 +148,9 @@ void RemovableDriveManager::search_for_drives() //search /media/* folder search_path("/media/*", "/media"); + //search /Volumes/* folder (OSX) + search_path("/Volumes/*", "/Volumes"); + std::string path(std::getenv("USER")); std::string pp(path); //std::cout << "user: "<< path << "\n"; From 79cdb0ab07e8e1c62b5583384e33561e9d93aa76 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Wed, 4 Dec 2019 11:47:47 +0100 Subject: [PATCH 13/50] linux owner checking --- src/slic3r/GUI/RemovableDriveManager.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index bdc1727403..99520b8429 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -154,7 +154,10 @@ void RemovableDriveManager::search_for_drives() std::string path(std::getenv("USER")); std::string pp(path); //std::cout << "user: "<< path << "\n"; - if(path == "root"){ //if program is run with sudo, we have to search for all users + //if program is run with sudo, we have to search for all users + // but do we want that? + /* + if(path == "root"){ while (true) { passwd* entry = getpwent(); if (!entry) { @@ -174,6 +177,7 @@ void RemovableDriveManager::search_for_drives() } endpwent(); }else + */ { //search /media/USERNAME/* folder pp = "/media/"+pp; @@ -187,7 +191,7 @@ void RemovableDriveManager::search_for_drives() } - //std::cout << "found drives:" <pw_name == username) + { + std::string name = basename(globbuf.gl_pathv[i]); + m_current_drives.push_back(DriveData(name,globbuf.gl_pathv[i])); + } + } } } }else From fd7d75028a28f78b8d5c16c8d3b8a5269f7680e3 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Wed, 4 Dec 2019 13:10:08 +0100 Subject: [PATCH 14/50] path check --- src/slic3r/GUI/RemovableDriveManager.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 99520b8429..e1ab1626c5 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -248,6 +248,15 @@ void RemovableDriveManager::eject_drive(const std::string &path) { if((*it).path == path) { + + std::string correct_path(path); + for (size_t i = 0; i < correct_path.size(); ++i) + { + if(correct_path[i]==' ') + { + correct_path = correct_path.insert(i,"\\"); + } + } std::cout<<"Ejecting "<<(*it).name<<" from "<< (*it).path<<"\n"; std::string command = "umount "; command += (*it).path; @@ -301,6 +310,7 @@ bool RemovableDriveManager::update(long time) } search_for_drives(); check_and_notify(); + eject_drive(m_current_drives.back().path); return !m_current_drives.empty(); } From 0b015b0864911f45aaa9e6feb2c4c630575746c3 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Wed, 4 Dec 2019 13:13:18 +0100 Subject: [PATCH 15/50] path check --- src/slic3r/GUI/RemovableDriveManager.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index e1ab1626c5..3ff5735f91 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -255,6 +255,7 @@ void RemovableDriveManager::eject_drive(const std::string &path) if(correct_path[i]==' ') { correct_path = correct_path.insert(i,"\\"); + i++; } } std::cout<<"Ejecting "<<(*it).name<<" from "<< (*it).path<<"\n"; From 1c9dddeb2b923c2444def337ab0f7f0be34a099d Mon Sep 17 00:00:00 2001 From: David Kocik Date: Wed, 4 Dec 2019 13:18:08 +0100 Subject: [PATCH 16/50] path check --- src/slic3r/GUI/RemovableDriveManager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 3ff5735f91..7216763eec 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -254,13 +254,13 @@ void RemovableDriveManager::eject_drive(const std::string &path) { if(correct_path[i]==' ') { - correct_path = correct_path.insert(i,"\\"); + correct_path = correct_path.insert(i,1,'\\'); i++; } } - std::cout<<"Ejecting "<<(*it).name<<" from "<< (*it).path<<"\n"; + std::cout<<"Ejecting "<<(*it).name<<" from "<< correct_path<"\n"; std::string command = "umount "; - command += (*it).path; + command += correct_path; int err = system(command.c_str()); if(err) { From 9a301ac98df7ffecfa1e86dbc66d2f1259a9a3dd Mon Sep 17 00:00:00 2001 From: David Kocik Date: Wed, 4 Dec 2019 13:21:41 +0100 Subject: [PATCH 17/50] path check --- src/slic3r/GUI/RemovableDriveManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 7216763eec..c859a5d872 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -258,7 +258,7 @@ void RemovableDriveManager::eject_drive(const std::string &path) i++; } } - std::cout<<"Ejecting "<<(*it).name<<" from "<< correct_path<"\n"; + std::cout<<"Ejecting "<<(*it).name<<" from "<< correct_path<<"\n"; std::string command = "umount "; command += correct_path; int err = system(command.c_str()); From 1f6d2c87b85855e4998e7770a75499e3665652c9 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Wed, 4 Dec 2019 13:30:25 +0100 Subject: [PATCH 18/50] path check --- src/slic3r/GUI/RemovableDriveManager.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index c859a5d872..3d77606c81 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -259,7 +259,13 @@ void RemovableDriveManager::eject_drive(const std::string &path) } } std::cout<<"Ejecting "<<(*it).name<<" from "<< correct_path<<"\n"; - std::string command = "umount "; + + std::string command = ""; +#if __APPLE__ + command = "diskutil unmount "; +#else + command = "umount "; +#endif command += correct_path; int err = system(command.c_str()); if(err) From 0a4b2331a15c93cd503117b7110d3ed5c4013d4d Mon Sep 17 00:00:00 2001 From: David Kocik Date: Wed, 4 Dec 2019 13:43:28 +0100 Subject: [PATCH 19/50] comment testing lines --- src/slic3r/GUI/RemovableDriveManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 3d77606c81..0665e57dc2 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -317,7 +317,7 @@ bool RemovableDriveManager::update(long time) } search_for_drives(); check_and_notify(); - eject_drive(m_current_drives.back().path); + //eject_drive(m_current_drives.back().path); return !m_current_drives.empty(); } From 18be3ffb5f6db881353d12331c2022f304220be9 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Wed, 4 Dec 2019 15:27:33 +0100 Subject: [PATCH 20/50] refactoring --- src/slic3r/GUI/RemovableDriveManager.cpp | 14 +++++++------- src/slic3r/GUI/RemovableDriveManager.hpp | 3 ++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 0665e57dc2..a655425fc4 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -121,6 +121,7 @@ bool RemovableDriveManager::is_path_on_removable_drive(const std::string &path) } void RemovableDriveManager::register_window() { + //std::cout << "Registering for device notification\n"; /* WNDCLASSEX wndClass; @@ -137,6 +138,7 @@ void RemovableDriveManager::register_window() wndClass.lpszMenuName = NULL; wndClass.hIconSm = wndClass.hIcon; */ + //std::cout << "Failed\n"; } #else void RemovableDriveManager::search_for_drives() @@ -191,7 +193,7 @@ void RemovableDriveManager::search_for_drives() } - std::cout << "found drives:" < callback); void print(); private: - RemovableDriveManager():m_drives_count(0){} + RemovableDriveManager():m_drives_count(0),m_last_update(0){} void search_for_drives(); void check_and_notify(); std::vector m_current_drives; std::vector> m_callbacks; size_t m_drives_count; + long m_last_update; #if _WIN32 void register_window(); #else From 5f54856be0ae9dbde03595101e040f9fd45afab7 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Thu, 5 Dec 2019 14:07:02 +0100 Subject: [PATCH 21/50] last path functions --- src/slic3r/GUI/GUI_App.cpp | 3 +- src/slic3r/GUI/Plater.cpp | 2 + src/slic3r/GUI/RemovableDriveManager.cpp | 174 +++++++++++++++++++++-- src/slic3r/GUI/RemovableDriveManager.hpp | 12 +- 4 files changed, 173 insertions(+), 18 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index c36c2748dd..37753a0dea 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -270,7 +270,8 @@ bool GUI_App::on_init_inner() this->obj_manipul()->update_if_dirty(); - RemovableDriveManager::get_instance().update(wxGetLocalTime()); + //RemovableDriveManager::get_instance().update(wxGetLocalTime()); + std::cout << RemovableDriveManager::get_instance().is_last_drive_removed() << "\n"; // Preset updating & Configwizard are done after the above initializations, // and after MainFrame is created & shown. diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 5d967cb6c0..d1ce50f41f 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -4575,9 +4575,11 @@ void Plater::export_gcode() fs::path path = into_path(dlg.GetPath()); wxGetApp().app_config->update_last_output_dir(path.parent_path().string()); output_path = std::move(path); + RemovableDriveManager::get_instance().set_last_save_path(output_path.string()); } if (! output_path.empty()) p->export_gcode(std::move(output_path), PrintHostJob()); + } void Plater::export_stl(bool extended, bool selection_only) diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index a655425fc4..146bebc119 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -7,8 +7,11 @@ #include #include #include -DEFINE_GUID(GUID_DEVINTERFACE_USB_DEVICE, - 0xA5DCBF10L, 0x6530, 0x11D2, 0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED); + +//#include +//GUID WceusbshGUID = { 0x25dbce51, 0x6c8f, 0x4a72, +// 0x8a,0x6d,0xb5,0x4c,0x2b,0x4f,0xc8,0x35 }; + #else //linux includes #include @@ -26,6 +29,7 @@ namespace GUI { #if _WIN32 +//INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); void RemovableDriveManager::search_for_drives() { m_current_drives.clear(); @@ -84,7 +88,7 @@ void RemovableDriveManager::eject_drive(const std::string &path) { std::string mpath = "\\\\.\\" + path; mpath = mpath.substr(0, mpath.size() - 1); - std::cout << "Ejecting " << mpath << "\n"; + //std::cout << "Ejecting " << mpath << "\n"; HANDLE handle = CreateFileA(mpath.c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, 0, nullptr); if (handle == INVALID_HANDLE_VALUE) { @@ -119,10 +123,24 @@ bool RemovableDriveManager::is_path_on_removable_drive(const std::string &path) } return false; } +std::string RemovableDriveManager::get_drive_from_path(const std::string& path) +{ + int letter = PathGetDriveNumberA(path.c_str()); + for (auto it = m_current_drives.begin(); it != m_current_drives.end(); ++it) + { + char drive = (*it).path[0]; + if (drive == ('A' + letter)) + return (*it).path; + } + return ""; +} void RemovableDriveManager::register_window() { - //std::cout << "Registering for device notification\n"; /* + std::cout << "Registering for device notification\n"; + + + WNDCLASSEX wndClass; wndClass.cbSize = sizeof(WNDCLASSEX); @@ -134,12 +152,109 @@ void RemovableDriveManager::register_window() wndClass.hIcon = LoadIcon(0, IDI_APPLICATION); wndClass.hbrBackground = CreateSolidBrush(RGB(192, 192, 192)); wndClass.hCursor = LoadCursor(0, IDC_ARROW); - wndClass.lpszClassName = L"SlicerWindowClass"; + wndClass.lpszClassName = L"PrusaSlicer_aux_class"; wndClass.lpszMenuName = NULL; wndClass.hIconSm = wndClass.hIcon; - */ - //std::cout << "Failed\n"; + + HINSTANCE hInstanceExe = GetModuleHandle(NULL); + + HWND hWnd = CreateWindowEx( + WS_EX_CLIENTEDGE | WS_EX_APPWINDOW, + L"PrusaSlicer_aux_class", + L"PrusaSlicer_aux_wnd", + WS_OVERLAPPEDWINDOW, // style + CW_USEDEFAULT, 0, + 640, 480, + NULL, NULL, + hInstanceExe, + NULL); +*/ } +/* +INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + LRESULT lRet = 1; + static HDEVNOTIFY hDeviceNotify; + static HWND hEditWnd; + static ULONGLONG msgCount = 0; + + switch (message) + { + case WM_CREATE: + + + DEV_BROADCAST_DEVICEINTERFACE NotificationFilter; + + ZeroMemory(&NotificationFilter, sizeof(NotificationFilter)); + NotificationFilter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE); + NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; + NotificationFilter.dbcc_classguid = WceusbshGUID; + + hDeviceNotify = RegisterDeviceNotification( + hWnd, // events recipient + &NotificationFilter, // type of device + DEVICE_NOTIFY_WINDOW_HANDLE // type of recipient handle + ); + break; + + + + case WM_DEVICECHANGE: + { + std::cout << "WM_DEVICECHANGE\n"; + /* + // 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: + msgCount++; + 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; + default: + // Send all other messages on to the default windows handler. + lRet = DefWindowProc(hWnd, message, wParam, lParam); + break; + } + return lRet; +} +*/ #else void RemovableDriveManager::search_for_drives() { @@ -294,6 +409,16 @@ bool RemovableDriveManager::is_path_on_removable_drive(const std::string &path) } return false; } +std::string RemovableDriveManager::get_drive_from_path(const std::string& path) +{ + //check if same filesystem + for (auto it = m_current_drives.begin(); it != m_current_drives.end(); ++it) + { + if (compare_filesystem_id(path, (*it).path)) + return (*it).path; + } + return ""; +} #endif bool RemovableDriveManager::update(long time) { @@ -301,7 +426,7 @@ bool RemovableDriveManager::update(long time) { //add_callback([](void) { RemovableDriveManager::get_instance().print(); }); #if _WIN32 - register_window(); + //register_window(); #endif } if(time != 0) //time = 0 is forced update @@ -338,11 +463,9 @@ std::string RemovableDriveManager::get_last_drive_path() { if (!m_current_drives.empty()) { -//#if _WIN32 -// return m_current_drives.back().path + "\\"; -//#else + if (m_last_save_path != "") + return m_last_save_path; return m_current_drives.back().path; -//#endif } return ""; } @@ -356,9 +479,12 @@ void RemovableDriveManager::check_and_notify() 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) + if(m_drives_count > m_current_drives.size()) { - (*it)(); + for (auto it = m_callbacks.begin(); it != m_callbacks.end(); ++it) + { + (*it)(); + } } m_drives_count = m_current_drives.size(); } @@ -368,6 +494,26 @@ void RemovableDriveManager::add_callback(std::function callback) { m_callbacks.push_back(callback); } +void RemovableDriveManager::set_last_save_path(const std::string& path) +{ + std::string last_drive = get_drive_from_path(path); + if(last_drive != "") + { + m_last_save_path = last_drive; + } +} +bool RemovableDriveManager::is_last_drive_removed() +{ + if(m_last_save_path == "") + { + return true; + } + return !is_drive_mounted(m_last_save_path); +} +void RemovableDriveManager::reset_last_save_path() +{ + m_last_save_path = ""; +} void RemovableDriveManager::print() { std::cout << "notified\n"; diff --git a/src/slic3r/GUI/RemovableDriveManager.hpp b/src/slic3r/GUI/RemovableDriveManager.hpp index c65a7fe625..be5ae5968e 100644 --- a/src/slic3r/GUI/RemovableDriveManager.hpp +++ b/src/slic3r/GUI/RemovableDriveManager.hpp @@ -24,24 +24,30 @@ public: void operator=(RemovableDriveManager const&) = delete; //update() searches for removable devices, returns false if empty. - bool update(long time = 0); //time = 0 is forced update + bool update(long time = 0); //time = 0 is forced update, time expects wxGetLocalTime() bool is_drive_mounted(const std::string &path); void eject_drive(const std::string &path); std::string get_last_drive_path(); std::vector get_all_drives(); bool is_path_on_removable_drive(const std::string &path); - void add_callback(std::function callback); + void add_callback(std::function callback); // callback will notify every drive removal. to see if it was last used drive call is_last_drive_removed() + void set_last_save_path(const std::string &path); + bool is_last_drive_removed(); //if we dont need info about this drive, call reset_last_save_path(); + void reset_last_save_path(); void print(); private: - RemovableDriveManager():m_drives_count(0),m_last_update(0){} + RemovableDriveManager():m_drives_count(0),m_last_update(0),m_last_save_path(""){} void search_for_drives(); void check_and_notify(); + std::string get_drive_from_path(const std::string& path);//returns drive path (same as path in DriveData) if exists otherwise empty string "" std::vector m_current_drives; std::vector> m_callbacks; size_t m_drives_count; long m_last_update; + std::string m_last_save_path; #if _WIN32 void register_window(); + //INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); #else void search_path(const std::string &path, const std::string &parent_path); bool compare_filesystem_id(const std::string &path_a, const std::string &path_b); From 822ffa6c86076cd4f49731c09b84b4248104976f Mon Sep 17 00:00:00 2001 From: David Kocik Date: Thu, 5 Dec 2019 16:22:54 +0100 Subject: [PATCH 22/50] last save path --- src/slic3r/GUI/GUI_App.cpp | 7 ++++--- src/slic3r/GUI/RemovableDriveManager.cpp | 10 ++++++++-- src/slic3r/GUI/RemovableDriveManager.hpp | 3 ++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 37753a0dea..ed5371e669 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -270,9 +270,10 @@ bool GUI_App::on_init_inner() this->obj_manipul()->update_if_dirty(); - //RemovableDriveManager::get_instance().update(wxGetLocalTime()); - std::cout << RemovableDriveManager::get_instance().is_last_drive_removed() << "\n"; - + + RemovableDriveManager::get_instance().update(wxGetLocalTime()); + + // Preset updating & Configwizard are done after the above initializations, // and after MainFrame is created & shown. // The extra CallAfter() is needed because of Mac, where this is the only way diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 146bebc119..e94ea6918a 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -420,11 +420,11 @@ std::string RemovableDriveManager::get_drive_from_path(const std::string& path) return ""; } #endif -bool RemovableDriveManager::update(long time) +bool RemovableDriveManager::update(const long time) { if(m_last_update == 0) { - //add_callback([](void) { RemovableDriveManager::get_instance().print(); }); + add_callback([](void) { RemovableDriveManager::get_instance().print(); }); #if _WIN32 //register_window(); #endif @@ -510,12 +510,18 @@ bool RemovableDriveManager::is_last_drive_removed() } return !is_drive_mounted(m_last_save_path); } +bool RemovableDriveManager::is_last_drive_removed_with_update(const long time) +{ + update(time); + return is_last_drive_removed(); +} void RemovableDriveManager::reset_last_save_path() { m_last_save_path = ""; } void RemovableDriveManager::print() { + //std::cout << "Removed Device: "<<(int)is_last_drive_removed()<<"\n"; std::cout << "notified\n"; } }}//namespace Slicer::Gui:: \ No newline at end of file diff --git a/src/slic3r/GUI/RemovableDriveManager.hpp b/src/slic3r/GUI/RemovableDriveManager.hpp index be5ae5968e..906667244b 100644 --- a/src/slic3r/GUI/RemovableDriveManager.hpp +++ b/src/slic3r/GUI/RemovableDriveManager.hpp @@ -24,7 +24,7 @@ public: void operator=(RemovableDriveManager const&) = delete; //update() searches for removable devices, returns false if empty. - bool update(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); void eject_drive(const std::string &path); std::string get_last_drive_path(); @@ -33,6 +33,7 @@ public: void add_callback(std::function callback); // callback will notify every drive removal. to see if it was last used drive call is_last_drive_removed() void set_last_save_path(const std::string &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() void reset_last_save_path(); void print(); private: From 0f18e7e7ecb81e896f19bc9a5704b133225198bf Mon Sep 17 00:00:00 2001 From: David Kocik Date: Fri, 6 Dec 2019 13:17:36 +0100 Subject: [PATCH 23/50] callback only for used device --- src/slic3r/GUI/RemovableDriveManager.cpp | 2 +- src/slic3r/GUI/RemovableDriveManager.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index e94ea6918a..6581d53614 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -479,7 +479,7 @@ void RemovableDriveManager::check_and_notify() if(m_drives_count != m_current_drives.size()) { //std::cout<<" vs "<< m_current_drives.size(); - if(m_drives_count > m_current_drives.size()) + if(m_drives_count > m_current_drives.size() && m_last_save_path != "" && !is_drive_mounted(m_last_save_path)) { for (auto it = m_callbacks.begin(); it != m_callbacks.end(); ++it) { diff --git a/src/slic3r/GUI/RemovableDriveManager.hpp b/src/slic3r/GUI/RemovableDriveManager.hpp index 906667244b..741b4424ab 100644 --- a/src/slic3r/GUI/RemovableDriveManager.hpp +++ b/src/slic3r/GUI/RemovableDriveManager.hpp @@ -30,7 +30,7 @@ public: std::string get_last_drive_path(); std::vector get_all_drives(); bool is_path_on_removable_drive(const std::string &path); - void add_callback(std::function callback); // callback will notify every drive removal. to see if it was last used drive call is_last_drive_removed() + void add_callback(std::function callback); // callback will notify only if device with last save path was removed void set_last_save_path(const std::string &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() From 118354ecf43e366f6670b0dc6c83f6882f02b472 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Fri, 6 Dec 2019 13:21:44 +0100 Subject: [PATCH 24/50] erase callbacks --- src/slic3r/GUI/RemovableDriveManager.cpp | 4 ++++ src/slic3r/GUI/RemovableDriveManager.hpp | 1 + 2 files changed, 5 insertions(+) diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 6581d53614..1fbc33fc57 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -494,6 +494,10 @@ void RemovableDriveManager::add_callback(std::function callback) { m_callbacks.push_back(callback); } +void RemovableDriveManager::erase_callbacks() +{ + m_callbacks.clear(); +} void RemovableDriveManager::set_last_save_path(const std::string& path) { std::string last_drive = get_drive_from_path(path); diff --git a/src/slic3r/GUI/RemovableDriveManager.hpp b/src/slic3r/GUI/RemovableDriveManager.hpp index 741b4424ab..8d9e65c47e 100644 --- a/src/slic3r/GUI/RemovableDriveManager.hpp +++ b/src/slic3r/GUI/RemovableDriveManager.hpp @@ -31,6 +31,7 @@ public: std::vector get_all_drives(); bool is_path_on_removable_drive(const std::string &path); void add_callback(std::function callback); // callback will notify only if device with last save path was removed + void erase_callbacks(); // erases all callbacks added by add_callback() void set_last_save_path(const std::string &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() From 87fff4626e4a584abffb98da52dd62577cd997ee Mon Sep 17 00:00:00 2001 From: David Kocik Date: Fri, 6 Dec 2019 16:51:04 +0100 Subject: [PATCH 25/50] windows registration for device notif(thru hidden app) - windows doesnt need update now --- src/slic3r/GUI/GUI_App.cpp | 3 +- src/slic3r/GUI/RemovableDriveManager.cpp | 108 ++++++++--------------- src/slic3r/GUI/RemovableDriveManager.hpp | 2 + 3 files changed, 40 insertions(+), 73 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index ed5371e669..90e6cd4bdb 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -271,7 +271,7 @@ bool GUI_App::on_init_inner() 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, @@ -301,6 +301,7 @@ bool GUI_App::on_init_inner() preset_updater->slic3r_update_notify(); preset_updater->sync(preset_bundle); }); + RemovableDriveManager::get_instance().init(); } }); diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 1fbc33fc57..5daa9eb261 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -8,9 +8,9 @@ #include #include -//#include -//GUID WceusbshGUID = { 0x25dbce51, 0x6c8f, 0x4a72, -// 0x8a,0x6d,0xb5,0x4c,0x2b,0x4f,0xc8,0x35 }; +#include +GUID WceusbshGUID = { 0x25dbce51, 0x6c8f, 0x4a72, + 0x8a,0x6d,0xb5,0x4c,0x2b,0x4f,0xc8,0x35 }; #else //linux includes @@ -29,7 +29,7 @@ namespace GUI { #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() { m_current_drives.clear(); @@ -136,13 +136,8 @@ std::string RemovableDriveManager::get_drive_from_path(const std::string& path) } void RemovableDriveManager::register_window() { - /* std::cout << "Registering for device notification\n"; - - - WNDCLASSEX wndClass; - wndClass.cbSize = sizeof(WNDCLASSEX); wndClass.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; wndClass.hInstance = reinterpret_cast(GetModuleHandle(0)); @@ -155,34 +150,41 @@ void RemovableDriveManager::register_window() wndClass.lpszClassName = L"PrusaSlicer_aux_class"; wndClass.lpszMenuName = NULL; wndClass.hIconSm = wndClass.hIcon; - - HINSTANCE hInstanceExe = GetModuleHandle(NULL); + if(!RegisterClassEx(&wndClass)) + { + DWORD err = GetLastError(); + return; + } HWND hWnd = CreateWindowEx( - WS_EX_CLIENTEDGE | WS_EX_APPWINDOW, + WS_EX_NOACTIVATE, L"PrusaSlicer_aux_class", L"PrusaSlicer_aux_wnd", - WS_OVERLAPPEDWINDOW, // style + WS_DISABLED, // style CW_USEDEFAULT, 0, 640, 480, NULL, NULL, - hInstanceExe, + GetModuleHandle(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) { LRESULT lRet = 1; static HDEVNOTIFY hDeviceNotify; + static HWND hEditWnd; static ULONGLONG msgCount = 0; switch (message) { case WM_CREATE: - - DEV_BROADCAST_DEVICEINTERFACE 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 ); break; - - - case WM_DEVICECHANGE: { - std::cout << "WM_DEVICECHANGE\n"; - /* - // 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) + if(wParam == DBT_DEVICEREMOVECOMPLETE) { - case DBT_DEVICEARRIVAL: - msgCount++; - 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; + std::cout << "WM_DEVICECHANGE\n"; + RemovableDriveManager::get_instance().on_drive_removed_callback(); } - OutputMessage(hEditWnd, wParam, (LPARAM)strBuff); - / } break; default: @@ -254,7 +214,7 @@ INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lP } return lRet; } -*/ + #else void RemovableDriveManager::search_for_drives() { @@ -420,15 +380,16 @@ std::string RemovableDriveManager::get_drive_from_path(const std::string& path) return ""; } #endif +void RemovableDriveManager::init() +{ + add_callback([](void) { RemovableDriveManager::get_instance().print(); }); +#if _WIN32 + register_window(); +#endif + update(); +} bool RemovableDriveManager::update(const long time) { - if(m_last_update == 0) - { - add_callback([](void) { RemovableDriveManager::get_instance().print(); }); -#if _WIN32 - //register_window(); -#endif - } if(time != 0) //time = 0 is forced update { long diff = m_last_update - time; @@ -442,7 +403,6 @@ bool RemovableDriveManager::update(const long time) } search_for_drives(); check_and_notify(); - //eject_drive(m_current_drives.back().path); return !m_current_drives.empty(); } @@ -523,6 +483,10 @@ void RemovableDriveManager::reset_last_save_path() { m_last_save_path = ""; } +void RemovableDriveManager::on_drive_removed_callback() +{ + update(); +} void RemovableDriveManager::print() { //std::cout << "Removed Device: "<<(int)is_last_drive_removed()<<"\n"; diff --git a/src/slic3r/GUI/RemovableDriveManager.hpp b/src/slic3r/GUI/RemovableDriveManager.hpp index 8d9e65c47e..210d89477b 100644 --- a/src/slic3r/GUI/RemovableDriveManager.hpp +++ b/src/slic3r/GUI/RemovableDriveManager.hpp @@ -24,6 +24,7 @@ public: void operator=(RemovableDriveManager const&) = delete; //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 is_drive_mounted(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_with_update(const long time = 0); // param as update() void reset_last_save_path(); + void on_drive_removed_callback(); void print(); private: RemovableDriveManager():m_drives_count(0),m_last_update(0),m_last_save_path(""){} From 0d2a2d2b20e128b6de3ca65b7140a26badeb23ba Mon Sep 17 00:00:00 2001 From: David Kocik Date: Mon, 9 Dec 2019 15:33:10 +0100 Subject: [PATCH 26/50] osx device unmount callback - not sure if will build --- src/slic3r/CMakeLists.txt | 1 + src/slic3r/GUI/RemovableDriveManager.cpp | 11 ++--- src/slic3r/GUI/RemovableDriveManager.hpp | 4 +- src/slic3r/GUI/RemovableDriveManager.mm | 51 ++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 src/slic3r/GUI/RemovableDriveManager.mm diff --git a/src/slic3r/CMakeLists.txt b/src/slic3r/CMakeLists.txt index 03413f9337..6a14a1b3f3 100644 --- a/src/slic3r/CMakeLists.txt +++ b/src/slic3r/CMakeLists.txt @@ -169,6 +169,7 @@ if (APPLE) list(APPEND SLIC3R_GUI_SOURCES Utils/RetinaHelperImpl.mm Utils/MacDarkMode.mm + GUI/RemovableDriveManager.mm ) endif () diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 5daa9eb261..166728e68b 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -203,7 +203,7 @@ INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lP if(wParam == DBT_DEVICEREMOVECOMPLETE) { std::cout << "WM_DEVICECHANGE\n"; - RemovableDriveManager::get_instance().on_drive_removed_callback(); + RemovableDriveManager::get_instance().update(); } } break; @@ -219,6 +219,10 @@ INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lP void RemovableDriveManager::search_for_drives() { +#if __APPLE__ + list_devices(); +#endif + m_current_drives.clear(); m_current_drives.reserve(26); @@ -483,10 +487,7 @@ void RemovableDriveManager::reset_last_save_path() { m_last_save_path = ""; } -void RemovableDriveManager::on_drive_removed_callback() -{ - update(); -} + void RemovableDriveManager::print() { //std::cout << "Removed Device: "<<(int)is_last_drive_removed()<<"\n"; diff --git a/src/slic3r/GUI/RemovableDriveManager.hpp b/src/slic3r/GUI/RemovableDriveManager.hpp index 210d89477b..501c16b71a 100644 --- a/src/slic3r/GUI/RemovableDriveManager.hpp +++ b/src/slic3r/GUI/RemovableDriveManager.hpp @@ -37,7 +37,6 @@ public: 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() void reset_last_save_path(); - void on_drive_removed_callback(); void print(); private: RemovableDriveManager():m_drives_count(0),m_last_update(0),m_last_save_path(""){} @@ -52,6 +51,9 @@ private: #if _WIN32 void register_window(); //INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); +#elif __APPLE__ + void register_window(); + void list_devices(); #else void search_path(const std::string &path, const std::string &parent_path); bool compare_filesystem_id(const std::string &path_a, const std::string &path_b); diff --git a/src/slic3r/GUI/RemovableDriveManager.mm b/src/slic3r/GUI/RemovableDriveManager.mm new file mode 100644 index 0000000000..a1358625fc --- /dev/null +++ b/src/slic3r/GUI/RemovableDriveManager.mm @@ -0,0 +1,51 @@ +#import "RemovableDriveManager.hpp" + +@implementation RemovableDriveManager + +namespace Slic3r { +namespace GUI { + +void RemovableDriveManager::register_window() +{ + //[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector: @selector(volumesChanged:) name:NSWorkspaceDidMountNotification object: nil]; + [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector: @selector(on_device_unmount:) name:NSWorkspaceDidUnmountNotification object:nil]; +} + +-(void) on_device_unmount: (NSNotification*) notification +{ + NSLog(@"on device change"); + RemovableDriveManager::get_instance().update(); +} + +-(void) RemovableDriveManager::list_devices() +{ + NSLog(@"---"); + NSArray* devices = [[NSWorkspace sharedWorkspace] mountedRemovableMedia]; + for (NSString* volumePath in listOfMedia) + { + NSLog(@"@", volumePath); + } + NSLog(@"--"); + //removable here means CD not USB :/ + NSArray* listOfMedia = [[NSWorkspace sharedWorkspace] mountedLocalVolumePaths]; + NSLog(@"%@", listOfMedia); + + for (NSString* volumePath in listOfMedia) + { + BOOL isRemovable = NO; + BOOL isWritable = NO; + BOOL isUnmountable = NO; + NSString* description = [NSString string]; + NSString* type = [NSString string]; + + BOOL result = [[NSWorkspace sharedWorkspace] getFileSystemInfoForPath:volumePath + isRemovable:&isRemovable + isWritable:&isWritable + isUnmountable:&isUnmountable + description:&description + type:&type]; + NSLog(@"Result:%i Volume: %@, Removable:%i, W:%i, Unmountable:%i, Desc:%@, type:%@", result, volumePath, isRemovable, isWritable, isUnmountable, description, type); + } +} + +}}//namespace Slicer::GUI \ No newline at end of file From 8810a9aa31d07a63a1de6af0fefeb6ed6cb1f183 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Mon, 9 Dec 2019 17:12:22 +0100 Subject: [PATCH 27/50] init call --- src/slic3r/GUI/GUI_App.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 90e6cd4bdb..1b2fe919a2 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -260,6 +260,8 @@ bool GUI_App::on_init_inner() m_printhost_job_queue.reset(new PrintHostJobQueue(mainframe->printhost_queue_dlg())); + RemovableDriveManager::get_instance().init(); + Bind(wxEVT_IDLE, [this](wxIdleEvent& event) { if (! plater_) @@ -301,7 +303,7 @@ bool GUI_App::on_init_inner() preset_updater->slic3r_update_notify(); preset_updater->sync(preset_bundle); }); - RemovableDriveManager::get_instance().init(); + } }); From fdc493f6fd1d76209e5109f55d47aa9619867597 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Tue, 10 Dec 2019 10:08:57 +0100 Subject: [PATCH 28/50] macos mm files --- src/slic3r/CMakeLists.txt | 3 +- src/slic3r/GUI/RemovableDriveManager.hpp | 3 +- src/slic3r/GUI/RemovableDriveManagerMM.h | 9 ++++++ ...eManager.mm => RemovableDriveManagerMM.mm} | 29 +++++++++++++++---- 4 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 src/slic3r/GUI/RemovableDriveManagerMM.h rename src/slic3r/GUI/{RemovableDriveManager.mm => RemovableDriveManagerMM.mm} (84%) diff --git a/src/slic3r/CMakeLists.txt b/src/slic3r/CMakeLists.txt index 6a14a1b3f3..9d51f6219c 100644 --- a/src/slic3r/CMakeLists.txt +++ b/src/slic3r/CMakeLists.txt @@ -169,7 +169,8 @@ if (APPLE) list(APPEND SLIC3R_GUI_SOURCES Utils/RetinaHelperImpl.mm Utils/MacDarkMode.mm - GUI/RemovableDriveManager.mm + GUI/RemovableDriveManagerMM.mm + GUI/RemovableDriveManagerMM.h ) endif () diff --git a/src/slic3r/GUI/RemovableDriveManager.hpp b/src/slic3r/GUI/RemovableDriveManager.hpp index 501c16b71a..04bbe48b5d 100644 --- a/src/slic3r/GUI/RemovableDriveManager.hpp +++ b/src/slic3r/GUI/RemovableDriveManager.hpp @@ -52,8 +52,9 @@ private: void register_window(); //INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); #elif __APPLE__ + void *m_rdmmm; void register_window(); - void list_devices(); + //void list_devices(); #else void search_path(const std::string &path, const std::string &parent_path); bool compare_filesystem_id(const std::string &path_a, const std::string &path_b); diff --git a/src/slic3r/GUI/RemovableDriveManagerMM.h b/src/slic3r/GUI/RemovableDriveManagerMM.h new file mode 100644 index 0000000000..8f783c2d2a --- /dev/null +++ b/src/slic3r/GUI/RemovableDriveManagerMM.h @@ -0,0 +1,9 @@ +#import + +@interface RemovableDriveManagerMM : NSObject + +-(instancetype) init; +-(void) add_unmount_observer; +-(void) on_device_unmount: (NSNotification*) notification; + +@end \ No newline at end of file diff --git a/src/slic3r/GUI/RemovableDriveManager.mm b/src/slic3r/GUI/RemovableDriveManagerMM.mm similarity index 84% rename from src/slic3r/GUI/RemovableDriveManager.mm rename to src/slic3r/GUI/RemovableDriveManagerMM.mm index a1358625fc..e4e324654e 100644 --- a/src/slic3r/GUI/RemovableDriveManager.mm +++ b/src/slic3r/GUI/RemovableDriveManagerMM.mm @@ -1,22 +1,39 @@ #import "RemovableDriveManager.hpp" -@implementation RemovableDriveManager +#import + +@implementation RemovableDriveManagerMM namespace Slic3r { namespace GUI { -void RemovableDriveManager::register_window() +-(instancetype) init { - //[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector: @selector(volumesChanged:) name:NSWorkspaceDidMountNotification object: nil]; - [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector: @selector(on_device_unmount:) name:NSWorkspaceDidUnmountNotification object:nil]; + self = [super init]; + if(self) + { + [self add_unmount_observer] + } + return self; } - -(void) on_device_unmount: (NSNotification*) notification { NSLog(@"on device change"); RemovableDriveManager::get_instance().update(); } +-(void) add_unmount_observer +{ + [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector: @selector(on_device_unmount:) name:NSWorkspaceDidUnmountNotification object:nil]; +} +void RemovableDriveManager::register_window() +{ + m_rdmmm = nullptr; + m_rdmmm = [[RemovableDriveManagerMM alloc] init]; +} + + +/* -(void) RemovableDriveManager::list_devices() { NSLog(@"---"); @@ -47,5 +64,5 @@ void RemovableDriveManager::register_window() NSLog(@"Result:%i Volume: %@, Removable:%i, W:%i, Unmountable:%i, Desc:%@, type:%@", result, volumePath, isRemovable, isWritable, isUnmountable, description, type); } } - +*/ }}//namespace Slicer::GUI \ No newline at end of file From 40a83e67dd11f2cb66beae511159aa42c9a44fad Mon Sep 17 00:00:00 2001 From: Slic3rPE Date: Tue, 10 Dec 2019 11:17:12 +0100 Subject: [PATCH 29/50] macos implementation --- src/slic3r/GUI/RemovableDriveManager.cpp | 8 +++++--- src/slic3r/GUI/RemovableDriveManager.hpp | 4 +++- src/slic3r/GUI/RemovableDriveManagerMM.mm | 18 ++++++++++-------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 166728e68b..8145c90760 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -218,11 +218,11 @@ INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lP #else void RemovableDriveManager::search_for_drives() { - + /* #if __APPLE__ list_devices(); #endif - +*/ m_current_drives.clear(); m_current_drives.reserve(26); @@ -389,6 +389,8 @@ void RemovableDriveManager::init() add_callback([](void) { RemovableDriveManager::get_instance().print(); }); #if _WIN32 register_window(); +#elif __APPLE__ + register_window(); #endif update(); } @@ -493,4 +495,4 @@ void RemovableDriveManager::print() //std::cout << "Removed Device: "<<(int)is_last_drive_removed()<<"\n"; std::cout << "notified\n"; } -}}//namespace Slicer::Gui:: \ No newline at end of file +}}//namespace Slicer::Gui:: diff --git a/src/slic3r/GUI/RemovableDriveManager.hpp b/src/slic3r/GUI/RemovableDriveManager.hpp index 04bbe48b5d..c4f55029b7 100644 --- a/src/slic3r/GUI/RemovableDriveManager.hpp +++ b/src/slic3r/GUI/RemovableDriveManager.hpp @@ -55,10 +55,12 @@ private: void *m_rdmmm; void register_window(); //void list_devices(); + void search_path(const std::string &path, const std::string &parent_path); + bool compare_filesystem_id(const std::string &path_a, const std::string &path_b); #else void search_path(const std::string &path, const std::string &parent_path); bool compare_filesystem_id(const std::string &path_a, const std::string &path_b); #endif }; }} -#endif \ No newline at end of file +#endif diff --git a/src/slic3r/GUI/RemovableDriveManagerMM.mm b/src/slic3r/GUI/RemovableDriveManagerMM.mm index e4e324654e..99abd73860 100644 --- a/src/slic3r/GUI/RemovableDriveManagerMM.mm +++ b/src/slic3r/GUI/RemovableDriveManagerMM.mm @@ -1,37 +1,38 @@ #import "RemovableDriveManager.hpp" - +#import "RemovableDriveManagerMM.h" #import @implementation RemovableDriveManagerMM -namespace Slic3r { -namespace GUI { + -(instancetype) init { self = [super init]; if(self) { - [self add_unmount_observer] + [self add_unmount_observer]; } return self; } -(void) on_device_unmount: (NSNotification*) notification { NSLog(@"on device change"); - RemovableDriveManager::get_instance().update(); + Slic3r::GUI::RemovableDriveManager::get_instance().update(); } -(void) add_unmount_observer { + NSLog(@"add unmount observer"); [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector: @selector(on_device_unmount:) name:NSWorkspaceDidUnmountNotification object:nil]; } - +namespace Slic3r { +namespace GUI { void RemovableDriveManager::register_window() { m_rdmmm = nullptr; m_rdmmm = [[RemovableDriveManagerMM alloc] init]; } - +}}//namespace Slicer::GUI /* -(void) RemovableDriveManager::list_devices() @@ -65,4 +66,5 @@ void RemovableDriveManager::register_window() } } */ -}}//namespace Slicer::GUI \ No newline at end of file + +@end From 3b6daf64c7b22a2ba3ffa7dda89bc22aa36fd0a1 Mon Sep 17 00:00:00 2001 From: Slic3rPE Date: Tue, 10 Dec 2019 11:35:39 +0100 Subject: [PATCH 30/50] macos list devices --- src/slic3r/GUI/RemovableDriveManager.cpp | 4 +- src/slic3r/GUI/RemovableDriveManager.hpp | 4 +- src/slic3r/GUI/RemovableDriveManagerMM.h | 4 +- src/slic3r/GUI/RemovableDriveManagerMM.mm | 65 +++++++++++++---------- 4 files changed, 42 insertions(+), 35 deletions(-) diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 8145c90760..50e2b6359c 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -218,11 +218,11 @@ INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lP #else void RemovableDriveManager::search_for_drives() { - /* + #if __APPLE__ list_devices(); #endif -*/ + m_current_drives.clear(); m_current_drives.reserve(26); diff --git a/src/slic3r/GUI/RemovableDriveManager.hpp b/src/slic3r/GUI/RemovableDriveManager.hpp index c4f55029b7..7109bbd070 100644 --- a/src/slic3r/GUI/RemovableDriveManager.hpp +++ b/src/slic3r/GUI/RemovableDriveManager.hpp @@ -39,7 +39,7 @@ public: void reset_last_save_path(); void print(); 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(""),m_rdmmm(nullptr){} void search_for_drives(); void check_and_notify(); std::string get_drive_from_path(const std::string& path);//returns drive path (same as path in DriveData) if exists otherwise empty string "" @@ -54,7 +54,7 @@ private: #elif __APPLE__ void *m_rdmmm; void register_window(); - //void list_devices(); + void list_devices(); void search_path(const std::string &path, const std::string &parent_path); bool compare_filesystem_id(const std::string &path_a, const std::string &path_b); #else diff --git a/src/slic3r/GUI/RemovableDriveManagerMM.h b/src/slic3r/GUI/RemovableDriveManagerMM.h index 8f783c2d2a..4a5fa2515e 100644 --- a/src/slic3r/GUI/RemovableDriveManagerMM.h +++ b/src/slic3r/GUI/RemovableDriveManagerMM.h @@ -5,5 +5,5 @@ -(instancetype) init; -(void) add_unmount_observer; -(void) on_device_unmount: (NSNotification*) notification; - -@end \ No newline at end of file +-(void) list_dev; +@end diff --git a/src/slic3r/GUI/RemovableDriveManagerMM.mm b/src/slic3r/GUI/RemovableDriveManagerMM.mm index 99abd73860..7e8b56c59b 100644 --- a/src/slic3r/GUI/RemovableDriveManagerMM.mm +++ b/src/slic3r/GUI/RemovableDriveManagerMM.mm @@ -25,6 +25,36 @@ NSLog(@"add unmount observer"); [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector: @selector(on_device_unmount:) name:NSWorkspaceDidUnmountNotification object:nil]; } +-(void) list_dev +{ + NSLog(@"---"); + NSArray* devices = [[NSWorkspace sharedWorkspace] mountedRemovableMedia]; + for (NSString* volumePath in devices) + { + NSLog(@"@", volumePath); + } + NSLog(@"--"); + //removable here means CD not USB :/ + NSArray* listOfMedia = [[NSWorkspace sharedWorkspace] mountedLocalVolumePaths]; + NSLog(@"%@", listOfMedia); + + for (NSString* volumePath in listOfMedia) + { + BOOL isRemovable = NO; + BOOL isWritable = NO; + BOOL isUnmountable = NO; + NSString* description = [NSString string]; + NSString* type = [NSString string]; + + BOOL result = [[NSWorkspace sharedWorkspace] getFileSystemInfoForPath:volumePath + isRemovable:&isRemovable + isWritable:&isWritable + isUnmountable:&isUnmountable + description:&description + type:&type]; + NSLog(@"Result:%i Volume: %@, Removable:%i, W:%i, Unmountable:%i, Desc:%@, type:%@", result, volumePath, isRemovable, isWritable, isUnmountable, description, type); + } +} namespace Slic3r { namespace GUI { void RemovableDriveManager::register_window() @@ -32,39 +62,16 @@ void RemovableDriveManager::register_window() m_rdmmm = nullptr; m_rdmmm = [[RemovableDriveManagerMM alloc] init]; } +void RemovableDriveManager::list_devices() +{ + if(m_rdmmm == nullptr) + return; + [m_rdmmm list_dev]; +} }}//namespace Slicer::GUI /* --(void) RemovableDriveManager::list_devices() -{ - NSLog(@"---"); - NSArray* devices = [[NSWorkspace sharedWorkspace] mountedRemovableMedia]; - for (NSString* volumePath in listOfMedia) - { - NSLog(@"@", volumePath); - } - NSLog(@"--"); - //removable here means CD not USB :/ - NSArray* listOfMedia = [[NSWorkspace sharedWorkspace] mountedLocalVolumePaths]; - NSLog(@"%@", listOfMedia); - for (NSString* volumePath in listOfMedia) - { - BOOL isRemovable = NO; - BOOL isWritable = NO; - BOOL isUnmountable = NO; - NSString* description = [NSString string]; - NSString* type = [NSString string]; - - BOOL result = [[NSWorkspace sharedWorkspace] getFileSystemInfoForPath:volumePath - isRemovable:&isRemovable - isWritable:&isWritable - isUnmountable:&isUnmountable - description:&description - type:&type]; - NSLog(@"Result:%i Volume: %@, Removable:%i, W:%i, Unmountable:%i, Desc:%@, type:%@", result, volumePath, isRemovable, isWritable, isUnmountable, description, type); - } -} */ @end From d2a440c79440b63cda1c62e8b2f423b2e616bde4 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Tue, 10 Dec 2019 14:10:47 +0100 Subject: [PATCH 31/50] macos better wrapper --- src/slic3r/GUI/RemovableDriveManager.cpp | 50 +++++++++-------- src/slic3r/GUI/RemovableDriveManager.hpp | 33 ++++++++--- src/slic3r/GUI/RemovableDriveManagerMM.h | 2 +- src/slic3r/GUI/RemovableDriveManagerMM.mm | 68 +++++++++++------------ 4 files changed, 87 insertions(+), 66 deletions(-) diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 50e2b6359c..763113ea2c 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -220,9 +220,11 @@ void RemovableDriveManager::search_for_drives() { #if __APPLE__ - list_devices(); -#endif - + if(m_rdmmm) + { + m_rdmmm->list_devices(); + } +#else m_current_drives.clear(); m_current_drives.reserve(26); @@ -273,6 +275,7 @@ void RemovableDriveManager::search_for_drives() } //std::cout << "found drives:" <pw_name == username) - { - std::string name = basename(globbuf.gl_pathv[i]); - m_current_drives.push_back(DriveData(name,globbuf.gl_pathv[i])); - } - } - } + } }else { @@ -310,7 +296,27 @@ void RemovableDriveManager::search_path(const std::string &path,const std::strin globfree(&globbuf); } - +void RemovableDriveManager::inspect_file(const std::string &path, const std::string &parent_path) +{ + //if not same file system - could be removable drive + if(!compare_filesystem_id(globbuf.gl_pathv[i], parent_path)) + { + //user id + struct stat buf; + stat(globbuf.gl_pathv[i],&buf); + uid_t uid = buf.st_uid; + std::string username(std::getenv("USER")); + struct passwd *pw = getpwuid(uid); + if(pw != 0) + { + if(pw->pw_name == username) + { + std::string name = basename(globbuf.gl_pathv[i]); + m_current_drives.push_back(DriveData(name,globbuf.gl_pathv[i])); + } + } + } +} bool RemovableDriveManager::compare_filesystem_id(const std::string &path_a, const std::string &path_b) { struct stat buf; diff --git a/src/slic3r/GUI/RemovableDriveManager.hpp b/src/slic3r/GUI/RemovableDriveManager.hpp index 7109bbd070..202680328e 100644 --- a/src/slic3r/GUI/RemovableDriveManager.hpp +++ b/src/slic3r/GUI/RemovableDriveManager.hpp @@ -39,7 +39,11 @@ public: void reset_last_save_path(); void print(); private: - RemovableDriveManager():m_drives_count(0),m_last_update(0),m_last_save_path(""),m_rdmmm(nullptr){} +#if __APPLE__ + RemovableDriveManager():m_drives_count(0),m_last_update(0),m_last_save_path(""),m_rdmmm(new RemovableDriveManagerMM()){} +#else + RemovableDriveManager() : m_drives_count(0), m_last_update(0), m_last_save_path(""){} +#endif void search_for_drives(); void check_and_notify(); std::string get_drive_from_path(const std::string& path);//returns drive path (same as path in DriveData) if exists otherwise empty string "" @@ -51,16 +55,27 @@ private: #if _WIN32 void register_window(); //INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); -#elif __APPLE__ - void *m_rdmmm; - void register_window(); - void list_devices(); - void search_path(const std::string &path, const std::string &parent_path); - bool compare_filesystem_id(const std::string &path_a, const std::string &path_b); #else - void search_path(const std::string &path, const std::string &parent_path); - bool compare_filesystem_id(const std::string &path_a, const std::string &path_b); +#if __APPLE__ + RemovableDriveManagerMM * m_rdmmm; + #endif + void search_path(const std::string &path, const std::string &parent_path); + void inspect_file(const std::string &path, const std::string &parent_path); + bool compare_filesystem_id(const std::string &path_a, const std::string &path_b); #endif }; +#if __APPLE__ +class RemovableDriveManagerMM +{ +public: + RemovableDriveManagerMM(); + ~RemovableDriveManagerMM(); + register_window(); + list_devices(); +private: + RemovableDriveManagerMMImpl *m_imp; + friend void RemovableDriveManager::inspect_file(const std::string &path, const std::string &parent_path); +}; +#endif }} #endif diff --git a/src/slic3r/GUI/RemovableDriveManagerMM.h b/src/slic3r/GUI/RemovableDriveManagerMM.h index 4a5fa2515e..2999415454 100644 --- a/src/slic3r/GUI/RemovableDriveManagerMM.h +++ b/src/slic3r/GUI/RemovableDriveManagerMM.h @@ -5,5 +5,5 @@ -(instancetype) init; -(void) add_unmount_observer; -(void) on_device_unmount: (NSNotification*) notification; --(void) list_dev; +-(NSArray*) list_dev; @end diff --git a/src/slic3r/GUI/RemovableDriveManagerMM.mm b/src/slic3r/GUI/RemovableDriveManagerMM.mm index 7e8b56c59b..25fa6da091 100644 --- a/src/slic3r/GUI/RemovableDriveManagerMM.mm +++ b/src/slic3r/GUI/RemovableDriveManagerMM.mm @@ -10,8 +10,7 @@ { self = [super init]; if(self) - { - [self add_unmount_observer]; + { } return self; } @@ -25,48 +24,49 @@ NSLog(@"add unmount observer"); [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector: @selector(on_device_unmount:) name:NSWorkspaceDidUnmountNotification object:nil]; } --(void) list_dev +-(NSArray*) list_dev { - NSLog(@"---"); NSArray* devices = [[NSWorkspace sharedWorkspace] mountedRemovableMedia]; for (NSString* volumePath in devices) { - NSLog(@"@", volumePath); - } - NSLog(@"--"); - //removable here means CD not USB :/ - NSArray* listOfMedia = [[NSWorkspace sharedWorkspace] mountedLocalVolumePaths]; - NSLog(@"%@", listOfMedia); + NSLog(@"%@", volumePath); + } + return devices; - for (NSString* volumePath in listOfMedia) - { - BOOL isRemovable = NO; - BOOL isWritable = NO; - BOOL isUnmountable = NO; - NSString* description = [NSString string]; - NSString* type = [NSString string]; - - BOOL result = [[NSWorkspace sharedWorkspace] getFileSystemInfoForPath:volumePath - isRemovable:&isRemovable - isWritable:&isWritable - isUnmountable:&isUnmountable - description:&description - type:&type]; - NSLog(@"Result:%i Volume: %@, Removable:%i, W:%i, Unmountable:%i, Desc:%@, type:%@", result, volumePath, isRemovable, isWritable, isUnmountable, description, type); - } } namespace Slic3r { namespace GUI { -void RemovableDriveManager::register_window() -{ - m_rdmmm = nullptr; - m_rdmmm = [[RemovableDriveManagerMM alloc] init]; +struct RemovableDriveManagerMMImpl{ + RemovableDriveManagerMM * wrap; } -void RemovableDriveManager::list_devices() +RemovableDriveManagerMM():impl(new RemovableDriveManagerMMImpl){ + impl->wrap = [[RemovableDriveManagerMM alloc] init]; +} +RemovableDriveManagerMM::~RemovableDriveManagerMM() { - if(m_rdmmm == nullptr) - return; - [m_rdmmm list_dev]; + if(impl) + { + [impl->wrap release]; + } +} +void RDMMMWrapper::register_window() +{ + if(impl->wrap) + { + [impl->wrap add_unmount_observer]; + } +} +void RDMMMWrapper::list_devices() +{ + if(impl->wrap) + { + NSArray* devices = [impl->wrap list_dev]; + for (NSString* volumePath in devices) + { + NSLog(@"%@", volumePath); + Slic3r::GUI::RemovableDriveManager::get_instance().inspect_file(std::string([volumePath UTF8String]), "/Volumes"); + } + } } }}//namespace Slicer::GUI From 027b9f508285b3ab7e9783f4c165aa99bee4f886 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Tue, 10 Dec 2019 14:41:49 +0100 Subject: [PATCH 32/50] fix --- src/slic3r/GUI/RemovableDriveManager.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 763113ea2c..c5dca1bd55 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -231,9 +231,10 @@ void RemovableDriveManager::search_for_drives() //search /media/* folder search_path("/media/*", "/media"); +/* //search /Volumes/* folder (OSX) search_path("/Volumes/*", "/Volumes"); - +*/ std::string path(std::getenv("USER")); std::string pp(path); //std::cout << "user: "<< path << "\n"; @@ -286,7 +287,7 @@ void RemovableDriveManager::search_path(const std::string &path,const std::strin { for(size_t i = 0; i < globbuf.gl_pathc; i++) { - + inspect_file(globbuf.gl_pathv[i], parent_path); } }else { @@ -299,11 +300,11 @@ void RemovableDriveManager::search_path(const std::string &path,const std::strin void RemovableDriveManager::inspect_file(const std::string &path, const std::string &parent_path) { //if not same file system - could be removable drive - if(!compare_filesystem_id(globbuf.gl_pathv[i], parent_path)) + if(!compare_filesystem_id(path, parent_path)) { //user id struct stat buf; - stat(globbuf.gl_pathv[i],&buf); + stat(path.c_str(), &buf); uid_t uid = buf.st_uid; std::string username(std::getenv("USER")); struct passwd *pw = getpwuid(uid); @@ -311,8 +312,8 @@ void RemovableDriveManager::inspect_file(const std::string &path, const std::str { if(pw->pw_name == username) { - std::string name = basename(globbuf.gl_pathv[i]); - m_current_drives.push_back(DriveData(name,globbuf.gl_pathv[i])); + std::string name = basename(const_cast(path.c_str())); + m_current_drives.push_back(DriveData(name,path)); } } } From 37b6d9e8adb5964d7933bcc999302a0a1301f6b7 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 10 Dec 2019 17:31:27 +0100 Subject: [PATCH 33/50] Implemented "Disconnect" button --- src/slic3r/GUI/Plater.cpp | 41 ++++++++++++++++++++++++++++++++------- src/slic3r/GUI/Plater.hpp | 1 + 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index d1ce50f41f..b50f6f150d 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -700,6 +700,7 @@ struct Sidebar::priv wxButton *btn_export_gcode; wxButton *btn_reslice; wxButton *btn_send_gcode; + ScalableButton *btn_disconnect; priv(Plater *plater) : plater(plater) {} ~priv(); @@ -848,22 +849,39 @@ Sidebar::Sidebar(Plater *parent) // Buttons underneath the scrolled area - auto init_btn = [this](wxButton **btn, wxString label) { + auto init_btn = [this](wxButton **btn, wxString label, const std::string icon_name = "", wxString tooltip = wxEmptyString) { *btn = new wxButton(this, wxID_ANY, label, wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT); (*btn)->SetFont(wxGetApp().bold_font()); + (*btn)->SetToolTip(tooltip); + + if (!icon_name.empty()) + (*btn)->SetBitmap(create_scaled_bitmap(this, icon_name)); }; - init_btn(&p->btn_send_gcode, _(L("Send to printer"))); + init_btn(&p->btn_send_gcode, /*_(L("Send to printer"))*/"", "export_gcode", _(L("Send to printer"))); p->btn_send_gcode->Hide(); init_btn(&p->btn_export_gcode, _(L("Export G-code")) + dots); init_btn(&p->btn_reslice, _(L("Slice now"))); + + p->btn_disconnect = new ScalableButton(this, wxID_ANY, "revert_all_", "", + wxDefaultSize, wxDefaultPosition, wxBU_EXACTFIT); + p->btn_disconnect->Hide(); + p->btn_disconnect->SetToolTip(_(L("Remove device"))); + enable_buttons(false); auto *btns_sizer = new wxBoxSizer(wxVERTICAL); + + auto* complect_btns_sizer = new wxBoxSizer(wxHORIZONTAL); + complect_btns_sizer->Add(p->btn_export_gcode, 1, wxEXPAND); + complect_btns_sizer->Add(p->btn_send_gcode, 0, wxEXPAND); + complect_btns_sizer->Add(p->btn_disconnect); + btns_sizer->Add(p->btn_reslice, 0, wxEXPAND | wxTOP, margin_5); - btns_sizer->Add(p->btn_send_gcode, 0, wxEXPAND | wxTOP, margin_5); - btns_sizer->Add(p->btn_export_gcode, 0, wxEXPAND | wxTOP, margin_5); + btns_sizer->Add(complect_btns_sizer, 0, wxEXPAND | wxTOP, margin_5); +// btns_sizer->Add(p->btn_send_gcode, 0, wxEXPAND | wxTOP, margin_5); +// btns_sizer->Add(p->btn_export_gcode, 0, wxEXPAND | wxTOP, margin_5); auto *sizer = new wxBoxSizer(wxVERTICAL); sizer->Add(p->scrolled, 1, wxEXPAND); @@ -882,6 +900,9 @@ Sidebar::Sidebar(Plater *parent) p->plater->select_view_3D("Preview"); }); p->btn_send_gcode->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { p->plater->send_gcode(); }); + p->btn_disconnect->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { + // #dk_FIXME + }); } Sidebar::~Sidebar() {} @@ -1255,11 +1276,13 @@ void Sidebar::enable_buttons(bool enable) p->btn_reslice->Enable(enable); p->btn_export_gcode->Enable(enable); p->btn_send_gcode->Enable(enable); + p->btn_disconnect->Enable(enable); } bool Sidebar::show_reslice(bool show) const { return p->btn_reslice->Show(show); } bool Sidebar::show_export(bool show) const { return p->btn_export_gcode->Show(show); } bool Sidebar::show_send(bool show) const { return p->btn_send_gcode->Show(show); } +bool Sidebar::show_disconnect(bool show)const { return p->btn_disconnect->Show(show); } bool Sidebar::is_multifilament() { @@ -4019,20 +4042,24 @@ void Plater::priv::show_action_buttons(const bool is_ready_to_slice) const wxWindowUpdateLocker noUpdater(sidebar); const auto prin_host_opt = config->option("print_host"); const bool send_gcode_shown = prin_host_opt != nullptr && !prin_host_opt->value.empty(); + + const bool disconnect_shown = true; // #dk_FIXME // when a background processing is ON, export_btn and/or send_btn are showing if (wxGetApp().app_config->get("background_processing") == "1") { if (sidebar->show_reslice(false) | sidebar->show_export(true) | - sidebar->show_send(send_gcode_shown)) + sidebar->show_send(send_gcode_shown) | + sidebar->show_disconnect(disconnect_shown)) sidebar->Layout(); } else { if (sidebar->show_reslice(is_ready_to_slice) | sidebar->show_export(!is_ready_to_slice) | - sidebar->show_send(send_gcode_shown && !is_ready_to_slice)) + sidebar->show_send(send_gcode_shown && !is_ready_to_slice) | + sidebar->show_disconnect(disconnect_shown && !is_ready_to_slice)) sidebar->Layout(); } } @@ -4273,7 +4300,7 @@ void Sidebar::set_btn_label(const ActionButtonType btn_type, const wxString& lab { case ActionButtonType::abReslice: p->btn_reslice->SetLabelText(label); break; case ActionButtonType::abExport: p->btn_export_gcode->SetLabelText(label); break; - case ActionButtonType::abSendGCode: p->btn_send_gcode->SetLabelText(label); break; + case ActionButtonType::abSendGCode: /*p->btn_send_gcode->SetLabelText(label);*/ break; } } diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index 5c36dbf5e0..af4b989c42 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -119,6 +119,7 @@ public: bool show_reslice(bool show) const; bool show_export(bool show) const; bool show_send(bool show) const; + bool show_disconnect(bool show)const; bool is_multifilament(); void update_mode(); From cd1d49b015e7f90c375c44bc6ef15e11507dfdaf Mon Sep 17 00:00:00 2001 From: Slic3rPE Date: Wed, 11 Dec 2019 10:16:32 +0100 Subject: [PATCH 34/50] macos better wrapper --- src/slic3r/GUI/RemovableDriveManager.hpp | 29 +++++++++++++---------- src/slic3r/GUI/RemovableDriveManagerMM.mm | 21 +++++++--------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/slic3r/GUI/RemovableDriveManager.hpp b/src/slic3r/GUI/RemovableDriveManager.hpp index 202680328e..cbf6f53aac 100644 --- a/src/slic3r/GUI/RemovableDriveManager.hpp +++ b/src/slic3r/GUI/RemovableDriveManager.hpp @@ -6,6 +6,10 @@ namespace Slic3r { namespace GUI { +class RDMMMWrapper; +#if __APPLE__ + + struct DriveData { std::string name; @@ -57,25 +61,24 @@ private: //INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); #else #if __APPLE__ - RemovableDriveManagerMM * m_rdmmm; + RDMMMWrapper * m_rdmmm; #endif void search_path(const std::string &path, const std::string &parent_path); void inspect_file(const std::string &path, const std::string &parent_path); bool compare_filesystem_id(const std::string &path_a, const std::string &path_b); #endif }; -#if __APPLE__ -class RemovableDriveManagerMM -{ -public: - RemovableDriveManagerMM(); - ~RemovableDriveManagerMM(); - register_window(); - list_devices(); -private: - RemovableDriveManagerMMImpl *m_imp; - friend void RemovableDriveManager::inspect_file(const std::string &path, const std::string &parent_path); -}; + class RDMMMWrapper + { + public: + RDMMMWrapper(); + ~RDMMMWrapper(); + void register_window(); + void list_devices(); + private: + void *m_imp; + friend void RemovableDriveManager::inspect_file(const std::string &path, const std::string &parent_path); + }; #endif }} #endif diff --git a/src/slic3r/GUI/RemovableDriveManagerMM.mm b/src/slic3r/GUI/RemovableDriveManagerMM.mm index 25fa6da091..269a2255b0 100644 --- a/src/slic3r/GUI/RemovableDriveManagerMM.mm +++ b/src/slic3r/GUI/RemovableDriveManagerMM.mm @@ -36,31 +36,28 @@ } namespace Slic3r { namespace GUI { -struct RemovableDriveManagerMMImpl{ - RemovableDriveManagerMM * wrap; +RDMMMWrapper::RDMMMWrapper():m_imp(nullptr){ + m_imp = [[RemovableDriveManagerMM alloc] init]; } -RemovableDriveManagerMM():impl(new RemovableDriveManagerMMImpl){ - impl->wrap = [[RemovableDriveManagerMM alloc] init]; -} -RemovableDriveManagerMM::~RemovableDriveManagerMM() +RDMMMWrapper::~RDMMMWrapper() { - if(impl) + if(m_imp) { - [impl->wrap release]; + [m_imp release]; } } void RDMMMWrapper::register_window() { - if(impl->wrap) + if(m_imp) { - [impl->wrap add_unmount_observer]; + [m_imp add_unmount_observer]; } } void RDMMMWrapper::list_devices() { - if(impl->wrap) + if(m_imp) { - NSArray* devices = [impl->wrap list_dev]; + NSArray* devices = [m_imp list_dev]; for (NSString* volumePath in devices) { NSLog(@"%@", volumePath); From be09c91a1d1984e74d4ec0133314200fe100b1cf Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 11 Dec 2019 11:00:23 +0100 Subject: [PATCH 35/50] Added missed icon --- resources/icons/revert_all_.svg | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 resources/icons/revert_all_.svg diff --git a/resources/icons/revert_all_.svg b/resources/icons/revert_all_.svg new file mode 100644 index 0000000000..fe8de635db --- /dev/null +++ b/resources/icons/revert_all_.svg @@ -0,0 +1,9 @@ + + + + + Svg Vector Icons : http://www.onlinewebfonts.com/icon + + + + \ No newline at end of file From bcfc333fb108f87e62f961f403ede08cebc124a5 Mon Sep 17 00:00:00 2001 From: Slic3rPE Date: Wed, 11 Dec 2019 11:00:47 +0100 Subject: [PATCH 36/50] macos better wrapper --- src/slic3r/GUI/RemovableDriveManager.cpp | 12 ++++++- src/slic3r/GUI/RemovableDriveManager.hpp | 40 ++++++++++++----------- src/slic3r/GUI/RemovableDriveManagerMM.mm | 4 --- 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index c5dca1bd55..164b6e38aa 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -391,13 +391,23 @@ std::string RemovableDriveManager::get_drive_from_path(const std::string& path) return ""; } #endif + +RemovableDriveManager::RemovableDriveManager(): + m_drives_count(0), + m_last_update(0), + m_last_save_path(""), +#if __APPLE__ + m_rdmmm(new RDMMMWrapper()) +#endif +{} + void RemovableDriveManager::init() { add_callback([](void) { RemovableDriveManager::get_instance().print(); }); #if _WIN32 register_window(); #elif __APPLE__ - register_window(); + m_rdmmm->register_window(); #endif update(); } diff --git a/src/slic3r/GUI/RemovableDriveManager.hpp b/src/slic3r/GUI/RemovableDriveManager.hpp index cbf6f53aac..a5027a5adf 100644 --- a/src/slic3r/GUI/RemovableDriveManager.hpp +++ b/src/slic3r/GUI/RemovableDriveManager.hpp @@ -6,9 +6,9 @@ namespace Slic3r { namespace GUI { -class RDMMMWrapper; #if __APPLE__ - +class RDMMMWrapper; +#endif struct DriveData { @@ -18,6 +18,9 @@ struct DriveData }; class RemovableDriveManager { +#if __APPLE__ +friend class RDMMMWrapper; +#endif public: static RemovableDriveManager& get_instance() { @@ -42,12 +45,9 @@ public: bool is_last_drive_removed_with_update(const long time = 0); // param as update() void reset_last_save_path(); void print(); + private: -#if __APPLE__ - RemovableDriveManager():m_drives_count(0),m_last_update(0),m_last_save_path(""),m_rdmmm(new RemovableDriveManagerMM()){} -#else - RemovableDriveManager() : m_drives_count(0), m_last_update(0), m_last_save_path(""){} -#endif + RemovableDriveManager(); void search_for_drives(); void check_and_notify(); std::string get_drive_from_path(const std::string& path);//returns drive path (same as path in DriveData) if exists otherwise empty string "" @@ -64,21 +64,23 @@ private: RDMMMWrapper * m_rdmmm; #endif void search_path(const std::string &path, const std::string &parent_path); - void inspect_file(const std::string &path, const std::string &parent_path); bool compare_filesystem_id(const std::string &path_a, const std::string &path_b); + void inspect_file(const std::string &path, const std::string &parent_path); #endif }; - class RDMMMWrapper - { - public: - RDMMMWrapper(); - ~RDMMMWrapper(); - void register_window(); - void list_devices(); - private: - void *m_imp; - friend void RemovableDriveManager::inspect_file(const std::string &path, const std::string &parent_path); - }; + +#if __APPLE__ +class RDMMMWrapper +{ +public: + RDMMMWrapper(); + ~RDMMMWrapper(); + void register_window(); + void list_devices(); +protected: + void *m_imp; + //friend void RemovableDriveManager::inspect_file(const std::string &path, const std::string &parent_path); +}; #endif }} #endif diff --git a/src/slic3r/GUI/RemovableDriveManagerMM.mm b/src/slic3r/GUI/RemovableDriveManagerMM.mm index 269a2255b0..d32b7b278e 100644 --- a/src/slic3r/GUI/RemovableDriveManagerMM.mm +++ b/src/slic3r/GUI/RemovableDriveManagerMM.mm @@ -27,10 +27,6 @@ -(NSArray*) list_dev { NSArray* devices = [[NSWorkspace sharedWorkspace] mountedRemovableMedia]; - for (NSString* volumePath in devices) - { - NSLog(@"%@", volumePath); - } return devices; } From 975642e3e055297bd178196c16a69eaf58cb75bb Mon Sep 17 00:00:00 2001 From: David Kocik Date: Wed, 11 Dec 2019 12:28:51 +0100 Subject: [PATCH 37/50] eject button functionality --- src/slic3r/GUI/Plater.cpp | 19 ++++++++++++++++++- src/slic3r/GUI/Plater.hpp | 2 ++ src/slic3r/GUI/RemovableDriveManager.cpp | 22 +++++++++------------- src/slic3r/GUI/RemovableDriveManager.hpp | 8 +++++--- 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index b50f6f150d..e94e0a4e63 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -902,6 +902,7 @@ Sidebar::Sidebar(Plater *parent) p->btn_send_gcode->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { p->plater->send_gcode(); }); p->btn_disconnect->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { // #dk_FIXME + p->plater->eject_drive(); }); } @@ -4043,7 +4044,7 @@ void Plater::priv::show_action_buttons(const bool is_ready_to_slice) const const auto prin_host_opt = config->option("print_host"); const bool send_gcode_shown = prin_host_opt != nullptr && !prin_host_opt->value.empty(); - const bool disconnect_shown = true; // #dk_FIXME + const bool disconnect_shown = !(RemovableDriveManager::get_instance().is_last_drive_removed()); // #dk_FIXME // when a background processing is ON, export_btn and/or send_btn are showing if (wxGetApp().app_config->get("background_processing") == "1") @@ -4886,6 +4887,22 @@ void Plater::send_gcode() } } +void Plater::eject_drive() +{ + if (GUI::RemovableDriveManager::get_instance().update()) + { + RemovableDriveManager::get_instance().erase_callbacks(); + RemovableDriveManager::get_instance().add_callback(std::bind(&Plater::drive_ejected_callback, this)); + RemovableDriveManager::get_instance().eject_drive(RemovableDriveManager::get_instance().get_last_drive_path()); + } +} +void Plater::drive_ejected_callback() +{ + p->show_action_buttons(false); +} + + + void Plater::take_snapshot(const std::string &snapshot_name) { p->take_snapshot(snapshot_name); } void Plater::take_snapshot(const wxString &snapshot_name) { p->take_snapshot(snapshot_name); } void Plater::suppress_snapshots() { p->suppress_snapshots(); } diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index af4b989c42..a247f82922 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -202,6 +202,8 @@ public: void suppress_background_process(const bool stop_background_process) ; void fix_through_netfabb(const int obj_idx, const int vol_idx = -1); void send_gcode(); + void eject_drive(); + void drive_ejected_callback(); void take_snapshot(const std::string &snapshot_name); void take_snapshot(const wxString &snapshot_name); diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 164b6e38aa..1a964f889d 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -395,9 +395,9 @@ std::string RemovableDriveManager::get_drive_from_path(const std::string& path) RemovableDriveManager::RemovableDriveManager(): m_drives_count(0), m_last_update(0), - m_last_save_path(""), + m_last_save_path("") #if __APPLE__ - m_rdmmm(new RDMMMWrapper()) + , m_rdmmm(new RDMMMWrapper()) #endif {} @@ -411,7 +411,7 @@ void RemovableDriveManager::init() #endif update(); } -bool RemovableDriveManager::update(const long time) +bool RemovableDriveManager::update(const long time, bool check) { if(time != 0) //time = 0 is forced update { @@ -425,7 +425,7 @@ bool RemovableDriveManager::update(const long time) } } search_for_drives(); - check_and_notify(); + if(check)check_and_notify(); return !m_current_drives.empty(); } @@ -444,13 +444,7 @@ bool RemovableDriveManager::is_drive_mounted(const std::string &path) std::string RemovableDriveManager::get_last_drive_path() { - if (!m_current_drives.empty()) - { - if (m_last_save_path != "") - return m_last_save_path; - return m_current_drives.back().path; - } - return ""; + return m_last_save_path; } std::vector RemovableDriveManager::get_all_drives() { @@ -495,11 +489,13 @@ bool RemovableDriveManager::is_last_drive_removed() { return true; } - return !is_drive_mounted(m_last_save_path); + bool r = !is_drive_mounted(m_last_save_path); + if (r) reset_last_save_path(); + return r; } bool RemovableDriveManager::is_last_drive_removed_with_update(const long time) { - update(time); + update(time, false); return is_last_drive_removed(); } void RemovableDriveManager::reset_last_save_path() diff --git a/src/slic3r/GUI/RemovableDriveManager.hpp b/src/slic3r/GUI/RemovableDriveManager.hpp index a5027a5adf..f412940010 100644 --- a/src/slic3r/GUI/RemovableDriveManager.hpp +++ b/src/slic3r/GUI/RemovableDriveManager.hpp @@ -32,7 +32,7 @@ public: //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, bool check = true); //time = 0 is forced update, time expects wxGetLocalTime() bool is_drive_mounted(const std::string &path); void eject_drive(const std::string &path); std::string get_last_drive_path(); @@ -41,9 +41,8 @@ public: void add_callback(std::function callback); // callback will notify only if device with last save path was removed void erase_callbacks(); // erases all callbacks added by add_callback() void set_last_save_path(const std::string &path); - bool is_last_drive_removed(); //if we dont need info about this drive, call reset_last_save_path(); + bool is_last_drive_removed(); bool is_last_drive_removed_with_update(const long time = 0); // param as update() - void reset_last_save_path(); void print(); private: @@ -51,11 +50,14 @@ private: void search_for_drives(); void check_and_notify(); std::string get_drive_from_path(const std::string& path);//returns drive path (same as path in DriveData) if exists otherwise empty string "" + void reset_last_save_path(); + std::vector m_current_drives; std::vector> m_callbacks; size_t m_drives_count; long m_last_update; std::string m_last_save_path; + #if _WIN32 void register_window(); //INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); From 4a7f50ad669a3b71cf152b61a751cc088151578e Mon Sep 17 00:00:00 2001 From: David Kocik Date: Wed, 11 Dec 2019 14:53:28 +0100 Subject: [PATCH 38/50] eject button functionality --- src/slic3r/GUI/GUI_App.cpp | 2 +- src/slic3r/GUI/Plater.cpp | 6 +++--- src/slic3r/GUI/RemovableDriveManager.cpp | 24 +++++++++++++++++------ src/slic3r/GUI/RemovableDriveManager.hpp | 5 +++-- src/slic3r/GUI/RemovableDriveManagerMM.mm | 2 +- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 1b2fe919a2..fc25b4f295 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -273,7 +273,7 @@ bool GUI_App::on_init_inner() this->obj_manipul()->update_if_dirty(); - //RemovableDriveManager::get_instance().update(wxGetLocalTime()); + RemovableDriveManager::get_instance().update(wxGetLocalTime(), true); // Preset updating & Configwizard are done after the above initializations, diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index e94e0a4e63..905d56e900 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -4588,7 +4588,7 @@ void Plater::export_gcode() { if (!RemovableDriveManager::get_instance().is_path_on_removable_drive(start_dir)) { - start_dir = RemovableDriveManager::get_instance().get_last_drive_path(); + start_dir = RemovableDriveManager::get_instance().get_drive_path(); } } wxFileDialog dlg(this, (printer_technology() == ptFFF) ? _(L("Save G-code file as:")) : _(L("Save SL1 file as:")), @@ -4889,11 +4889,11 @@ void Plater::send_gcode() void Plater::eject_drive() { - if (GUI::RemovableDriveManager::get_instance().update()) + if (GUI::RemovableDriveManager::get_instance().update(0, true)) { RemovableDriveManager::get_instance().erase_callbacks(); RemovableDriveManager::get_instance().add_callback(std::bind(&Plater::drive_ejected_callback, this)); - RemovableDriveManager::get_instance().eject_drive(RemovableDriveManager::get_instance().get_last_drive_path()); + RemovableDriveManager::get_instance().eject_drive(RemovableDriveManager::get_instance().get_last_save_path()); } } void Plater::drive_ejected_callback() diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 1a964f889d..49bf59e11f 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -198,15 +198,16 @@ INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lP DEVICE_NOTIFY_WINDOW_HANDLE // type of recipient handle ); break; + /* case WM_DEVICECHANGE: { if(wParam == DBT_DEVICEREMOVECOMPLETE) { - std::cout << "WM_DEVICECHANGE\n"; - RemovableDriveManager::get_instance().update(); +- RemovableDriveManager::get_instance().update(0, true); } } break; + */ default: // Send all other messages on to the default windows handler. lRet = DefWindowProc(hWnd, message, wParam, lParam); @@ -403,7 +404,7 @@ RemovableDriveManager::RemovableDriveManager(): void RemovableDriveManager::init() { - add_callback([](void) { RemovableDriveManager::get_instance().print(); }); + //add_callback([](void) { RemovableDriveManager::get_instance().print(); }); #if _WIN32 register_window(); #elif __APPLE__ @@ -441,8 +442,18 @@ bool RemovableDriveManager::is_drive_mounted(const std::string &path) } return false; } - -std::string RemovableDriveManager::get_last_drive_path() +std::string RemovableDriveManager::get_drive_path() +{ + if (m_current_drives.size() == 0) + { + reset_last_save_path(); + return ""; + } + if (m_last_save_path != "") + return m_last_save_path; + return m_current_drives.back().path; +} +std::string RemovableDriveManager::get_last_save_path() { return m_last_save_path; } @@ -456,7 +467,7 @@ void RemovableDriveManager::check_and_notify() if(m_drives_count != m_current_drives.size()) { //std::cout<<" vs "<< m_current_drives.size(); - if(m_drives_count > m_current_drives.size() && m_last_save_path != "" && !is_drive_mounted(m_last_save_path)) + if(m_callbacks.size() != 0 && m_drives_count > m_current_drives.size() && m_last_save_path != "" && !is_drive_mounted(m_last_save_path)) { for (auto it = m_callbacks.begin(); it != m_callbacks.end(); ++it) { @@ -485,6 +496,7 @@ void RemovableDriveManager::set_last_save_path(const std::string& path) } bool RemovableDriveManager::is_last_drive_removed() { + m_drives_count = m_current_drives.size(); if(m_last_save_path == "") { return true; diff --git a/src/slic3r/GUI/RemovableDriveManager.hpp b/src/slic3r/GUI/RemovableDriveManager.hpp index f412940010..49df414827 100644 --- a/src/slic3r/GUI/RemovableDriveManager.hpp +++ b/src/slic3r/GUI/RemovableDriveManager.hpp @@ -32,10 +32,11 @@ public: //update() searches for removable devices, returns false if empty. void init(); - bool update(const long time = 0, bool check = true); //time = 0 is forced update, time expects wxGetLocalTime() + bool update(const long time = 0, bool check = false); //time = 0 is forced update, time expects wxGetLocalTime() bool is_drive_mounted(const std::string &path); void eject_drive(const std::string &path); - std::string get_last_drive_path(); + std::string get_last_save_path(); + std::string get_drive_path(); std::vector get_all_drives(); bool is_path_on_removable_drive(const std::string &path); void add_callback(std::function callback); // callback will notify only if device with last save path was removed diff --git a/src/slic3r/GUI/RemovableDriveManagerMM.mm b/src/slic3r/GUI/RemovableDriveManagerMM.mm index d32b7b278e..7a1108541a 100644 --- a/src/slic3r/GUI/RemovableDriveManagerMM.mm +++ b/src/slic3r/GUI/RemovableDriveManagerMM.mm @@ -17,7 +17,7 @@ -(void) on_device_unmount: (NSNotification*) notification { NSLog(@"on device change"); - Slic3r::GUI::RemovableDriveManager::get_instance().update(); + Slic3r::GUI::RemovableDriveManager::get_instance().update(0,true); } -(void) add_unmount_observer { From 6dddc1cc6bcb1b7376b2af15bd271f2984190377 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Wed, 11 Dec 2019 15:02:20 +0100 Subject: [PATCH 39/50] eject button functionality --- src/slic3r/GUI/Plater.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 905d56e900..0300670e48 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -4603,7 +4603,9 @@ void Plater::export_gcode() fs::path path = into_path(dlg.GetPath()); wxGetApp().app_config->update_last_output_dir(path.parent_path().string()); output_path = std::move(path); - RemovableDriveManager::get_instance().set_last_save_path(output_path.string()); + RemovableDriveManager::get_instance().update(0, true); + RemovableDriveManager::get_instance().set_last_save_path(output_path.string()); + } if (! output_path.empty()) p->export_gcode(std::move(output_path), PrintHostJob()); From 38c69f16f04cd051d66175e39514c4e0873de8e5 Mon Sep 17 00:00:00 2001 From: Slic3rPE Date: Wed, 11 Dec 2019 16:59:26 +0100 Subject: [PATCH 40/50] macos eject --- src/slic3r/GUI/GUI_App.cpp | 2 +- src/slic3r/GUI/RemovableDriveManager.cpp | 5 +++++ src/slic3r/GUI/RemovableDriveManager.hpp | 1 + src/slic3r/GUI/RemovableDriveManagerMM.mm | 4 ++++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index fc25b4f295..8e450f4972 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -273,7 +273,7 @@ bool GUI_App::on_init_inner() 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, diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 49bf59e11f..284c224fbd 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -425,6 +425,10 @@ bool RemovableDriveManager::update(const long time, bool check) return false; // return value shouldnt matter if update didnt run } } + if(check) + { + m_rdmmm->log("update"); + } search_for_drives(); if(check)check_and_notify(); return !m_current_drives.empty(); @@ -466,6 +470,7 @@ void RemovableDriveManager::check_and_notify() //std::cout<<"drives count: "<log("drives count not same"); //std::cout<<" vs "<< m_current_drives.size(); if(m_callbacks.size() != 0 && m_drives_count > m_current_drives.size() && m_last_save_path != "" && !is_drive_mounted(m_last_save_path)) { diff --git a/src/slic3r/GUI/RemovableDriveManager.hpp b/src/slic3r/GUI/RemovableDriveManager.hpp index 49df414827..9eea355f79 100644 --- a/src/slic3r/GUI/RemovableDriveManager.hpp +++ b/src/slic3r/GUI/RemovableDriveManager.hpp @@ -80,6 +80,7 @@ public: ~RDMMMWrapper(); void register_window(); void list_devices(); + void log(const std::string &msg); protected: void *m_imp; //friend void RemovableDriveManager::inspect_file(const std::string &path, const std::string &parent_path); diff --git a/src/slic3r/GUI/RemovableDriveManagerMM.mm b/src/slic3r/GUI/RemovableDriveManagerMM.mm index 7a1108541a..45bd21bcfa 100644 --- a/src/slic3r/GUI/RemovableDriveManagerMM.mm +++ b/src/slic3r/GUI/RemovableDriveManagerMM.mm @@ -61,6 +61,10 @@ void RDMMMWrapper::list_devices() } } } +void RDMMMWrapper::log(const std::string &msg) +{ + NSLog(@"%s", msg.c_str()); +} }}//namespace Slicer::GUI /* From f057077826b7499a54f7b21ef198a370446b53ad Mon Sep 17 00:00:00 2001 From: David Kocik Date: Wed, 11 Dec 2019 17:02:12 +0100 Subject: [PATCH 41/50] eject button functionality --- src/slic3r/GUI/GUI_App.cpp | 2 +- src/slic3r/GUI/RemovableDriveManager.cpp | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index fc25b4f295..8e450f4972 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -273,7 +273,7 @@ bool GUI_App::on_init_inner() 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, diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 49bf59e11f..dc8469d9a2 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -96,14 +96,16 @@ void RemovableDriveManager::eject_drive(const std::string &path) return; } 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); - CloseHandle(handle); if (error == 0) { + CloseHandle(handle); std::cerr << "Ejecting " << mpath << " failed " << deviceControlRetVal << " " << GetLastError() << " \n"; return; } - + CloseHandle(handle); m_current_drives.erase(it); 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 ); break; - /* + case WM_DEVICECHANGE: { if(wParam == DBT_DEVICEREMOVECOMPLETE) @@ -207,7 +209,7 @@ INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lP } } break; - */ + default: // Send all other messages on to the default windows handler. lRet = DefWindowProc(hWnd, message, wParam, lParam); From a03ce255d6ad5b84b62f1bb9afa5b34e3e13617b Mon Sep 17 00:00:00 2001 From: Slic3rPE Date: Wed, 11 Dec 2019 17:39:34 +0100 Subject: [PATCH 42/50] macos eject --- src/slic3r/GUI/RemovableDriveManager.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index afe5ee7393..ab2dd10eb2 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -221,15 +221,17 @@ INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lP #else void RemovableDriveManager::search_for_drives() { - + + m_current_drives.clear(); + m_current_drives.reserve(26); + #if __APPLE__ if(m_rdmmm) { m_rdmmm->list_devices(); } #else - m_current_drives.clear(); - m_current_drives.reserve(26); + //search /media/* folder search_path("/media/*", "/media"); From e2048775f6bc1f729df39843d7683ad33f457c1b Mon Sep 17 00:00:00 2001 From: David Kocik Date: Wed, 11 Dec 2019 17:42:56 +0100 Subject: [PATCH 43/50] eject button functionality --- src/slic3r/GUI/Plater.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 0300670e48..a0e453abc3 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -4891,12 +4891,11 @@ void Plater::send_gcode() void Plater::eject_drive() { - if (GUI::RemovableDriveManager::get_instance().update(0, true)) - { - RemovableDriveManager::get_instance().erase_callbacks(); - RemovableDriveManager::get_instance().add_callback(std::bind(&Plater::drive_ejected_callback, this)); - RemovableDriveManager::get_instance().eject_drive(RemovableDriveManager::get_instance().get_last_save_path()); - } + RemovableDriveManager::get_instance().update(0, true); + RemovableDriveManager::get_instance().erase_callbacks(); + RemovableDriveManager::get_instance().add_callback(std::bind(&Plater::drive_ejected_callback, this)); + RemovableDriveManager::get_instance().eject_drive(RemovableDriveManager::get_instance().get_last_save_path()); + } void Plater::drive_ejected_callback() { From 59fa78373b1a0cd199bfac3ddc513235ca33e59f Mon Sep 17 00:00:00 2001 From: David Kocik Date: Wed, 11 Dec 2019 18:30:03 +0100 Subject: [PATCH 44/50] linux eject --- src/slic3r/GUI/GUI_App.cpp | 6 +++--- src/slic3r/GUI/RemovableDriveManager.cpp | 9 ++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 8e450f4972..258e338719 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -272,9 +272,9 @@ bool GUI_App::on_init_inner() this->obj_manipul()->update_if_dirty(); - - //RemovableDriveManager::get_instance().update(wxGetLocalTime(), true); - +#if __linux__ + RemovableDriveManager::get_instance().update(wxGetLocalTime(), true); +#endif // Preset updating & Configwizard are done after the above initializations, // and after MainFrame is created & shown. diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index ab2dd10eb2..d5f2244095 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -429,10 +429,6 @@ bool RemovableDriveManager::update(const long time, bool check) return false; // return value shouldnt matter if update didnt run } } - if(check) - { - m_rdmmm->log("update"); - } search_for_drives(); if(check)check_and_notify(); return !m_current_drives.empty(); @@ -474,7 +470,7 @@ void RemovableDriveManager::check_and_notify() //std::cout<<"drives count: "<log("drives count not same"); + //m_rdmmm->log("drives count not same"); //std::cout<<" vs "<< m_current_drives.size(); if(m_callbacks.size() != 0 && m_drives_count > m_current_drives.size() && m_last_save_path != "" && !is_drive_mounted(m_last_save_path)) { @@ -505,13 +501,16 @@ void RemovableDriveManager::set_last_save_path(const std::string& path) } bool RemovableDriveManager::is_last_drive_removed() { + std::cout<<"is last: "< Date: Thu, 12 Dec 2019 10:48:33 +0100 Subject: [PATCH 45/50] eject button after export --- src/slic3r/GUI/GUI_App.cpp | 2 +- src/slic3r/GUI/Plater.cpp | 9 +++++---- src/slic3r/GUI/RemovableDriveManager.cpp | 8 ++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 258e338719..bdaf8f8a79 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -272,7 +272,7 @@ bool GUI_App::on_init_inner() this->obj_manipul()->update_if_dirty(); -#if __linux__ +#if !__APPLE__ RemovableDriveManager::get_instance().update(wxGetLocalTime(), true); #endif diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index a0e453abc3..74a26c4002 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -4052,7 +4052,7 @@ void Plater::priv::show_action_buttons(const bool is_ready_to_slice) const if (sidebar->show_reslice(false) | sidebar->show_export(true) | sidebar->show_send(send_gcode_shown) | - sidebar->show_disconnect(disconnect_shown)) + sidebar->show_disconnect(false/*disconnect_shown*/)) sidebar->Layout(); } else @@ -4603,12 +4603,13 @@ void Plater::export_gcode() fs::path path = into_path(dlg.GetPath()); wxGetApp().app_config->update_last_output_dir(path.parent_path().string()); output_path = std::move(path); - RemovableDriveManager::get_instance().update(0, true); - RemovableDriveManager::get_instance().set_last_save_path(output_path.string()); - } if (! output_path.empty()) + { + RemovableDriveManager::get_instance().update(0, true); + RemovableDriveManager::get_instance().set_last_save_path(output_path.string()); p->export_gcode(std::move(output_path), PrintHostJob()); + } } diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index d5f2244095..7ab34204bc 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -410,7 +410,7 @@ void RemovableDriveManager::init() { //add_callback([](void) { RemovableDriveManager::get_instance().print(); }); #if _WIN32 - register_window(); + //register_window(); #elif __APPLE__ m_rdmmm->register_window(); #endif @@ -501,16 +501,16 @@ void RemovableDriveManager::set_last_save_path(const std::string& path) } bool RemovableDriveManager::is_last_drive_removed() { - std::cout<<"is last: "< Date: Thu, 12 Dec 2019 14:56:30 +0100 Subject: [PATCH 46/50] button show after write --- src/slic3r/GUI/Plater.cpp | 8 ++++-- src/slic3r/GUI/RemovableDriveManager.cpp | 35 +++--------------------- src/slic3r/GUI/RemovableDriveManager.hpp | 4 +-- 3 files changed, 10 insertions(+), 37 deletions(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 74a26c4002..3ecb174ce9 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -3171,6 +3171,7 @@ void Plater::priv::update_fff_scene() this->preview->reload_print(); // In case this was MM print, wipe tower bounding box on 3D tab might need redrawing with exact depth: view3D->reload_scene(true); + show_action_buttons(false); } void Plater::priv::update_sla_scene() @@ -4052,7 +4053,7 @@ void Plater::priv::show_action_buttons(const bool is_ready_to_slice) const if (sidebar->show_reslice(false) | sidebar->show_export(true) | sidebar->show_send(send_gcode_shown) | - sidebar->show_disconnect(false/*disconnect_shown*/)) + sidebar->show_disconnect(disconnect_shown)) sidebar->Layout(); } else @@ -4606,9 +4607,10 @@ void Plater::export_gcode() } if (! output_path.empty()) { - RemovableDriveManager::get_instance().update(0, true); - RemovableDriveManager::get_instance().set_last_save_path(output_path.string()); + std::string path = output_path.string(); p->export_gcode(std::move(output_path), PrintHostJob()); + RemovableDriveManager::get_instance().update(0, true); + RemovableDriveManager::get_instance().set_last_save_path(path); } } diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 7ab34204bc..cd360b580f 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -24,9 +24,6 @@ GUID WceusbshGUID = { 0x25dbce51, 0x6c8f, 0x4a72, namespace Slic3r { namespace GUI { -//std::vector RemovableDriveManager::m_current_drives; -//std::vector> RemovableDriveManager::m_callbacks; - #if _WIN32 INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); @@ -42,7 +39,6 @@ void RemovableDriveManager::search_for_drives() std::string path (1,(char)('A' + i)); path+=":"; UINT drive_type = GetDriveTypeA(path.c_str()); - //std::cout << "found drive" << (char)('A' + i) << ": type:" < 0) { path += "\\"; @@ -74,12 +69,9 @@ void RemovableDriveManager::search_for_drives() } } } - //std::cout << "found drives:" << m_current_drives.size() << "\n"; } void RemovableDriveManager::eject_drive(const std::string &path) { - - //if (!update() || !is_drive_mounted(path)) if(m_current_drives.empty()) return; for (auto it = m_current_drives.begin(); it != m_current_drives.end(); ++it) @@ -88,7 +80,6 @@ void RemovableDriveManager::eject_drive(const std::string &path) { std::string mpath = "\\\\.\\" + path; mpath = mpath.substr(0, mpath.size() - 1); - //std::cout << "Ejecting " << mpath << "\n"; HANDLE handle = CreateFileA(mpath.c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, 0, nullptr); if (handle == INVALID_HANDLE_VALUE) { @@ -138,7 +129,7 @@ std::string RemovableDriveManager::get_drive_from_path(const std::string& path) } void RemovableDriveManager::register_window() { - std::cout << "Registering for device notification\n"; + //creates new unvisible window that is recieving callbacks from system WNDCLASSEX wndClass; wndClass.cbSize = sizeof(WNDCLASSEX); wndClass.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; @@ -181,9 +172,6 @@ INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lP LRESULT lRet = 1; static HDEVNOTIFY hDeviceNotify; - static HWND hEditWnd; - static ULONGLONG msgCount = 0; - switch (message) { case WM_CREATE: @@ -194,11 +182,7 @@ INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lP NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; NotificationFilter.dbcc_classguid = WceusbshGUID; - hDeviceNotify = RegisterDeviceNotification( - hWnd, // events recipient - &NotificationFilter, // type of device - DEVICE_NOTIFY_WINDOW_HANDLE // type of recipient handle - ); + hDeviceNotify = RegisterDeviceNotification(hWnd, &NotificationFilter, DEVICE_NOTIFY_WINDOW_HANDLE); break; case WM_DEVICECHANGE: @@ -280,7 +264,6 @@ void RemovableDriveManager::search_for_drives() } - //std::cout << "found drives:" < RemovableDriveManager::get_all_drives() } void RemovableDriveManager::check_and_notify() { - //std::cout<<"drives count: "<log("drives count not same"); - //std::cout<<" vs "<< m_current_drives.size(); if(m_callbacks.size() != 0 && m_drives_count > m_current_drives.size() && m_last_save_path != "" && !is_drive_mounted(m_last_save_path)) { for (auto it = m_callbacks.begin(); it != m_callbacks.end(); ++it) @@ -481,7 +461,6 @@ void RemovableDriveManager::check_and_notify() } m_drives_count = m_current_drives.size(); } - //std::cout<<"\n"; } void RemovableDriveManager::add_callback(std::function callback) { @@ -522,10 +501,4 @@ void RemovableDriveManager::reset_last_save_path() { m_last_save_path = ""; } - -void RemovableDriveManager::print() -{ - //std::cout << "Removed Device: "<<(int)is_last_drive_removed()<<"\n"; - std::cout << "notified\n"; -} -}}//namespace Slicer::Gui:: +}}//namespace Slicer::Gui diff --git a/src/slic3r/GUI/RemovableDriveManager.hpp b/src/slic3r/GUI/RemovableDriveManager.hpp index 9eea355f79..b4fc71e265 100644 --- a/src/slic3r/GUI/RemovableDriveManager.hpp +++ b/src/slic3r/GUI/RemovableDriveManager.hpp @@ -32,7 +32,7 @@ public: //update() searches for removable devices, returns false if empty. void init(); - bool update(const long time = 0, bool check = false); //time = 0 is forced update, time expects wxGetLocalTime() + bool update(const long time = 0,const bool check = false); //time = 0 is forced update, time expects wxGetLocalTime() bool is_drive_mounted(const std::string &path); void eject_drive(const std::string &path); std::string get_last_save_path(); @@ -44,8 +44,6 @@ public: void set_last_save_path(const std::string &path); bool is_last_drive_removed(); bool is_last_drive_removed_with_update(const long time = 0); // param as update() - void print(); - private: RemovableDriveManager(); void search_for_drives(); From e1d9de3ca425cedaa239106dd67d0055751d2e30 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Thu, 12 Dec 2019 15:43:14 +0100 Subject: [PATCH 47/50] button show after write --- src/slic3r/GUI/Plater.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 3ecb174ce9..417afa0a96 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -3171,7 +3171,7 @@ void Plater::priv::update_fff_scene() this->preview->reload_print(); // In case this was MM print, wipe tower bounding box on 3D tab might need redrawing with exact depth: view3D->reload_scene(true); - show_action_buttons(false); + } void Plater::priv::update_sla_scene() @@ -3518,6 +3518,8 @@ void Plater::priv::on_process_completed(wxCommandEvent &evt) default: break; } + show_action_buttons(false); + if (canceled) { if (wxGetApp().get_mode() == comSimple) sidebar->set_btn_label(ActionButtonType::abReslice, "Slice now"); From ff58fa99f41f315e1f03ee330ea7b528e5c65f55 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Fri, 13 Dec 2019 11:52:08 +0100 Subject: [PATCH 48/50] comments --- src/slic3r/GUI/RemovableDriveManager.cpp | 24 ++++++++++++++++++---- src/slic3r/GUI/RemovableDriveManager.hpp | 26 ++++++++++++++++-------- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index cd360b580f..02681b7daf 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -30,7 +30,7 @@ INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lP void RemovableDriveManager::search_for_drives() { m_current_drives.clear(); - m_current_drives.reserve(26); + //get logical drives flags by letter in alphabetical order DWORD drives_mask = GetLogicalDrives(); for (size_t i = 0; i < 26; i++) { @@ -39,6 +39,7 @@ void RemovableDriveManager::search_for_drives() std::string path (1,(char)('A' + i)); path+=":"; UINT drive_type = GetDriveTypeA(path.c_str()); + // DRIVE_REMOVABLE on W are sd cards and usb thumbnails (not usb harddrives) if (drive_type == DRIVE_REMOVABLE) { // get name of drive @@ -51,10 +52,12 @@ void RemovableDriveManager::search_for_drives() BOOL error = GetVolumeInformationW(wpath.c_str(), &volume_name[0], sizeof(volume_name), NULL, NULL, NULL, &file_system_name[0], sizeof(file_system_name)); if(error != 0) { + /* if (volume_name == L"") { volume_name = L"REMOVABLE DRIVE"; } + */ if (file_system_name != L"") { ULARGE_INTEGER free_space; @@ -78,6 +81,7 @@ void RemovableDriveManager::eject_drive(const std::string &path) { if ((*it).path == path) { + // get handle to device std::string mpath = "\\\\.\\" + path; mpath = mpath.substr(0, mpath.size() - 1); HANDLE handle = CreateFileA(mpath.c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, 0, nullptr); @@ -87,8 +91,12 @@ void RemovableDriveManager::eject_drive(const std::string &path) return; } DWORD deviceControlRetVal(0); + //these 3 commands should eject device safely but they dont, the device does disappear from file explorer but the "device was safely remove" notification doesnt trigger. + //sd cards does trigger WM_DEVICECHANGE messege, usb drives dont + DeviceIoControl(handle, FSCTL_LOCK_VOLUME, nullptr, 0, nullptr, 0, &deviceControlRetVal, nullptr); DeviceIoControl(handle, FSCTL_DISMOUNT_VOLUME, nullptr, 0, nullptr, 0, &deviceControlRetVal, nullptr); + // some implemenatations also calls IOCTL_STORAGE_MEDIA_REMOVAL here but it returns error to me BOOL error = DeviceIoControl(handle, IOCTL_STORAGE_EJECT_MEDIA, nullptr, 0, nullptr, 0, &deviceControlRetVal, nullptr); if (error == 0) { @@ -130,11 +138,12 @@ std::string RemovableDriveManager::get_drive_from_path(const std::string& path) void RemovableDriveManager::register_window() { //creates new unvisible window that is recieving callbacks from system + // structure to register WNDCLASSEX wndClass; wndClass.cbSize = sizeof(WNDCLASSEX); wndClass.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; wndClass.hInstance = reinterpret_cast(GetModuleHandle(0)); - wndClass.lpfnWndProc = reinterpret_cast(WinProcCallback); + wndClass.lpfnWndProc = reinterpret_cast(WinProcCallback);//this is callback wndClass.cbClsExtra = 0; wndClass.cbWndExtra = 0; wndClass.hIcon = LoadIcon(0, IDI_APPLICATION); @@ -169,6 +178,9 @@ void RemovableDriveManager::register_window() INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { + // here we need to catch messeges about device removal + // problem is that when ejecting usb (how is it implemented above) there is no messege dispached. Only after physical removal of the device. + //uncomment register_window() in init() to register and comment update() in GUI_App.cpp (only for windows!) to stop recieving periodical updates LRESULT lRet = 1; static HDEVNOTIFY hDeviceNotify; @@ -187,6 +199,7 @@ INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lP case WM_DEVICECHANGE: { + // here is the important if(wParam == DBT_DEVICEREMOVECOMPLETE) { - RemovableDriveManager::get_instance().update(0, true); @@ -207,9 +220,9 @@ void RemovableDriveManager::search_for_drives() { m_current_drives.clear(); - m_current_drives.reserve(26); #if __APPLE__ + // if on macos obj-c class will enumerate if(m_rdmmm) { m_rdmmm->list_devices(); @@ -287,6 +300,8 @@ void RemovableDriveManager::search_path(const std::string &path,const std::strin } void RemovableDriveManager::inspect_file(const std::string &path, const std::string &parent_path) { + //confirms if the file is removable drive and adds it to vector + //if not same file system - could be removable drive if(!compare_filesystem_id(path, parent_path)) { @@ -335,7 +350,8 @@ void RemovableDriveManager::eject_drive(const std::string &path) } } std::cout<<"Ejecting "<<(*it).name<<" from "<< correct_path<<"\n"; - +// there is no usable command in c++ so terminal command is used instead +// but neither triggers "succesful safe removal messege" std::string command = ""; #if __APPLE__ command = "diskutil unmount "; diff --git a/src/slic3r/GUI/RemovableDriveManager.hpp b/src/slic3r/GUI/RemovableDriveManager.hpp index b4fc71e265..ac1645df7b 100644 --- a/src/slic3r/GUI/RemovableDriveManager.hpp +++ b/src/slic3r/GUI/RemovableDriveManager.hpp @@ -29,26 +29,34 @@ public: } RemovableDriveManager(RemovableDriveManager const&) = delete; void operator=(RemovableDriveManager const&) = delete; - - //update() searches for removable devices, returns false if empty. + //call only once. on apple register for unmnount callbacks. on windows register for device notification is prepared but not called (eject usb drive on widnows doesnt trigger the callback, sdc ard does), also enumerates devices for first time so init shoud be called on linux too. void init(); - bool update(const long time = 0,const bool check = false); //time = 0 is forced update, time expects wxGetLocalTime() + //update() searches for removable devices, returns false if empty. /time = 0 is forced update, time expects wxGetLocalTime() + bool update(const long time = 0,const bool check = false); bool is_drive_mounted(const std::string &path); void eject_drive(const std::string &path); + //returns path to last drive which was used, if none was used, returns device that was enumerated last std::string get_last_save_path(); + //returns path to last drive which was used, if none was used, returns empty string std::string get_drive_path(); std::vector get_all_drives(); bool is_path_on_removable_drive(const std::string &path); - void add_callback(std::function callback); // callback will notify only if device with last save path was removed - void erase_callbacks(); // erases all callbacks added by add_callback() + // callback will notify only if device with last save path was removed + void add_callback(std::function callback); + // erases all callbacks added by add_callback() + void erase_callbacks(); + // marks one of the eveices in vector as last used void set_last_save_path(const std::string &path); bool is_last_drive_removed(); - bool is_last_drive_removed_with_update(const long time = 0); // param as update() + // param as update() + bool is_last_drive_removed_with_update(const long time = 0); private: RemovableDriveManager(); void search_for_drives(); + //triggers callbacks if last used drive was removed void check_and_notify(); - std::string get_drive_from_path(const std::string& path);//returns drive path (same as path in DriveData) if exists otherwise empty string "" + //returns drive path (same as path in DriveData) if exists otherwise empty string "" + std::string get_drive_from_path(const std::string& path); void reset_last_save_path(); std::vector m_current_drives; @@ -58,8 +66,8 @@ private: std::string m_last_save_path; #if _WIN32 + //registers for notifications by creating invisible window void register_window(); - //INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); #else #if __APPLE__ RDMMMWrapper * m_rdmmm; @@ -69,7 +77,7 @@ private: void inspect_file(const std::string &path, const std::string &parent_path); #endif }; - +// apple wrapper for RemovableDriveManagerMM which searches for drives and/or ejects them #if __APPLE__ class RDMMMWrapper { From 8895e944cf2deca3b894415ba05fe281af4a7456 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Fri, 13 Dec 2019 13:04:09 +0100 Subject: [PATCH 49/50] comments --- src/slic3r/GUI/Plater.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 417afa0a96..0dc09d9d81 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -3517,7 +3517,7 @@ void Plater::priv::on_process_completed(wxCommandEvent &evt) break; default: break; } - + //added to show disconnect_button after writing show_action_buttons(false); if (canceled) { From e5fcb587e2bbff1313da989924792c44cd4f4a92 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Fri, 13 Dec 2019 13:23:55 +0100 Subject: [PATCH 50/50] Implemented rescaling for "Remove device" button --- src/slic3r/GUI/Plater.cpp | 58 ++++++++++++++++++--------------- src/slic3r/GUI/wxExtensions.cpp | 8 +++-- src/slic3r/GUI/wxExtensions.hpp | 7 ++++ 3 files changed, 44 insertions(+), 29 deletions(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 417afa0a96..814bcde0cf 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -699,8 +699,8 @@ struct Sidebar::priv wxButton *btn_export_gcode; wxButton *btn_reslice; - wxButton *btn_send_gcode; - ScalableButton *btn_disconnect; + ScalableButton *btn_send_gcode; + ScalableButton *btn_remove_device; priv(Plater *plater) : plater(plater) {} ~priv(); @@ -849,25 +849,30 @@ Sidebar::Sidebar(Plater *parent) // Buttons underneath the scrolled area - auto init_btn = [this](wxButton **btn, wxString label, const std::string icon_name = "", wxString tooltip = wxEmptyString) { - *btn = new wxButton(this, wxID_ANY, label, wxDefaultPosition, - wxDefaultSize, wxBU_EXACTFIT); - (*btn)->SetFont(wxGetApp().bold_font()); - (*btn)->SetToolTip(tooltip); + // rescalable bitmap buttons "Send to printer" and "Remove device" - if (!icon_name.empty()) - (*btn)->SetBitmap(create_scaled_bitmap(this, icon_name)); + auto init_scalable_btn = [this](ScalableButton** btn, const std::string& icon_name, wxString tooltip = wxEmptyString) + { + ScalableBitmap bmp = ScalableBitmap(this, icon_name, int(2.5 * wxGetApp().em_unit())); + *btn = new ScalableButton(this, wxID_ANY, bmp, "", wxBU_EXACTFIT); + (*btn)->SetToolTip(tooltip); + (*btn)->Hide(); }; - init_btn(&p->btn_send_gcode, /*_(L("Send to printer"))*/"", "export_gcode", _(L("Send to printer"))); - p->btn_send_gcode->Hide(); - init_btn(&p->btn_export_gcode, _(L("Export G-code")) + dots); - init_btn(&p->btn_reslice, _(L("Slice now"))); + init_scalable_btn(&p->btn_send_gcode , "export_gcode", _(L("Send to printer"))); + init_scalable_btn(&p->btn_remove_device, "revert_all_" , _(L("Remove device"))); - p->btn_disconnect = new ScalableButton(this, wxID_ANY, "revert_all_", "", - wxDefaultSize, wxDefaultPosition, wxBU_EXACTFIT); - p->btn_disconnect->Hide(); - p->btn_disconnect->SetToolTip(_(L("Remove device"))); + // regular buttons "Slice now" and "Export G-code" + + const int scaled_height = p->btn_remove_device->GetBitmap().GetHeight() + 4; + auto init_btn = [this](wxButton **btn, wxString label, const int button_height) { + *btn = new wxButton(this, wxID_ANY, label, wxDefaultPosition, + wxSize(-1, button_height), wxBU_EXACTFIT); + (*btn)->SetFont(wxGetApp().bold_font()); + }; + + init_btn(&p->btn_export_gcode, _(L("Export G-code")) + dots , scaled_height); + init_btn(&p->btn_reslice , _(L("Slice now")) , scaled_height); enable_buttons(false); @@ -876,12 +881,10 @@ Sidebar::Sidebar(Plater *parent) auto* complect_btns_sizer = new wxBoxSizer(wxHORIZONTAL); complect_btns_sizer->Add(p->btn_export_gcode, 1, wxEXPAND); complect_btns_sizer->Add(p->btn_send_gcode, 0, wxEXPAND); - complect_btns_sizer->Add(p->btn_disconnect); + complect_btns_sizer->Add(p->btn_remove_device); btns_sizer->Add(p->btn_reslice, 0, wxEXPAND | wxTOP, margin_5); btns_sizer->Add(complect_btns_sizer, 0, wxEXPAND | wxTOP, margin_5); -// btns_sizer->Add(p->btn_send_gcode, 0, wxEXPAND | wxTOP, margin_5); -// btns_sizer->Add(p->btn_export_gcode, 0, wxEXPAND | wxTOP, margin_5); auto *sizer = new wxBoxSizer(wxVERTICAL); sizer->Add(p->scrolled, 1, wxEXPAND); @@ -900,10 +903,7 @@ Sidebar::Sidebar(Plater *parent) p->plater->select_view_3D("Preview"); }); p->btn_send_gcode->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { p->plater->send_gcode(); }); - p->btn_disconnect->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { - // #dk_FIXME - p->plater->eject_drive(); - }); + p->btn_remove_device->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { p->plater->eject_drive(); }); } Sidebar::~Sidebar() {} @@ -1049,6 +1049,12 @@ void Sidebar::msw_rescale() p->object_info->msw_rescale(); + p->btn_send_gcode->msw_rescale(); + p->btn_remove_device->msw_rescale(); + const int scaled_height = p->btn_remove_device->GetBitmap().GetHeight() + 4; + p->btn_export_gcode->SetMinSize(wxSize(-1, scaled_height)); + p->btn_reslice ->SetMinSize(wxSize(-1, scaled_height)); + p->scrolled->Layout(); } @@ -1277,13 +1283,13 @@ void Sidebar::enable_buttons(bool enable) p->btn_reslice->Enable(enable); p->btn_export_gcode->Enable(enable); p->btn_send_gcode->Enable(enable); - p->btn_disconnect->Enable(enable); + p->btn_remove_device->Enable(enable); } bool Sidebar::show_reslice(bool show) const { return p->btn_reslice->Show(show); } bool Sidebar::show_export(bool show) const { return p->btn_export_gcode->Show(show); } bool Sidebar::show_send(bool show) const { return p->btn_send_gcode->Show(show); } -bool Sidebar::show_disconnect(bool show)const { return p->btn_disconnect->Show(show); } +bool Sidebar::show_disconnect(bool show)const { return p->btn_remove_device->Show(show); } bool Sidebar::is_multifilament() { diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index 8493138971..735e704ee8 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -3935,8 +3935,10 @@ ScalableButton::ScalableButton( wxWindow * parent, const ScalableBitmap& bitmap, const wxString& label /*= wxEmptyString*/, long style /*= wxBU_EXACTFIT | wxNO_BORDER*/) : + m_parent(parent), m_current_icon_name(bitmap.name()), - m_parent(parent) + m_px_cnt(bitmap.px_cnt()), + m_is_horizontal(bitmap.is_horizontal()) { Create(parent, id, label, wxDefaultPosition, wxDefaultSize, style); #ifdef __WXMSW__ @@ -3961,9 +3963,9 @@ void ScalableButton::SetBitmapDisabled_(const ScalableBitmap& bmp) void ScalableButton::msw_rescale() { - SetBitmap(create_scaled_bitmap(m_parent, m_current_icon_name)); + SetBitmap(create_scaled_bitmap(m_parent, m_current_icon_name, m_px_cnt, m_is_horizontal)); if (!m_disabled_icon_name.empty()) - SetBitmapDisabled(create_scaled_bitmap(m_parent, m_disabled_icon_name)); + SetBitmapDisabled(create_scaled_bitmap(m_parent, m_disabled_icon_name, m_px_cnt, m_is_horizontal)); if (m_width > 0 || m_height>0) { diff --git a/src/slic3r/GUI/wxExtensions.hpp b/src/slic3r/GUI/wxExtensions.hpp index 7841b62fee..951f7ea8f4 100644 --- a/src/slic3r/GUI/wxExtensions.hpp +++ b/src/slic3r/GUI/wxExtensions.hpp @@ -729,6 +729,9 @@ public: wxBitmap& bmp() { return m_bmp; } const std::string& name() const{ return m_icon_name; } + int px_cnt()const {return m_px_cnt;} + bool is_horizontal()const {return m_is_horizontal;} + private: wxWindow* m_parent{ nullptr }; wxBitmap m_bmp = wxBitmap(); @@ -1116,6 +1119,10 @@ private: std::string m_disabled_icon_name = ""; int m_width {-1}; // should be multiplied to em_unit int m_height{-1}; // should be multiplied to em_unit + + // bitmap dimensions + int m_px_cnt{ 16 }; + bool m_is_horizontal{ false }; };