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 35 #ifndef FS_UTILS_H 36 #define FS_UTILS_H 37 38 #include <FindDirectory.h> 39 #include <List.h> 40 #include <Point.h> 41 #include <StorageDefs.h> 42 43 #include <vector> 44 45 #include "Model.h" 46 #include "ObjectList.h" 47 48 // Note - APIs/code in FSUtils.h and FSUtils.cpp is slated for a major cleanup 49 // -- in other words, you will find a lot of ugly cruft in here 50 51 class BDirectory; 52 class BEntry; 53 class BList; 54 class BFile; 55 56 namespace BPrivate { 57 58 class BInfoWindow; 59 60 //! Controls the copy engine; may be overriden to specify how conflicts are 61 // handled, etc. 62 class CopyLoopControl { 63 public: 64 virtual ~CopyLoopControl(); 65 66 virtual void Init(uint32 jobKind); 67 virtual void Init(int32 totalItems, off_t totalSize, 68 const entry_ref* destDir = NULL, 69 bool showCount = true); 70 71 //! Inform that a file error occurred while copying <name>. 72 // \return \c True if user decided to continue 73 virtual bool FileError(const char* message, 74 const char* name, status_t error, 75 bool allowContinue); 76 77 virtual void UpdateStatus(const char* name, 78 const entry_ref& ref, int32 count, 79 bool optional = false); 80 81 //! \return \c true if canceled 82 virtual bool CheckUserCanceled(); 83 84 enum OverwriteMode { 85 kSkip, // do not replace, go to next entry 86 kReplace, // remove entry before copying new one 87 kMerge // for folders: leave existing folder, update 88 // contents leaving nonconflicting items 89 // for files: save original attributes on file. 90 }; 91 92 //! Override to always overwrite, never overwrite, let user decide, 93 // compare dates, etc. 94 virtual OverwriteMode OverwriteOnConflict(const BEntry* srcEntry, 95 const char* destName, 96 const BDirectory* destDir, 97 bool srcIsDir, bool dstIsDir); 98 99 //! Override to prevent copying of a given file or directory 100 virtual bool SkipEntry(const BEntry *, bool file); 101 102 //! During a file copy, this is called every time a chunk of data 103 // is copied. Users may override to keep a running checksum. 104 virtual void ChecksumChunk(const char* block, size_t size); 105 106 //! This is called when a file is finished copying. Users of this 107 // class may override to verify that the checksum they've been 108 // computing in ChecksumChunk matches. If this returns true, 109 // the copy will continue. If false, if will abort. 110 virtual bool ChecksumFile(const entry_ref*); 111 112 virtual bool SkipAttribute(const char* attributeName); 113 virtual bool PreserveAttribute(const char* attributeName); 114 }; 115 116 117 //! This is the Tracker copy-specific version of CopyLoopControl. 118 class TrackerCopyLoopControl : public CopyLoopControl { 119 public: 120 TrackerCopyLoopControl(); 121 TrackerCopyLoopControl(uint32 jobKind); 122 TrackerCopyLoopControl(int32 totalItems, 123 off_t totalSize); 124 virtual ~TrackerCopyLoopControl(); 125 126 virtual void Init(uint32 state); 127 virtual void Init(int32 totalItems, off_t totalSize, 128 const entry_ref* destDir = NULL, 129 bool showCount = true); 130 131 virtual bool FileError(const char *message, 132 const char *name, status_t error, 133 bool allowContinue); 134 135 virtual void UpdateStatus(const char *name, 136 const entry_ref& ref, int32 count, 137 bool optional = false); 138 139 virtual bool CheckUserCanceled(); 140 141 virtual bool SkipAttribute(const char *attributeName); 142 143 144 // One can specify an entry_ref list with the source entries. This will 145 // then trigger the feature to pull additional source entries from the 146 // status window, such that the user can drop additional items onto the 147 // progress display of the ongoing copy process to copy these items to 148 // the same target directory. 149 typedef BObjectList<entry_ref> EntryList; 150 151 void SetSourceList(EntryList* list); 152 153 private: 154 thread_id fThread; 155 156 EntryList* fSourceList; 157 }; 158 159 160 #define B_DESKTOP_DIR_NAME "Desktop" 161 162 #ifndef _IMPEXP_TRACKER 163 #define _IMPEXP_TRACKER 164 #endif 165 _IMPEXP_TRACKER status_t FSCopyAttributesAndStats(BNode *, BNode *); 166 167 _IMPEXP_TRACKER void FSDuplicate(BObjectList<entry_ref> *srcList, BList *pointList); 168 _IMPEXP_TRACKER void FSMoveToFolder(BObjectList<entry_ref> *srcList, BEntry *, uint32 moveMode, 169 BList *pointList = NULL); 170 _IMPEXP_TRACKER void FSMakeOriginalName(char *name, BDirectory *destDir, const char *suffix); 171 _IMPEXP_TRACKER bool FSIsTrashDir(const BEntry *); 172 _IMPEXP_TRACKER bool FSIsPrintersDir(const BEntry *); 173 _IMPEXP_TRACKER bool FSIsDeskDir(const BEntry *); 174 _IMPEXP_TRACKER bool FSIsHomeDir(const BEntry *); 175 _IMPEXP_TRACKER void FSMoveToTrash(BObjectList<entry_ref> *srcList, BList *pointList = NULL, 176 bool async = true); 177 // Deprecated 178 179 void FSDeleteRefList(BObjectList<entry_ref> *, bool, bool confirm = true); 180 void FSDelete(entry_ref *, bool, bool confirm = true); 181 void FSRestoreRefList(BObjectList<entry_ref> *list, bool async); 182 183 _IMPEXP_TRACKER status_t FSLaunchItem(const entry_ref *application, const BMessage *refsReceived, 184 bool async, bool openWithOK); 185 // Preferred way of launching; only pass an actual application in <application>, not 186 // a document; to open documents with the preferred app, pase 0 in <application> and 187 // stuff all the document refs into <refsReceived> 188 // Consider having silent mode that does not show alerts, just returns error code 189 190 _IMPEXP_TRACKER status_t FSOpenWith(BMessage *listOfRefs); 191 // runs the Open With window; pas a list of refs 192 193 _IMPEXP_TRACKER void FSEmptyTrash(); 194 _IMPEXP_TRACKER status_t FSCreateNewFolderIn(const node_ref *destDir, entry_ref *newRef, 195 node_ref *new_node); 196 _IMPEXP_TRACKER void FSCreateTrashDirs(); 197 _IMPEXP_TRACKER status_t FSGetTrashDir(BDirectory *trashDir, dev_t volume); 198 _IMPEXP_TRACKER status_t FSGetDeskDir(BDirectory *deskDir); 199 _IMPEXP_TRACKER status_t FSRecursiveCalcSize(BInfoWindow *, 200 CopyLoopControl* loopControl, BDirectory *, off_t *runningSize, 201 int32 *fileCount, int32 *dirCount); 202 203 bool FSInTrashDir(const entry_ref *); 204 205 // doesn't need to be exported 206 bool FSGetPoseLocation(const BNode *node, BPoint *point); 207 status_t FSSetPoseLocation(BEntry *entry, BPoint point); 208 status_t FSSetPoseLocation(ino_t destDirInode, BNode *destNode, BPoint point); 209 status_t FSGetBootDeskDir(BDirectory *deskDir); 210 211 status_t FSGetOriginalPath(BEntry *entry, BPath *path); 212 213 enum ReadAttrResult { 214 kReadAttrFailed, 215 kReadAttrNativeOK, 216 kReadAttrForeignOK 217 }; 218 219 ReadAttrResult ReadAttr(const BNode *, const char *hostAttrName, const char *foreignAttrName, 220 type_code , off_t , void *, size_t , void (*swapFunc)(void *) = 0, 221 bool isForeign = false); 222 // Endian swapping ReadAttr call; endianness is determined by trying first the 223 // native attribute name, then the foreign one; an endian swapping function can 224 // be passed, if null data won't be swapped; if <isForeign> set the foreign endianness 225 // will be read directly without first trying the native one 226 227 ReadAttrResult GetAttrInfo(const BNode *, const char *hostAttrName, const char *foreignAttrName, 228 type_code * = NULL, size_t * = NULL); 229 230 status_t FSCreateNewFolder(const entry_ref *); 231 status_t FSRecursiveCreateFolder(const char *path); 232 void FSMakeOriginalName(BString &name, const BDirectory *destDir, const char *suffix = 0); 233 234 status_t TrackerLaunch(const entry_ref *app, bool async); 235 status_t TrackerLaunch(const BMessage *refs, bool async, bool okToRunOpenWith = true); 236 status_t TrackerLaunch(const entry_ref *app, const BMessage *refs, bool async, 237 bool okToRunOpenWith = true); 238 status_t LaunchBrokenLink(const char *, const BMessage *); 239 240 status_t FSFindTrackerSettingsDir(BPath *, bool autoCreate = true); 241 242 bool FSIsDeskDir(const BEntry *); 243 244 bool ConfirmChangeIfWellKnownDirectory(const BEntry *entry, const char *action, 245 bool dontAsk = false, int32 *confirmedAlready = NULL); 246 247 bool CheckDevicesEqual(const entry_ref *entry, const Model *targetModel); 248 249 // Deprecated calls use newer calls above instead 250 _IMPEXP_TRACKER void FSLaunchItem(const entry_ref *, BMessage * = NULL, int32 workspace = -1); 251 _IMPEXP_TRACKER status_t FSLaunchItem(const entry_ref *, BMessage *, 252 int32 workspace, bool asynch); 253 _IMPEXP_TRACKER void FSOpenWithDocuments(const entry_ref *executableToLaunch, 254 BMessage *documentEntryRefs); 255 _IMPEXP_TRACKER status_t FSLaunchUsing(const entry_ref *ref, BMessage *listOfRefs); 256 257 258 // some extra directory_which values 259 // move these to FindDirectory.h 260 const uint32 B_USER_MAIL_DIRECTORY = 3500; 261 const uint32 B_USER_QUERIES_DIRECTORY = 3501; 262 const uint32 B_USER_PEOPLE_DIRECTORY = 3502; 263 const uint32 B_USER_DOWNLOADS_DIRECTORY = 3503; 264 const uint32 B_USER_DESKBAR_APPS_DIRECTORY = 3504; 265 const uint32 B_USER_DESKBAR_PREFERENCES_DIRECTORY = 3505; 266 const uint32 B_USER_DESKBAR_DEVELOP_DIRECTORY = 3506; 267 268 const int32 B_BOOT_DISK = 10000000; 269 // map /boot into the directory_which enum for convenience 270 271 class WellKnowEntryList { 272 // matches up names, id's and node_refs of well known entries in the 273 // system hierarchy 274 public: 275 struct WellKnownEntry { 276 WellKnownEntry(const node_ref *node, directory_which which, const char *name) 277 : 278 node(*node), 279 which(which), 280 name(name) 281 { 282 } 283 284 // mwcc needs these explicitly to use vector 285 WellKnownEntry(const WellKnownEntry &clone) 286 : 287 node(clone.node), 288 which(clone.which), 289 name(clone.name) 290 { 291 } 292 293 WellKnownEntry() 294 { 295 } 296 297 node_ref node; 298 directory_which which; 299 const char *name; 300 }; 301 302 static directory_which Match(const node_ref *); 303 static const WellKnownEntry *MatchEntry(const node_ref *); 304 static void Quit(); 305 306 private: 307 const WellKnownEntry *MatchEntryCommon(const node_ref *); 308 WellKnowEntryList(); 309 void AddOne(directory_which, const char *name); 310 void AddOne(directory_which, const char *path, const char *name); 311 void AddOne(directory_which, directory_which base, const char *extension, 312 const char *name); 313 314 std::vector<WellKnownEntry> entries; 315 static WellKnowEntryList *self; 316 }; 317 318 #if B_BEOS_VERSION_DANO 319 #undef _IMPEXP_TRACKER 320 #endif 321 322 } // namespace BPrivate 323 324 using namespace BPrivate; 325 326 #endif /* FS_UTILS_H */ 327