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-11-26 13:19:29 +00:00
< < < < < < < HEAD
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
= = = = = = =
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 :
static RemovableDriveManager & getInstance ( )
> > > > > > > removable drive manager - Windows part
2019-11-26 13:19:29 +00:00
{
static RemovableDriveManager instance ;
return instance ;
}
RemovableDriveManager ( RemovableDriveManager const & ) = delete ;
void operator = ( RemovableDriveManager const & ) = delete ;
2019-11-26 13:19:29 +00:00
< < < < < < < HEAD
2019-12-13 10:52:08 +00:00
//call only once. on apple register for unmnount callbacks. on windows register for device notification is prepared but not called (eject usb drive on widnows doesnt trigger the callback, sdc ard does), also enumerates devices for first time so init shoud be called on linux too.
2019-12-06 15:51:04 +00:00
void init ( ) ;
2019-12-13 10:52:08 +00:00
//update() searches for removable devices, returns false if empty. /time = 0 is forced update, time expects wxGetLocalTime()
bool update ( const long time = 0 , const bool check = false ) ;
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-13 10:52:08 +00:00
//returns path to last drive which was used, if none was used, returns device that was enumerated last
2019-12-11 13:53:28 +00:00
std : : string get_last_save_path ( ) ;
2019-12-13 10:52:08 +00:00
//returns path to last drive which was used, if none was used, returns empty string
2019-12-11 13:53:28 +00:00
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-13 10:52:08 +00:00
// callback will notify only if device with last save path was removed
void add_callback ( std : : function < void ( ) > callback ) ;
// erases all callbacks added by add_callback()
void erase_callbacks ( ) ;
// marks one of the eveices in vector as last used
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-13 10:52:08 +00:00
// param as update()
bool is_last_drive_removed_with_update ( const long time = 0 ) ;
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 ( ) ;
2019-12-13 10:52:08 +00:00
//triggers callbacks if last used drive was removed
2019-11-28 12:50:58 +00:00
void check_and_notify ( ) ;
2019-12-13 10:52:08 +00:00
//returns drive path (same as path in DriveData) if exists otherwise empty string ""
std : : string get_drive_from_path ( const std : : string & path ) ;
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-12-13 10:52:08 +00:00
//registers for notifications by creating invisible window
2019-11-28 12:50:58 +00:00
void register_window ( ) ;
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-13 10:52:08 +00:00
// apple wrapper for RemovableDriveManagerMM which searches for drives and/or ejects them
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
2019-11-26 13:19:29 +00:00
= = = = = = =
//update() searches for removable devices, returns false if empty.
static bool update ( ) ;
2019-11-27 10:33:36 +00:00
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 ( ) ;
2019-11-27 12:30:45 +00:00
static bool is_path_on_removable_drive ( const std : : string & path ) ;
2019-11-26 13:19:29 +00:00
private :
RemovableDriveManager ( ) { }
2019-11-27 10:33:36 +00:00
static void search_for_drives ( ) ;
static std : : vector < DriveData > m_current_drives ;
2019-11-26 14:52:18 +00:00
# if _WIN32
# else
2019-11-27 10:33:36 +00:00
static void search_path ( const std : : string & path , const dev_t & parentDevID ) ;
2019-11-26 14:52:18 +00:00
# endif
2019-11-26 13:19:29 +00:00
} ;
} }
# endif
> > > > > > > removable drive manager - Windows part