1 /* 2 Open Tracker License 3 4 Terms and Conditions 5 6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved. 7 8 Permission is hereby granted, free of charge, to any person obtaining a copy of 9 this software and associated documentation files (the "Software"), to deal in 10 the Software without restriction, including without limitation the rights to 11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 12 of the Software, and to permit persons to whom the Software is furnished to do 13 so, subject to the following conditions: 14 15 The above copyright notice and this permission notice applies to all licensees 16 and shall be included in all copies or substantial portions of the Software. 17 18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY, 20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION 23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 25 Except as contained in this notice, the name of Be Incorporated shall not be 26 used in advertising or otherwise to promote the sale, use or other dealings in 27 this Software without prior written authorization from Be Incorporated. 28 29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks 30 of Be Incorporated in the United States and other countries. Other brand product 31 names are registered trademarks or trademarks of their respective holders. 32 All rights reserved. 33 */ 34 #ifndef FS_UTILS_H 35 #define FS_UTILS_H 36 37 38 #include <FindDirectory.h> 39 #include <List.h> 40 #include <ObjectList.h> 41 #include <Point.h> 42 #include <StorageDefs.h> 43 44 #include <vector> 45 46 #include "Model.h" 47 48 49 // APIs/code in FSUtils.h and FSUtils.cpp is slated for a major cleanup 50 // -- in other words, you will find a lot of ugly cruft in here 51 52 class BDirectory; 53 class BEntry; 54 class BList; 55 class BFile; 56 57 namespace BPrivate { 58 59 class BInfoWindow; 60 61 //! Controls the copy engine; may be overriden to specify how conflicts are 62 // handled, etc. 63 class CopyLoopControl { 64 public: 65 virtual ~CopyLoopControl(); 66 67 virtual void Init(uint32 jobKind); 68 virtual void Init(int32 totalItems, off_t totalSize, 69 const entry_ref* destDir = NULL, 70 bool showCount = true); 71 72 //! Inform that a file error occurred while copying <name>. 73 // \return \c True if user decided to continue 74 virtual bool FileError(const char* message, 75 const char* name, status_t error, 76 bool allowContinue); 77 78 virtual void UpdateStatus(const char* name, 79 const entry_ref& ref, int32 count, 80 bool optional = false); 81 82 //! \return \c true if canceled 83 virtual bool CheckUserCanceled(); 84 85 enum OverwriteMode { 86 kSkip, // do not replace, go to next entry 87 kReplace, // remove entry before copying new one 88 kMerge // for folders: leave existing folder, update 89 // contents leaving nonconflicting items 90 // for files: save original attributes on file 91 }; 92 93 //! Override to always overwrite, never overwrite, let user decide, 94 // compare dates, etc. 95 virtual OverwriteMode OverwriteOnConflict(const BEntry* srcEntry, 96 const char* destName, 97 const BDirectory* destDir, 98 bool srcIsDir, bool dstIsDir); 99 100 //! Override to prevent copying of a given file or directory 101 virtual bool SkipEntry(const BEntry*, bool file); 102 103 //! During a file copy, this is called every time a chunk of data 104 // is copied. Users may override to keep a running checksum. 105 virtual void ChecksumChunk(const char* block, size_t size); 106 107 //! This is called when a file is finished copying. Users of this 108 // class may override to verify that the checksum they've been 109 // computing in ChecksumChunk matches. If this returns true, 110 // the copy will continue. If false, if will abort. 111 virtual bool ChecksumFile(const entry_ref*); 112 113 virtual bool SkipAttribute(const char* attributeName); 114 virtual bool PreserveAttribute(const char* attributeName); 115 }; 116 117 118 //! This is the Tracker copy-specific version of CopyLoopControl. 119 class TrackerCopyLoopControl : public CopyLoopControl { 120 public: 121 TrackerCopyLoopControl(); 122 TrackerCopyLoopControl(uint32 jobKind); 123 TrackerCopyLoopControl(int32 totalItems, 124 off_t totalSize); 125 virtual ~TrackerCopyLoopControl(); 126 127 virtual void Init(uint32 state); 128 virtual void Init(int32 totalItems, off_t totalSize, 129 const entry_ref* destDir = NULL, 130 bool showCount = true); 131 132 virtual bool FileError(const char* message, 133 const char* name, status_t error, 134 bool allowContinue); 135 136 virtual void UpdateStatus(const char* name, 137 const entry_ref& ref, int32 count, 138 bool optional = false); 139 140 virtual bool CheckUserCanceled(); 141 142 virtual bool SkipAttribute(const char* attributeName); 143 144 145 // One can specify an entry_ref list with the source entries. This will 146 // then trigger the feature to pull additional source entries from the 147 // status window, such that the user can drop additional items onto the 148 // progress display of the ongoing copy process to copy these items to 149 // the same target directory. 150 typedef BObjectList<entry_ref> EntryList; 151 152 void SetSourceList(EntryList* list); 153 154 private: 155 thread_id fThread; 156 157 EntryList* fSourceList; 158 }; 159 160 161 #define B_DESKTOP_DIR_NAME "Desktop" 162 #define B_DISKS_DIR_NAME "Disks" 163 #define B_TRASH_DIR_NAME "Trash" 164 165 #ifndef _IMPEXP_TRACKER 166 #define _IMPEXP_TRACKER 167 #endif 168 _IMPEXP_TRACKER status_t FSCopyAttributesAndStats(BNode*, BNode*, bool = true); 169 170 _IMPEXP_TRACKER void FSDuplicate(BObjectList<entry_ref>* srcList, 171 BList* pointList); 172 _IMPEXP_TRACKER void FSMoveToFolder(BObjectList<entry_ref>* srcList, BEntry*, 173 uint32 moveMode, BList* pointList = NULL); 174 _IMPEXP_TRACKER void FSMakeOriginalName(char* name, BDirectory* destDir, 175 const char* suffix); 176 _IMPEXP_TRACKER bool FSIsTrashDir(const BEntry*); 177 _IMPEXP_TRACKER bool FSIsPrintersDir(const BEntry*); 178 _IMPEXP_TRACKER bool FSIsDeskDir(const BEntry*); 179 _IMPEXP_TRACKER bool FSIsHomeDir(const BEntry*); 180 _IMPEXP_TRACKER bool FSIsRootDir(const BEntry*); 181 _IMPEXP_TRACKER void FSMoveToTrash(BObjectList<entry_ref>* srcList, 182 BList* pointList = NULL, bool async = true); 183 // Deprecated 184 185 void FSDeleteRefList(BObjectList<entry_ref>*, bool, bool confirm = true); 186 void FSDelete(entry_ref*, bool, bool confirm = true); 187 void FSRestoreRefList(BObjectList<entry_ref>* list, bool async); 188 189 _IMPEXP_TRACKER status_t FSLaunchItem(const entry_ref* application, 190 const BMessage* refsReceived, bool async, bool openWithOK); 191 // Preferred way of launching; only pass an actual application in 192 // <application>, not a document; to open documents with the preferred 193 // app, pase 0 in <application> and stuff all the document refs into 194 // <refsReceived> Consider having silent mode that does not show alerts, 195 // just returns error code 196 197 _IMPEXP_TRACKER status_t FSOpenWith(BMessage* listOfRefs); 198 // runs the Open With window; pas a list of refs 199 200 _IMPEXP_TRACKER void FSEmptyTrash(); 201 _IMPEXP_TRACKER status_t FSCreateNewFolderIn(const node_ref* destDir, 202 entry_ref* newRef, node_ref* new_node); 203 _IMPEXP_TRACKER void FSCreateTrashDirs(); 204 _IMPEXP_TRACKER status_t FSGetTrashDir(BDirectory* trashDir, dev_t volume); 205 _IMPEXP_TRACKER status_t FSGetDeskDir(BDirectory* deskDir); 206 _IMPEXP_TRACKER status_t FSRecursiveCalcSize(BInfoWindow*, 207 CopyLoopControl* loopControl, BDirectory*, off_t* runningSize, 208 int32* fileCount, int32* dirCount); 209 210 bool FSInDeskDir(const entry_ref*); 211 bool FSIsQueriesDir(const entry_ref*); 212 bool FSInRootDir(const entry_ref*); 213 bool FSInTrashDir(const entry_ref*); 214 215 // doesn't need to be exported 216 bool FSGetPoseLocation(const BNode* node, BPoint* point); 217 status_t FSSetPoseLocation(BEntry* entry, BPoint point); 218 status_t FSSetPoseLocation(ino_t destDirInode, BNode* destNode, BPoint point); 219 status_t FSGetBootDeskDir(BDirectory* deskDir); 220 221 status_t FSGetOriginalPath(BEntry* entry, BPath* path); 222 223 enum ReadAttrResult { 224 kReadAttrFailed, 225 kReadAttrNativeOK, 226 kReadAttrForeignOK 227 }; 228 229 ReadAttrResult ReadAttr(const BNode*, const char* hostAttrName, 230 const char* foreignAttrName, type_code, off_t, void*, size_t, 231 void (*swapFunc)(void*) = 0, bool isForeign = false); 232 // Endian swapping ReadAttr call; endianness is determined by trying 233 // first the native attribute name, then the foreign one; an endian 234 // swapping function can be passed, if null data won't be swapped; 235 // if <isForeign> set the foreign endianness will be read directly 236 // without first trying the native one 237 238 ReadAttrResult GetAttrInfo(const BNode*, const char* hostAttrName, 239 const char* foreignAttrName, type_code* = NULL, size_t* = NULL); 240 241 status_t FSCreateNewFolder(entry_ref*); 242 status_t FSRecursiveCreateFolder(const char* path); 243 void FSMakeOriginalName(BString &name, const BDirectory* destDir, 244 const char* suffix = 0); 245 246 status_t FSGetParentVirtualDirectoryAware(const BEntry& entry, entry_ref& _ref); 247 status_t FSGetParentVirtualDirectoryAware(const BEntry& entry, BEntry& _entry); 248 status_t FSGetParentVirtualDirectoryAware(const BEntry& entry, BNode& _node); 249 250 status_t TrackerLaunch(const entry_ref* appRef, bool async); 251 status_t TrackerLaunch(const BMessage* refs, bool async, 252 bool okToRunOpenWith = true); 253 status_t TrackerLaunch(const entry_ref* appRef, const BMessage* refs, 254 bool async, bool okToRunOpenWith = true); 255 256 status_t FSFindTrackerSettingsDir(BPath*, bool autoCreate = true); 257 258 bool FSIsDeskDir(const BEntry*); 259 260 enum DestructiveAction { 261 kRename, 262 kMove 263 }; 264 265 bool ConfirmChangeIfWellKnownDirectory(const BEntry* entry, 266 DestructiveAction action, bool dontAsk = false, 267 int32* confirmedAlready = NULL); 268 269 status_t EditModelName(const Model* model, const char* name, size_t); 270 // return B_OK if name was edited 271 status_t ShouldEditRefName(const entry_ref* ref, const char* name, size_t); 272 // return B_OK if name should be edited 273 274 bool CheckDevicesEqual(const entry_ref* entry, const Model* targetModel); 275 276 // Deprecated calls use newer calls above instead 277 _IMPEXP_TRACKER void FSLaunchItem(const entry_ref* appRef, 278 BMessage* refs = NULL, int32 workspace = -1); 279 _IMPEXP_TRACKER status_t FSLaunchItem(const entry_ref* appRef, 280 BMessage* refs, int32 workspace, bool asynch); 281 _IMPEXP_TRACKER void FSOpenWithDocuments(const entry_ref* executableToLaunch, 282 BMessage* documentEntryRefs); 283 _IMPEXP_TRACKER status_t FSLaunchUsing(const entry_ref* ref, 284 BMessage* listOfRefs); 285 286 287 // some extra directory_which values 288 // move these to FindDirectory.h 289 const uint32 B_USER_MAIL_DIRECTORY = 3500; 290 const uint32 B_USER_QUERIES_DIRECTORY = 3501; 291 const uint32 B_USER_PEOPLE_DIRECTORY = 3502; 292 const uint32 B_USER_DOWNLOADS_DIRECTORY = 3503; 293 const uint32 B_USER_DESKBAR_APPS_DIRECTORY = 3504; 294 const uint32 B_USER_DESKBAR_PREFERENCES_DIRECTORY = 3505; 295 const uint32 B_USER_DESKBAR_DEVELOP_DIRECTORY = 3506; 296 const uint32 B_BOOT_DISK = 3507; 297 // map /boot into the directory_which enum for convenience 298 299 class WellKnowEntryList { 300 // matches up names, id's and node_refs of well known entries in the 301 // system hierarchy 302 public: 303 struct WellKnownEntry { 304 WellKnownEntry(const node_ref* node, directory_which which, 305 const char* name) 306 : 307 node(*node), 308 which(which), 309 name(name) 310 { 311 } 312 313 // mwcc needs these explicitly to use vector 314 WellKnownEntry(const WellKnownEntry &clone) 315 : 316 node(clone.node), 317 which(clone.which), 318 name(clone.name) 319 { 320 } 321 322 WellKnownEntry() 323 { 324 } 325 326 node_ref node; 327 directory_which which; 328 BString name; 329 }; 330 331 static directory_which Match(const node_ref*); 332 static const WellKnownEntry* MatchEntry(const node_ref*); 333 static void Quit(); 334 335 private: 336 const WellKnownEntry* MatchEntryCommon(const node_ref*); 337 WellKnowEntryList(); 338 void AddOne(directory_which, const char* name); 339 void AddOne(directory_which, const char* path, const char* name); 340 void AddOne(directory_which, directory_which base, 341 const char* extension, const char* name); 342 343 std::vector<WellKnownEntry> entries; 344 static WellKnowEntryList* self; 345 }; 346 347 #if B_BEOS_VERSION_DANO 348 #undef _IMPEXP_TRACKER 349 #endif 350 351 } // namespace BPrivate 352 353 using namespace BPrivate; 354 355 #endif // FS_UTILS_H 356