TYPE ZECBANK
Count AS LONG
DataName(1000) AS STRING * 20
DataSize(1000) AS LONG
DataValue(1000) AS STRING * 65535
END TYPE
DIM ZBank AS ZECBANK
DIM BankOpen AS INTEGER
DIM ZBFStream AS QFILESTREAM
DIM strBuffer AS STRING
DIM intBuffer AS LONG
DIM ZBr AS LONG
BankOpen=0
ZBank.Count=0
DECLARE FUNCTION BankIsOpen() AS INTEGER
DECLARE SUB LoadBank (Filename AS STRING)
DECLARE FUNCTION DatasCount() AS LONG
DECLARE FUNCTION GetDataIndex(Name AS STRING) AS LONG
DECLARE FUNCTION GetDataName (Index AS LONG) AS STRING
DECLARE FUNCTION GetDataSize (Name AS STRING) AS LONG
DECLARE FUNCTION GetDataValue (Name AS STRING) AS STRING
DECLARE SUB ExtractDataToFile (Name AS STRING,FileName AS STRING)
DECLARE SUB AddData (Name AS STRING,Value AS STRING)
DECLARE SUB AddDataFromFile (Name AS STRING,FileName AS STRING)
DECLARE SUB ReplaceData (Name AS INTEGER,Value AS STRING)
DECLARE SUB ReplaceDataFromFile (Name AS INTEGER,FileName AS STRING)
DECLARE SUB DeleteData (Name AS STRING)
DECLARE SUB RenameData(OldName AS STRING,Name AS STRING)
DECLARE SUB SaveBank (FileName AS STRING)
DECLARE FUNCTION NameExists (Name AS STRING) AS LONG
DECLARE SUB CreateBank()
FUNCTION BankIsOpen() AS INTEGER
BankIsOpen=BankOpen
END FUNCTION
FUNCTION NameExists(Name AS STRING) AS LONG
FOR ZBr=1 TO ZBank.Count
IF RTRIM$(ZBank.DataName(ZBr))=Name THEN
NameExists=1
EXIT FUNCTION
END IF
NEXT
NameExists=0
END FUNCTION
FUNCTION DatasCount() AS LONG
IF BankIsOpen=0 THEN
MESSAGEDLG "No Bank Loaded!",mtWarning,0,0
EXIT FUNCTION
END IF
DatasCount=ZBank.Count
END FUNCTION
FUNCTION GetDataIndex(Name AS STRING) AS LONG
IF BankIsOpen=0 THEN
MESSAGEDLG "No Bank Loaded!",mtWarning,0,0
EXIT FUNCTION
END IF
FOR ZBr=1 TO DatasCount
IF RTRIM$(GetDataName(ZBr))=Name THEN
GetDataIndex=ZBr
EXIT FUNCTION
END IF
NEXT
MESSAGEDLG "The bloc of datas " & Name & " not exists in the bank.",mtWarning,0,0
END FUNCTION
FUNCTION GetDataName(Index AS LONG) AS STRING
IF BankIsOpen=0 THEN
MESSAGEDLG "No Bank Loaded!",mtWarning,0,0
EXIT FUNCTION
END IF
IF Index>ZBank.Count OR Index<1 THEN
MESSAGEDLG "Invalid Index",mtWarning,0,0
EXIT FUNCTION
END IF
GetDataName=RTRIM$(ZBank.DataName(Index))
END FUNCTION
FUNCTION GetDataSize(Name AS STRING) AS LONG
IF BankIsOpen=0 THEN
MESSAGEDLG "No bank Loaded!",mtWarning,0,0
EXIT FUNCTION
END IF
FOR ZBr=1 TO ZBank.Count
IF GetDataName(ZBr)=Name THEN
GetDataSize=ZBank.DataSize(ZBr)
EXIT FUNCTION
END IF
NEXT
MESSAGEDLG "The bloc of datas " & Name & " not exists in the bank.",mtWarning,0,0
END FUNCTION
FUNCTION GetDataValue (Name AS STRING) AS STRING
IF BankIsOpen=0 THEN
MESSAGEDLG "No bank Loaded!",mtWarning,0,0
EXIT FUNCTION
END IF
FOR ZBr=1 TO ZBank.Count
IF GetDataName(ZBr)=Name THEN
GetDataValue=RTRIM$(ZBank.DataValue(ZBr))
EXIT FUNCTION
END IF
NEXT
MESSAGEDLG "The bloc of datas " & Name & " not exists in the bank.",mtWarning,0,0
END FUNCTION
SUB ExtractDataToFile (Name AS STRING, FileName AS STRING)
IF BankIsOpen=0 THEN
MESSAGEDLG "No Bank Loaded!",mtWarning,0,0
EXIT SUB
END IF
ZBFStream.OPEN(FileName,fmCreate)
ZBFStream.WriteStr(GetDataValue(Name),GetDataSize(Name))
ZBFStream.CLOSE
END SUB
SUB AddData(Name AS STRING,Value AS STRING)
IF BankIsOpen=0 THEN
MESSAGEDLG "No Bank Loaded!",mtWarning,0,0
EXIT SUB
END IF
IF NameExists(Name)=1 THEN
MESSAGEDLG "The bloc of datas " & Name & " not exists in the bank.",mtWarning,0,0
EXIT SUB
END IF
IF LEN(name)>20 THEN
MESSAGEDLG "Bloc's name too long. 20 caracters maximum.",mtWarning,0,0
EXIT SUB
END IF
IF LEN(Value)>65535 THEN
MESSAGEDLG "Bloc'datas too great than 65535 bytes (64kb).",mtWarning,0,0
EXIT SUB
END IF
ZBank.Count=DatasCount+1
ZBank.DataName(DatasCount)=Name
ZBank.DataSize(DatasCount)=LEN(Value)
ZBank.DataValue(DatasCount)=Value
END SUB
SUB AddDataFromFile (Name AS STRING,FileName AS STRING)
IF BankIsOpen=0 THEN
MESSAGEDLG "No bank Loaded!",mtWarning,0,0
EXIT SUB
END IF
IF NameExists(Name)=1 THEN
MESSAGEDLG "The bloc of datas " & Name & " not exists in the bank.",mtWarning,0,0
EXIT SUB
END IF
IF LEN(name)>20 THEN
MESSAGEDLG "Bloc's name too long. 20 caracters maximum.",mtWarning,0,0
EXIT SUB
END IF
IF FILEEXISTS(Filename)=False THEN
MESSAGEDLG filename & " not found.",mtWarning,0,0
EXIT SUB
END IF
ZBFStream.OPEN(FileName,fmOpenRead)
IF ZBFStream.size>65535 THEN
MESSAGEDLG "Bloc'datas too great than 65535 bytes (64kb).",mtWarning,0,0
EXIT SUB
END IF
strBuffer=ZBFStream.ReadStr(ZBFStream.Size)
ZBank.Count=ZBank.Count+1
ZBank.DataName(ZBank.Count)=Name
ZBank.DataSize(ZBank.Count)=LEN(strBuffer)
ZBank.DataValue(ZBank.Count)=strBuffer
ZBFStream.CLOSE
END SUB
SUB ReplaceData (Name AS STRING,Value AS STRING)
IF BankIsOpen=0 THEN
MESSAGEDLG "No bank Loaded",mtWarning,0,0
EXIT SUB
END IF
IF NameExists(Name)=0 THEN
MESSAGEDLG "The bloc of datas " & Name & " not exists in the bank.",mtWarning,0,0
EXIT SUB
END IF
IF LEN(Value)>65535 THEN
MESSAGEDLG "Bloc'datas too great than 65535 bytes (64kb).",mtWarning,0,0
EXIT SUB
END IF
ZBank.DataSize(GetDataIndex(Name))=LEN(Value)
ZBank.DataValue(GetDataIndex(Name))=Value
END SUB
SUB ReplaceDataFromFile (Name AS STRING,FileName AS STRING)
IF BankIsOpen=0 THEN
MESSAGEDLG "No Bank Loaded!",mtWarning,0,0
EXIT SUB
END IF
IF NameExists(Name)=0 THEN
MESSAGEDLG "The bloc of datas " & Name & " not exists in the bank.",mtWarning,0,0
EXIT SUB
END IF
IF FILEEXISTS(Filename)=False THEN
MESSAGEDLG filename & " not found.",mtWarning,0,0
EXIT SUB
END IF
ZBFStream.OPEN(FileName,fmOpenRead)
IF ZBFStream.size>65535 THEN
MESSAGEDLG "Bloc'datas too great than 65535 bytes (64kb).",mtWarning,0,0
EXIT SUB
END IF
strBuffer=ZBFStream.ReadStr(ZBFStream.Size)
ZBank.DataSize(GetDataIndex(Name))=LEN(strBuffer)
ZBank.DataValue(GetDataIndex(Name))=strBuffer
ZBFStream.CLOSE
END SUB
SUB DeleteData (Name AS STRING)
IF BankIsOpen=0 THEN
MESSAGEDLG "No Bank Loaded!",mtWarning,0,0
EXIT SUB
END IF
IF NameExists(Name)=0 THEN
MESSAGEDLG "The bloc of datas " & Name & " not exists in the bank.",mtWarning,0,0
EXIT SUB
END IF
ZBr=GetDataIndex(Name)
WHILE ZBr<DatasCount
ZBank.DataName(ZBr)=ZBank.DataName(ZBr+1)
ZBank.DataSize(ZBr)=ZBank.DataSize(ZBr+1)
ZBank.DataValue(ZBr)=ZBank.DataValue(ZBr+1)
ZBr=ZBr+1
WEND
ZBank.Count=DatasCount-1
END SUB
SUB RenameData(OldName AS STRING,Name AS STRING)
IF BankIsOpen=0 THEN
MESSAGEDLG "No Bank Loaded!",mtWarning,0,0
EXIT SUB
END IF
IF NameExists(OldName)=0 THEN
MESSAGEDLG "The bloc of datas " & Name & " not exists in the bank.",mtWarning,0,0
EXIT SUB
END IF
IF LEN(name)>20 THEN
MESSAGEDLG "Bloc's name too long. 20 caracters maximum.",mtWarning,0,0
EXIT SUB
END IF
IF NameExists(Name)=1 THEN
MESSAGEDLG "A bloc named " & Name & " already exists int the bank.",mtWarning,0,0
EXIT SUB
END IF
ZBank.DataName(GetDataIndex(OldName))=Name
END SUB
SUB LoadBank (FileName AS STRING)
IF FILEEXISTS(Filename)=False THEN
MESSAGEDLG FileName & " not found.",mtWarning,0,0
EXIT SUB
END IF
ZBFStream.OPEN(FileName,fmOpenRead)
strBuffer=ZBFStream.ReadStr(26)
strBuffer=RTRIM$(strBuffer)
IF strBuffer<>"ZBF1.0 Zecreator Bank File" AND strBuffer<>"ZBF1.c Zecreator Bank File" THEN
MESSAGEDLG "The file " & FileName & " is not a valid bank file.",mtWarning,0,0
EXIT SUB
END IF
IF strBuffer="ZBF1.0 Zecreator Bank File" THEN
ZBank.Count=0
WHILE ZBFStream.Position<ZBFStream.Size
ZBank.count=ZBank.Count+1
strBuffer=ZBFSTream.Readstr(20)
ZBank.DataName(ZBank.Count)=strBuffer
strBuffer=ZBFSTream.Readstr(65535)
ZBank.DataValue(ZBank.Count)=strBuffer
ZBank.DataSize(ZBank.Count)=LEN(RTRIM$(strBuffer))
WEND
END IF
IF strBuffer="ZBF1.c Zecreator Bank File" THEN
ZBank.Count=0
WHILE ZBFStream.Position<ZBFStream.Size
ZBank.count=ZBank.Count+1
strBuffer=ZBFSTream.Readstr(20)
ZBank.DataName(ZBank.Count)=strBuffer
strBuffer=ZBFStream.Readstr(5)
intBuffer=VAL(strBuffer)
strBuffer=ZBFStream.Readstr(intBuffer)
ZBank.DataValue(ZBank.Count)=strBuffer
ZBank.DataSize(ZBank.Count)=intBuffer
WEND
END IF
BankOpen=1
ZBFStream.CLOSE
END SUB
SUB SaveBank (FileName AS STRING)
ZBFStream.OPEN(Filename,fmCreate)
strBuffer="ZBF1.0 Zecreator Bank File"
ZBFStream.WriteStr(strBuffer,LEN(strBuffer))
FOR ZBr=1 TO ZBank.Count
ZBFStream.WriteStr(ZBank.DataName(ZBr),20)
ZBFStream.WriteStr(ZBank.DataValue(ZBr),65535)
NEXT
ZBFStream.CLOSE
END SUB
SUB CompressBank (FileName AS STRING)
ZBFStream.OPEN(Filename,fmCreate)
strBuffer="ZBF1.c Zecreator Bank File"
ZBFStream.WriteStr(strBuffer,LEN(strBuffer))
FOR ZBr=1 TO ZBank.Count
ZBFStream.WriteStr(ZBank.DataName(ZBr),20)
strBuffer=STR$(ZBank.DataSize(ZBr))
IF LEN(strBuffer)<5 THEN
strBuffer=STRING$(5-LEN(strBuffer),"0") & strBuffer
END IF
ZBFStream.WriteStr(strBuffer,5)
ZBFStream.WriteStr(ZBank.DataValue(ZBr),ZBank.DataSize(ZBr))
NEXT
ZBFStream.CLOSE
END SUB
SUB CreateBank()
ZBank.Count=0
BankOpen=1
END SUB
|
|