Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/supermerill/SuperSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Kocik <kocikdav@gmail.com>2020-03-10 10:28:27 +0300
committerDavid Kocik <kocikdav@gmail.com>2020-03-10 10:29:11 +0300
commite6035542fa032b95d5b8532f1577b4a130f6ea92 (patch)
tree4fe464f5a0f396ca828f36dd7f934c9d562eff01 /src/slic3r/GUI
parent0836df93e1f1692544fcdc8a89677f321c57f66a (diff)
ejecting sd card/flash drives with boost::process::child on mac/linux
Diffstat (limited to 'src/slic3r/GUI')
-rw-r--r--src/slic3r/GUI/RemovableDriveManager.cpp30
1 files changed, 21 insertions, 9 deletions
diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp
index 1580c5025..f76625049 100644
--- a/src/slic3r/GUI/RemovableDriveManager.cpp
+++ b/src/slic3r/GUI/RemovableDriveManager.cpp
@@ -21,6 +21,7 @@
#include <pwd.h>
#include <boost/filesystem.hpp>
#include <boost/filesystem/convenience.hpp>
+#include <boost/process.hpp>
#endif
namespace Slic3r {
@@ -329,29 +330,40 @@ void RemovableDriveManager::eject_drive()
auto it_drive_data = this->find_last_save_path_drive_data();
if (it_drive_data != m_current_drives.end()) {
std::string correct_path(m_last_save_path);
- for (size_t i = 0; i < correct_path.size(); ++i)
+#ifndef __APPLE__
+ for (size_t i = 0; i < correct_path.size(); ++i)
if (correct_path[i]==' ') {
correct_path = correct_path.insert(i,1,'\\');
++ i;
}
+#endif
//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 =
+ BOOST_LOG_TRIVIAL(info) << "Ejecting started";
+ boost::process::ipstream istd_err;
+ boost::process::child child(
#if __APPLE__
- "diskutil unmount ";
+ boost::process::search_path("diskutil"), "eject", correct_path.c_str(), (boost::process::std_out & boost::process::std_err) > istd_err);
//Another option how to eject at mac. Currently not working.
//used insted of system() command;
//this->eject_device(correct_path);
#else
- "umount ";
+ boost::process::search_path("umount"), correct_path.c_str(), (boost::process::std_out & boost::process::std_err) > istd_err);
#endif
- command += correct_path;
- int err = system(command.c_str());
- if (err) {
- BOOST_LOG_TRIVIAL(error) << "Ejecting " << m_last_save_path << " failed";
- return;
+ std::string line;
+ while (child.running() && std::getline(istd_err, line)) {
+ BOOST_LOG_TRIVIAL(trace) << line;
}
+ // wait for command to finnish (blocks ui thread)
+ child.wait();
+ int err = child.exit_code();
+ if(err)
+ {
+ BOOST_LOG_TRIVIAL(error) << "Ejecting failed";
+ return;
+ }
+ BOOST_LOG_TRIVIAL(info) << "Ejecting finished";
assert(m_callback_evt_handler);
if (m_callback_evt_handler)