home *** CD-ROM | disk | FTP | other *** search
- #include "simple.h"
-
- /*****
- * a structure used to pre-select a folder
- *****/
- typedef struct {
- FSSpec *theFile;
- StandardFileReply *theReply;
- } MyDataRecord;
-
-
- #define isDirectory 0x0010
- #define kReportDlgID 257
- #define kSFPutDlgID 256
-
-
- /** PROTOTYPES for MoreFiles functions **/
-
- pascal OSErr HGetDirAccess(short vRefNum,
- long dirID,
- Str255 name,
- long *ownerID,
- long *groupID,
- long *accessRights);
-
- pascal OSErr FSpGetDirAccess(const FSSpec *spec,
- long *ownerID,
- long *groupID,
- long *accessRights);
-
- pascal OSErr HMapID(Str255 volName,
- short vRefNum,
- long ID,
- short objType,
- Str255 name);
-
-
-
- /*****
- * On first call through CustomGetFile(), set everything so folder specified in
- * myDataPtr->theFile is preselected
- *****/
- pascal short dlgHook(short item, DialogPtr theDialog, MyDataRecord *myDataPtr)
- {
- if (item == sfHookFirstCall)
- {
- myDataPtr->theReply->sfFile = *(myDataPtr->theFile);
-
- // the following line ensures the first subfolder in the folder specified
- // is selected. If we didn't nil out the name, the last subfolder would
- // be selected.
- myDataPtr->theReply->sfFile.name[0] = 0;
- myDataPtr->theReply->sfScript = 0;
- return sfHookChangeSelection;
- }
- return item;
- }
-
-
- /*****
- * Display a folder at the location specified by myFSSpec. The files within this
- * folder are grayed out. We return with a full FSSpec, or -1 if user hit cancel.
- *****/
- OSErr GetFileGray(FSSpec *myFSSpec)
- {
- OSErr err;
-
-
- MyDataRecord myData;
-
- /*
- * the default name is used in building a FSSpec for the reply. It must
- * not be passed in as a null string, or your "select this folder" button
- * won't ever be active.
- */
- Str255 defaultName = "\pMust Not Be Null";
- StandardFileReply reply;
- Point where = {-1, -1}; // autocenter, System 7!
- short activeList[2] = {1, 7}; // only keyboard on file list
-
- myData.theFile = myFSSpec;
- myData.theReply = &reply;
-
- CustomPutFile("\p",
- defaultName,
- &reply,
- kSFPutDlgID,
- where,
- (DlgHookYDProcPtr)dlgHook,
- nil,
- activeList,
- nil,
- &myData);
- if (reply.sfGood)
- err = FSMakeFSSpec(reply.sfFile.vRefNum, reply.sfFile.parID, nil, myFSSpec);
- else
- err = -1; // return some arbitrary error telling us cancel was selected.
- return err;
- }
-
-
- /*****
- * Set up a file spec to point to System file in System Folder
- *****/
- OSErr SetUpFile(FSSpec *fileSpec)
- {
- OSErr err;
- short vRefNum;
- long dirID;
-
- err = FindFolder(kOnSystemDisk,kSystemFolderType,kDontCreateFolder, &vRefNum,&dirID);
-
- if (err) {
- DebugStr("\pFickle FindFolder failed to find fey folder");
- ExitToShell();
- }
-
- err = FSMakeFSSpec(vRefNum,dirID,"\pSystem",fileSpec);
-
- if (err) {
- DebugStr("\pFaulty FSMakeFSSpec fails in forming FSSpec.");
- ExitToShell();
- }
- return err;
-
- }
-
- /******
- * Report on file, group, and owner selected
- * Really hacky, but it seems to do the job -- VDM 9/23/94
- ******/
- void Report(FSSpec *theFile)
- {
- long theOwnerID, /* owner of the parent directory */
- theGroupID, /* group with access to parent directory */
- theAccessRights; /* access rights to parent directory */
- OSErr myErr;
- Str255 theOwnerName;
- Str255 theGroupName;
-
- myErr = FSpGetDirAccess ( theFile, &theOwnerID, &theGroupID, &theAccessRights );
-
- if (myErr == noErr)
- {
- myErr = HMapID ( nil, theFile->vRefNum, theOwnerID, 1, theOwnerName ); /* passing 1 gives us owner info */
- if (myErr == noErr)
- myErr = HMapID (nil, theFile->vRefNum, theGroupID, 2, theGroupName ); /* passing 2 gives us group info */
- else
- DebugStr("\pTrouble getting owner name!");
- }
- else
- {
- DebugStr("\pWe're hosed with GetDirAccess!");
- }
-
- if (myErr == noErr)
- {
- ParamText(theFile->name, theOwnerName, theGroupName, "\p");
- Alert (kReportDlgID, nil);
- }
-
- else
- DebugStr("\pCannot get the group name!");
-
- }
-
- /******
- * Test Displaying folders only, with files within the folders in gray
- ******/
- void TestGetFileGray(void)
- {
- OSErr err;
- FSSpec theFile;
-
- err = SetUpFile(&theFile);
- if (!err)
- {
- err = GetFileGray(&theFile);
- if (!err)
- Report(&theFile);
- }
- }
-
- /******
- * if the isDirectory bit is set, return false (to show the directory)
- * if the isDirectory bit is clear, return true (to filter out all files)
- ******/
- pascal Boolean MyStandardFileFilter(CInfoPBPtr pb, MyDataRecord *myDataPtr)
- {
- return ( !(pb->dirInfo.ioFlAttrib & isDirectory) );
- }
-
- /*****
- * Handle items hit in our dialog
- *****/
- pascal short MyDlgFilter(short item, DialogPtr theDialog, MyDataRecord *myDataPtr)
- {
- if (item == sfHookFirstCall)
- {
- myDataPtr->theReply->sfFile = *(myDataPtr->theFile);
-
- // the following line ensures the first subfolder in the folder specified
- // is selected. If we didn't nil out the name, the last subfolder would
- // be selected.
- myDataPtr->theReply->sfFile.name[0] = 0;
- myDataPtr->theReply->sfScript = 0;
- return sfHookChangeSelection;
- }
- if (item == 10)
- return sfItemOpenButton;
- return item;
- }
-
- /*****
- * Test Displaying folder only, with no files within the folders.
- *****/
- TestGetFileNoGray()
- {
- FSSpec myFSSpec;
- SFTypeList typeList;
- StandardFileReply reply;
- Point where = {-1, -1};
- MyDataRecord myData;
-
- //my variables VDM
- OSErr myErr;
- long ownerID;
- long groupID;
- long accessRights;
-
-
-
- myData.theFile = &myFSSpec;
- myData.theReply = &reply;
-
- SetUpFile(&myFSSpec);
- CustomGetFile((FileFilterYDProcPtr)MyStandardFileFilter,
- -1,
- typeList,
- &reply,
- -6042,
- where,
- (DlgHookYDProcPtr)MyDlgFilter,
- nil,
- 0,
- nil,
- &myData);
- if (reply.sfGood)
- {
- FSMakeFSSpec(reply.sfFile.vRefNum, reply.sfFile.parID, nil, &myFSSpec);
- myErr = HGetDirAccess(reply.sfFile.vRefNum, reply.sfFile.parID, nil, &ownerID, &groupID, &accessRights);
- Report(&myFSSpec);
- }
- }
-
- /****
- *Routines lifted from MoreFiles with a few modifications -- VDM - 9/23
- ****/
- /*****************************************************************************/
-
- pascal OSErr HGetDirAccess(short vRefNum,
- long dirID,
- Str255 name,
- long *ownerID,
- long *groupID,
- long *accessRights)
- {
- HParamBlockRec pb;
- OSErr error;
-
- pb.accessParam.ioNamePtr = name;
- pb.accessParam.ioVRefNum = vRefNum;
- pb.fileParam.ioDirID = dirID;
- error = PBHGetDirAccessSync(&pb);
- *ownerID = pb.accessParam.ioACOwnerID;
- *groupID = pb.accessParam.ioACGroupID;
- *accessRights = pb.accessParam.ioACAccess;
- return (error);
- }
-
- /*****************************************************************************/
-
- pascal OSErr FSpGetDirAccess(const FSSpec *spec,
- long *ownerID,
- long *groupID,
- long *accessRights)
- {
- return (HGetDirAccess(spec->vRefNum, spec->parID, (StringPtr)spec->name,
- ownerID, groupID, accessRights));
- }
-
- /*****************************************************************************/
-
- pascal OSErr HMapID(Str255 volName,
- short vRefNum,
- long ID,
- short objType,
- Str255 name)
- {
- HParamBlockRec pb;
-
- pb.objParam.ioNamePtr = volName;
- pb.objParam.ioVRefNum = vRefNum;
- pb.objParam.ioObjType = objType;
- pb.objParam.ioObjNamePtr = name;
- pb.objParam.ioObjID = ID;
- return (PBHMapIDSync(&pb));
- }
-
- /*****************************************************************************/
-