]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/morefile/MoreFiles.c
support for default key handling (escape,enter,command-period) even if there is no...
[wxWidgets.git] / src / mac / carbon / morefile / MoreFiles.c
1 /*
2 File: MoreFiles.c
3
4 Contains: The long lost high-level and FSSpec File Manager functions.
5
6 Version: MoreFiles
7
8 Copyright: © 1992-2001 by Apple Computer, Inc., all rights reserved.
9
10 You may incorporate this sample code into your applications without
11 restriction, though the sample code has been provided "AS IS" and the
12 responsibility for its operation is 100% yours. However, what you are
13 not permitted to do is to redistribute the source as "DSC Sample Code"
14 after having made changes. If you're going to re-distribute the source,
15 we require that you make it clear in the source that the code was
16 descended from Apple Sample Code, but that you've made changes.
17
18 File Ownership:
19
20 DRI: Apple Macintosh Developer Technical Support
21
22 Other Contact: Apple Macintosh Developer Technical Support
23 <http://developer.apple.com/bugreporter/>
24
25 Technology: DTS Sample Code
26
27 Writers:
28
29 (JL) Jim Luther
30
31 Change History (most recent first):
32
33 <2> 2/7/01 JL Added standard header. Updated names of includes.
34 <1> 12/06/99 JL MoreFiles 1.5.
35 */
36
37 #include <MacTypes.h>
38 #include <MacErrors.h>
39 #include <Files.h>
40
41 #define __COMPILINGMOREFILES
42
43 #include "MoreFiles.h"
44 #include "MoreFilesExtras.h"
45
46 /*****************************************************************************/
47
48 pascal OSErr HGetVolParms(ConstStr255Param volName,
49 short vRefNum,
50 GetVolParmsInfoBuffer *volParmsInfo,
51 long *infoSize)
52 {
53 HParamBlockRec pb;
54 OSErr error;
55
56 pb.ioParam.ioNamePtr = (StringPtr)volName;
57 pb.ioParam.ioVRefNum = vRefNum;
58 pb.ioParam.ioBuffer = (Ptr)volParmsInfo;
59 pb.ioParam.ioReqCount = *infoSize;
60 error = PBHGetVolParmsSync(&pb);
61 if ( error == noErr )
62 {
63 *infoSize = pb.ioParam.ioActCount;
64 }
65 return ( error );
66 }
67
68 /*****************************************************************************/
69
70 pascal OSErr HCreateMinimum(short vRefNum,
71 long dirID,
72 ConstStr255Param fileName)
73 {
74 HParamBlockRec pb;
75
76 pb.fileParam.ioNamePtr = (StringPtr)fileName;
77 pb.fileParam.ioVRefNum = vRefNum;
78 pb.ioParam.ioVersNum = 0;
79 pb.fileParam.ioDirID = dirID;
80 return ( PBHCreateSync(&pb) );
81 }
82
83 /*****************************************************************************/
84
85 pascal OSErr FSpCreateMinimum(const FSSpec *spec)
86 {
87 return ( HCreateMinimum(spec->vRefNum, spec->parID, spec->name) );
88 }
89
90 /*****************************************************************************/
91
92 pascal OSErr ExchangeFiles(short vRefNum,
93 long srcDirID,
94 ConstStr255Param srcName,
95 long dstDirID,
96 ConstStr255Param dstName)
97 {
98 HParamBlockRec pb;
99
100 pb.fidParam.ioVRefNum = vRefNum;
101 pb.fidParam.ioSrcDirID = srcDirID;
102 pb.fidParam.ioNamePtr = (StringPtr)srcName;
103 pb.fidParam.ioDestDirID = dstDirID;
104 pb.fidParam.ioDestNamePtr = (StringPtr)dstName;
105 return ( PBExchangeFilesSync(&pb) );
106 }
107
108 /*****************************************************************************/
109
110 pascal OSErr ResolveFileIDRef(ConstStr255Param volName,
111 short vRefNum,
112 long fileID,
113 long *parID,
114 StringPtr fileName)
115 {
116 HParamBlockRec pb;
117 OSErr error;
118 Str255 tempStr;
119
120 tempStr[0] = 0;
121 if ( volName != NULL )
122 {
123 BlockMoveData(volName, tempStr, volName[0] + 1);
124 }
125 pb.fidParam.ioNamePtr = (StringPtr)tempStr;
126 pb.fidParam.ioVRefNum = vRefNum;
127 pb.fidParam.ioFileID = fileID;
128 error = PBResolveFileIDRefSync(&pb);
129 if ( error == noErr )
130 {
131 *parID = pb.fidParam.ioSrcDirID;
132 if ( fileName != NULL )
133 {
134 BlockMoveData(tempStr, fileName, tempStr[0] + 1);
135 }
136 }
137 return ( error );
138 }
139
140 /*****************************************************************************/
141
142 pascal OSErr FSpResolveFileIDRef(ConstStr255Param volName,
143 short vRefNum,
144 long fileID,
145 FSSpec *spec)
146 {
147 OSErr error;
148
149 error = DetermineVRefNum(volName, vRefNum, &(spec->vRefNum));
150 if ( error == noErr )
151 {
152 error = ResolveFileIDRef(volName, vRefNum, fileID, &(spec->parID), spec->name);
153 }
154 return ( error );
155 }
156
157 /*****************************************************************************/
158
159 pascal OSErr CreateFileIDRef(short vRefNum,
160 long parID,
161 ConstStr255Param fileName,
162 long *fileID)
163 {
164 HParamBlockRec pb;
165 OSErr error;
166
167 pb.fidParam.ioNamePtr = (StringPtr)fileName;
168 pb.fidParam.ioVRefNum = vRefNum;
169 pb.fidParam.ioSrcDirID = parID;
170 error = PBCreateFileIDRefSync(&pb);
171 if ( (error == noErr) || (error == fidExists) || (error == afpIDExists) )
172 {
173 *fileID = pb.fidParam.ioFileID;
174 }
175 return ( error );
176 }
177
178 /*****************************************************************************/
179
180 pascal OSErr FSpCreateFileIDRef(const FSSpec *spec,
181 long *fileID)
182 {
183 return ( CreateFileIDRef(spec->vRefNum, spec->parID, spec->name, fileID) );
184 }
185
186 /*****************************************************************************/
187
188 pascal OSErr DeleteFileIDRef(ConstStr255Param volName,
189 short vRefNum,
190 long fileID)
191 {
192 HParamBlockRec pb;
193
194 pb.fidParam.ioNamePtr = (StringPtr)volName;
195 pb.fidParam.ioVRefNum = vRefNum;
196 pb.fidParam.ioFileID = fileID;
197 return ( PBDeleteFileIDRefSync(&pb) );
198 }
199
200 /*****************************************************************************/
201
202 pascal OSErr FlushFile(short refNum)
203 {
204 ParamBlockRec pb;
205
206 pb.ioParam.ioRefNum = refNum;
207 return ( PBFlushFileSync(&pb) );
208 }
209
210 /*****************************************************************************/
211
212 pascal OSErr LockRange(short refNum,
213 long rangeLength,
214 long rangeStart)
215 {
216 ParamBlockRec pb;
217
218 pb.ioParam.ioRefNum = refNum;
219 pb.ioParam.ioReqCount = rangeLength;
220 pb.ioParam.ioPosMode = fsFromStart;
221 pb.ioParam.ioPosOffset = rangeStart;
222 return ( PBLockRangeSync(&pb) );
223 }
224
225 /*****************************************************************************/
226
227 pascal OSErr UnlockRange(short refNum,
228 long rangeLength,
229 long rangeStart)
230 {
231 ParamBlockRec pb;
232
233 pb.ioParam.ioRefNum = refNum;
234 pb.ioParam.ioReqCount = rangeLength;
235 pb.ioParam.ioPosMode = fsFromStart;
236 pb.ioParam.ioPosOffset = rangeStart;
237 return ( PBUnlockRangeSync(&pb) );
238 }
239
240 /*****************************************************************************/
241
242 pascal OSErr GetForeignPrivs(short vRefNum,
243 long dirID,
244 ConstStr255Param name,
245 void *foreignPrivBuffer,
246 long *foreignPrivSize,
247 long *foreignPrivInfo1,
248 long *foreignPrivInfo2,
249 long *foreignPrivInfo3,
250 long *foreignPrivInfo4)
251 {
252 HParamBlockRec pb;
253 OSErr error;
254
255 pb.foreignPrivParam.ioNamePtr = (StringPtr)name;
256 pb.foreignPrivParam.ioVRefNum = vRefNum;
257 pb.foreignPrivParam.ioForeignPrivDirID = dirID;
258 pb.foreignPrivParam.ioForeignPrivBuffer = (Ptr)foreignPrivBuffer;
259 pb.foreignPrivParam.ioForeignPrivReqCount = *foreignPrivSize;
260 error = PBGetForeignPrivsSync(&pb);
261 *foreignPrivSize = pb.foreignPrivParam.ioForeignPrivActCount;
262 *foreignPrivInfo1 = pb.foreignPrivParam.ioForeignPrivInfo1;
263 *foreignPrivInfo2 = pb.foreignPrivParam.ioForeignPrivInfo2;
264 *foreignPrivInfo3 = pb.foreignPrivParam.ioForeignPrivInfo3;
265 *foreignPrivInfo4 = pb.foreignPrivParam.ioForeignPrivInfo4;
266 return ( error );
267 }
268
269 /*****************************************************************************/
270
271 pascal OSErr FSpGetForeignPrivs(const FSSpec *spec,
272 void *foreignPrivBuffer,
273 long *foreignPrivSize,
274 long *foreignPrivInfo1,
275 long *foreignPrivInfo2,
276 long *foreignPrivInfo3,
277 long *foreignPrivInfo4)
278 {
279 return ( GetForeignPrivs(spec->vRefNum, spec->parID, spec->name,
280 foreignPrivBuffer, foreignPrivSize,
281 foreignPrivInfo1, foreignPrivInfo2,
282 foreignPrivInfo3, foreignPrivInfo4) );
283 }
284
285 /*****************************************************************************/
286
287 pascal OSErr SetForeignPrivs(short vRefNum,
288 long dirID,
289 ConstStr255Param name,
290 const void *foreignPrivBuffer,
291 long *foreignPrivSize,
292 long foreignPrivInfo1,
293 long foreignPrivInfo2,
294 long foreignPrivInfo3,
295 long foreignPrivInfo4)
296 {
297 HParamBlockRec pb;
298 OSErr error;
299
300 pb.foreignPrivParam.ioNamePtr = (StringPtr)name;
301 pb.foreignPrivParam.ioVRefNum = vRefNum;
302 pb.foreignPrivParam.ioForeignPrivDirID = dirID;
303 pb.foreignPrivParam.ioForeignPrivBuffer = (Ptr)foreignPrivBuffer;
304 pb.foreignPrivParam.ioForeignPrivReqCount = *foreignPrivSize;
305 pb.foreignPrivParam.ioForeignPrivInfo1 = foreignPrivInfo1;
306 pb.foreignPrivParam.ioForeignPrivInfo2 = foreignPrivInfo2;
307 pb.foreignPrivParam.ioForeignPrivInfo3 = foreignPrivInfo3;
308 pb.foreignPrivParam.ioForeignPrivInfo4 = foreignPrivInfo4;
309 error = PBSetForeignPrivsSync(&pb);
310 if ( error == noErr )
311 {
312 *foreignPrivSize = pb.foreignPrivParam.ioForeignPrivActCount;
313 }
314 return ( error );
315 }
316
317 /*****************************************************************************/
318
319 pascal OSErr FSpSetForeignPrivs(const FSSpec *spec,
320 const void *foreignPrivBuffer,
321 long *foreignPrivSize,
322 long foreignPrivInfo1,
323 long foreignPrivInfo2,
324 long foreignPrivInfo3,
325 long foreignPrivInfo4)
326 {
327 return ( SetForeignPrivs(spec->vRefNum, spec->parID, spec->name,
328 foreignPrivBuffer, foreignPrivSize,
329 foreignPrivInfo1, foreignPrivInfo2,
330 foreignPrivInfo3, foreignPrivInfo4) );
331 }
332
333 /*****************************************************************************/
334
335 pascal OSErr HGetLogInInfo(ConstStr255Param volName,
336 short vRefNum,
337 short *loginMethod,
338 StringPtr userName)
339 {
340 HParamBlockRec pb;
341 OSErr error;
342
343 pb.objParam.ioNamePtr = (StringPtr)volName;
344 pb.objParam.ioVRefNum = vRefNum;
345 pb.objParam.ioObjNamePtr = userName;
346 error = PBHGetLogInInfoSync(&pb);
347 if ( error == noErr )
348 {
349 *loginMethod = pb.objParam.ioObjType;
350 }
351 return ( error );
352 }
353
354 /*****************************************************************************/
355
356 pascal OSErr HGetDirAccess(short vRefNum,
357 long dirID,
358 ConstStr255Param name,
359 long *ownerID,
360 long *groupID,
361 long *accessRights)
362 {
363 HParamBlockRec pb;
364 OSErr error;
365
366 pb.accessParam.ioNamePtr = (StringPtr)name;
367 pb.accessParam.ioVRefNum = vRefNum;
368 pb.fileParam.ioDirID = dirID;
369 error = PBHGetDirAccessSync(&pb);
370 if ( error == noErr )
371 {
372 *ownerID = pb.accessParam.ioACOwnerID;
373 *groupID = pb.accessParam.ioACGroupID;
374 *accessRights = pb.accessParam.ioACAccess;
375 }
376 return ( error );
377 }
378
379 /*****************************************************************************/
380
381 pascal OSErr FSpGetDirAccess(const FSSpec *spec,
382 long *ownerID,
383 long *groupID,
384 long *accessRights)
385 {
386 return ( HGetDirAccess(spec->vRefNum, spec->parID, spec->name,
387 ownerID, groupID, accessRights) );
388 }
389
390 /*****************************************************************************/
391
392 pascal OSErr HSetDirAccess(short vRefNum,
393 long dirID,
394 ConstStr255Param name,
395 long ownerID,
396 long groupID,
397 long accessRights)
398 {
399 HParamBlockRec pb;
400
401 pb.accessParam.ioNamePtr = (StringPtr)name;
402 pb.accessParam.ioVRefNum = vRefNum;
403 pb.fileParam.ioDirID = dirID;
404 pb.accessParam.ioACOwnerID = ownerID;
405 pb.accessParam.ioACGroupID = groupID;
406 pb.accessParam.ioACAccess = accessRights;
407 return ( PBHSetDirAccessSync(&pb) );
408 }
409
410 /*****************************************************************************/
411
412 pascal OSErr FSpSetDirAccess(const FSSpec *spec,
413 long ownerID,
414 long groupID,
415 long accessRights)
416 {
417 return ( HSetDirAccess(spec->vRefNum, spec->parID, spec->name,
418 ownerID, groupID, accessRights) );
419 }
420
421 /*****************************************************************************/
422
423 pascal OSErr HMapID(ConstStr255Param volName,
424 short vRefNum,
425 long ugID,
426 short objType,
427 StringPtr name)
428 {
429 HParamBlockRec pb;
430
431 pb.objParam.ioNamePtr = (StringPtr)volName;
432 pb.objParam.ioVRefNum = vRefNum;
433 pb.objParam.ioObjType = objType;
434 pb.objParam.ioObjNamePtr = name;
435 pb.objParam.ioObjID = ugID;
436 return ( PBHMapIDSync(&pb) );
437 }
438
439 /*****************************************************************************/
440
441 pascal OSErr HMapName(ConstStr255Param volName,
442 short vRefNum,
443 ConstStr255Param name,
444 short objType,
445 long *ugID)
446 {
447 HParamBlockRec pb;
448 OSErr error;
449
450 pb.objParam.ioNamePtr = (StringPtr)volName;
451 pb.objParam.ioVRefNum = vRefNum;
452 pb.objParam.ioObjType = objType;
453 pb.objParam.ioObjNamePtr = (StringPtr)name;
454 error = PBHMapNameSync(&pb);
455 if ( error == noErr )
456 {
457 *ugID = pb.objParam.ioObjID;
458 }
459 return ( error );
460 }
461
462 /*****************************************************************************/
463
464 pascal OSErr HCopyFile(short srcVRefNum,
465 long srcDirID,
466 ConstStr255Param srcName,
467 short dstVRefNum,
468 long dstDirID,
469 ConstStr255Param dstPathname,
470 ConstStr255Param copyName)
471 {
472 HParamBlockRec pb;
473
474 pb.copyParam.ioVRefNum = srcVRefNum;
475 pb.copyParam.ioDirID = srcDirID;
476 pb.copyParam.ioNamePtr = (StringPtr)srcName;
477 pb.copyParam.ioDstVRefNum = dstVRefNum;
478 pb.copyParam.ioNewDirID = dstDirID;
479 pb.copyParam.ioNewName = (StringPtr)dstPathname;
480 pb.copyParam.ioCopyName = (StringPtr)copyName;
481 return ( PBHCopyFileSync(&pb) );
482 }
483
484 /*****************************************************************************/
485
486 pascal OSErr FSpCopyFile(const FSSpec *srcSpec,
487 const FSSpec *dstSpec,
488 ConstStr255Param copyName)
489 {
490 return ( HCopyFile(srcSpec->vRefNum, srcSpec->parID, srcSpec->name,
491 dstSpec->vRefNum, dstSpec->parID,
492 dstSpec->name, copyName) );
493 }
494
495 /*****************************************************************************/
496
497 pascal OSErr HMoveRename(short vRefNum,
498 long srcDirID,
499 ConstStr255Param srcName,
500 long dstDirID,
501 ConstStr255Param dstpathName,
502 ConstStr255Param copyName)
503 {
504 HParamBlockRec pb;
505
506 pb.copyParam.ioVRefNum = vRefNum;
507 pb.copyParam.ioDirID = srcDirID;
508 pb.copyParam.ioNamePtr = (StringPtr)srcName;
509 pb.copyParam.ioNewDirID = dstDirID;
510 pb.copyParam.ioNewName = (StringPtr)dstpathName;
511 pb.copyParam.ioCopyName = (StringPtr)copyName;
512 return ( PBHMoveRenameSync(&pb) );
513 }
514
515 /*****************************************************************************/
516
517 pascal OSErr FSpMoveRename(const FSSpec *srcSpec,
518 const FSSpec *dstSpec,
519 ConstStr255Param copyName)
520 {
521 OSErr error;
522
523 /* make sure the FSSpecs refer to the same volume */
524 if ( srcSpec->vRefNum != dstSpec->vRefNum )
525 {
526 error = diffVolErr;
527 }
528 else
529 {
530 error = HMoveRename(srcSpec->vRefNum, srcSpec->parID, srcSpec->name,
531 dstSpec->parID, dstSpec->name, copyName);
532 }
533 return ( error );
534 }
535
536 /*****************************************************************************/
537
538 pascal OSErr GetVolMountInfoSize(ConstStr255Param volName,
539 short vRefNum,
540 short *size)
541 {
542 ParamBlockRec pb;
543
544 pb.ioParam.ioNamePtr = (StringPtr)volName;
545 pb.ioParam.ioVRefNum = vRefNum;
546 pb.ioParam.ioBuffer = (Ptr)size;
547 return ( PBGetVolMountInfoSize(&pb) );
548 }
549
550 /*****************************************************************************/
551
552 pascal OSErr GetVolMountInfo(ConstStr255Param volName,
553 short vRefNum,
554 void *volMountInfo)
555 {
556 ParamBlockRec pb;
557
558 pb.ioParam.ioNamePtr = (StringPtr)volName;
559 pb.ioParam.ioVRefNum = vRefNum;
560 pb.ioParam.ioBuffer = (Ptr)volMountInfo;
561 return ( PBGetVolMountInfo(&pb) );
562 }
563
564 /*****************************************************************************/
565
566 pascal OSErr VolumeMount(const void *volMountInfo,
567 short *vRefNum)
568 {
569 ParamBlockRec pb;
570 OSErr error;
571
572 pb.ioParam.ioBuffer = (Ptr)volMountInfo;
573 error = PBVolumeMount(&pb);
574 if ( error == noErr )
575 {
576 *vRefNum = pb.ioParam.ioVRefNum;
577 }
578 return ( error );
579 }
580
581 /*****************************************************************************/
582
583 pascal OSErr Share(short vRefNum,
584 long dirID,
585 ConstStr255Param name)
586 {
587 HParamBlockRec pb;
588
589 pb.fileParam.ioNamePtr = (StringPtr)name;
590 pb.fileParam.ioVRefNum = vRefNum;
591 pb.fileParam.ioDirID = dirID;
592 return ( PBShareSync(&pb) );
593 }
594
595 /*****************************************************************************/
596
597 pascal OSErr FSpShare(const FSSpec *spec)
598 {
599 return ( Share(spec->vRefNum, spec->parID, spec->name) );
600 }
601
602 /*****************************************************************************/
603
604 pascal OSErr Unshare(short vRefNum,
605 long dirID,
606 ConstStr255Param name)
607 {
608 HParamBlockRec pb;
609
610 pb.fileParam.ioNamePtr = (StringPtr)name;
611 pb.fileParam.ioVRefNum = vRefNum;
612 pb.fileParam.ioDirID = dirID;
613 return ( PBUnshareSync(&pb) );
614 }
615
616 /*****************************************************************************/
617
618 pascal OSErr FSpUnshare(const FSSpec *spec)
619 {
620 return ( Unshare(spec->vRefNum, spec->parID, spec->name) );
621 }
622
623 /*****************************************************************************/
624
625 pascal OSErr GetUGEntry(short objType,
626 StringPtr objName,
627 long *objID)
628 {
629 HParamBlockRec pb;
630 OSErr error;
631
632 pb.objParam.ioObjType = objType;
633 pb.objParam.ioObjNamePtr = objName;
634 pb.objParam.ioObjID = *objID;
635 error = PBGetUGEntrySync(&pb);
636 if ( error == noErr )
637 {
638 *objID = pb.objParam.ioObjID;
639 }
640 return ( error );
641 }
642
643 /*****************************************************************************/