Files
OrcaSlicer-bambulab/src/slic3r/GUI/RemovableDriveManager.hpp
T

87 lines
2.6 KiB
C++
Raw Normal View History

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