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:
-rw-r--r--src/slic3r/GUI/AppConfig.cpp2
-rw-r--r--src/slic3r/GUI/RemovableDriveManager.cpp118
-rw-r--r--src/slic3r/GUI/RemovableDriveManager.hpp15
3 files changed, 64 insertions, 71 deletions
diff --git a/src/slic3r/GUI/AppConfig.cpp b/src/slic3r/GUI/AppConfig.cpp
index f24bde242..9f294a3b6 100644
--- a/src/slic3r/GUI/AppConfig.cpp
+++ b/src/slic3r/GUI/AppConfig.cpp
@@ -363,7 +363,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();
}
>>>>>>> removable drive manager - Windows part
const auto it = m_storage.find("");
diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp
index e61332045..30f6c9b29 100644
--- a/src/slic3r/GUI/RemovableDriveManager.cpp
+++ b/src/slic3r/GUI/RemovableDriveManager.cpp
@@ -1,5 +1,6 @@
#include "RemovableDriveManager.hpp"
<<<<<<< HEAD
+<<<<<<< HEAD
#include <iostream>
#include "boost/nowide/convert.hpp"
@@ -71,13 +72,16 @@ void RemovableDriveManager::search_for_drives()
+=======
+>>>>>>> refactoring
#include <iostream>
#include <stdio.h>
-
+#include "boost/nowide/convert.hpp"
#if _WIN32
#include <windows.h>
#include <tchar.h>
+#include <winioctl.h>
DEFINE_GUID(GUID_DEVINTERFACE_USB_DEVICE,
0xA5DCBF10L, 0x6530, 0x11D2, 0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED);
#else
@@ -92,16 +96,13 @@ DEFINE_GUID(GUID_DEVINTERFACE_USB_DEVICE,
namespace Slic3r {
namespace GUI {
-std::vector<DriveData> RemovableDriveManager::currentDrives;
-
-
-
+std::vector<DriveData> RemovableDriveManager::m_current_drives;
#if _WIN32
-void RemovableDriveManager::searchForDrives(std::vector<DriveData>& 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++)
{
@@ -134,8 +135,12 @@ void RemovableDriveManager::searchForDrives(std::vector<DriveData>& newDrives)
//std::cout << std::string(volumeName.begin(), volumeName.end()) << " " << std::string(fileSystemName.begin(), fileSystemName.end()) << " " << freeSpace.QuadPart << "\n";
if (freeSpace.QuadPart > 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
}
}
}
@@ -597,49 +602,51 @@ void RemovableDriveManager::reset_last_save_path()
}
}
-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<DriveData>& 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: " <<buf.st_dev << "\n";
- searchPath(newDrives, "/media/*", buf.st_dev);
+ search_path("/media/*", buf.st_dev);
//search /media/USERNAME/* folder
pp = "/media/"+pp;
@@ -647,18 +654,18 @@ void RemovableDriveManager::searchForDrives(std::vector<DriveData>& newDrives)
stat(pp.c_str() ,&buf);
std::cout << pp <<" ID: " <<buf.st_dev << "\n";
- searchPath(newDrives, path, buf.st_dev);
+ searchPath(path, buf.st_dev);
//search /run/media/USERNAME/* folder
path = "/run" + path;
pp = "/run"+pp;
stat(pp.c_str() ,&buf);
std::cout << pp <<" ID: " <<buf.st_dev << "\n";
- searchPath(newDrives, path, buf.st_dev);
+ searchPath(path, buf.st_dev);
std::cout << "found drives:" <<newDrives.size() << "\n";
}
-void RemovableDriveManager::searchPath(std::vector<DriveData>& 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;
@@ -679,17 +686,17 @@ void RemovableDriveManager::searchPath(std::vector<DriveData>& 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)
{
@@ -700,7 +707,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;
}
@@ -710,22 +717,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<DriveData>& 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)
+
+bool RemovableDriveManager::is_drive_mounted(const 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)
{
@@ -735,22 +734,17 @@ 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<DriveData>& drives)
+std::vector<DriveData> 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;
}
}}
>>>>>>> removable drive manager - Windows part
diff --git a/src/slic3r/GUI/RemovableDriveManager.hpp b/src/slic3r/GUI/RemovableDriveManager.hpp
index 157f670b3..c00164446 100644
--- a/src/slic3r/GUI/RemovableDriveManager.hpp
+++ b/src/slic3r/GUI/RemovableDriveManager.hpp
@@ -112,18 +112,17 @@ protected:
//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<DriveData>& 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<DriveData> get_all_drives();
private:
RemovableDriveManager(){}
- static void searchForDrives(std::vector<DriveData>& newDrives);
- static void updateCurrentDrives(const std::vector<DriveData>& newDrives);
- static std::vector<DriveData> currentDrives;
+ static void search_for_drives();
+ static std::vector<DriveData> m_current_drives;
#if _WIN32
#else
- static void searchPath(std::vector<DriveData>& newDrives,const std::string path, const dev_t parentDevID);
+ static void search_path(const std::string &path, const dev_t &parentDevID);
#endif
};
}}