$TYPECHECK ON
$INCLUDE "rapidq.inc"
TYPE QResourceStream EXTENDS QFILESTREAM
PRIVATE:
DataTypeToSize(Num_BYTE TO Num_DOUBLE) AS INTEGER
Offset AS INTEGER
ResourceStart AS INTEGER
RealFile AS QFILESTREAM
PUBLIC:
LineCount AS INTEGER
Position AS INTEGER
Size AS INTEGER
CONSTRUCTOR
Offset = 0
LineCount = 0
DataTypeToSize(Num_BYTE) = SIZEOF(BYTE)
DataTypeToSize(Num_SHORT) = SIZEOF(SHORT)
DataTypeToSize(Num_WORD) = SIZEOF(WORD)
DataTypeToSize(Num_LONG) = SIZEOF(LONG)
DataTypeToSize(Num_DWORD) = SIZEOF(DWORD)
DataTypeToSize(Num_SINGLE) = SIZEOF(SINGLE)
DataTypeToSize(Num_DOUBLE) = SIZEOF(DOUBLE)
RealFile.OPEN(COMMAND$(0), fmOpenRead)
RealFile.Seek(-4, soFromEnd)
ResourceStart = QResourceStream.RealFile.Size - QResourceStream.RealFile.ReadNum(Num_LONG) - 4
END CONSTRUCTOR
FUNCTION OPEN(Res AS INTEGER) AS INTEGER
WITH QResourceStream
IF Res >= RESOURCECOUNT THEN
Result = False
ELSE
.Offset = .ResourceStart + RESOURCE(Res)
.RealFile.Seek(.Offset, soFromBeginning)
.Size = .RealFile.ReadNum(Num_LONG)
.Offset + = SIZEOF(LONG)
.Position = 0
Result = True
END IF
END WITH
END SUB
SUB CLOSE
QResourceStream.Offset = 0
END SUB
SUB Seek(NewPos AS INTEGER, From AS INTEGER)
WITH QResourceStream
SELECT CASE From
CASE IS = soFromBeginning
.Position = NewPos
CASE IS = soFromCurrent
.Position + = NewPos
CASE IS = soFromEnd
.Position = .Size - NewPos - 1
END SELECT
IF .Position < 0 THEN .Position = 0
IF .Position >= .Size THEN .Position = .Size - 1
.RealFile.Seek(.Offset + .Position, soFromBeginning)
END WITH
END SUB
FUNCTION EOF AS INTEGER
IF QResourceStream.Position = QResourceStream.Size THEN
Result = True
ELSE
Result = False
END IF
END FUNCTION
PRIVATE:
SUB CheckForEOF
WITH QResourceStream
IF .Position > .Size THEN
.Position = .Size
END IF
END WITH
END SUB
PUBLIC:
FUNCTION ReadNum(Size AS INTEGER) AS DOUBLE
WITH QResourceStream
IF .Position = .Size THEN EXIT FUNCTION
Result = .RealFile.ReadNum(Size)
.Position + = .DataTypeToSize(Size)
.CheckForEOF
END WITH
END FUNCTION
FUNCTION ReadStr(Size AS INTEGER) AS STRING
DEFSTR Tmp
WITH QResourceStream
IF .Position = .Size THEN EXIT FUNCTION
Tmp = .RealFile.ReadStr(Size)
IF .Position >= .Size THEN
Tmp = LEFT$(Tmp, LEN(Tmp) - (.Position - .Size + 1))
.Position = .Size - 1
.Seek(0, soFromEnd)
END IF
Result = Tmp
END WITH
END FUNCTION
FUNCTION ReadBinStr(Size AS INTEGER) AS STRING
Result = QResourceStream.ReadStr(Size)
END FUNCTION
FUNCTION ReadLine AS STRING
DEFINT char
DEFSTR Res
WITH QResourceStream
IF .Position = .Size THEN EXIT FUNCTION
char = 0 : Res = ""
WHILE char <> 13 AND .Size <> .Position
char = .ReadNum(Num_BYTE)
IF char <> 13 AND char <> 10 THEN
Res = Res + CHR$(char)
END IF
WEND
Result = Res
END WITH
END FUNCTION
SUB ReadUDT(DATA AS QOBJECT)
END SUB
SUB WriteNum(Number AS INTEGER, Size AS INTEGER)
END SUB
SUB WriteStr(DATA AS STRING, Size AS INTEGER)
END SUB
SUB WriteBinStr(DATA AS STRING, Size AS INTEGER)
END SUB
SUB WriteLine(Line AS STRING)
END SUB
SUB WriteUDT(DATA AS QOBJECT)
END SUB
SUB CopyFrom(Stream AS QOBJECT, Bytes AS INTEGER)
END SUB
END TYPE
|