source: oup/releases/0.27a/Unit2_functions.pas@ 1080

Last change on this file since 1080 was 26, checked in by alloc, 18 years ago
File size: 19.7 KB
RevLine 
[26]1UNIT Unit2_functions;
2INTERFACE
3USES Classes, Dialogs, SysUtils, StrUtils, Math,
4 Unit3_data, ABSDecUtil, ABSMain, DB;
5
6TYPE
7 TExportSet=SET OF (DO_dat,DO_raw,DO_convert,DO_toone);
8
9FUNCTION GetFilesList(ext:String; pattern:String; NoEmptyFiles:Boolean):TStringList;
10FUNCTION GetExtensionsList:TStringList;
11
12FUNCTION Decode_Int(buffer:Tdata):LongWord;
13FUNCTION Encode_Int(input:LongWord):Tdata;
14FUNCTION Decode_Float(buffer:Tdata):Single;
15FUNCTION Encode_Float(input:Single):Tdata;
16FUNCTION DataToBin(data:Tdata):String;
17FUNCTION BinToInt(bin:String):Byte;
18
19FUNCTION GetFileInfo(fileid:LongWord):TFileInfo;
20FUNCTION LoadDatInfos(filename:String):Boolean;
21PROCEDURE OpenDatabase(FileName:String);
22PROCEDURE CloseDatabase;
23
24FUNCTION LoadDatFile(fileid:LongWord):Tdata;
25PROCEDURE UpdateDatFile(fileid:LongWord; data:Tdata);
26FUNCTION LoadDatFilePart(fileid,offset,size:LongWord; target:Pointer):Boolean;
27FUNCTION UpdateDatFilePart(fileid,offset,size:LongWord; target:Pointer):Boolean;
28
29FUNCTION LoadRawFile(fileid,dat_offset,raw_addr,size:LongWord; loc_sep:Boolean; target:Pointer):Boolean;
30FUNCTION LoadRawFileByIDOffset(fileid,dat_offset:LongWord; target:Pointer):Boolean;
31FUNCTION UpdateRawFile(rawinfo:TRawInfo; target:Pointer):Boolean;
32
33FUNCTION ExportFile(fileid:LongWord; filename:String; settings:TExportSet; path:String):Integer;
34
35FUNCTION FormatNumber(value:LongWord; width:Byte; leadingzeros:Char):String;
36FUNCTION FormatFileSize(size:LongWord):String;
37FUNCTION CreateHexString(data:Tdata; HexOnly:Boolean):String;
38FUNCTION GetWinFileName(name:String):String;
39FUNCTION GetExtractPath:String;
40
41
42IMPLEMENTATION
43USES Unit4_Exporters, Unit9_data_structures;
44
45VAR
46 Database:TABSDatabase;
47 Query:TABSQuery;
48
49TYPE
50 TValueSwitcher=Record
51 CASE IsFloat: Boolean OF
52 True: (ValueFloat:Single);
53 False: (ValueInt:LongWord);
54 END;
55
56FUNCTION Decode_Int(buffer:Tdata):LongWord;
57 BEGIN
58 Result:=buffer[0]+buffer[1]*256+buffer[2]*256*256+buffer[3]*256*256*256;
59 END;
60FUNCTION Encode_Int(input:LongWord):Tdata;
61 BEGIN
62 SetLength(Result,4);
63 Result[0]:=input MOD 256;
64 input:=input DIV 256;
65 Result[1]:=input MOD 256;
66 input:=input DIV 256;
67 Result[2]:=input MOD 256;
68 input:=input DIV 256;
69 Result[3]:=input MOD 256;
70 END;
71FUNCTION Decode_Float(buffer:Tdata):Single;
72 VAR _valueswitcher:TValueSwitcher;
73 BEGIN
74 _valueswitcher.ValueInt:=Decode_Int(buffer);
75 Result:=_valueswitcher.ValueFloat;
76 IF IsNAN(Result) THEN Result:=0.0;
77 END;
78FUNCTION Encode_Float(input:Single):Tdata;
79 VAR _valueswitcher:TValueSwitcher;
80 BEGIN
81 _valueswitcher.ValueFloat:=input;
82 Result:=Encode_Int(_valueswitcher.ValueInt);
83 END;
84
85FUNCTION DataToBin(data:Tdata):String;
86 VAR
87 i,j:Byte;
88 singlebyte:Byte;
89 bytepart:String;
90 BEGIN
91 SetLength(bytepart,8);
92 Result:='';
93 FOR i:=0 TO High(data) DO BEGIN
94 singlebyte:=data[i];
95 FOR j:=7 DOWNTO 0 DO BEGIN
96 bytepart[j+1]:=Char((singlebyte AND $01)+48);
97 singlebyte:=singlebyte SHR 1;
98 END;
99 Result:=Result+bytepart+' ';
100 END;
101 END;
102FUNCTION BinToInt(bin:String):Byte;
103 VAR
104 Add: Integer;
105 i: Byte;
106 BEGIN
107 Result:=0;
108 IF Length(bin)<>8 THEN Exit;
109 Add:=1;
110 FOR i:=8 DOWNTO 1 DO BEGIN
111 IF NOT (bin[i] IN ['0','1']) THEN Exit;
112 IF bin[i] = '1' THEN Inc(Result,Add);
113 Add:=Add SHL 1;
114 END;
115 END;
116
117FUNCTION GetFileInfo(fileid:LongWord):TFileInfo;
118 BEGIN
119 IF opened_state=opened_dat THEN BEGIN
120 Result:=dat_files[fileid];
121 END ELSE BEGIN
122 Query.SQL.Text:='SELECT * FROM datfiles WHERE id='+IntToStr(fileid)+' ORDER BY id ASC;';
123 Query.Open;
124 IF Query.RecordCount=1 THEN BEGIN
125 Query.First;
126 Result.ID:=Query.FieldByName('id').AsInteger;
127 Result.Name:=Query.FieldByName('name').AsString;
128 Result.Extension:=Query.FieldByName('extension').AsString;
129 Result.FileName:=FormatNumber(Result.ID,5,'0')+'-'+Result.Name+'.'+Result.Extension;
130 Result.Size:=Query.FieldByName('size').AsInteger;
131 Result.FileType:=Query.FieldByName('contenttype').AsInteger;
132 Result.DatAddr:=0;
133 Result.opened:=False;
134 END;
135 Query.Close;
136 END;
137 END;
138
139
140FUNCTION GetFilesList(ext:String; pattern:String; NoEmptyFiles:Boolean):TStringList;
141 VAR
142 i:LongWord;
143 where:String;
144 where_ext:String;
145 BEGIN
146 SetLength(Result,0);
147 IF opened_state=opened_dat THEN BEGIN
148 FOR i:=0 TO dat_header.Files-1 DO BEGIN
149 IF ( (Length(ext)=0) OR (Pos(dat_files[i].Extension,ext)>0) ) AND
150 ( (Length(pattern)=0) OR (Pos(UpperCase(pattern),UpperCase(dat_files[i].Name))>0) ) THEN BEGIN
151 IF NoEmptyFiles THEN BEGIN
152 IF (dat_files[i].FileType AND $02)=0 THEN BEGIN
153 SetLength(Result,Length(Result)+1);
154 Result[High(Result)]:=dat_files[i].FileName;
155 END;
156 END ELSE BEGIN
157 SetLength(Result,Length(Result)+1);
158 Result[High(Result)]:=dat_files[i].FileName;
159 END;
160 END;
161 END;
162 END ELSE BEGIN
163 where:='';
164 IF Length(ext)>0 THEN BEGIN
165 IF Length(where)>0 THEN where:=where+' AND ';
166 IF Pos(',',ext)>0 THEN BEGIN
167 i:=1;
168 where_ext:='';
169 WHILE i<Length(ext) DO BEGIN
170 IF Length(where_ext)>0 THEN where_ext:=where_ext+' OR ';
171 where_ext:=where_ext+'(extension="'+MidStr(ext,i,4)+'")';
172 i:=i+5;
173 END;
174 where:=where+'('+where_ext+')';
175 END ELSE BEGIN
176 where:=where+'(extension="'+ext+'")';
177 END;
178 END;
179 IF Length(pattern)>0 THEN BEGIN
180 IF Length(where)>0 THEN where:=where+' AND ';
181 where:=where+'(name LIKE "%'+pattern+'%")';
182 END;
183 IF NoEmptyFiles THEN BEGIN
184 IF Length(where)>0 THEN where:=where+' AND ';
185 where:=where+'(contenttype<>2)';
186 END;
187 IF Length(where)>0 THEN where:=' WHERE '+where;
188 Query.SQL.Text:='SELECT id,name,extension FROM datfiles'+where+' ORDER BY id ASC;';
189 Query.Open;
190 IF Query.RecordCount>0 THEN BEGIN
191 Query.First;
192 SetLength(Result,Query.RecordCount);
193 i:=0;
194 REPEAT
195 Result[i]:=FormatNumber(Query.FieldByName('id').AsInteger,5,'0')+'-'+Query.FieldByName('name').AsString+'.'+Query.FieldByName('extension').AsString;
196 Inc(i);
197 Query.Next;
198 UNTIL Query.EOF;
199 END;
200 Query.Close;
201 END;
202 END;
203
204FUNCTION GetExtensionsList:TStringList;
205 VAR
206 i:LongWord;
207 BEGIN
208 SetLength(Result,0);
209 IF opened_state=opened_dat THEN BEGIN
210 FOR i:=0 TO dat_header.Extensions-1 DO BEGIN
211 SetLength(Result,Length(Result)+1);
212 WITH dat_extensionsmap[i] DO BEGIN
213 Result[High(Result)]:=Extension[3]+Extension[2]+Extension[1]+Extension[0]+' ('+IntToStr(ExtCount)+')';
214 END;
215 END;
216 END ELSE BEGIN
217 Query.SQL.Text:='SELECT extension,count(extension) AS x FROM datfiles GROUP BY extension ORDER BY extension ASC;';
218 Query.Open;
219 IF Query.RecordCount>0 THEN BEGIN
220 SetLength(Result,Query.RecordCount);
221 i:=0;
222 REPEAT
223 Result[i]:=Query.FieldByName('extension').AsString+' ('+IntToStr(Query.FieldByName('x').AsInteger)+')';
224 Inc(i);
225 Query.Next;
226 UNTIL Query.EOF;
227 END;
228 Query.Close;
229 END;
230 END;
231
232FUNCTION LoadDatInfos(filename:String):Boolean;
233 VAR i:LongWord;
234 dat_file:TFileStream;
235 header_pc,header_mac:Boolean;
236 BEGIN
237 Result:=True;
238 opened_state:=opened_dat;
239 dat_filename:=filename;
240 raw_filename:=MidStr(filename,1,Length(filename)-3)+'raw';
241 dat_file:=TFileStream.Create(filename, fmOpenRead);
242 dat_file.Read(dat_header,SizeOf(dat_header));
243 header_pc:=True;
244 header_mac:=True;
245 FOR i:=0 TO High(dat_header.Ident) DO BEGIN
246 IF dat_header.Ident[i]<>header_ident1_pc[i] THEN BEGIN
247 header_pc:=False;
248 END;
249 IF dat_header.Ident[i]<>header_ident1_mac[i] THEN BEGIN
250 header_mac:=False;
251 END;
252 END;
253 IF NOT (header_pc OR header_mac) THEN BEGIN
254 Result:=False;
255 Exit;
256 END ELSE BEGIN
257 IF (header_pc AND NOT header_mac) THEN
258 dat_os_mac:=False
259 ELSE
260 IF (NOT header_pc AND header_mac) THEN
261 dat_os_mac:=True
262 ELSE BEGIN
263 Result:=False;
264 Exit;
265 END;
266 END;
267 SetLength(dat_filesmap,dat_header.Files);
268 SetLength(dat_files,dat_header.Files);
269 FOR i:=0 TO dat_header.Files-1 DO dat_file.Read(dat_filesmap[i],SizeOf(dat_filesmap[i]));
270 FOR i:=0 TO dat_header.Files-1 DO BEGIN
271 dat_files[i].Extension:=dat_filesmap[i].Extension;
272 dat_files[i].Extension:=ReverseString(dat_files[i].Extension);
273 dat_files[i].Size:=dat_filesmap[i].FileSize;
274 dat_files[i].FileType:=dat_filesmap[i].FileType;
275 dat_files[i].DatAddr:=dat_filesmap[i].DataAddr-8+dat_header.DataAddr;
276 IF (dat_filesmap[i].FileType AND $01)=0 THEN BEGIN
277 dat_file.Seek(dat_filesmap[i].NameAddr+dat_header.NamesAddr,soFromBeginning);
278 SetLength(dat_files[i].Name,100);
279 dat_file.Read(dat_files[i].Name[1],100);
280 dat_files[i].Name:=MidStr(dat_files[i].Name,1+4,Pos(#0,dat_files[i].Name)-1-4);
281 END ELSE BEGIN
282 dat_files[i].Name:='';
283 END;
284 dat_files[i].FileName:=FormatNumber(i,5,'0')+'-'+dat_files[i].Name+'.'+dat_files[i].Extension;
285 END;
286 dat_file.Seek($40+dat_header.Files*$14,soFromBeginning);
287 SetLength(dat_namedfilesmap,dat_header.NamedFiles);
288 FOR i:=0 TO dat_header.NamedFiles-1 DO dat_file.Read(dat_namedfilesmap[i],SizeOf(dat_namedfilesmap[i]));
289
290 dat_file.Seek($40+dat_header.Files*$14+dat_header.NamedFiles*$8,soFromBeginning);
291 SetLength(dat_extensionsmap,dat_header.Extensions);
292 FOR i:=0 TO dat_header.Extensions-1 DO dat_file.Read(dat_extensionsmap[i],SizeOf(dat_extensionsmap[i]));
293
294 dat_file.Free;
295 END;
296
297
298FUNCTION LoadDatFile(fileid:LongWord):Tdata;
299 VAR
300 dat_file:TFileStream;
301 mem:TStream;
302 BEGIN
303 IF opened_state=opened_dat THEN BEGIN
304 dat_file:=TFileStream.Create(dat_filename, fmOpenRead);
305 dat_file.Seek(dat_files[fileid].DatAddr,soFromBeginning);
306 SetLength(Result,dat_files[fileid].Size);
307 dat_file.Read(Result[0],dat_files[fileid].Size);
308 dat_file.Free;
309 END ELSE BEGIN
310 Query.SQL.Text:='SELECT data FROM datfiles WHERE id='+IntToStr(fileid)+';';
311 Query.Open;
312 IF Query.RecordCount>0 THEN BEGIN
313 mem:=Query.CreateBlobStream(Query.FieldByName('data'),bmRead);
314 SetLength(Result,mem.Size);
315 mem.Seek(0,soFromBeginning);
316 mem.Read(Result[0],mem.Size);
317 mem.Free;
318 END;
319 Query.Close;
320 END;
321 END;
322PROCEDURE UpdateDatFile(fileid:LongWord; data:Tdata);
323 VAR
324 dat_file:TFileStream;
325 BEGIN
326 IF opened_state=opened_dat THEN BEGIN
327 dat_file:=TFileStream.Create(dat_filename, fmOpenReadWrite);
328 dat_file.Seek(dat_files[fileid].DatAddr,soFromBeginning);
329 dat_file.Write(data[0],Length(data));
330 dat_file.Free;
331 END ELSE BEGIN
332 END;
333 END;
334
335FUNCTION LoadDatFilePart(fileid,offset,size:LongWord; target:Pointer):Boolean;
336 VAR
337 dat_file:TFileStream;
338 mem:TStream;
339 BEGIN
340 Result:=False;
341 IF opened_state=opened_dat THEN BEGIN
342 dat_file:=TFileStream.Create(dat_filename, fmOpenRead);
343 Result:=True;
344 dat_file.Seek(dat_files[fileid].DatAddr+offset,soFromBeginning);
345 dat_file.Read(target^,size);
346 dat_file.Free;
347 END ELSE BEGIN
348 Query.SQL.Text:='SELECT data FROM datfiles WHERE id='+IntToStr(fileid)+';';
349 Query.Open;
350 IF Query.RecordCount>0 THEN BEGIN
351 mem:=Query.CreateBlobStream(Query.FieldByName('data'),bmRead);
352 mem.Seek(offset,soFromBeginning);
353 mem.Read(target^,size);
354 mem.Free;
355 END;
356 Query.Close;
357 END;
358 END;
359FUNCTION UpdateDatFilePart(fileid,offset,size:LongWord; target:Pointer):Boolean;
360 VAR
361 dat_file:TFileStream;
362 BEGIN
363 Result:=False;
364 IF opened_state=opened_dat THEN BEGIN
365 dat_file:=TFileStream.Create(dat_filename, fmOpenReadWrite);
366 Result:=True;
367 dat_file.Seek(dat_files[fileid].DatAddr+offset,soFromBeginning);
368 dat_file.Write(target^,size);
369 dat_file.Free;
370 END ELSE BEGIN
371 END;
372 END;
373
374FUNCTION LoadRawFile(fileid,dat_offset,raw_addr,size:LongWord; loc_sep:Boolean; target:Pointer):Boolean;
375 VAR
376 filestream:TFileStream;
377 mem:TStream;
378 BEGIN
379 Result:=False;
380 IF opened_state=opened_dat THEN BEGIN
381 Result:=True;
382 IF NOT loc_sep THEN
383 filestream:=TFileStream.Create(AnsiReplaceStr(dat_filename,'.dat','.raw'),fmOpenRead)
384 ELSE
385 filestream:=TFileStream.Create(AnsiReplaceStr(dat_filename,'.dat','.sep'),fmOpenRead);
386 filestream.Seek(raw_addr,soFromBeginning);
387 filestream.Read(target^,size);
388 filestream.Free;
389 END ELSE BEGIN
390 Query.SQL.Text:='SELECT data FROM rawmap WHERE (src_id='+IntToStr(fileid)+') AND (src_link_offset='+IntToStr(dat_offset)+');';
391 Query.Open;
392 IF Query.RecordCount>0 THEN BEGIN
393 Result:=True;
394 mem:=Query.CreateBlobStream(Query.FieldByName('data'),bmRead);
395 mem.Seek(0,soFromBeginning);
396 mem.Read(target^,size);
397 mem.Free;
398 END;
399 Query.Close;
400 END;
401 END;
402FUNCTION LoadRawFileByIDOffset(fileid,dat_offset:LongWord; target:Pointer):Boolean;
403 VAR
404 i:Byte;
405 raw_info:TRawInfo;
406 mem:TStream;
407 BEGIN
408 Result:=False;
409 IF opened_state=opened_dat THEN BEGIN
410 Result:=True;
411 raw_info:=GetRawInfo(fileid,dat_offset);
412 LoadRawFile(fileid,dat_offset,raw_info.raw_addr,raw_info.raw_size,raw_info.loc_sep,target);
413 END ELSE BEGIN
414 Query.SQL.Text:='SELECT data FROM rawmap WHERE (src_id='+IntToStr(fileid)+') AND (src_link_offset='+IntToStr(dat_offset)+');';
415 Query.Open;
416 IF Query.RecordCount>0 THEN BEGIN
417 Result:=True;
418 mem:=Query.CreateBlobStream(Query.FieldByName('data'),bmRead);
419 mem.Seek(0,soFromBeginning);
420 mem.Read(target^,mem.size);
421 mem.Free;
422 END;
423 Query.Close;
424 END;
425 END;
426FUNCTION UpdateRawFile(rawinfo:TRawInfo; target:Pointer):Boolean;
427 VAR
428 filestream:TFileStream;
429 BEGIN
430 Result:=False;
431 IF opened_state=opened_dat THEN BEGIN
432 Result:=True;
433 IF NOT rawinfo.loc_sep THEN
434 filestream:=TFileStream.Create(AnsiReplaceStr(dat_filename,'.dat','.raw'),fmOpenReadWrite)
435 ELSE
436 filestream:=TFileStream.Create(AnsiReplaceStr(dat_filename,'.dat','.sep'),fmOpenReadWrite);
437 filestream.Seek(rawinfo.raw_addr,soFromBeginning);
438 filestream.Write(target^,rawinfo.raw_size);
439 filestream.Free;
440 END ELSE BEGIN
441 END;
442 END;
443
444
445FUNCTION FormatNumber(value:LongWord; width:Byte; leadingzeros:Char):String;
446 BEGIN
447 Result:=AnsiReplaceStr(Format('%'+IntToStr(width)+'u',[value]),' ',leadingzeros);
448 END;
449
450FUNCTION FormatFileSize(size:LongWord):String;
451 BEGIN
452 IF size>=1000*1024*1024 THEN BEGIN
453 Result:=FloatToStrF(size/1024/1024/1024,ffFixed,5,1)+' GB';
454 END ELSE BEGIN
455 IF size>=1000*1024 THEN BEGIN
456 Result:=FloatToStrF(size/1024/1024,ffFixed,5,1)+' MB';
457 END ELSE BEGIN
458 IF size>=1000 THEN BEGIN
459 Result:=FloatToStrF(size/1024,ffFixed,5,1)+' KB';
460 END ELSE BEGIN
461 Result:=IntToStr(size)+' B';
462 END;
463 END;
464 END;
465 END;
466
467FUNCTION CreateHexString(data:Tdata; HexOnly:Boolean):String;
468 VAR
469 string_build,ascii_version:String;
470 i:LongWord;
471 BEGIN
472 string_build:='';
473 ascii_version:='';
474 FOR i:=0 TO High(data) DO BEGIN
475 IF NOT HexOnly THEN
476 IF (i MOD 16)=0 THEN
477 string_build:=string_build+'0x'+IntToHex(i,6)+' ';
478 string_build:=string_build+IntToHex(data[i],2);
479 IF NOT HexOnly THEN BEGIN
480 IF data[i]>=32 THEN ascii_version:=ascii_version+Chr(data[i])
481 ELSE ascii_version:=ascii_version+'.';
482 IF ((i+1) MOD 2)=0 THEN string_build:=string_build+#32;
483 IF ((i+1) MOD 16)=0 THEN BEGIN
484 string_build:=string_build+#32+ascii_version+CrLf;
485 ascii_version:='';
486 END;
487 END;
488 END;
489 Result:=string_build;
490 END;
491
492
493FUNCTION ExportFile(fileid:LongWord; filename:String; settings:TExportSet; path:String):Integer;
494 VAR
495 i:Byte;
496 extension:String;
497 BEGIN
498 Result:=export_noerror;
499 extension:=RightStr(filename,4);
500 IF DO_toone IN settings THEN BEGIN
501 ExportDatFile(fileid,path+'\'+GetWinFileName(filename));
502 END ELSE BEGIN
503 IF DO_dat IN settings THEN ExportDatFile(fileid,path+'\'+GetWinFileName(filename));
504 IF DO_raw IN settings THEN BEGIN
505 FOR i:=1 TO Length(ExportHandlers)+1 DO BEGIN
506 IF i<=Length(ExportHandlers) THEN BEGIN
507 IF ExportHandlers[i].Ext=extension THEN BEGIN
508 IF ExportHandlers[i].needed THEN BEGIN
509 CASE ExportHandlers[i].Handler(fileid,path+'\'+GetWinFileName(filename),(DO_convert IN settings)) OF
510 0: Result:=0;
511 ELSE
512 Result:=export_handlererror;
513 END;
514 END;
515 Break;
516 END;
517 END ELSE BEGIN
518 Result:=export_nohandler;
519 END;
520 END;
521 END;
522 END;
523 END;
524
525
526FUNCTION GetWinFileName(name:String):String;
527 BEGIN
528 Result:=name;
529 Result:=AnsiReplaceStr(Result,'\','__');
530 Result:=AnsiReplaceStr(Result,'/','__');
531 Result:=AnsiReplaceStr(Result,'>','__');
532 Result:=AnsiReplaceStr(Result,'<','__');
533 END;
534
535FUNCTION GetExtractPath:String;
536 BEGIN
537 Result:=ExtractFilePath(dat_filename)+'\extracted_'+ExtractFileName(dat_filename);
538 END;
539
540
541PROCEDURE OpenDatabase(FileName:String);
542 VAR
543 i:Byte;
544 temps:String;
545 BEGIN
546 IF NOT FileExists(FileName) THEN BEGIN
547 ShowMessage('File doesn''t exist!!!');
548 Exit;
549 END;
550 Database:=TABSDatabase.Create(NIL);
551 Database.DatabaseName:='OLDBcon';
552 Database.DatabaseFileName:=FileName;
553 Database.Open;
554 Query:=TABSQuery.Create(Database);
555 Query.DatabaseName:='OLDBcon';
556 Query.SQL.Text:='SELECT [name],[value] FROM globals ORDER BY [name] ASC';
557 Query.Open;
558 Query.First;
559 REPEAT
560 IF Query.FieldByName('name').AsString='dbversion' THEN BEGIN
561 IF Query.FieldByName('value').AsString<>DBversion THEN BEGIN
562 ShowMessage('Database-file '+CrLf+'"'+FileName+'"'+CrLf+'has wrong version. (Required: '+DBversion+'; found: '+Query.FieldByName('value').AsString+')');
563 Query.Close;
564 CloseDatabase;
565 Exit;
566 END;
567 END;
568 IF Query.FieldByName('name').AsString='lvl' THEN BEGIN
569 database_level:=StrToInt(Query.FieldByName('value').AsString);
570 END;
571 IF Query.FieldByName('name').AsString='ident' THEN BEGIN
572 temps:=Query.FieldByName('value').AsString;
573 FOR i:=0 TO High(database_ident) DO BEGIN
574 CASE temps[(i*2)+1+0] OF
575 '0'..'9': database_ident[i]:=Ord(temps[(i*2)+1+0])-48;
576 'A'..'F': database_ident[i]:=Ord(temps[(i*2)+1+0])-55;
577 END;
578 database_ident[i]:=database_ident[i]*16;
579 CASE temps[(i*2)+1+1] OF
580 '0'..'9': database_ident[i]:=database_ident[i]+Ord(temps[(i*2)+1+0])-48;
581 'A'..'F': database_ident[i]:=database_ident[i]+Ord(temps[(i*2)+1+0])-55;
582 END;
583 END;
584 END;
585 Query.Next;
586 UNTIL Query.Eof;
587 Query.Close;
588 opened_state:=opened_db;
589 END;
590PROCEDURE CloseDatabase;
591 BEGIN
592 Database.Close;
593 Database.Free;
594 opened_state:=opened_nothing;
595 END;
596
597
598
599END.
Note: See TracBrowser for help on using the repository browser.