PrusaSlicer-NonPlainar/src/slic3r/GUI/RemovableDriveManager.hpp

91 lines
2.6 KiB
C++
Raw Normal View History

2019-11-26 13:19:29 +00:00
#ifndef slic3r_GUI_RemovableDriveManager_hpp_
#define slic3r_GUI_RemovableDriveManager_hpp_
#include <vector>
#include <string>
namespace Slic3r {
namespace GUI {
2019-12-11 09:16:32 +00:00
#if __APPLE__
2019-12-11 10:00:47 +00:00
class RDMMMWrapper;
#endif
2019-12-11 09:16:32 +00:00
2019-11-26 13:19:29 +00:00
struct DriveData
{
2019-11-26 14:52:18 +00:00
std::string name;
2019-11-26 13:19:29 +00:00
std::string path;
2019-11-26 14:52:18 +00:00
DriveData(std::string n, std::string p):name(n),path(p){}
2019-11-26 13:19:29 +00:00
};
class RemovableDriveManager
{
2019-12-11 10:00:47 +00:00
#if __APPLE__
friend class RDMMMWrapper;
#endif
2019-11-26 13:19:29 +00:00
public:
2019-11-28 12:50:58 +00:00
static RemovableDriveManager& get_instance()
2019-11-26 13:19:29 +00:00
{
static RemovableDriveManager instance;
return instance;
}
RemovableDriveManager(RemovableDriveManager const&) = delete;
void operator=(RemovableDriveManager const&) = delete;
//update() searches for removable devices, returns false if empty.
void init();
2019-12-11 13:53:28 +00:00
bool update(const long time = 0, bool check = false); //time = 0 is forced update, time expects wxGetLocalTime()
2019-11-28 12:50:58 +00:00
bool is_drive_mounted(const std::string &path);
void eject_drive(const std::string &path);
2019-12-11 13:53:28 +00:00
std::string get_last_save_path();
std::string get_drive_path();
2019-11-28 12:50:58 +00:00
std::vector<DriveData> get_all_drives();
bool is_path_on_removable_drive(const std::string &path);
2019-12-06 12:17:36 +00:00
void add_callback(std::function<void()> callback); // callback will notify only if device with last save path was removed
2019-12-06 12:21:44 +00:00
void erase_callbacks(); // erases all callbacks added by add_callback()
2019-12-05 13:07:02 +00:00
void set_last_save_path(const std::string &path);
2019-12-11 11:28:51 +00:00
bool is_last_drive_removed();
2019-12-05 15:22:54 +00:00
bool is_last_drive_removed_with_update(const long time = 0); // param as update()
2019-11-28 12:50:58 +00:00
void print();
2019-12-11 10:00:47 +00:00
2019-11-26 13:19:29 +00:00
private:
2019-12-11 10:00:47 +00:00
RemovableDriveManager();
2019-11-28 12:50:58 +00:00
void search_for_drives();
void check_and_notify();
2019-12-05 13:07:02 +00:00
std::string get_drive_from_path(const std::string& path);//returns drive path (same as path in DriveData) if exists otherwise empty string ""
2019-12-11 11:28:51 +00:00
void reset_last_save_path();
2019-11-28 12:50:58 +00:00
std::vector<DriveData> m_current_drives;
std::vector<std::function<void()>> m_callbacks;
2019-12-03 09:09:53 +00:00
size_t m_drives_count;
2019-12-04 14:27:33 +00:00
long m_last_update;
2019-12-05 13:07:02 +00:00
std::string m_last_save_path;
2019-12-11 11:28:51 +00:00
2019-11-26 14:52:18 +00:00
#if _WIN32
2019-11-28 12:50:58 +00:00
void register_window();
2019-12-05 13:07:02 +00:00
//INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
2019-12-10 13:10:47 +00:00
#else
#if __APPLE__
2019-12-11 09:16:32 +00:00
RDMMMWrapper * m_rdmmm;
2019-12-10 13:10:47 +00:00
#endif
2019-12-10 10:17:12 +00:00
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);
2019-12-11 10:00:47 +00:00
void inspect_file(const std::string &path, const std::string &parent_path);
2019-11-26 14:52:18 +00:00
#endif
2019-11-26 13:19:29 +00:00
};
2019-12-11 10:00:47 +00:00
#if __APPLE__
class RDMMMWrapper
{
public:
RDMMMWrapper();
~RDMMMWrapper();
void register_window();
void list_devices();
2019-12-11 15:59:26 +00:00
void log(const std::string &msg);
2019-12-11 10:00:47 +00:00
protected:
void *m_imp;
//friend void RemovableDriveManager::inspect_file(const std::string &path, const std::string &parent_path);
};
2019-12-10 13:10:47 +00:00
#endif
2019-11-26 13:19:29 +00:00
}}
2019-12-10 10:17:12 +00:00
#endif