Glider4/Glider_405/Sources/G-FileInNOut.p

1 line
16 KiB
OpenEdge ABL
Raw Normal View History

unit FileInNOut; interface uses Palettes, Globals, GlobalUtils; function ErrorCheckFile: Boolean; function OpenHouse: Boolean; function DoOpen (whichType: Integer): Boolean; procedure DoClose (volNum: Integer); function GetHouse: Boolean; function ReadGame: Boolean; function SaveGameAs: Boolean; function SaveGame: Boolean; function WriteHouse: Boolean; implementation const dlgTop = 50; dlgLeft = 85; var typeIs: Integer; {=================================} function ErrorCheckFile; var nRooms, index: Integer; begin ErrorCheckFile := FALSE; with thisHouse do begin nRooms := numberORooms; if ((nRooms < 1) or (nRooms > 40)) then {check for valid # of rooms} begin Exit(ErrorCheckFile); end; for index := 1 to nRooms do {check PICT ID numbers} begin if (theRooms[index].backPictID < 200) or (theRooms[index].backPictID > 215) then begin Exit(ErrorCheckFile); end; end; end; ErrorCheckFile := TRUE; end; {=================================} function IOCheck (theErr: OSErr): OSErr; var dummyInt: Integer; line1, line2: Str255; alertHandle: AlertTHndl; alertRect: Rect; begin InitCursor; UseResFile(gliderResNum); if (theErr <> NoErr) then begin case theErr of DskFulErr: GetIndString(line1, rFileStrIDs, 1); FNFErr: begin fileWasLost := TRUE; GetIndString(line1, rFileStrIDs, 2); end; WPrErr: GetIndString(line1, rFileStrIDs, 3); FLckdErr: GetIndString(line1, rFileStrIDs, 4); VLckdErr: GetIndString(line1, rFileStrIDs, 5); FBsyErr, OpWrErr: GetIndString(line1, rFileStrIDs, 6); EOFErr: GetIndString(line1, rFileStrIDs, 7); otherwise GetIndString(line1, rFileStrIDs, 10); end; NumToString(theErr, line2); line2 := CONCAT('Error code = ', line2); ParamText(line1, line2, '', ''); alertHandle := AlertTHndl(Get1Resource('ALRT', rFileAlertID)); if (alertHandle <> nil) then begin HNoPurge(Handle(alertHandle)); alertRect := alertHandle^^.boundsRect; OffsetRect(alertRect, -alertRect.left, -alertRect.top); dummyInt := (screenBits.bounds.right - alertRect.right) div 2; OffsetRect(alertRect, dummyInt, 0); dummyInt := (screenBits.bounds.bottom - alertRect.bottom) div 3; OffsetRect(alertRect, 0, dummyInt); alertHandle^^.boundsRect := alertRect; HPurge(Handle(alertHandle)); end; dummyInt := Alert(rFileAlertID, nil); end; IOCheck := theErr; end; {=================================} function OpenHouse; var index: Integer; textLength: LongInt; ignored: Boolean; begin OpenHouse := FALSE; theErr := SetVol(nil, houseVolNum); if (IOCheck(theErr) <> 0) then Exit(OpenHouse); theErr := FSOpen(housesName, houseVolNum, houseNumber); if (IOCheck(theErr) <> 0) then begin if (not DoOpen(kHouseType)) then begin playing := FALSE; theErr := FSClose(houseNumber); Exit(OpenHouse); end; theErr := FSOpen(housesName, houseVolNum, houseNumber); if (IOCheck(theErr) <> 0) then begin playing := FALSE; theErr := FSClose(houseNumber); Exit(OpenHouse); end; end; theErr := SetFPos(houseNumber, FSFromStart, 0); if (IOCheck(theErr) <> 0) then begin playing := FALSE; theErr := FSClose(houseNumber); Exit(OpenHouse); end; textLength := SIZEOF(thisHouse); theErr := FSRead(houseNumber, textLength, @thisHouse); if (IOCheck(theErr) <> 0) then begin playing := FALSE; theErr := FSClose(houseNumber); Exit(OpenHouse); end; OpenHouse := TRUE; end; {=================================} function OpenSFGetHook (theSFitem: integer; theDialog: DialogPtr): integer; const statText = 11; {DITL item number of textAppButton} firstTime = -1; var itemToChange: Handle; {needed for GetDItem and SetCtlValue} itemBox: Rect; {needed for GetDItem} itemType: integer; {needed for GetDItem} statTitle: Str255; {needed for GetIndString} begin OpenSFGetHook := theSFitem; case theSFitem of fir