6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
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:
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.
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.
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.
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.
38 #include <FindDirectory.h>
40 #include <ObjectList.h>
42 #include <StorageDefs.h>
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
61 //! Controls the copy engine; may be overriden to specify how conflicts are
63 class CopyLoopControl
{
65 virtual ~CopyLoopControl();
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);
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
,
78 virtual void UpdateStatus(const char* name
,
79 const entry_ref
& ref
, int32 count
,
80 bool optional
= false);
82 //! \return \c true if canceled
83 virtual bool CheckUserCanceled();
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
93 //! Override to always overwrite, never overwrite, let user decide,
94 // compare dates, etc.
95 virtual OverwriteMode
OverwriteOnConflict(const BEntry
* srcEntry
,
97 const BDirectory
* destDir
,
98 bool srcIsDir
, bool dstIsDir
);
100 //! Override to prevent copying of a given file or directory
101 virtual bool SkipEntry(const BEntry
*, bool file
);
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
);
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
*);
113 virtual bool SkipAttribute(const char* attributeName
);
114 virtual bool PreserveAttribute(const char* attributeName
);
118 //! This is the Tracker copy-specific version of CopyLoopControl.
119 class TrackerCopyLoopControl
: public CopyLoopControl
{
121 TrackerCopyLoopControl();
122 TrackerCopyLoopControl(uint32 jobKind
);
123 TrackerCopyLoopControl(int32 totalItems
,
125 virtual ~TrackerCopyLoopControl();
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);
132 virtual bool FileError(const char* message
,
133 const char* name
, status_t error
,
136 virtual void UpdateStatus(const char* name
,
137 const entry_ref
& ref
, int32 count
,
138 bool optional
= false);
140 virtual bool CheckUserCanceled();
142 virtual bool SkipAttribute(const char* attributeName
);
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
;
152 void SetSourceList(EntryList
* list
);
157 EntryList
* fSourceList
;
161 #define B_DESKTOP_DIR_NAME "Desktop"
162 #define B_DISKS_DIR_NAME "Disks"
163 #define B_TRASH_DIR_NAME "Trash"
165 #ifndef _IMPEXP_TRACKER
166 #define _IMPEXP_TRACKER
168 _IMPEXP_TRACKER status_t
FSCopyAttributesAndStats(BNode
*, BNode
*, bool = true);
170 _IMPEXP_TRACKER
void FSDuplicate(BObjectList
<entry_ref
>* srcList
,
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
,
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);
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
);
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
197 _IMPEXP_TRACKER status_t
FSOpenWith(BMessage
* listOfRefs
);
198 // runs the Open With window; pas a list of refs
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
);
210 bool FSInTrashDir(const entry_ref
*);
212 // doesn't need to be exported
213 bool FSGetPoseLocation(const BNode
* node
, BPoint
* point
);
214 status_t
FSSetPoseLocation(BEntry
* entry
, BPoint point
);
215 status_t
FSSetPoseLocation(ino_t destDirInode
, BNode
* destNode
, BPoint point
);
216 status_t
FSGetBootDeskDir(BDirectory
* deskDir
);
218 status_t
FSGetOriginalPath(BEntry
* entry
, BPath
* path
);
220 enum ReadAttrResult
{
226 ReadAttrResult
ReadAttr(const BNode
*, const char* hostAttrName
,
227 const char* foreignAttrName
, type_code
, off_t
, void*, size_t,
228 void (*swapFunc
)(void*) = 0, bool isForeign
= false);
229 // Endian swapping ReadAttr call; endianness is determined by trying
230 // first the native attribute name, then the foreign one; an endian
231 // swapping function can be passed, if null data won't be swapped;
232 // if <isForeign> set the foreign endianness will be read directly
233 // without first trying the native one
235 ReadAttrResult
GetAttrInfo(const BNode
*, const char* hostAttrName
,
236 const char* foreignAttrName
, type_code
* = NULL
, size_t* = NULL
);
238 status_t
FSCreateNewFolder(const entry_ref
*);
239 status_t
FSRecursiveCreateFolder(const char* path
);
240 void FSMakeOriginalName(BString
&name
, const BDirectory
* destDir
,
241 const char* suffix
= 0);
243 status_t
FSGetParentVirtualDirectoryAware(const BEntry
& entry
, entry_ref
& _ref
);
244 status_t
FSGetParentVirtualDirectoryAware(const BEntry
& entry
, BEntry
& _entry
);
245 status_t
FSGetParentVirtualDirectoryAware(const BEntry
& entry
, BNode
& _node
);
247 status_t
TrackerLaunch(const entry_ref
* appRef
, bool async
);
248 status_t
TrackerLaunch(const BMessage
* refs
, bool async
,
249 bool okToRunOpenWith
= true);
250 status_t
TrackerLaunch(const entry_ref
* appRef
, const BMessage
* refs
,
251 bool async
, bool okToRunOpenWith
= true);
252 status_t
LaunchBrokenLink(const char*, const BMessage
*);
254 status_t
FSFindTrackerSettingsDir(BPath
*, bool autoCreate
= true);
256 bool FSIsDeskDir(const BEntry
*);
258 enum DestructiveAction
{
263 bool ConfirmChangeIfWellKnownDirectory(const BEntry
* entry
,
264 DestructiveAction action
, bool dontAsk
= false,
265 int32
* confirmedAlready
= NULL
);
267 bool CheckDevicesEqual(const entry_ref
* entry
, const Model
* targetModel
);
269 // Deprecated calls use newer calls above instead
270 _IMPEXP_TRACKER
void FSLaunchItem(const entry_ref
* appRef
,
271 BMessage
* refs
= NULL
, int32 workspace
= -1);
272 _IMPEXP_TRACKER status_t
FSLaunchItem(const entry_ref
* appRef
,
273 BMessage
* refs
, int32 workspace
, bool asynch
);
274 _IMPEXP_TRACKER
void FSOpenWithDocuments(const entry_ref
* executableToLaunch
,
275 BMessage
* documentEntryRefs
);
276 _IMPEXP_TRACKER status_t
FSLaunchUsing(const entry_ref
* ref
,
277 BMessage
* listOfRefs
);
280 // some extra directory_which values
281 // move these to FindDirectory.h
282 const uint32 B_USER_MAIL_DIRECTORY
= 3500;
283 const uint32 B_USER_QUERIES_DIRECTORY
= 3501;
284 const uint32 B_USER_PEOPLE_DIRECTORY
= 3502;
285 const uint32 B_USER_DOWNLOADS_DIRECTORY
= 3503;
286 const uint32 B_USER_DESKBAR_APPS_DIRECTORY
= 3504;
287 const uint32 B_USER_DESKBAR_PREFERENCES_DIRECTORY
= 3505;
288 const uint32 B_USER_DESKBAR_DEVELOP_DIRECTORY
= 3506;
289 const uint32 B_BOOT_DISK
= 3507;
290 // map /boot into the directory_which enum for convenience
292 class WellKnowEntryList
{
293 // matches up names, id's and node_refs of well known entries in the
296 struct WellKnownEntry
{
297 WellKnownEntry(const node_ref
* node
, directory_which which
,
306 // mwcc needs these explicitly to use vector
307 WellKnownEntry(const WellKnownEntry
&clone
)
320 directory_which which
;
324 static directory_which
Match(const node_ref
*);
325 static const WellKnownEntry
* MatchEntry(const node_ref
*);
329 const WellKnownEntry
* MatchEntryCommon(const node_ref
*);
331 void AddOne(directory_which
, const char* name
);
332 void AddOne(directory_which
, const char* path
, const char* name
);
333 void AddOne(directory_which
, directory_which base
,
334 const char* extension
, const char* name
);
336 std::vector
<WellKnownEntry
> entries
;
337 static WellKnowEntryList
* self
;
340 #if B_BEOS_VERSION_DANO
341 #undef _IMPEXP_TRACKER
344 } // namespace BPrivate
346 using namespace BPrivate
;