102be5353SAxel Dörfler/*
202be5353SAxel DörflerOpen Tracker License
302be5353SAxel Dörfler
402be5353SAxel DörflerTerms and Conditions
502be5353SAxel Dörfler
602be5353SAxel DörflerCopyright (c) 1991-2000, Be Incorporated. All rights reserved.
702be5353SAxel Dörfler
802be5353SAxel DörflerPermission is hereby granted, free of charge, to any person obtaining a copy of
902be5353SAxel Dörflerthis software and associated documentation files (the "Software"), to deal in
1002be5353SAxel Dörflerthe Software without restriction, including without limitation the rights to
1102be5353SAxel Dörfleruse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
1202be5353SAxel Dörflerof the Software, and to permit persons to whom the Software is furnished to do
1302be5353SAxel Dörflerso, subject to the following conditions:
1402be5353SAxel Dörfler
1502be5353SAxel DörflerThe above copyright notice and this permission notice applies to all licensees
1602be5353SAxel Dörflerand shall be included in all copies or substantial portions of the Software.
1702be5353SAxel Dörfler
2402be5353SAxel Dörfler
2502be5353SAxel DörflerExcept as contained in this notice, the name of Be Incorporated shall not be
2602be5353SAxel Dörflerused in advertising or otherwise to promote the sale, use or other dealings in
2702be5353SAxel Dörflerthis Software without prior written authorization from Be Incorporated.
2802be5353SAxel Dörfler
2902be5353SAxel DörflerTracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
3002be5353SAxel Dörflerof Be Incorporated in the United States and other countries. Other brand product
3102be5353SAxel Dörflernames are registered trademarks or trademarks of their respective holders.
3202be5353SAxel DörflerAll rights reserved.
3302be5353SAxel Dörfler*/
34b05aa8b5SJohn Scipione#ifndef FS_UTILS_H
35b05aa8b5SJohn Scipione#define FS_UTILS_H
3602be5353SAxel Dörfler
3702be5353SAxel Dörfler
3802be5353SAxel Dörfler#include <FindDirectory.h>
3902be5353SAxel Dörfler#include <List.h>
40aee40335SJohn Scipione#include <ObjectList.h>
4102be5353SAxel Dörfler#include <Point.h>
4202be5353SAxel Dörfler#include <StorageDefs.h>
4302be5353SAxel Dörfler
4402be5353SAxel Dörfler#include <vector>
4502be5353SAxel Dörfler
4602be5353SAxel Dörfler#include "Model.h"
4702be5353SAxel Dörfler
48b05aa8b5SJohn Scipione
49a51764c5SJohn Scipione// APIs/code in FSUtils.h and FSUtils.cpp is slated for a major cleanup
50a51764c5SJohn Scipione// -- in other words, you will find a lot of ugly cruft in here
5102be5353SAxel Dörfler
5202be5353SAxel Dörflerclass BDirectory;
5302be5353SAxel Dörflerclass BEntry;
5402be5353SAxel Dörflerclass BList;
5502be5353SAxel Dörflerclass BFile;
5602be5353SAxel Dörfler
5702be5353SAxel Dörflernamespace BPrivate {
5802be5353SAxel Dörfler
5902be5353SAxel Dörflerclass BInfoWindow;
6002be5353SAxel Dörfler
619869082cSStephan Aßmus//! Controls the copy engine; may be overriden to specify how conflicts are
629869082cSStephan Aßmus// handled, etc.
6302be5353SAxel Dörflerclass CopyLoopControl {
649869082cSStephan Aßmuspublic:
659869082cSStephan Aßmus	virtual						~CopyLoopControl();
669869082cSStephan Aßmus
673cc5c3ffSStephan Aßmus	virtual	void				Init(uint32 jobKind);
683cc5c3ffSStephan Aßmus	virtual	void				Init(int32 totalItems, off_t totalSize,
693cc5c3ffSStephan Aßmus									const entry_ref* destDir = NULL,
703cc5c3ffSStephan Aßmus									bool showCount = true);
713cc5c3ffSStephan Aßmus
729869082cSStephan Aßmus	//! Inform that a file error occurred while copying <name>.
739869082cSStephan Aßmus	// \return \c True if user decided to continue
743cc5c3ffSStephan Aßmus	virtual	bool				FileError(const char* message,
753cc5c3ffSStephan Aßmus									const char* name, status_t error,
763cc5c3ffSStephan Aßmus									bool allowContinue);
779869082cSStephan Aßmus
783cc5c3ffSStephan Aßmus	virtual	void				UpdateStatus(const char* name,
799869082cSStephan Aßmus									const entry_ref& ref, int32 count,
803cc5c3ffSStephan Aßmus									bool optional = false);
819869082cSStephan Aßmus
829869082cSStephan Aßmus	//! \return \c true if canceled
833cc5c3ffSStephan Aßmus	virtual	bool				CheckUserCanceled();
849869082cSStephan Aßmus
859869082cSStephan Aßmus			enum OverwriteMode {
869869082cSStephan Aßmus				kSkip,			// do not replace, go to next entry
879869082cSStephan Aßmus				kReplace,		// remove entry before copying new one
889869082cSStephan Aßmus				kMerge			// for folders: leave existing folder, update
899869082cSStephan Aßmus								// contents leaving nonconflicting items
90ea001e58SJohn Scipione								// for files: save original attributes on file
919869082cSStephan Aßmus			};
929869082cSStephan Aßmus
939869082cSStephan Aßmus	//! Override to always overwrite, never overwrite, let user decide,
949869082cSStephan Aßmus	// compare dates, etc.
953cc5c3ffSStephan Aßmus	virtual	OverwriteMode		OverwriteOnConflict(const BEntry* srcEntry,
963cc5c3ffSStephan Aßmus									const char* destName,
973cc5c3ffSStephan Aßmus									const BDirectory* destDir,
983cc5c3ffSStephan Aßmus									bool srcIsDir, bool dstIsDir);
999869082cSStephan Aßmus
1009869082cSStephan Aßmus	//! Override to prevent copying of a given file or directory
101b05aa8b5SJohn Scipione	virtual	bool				SkipEntry(const BEntry*, bool file);
1029869082cSStephan Aßmus
1039869082cSStephan Aßmus	//! During a file copy, this is called every time a chunk of data
1049869082cSStephan Aßmus	// is copied.  Users may override to keep a running checksum.
1053cc5c3ffSStephan Aßmus	virtual	void				ChecksumChunk(const char* block, size_t size);
1069869082cSStephan Aßmus
1079869082cSStephan Aßmus	//! This is called when a file is finished copying.  Users of this
1089869082cSStephan Aßmus	// class may override to verify that the checksum they've been
1099869082cSStephan Aßmus	// computing in ChecksumChunk matches.  If this returns true,
1109869082cSStephan Aßmus	// the copy will continue.  If false, if will abort.
1113cc5c3ffSStephan Aßmus	virtual	bool				ChecksumFile(const entry_ref*);
1129869082cSStephan Aßmus
1133cc5c3ffSStephan Aßmus	virtual	bool				SkipAttribute(const char* attributeName);
1143cc5c3ffSStephan Aßmus	virtual	bool				PreserveAttribute(const char* attributeName);
1159869082cSStephan Aßmus};
11602be5353SAxel Dörfler
11702be5353SAxel Dörfler
1189869082cSStephan Aßmus//! This is the Tracker copy-specific version of CopyLoopControl.
1199869082cSStephan Aßmusclass TrackerCopyLoopControl : public CopyLoopControl {
1209869082cSStephan Aßmuspublic:
1213cc5c3ffSStephan Aßmus								TrackerCopyLoopControl();
1223cc5c3ffSStephan Aßmus								TrackerCopyLoopControl(uint32 jobKind);
1233cc5c3ffSStephan Aßmus								TrackerCopyLoopControl(int32 totalItems,
1243cc5c3ffSStephan Aßmus									off_t totalSize);
1259869082cSStephan Aßmus	virtual						~TrackerCopyLoopControl();
12602be5353SAxel Dörfler
1273cc5c3ffSStephan Aßmus	virtual	void				Init(uint32 state);
1283cc5c3ffSStephan Aßmus	virtual	void				Init(int32 totalItems, off_t totalSize,
1293cc5c3ffSStephan Aßmus									const entry_ref* destDir = NULL,
1303cc5c3ffSStephan Aßmus									bool showCount = true);
1313cc5c3ffSStephan Aßmus
132b05aa8b5SJohn Scipione	virtual	bool				FileError(const char* message,
133b05aa8b5SJohn Scipione									const char* name, status_t error,
1349869082cSStephan Aßmus									bool allowContinue);
13502be5353SAxel Dörfler
136b05aa8b5SJohn Scipione	virtual	void				UpdateStatus(const char* name,
1379869082cSStephan Aßmus									const entry_ref& ref, int32 count,
1389869082cSStephan Aßmus									bool optional = false);
13902be5353SAxel Dörfler
1409869082cSStephan Aßmus	virtual	bool				CheckUserCanceled();
14102be5353SAxel Dörfler
142b05aa8b5SJohn Scipione	virtual	bool				SkipAttribute(const char* attributeName);
14302be5353SAxel Dörfler
14402be5353SAxel Dörfler
1459869082cSStephan Aßmus	// One can specify an entry_ref list with the source entries. This will
1469869082cSStephan Aßmus	// then trigger the feature to pull additional source entries from the
1479869082cSStephan Aßmus	// status window, such that the user can drop additional items onto the
1489869082cSStephan Aßmus	// progress display of the ongoing copy process to copy these items to
1499869082cSStephan Aßmus	// the same target directory.
1509869082cSStephan Aßmus			typedef BObjectList<entry_ref> EntryList;
15102be5353SAxel Dörfler
1529869082cSStephan Aßmus			void				SetSourceList(EntryList* list);
15302be5353SAxel Dörfler
1549869082cSStephan Aßmusprivate:
1559869082cSStephan Aßmus			thread_id			fThread;
15602be5353SAxel Dörfler
1579869082cSStephan Aßmus			EntryList*			fSourceList;
15802be5353SAxel Dörfler};
15902be5353SAxel Dörfler
16002be5353SAxel Dörfler
16102be5353SAxel Dörfler#define B_DESKTOP_DIR_NAME "Desktop"
1629437e677SJohn Scipione#define B_DISKS_DIR_NAME "Disks"
1639437e677SJohn Scipione#define B_TRASH_DIR_NAME "Trash"
16402be5353SAxel Dörfler
165f6e4cbb9SAxel Dörfler#ifndef _IMPEXP_TRACKER
16602be5353SAxel Dörfler#define _IMPEXP_TRACKER
16702be5353SAxel Dörfler#endif
168606ae81aSAugustin Cavalier_IMPEXP_TRACKER status_t FSCopyAttributesAndStats(BNode*, BNode*, bool = true);
169b05aa8b5SJohn Scipione
170a51764c5SJohn Scipione_IMPEXP_TRACKER void FSDuplicate(BObjectList<entry_ref>* srcList,
171a51764c5SJohn Scipione	BList* pointList);
172a51764c5SJohn Scipione_IMPEXP_TRACKER void FSMoveToFolder(BObjectList<entry_ref>* srcList, BEntry*,
173a51764c5SJohn Scipione	uint32 moveMode, BList* pointList = NULL);
174a51764c5SJohn Scipione_IMPEXP_TRACKER void FSMakeOriginalName(char* name, BDirectory* destDir,
175a51764c5SJohn Scipione	const char* suffix);
176b05aa8b5SJohn Scipione_IMPEXP_TRACKER bool FSIsTrashDir(const BEntry*);
177b05aa8b5SJohn Scipione_IMPEXP_TRACKER bool FSIsPrintersDir(const BEntry*);
178b05aa8b5SJohn Scipione_IMPEXP_TRACKER bool FSIsDeskDir(const BEntry*);
179b05aa8b5SJohn Scipione_IMPEXP_TRACKER bool FSIsHomeDir(const BEntry*);
180b05aa8b5SJohn Scipione_IMPEXP_TRACKER bool FSIsRootDir(const BEntry*);
181a51764c5SJohn Scipione_IMPEXP_TRACKER void FSMoveToTrash(BObjectList<entry_ref>* srcList,
182a51764c5SJohn Scipione	BList* pointList = NULL, bool async = true);
18302be5353SAxel Dörfler	// Deprecated
18402be5353SAxel Dörfler
185b05aa8b5SJohn Scipionevoid FSDeleteRefList(BObjectList<entry_ref>*, bool, bool confirm = true);
186b05aa8b5SJohn Scipionevoid FSDelete(entry_ref*, bool, bool confirm = true);
187b05aa8b5SJohn Scipionevoid FSRestoreRefList(BObjectList<entry_ref>* list, bool async);
18802be5353SAxel Dörfler
189a51764c5SJohn Scipione_IMPEXP_TRACKER status_t FSLaunchItem(const entry_ref* application,
190a51764c5SJohn Scipione	const BMessage* refsReceived, bool async, bool openWithOK);
191a51764c5SJohn Scipione	// Preferred way of launching; only pass an actual application in
192a51764c5SJohn Scipione	// <application>, not a document; to open documents with the preferred
193a51764c5SJohn Scipione	// app, pase 0 in <application> and stuff all the document refs into
194a51764c5SJohn Scipione	// <refsReceived> Consider having silent mode that does not show alerts,
195a51764c5SJohn Scipione	// just returns error code
196317bd7ddSAxel Dörfler
197b05aa8b5SJohn Scipione_IMPEXP_TRACKER status_t FSOpenWith(BMessage* listOfRefs);
19802be5353SAxel Dörfler	// runs the Open With window; pas a list of refs
19902be5353SAxel Dörfler
20002be5353SAxel Dörfler_IMPEXP_TRACKER void FSEmptyTrash();
201a51764c5SJohn Scipione_IMPEXP_TRACKER status_t FSCreateNewFolderIn(const node_ref* destDir,
202a51764c5SJohn Scipione	entry_ref* newRef, node_ref* new_node);
20302be5353SAxel Dörfler_IMPEXP_TRACKER void FSCreateTrashDirs();
204b05aa8b5SJohn Scipione_IMPEXP_TRACKER status_t FSGetTrashDir(BDirectory* trashDir, dev_t volume);
205b05aa8b5SJohn Scipione_IMPEXP_TRACKER status_t FSGetDeskDir(BDirectory* deskDir);
206b05aa8b5SJohn Scipione_IMPEXP_TRACKER status_t FSRecursiveCalcSize(BInfoWindow*,
207b05aa8b5SJohn Scipione	CopyLoopControl* loopControl, BDirectory*, off_t* runningSize,
208b05aa8b5SJohn Scipione	int32* fileCount, int32* dirCount);
20902be5353SAxel Dörfler
210b05aa8b5SJohn Scipionebool FSInTrashDir(const entry_ref*);
21102be5353SAxel Dörfler
21202be5353SAxel Dörfler// doesn't need to be exported
213b05aa8b5SJohn Scipionebool FSGetPoseLocation(const BNode* node, BPoint* point);
214b05aa8b5SJohn Scipionestatus_t FSSetPoseLocation(BEntry* entry, BPoint point);
215b05aa8b5SJohn Scipionestatus_t FSSetPoseLocation(ino_t destDirInode, BNode* destNode, BPoint point);
216b05aa8b5SJohn Scipionestatus_t FSGetBootDeskDir(BDirectory* deskDir);
21702be5353SAxel Dörfler
218b05aa8b5SJohn Scipionestatus_t FSGetOriginalPath(BEntry* entry, BPath* path);
21902be5353SAxel Dörfler
22002be5353SAxel Dörflerenum ReadAttrResult {
22102be5353SAxel Dörfler	kReadAttrFailed,
22202be5353SAxel Dörfler	kReadAttrNativeOK,
22302be5353SAxel Dörfler	kReadAttrForeignOK
22402be5353SAxel Dörfler};
22502be5353SAxel Dörfler
226a51764c5SJohn ScipioneReadAttrResult ReadAttr(const BNode*, const char* hostAttrName,
227a51764c5SJohn Scipione	const char* foreignAttrName, type_code, off_t, void*, size_t,
228a51764c5SJohn Scipione	void (*swapFunc)(void*) = 0, bool isForeign = false);
229a51764c5SJohn Scipione	// Endian swapping ReadAttr call; endianness is determined by trying
230a51764c5SJohn Scipione	// first the native attribute name, then the foreign one; an endian
231a51764c5SJohn Scipione	// swapping function can be passed, if null data won't be swapped;
232a51764c5SJohn Scipione	// if <isForeign> set the foreign endianness will be read directly
233a51764c5SJohn Scipione	// without first trying the native one
234317bd7ddSAxel Dörfler
235a51764c5SJohn ScipioneReadAttrResult GetAttrInfo(const BNode*, const char* hostAttrName,
236a51764c5SJohn Scipione	const char* foreignAttrName, type_code* = NULL, size_t* = NULL);
23702be5353SAxel Dörfler
238b05aa8b5SJohn Scipionestatus_t FSCreateNewFolder(const entry_ref*);
239b05aa8b5SJohn Scipionestatus_t FSRecursiveCreateFolder(const char* path);
240a51764c5SJohn Scipionevoid FSMakeOriginalName(BString &name, const BDirectory* destDir,
241a51764c5SJohn Scipione	const char* suffix = 0);
24202be5353SAxel Dörfler
2431c29b26eSIngo Weinholdstatus_t FSGetParentVirtualDirectoryAware(const BEntry& entry, entry_ref& _ref);
2441c29b26eSIngo Weinholdstatus_t FSGetParentVirtualDirectoryAware(const BEntry& entry, BEntry& _entry);
2451c29b26eSIngo Weinholdstatus_t FSGetParentVirtualDirectoryAware(const BEntry& entry, BNode& _node);
2461c29b26eSIngo Weinhold
247ab28908dSJohn Scipionestatus_t TrackerLaunch(const entry_ref* appRef, bool async);
248a51764c5SJohn Scipionestatus_t TrackerLaunch(const BMessage* refs, bool async,
249a51764c5SJohn Scipione	bool okToRunOpenWith = true);
250ab28908dSJohn Scipionestatus_t TrackerLaunch(const entry_ref* appRef, const BMessage* refs,
251ab28908dSJohn Scipione	bool async, bool okToRunOpenWith = true);
25202be5353SAxel Dörfler
253b05aa8b5SJohn Scipionestatus_t FSFindTrackerSettingsDir(BPath*, bool autoCreate = true);
25402be5353SAxel Dörfler
255b05aa8b5SJohn Scipionebool FSIsDeskDir(const BEntry*);
25602be5353SAxel Dörfler
2574072c4f1SAdrien Destuguesenum DestructiveAction {
2584072c4f1SAdrien Destugues	kRename,
2594072c4f1SAdrien Destugues	kMove
2604072c4f1SAdrien Destugues};
2614072c4f1SAdrien Destugues
262b05aa8b5SJohn Scipionebool ConfirmChangeIfWellKnownDirectory(const BEntry* entry,
2634072c4f1SAdrien Destugues	DestructiveAction action, bool dontAsk = false,
264b05aa8b5SJohn Scipione	int32* confirmedAlready = NULL);
26502be5353SAxel Dörfler
266b05aa8b5SJohn Scipionebool CheckDevicesEqual(const entry_ref* entry, const Model* targetModel);
267d3b11328SRene Gollent
26802be5353SAxel Dörfler// Deprecated calls use newer calls above instead
269ab28908dSJohn Scipione_IMPEXP_TRACKER void FSLaunchItem(const entry_ref* appRef,
270ab28908dSJohn Scipione	BMessage* refs = NULL, int32 workspace = -1);
271ab28908dSJohn Scipione_IMPEXP_TRACKER status_t FSLaunchItem(const entry_ref* appRef,
272ab28908dSJohn Scipione	BMessage* refs, int32 workspace, bool asynch);
273b05aa8b5SJohn Scipione_IMPEXP_TRACKER void FSOpenWithDocuments(const entry_ref* executableToLaunch,
274b05aa8b5SJohn Scipione	BMessage* documentEntryRefs);
275a51764c5SJohn Scipione_IMPEXP_TRACKER status_t FSLaunchUsing(const entry_ref* ref,
276a51764c5SJohn Scipione	BMessage* listOfRefs);
27702be5353SAxel Dörfler
27802be5353SAxel Dörfler
279aa56e459SJérôme Duval// some extra directory_which values
280aa56e459SJérôme Duval// move these to FindDirectory.h
281aa56e459SJérôme Duvalconst uint32 B_USER_MAIL_DIRECTORY = 3500;
282aa56e459SJérôme Duvalconst uint32 B_USER_QUERIES_DIRECTORY = 3501;
283aa56e459SJérôme Duvalconst uint32 B_USER_PEOPLE_DIRECTORY = 3502;
284aa56e459SJérôme Duvalconst uint32 B_USER_DOWNLOADS_DIRECTORY = 3503;
285aa56e459SJérôme Duvalconst uint32 B_USER_DESKBAR_APPS_DIRECTORY = 3504;
286aa56e459SJérôme Duvalconst uint32 B_USER_DESKBAR_PREFERENCES_DIRECTORY = 3505;
287aa56e459SJérôme Duvalconst uint32 B_USER_DESKBAR_DEVELOP_DIRECTORY = 3506;
288aa56e459SJérôme Duvalconst uint32 B_BOOT_DISK = 3507;
289aa56e459SJérôme Duval	// map /boot into the directory_which enum for convenience
290aa56e459SJérôme Duval
29102be5353SAxel Dörflerclass WellKnowEntryList {
29202be5353SAxel Dörfler	// matches up names, id's and node_refs of well known entries in the
29302be5353SAxel Dörfler	// system hierarchy
29402be5353SAxel Dörfler	public:
29502be5353SAxel Dörfler		struct WellKnownEntry {
296a51764c5SJohn Scipione			WellKnownEntry(const node_ref* node, directory_which which,
297a51764c5SJohn Scipione				const char* name)
29802be5353SAxel Dörfler				:
29902be5353SAxel Dörfler				node(*node),
30002be5353SAxel Dörfler				which(which),
30102be5353SAxel Dörfler				name(name)
30202be5353SAxel Dörfler			{
30302be5353SAxel Dörfler			}
30402be5353SAxel Dörfler
30502be5353SAxel Dörfler			// mwcc needs these explicitly to use vector
30602be5353SAxel Dörfler			WellKnownEntry(const WellKnownEntry &clone)
30702be5353SAxel Dörfler				:
30802be5353SAxel Dörfler				node(clone.node),
30902be5353SAxel Dörfler				which(clone.which),
31002be5353SAxel Dörfler				name(clone.name)
31102be5353SAxel Dörfler			{
31202be5353SAxel Dörfler			}
31302be5353SAxel Dörfler
31402be5353SAxel Dörfler			WellKnownEntry()
31502be5353SAxel Dörfler			{
31602be5353SAxel Dörfler			}
31702be5353SAxel Dörfler
31802be5353SAxel Dörfler			node_ref node;
31902be5353SAxel Dörfler			directory_which which;
320140f3bd8SRene Gollent			BString name;
32102be5353SAxel Dörfler		};
32202be5353SAxel Dörfler
323b05aa8b5SJohn Scipione		static directory_which Match(const node_ref*);
324b05aa8b5SJohn Scipione		static const WellKnownEntry* MatchEntry(const node_ref*);
32502be5353SAxel Dörfler		static void Quit();
32602be5353SAxel Dörfler
32702be5353SAxel Dörfler	private:
328b05aa8b5SJohn Scipione		const WellKnownEntry* MatchEntryCommon(const node_ref*);
32902be5353SAxel Dörfler		WellKnowEntryList();
330b05aa8b5SJohn Scipione		void AddOne(directory_which, const char* name);
331b05aa8b5SJohn Scipione		void AddOne(directory_which, const char* path, const char* name);
332a51764c5SJohn Scipione		void AddOne(directory_which, directory_which base,
333a51764c5SJohn Scipione			const char* extension, const char* name);
33402be5353SAxel Dörfler
33502be5353SAxel Dörfler		std::vector<WellKnownEntry> entries;
336b05aa8b5SJohn Scipione		static WellKnowEntryList* self;
33702be5353SAxel Dörfler};
33802be5353SAxel Dörfler
33902be5353SAxel Dörfler#if B_BEOS_VERSION_DANO
34002be5353SAxel Dörfler#undef _IMPEXP_TRACKER
34102be5353SAxel Dörfler#endif
34202be5353SAxel Dörfler
34302be5353SAxel Dörfler} // namespace BPrivate
34402be5353SAxel Dörfler
34502be5353SAxel Dörflerusing namespace BPrivate;
34602be5353SAxel Dörfler
347b05aa8b5SJohn Scipione#endif	// FS_UTILS_H