From 97a9f245f96617dfd1fb74c1262911abf1b68108 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 | 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 320f33751..16f045966 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 789271581..bbfa9d932 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 53515ccdc..776334bf2 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 8270c0f0f..3de9d72ce 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();