Glider4/RoomEditor_103/Sources/E-FileInNOut.p

1 line
12 KiB
OpenEdge ABL
Raw Normal View History

unit FileInNOut; interface uses Palettes, Globals, Utilities; function OpenFile (fileName: Str255; vNum: Integer): Boolean; function DoOpen: Boolean; function WriteFile (theFile, volNum: Integer): Boolean; function DoSaveAs: Boolean; function DoSave: Boolean; function DoClose: Boolean; function SaveNoClose: Integer; function SaveFirst: Integer; procedure SavePrefs; implementation {=================================} function IOCheck (theErr: OSErr): Integer; var dummyInt: Integer; line1, line2: Str255; alertHandle: AlertTHndl; alertRect: Rect; begin UseResFile(editorResNum); if (theErr <> NoErr) then begin InitCursor; case theErr of DskFulErr: GetIndString(line1, fileStrIDs, 1); FNFErr: GetIndString(line1, fileStrIDs, 2); WPrErr: GetIndString(line1, fileStrIDs, 3); FLckdErr: GetIndString(line1, fileStrIDs, 4); VLckdErr: GetIndString(line1, fileStrIDs, 5); FBsyErr, OpWrErr: GetIndString(line1, fileStrIDs, 6); EOFErr: GetIndString(line1, fileStrIDs, 7); otherwise GetIndString(line1, fileStrIDs, 10); end; NumToString(theErr, line2); line2 := CONCAT('Error code = ', line2); ParamText(line1, line2, '', ''); alertHandle := AlertTHndl(Get1Resource('ALRT', fileAlertID)); 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(fileAlertID, nil); end; IOCheck := theErr; end; {=================================} function OpenFile; var textLength: LongInt; resultCode: OSErr; dummy: Boolean; begin SpinBall; OpenFile := FALSE; resultCode := FSOpen(fileName, vNum, fileNumber); if (IOCheck(resultCode) <> 0) then Exit(OpenFile); SpinBall; resultCode := SetFPos(fileNumber, FSFromStart, 0); if (IOCheck(resultCode) <> 0) then begin fileIsOpen := TRUE; dummy := DoClose; Exit(OpenFile); end; SpinBall; textLength := SIZEOF(houseRec); resultCode := FSRead(fileNumber, textLength, @thisHouse); if (IOCheck(resultCode) <> 0) then begin fileIsOpen := TRUE; dummy := DoClose; Exit(OpenFile); end; SpinBall; if (thisHouse.timeStamp <= 0) then begin GenericAlert(24); fileIsOpen := TRUE; volumeNumber := vNum; dummy := DoClose; Exit(OpenFile); end; SpinBall; fileIsOpen := TRUE; OpenFile := TRUE; lockIt := FALSE; volumeNumber := vNum; end; {=================================} function SimpleFileFilter (p: ParmBlkPtr): BOOLEAN; begin SimpleFileFilter := TRUE; {Don't show it -- default} with p^.ioFlFndrInfo do if (fdType = 'GLhs') then SimpleFileFilter := FALSE; {Show it} end; {=====================================} function DoOpen; var dlgOrigin: Point; theTypeList: SFTypeList; theReply: SFReply; begin DoOpen := FALSE; SetPt(dlgOrigin, dlgLeft + rightOffset, dlgTop + downOffset); theTypeList[0] := 'GLhs'; SFPGetFile(dlgOrigin, '', @SimpleFileFilter, -1, theTypeList, nil, theReply, custGetID, nil); with theReply do begin if (good) then begin housesName := fName; DoOpen := (OpenFile(fName, vRefNum)); InitCursor; end else begin DoOpen := FALSE; Exit(DoOpen); end; end; end; {=====================================} function WriteFile; var index, temp: Integer; fileLength: LongInt; resultCode: OSErr; begin SpinBall; WriteFile := FALSE; fileLength := SIZEOF(houseRec); SpinBall; resultCode := SetFPos(theFile, FSFromStart, 0); if (IOCheck(resultCode) <> 0) then begin Exit(WriteFile); end; SpinBall; resultCode := FSWrite(theFile, fileLength, @thisHouse); if (IOCh