VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/xpcom/MoreFiles/FSCopyObject.h@ 4837

Last change on this file since 4837 was 4481, checked in by vboxsync, 17 years ago

remove Apple disclaimer as permitted by original disclaimer and make it MPL/GPL

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.0 KB
Line 
1/*
2 File: FSCopyObject.h
3
4 Contains: A Copy/Delete Files/Folders engine which uses the HFS+ API's
5
6*/
7
8/* ***** BEGIN LICENSE BLOCK *****
9 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
10 *
11 * The contents of this file are subject to the Mozilla Public License Version
12 * 1.1 (the "License"); you may not use this file except in compliance with
13 * the License. You may obtain a copy of the License at
14 * http://www.mozilla.org/MPL/
15 *
16 * Software distributed under the License is distributed on an "AS IS" basis,
17 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
18 * for the specific language governing rights and limitations under the
19 * License.
20 *
21 * The Original Code is Mozilla Communicator client code, released
22 * March 31, 1998.
23 *
24 * The Initial Developer of the Original Code is
25 * Netscape Communications Corporation.
26 * Portions created by the Initial Developer are Copyright (C) 2000
27 * the Initial Developer. All Rights Reserved.
28 *
29 * Contributor(s):
30 *
31 * Alternatively, the contents of this file may be used under the terms of
32 * either of the GNU General Public License Version 2 or later (the "GPL"),
33 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
34 * in which case the provisions of the GPL or the LGPL are applicable instead
35 * of those above. If you wish to allow use of your version of this file only
36 * under the terms of either the GPL or the LGPL, and not to allow others to
37 * use your version of this file under the terms of the MPL, indicate your
38 * decision by deleting the provisions above and replace them with the notice
39 * and other provisions required by the GPL or the LGPL. If you do not delete
40 * the provisions above, a recipient may use your version of this file under
41 * the terms of any one of the MPL, the GPL or the LGPL.
42 *
43 * ***** END LICENSE BLOCK ***** */
44
45
46// Modified 2006-01-23 - added this comment.
47
48#ifndef __FSCOPYOBJECT_H__
49#define __FSCOPYOBJECT_H__
50
51#include <Files.h>
52
53#ifdef __cplusplus
54extern "C" {
55#endif
56
57#define DEBUG_COPY_OBJECT 0 // set to zero if you don't want debug spew
58
59#define QuoteExceptionString(x) #x
60
61#if DEBUG_COPY_OBJECT
62 #include <stdio.h>
63
64 #define mycheck_noerr(error) \
65 do { \
66 OSStatus localError = error; \
67 if (localError == noErr) ; \
68 else { \
69 printf(QuoteExceptionString(error) " != noErr in File: %s, Function: %s, Line: %d, Error: %d\n", \
70 __FILE__, __FUNCTION__, __LINE__, localError); \
71 } \
72 } while (false)
73
74 #define mycheck(assertion) \
75 do { \
76 if (assertion) ; \
77 else { \
78 printf(QuoteExceptionString(assertion) " failed in File: %s, Function: %s, Line: %d\n", \
79 __FILE__, __FUNCTION__, __LINE__); \
80 } \
81 } while (false)
82 #define myverify(assertion) mycheck(assertion)
83 #define myverify_noerr(assertion) mycheck_noerr( (assertion) )
84#else
85 #define mycheck(assertion)
86 #define mycheck_noerr(err)
87 #define myverify(assertion) do { (void) (assertion); } while (0)
88 #define myverify_noerr(assertion) myverify(assertion)
89#endif
90
91/*
92 This code is a combination of MoreFilesX (by Jim Luther) and MPFileCopy (by Quinn)
93 with some added features and bug fixes. This code will run in OS 9.1 and up
94 and 10.1.x (Classic and Carbon)
95*/
96
97/*****************************************************************************/
98
99#pragma mark CopyObjectFilterProcPtr
100
101/*
102 This is the prototype for the CallCopyObjectFilterProc function which
103 is called once for each file and directory found by FSCopyObject.
104 The CallCopyObjectFilterProc can use the read-only data it receives for
105 whatever it wants.
106
107 The result of the CallCopyObjectFilterProc function indicates if
108 iteration should be stopped. To stop iteration, return true; to continue
109 iteration, return false.
110
111 The yourDataPtr parameter can point to whatever data structure you might
112 want to access from within the CallCopyObjectFilterProc.
113
114 containerChanged --> Set to true if the container's contents changed
115 during iteration.
116 currentLevel --> The current recursion level into the container.
117 1 = the container, 2 = the container's immediate
118 subdirectories, etc.
119 currentOSErr --> The current error code, shows the results of the
120 copy of the current object (ref)
121 catalogInfo --> The catalog information for the current object.
122 Only the fields requested by the whichInfo
123 parameter passed to FSIterateContainer are valid.
124 ref --> The FSRef to the current object.
125 spec --> The FSSpec to the current object if the wantFSSpec
126 parameter passed to FSCopyObject is true.
127 name --> The name of the current object if the wantName
128 parameter passed to FSCopyObject is true.
129 yourDataPtr --> An optional pointer to whatever data structure you
130 might want to access from within the
131 CallCopyObjectFilterProc.
132 result <-- To stop iteration, return true; to continue
133 iteration, return false.
134
135 __________
136
137 Also see: FSCopyObject
138*/
139
140typedef CALLBACK_API( Boolean , CopyObjectFilterProcPtr ) (
141 Boolean containerChanged,
142 ItemCount currentLevel,
143 OSErr currentOSErr,
144 const FSCatalogInfo *catalogInfo,
145 const FSRef *ref,
146 const FSSpec *spec,
147 const HFSUniStr255 *name,
148 void *yourDataPtr);
149
150
151/*****************************************************************************/
152
153#pragma mark CallCopyObjectFilterProc
154
155#define CallCopyObjectFilterProc(userRoutine, containerChanged, currentLevel, currentOSErr, catalogInfo, ref, spec, name, yourDataPtr) \
156 (*(userRoutine))((containerChanged), (currentLevel), (currentOSErr), (catalogInfo), (ref), (spec), (name), (yourDataPtr))
157
158/*****************************************************************************/
159
160#pragma mark FSCopyObject
161
162/*
163 The FSCopyObject function takes a source object (can be a file or directory)
164 and copies it (and its contents if it's a directory) to the new destination
165 directory.
166
167 It will call your CopyObjectFilterProcPtr once for each file/directory
168 copied
169
170 The maxLevels parameter is only used when the object is a directory,
171 ignored otherwise.
172 It lets you control how deep the recursion goes.
173 If maxLevels is 1, FSCopyObject only scans the specified directory;
174 if maxLevels is 2, FSCopyObject scans the specified directory and
175 one subdirectory below the specified directory; etc. Set maxLevels to
176 zero to scan all levels.
177
178 The yourDataPtr parameter can point to whatever data structure you might
179 want to access from within your CopyObjectFilterProcPtr.
180
181 source --> The FSRef to the object you want to copy
182 destDir --> The FSRef to the directory you wish to copy source to
183 maxLevels --> Maximum number of directory levels to scan or
184 zero to scan all directory levels, ignored if the
185 object is a file
186 whichInfo --> The fields of the FSCatalogInfo you wish passed
187 to you in your CopyObjectFilterProc
188 wantFSSpec --> Set to true if you want the FSSpec to each
189 object passed to your CopyObjectFilterProc.
190 wantName --> Set to true if you want the name of each
191 object passed to your CopyObjectFilterProc.
192 iterateFilter --> A pointer to the CopyObjectFilterProc you
193 want called once for each object found
194 by FSCopyObject.
195 yourDataPtr --> An optional pointer to whatever data structure you
196 might want to access from within the
197 CopyObjectFilterProc.
198*/
199
200OSErr FSCopyObject( const FSRef *source,
201 const FSRef *destDir,
202 UniCharCount nameLength,
203 const UniChar *copyName, // can be NULL (no rename during copy)
204 ItemCount maxLevels,
205 FSCatalogInfoBitmap whichInfo,
206 Boolean wantFSSpec,
207 Boolean wantName,
208 CopyObjectFilterProcPtr filterProcPtr, // can be NULL
209 void *yourDataPtr, // can be NULL
210 FSRef *newObject); // can be NULL
211
212/*****************************************************************************/
213
214#pragma mark FSDeleteObjects
215
216/*
217 The FSDeleteObjects function takes an FSRef to a file or directory
218 and attempts to delete it. If the object is a directory, all files
219 and subdirectories in the specified directory are deleted. If a
220 locked file or directory is encountered, it is unlocked and then
221 deleted. After deleting the directory's contents, the directory
222 is deleted. If any unexpected errors are encountered,
223 FSDeleteContainer quits and returns to the caller.
224
225 source --> FSRef to an object (can be file or directory).
226
227 __________
228*/
229
230OSErr FSDeleteObjects( const FSRef *source );
231
232#ifdef __cplusplus
233}
234#endif
235
236#endif
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use