AmendHub

Download

nulleric

/

Fix-a-Fork

/

scratch.c

 

(View History)

eric   Add TouchFolder to update the modification time so folders show new icons right away. Latest amendment: 35 on 2024-04-05

1 /*
2 Copyright Eric Helgeson 2023-2024.
3 */
4 // some unused attempts to get folders working
5 #include <unix.h>
6 /*
7 // some stuff in main just to get a stdout window
8 printf("hello\n");
9 //fflush(stdout);
10 while(!Button());
11 ExitToShell();
12
13
14 // This does seem to work!
15 static Boolean isFSSpecFolder(FSSpec *fss)
16 {
17 HFileInfo pb;
18 OSErr err = 0;
19
20 pb.ioCompletion = 0L;
21 pb.ioNamePtr = &fss->name[0];
22 pb.ioVRefNum = fss->vRefNum;
23 pb.ioFDirIndex = 0;
24 pb.ioDirID = fss->parID;
25
26 err = PBGetCatInfoSync((CInfoPBPtr)&pb);
27 if((pb.ioFlAttrib & 0x10) != 0)
28 {
29 puts("folder");
30 return true;
31 } else {
32 puts("not folder");
33 return false;
34 }
35 }
36
37 // This does seem to work but i only haven parentID so never get the actual dir i want.
38 Str255 filename, temp;
39 void loopFilesInDir(long dirID, short vRefNum, char *dirName)
40 {
41 CInfoPBRec cipbr;
42 HFileInfo *fpb = (HFileInfo *)&cipbr;
43 DirInfo *dpb = (DirInfo *)&cipbr;
44 short rc, idx;
45 Str255 dirFullName;
46 char cstrName[32] = {0};
47
48 // dont need probably
49 //strcpy((char *) dirFullName, dirName);
50 printf(" Searching: %s\n", dirName);
51
52 fpb->ioVRefNum = vRefNum; // example had 0... cant assume defaulvol...?
53 fpb->ioNamePtr = filename;
54
55 for(idx=1; true; idx++) {
56 fpb->ioDirID = dirID;
57 fpb->ioFDirIndex = idx;
58
59 rc = PBGetCatInfo(&cipbr, false);
60 if(rc) break;
61
62 pToCStr(filename,cstrName );
63 printf("%s\n", cstrName);
64 }
65 }
66
67 /* an attempt to get a dirID from a FSSpec
68 short GetDirID(FSSpec *fss, long *dirID)
69 {
70 CInfoPBRec rec;
71 short err = 0;
72 Boolean isFolder, wasAlias;
73 int loopCnt = 0;
74 tryAgain:
75 rec.hFileInfo.ioVRefNum = fss->vRefNum;
76 rec.hFileInfo.ioDirID = fss->parID;
77 rec.hFileInfo.ioNamePtr = fss->name;
78 rec.hFileInfo.ioFDirIndex = -1; // dir
79
80 PBGetCatInfoSync(&rec); //err handle
81 return err;
82 if( !(rec.hFileInfo.ioFlAttrib & 0x10) ) {
83 fss->parID = rec.hFileInfo.ioFlParID;
84 fss->vRefNum = rec.hFileInfo.ioVRefNum;
85 loopCnt++;
86 if(loopCnt > 2)
87 return dirNFErr;
88 goto tryAgain;
89 }
90 *dirID = rec.dirInfo.ioDrDirID;
91 return err;
92 } */
93
94 pascal OSErr DoOpenDoc(AppleEvent *event, AppleEvent *reply, long handlerRefcon)
95 {
96 CInfoPBRec cipbr;
97 HFileInfo *fpb = (HFileInfo *)&cipbr;
98 DirInfo *dpb = (DirInfo *)&cipbr;
99
100 FSSpec fss;
101 AEDescList docList;
102 OSErr err = noErr;
103 long index, itemsInList;
104 Size actualSize;
105 AEKeyword keywd;
106 DescType returnedType;
107 short fRefNum = 0;
108 char cstrName[32] = {0};
109 long dirID = 0;
110
111 err = AEGetParamDesc(event, keyDirectObject, typeAEList, &docList);
112 if(err != noErr) return err;
113 err = AECountItems(&docList, &itemsInList);
114 if(err != noErr) return err;
115
116 for(index = 1; index <= itemsInList; index++)
117 {
118 err = AEGetNthPtr(&docList, index, typeFSS, &keywd, &returnedType, (Ptr)&fss, sizeof(fss), &actualSize);
119 if(err) return err;
120 printf("fss.vRefNum: %d\n", fss.vRefNum);
121 printf("fss.parID: %d\n", fss.parID);
122 pToCStr(fss.name, cstrName);
123 printf("fss.name: %s\n", cstrName);
124 if(isFSSpecFolder(&fss)) {
125 // GetDirID(&fss, &dirID);
126 //ListFiles(fss.vRefNum, fss.parID);
127 loopFilesInDir(fss.parID, fss.vRefNum, cstrName);
128
129 }
130 err = FSpOpenDF(&fss, fsRdPerm, &fRefNum);
131 if(err) return err;
132
133 err = openFile(fss.name, fRefNum, fss.vRefNum, fss.parID);
134 if(err)
135 return err;
136 else
137 gHandledByDnD = true;
138 }
139 AEDisposeDesc(&docList);
140 return noErr;
141 }
142
143
144 // This does not work on 7.1 and below.
145 // An attempt to send the finder update apple event to refresh the folder.
146 void SendFinderSyncEvent(FSSpec spec)
147 {
148 const OSType sig = 'MACS';
149 OSErr err = 0;
150 Str255 errString;
151 AppleEvent event, reply;
152 AEAddressDesc addr;
153
154 if(!gHasAppleEvents)
155 return;
156
157 AECreateDesc( typeApplSignature, &sig, sizeof sig, &addr);
158 AECreateAppleEvent('fndr', 'fupd', &addr, kAutoGenerateReturnID, kAnyTransactionID, &event);
159 AEPutParamPtr(&event, keyDirectObject, typeFSS, &spec, sizeof(spec));
160 AESend(&event, &reply, kAENoReply, kAENormalPriority, kNoTimeOut, NULL, NULL);
161 AEDisposeDesc(&event);
162 }
163 */