Changeset 85371 in vbox for trunk/include/VBox
- Timestamp:
- Jul 17, 2020 10:02:58 AM (5 years ago)
- Location:
- trunk/include/VBox
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/GuestHost/DragAndDrop.h
r85028 r85371 33 33 #include <iprt/assert.h> 34 34 #include <iprt/fs.h> 35 36 #include <iprt/cpp/list.h> 37 #include <iprt/cpp/ministring.h> 35 #include <iprt/list.h> 38 36 39 37 /** DnDURIDroppedFiles flags. */ … … 44 42 45 43 /** 46 * Class for maintaining a "dropped files" directory 44 * Structure for keeping a DnD dropped files entry. 45 */ 46 typedef struct DNDDROPPEDFILESENTRY 47 { 48 RTLISTNODE Node; 49 char *pszPath; 50 } DNDDROPPEDFILESENTRY; 51 /** Pointer to a DnD dropped files entry. */ 52 typedef DNDDROPPEDFILESENTRY *PDNDDROPPEDFILESENTRY; 53 54 /** 55 * Structure for maintaining a "dropped files" directory 47 56 * on the host or guest. This will contain all received files & directories 48 57 * for a single drag and drop operation. 49 58 * 50 * In case of a failed drag and drop operation this c lass can also59 * In case of a failed drag and drop operation this can also 51 60 * perform a gentle rollback if required. 52 61 */ 53 class DnDDroppedFiles 54 { 55 public: 56 #ifdef RT_NEED_NEW_AND_DELETE 57 RTMEM_IMPLEMENT_NEW_AND_DELETE(); 58 #endif 59 DnDDroppedFiles(void); 60 DnDDroppedFiles(const char *pszPath, DNDURIDROPPEDFILEFLAGS fFlags = DNDURIDROPPEDFILE_FLAGS_NONE); 61 virtual ~DnDDroppedFiles(void); 62 63 public: 64 65 int AddFile(const char *pszFile); 66 int AddDir(const char *pszDir); 67 int Close(void); 68 bool IsOpen(void) const; 69 int OpenEx(const char *pszPath, DNDURIDROPPEDFILEFLAGS fFlags = DNDURIDROPPEDFILE_FLAGS_NONE); 70 int OpenTemp(DNDURIDROPPEDFILEFLAGS fFlags = DNDURIDROPPEDFILE_FLAGS_NONE); 71 const char *GetDirAbs(void) const; 72 int Reopen(void); 73 int Reset(bool fDelete); 74 int Rollback(void); 75 76 protected: 77 78 int closeInternal(void); 79 80 protected: 81 62 typedef struct DNDDROPPEDFILES 63 { 82 64 /** Open flags. */ 83 uint32_t 65 uint32_t m_fOpen; 84 66 /** Directory handle for drop directory. */ 85 RTDIR 67 RTDIR m_hDir; 86 68 /** Absolute path to drop directory. */ 87 RTCString m_strPathAbs;69 char *pszPathAbs; 88 70 /** List for holding created directories in the case of a rollback. */ 89 RT CList<RTCString>m_lstDirs;71 RTLISTANCHOR m_lstDirs; 90 72 /** List for holding created files in the case of a rollback. */ 91 RTCList<RTCString> m_lstFiles; 92 }; 73 RTLISTANCHOR m_lstFiles; 74 } DNDDROPPEDFILES; 75 /** Pointer to a DnD dropped files directory. */ 76 typedef DNDDROPPEDFILES *PDNDDROPPEDFILES; 77 78 int DnDDroppedFilesInit(PDNDDROPPEDFILES pDF, const char *pszPath, DNDURIDROPPEDFILEFLAGS fFlags); 79 void DnDDroppedFilesDestroy(PDNDDROPPEDFILES pDF); 80 int DnDDroppedFilesAddFile(PDNDDROPPEDFILES pDF, const char *pszFile); 81 int DnDDroppedFilesAddDir(PDNDDROPPEDFILES pDF, const char *pszDir); 82 int DnDDroppedFilesClose(PDNDDROPPEDFILES pDF); 83 bool DnDDroppedFilesIsOpen(PDNDDROPPEDFILES pDF); 84 int DnDDroppedFilesOpenEx(PDNDDROPPEDFILES pDF, const char *pszPath, DNDURIDROPPEDFILEFLAGS fFlags); 85 int DnDDroppedFilesOpenTemp(PDNDDROPPEDFILES pDF, DNDURIDROPPEDFILEFLAGS fFlags); 86 const char *DnDDroppedFilesGetDirAbs(PDNDDROPPEDFILES pDF); 87 int DnDDroppedFilesReopen(PDNDDROPPEDFILES pDF); 88 int DnDDroppedFilesReset(PDNDDROPPEDFILES pDF, bool fDelete); 89 int DnDDroppedFilesRollback(PDNDDROPPEDFILES pDF); 93 90 94 91 bool DnDMIMEHasFileURLs(const char *pcszFormat, size_t cchFormatMax); … … 101 98 102 99 /** No flags specified. 103 * This alsowill convert the path to the universal tansport style. */104 #define DNDPATHCONVERT_FLAGS_ NONE0100 * This will convert the path to the universal tansport style. */ 101 #define DNDPATHCONVERT_FLAGS_TRANSPORT 0 105 102 /** Converts the path to a OS-dependent path. */ 106 #define DNDPATHCONVERT_FLAGS_TO_ NATIVERT_BIT(0)103 #define DNDPATHCONVERT_FLAGS_TO_DOS RT_BIT(0) 107 104 108 105 /** Mask of all valid DnD path conversion flags. */ … … 110 107 111 108 int DnDPathConvert(char *pszPath, size_t cbPath, DNDPATHCONVERTFLAGS fFlags); 112 int DnDPathSanitize(char *pszPath, size_t cbPath); 113 114 /** DnDURIObject flags. */ 115 typedef uint32_t DNDURIOBJECTFLAGS; 109 int DnDPathSanitizeFileName(char *pszPath, size_t cbPath); 110 int DnDPathRebase(const char *pcszPathAbs, const char *pcszBaseOld, const char *pcszBaseNew, char **ppszPath); 111 112 /** DnDTransferObject flags. */ 113 typedef uint32_t DNDTRANSFEROBJECTFLAGS; 116 114 117 115 /** No flags specified. */ 118 #define DNDURIOBJECT_FLAGS_NONE 0 119 120 /** Mask of all valid DnD URI object flags. */ 121 #define DNDURIOBJECT_FLAGS_VALID_MASK UINT32_C(0x0) 122 123 /** 124 * Class for handling DnD URI objects. 125 * This class abstracts the access and handling objects when performing DnD actions. 126 */ 127 class DnDURIObject 128 { 129 public: 130 131 /** 132 * Enumeration for specifying an URI object type. 133 */ 134 enum Type 135 { 136 /** Unknown type, do not use. */ 137 Type_Unknown = 0, 138 /** Object is a file. */ 139 Type_File, 140 /** Object is a directory. */ 141 Type_Directory, 142 /** The usual 32-bit hack. */ 143 Type_32Bit_Hack = 0x7fffffff 144 }; 145 146 #ifdef RT_NEED_NEW_AND_DELETE 147 RTMEM_IMPLEMENT_NEW_AND_DELETE(); 148 #endif 149 DnDURIObject(Type enmType = Type_Unknown, const RTCString &strPathAbs = ""); 150 151 virtual ~DnDURIObject(void); 152 153 public: 154 155 /** 156 * Returns the given absolute source path of the object. 157 * 158 * @return Absolute source path of the object. 159 */ 160 const RTCString &GetPath(void) const { return m_strPathAbs; } 161 162 RTFMODE GetMode(void) const; 163 164 uint64_t GetProcessed(void) const; 165 166 uint64_t GetSize(void) const; 167 168 /** 169 * Returns the object's type. 170 * 171 * @return The object's type. 172 */ 173 Type GetType(void) const { return m_enmType; } 174 175 public: 176 177 int Init(Type enmType, const RTCString &strPathAbs = ""); 178 179 int SetSize(uint64_t cbSize); 180 181 public: 182 183 void Close(void); 184 bool IsComplete(void) const; 185 bool IsOpen(void) const; 186 int Open(uint64_t fOpen, RTFMODE fMode = 0, DNDURIOBJECTFLAGS = DNDURIOBJECT_FLAGS_NONE); 187 int QueryInfo(void); 188 int Read(void *pvBuf, size_t cbBuf, uint32_t *pcbRead); 189 void Reset(void); 190 int Write(const void *pvBuf, size_t cbBuf, uint32_t *pcbWritten); 191 192 public: 193 194 static int RebaseURIPath(RTCString &strPath, const RTCString &strBaseOld = "", const RTCString &strBaseNew = ""); 195 196 protected: 197 198 void closeInternal(void); 199 int queryInfoInternal(void); 200 201 protected: 202 116 #define DNDTRANSFEROBJECT_FLAGS_NONE 0 117 118 /** Mask of all valid DnD transfer object flags. */ 119 #define DNDTRANSFEROBJECT_FLAGS_VALID_MASK UINT32_C(0x0) 120 121 /** 122 * Enumeration for specifying a transfer object type. 123 */ 124 typedef enum DNDTRANSFEROBJTYPE 125 { 126 /** Unknown type, do not use. */ 127 DNDTRANSFEROBJTYPE_UNKNOWN = 0, 128 /** Object is a file. */ 129 DNDTRANSFEROBJTYPE_FILE, 130 /** Object is a directory. */ 131 DNDTRANSFEROBJTYPE_DIRECTORY, 132 /** The usual 32-bit hack. */ 133 DNDTRANSFEROBJTYPE_32BIT_HACK = 0x7fffffff 134 } DNDTRANSFEROBJTYPE; 135 136 /** 137 * Enumeration for specifying a path style. 138 */ 139 typedef enum DNDTRANSFEROBJPATHSTYLE 140 { 141 /** Transport style (UNIX-y), the default. */ 142 DNDTRANSFEROBJPATHSTYLE_TRANSPORT = 0, 143 /** DOS style, containing back slashes. */ 144 DNDTRANSFEROBJPATHSTYLE_DOS, 145 /** The usual 32-bit hack. */ 146 DNDTRANSFEROBJPATHSTYLE_32BIT_HACK = 0x7fffffff 147 } DNDTRANSFEROBJPATHSTYLE; 148 149 /** 150 * Structure for keeping a DnD transfer object. 151 */ 152 typedef struct DNDTRANSFEROBJECT 153 { 154 RTLISTNODE Node; 203 155 /** The object's type. */ 204 Type m_enmType; 205 /** Absolute path of the object. */ 206 RTCString m_strPathAbs; 156 DNDTRANSFEROBJTYPE enmType; 157 /** Index (in characters, UTF-8) at which the first destination segment starts. */ 158 uint16_t idxDst; 159 /** Allocated path. Includdes the absolute source path (if any) + destination segments. 160 * Transport (IPRT) style. */ 161 char *pszPath; 207 162 208 163 /** Union containing data depending on the object's type. */ … … 230 185 } Dir; 231 186 } u; 232 }; 233 234 /** DnDURIList flags. */ 235 typedef uint32_t DNDURILISTFLAGS; 187 } DNDTRANSFEROBJECT; 188 /** Pointer to a DnD transfer object. */ 189 typedef DNDTRANSFEROBJECT *PDNDTRANSFEROBJECT; 190 191 int DnDTransferObjectInit(PDNDTRANSFEROBJECT pObj, DNDTRANSFEROBJTYPE enmType, const char *pcszPathSrcAbs, const char *pcszPathDst); 192 void DnDTransferObjectDestroy(PDNDTRANSFEROBJECT pObj); 193 void DnDTransferObjectClose(PDNDTRANSFEROBJECT pObj); 194 void DnDTransferObjectReset(PDNDTRANSFEROBJECT pObj); 195 const char *DnDTransferObjectGetSourcePath(PDNDTRANSFEROBJECT pObj); 196 const char *DnDTransferObjectGetDestPath(PDNDTRANSFEROBJECT pObj); 197 int DnDTransferObjectGetDestPathEx(PDNDTRANSFEROBJECT pObj, DNDTRANSFEROBJPATHSTYLE enmStyle, char *pszBuf, size_t cbBuf); 198 RTFMODE DnDTransferObjectGetMode(PDNDTRANSFEROBJECT pObj); 199 uint64_t DnDTransferObjectGetProcessed(PDNDTRANSFEROBJECT pObj); 200 uint64_t DnDTransferObjectGetSize(PDNDTRANSFEROBJECT pObj); 201 DNDTRANSFEROBJTYPE DnDTransferObjectGetType(PDNDTRANSFEROBJECT pObj); 202 int DnDTransferObjectSetSize(PDNDTRANSFEROBJECT pObj, uint64_t cbSize); 203 bool DnDTransferObjectIsComplete(PDNDTRANSFEROBJECT pObj); 204 bool DnDTransferObjectIsOpen(PDNDTRANSFEROBJECT pObj); 205 int DnDTransferObjectOpen(PDNDTRANSFEROBJECT pObj, uint64_t fOpen, RTFMODE fMode, DNDTRANSFEROBJECTFLAGS fFlags); 206 int DnDTransferObjectQueryInfo(PDNDTRANSFEROBJECT pObj); 207 int DnDTransferObjectRead(PDNDTRANSFEROBJECT pObj, void *pvBuf, size_t cbBuf, uint32_t *pcbRead); 208 int DnDTransferObjectWrite(PDNDTRANSFEROBJECT pObj, const void *pvBuf, size_t cbBuf, uint32_t *pcbWritten); 209 210 /** Default URI list path separator, if not specified otherwrise. 211 * 212 * This is there for hysterical raisins, to not break older Guest Additions. 213 ** @todo Get rid of this. */ 214 #define DND_PATH_SEPARATOR "\r\n" 215 216 /** DnDTransferList flags. */ 217 typedef uint32_t DNDTRANSFERLISTFLAGS; 236 218 237 219 /** No flags specified. */ 238 #define DNDURILIST_FLAGS_NONE 0 239 /** Keep the original paths, don't convert paths to relative ones. */ 240 #define DNDURILIST_FLAGS_ABSOLUTE_PATHS RT_BIT(0) 241 /** Resolve all symlinks. */ 242 #define DNDURILIST_FLAGS_RESOLVE_SYMLINKS RT_BIT(1) 220 #define DNDTRANSFERLIST_FLAGS_NONE 0 221 /** Resolve all symlinks. Currently not supported. */ 222 #define DNDTRANSFERLIST_FLAGS_RESOLVE_SYMLINKS RT_BIT(0) 243 223 /** Keep the files + directory entries open while 244 224 * being in this list. */ 245 #define DND URILIST_FLAGS_KEEP_OPEN RT_BIT(2)246 /** Lazy loading: Only enumerate sub directories when needed. 225 #define DNDTRANSFERLIST_FLAGS_KEEP_OPEN RT_BIT(1) 226 /** Lazy loading: Only enumerate sub directories when needed. Not implemented yet. 247 227 ** @todo Implement lazy loading. */ 248 #define DNDURILIST_FLAGS_LAZY RT_BIT(3) 249 250 /** Mask of all valid DnD URI list flags. */ 251 #define DNDURILIST_FLAGS_VALID_MASK UINT32_C(0xF) 252 253 class DnDURIList 254 { 255 public: 256 #ifdef RT_NEED_NEW_AND_DELETE 257 RTMEM_IMPLEMENT_NEW_AND_DELETE(); 258 #endif 259 DnDURIList(void); 260 virtual ~DnDURIList(void); 261 262 public: 263 264 int AppendNativePath(const char *pszPath, DNDURILISTFLAGS fFlags); 265 int AppendNativePathsFromList(const char *pszNativePaths, size_t cbNativePaths, DNDURILISTFLAGS fFlags); 266 int AppendNativePathsFromList(const RTCList<RTCString> &lstNativePaths, DNDURILISTFLAGS fFlags); 267 int AppendURIPath(const char *pszURI, DNDURILISTFLAGS fFlags); 268 int AppendURIPathsFromList(const char *pszURIPaths, size_t cbURIPaths, DNDURILISTFLAGS fFlags); 269 int AppendURIPathsFromList(const RTCList<RTCString> &lstURI, DNDURILISTFLAGS fFlags); 270 271 void Clear(void); 272 DnDURIObject *First(void) { return m_lstTree.first(); } 273 bool IsEmpty(void) const { return m_lstTree.isEmpty(); } 274 void RemoveFirst(void); 275 int SetFromURIData(const void *pvData, size_t cbData, DNDURILISTFLAGS fFlags); 276 277 RTCString GetRootEntries(const RTCString &strPathBase = "", const RTCString &strSeparator = "\r\n") const; 278 uint64_t GetRootCount(void) const { return m_lstRoot.size(); } 279 uint64_t GetTotalCount(void) const { return m_cTotal; } 280 uint64_t GetTotalBytes(void) const { return m_cbTotal; } 281 282 protected: 283 284 int addEntry(const char *pcszSource, const char *pcszTarget, DNDURILISTFLAGS fFlags); 285 int appendPathRecursive(const char *pcszSrcPath, const char *pcszDstPath, const char *pcszDstBase, size_t cchDstBase, DNDURILISTFLAGS fFlags); 286 287 protected: 288 289 /** List of all top-level file/directory entries. 228 #define DNDTRANSFERLIST_FLAGS_LAZY RT_BIT(2) 229 230 /** Mask of all valid DnD transfer list flags. */ 231 #define DNDTRANSFERLIST_FLAGS_VALID_MASK UINT32_C(0x7) 232 233 /** 234 * Enumeration for specifying a transfer list format. 235 */ 236 typedef enum DNDTRANSFERLISTFMT 237 { 238 /** Unknown format, do not use. */ 239 DNDTRANSFERLISTFMT_UNKNOWN = 0, 240 /** Native format. */ 241 DNDTRANSFERLISTFMT_NATIVE, 242 /** URI format. */ 243 DNDTRANSFERLISTFMT_URI, 244 /** The usual 32-bit hack. */ 245 DNDTRANSFERLISTFMT_32BIT_HACK = 0x7fffffff 246 } DNDTRANSFERLISTFMT; 247 248 /** 249 * Structure for keeping a DnD transfer list root entry. 250 * 251 * A root entry always is relative to the parent list maintaining it. 252 */ 253 typedef struct DNDTRANSFERLISTROOT 254 { 255 /** List node. */ 256 RTLISTNODE Node; 257 /** Pointer to the relative, allocated root path. 258 * Always ends with a trailing slash. */ 259 char *pszPathRoot; 260 } DNDTRANSFERLISTROOT; 261 /** Pointer to a DnD list root entry. */ 262 typedef DNDTRANSFERLISTROOT *PDNDTRANSFERLISTROOT; 263 264 /** 265 * Struct for keeping a DnD transfer list. 266 * 267 * All entries must share a common (absolute) root path. For different root paths another transfer list is needed. 268 */ 269 typedef struct DNDTRANSFERLIST 270 { 271 /** Absolute root path of this transfer list, in native path style. 272 * Always ends with a separator. */ 273 char *pszPathRootAbs; 274 /** List of all relative (to \a pszPathRootAbs) top-level file/directory entries, of type DNDTRANSFERLISTROOT. 290 275 * Note: All paths are kept internally as UNIX paths for 291 276 * easier conversion/handling! */ 292 RT CList<RTCString> m_lstRoot;293 /** List of all URI objects added. The list's content294 * might vary depending on how the objects are being295 * added (lazy or not). */296 RT CList<DnDURIObject *> m_lstTree;297 /** Total number of all URIobjects. */298 uint64_t m_cTotal;299 /** Total size of all URIobjects, that is, the file277 RTLISTANCHOR lstRoot; 278 /** Total number of all transfer root entries. */ 279 uint64_t cRoots; 280 /** List of all transfer objects added, of type DNDTRANSFEROBJECT. */ 281 RTLISTANCHOR lstObj; 282 /** Total number of all transfer objects. */ 283 uint64_t cObj; 284 /** Total size of all transfer objects, that is, the file 300 285 * size of all objects (in bytes). 301 286 * Note: Do *not* size_t here, as we also want to support large files 302 287 * on 32-bit guests. */ 303 uint64_t m_cbTotal; 304 }; 288 uint64_t cbObjTotal; 289 } DNDTRANSFERLIST; 290 /** Pointer to a DNDTRANSFERLIST struct. */ 291 typedef DNDTRANSFERLIST *PDNDTRANSFERLIST; 292 293 int DnDTransferListInit(PDNDTRANSFERLIST pList, const char *pcszRootPathAbs); 294 void DnDTransferListDestroy(PDNDTRANSFERLIST pList); 295 void DnDTransferListReset(PDNDTRANSFERLIST pList); 296 297 int DnDTransferListAppendPath(PDNDTRANSFERLIST pList, DNDTRANSFERLISTFMT enmFmt, const char *pszPath, DNDTRANSFERLISTFLAGS fFlags); 298 int DnDTransferListAppendPathsFromBuffer(PDNDTRANSFERLIST pList, DNDTRANSFERLISTFMT enmFmt, const char *pszPaths, size_t cbPaths, const char *pcszSeparator, DNDTRANSFERLISTFLAGS fFlags); 299 int DnDTransferListAppendPathsFromArray(PDNDTRANSFERLIST pList, DNDTRANSFERLISTFMT enmFmt, const char * const *papcszPaths, size_t cPaths, DNDTRANSFERLISTFLAGS fFlags); 300 301 int DnDTransferListGetRootsEx(PDNDTRANSFERLIST pList, DNDTRANSFERLISTFMT enmFmt, const char *pcszPathBase, const char *pcszSeparator, char **ppszBuffer, size_t *pcbBuffer); 302 int DnDTransferListGetRoots(PDNDTRANSFERLIST pList, DNDTRANSFERLISTFMT enmFmt, char **ppszBuffer, size_t *pcbBuffer); 303 uint64_t DnDTransferListGetRootCount(PDNDTRANSFERLIST pList); 304 const char *DnDTransferListGetRootPathAbs(PDNDTRANSFERLIST pList); 305 306 PDNDTRANSFEROBJECT DnDTransferListObjGetFirst(PDNDTRANSFERLIST pList); 307 void DnDTransferListObjRemoveFirst(PDNDTRANSFERLIST pList); 308 uint64_t DnDTransferListObjCount(PDNDTRANSFERLIST pList); 309 uint64_t DnDTransferListObjTotalBytes(PDNDTRANSFERLIST pList); 305 310 306 311 #endif /* !VBOX_INCLUDED_GuestHost_DragAndDrop_h */ -
trunk/include/VBox/VBoxGuestLib.h
r85121 r85371 38 38 #include <VBox/VBoxGuestCoreTypes.h> 39 39 # ifdef VBOX_WITH_DRAG_AND_DROP 40 # include <VBox/GuestHost/DragAndDrop.h> 40 41 # include <VBox/GuestHost/DragAndDropDefs.h> 41 42 # endif … … 1178 1179 /** 1179 1180 * Structure for keeping + handling DnD meta data. 1180 *1181 * Note: Don't treat this struct as POD object, as the union has classes in it.1182 1181 */ 1183 1182 typedef struct VBGLR3GUESTDNDMETADATA … … 1185 1184 /** The meta data type the union contains. */ 1186 1185 VBGLR3GUESTDNDMETADATATYPE enmType; 1187 /** Pointer to actual meta data. */ 1188 void *pvMeta; 1189 /** Size (in bytes) of meta data. */ 1190 uint32_t cbMeta; 1186 /** Union based on \a enmType. */ 1187 union 1188 { 1189 struct 1190 { 1191 /** Pointer to actual meta data. */ 1192 void *pvMeta; 1193 /** Size (in bytes) of meta data. */ 1194 uint32_t cbMeta; 1195 } Raw; 1196 struct 1197 { 1198 DNDTRANSFERLIST Transfer; 1199 } URI; 1200 } u; 1191 1201 } VBGLR3GUESTDNDMETADATA; 1192 1202
Note:
See TracChangeset
for help on using the changeset viewer.