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

64 lines
2.2 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 {
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
{
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-05 15:22:54 +00:00
bool update(const long time = 0); //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);
std::string get_last_drive_path();
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);
bool is_last_drive_removed(); //if we dont need info about this drive, call reset_last_save_path();
2019-12-05 15:22:54 +00:00
bool is_last_drive_removed_with_update(const long time = 0); // param as update()
2019-12-05 13:07:02 +00:00
void reset_last_save_path();
2019-11-28 12:50:58 +00:00
void print();
2019-11-26 13:19:29 +00:00
private:
2019-12-05 13:07:02 +00:00
RemovableDriveManager():m_drives_count(0),m_last_update(0),m_last_save_path(""){}
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-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-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);
#elif __APPLE__
2019-12-10 09:08:57 +00:00
void *m_rdmmm;
void register_window();
2019-12-10 09:08:57 +00:00
//void list_devices();
2019-11-26 14:52:18 +00:00
#else
2019-11-28 15:35:22 +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-11-26 14:52:18 +00:00
#endif
2019-11-26 13:19:29 +00:00
};
}}
#endif