home *** CD-ROM | disk | FTP | other *** search
- /*
- * BlessFolder.c, vers 0.1, 890718, Ragnar Sundblad, ragge@nada.kth.se
- *
- * usage: BlessFolder <directory name>
- *
- * BlessFolder puts the given directory's id in the Finder Info Parameter no 0
- * on the directory's volume. That's about it.
- *
- * ⌐1989 Ragnar Sundblad
- * May be used bot not sold, or in any other way be made profit on or with.
- * But please hand it to everyone who wants it. I sometimes find it very handy myself.
- *
- */
-
- #include <types.h>
- #include <files.h>
- #include <stdio.h>
-
- #define HFSSIGN 0x4244
-
- int c2pstr(char *c, Str255 p);
-
- main(int argc, char *argv[])
- {
- OSErr err;
- HParamBlockRec pbr;
- CInfoPBRec cir;
- Str255 path;
-
- if(argc != 2) {
- fprintf(stderr, "usage: %s <directory path>\n", argv[0]);
- exit(0);
- }
-
- if(c2pstr(argv[1], path)) {
- fprintf(stderr, "%s: Path name to long, max 255 characters. Extremely sorry.\n", argv[0]);
- exit(1);
- }
-
- /* Get directory id! */
-
- cir.dirInfo.ioNamePtr = &path; /* Path */
- cir.dirInfo.ioVRefNum = 0; /* we don't know */
- cir.dirInfo.ioFDirIndex = 0; /* nope, we don't want to use this indexing feature */
- cir.dirInfo.ioDrDirID = 0; /* looks informative, ey? */
-
-
- err = PBGetCatInfo(&cir, false);
-
- if(err) {
- fprintf(stderr, "%s: Error while getting file/directory info: %d\n", argv[0], err);
- exit(1);
- }
-
- if((cir.dirInfo.ioFlAttrib & 0x10) == 0) {
- fprintf(stderr, "%s: Specified path is not a directory!\n", argv[0]);
- exit(1);
- }
-
- /* Now go for the volume information */
-
- pbr.volumeParam.ioVolIndex = -1; /* Use named path instead */
- pbr.volumeParam.ioNamePtr = &path; /* path */
- pbr.volumeParam.ioVRefNum = 0; /* we don't know this */
-
- err = PBHGetVInfo(&pbr, false);
-
- if(err) {
- fprintf(stderr, "%s: Error while getting volume info: %d\n", argv[0], err);
- exit(1);
- }
-
- if(pbr.volumeParam.ioVSigWord != HFSSIGN) {
- fprintf(stderr, "%s: Not a HFS volume!\n", argv[0]);
- exit(1);
- }
-
- /* Ok, put the to-be-blessed-folder's id in finder parameter no 0 */
-
- pbr.volumeParam.ioVFndrInfo[0] = cir.dirInfo.ioDrDirID;
-
- /* Write new volume information down! */
-
- err = PBSetVInfo(&pbr, false);
-
- if(err) {
- fprintf(stderr, "%s: Error while setting volume info: %d\n", argv[0], err);
- exit(1);
- }
-
- /* Yeah! */
-
- exit(0);
- }
-
- /* c2pstr - copy c string to pascal string, return 0 if ok and 1 if to long */
-
- int c2pstr(char *c, Str255 p)
- {
- int i;
-
- i = 0;
- do {
- p[i+1] = c[i];
- i++;
- } while((i < 256) && (c[i] != '\0'));
-
- if(i >= 256) {
- return(1);
- }
-
- p[0] = i;
-
- return(0);
- }
-