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 bool FSIsRootDir(const BEntry *); 176 _IMPEXP_TRACKER void FSMoveToTrash(BObjectList<entry_ref> *srcList, BList *pointList = NULL, 177 bool async = true); 178 // Deprecated 179 180 void FSDeleteRefList(BObjectList<entry_ref> *, bool, bool confirm = true); 181 void FSDelete(entry_ref *, bool, bool confirm = true); 182 void FSRestoreRefList(BObjectList<entry_ref> *list, bool async); 183 184 _IMPEXP_TRACKER status_t FSLaunchItem(const entry_ref *application, const BMessage *refsReceived, 185 bool async, bool openWithOK); 186 // Preferred way of launching; only pass an actual application in <application>, not 187 // a document; to open documents with the preferred app, pase 0 in <application> and 188 // stuff all the document refs into <refsReceived> 189 // Consider having silent mode that does not show alerts, just returns error code 190 191 _IMPEXP_TRACKER status_t FSOpenWith(BMessage *listOfRefs); 192 // runs the Open With window; pas a list of refs 193 194 _IMPEXP_TRACKER void FSEmptyTrash(); 195 _IMPEXP_TRACKER status_t FSCreateNewFolderIn(const node_ref *destDir, entry_ref *newRef, 196 node_ref *new_node); 197 _IMPEXP_TRACKER void FSCreateTrashDirs(); 198 _IMPEXP_TRACKER status_t FSGetTrashDir(BDirectory *trashDir, dev_t volume); 199 _IMPEXP_TRACKER status_t FSGetDeskDir(BDirectory *deskDir); 200 _IMPEXP_TRACKER status_t FSRecursiveCalcSize(BInfoWindow *, 201 CopyLoopControl* loopControl, BDirectory *, off_t *runningSize, 202 int32 *fileCount, int32 *dirCount); 203 204 bool FSInTrashDir(const entry_ref *); 205 206 // doesn't need to be exported 207 bool FSGetPoseLocation(const BNode *node, BPoint *point); 208 status_t FSSetPoseLocation(BEntry *entry, BPoint point); 209 status_t FSSetPoseLocation(ino_t destDirInode, BNode *destNode, BPoint point); 210 status_t FSGetBootDeskDir(BDirectory *deskDir); 211 212 status_t FSGetOriginalPath(BEntry *entry, BPath *path); 213 214 enum ReadAttrResult { 215 kReadAttrFailed, 216 kReadAttrNativeOK, 217 kReadAttrForeignOK 218 }; 219 220 ReadAttrResult ReadAttr(const BNode *, const char *hostAttrName, const char *foreignAttrName, 221 type_code , off_t , void *, size_t , void (*swapFunc)(void *) = 0, 222 bool isForeign = false); 223 // Endian swapping ReadAttr call; endianness is determined by trying first the 224 // native attribute name, then the foreign one; an endian swapping function can 225 // be passed, if null data won't be swapped; if <isForeign> set the foreign endianness 226 // will be read directly without first trying the native one 227 228 ReadAttrResult GetAttrInfo(const BNode *, const char *hostAttrName, const char *foreignAttrName, 229 type_code * = NULL, size_t * = NULL); 230 231 status_t FSCreateNewFolder(const entry_ref *); 232 status_t FSRecursiveCreateFolder(const char *path); 233 void FSMakeOriginalName(BString &name, const BDirectory *destDir, const char *suffix = 0); 234 235 status_t TrackerLaunch(const entry_ref *app, bool async); 236 status_t TrackerLaunch(const BMessage *refs, bool async, bool okToRunOpenWith = true); 237 status_t TrackerLaunch(const entry_ref *app, const BMessage *refs, bool async, 238 bool okToRunOpenWith = true); 239 status_t LaunchBrokenLink(const char *, const BMessage *); 240 241 status_t FSFindTrackerSettingsDir(BPath *, bool autoCreate = true); 242 243 bool FSIsDeskDir(const BEntry *); 244 245 // two separate ifYouDoAction and toDoAction versions are needed for localization 246 // purposes. The first one is used in "If you do action ..." sentence, 247 // the second one in the "To do action" sentence. 248 bool ConfirmChangeIfWellKnownDirectory(const BEntry *entry, 249 const char *ifYouDoAction, const char *toDoAction, 250 bool dontAsk = false, int32 *confirmedAlready = NULL); 251 252 bool CheckDevicesEqual(const entry_ref *entry, const Model *targetModel); 253 254 // Deprecated calls use newer calls above instead 255 _IMPEXP_TRACKER void FSLaunchItem(const entry_ref *, BMessage * = NULL, int32 workspace = -1); 256 _IMPEXP_TRACKER status_t FSLaunchItem(const entry_ref *, BMessage *, 257 int32 workspace, bool asynch); 258 _IMPEXP_TRACKER void FSOpenWithDocuments(const entry_ref *executableToLaunch, 259 BMessage *documentEntryRefs); 260 _IMPEXP_TRACKER status_t FSLaunchUsing(const entry_ref *ref, BMessage *listOfRefs); 261 262 263 // some extra directory_which values 264 // move these to FindDirectory.h 265 const uint32 B_USER_MAIL_DIRECTORY = 3500; 266 const uint32 B_USER_QUERIES_DIRECTORY = 3501; 267 const uint32 B_USER_PEOPLE_DIRECTORY = 3502; 268 const uint32 B_USER_DOWNLOADS_DIRECTORY = 3503; 269 const uint32 B_USER_DESKBAR_APPS_DIRECTORY = 3504; 270 const uint32 B_USER_DESKBAR_PREFERENCES_DIRECTORY = 3505; 271 const uint32 B_USER_DESKBAR_DEVELOP_DIRECTORY = 3506; 272 const uint32 B_BOOT_DISK = 3507; 273 // map /boot into the directory_which enum for convenience 274 275 class WellKnowEntryList { 276 // matches up names, id's and node_refs of well known entries in the 277 // system hierarchy 278 public: 279 struct WellKnownEntry { 280 WellKnownEntry(const node_ref *node, directory_which which, const char *name) 281 : 282 node(*node), 283 which(which), 284 name(name) 285 { 286 } 287 288 // mwcc needs these explicitly to use vector 289 WellKnownEntry(const WellKnownEntry &clone) 290 : 291 node(clone.node), 292 which(clone.which), 293 name(clone.name) 294 { 295 } 296 297 WellKnownEntry() 298 { 299 } 300 301 node_ref node; 302 directory_which which; 303 BString name; 304 }; 305 306 static directory_which Match(const node_ref *); 307 static const WellKnownEntry *MatchEntry(const node_ref *); 308 static void Quit(); 309 310 private: 311 const WellKnownEntry *MatchEntryCommon(const node_ref *); 312 WellKnowEntryList(); 313 void AddOne(directory_which, const char *name); 314 void AddOne(directory_which, const char *path, const char *name); 315 void AddOne(directory_which, directory_which base, const char *extension, 316 const char *name); 317 318 std::vector<WellKnownEntry> entries; 319 static WellKnowEntryList *self; 320 }; 321 322 #if B_BEOS_VERSION_DANO 323 #undef _IMPEXP_TRACKER 324 #endif 325 326 } // namespace BPrivate 327 328 using namespace BPrivate; 329 330 #endif /* FS_UTILS_H */ 331