home *** CD-ROM | disk | FTP | other *** search
-
- Debug equ 0 ; make non-zero for debugging
-
- String_Format 0 ; no string padding
-
-
- ; DeskCheck.asm: Find out whether everyone's bundle is legit.
- ; Ephraim Vishniac / P.O. Box 1357 / East Arlington, MA 02174
- ; This program is in the public domain.
-
- ;
-
- Include Traps.D
- Include SysEquX.D
- Include FSEqu.D
- Include ToolEqu.D
- Include SysErr.D
- Include PackMacs.Txt
-
- ; Our Macros
-
- MACRO DoAlert AlertNumber =
- IF Debug
- _Debugger
- ENDIF
- ; Alert (AlertNumber:INT, NIL:ProcPtr) : INT;
- clr.w -(sp) ; space for result
- move.w #{AlertNumber},-(sp) ; alert number
- clr.l -(sp) ; NIL filter
- _Alert
- move.w (sp)+,d0 ; d0 = button hit
- cmp.w #OKitem,d0 ; standard test
- |
-
- MACRO DebugPoint =
- IF Debug
- _Debugger
- ENDIF
- |
-
- MACRO UseUs =
- move.w OurMap(a5),CurMap ; make ours the current map
- |
-
- MACRO UseThem =
- move.w TheirMap(a5),CurMap ; make theirs the current map
- |
-
- MACRO SetParamText =
- move.l ParamZero(a5),-(sp) ; push our paramtext pointers
- move.l ParamOne(a5),-(sp)
- move.l ParamTwo(a5),-(sp)
- move.l ParamThree(a5),-(sp)
- _ParamText
- |
-
- macro DNAME Name =
- dc.b '{Name|0:8}'
- .align 2
- |
-
-
- ; Our alerts
-
- Greeting equ 128 ; say hello
- Farewell equ 129 ; say goodbye
- SetVolFailed equ 130 ; couldn't SetVol
- OpenResFailed equ 131 ; couldn't OpenResFile
- BundleBitClear equ 132 ; has bundles, but no bundle bit
- NumberOfTypes equ 133 ; bundles has unusual number of types
- NoSigResource equ 134 ; couldn't load signature resource
- NovelType equ 135 ; neither ICN#, nor FREF
- MissingBundle equ 136 ; bundle is too short
- ExcessBundle equ 137 ; bundle runs too long
- FunnyIcon equ 138 ; ICN# isn't 256 bytes
- SmallFREF equ 139 ; FREF is less than six bytes
- BigFREF equ 140 ; FREF is more than 262 bytes
- MissingResource equ 141 ; can't find some bundled resource
- DoVolumeAlert equ 142 ; should we do this volume?
- NoIcons equ 143 ; no ICN# list in bundle
- NoFREFs equ 144 ; no FREF list in bundle
- BadLocalID equ 145 ; local ID unresolved
- OrphanType equ 146 ; no FREF with this file type
- OrphanCreator equ 147 ; no BNDL with matching signature
- BundleBitNoRF equ 148 ; Bundle bit is on, but no resource fork
- BundleBitNoBNDL equ 149 ; Bundle bit is on, but no bundles
- BlankImage equ 150 ; The image area of the ICN# is blank
- BlankMask equ 151 ; The mask area of the ICN# is blank
-
- ; Our dialogs
-
- CurrentFile equ 500
-
- ; Other miscellaneous equates
-
- OKitem equ 1 ; Item number for OK button
- QuitItem equ 2 ; Item number for Quit button
-
- ; Our globals
-
- OurMap ds.w 1 ; a word from our sponsor
- TheirMap ds.w 1 ; equal time for the other guy
- DialogPtr ds.l 1 ; current dialog
- OtherBNDLs ds.w 1 ; 'background count' of BNDL resources
- ParamZero ds.l 1 ; our param zero text pointer
- ParamOne ds.l 1 ; our param one text pointer
- ParamTwo ds.l 1 ; our param two text pointer
- ParamThree ds.l 1 ; our param three text pointer
- FileType ds.l 1 ; File Type of current file
- FileCreator ds.l 1 ; File Creator of current file
- TypeMatch ds.b 1 ; flag for file type matched
- CreatorMatch ds.b 1 ; flag for file creator matched
-
- XDef FCensus
-
- DeskCheck
- ;------------------------------- Init Managers ----------------------------
-
- pea -4(A5) ; Quickdraw's global area
- _InitGraf ; Init Quickdraw
- _InitFonts ; Init Font Manager
- move.l #$FFFF,D0 ; Flush all events
- _FlushEvents
- _InitWindows ; Init Window Manager
- _InitMenus ; Init Menu Manager
- _TEInit ; Init Text Edit
- clr.l -(SP) ; No restart procedure
- _InitDialogs ; Init Dialog Manager
- _InitCursor ; Turn on arrow cursor
-
- ;------------------------------- Init Globals -----------------------------
- move.w CurMap,OurMap(a5) ; record our resource refnum
-
- ; we need to discount bundles in our file and the system
- clr.w -(sp)
- move.l #'BNDL',-(sp) ; How many bundles?
- _CountResources
- move.w (sp)+,OtherBNDLs(a5) ; save for later
-
- clr.l ParamZero(a5) ; clear our param text pointers
- clr.l ParamOne(a5)
- clr.l ParamTwo(a5)
- clr.l ParamThree(a5)
-
- ;-------------------------------Desk Check---------------------------------
- ; Just do a census of all files on all volumes, running them
- ; through our bundle checker.
-
- DoAlert Greeting ; say hello
- bne SayByeBye ; if not OK, split
-
- DebugPoint
-
- jsr CheckAllVols ; else test all volumes
- DoAlert FareWell ; say goodbye
- SayByeBye
- _ExitToShell
-
-
- ; CheckAllVols: Check each mounted volume
-
- CAVinfo equ -ioVQElSize ; a handy parm block
- VolumeName equ CAVinfo-256 ; name of current volume
- LastLocal set VolumeName
-
- CheckAllVols
- link a6,#LastLocal
- lea CAVinfo(a6),a0 ; a0 = parm block
- clr.l ioCompletion(a0) ; no completion routine
- lea VolumeName(a6),a1 ; storage for volume name
- move.l a1,ioFileName(a0) ; set in parm block
- clr.w ioVolIndex(a0) ; clear index
- @0 lea CAVinfo(a6),a0 ; a0 = parm block
- clr.l VolumeName(a6) ; no volname yet
- add.w #1,ioVolIndex(a0) ; advance to next volume
- _GetVolInfo
- cmp.w #nsvErr,d0 ; out of volumes?
- beq @1 ; exit if so
- move.l ioFileName(a0),ParamZero(a5) ; set param text zero
- SetParamText
- DoAlert DoVolumeAlert ; should we do this one?
- bne @0
- lea CAVinfo(a6),a0 ; a0 = parm block
- jsr CheckOneVol ; else check this volume
- bra @0 ; and loop back
- @1 clr.l ParamZero(a5)
- unlk a6
- rts
- DName CHECKALLVOLS
-
- ; CheckOneVol: Survey a single volume
- ; Entry: a0 = _GetVolInfo poop on the volume to check
-
- TheItemType set -2 ; Dialog item type
- TheItem set TheItemType-4 ; Dialog item handle
- TheBox set TheItem-8 ; Dialog item box
- LastLocal set TheBox
-
- CheckOneVol
- link a6,#LastLocal
- move.w ioVRefNum(a0),-(sp) ; save volume reference number
- move.l ioFileName(a0),-(sp) ; save volume name pointer
-
- clr.l -(sp) ; space for result
- move.w #CurrentFile,-(sp) ; dialog number
- clr.l -(sp) ; take what we get
- move.l #-1,-(sp) ; put this window in front
- _GetNewDialog ; Pop the question
- move.l (sp),DialogPtr(a5) ; save the dialog pointer
- _SetPort ; make ours the current port
- move.l DialogPtr(a5),-(sp)
- _DrawDialog ; force complete dialog drawing
-
- move.l DialogPtr(a5),-(sp)
- move.w #4,-(sp) ; item number 4
- pea TheItemType(a6) ; storage for item type
- pea TheItem(a6) ; storage for item handle
- pea TheBox(a6) ; storage for item box
- _GetDItem
- move.l (sp)+,a1 ; file name pointer
- move.l TheItem(a6),-(sp) ; item handle
- move.l a1,-(sp) ; point to file name
- _SetIText ; set file name in dialog
-
- move.l #2,-(sp) ; root directory
- pea CheckOneFile ; our file inspector
- jsr FCensus ; scan everything
-
- move.l DialogPtr(a5),-(sp) ; push the dialog pointer
- _DisposDialog ; and kill the dialog
-
- unlk a6
- rts
- DName CHECKONEVOL
-
- ; CheckOneFile(ParamBlock:ParmBlkPtr; dirID:longint):boolean
- ; Do the actual tests on a given file.
- ; A6 offsets
- OldA6 set 0
- ReturnAddr set OldA6+4
- DirID set ReturnAddr+4 ; directory ID
- FileInfo set DirID+4 ; param block from _GetFileInfo
- ReturnValue set FileInfo+4 ; return value (0 = continue)
- ArgsSz set ReturnValue-DirID
- ;
- ParmBlk set OldA6-ioHVQElSize ; local parm block
- ErrString set ParmBlk-32 ; Str31 for error codes
- TheItemType set ErrString-2 ; Dialog item type
- TheItem set TheItemType-4 ; Dialog item handle
- TheBox set TheItem-8 ; Dialog item box
- LastLocal set TheBox
-
- CheckOneFile
- link a6,#LastLocal
- clr.w ReturnValue(a6) ; always continue search
-
- move.l DialogPtr(a5),-(sp)
- move.w #2,-(sp) ; item number 2
- pea TheItemType(a6) ; storage for item type
- pea TheItem(a6) ; storage for item handle
- pea TheBox(a6) ; storage for item box
- _GetDItem
- move.l TheItem(a6),-(sp) ; item handle
- move.l FileInfo(a6),a1 ; point to GetFileInfo stuff
- move.l ioFileName(a1),-(sp) ; point to file name
- _SetIText ; set file name in dialog
-
- ; is there a resource fork?
- move.l FileInfo(a6),a1 ; point to _GetFileInfo stuff
- tst.l ioFlRLgLen(a1) ; is there a resource fork?
- bne @8 ; skip if so
-
- ; There's no resource fork, so the bundle bit shouldn't be set.
- move.l FileInfo(a6),a1 ; point to _GetFileInfo stuff
- move.w ioFlUsrWds+fdFlags(a1),d0 ; d0 = file flags
- btst #fHasBundle,d0 ; test bundle bit
- beq @9 ; skip if clear, that makes sense
-
- ; This bozo has no resource fork, but the bundle bit is on
- DoAlert BundleBitNoRF
- bra @9
-
- @8 lea ParmBlk(a6),a0 ; point to parm block
- clr.l ioCompletion(a0)
- clr.l ioFileName(a0)
- move.w ioVRefNum(a1),ioVRefNum(a0) ; volume from file info
- move.l DirID(a6),ioWDDirID(a0) ; directory ID from file info
- tst FSFCBLen ; HFS running?
- bmi @0 ; branch if not
- _HSetVol ; HFS, set volume and directory
- bra @1
- @0 _SetVol ; MFS, just set volume
- @1 move.w ioResult(a0),d0 ; did it work?
- beq @2 ; skip if vol ok
-
- ext.l d0
- lea ErrString(a6),a0
- move.l a0,ParamZero(a5) ; move to param text ptrs
- _NumToString
- SetParamText
- DoAlert SetVolFailed
- bra @9
-
- @2 move.l FileInfo(a6),a1 ; point to _GetFileInfo stuff
- clr.w -(sp) ; for _OpenResFile result
- move.l ioFileName(a1),-(sp) ; push given file name
- move.b #0,ResLoad ; don't load resources
- _OpenResFile ; give it a shot
- move.b #-1,ResLoad ; do load resources
- move.w (sp)+,d0 ; pop reference number
- bpl @3 ; skip if reasonable number
-
- move.w ResErr,d0 ; get the error code
- ext.l d0
- lea ErrString(a6),a0
- move.l a0,ParamZero(a5) ; move to param text ptrs
- _NumToString
- SetParamText
- UseUs ; do we need this?
- DoAlert OpenResFailed
- bra @9
-
- ; While the other file is open, we have to bracket our
- ; alerts and stuff with 'UseUs' - 'UseThem'
-
- @3 cmp.w SysMap,d0 ; did we just open the system?
- beq @9 ; skip ahead if so
- cmp.w OurMap(a5),d0 ; is it us?
- beq @9 ; skip ahead if so
- move.w d0,TheirMap(a5) ; refnum of file under test
-
- ; Here's where we actually examine the file contents...
-
- ; Does this bozo have a bundle?
- clr.w -(sp)
- move.l #'BNDL',-(sp) ; How many bundles?
- _CountResources
- move.w (sp)+,d3 ; well?
- cmp.w OtherBNDLs(a5),d3 ; discount other bundles
- bne @7 ; skip if there are more, test them
-
- ; There are no bundles. Is the bundle bit set anyway?
- move.l FileInfo(a6),a1 ; point to _GetFileInfo stuff
- move.w ioFlUsrWds+fdFlags(a1),d0 ; d0 = file flags
- btst #fHasBundle,d0 ; test bundle bit
- beq @5 ; skip if clear, that makes sense
-
- ; There are no bundles, but this bozo has his bundle bit set.
- DoAlert BundleBitNoBNDL
- bra @5
-
- @7 move.l FileInfo(a6),a1 ; point to _GetFileInfo stuff
- move.l ioFlUsrWds+fdType(a1),FileType(a5) ; save file type
- move.l ioFlUsrWds+fdCreator(a1),FileCreator(a5) ; ditto creator
- clr.b TypeMatch(a5) ; no matches yet
- clr.b CreatorMatch(a5)
-
- move.w ioFlUsrWds+fdFlags(a1),d0 ; d0 = file flags
- btst #fHasBundle,d0 ; test bundle bit
- bne @4 ; skip if set, that makes sense
-
- move.w D3,D0
- sub.w OtherBNDLs(a5),D0
- ext.l d0
- lea ErrString(a6),a0
- move.l a0,ParamZero(a5) ; move to param text ptrs
- _NumToString
- SetParamText
- UseUs
- DoAlert BundleBitClear
- UseThem
-
- @4 move.w D3,D0 ; retrieve number of bundles
- jsr TestBundles ; else go test the bundles
- tst.b TypeMatch(a5) ; found FREF with our Type?
- bne @6 ; skip if so
-
- lea ErrString+1(a6),a0 ; fudge alignment of string
- move.l a0,ParamZero(a5) ; it's param text zero
- move.b #4,(a0)+ ; set string length
- move.l FileType(a5),(a0) ; and string contents
- SetParamText
- UseUs
- DoAlert OrphanType
- UseThem
- @6 tst.b CreatorMatch(a5) ; found BNDL with our Creator?
- bne @5 ; skip if so
-
- lea ErrString+1(a6),a0 ; fudge alignment of string
- move.l a0,ParamZero(a5) ; it's param text zero
- move.b #4,(a0)+ ; set string length
- move.l FileCreator(a5),(a0) ; and string contents
- SetParamText
- UseUs
- DoAlert OrphanCreator
- UseThem
-
- ; Here's where we close up the file
- @5 move.w TheirMap(a5),-(sp) ; retrieve test file refnum
- _CloseResFile ; and close it up
-
- move.w CurMap,d0 ; check the current map
- cmp.w OurMap(a5),d0 ; is it us?
- beq @9 ; skip if so, we're good
- DebugPoint
-
- ; so much for this file. Restore default volume
- @9 UseUs ; in case we opened the System...
- clr.l ParamZero(a5) ; the string storage is gone
- unlk a6
- move.l (sp)+,a0 ; a0 = return address
- lea ArgsSz(sp),sp ; pop arguments
- jmp (a0) ; return
- DName CHECKONEFILE
-
- ; TestBundles: Test all the bundles of the current resource file
- ; d0 = number of BNDL available
- ; We only need to check ones native to the top map [TheirMap(a5)]
-
- OldA6 set 0
- ReturnAddr set OldA6+4
-
- ResIndex set OldA6-2 ; current resource index
- BNDLHandle set ResIndex-4 ; handle to current bundle
- LastLocal set BNDLHandle
-
-
- TestBundles
- link a6,#LastLocal
- move.w d0,ResIndex(a6) ; resources to check
-
- @0 clr.l -(sp)
- move.l #'BNDL',-(sp) ; resource type
- move.w ResIndex(a6),-(sp) ; resource index
- _GetIndResource ; get the bundle
- move.l (sp)+,BNDLHandle(a6) ; save handle
-
- ; is it one that we want?
- clr.w -(sp)
- move.l BNDLHandle(a6),-(sp) ; current bundle
- _HomeResFile
- move.w (sp)+,d0
- cmp.w TheirMap(a5),d0 ; is it theirs?
- bne @1 ; skip if not
-
- move.l BNDLHandle(a6),a0 ; get the bundle handle
- _HNoPurge ; make it unpurgeable
- move.l BNDLHandle(a6),a0 ; get the bundle handle
- _HLock ; lock it down
-
- move.l BNDLHandle(a6),a0 ; get the bundle handle
- jsr TestOneBundle ; and check it out
-
- @1 sub.w #1,ResIndex(a6) ; decrement resource index
- bne @0 ; and try again
-
- unlk a6
- rts
- DName TESTBUNDLES
-
- ; TestOneBundle: Examine one BNDL for validity, sanity, etc.
- ; a0 = handle to the bundle
-
- OldA6 set 0
- ReturnAddr set OldA6+4
-
- BNDLHandle set OldA6-4 ; handle to current bundle
- BundleIDStr set BNDLHandle-32 ; Str31 for resource ID
- BundleSize set BundleIDStr-4 ; size of bundle
- BundleID set BundleSize-2 ; bundle's resource ID
- BundleType set BundleID-4 ; bundle's resource type
- BundleName set BundleType-256 ; bundle's resource name
- OtherString set BundleName-32 ; for other stuff
- ICNlist set OtherString-4 ; pointer to ICN# list
- FREFlist set ICNlist-4 ; pointer to FREF list
- LastLocal set FREFlist
-
- TestOneBundle
- link a6,#LastLocal
- movem.l d2-d5/a2-a4,-(sp) ; save some registers
- clr.l ICNlist(a6) ; clear list pointers
- clr.l FREFlist(a6)
-
- move.l a0,BNDLHandle(a6) ; store bundle handle for later
- move.l (a0),a4 ; a4 = bundle pointer
-
- move.l a0,-(sp) ; push handle
- pea BundleID(a6) ; pointer to resource ID var
- pea BundleType(a6) ; pointer to resource type var
- pea BundleName(a6) ; pointer to resource name var
- _GetResInfo
-
- lea BundleIDStr(a6),a0 ; string for bundle's res ID
- move.l a0,ParamZero(a5) ; save for use in ParamText
- move.w BundleID(a6),d0 ; get the resource ID
- ext.l d0
- _NumToString
- SetParamText
-
- ; Examine the bundle for size-wise sanity
- clr.l -(sp)
- move.l BNDLHandle(a6),-(sp)
- _SizeRsrc ; how big is it?
- move.l (sp)+,D4 ; save for later
- move.l D4,BundleSize(a6) ; might need original figure...
- sub.w #8,D4 ; at least minimum length?
- bmi @5 ; branch if not
- move.l (a4),D0 ; D0 = signature type
- move.w 4(a4),d1 ; D1 = signature ID
- jsr TestSignature ; check it out!
-
- move.w 6(a4),d3 ; D3 = # types - 1
- cmp.w #1,D3 ; usual number?
- beq @0 ; skip if so
- move.w d3,d0
- add.w #1,d0 ; actual number of types
- lea OtherString(a6),a0 ; other string
- move.l a0,ParamOne(a5)
- ext.l d0
- _NumToString
- SetParamText
- UseUs
- DoAlert NumberOfTypes
- UseThem
- @0 lea 8(a4),a4 ; a4 = header of first resource list
-
- @1 sub.w #6,D4 ; length of list header
- bmi @5 ; skip out if too short
- cmpi.l #'ICN#',(a4) ; icons?
- bne @6 ; skip if not, try something else
- move.l a4,ICNlist(a6) ; save ICN# list pointer
- bra @2 ; and go check the list
- @6 cmpi.l #'FREF',(a4) ; file references?
- bne @7 ; skip if not, it's something weird
- move.l a4,FREFlist(a6) ; save FREF list pointer
- bra @2 ; and go check the list
- @7 lea OtherString(a6),a0 ; point to other string
- move.w #4,(a0)
- move.l (a4),2(a0) ; fill in resource type
- lea 1(a0),a0 ; use odd-aligned string
- move.l a0,ParamOne(a5)
- SetParamText
- UseUs
- DoAlert NovelType
- UseThem
- @2 move.w 4(a4),d2 ; resources - 1 of this type
- lea 6(a4),a3 ; a3 = start of resource list
- @3 sub.w #4,d4 ; size of list item
- bmi @5 ; skip out if too short
- move.l (a4),D0 ; resource type
- move.w 2(a3),D1 ; resource ID
- jsr TestOneResource ; test it!
- lea 4(a3),a3 ; next item in list
- dbra d2,@3 ; collect them all
- move.l a3,a4 ; next list
- dbra d3,@1 ; collect all of those, too
- tst.w d4 ; All used up?
- beq @4 ; skip if so, that's just right
- ; The bundle runs on longer than expected
- UseUs
- DoAlert ExcessBundle
- UseThem
- @4 move.l ICNlist(a6),a0 ; pick up ICN# and FREF pointers
- move.l FREFlist(a6),a1
- jsr TestLocalIDs
-
- clr.l ParamZero(a5)
- clr.l ParamOne(a5)
- movem.l (sp)+,d2-d5/a2-a4 ; restore some registers
- unlk a6
- rts
- DName TESTONEBUNDLE
-
- @5 UseUs
- DoAlert MissingBundle
- UseThem
- bra @4
-
-
- ; TestSignature: Does the 'signature' resource exist?
- ; D0 = resource type
- ; D1.w = resource ID
-
- OldA6 set 0
- ReturnAddr set OldA6+4
-
- SigType set OldA6-4 ; type of signature resource
- TypeStr set SigType-1 ; for type string
- FillerOne set TypeStr-1 ; restore alignment
- SigID set FillerOne-2 ; resource ID for signature
- IDString set SigID-32 ; Str31 for resource ID
-
- LastLocal set IDString
-
- TestSignature
- link a6,#LastLocal
- move.l d0,SigType(a6) ; save signature's resource type
- move.w d1,SigID(a6) ; save resource ID
- cmp.l FileCreator(a5),d0 ; FREF matches creator?
- seq d0
- or.b d0,CreatorMatch(a5) ; set match flag if so
-
- clr.l -(sp)
- move.l SigType(a6),-(sp) ; resource type
- move.w SigID(a6),-(sp) ; resource ID
- _GetResource ; Fetch!
- move.l (sp)+,d0 ; pop the handle
- beq @2 ; problem if NIL
- tst.w ResErr ; something wrong?
- bne @2 ; skip if so
- clr.w -(sp) ; check home file of resource
- move.l d0,-(sp)
- _HomeResFile
- move.w (sp)+,d0 ; pop res file reference
- cmp.w TheirMap(a5),d0 ; right file?
- beq @0 ; branch if so, it's good
-
- @2 move.b #4,TypeStr(a6) ; set resource type string
- lea TypeStr(a6),a0
- move.l a0,ParamOne(a5)
- SetParamText
-
- move.w SigID(a6),d0 ; d0 = signature's res ID
- ext.l d0
- lea IDString(a6),a0
- move.l a0,ParamTwo(a5)
- _NumToString
- SetParamText
-
- UseUs
- DoAlert NoSigResource
- UseThem
-
- @0 clr.l ParamOne(a5)
- clr.l ParamTwo(a5)
- unlk a6
- rts
- DName TESTSIGNATURE
-
- ; TestOneResource: Do a sanity check on one resource.
- ; For all kinds, be sure it exists.
- ; For ICN# and FREF, do some other stuff
- ; D0 = resource type
- ; D1.W = resource ID
-
- OldA6 set 0
- ReturnAddr set OldA6+4
-
- ResHandle set OldA6-4 ; handle to current resource
- ResType set ResHandle-4 ; resource type
- ResTypeStr set ResType-1 ; for using above as string
- FillerOne set ResTypeStr-1 ; restore alignment
- ResID set FillerOne-2 ; resource ID
- ResIDStr set ResID-32 ; Str31 for resource ID
- ResSize set ResIDStr-4 ; size of resource
- SizeString set ResSize-32 ; Str31 for resource size
- LastLocal set SizeString
-
- TestOneResource
- link a6,#LastLocal
- movem.l d2-d5/a2-a4,-(sp) ; save some registers
-
- move.l d0,ResType(a6)
- move.w d1,ResID(a6)
-
- move.b #4,ResTypeStr(a6) ; build type string
- lea ResTypeStr(a6),a0
- move.l a0,ParamOne(a5) ; set indirect pointer
-
- move.w ResID(a6),d0 ; resource ID
- lea ResIDStr(a6),a0 ; ID string
- move.l a0,ParamTwo(a5)
- ext.l d0
- _NumToString
- SetParamText
-
- clr.l -(sp)
- move.l ResType(a6),-(sp) ; resource type
- move.w ResID(a6),-(sp) ; resource ID
- _GetResource ; Fetch!
- move.l (sp)+,ResHandle(a6) ; save the handle
- tst.l ResHandle(a6) ; NIL handle?
- beq @4 ; error if so, resource is missing
- tst.w ResErr ; something wrong?
- bne @4 ; skip if so
- clr.w -(sp) ; else check home resource file
- move.l ResHandle(a6),-(sp)
- _HomeResFile
- move.w (sp)+,d0 ; pop res file ref
- cmp.w TheirMap(a5),d0 ; right file?
- beq @0 ; branch if so, we'll take it
-
- @4 UseUs
- DoAlert MissingResource
- UseThem
- bra @9
- @0 clr.l -(sp)
- move.l ResHandle(a6),-(sp)
- _SizeRsrc ; How big is this sucker?
- move.l (sp)+,ResSize(a6) ; save for later testing
-
- move.l ResSize(a6),d0 ; set up length string
- lea SizeString(a6),a0
- move.l a0,ParamThree(a5)
- _NumToString
- SetParamText
-
- move.l ResType(a6),d0 ; d0 = resource type
- cmpi.l #'ICN#',d0 ; Icon list?
- bne @2 ; skip if not
-
- move.l ResSize(a6),d0 ; check resource size
- cmp.l #256,d0 ; must be 256 bytes
- beq @5 ; skip if so, it's good
- UseUs
- DoAlert FunnyIcon
- UseThem
-
- @5 move.l ResHandle(a6),a0 ; a0 = ICN# handle
- move.l (a0),a0 ; a0 = ICN# pointer
- clr.l d0 ; accumulated OR of ICN# image
- move.l #31,d1 ; d1 = long words in ICN# image
- @6 or.l (a0)+,d0 ; add up the ICN# image
- dbra d1,@6 ; loop through them all
- tst.l d0 ; is there some image?
- bne @7 ; jump if so, that's good
- UseUs
- DoAlert BlankImage
- UseThem
- @7 move.l ResHandle(a6),a0 ; a0 = ICN# handle
- move.l (a0),a0 ; a0 = ICN# pointer
- lea 128(a0),a0 ; a0 = ICN# mask pointer
- clr.l d0 ; accumulated OR of ICN# mask
- move.l #31,d1 ; d1 = long words in ICN# mask
- @8 or.l (a0)+,d0 ; add up the ICN# mask
- dbra d1,@8 ; loop through them all
- tst.l d0 ; is there some mask?
- bne @9 ; jump if so, that's good
- UseUs
- DoAlert BlankMask
- UseThem
- bra @9
-
- @2 cmpi.l #'FREF',d0 ; FREF?
- bne @9 ; exit if not, we don't care
- move.l ResSize(a6),d0 ; check resource size
- cmpi.l #6,d0 ; reasonable size?
- bcc @3 ; branch if minimum or more
- UseUs
- DoAlert SmallFREF ; the FREF is too small
- UseThem
- bra @9
- @3 cmpi.l #263,d0 ; not too big?
- bcs @9 ; branch if in bounds
- UseUs
- DoAlert BigFREF
- UseThem
-
- @9 clr.l ParamOne(a5)
- clr.l ParamTwo(a5)
- clr.l ParamThree(a5)
- movem.l (sp)+,d2-d5/a2-a4 ; restore some registers
- unlk a6
- rts
- DName TESTONERESOURCE
-
- ; TestLocalIDs: See if the local IDs referred to by the FREFs are
- ; resolved in the ICN# list.
- ; a0 = ptr to ICN# list from bundle
- ; a1 = ptr to FREF list from bundle
-
- FREFIDStr set -32 ; Str31 for FREF ID #
- LocalIDStr set FREFIDStr-32 ; Str31 for local ID #
- FREFHandle set LocalIDStr-4 ; handle of current FREF
- LastLocal set FREFHandle
-
- TestLocalIDs
- link a6,#LastLocal ; some local storage
- movem.l a2-a4/d2-d4,-(sp) ; save some regs
-
- move.l a0,d0 ; is there an ICN# list?
- bne @0 ; skip if so
- UseUs
- DoAlert NoIcons
- UseThem
- bra @9
- @0 move.l a1,d0 ; is there an FREF list?
- bne @1 ; skip if so
- UseUs
- DoAlert NoFREFs
- UseThem
- bra @9
- @1 move.l a0,a4 ; a4 = ICN# list pointer
- move.w 4(a1),d4 ; d4 = # FREFs - 1
- lea 6(a1),a3 ; a3 = first FREF item
- @2 clr.l -(sp)
- move.l #'FREF',-(sp)
- move.w 2(a3),-(sp)
- _GetResource ; get the FREF
- move.l (sp)+,d0 ; pop the handle
- beq @5 ; skip if NIL handle
- tst.w ResErr
- bne @5 ; skip if resource error
- move.l d0,FREFHandle(a6) ; save FREF handle
- clr.w -(sp) ; check home res file
- move.l d0,-(sp)
- _HomeResFile
- move.w (sp)+,d0 ; pop home res file
- cmp.w TheirMap(a5),d0 ; from a good home?
- bne @5 ; exit if not
-
- move.l FREFHandle(a6),a0 ; a0 = FREF handle
- move.l (a0),a0 ; a0 = FREF pointer
-
- move.l (a0),d0 ; d0 = file type from FREF
- cmp.l FileType(a5),d0 ; match our file type?
- seq d0
- or.b d0,TypeMatch(a5) ; set type match flag if so
-
- move.w 4(a0),d0 ; d0 = local ID from FREF
- move.w 4(a4),d3 ; d3 = # ICN#s - 1
- lea 6(a4),a2 ; a2 = first ICN# item
- @3 cmp.w (a2),d0 ; local IDs match?
- beq @5 ; skip if so, test next FREF
- lea 4(a2),a2 ; else move to next ICN# item
- dbra d3,@3 ; search through ICN# list
-
- ; If we fall out, we have an unsatisfied local ID in d0
-
- ext.l d0
- lea LocalIDStr(a6),a0 ; string for local resource ID
- move.l a0,ParamTwo(a5)
- _NumToString
- move.w 2(a3),d0 ; FREF resource ID
- ext.l d0
- lea FREFIDStr(a6),a0 ; string for FREF resource ID
- move.l a0,ParamOne(a5)
- _NumToString
- SetParamText
- UseUs
- DoAlert BadLocalID
- UseThem
- clr.l ParamOne(a5)
- clr.l ParamTwo(a5)
- @5 lea 4(a3),a3 ; next FREF item in list
- dbra d4,@2 ; test entire FREF list
- @9 movem.l (sp)+,a2-a4/d2-d4 ; restore registers
- unlk a6
- rts
- DName TESTLOCALIDS
-
-