From 1ec7fc23e24b7d981b513d52a039201f2cac506f Mon Sep 17 00:00:00 2001 From: David Kocik Date: Wed, 27 Nov 2019 13:30:45 +0100 Subject: [PATCH] check if last path is on rem drive --- src/slic3r/GUI/AppConfig.cpp | 5 +- src/slic3r/GUI/Plater.cpp | 8 + src/slic3r/GUI/RemovableDriveManager.cpp | 230 ----------------------- src/slic3r/GUI/RemovableDriveManager.hpp | 1 + 4 files changed, 13 insertions(+), 231 deletions(-) diff --git a/src/slic3r/GUI/AppConfig.cpp b/src/slic3r/GUI/AppConfig.cpp index 9f294a3b6..e27fa1be6 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 { @@ -359,6 +358,7 @@ void AppConfig::update_skein_dir(const std::string &dir) std::string AppConfig::get_last_output_dir(const std::string &alt) const { <<<<<<< HEAD +<<<<<<< HEAD ======= if (GUI::RemovableDriveManager::getInstance().update()) @@ -366,6 +366,9 @@ std::string AppConfig::get_last_output_dir(const std::string &alt) const return GUI::RemovableDriveManager::getInstance().get_last_drive_path(); } >>>>>>> removable drive manager - Windows part +======= + +>>>>>>> check if last path is on rem drive 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 52255d176..aff162401 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -4693,11 +4693,19 @@ 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()); +<<<<<<< HEAD if (GUI::RemovableDriveManager::get_instance().update()) { if (!RemovableDriveManager::get_instance().is_path_on_removable_drive(start_dir)) { start_dir = RemovableDriveManager::get_instance().get_drive_path(); +======= + if (GUI::RemovableDriveManager::getInstance().update()) + { + if (!RemovableDriveManager::getInstance().is_path_on_removable_drive(start_dir)) + { + start_dir = RemovableDriveManager::getInstance().get_last_drive_path(); +>>>>>>> check if last path is on rem drive } } 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 30f6c9b29..02681b7da 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -1,6 +1,4 @@ #include "RemovableDriveManager.hpp" -<<<<<<< HEAD -<<<<<<< HEAD #include #include "boost/nowide/convert.hpp" @@ -68,84 +66,10 @@ void RemovableDriveManager::search_for_drives() { path += "\\"; m_current_drives.push_back(DriveData(boost::nowide::narrow(volume_name), path)); -======= - - - -======= ->>>>>>> refactoring -#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 -//linux includes -#include -#include -#include -#include -#include -#endif - -namespace Slic3r { -namespace GUI { - -std::vector RemovableDriveManager::m_current_drives; - -#if _WIN32 -void RemovableDriveManager::search_for_drives() -{ - m_current_drives.clear(); - m_current_drives.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) - { -<<<<<<< HEAD - newDrives.push_back(DriveData(volumeName, path)); ->>>>>>> removable drive manager - Windows part -======= - m_current_drives.push_back(DriveData(boost::nowide::narrow(volumeName), path)); ->>>>>>> refactoring } } } } -<<<<<<< HEAD } } } @@ -594,157 +518,3 @@ void RemovableDriveManager::reset_last_save_path() m_last_save_path = ""; } }}//namespace Slicer::Gui -======= - else if(driveType == 3)//disks and usb drives - { - } - } - } - -} -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) - { - if ((*it).path == path) - { - 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::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: " < RemovableDriveManager::get_all_drives() -{ - return m_current_drives; -} -}} ->>>>>>> removable drive manager - Windows part diff --git a/src/slic3r/GUI/RemovableDriveManager.hpp b/src/slic3r/GUI/RemovableDriveManager.hpp index c00164446..1e5d240f0 100644 --- a/src/slic3r/GUI/RemovableDriveManager.hpp +++ b/src/slic3r/GUI/RemovableDriveManager.hpp @@ -116,6 +116,7 @@ protected: 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();