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