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