source: oup/releases/0.33a/Code/OniDataClass.pas@ 1009

Last change on this file since 1009 was 56, checked in by alloc, 18 years ago
File size: 39.1 KB
Line 
1unit OniDataClass;
2interface
3uses Data, DataStructures, Classes, SysUtils, StrUtils,
4 Dialogs, ABSDecUtil, ABSMain, DB, Windows;
5
6type
7 TOniData = class
8 private
9 FFileName: String;
10 FLevelInfo: TLevelInfo;
11 FBackend: Integer;
12 Fos_mac: Boolean;
13 protected
14 public
15 property FileName: String Read FFileName Write FFileName;
16 property Backend: Integer Read FBackend Write FBackend;
17 property OSisMac: Boolean Read Fos_mac Write Fos_mac;
18 property LevelInfo: TLevelinfo Read FLevelInfo Write FLevelInfo;
19
20 constructor Create(filename: String; var Result: Boolean); virtual; abstract;
21 procedure Close; virtual; abstract;
22
23 function GetFileInfo(fileid: LongWord): TFileInfo; virtual; abstract;
24 function GetFilesList(ext: String; pattern: String;
25 NoEmptyFiles: Boolean; sort: TSortType): TStringArray; virtual; abstract;
26 function GetFilesCount: LongWord; virtual; abstract;
27 function GetExtensionsList: TStringArray; virtual; abstract;
28 function GetExtendedExtensionsList: TExtensionsMap; virtual; abstract;
29 function ExtractFileID(Name: String): Integer;
30 function GetFileIDByName(Name: String): Integer;
31
32 function LoadDatFile(fileid: LongWord): Tdata; virtual; abstract;
33 procedure UpdateDatFile(fileid: LongWord; Data: Tdata); virtual; abstract;
34 procedure LoadDatFilePart(fileid, offset, size: LongWord; target: Pointer);
35 virtual; abstract;
36 procedure UpdateDatFilePart(fileid, offset, size: LongWord; target: Pointer);
37 virtual; abstract;
38
39 function GetRawList(fileid: LongWord): TRawList; virtual; abstract;
40 function GetRawInfo(fileid, dat_offset: LongWord): TRawInfo;
41 procedure LoadRawFile(fileid, dat_offset: LongWord; target: Pointer);
42 virtual; abstract;
43 procedure UpdateRawFile(fileid, dat_offset: LongWord; size: LongWord; target: Pointer);
44 virtual; abstract;
45 procedure LoadRawFilePart(fileid, dat_offset: LongWord;
46 offset, size: LongWord; target: Pointer); virtual; abstract;
47 procedure UpdateRawFilePart(fileid, dat_offset: LongWord;
48 offset, size: LongWord; target: Pointer); virtual; abstract;
49 function AppendRawFile(loc_sep: Boolean; size: LongWord; target: Pointer): LongWord;
50 virtual; abstract;//Returns new Address
51 published
52 end;
53
54 TOniDataDat = class(TOniData)
55 private
56 Fdat_file: TFileStream;
57 Fraw_file: TFileStream;
58 Fsep_file: TFileStream;
59 Fdat_header: THeader;
60 Fdat_filesmap: TFilesMap;
61 Fdat_files: TFiles;
62 Fdat_namedfilesmap: TNamedFilesMap;
63 Fdat_extensionsmap: TExtensionsMap;
64 FUnloadWhenUnused: Boolean;
65 FDatOpened: Boolean;
66 FRawOpened: Boolean;
67 FSepOpened: Boolean;
68 protected
69 public
70 property UnloadWhenUnused: Boolean Read FUnloadWhenUnused Write FUnloadWhenUnused;
71
72 constructor Create(DatFilename: String; var Result: Boolean); override;
73 procedure Close; override;
74
75 function GetFileInfo(fileid: LongWord): TFileInfo; override;
76 function GetFilesList(ext: String; pattern: String;
77 NoEmptyFiles: Boolean; sort: TSortType): TStringArray; override;
78 function GetFilesCount: LongWord; override;
79 function GetExtensionsList: TStringArray; override;
80 function GetExtendedExtensionsList: TExtensionsMap; override;
81
82 function LoadDatFile(fileid: LongWord): Tdata; override;
83 procedure UpdateDatFile(fileid: LongWord; Data: Tdata); override;
84 procedure LoadDatFilePart(fileid, offset, size: LongWord; target: Pointer); override;
85 procedure UpdateDatFilePart(fileid, offset, size: LongWord; target: Pointer); override;
86
87 procedure LoadRawOffset(loc_sep: Boolean; raw_addr, size: LongWord; target: Pointer);
88 function GetRawList(fileid: LongWord): TRawList; override;
89 procedure LoadRawFile(fileid, dat_offset: LongWord; target: Pointer); override;
90 procedure UpdateRawFile(fileid, dat_offset: LongWord; size: LongWord;
91 target: Pointer); override;
92 procedure LoadRawFilePart(fileid, dat_offset: LongWord;
93 offset, size: LongWord; target: Pointer); override;
94 procedure UpdateRawFilePart(fileid, dat_offset: LongWord;
95 offset, size: LongWord; target: Pointer); override;
96 function AppendRawFile(loc_sep: Boolean; size: LongWord; target: Pointer): LongWord;
97 override;//Returns new Address
98 published
99 end;
100
101 TOniDataADB = class(TOniData)
102 private
103 FDatabase: TABSDatabase;
104 FQuery: TABSQuery;
105 Fdat_files: TFiles;
106 Fdat_extensionsmap: TExtensionsMap;
107 protected
108 public
109 constructor Create(OLDBFilename: String; var Result: Boolean); override;
110 procedure Close; override;
111
112 procedure UpdateListCache;
113 // function GetDatLinks(srcid:LongWord):TDatLinks;
114 function GetFileInfo(fileid: LongWord): TFileInfo; override;
115 function GetFilesList(ext: String; pattern: String;
116 NoEmptyFiles: Boolean; sort: TSortType): TStringArray; override;
117 function GetFilesCount: LongWord; override;
118 function GetExtensionsList: TStringArray; override;
119 function GetExtendedExtensionsList: TExtensionsMap; override;
120 function GetNamedFilesMap: TNamedFilesMap;
121
122 function LoadDatFile(fileid: LongWord): Tdata; override;
123 procedure UpdateDatFile(fileid: LongWord; Data: Tdata); override;
124 procedure LoadDatFilePart(fileid, offset, size: LongWord; target: Pointer); override;
125 procedure UpdateDatFilePart(fileid, offset, size: LongWord; target: Pointer); override;
126
127 function GetRawList(fileid: LongWord): TRawList; override;
128 procedure LoadRawFile(fileid, dat_offset: LongWord; target: Pointer); override;
129 procedure UpdateRawFile(fileid, dat_offset: LongWord; size: LongWord;
130 target: Pointer); override;
131 procedure LoadRawFilePart(fileid, dat_offset: LongWord;
132 offset, size: LongWord; target: Pointer); override;
133 procedure UpdateRawFilePart(fileid, dat_offset: LongWord;
134 offset, size: LongWord; target: Pointer); override;
135 published
136 end;
137
138
139const
140 ODB_None = -1;
141 ODB_Dat = 0;
142 ODB_ADB = 1;
143
144var
145 OniDataConnection: TOniData;
146
147function CreateDataConnection(filename: String; backend: Integer): Boolean;
148procedure CloseDataConnection;
149
150
151
152
153implementation
154uses Functions;
155
156
157
158(*
159 Implementation of TOniData
160*)
161
162function TOniData.GetFileIDByName(Name: String): Integer;
163var
164 files: TStringArray;
165 i: Integer;
166begin
167 Result := -1;
168 files := Self.GetFilesList('', Name, False, stIDAsc);
169 if Length(files) > 0 then
170 for i := 0 to High(files) do
171 if Pos(Name, files[i]) = Pos('-', files[i]) + 1 then
172 begin
173 // if MidStr(files[i],Pos('-',files[i])+1,Length(files[i])-Pos('-',files[i])-5)=name then begin
174 Result := Self.ExtractFileID(files[i]);
175 Break;
176 end;
177end;
178
179
180
181
182function TOniData.ExtractFileID(Name: String): Integer;
183begin
184 if Name[5] = '-' then
185 Result := HexToLong(MidStr(Name, 1, 4))
186 else
187 Result := StrToInt(MidStr(Name, 1, 5));
188end;
189
190
191
192
193function TOniData.GetRawInfo(fileid, dat_offset: LongWord): TRawInfo;
194var
195 i: LongWord;
196 raw_list: TRawList;
197begin
198 raw_list := Self.GetRawList(fileid);
199 Result.src_id := 0;
200 Result.src_offset := 0;
201 Result.raw_addr := 0;
202 Result.raw_size := 0;
203 for i := 0 to High(raw_list) do
204 begin
205 if raw_list[i].src_offset = dat_offset then
206 begin
207 Result.src_id := fileid;
208 Result.src_offset := raw_list[i].src_offset;
209 Result.raw_addr := raw_list[i].raw_addr;
210 Result.raw_size := raw_list[i].raw_size;
211 Result.loc_sep := raw_list[i].loc_sep;
212 Break;
213 end;
214 end;
215end;
216
217
218
219
220
221
222
223(*
224================================================================================
225 Implementation of TOniDataDat
226*)
227
228constructor TOniDataDat.Create(DatFilename: String; var Result: Boolean);
229const
230 header_ident1_pc: array[0..$13] of Byte =
231 ($1F, $27, $DC, $33, $DF, $BC, $03, $00, $31, $33, $52, $56, $40, $00,
232 $14, $00, $10, $00, $08, $00);
233 header_ident1_mac: array[0..$13] of Byte =
234 ($61, $30, $C1, $23, $DF, $BC, $03, $00, $31, $33, $52, $56, $40, $00,
235 $14, $00, $10, $00, $08, $00);
236 header_ident1_macbeta: array[0..$13] of Byte =
237 ($81, $11, $8D, $23, $DF, $BC, $03, $00, $31, $33, $52, $56, $40, $00,
238 $14, $00, $10, $00, $08, $00);
239 header_ident2: array[0..$F] of Byte =
240 ($99, $CF, $40, $00, $90, $4F, $63, $00, $F4, $55, $5F, $00, $90, $4F, $63, $00);
241var
242 i: LongWord;
243 header_pc, header_mac: Boolean;
244begin
245 FUnloadWhenUnused := True;
246 FDatOpened := False;
247 FRawOpened := False;
248 if not FileExists(DatFilename) then
249 begin
250 ShowMessage('File doesn''t exist!!!');
251 Result := False;
252 Exit;
253 end;
254 FFileName := DatFilename;
255 Fdat_file := TFileStream.Create(FFileName, fmOpenRead);
256 Fdat_file.Read(Fdat_header, SizeOf(Fdat_header));
257 header_pc := True;
258 header_mac := True;
259 for i := 0 to High(Fdat_header.Ident) do
260 begin
261 FLevelInfo.Ident[i] := Fdat_header.Ident[i];
262 if Fdat_header.Ident[i] <> header_ident1_pc[i] then
263 header_pc := False;
264 if Fdat_header.Ident[i] <> header_ident1_mac[i] then
265 header_mac := False;
266 end;
267 if not (header_pc xor header_mac) then
268 begin
269 Result := False;
270 Exit;
271 end
272 else
273 begin
274 if (header_pc and not header_mac) then
275 Fos_mac := False
276 else
277 Fos_mac := True;
278 end;
279 SetLength(Fdat_filesmap, Fdat_header.Files);
280 SetLength(Fdat_files, Fdat_header.Files);
281 for i := 0 to Fdat_header.Files - 1 do
282 Fdat_file.Read(Fdat_filesmap[i], SizeOf(Fdat_filesmap[i]));
283 for i := 0 to Fdat_header.Files - 1 do
284 begin
285 Fdat_files[i].ID := i;
286 Fdat_files[i].Extension := Fdat_filesmap[i].Extension;
287 Fdat_files[i].Extension := ReverseString(Fdat_files[i].Extension);
288 Fdat_files[i].Size := Fdat_filesmap[i].FileSize;
289 Fdat_files[i].FileType := Fdat_filesmap[i].FileType;
290 Fdat_files[i].DatAddr := Fdat_filesmap[i].DataAddr - 8 + Fdat_header.DataAddr;
291 if (Fdat_filesmap[i].FileType and $01) = 0 then
292 begin
293 Fdat_file.Seek(Fdat_filesmap[i].NameAddr + Fdat_header.NamesAddr, soFromBeginning);
294 SetLength(Fdat_files[i].Name, 100);
295 Fdat_file.Read(Fdat_files[i].Name[1], 100);
296 Fdat_files[i].Name := MidStr(Fdat_files[i].Name, 1 + 4, Pos(
297 #0, Fdat_files[i].Name) - 1 - 4);
298 end
299 else
300 begin
301 Fdat_files[i].Name := '';
302 end;
303 Fdat_files[i].FileName :=
304 FormatNumber(i, 5, '0') + '-' + Fdat_files[i].Name + '.' + Fdat_files[i].Extension;
305 Fdat_files[i].FileNameHex :=
306 IntToHex(i, 4) + '-' + Fdat_files[i].Name + '.' + Fdat_files[i].Extension;
307 end;
308 Fdat_file.Seek($40 + Fdat_header.Files * $14, soFromBeginning);
309 SetLength(Fdat_namedfilesmap, Fdat_header.NamedFiles);
310 for i := 0 to Fdat_header.NamedFiles - 1 do
311 Fdat_file.Read(Fdat_namedfilesmap[i], SizeOf(Fdat_namedfilesmap[i]));
312
313 Fdat_file.Seek($40 + Fdat_header.Files * $14 + Fdat_header.NamedFiles * $8, soFromBeginning);
314 SetLength(Fdat_extensionsmap, Fdat_header.Extensions);
315 for i := 0 to Fdat_header.Extensions - 1 do
316 Fdat_file.Read(Fdat_extensionsmap[i], SizeOf(Fdat_extensionsmap[i]));
317
318 Fdat_file.Seek(Fdat_files[0].DatAddr + 7, soFromBeginning);
319 Fdat_file.Read(FLevelInfo.LevelNumber, 1);
320 FLevelInfo.LevelNumber := FLevelInfo.LevelNumber div 2;
321
322 Fdat_file.Free;
323
324 Result := True;
325 FBackend := ODB_Dat;
326end;
327
328
329
330
331procedure TOniDataDat.Close;
332begin
333 if not FUnloadWhenUnused and FDatOpened then
334 Fdat_file.Free;
335 if not FUnloadWhenUnused and FRawOpened then
336 Fraw_file.Free;
337 if not FUnloadWhenUnused and FSepOpened then
338 Fsep_file.Free;
339 Self.Free;
340end;
341
342
343
344
345function TOniDataDat.GetFileInfo(fileid: LongWord): TFileInfo;
346begin
347 if fileid < Self.GetFilesCount then
348 Result := Fdat_files[fileid]
349 else
350 Result.ID := -1;
351end;
352
353
354
355
356function TOniDataDat.GetFilesList(ext: String; pattern: String;
357 NoEmptyFiles: Boolean; sort: TSortType): TStringArray;
358var
359 i: LongWord;
360 list: TStringList;
361 id, name, extension: String;
362 fields: TStrings;
363
364 procedure getfields;
365 begin
366 fields.CommaText := StringReplace(AnsiQuotedStr(list.Strings[i], '"'), ';', '","', [rfReplaceAll]);
367 if sort in [stIDAsc, stIDDesc] then
368 begin
369 id := fields.Strings[0];
370 name := fields.Strings[1];
371 extension := fields.Strings[2];
372 end;
373 if sort in [stNameAsc, stNameDesc] then
374 begin
375 id := fields.Strings[1];
376 name := fields.Strings[0];
377 extension := fields.Strings[2];
378 end;
379 if sort in [stExtAsc, stExtDesc] then
380 begin
381 id := fields.Strings[1];
382 name := fields.Strings[2];
383 extension := fields.Strings[0];
384 end;
385 end;
386
387begin
388 list := TStringList.Create;
389 list.Sorted := True;
390 for i := 0 to Fdat_header.Files - 1 do
391 begin
392 if ((Length(ext) = 0) or (Pos(Fdat_files[i].Extension, ext) > 0)) and
393 ((Length(pattern) = 0) or
394 (Pos(UpperCase(pattern), UpperCase(Fdat_files[i].Name)) > 0)) then
395 begin
396 if (NoEmptyFiles = False) or ((Fdat_files[i].FileType and $02) = 0) then
397 begin
398 if AppSettings.FilenumbersAsHex then
399 id := IntToHex(Fdat_files[i].ID, 4)
400 else
401 id := FormatNumber(Fdat_files[i].ID, 5, '0');
402 name := Fdat_files[i].Name;
403 extension := Fdat_files[i].Extension;
404
405 case sort of
406 stIDAsc, stIDDesc: list.Add(id + ';' + name + ';' + extension);
407 stNameAsc, stNameDesc: list.Add(name + ';' + id + ';' + extension);
408 stExtAsc, stExtDesc: list.Add(extension + ';' + id + ';' + name);
409 end;
410 end;
411 end;
412 end;
413 SetLength(Result, list.Count);
414 if Length(Result) > 0 then
415 begin
416 fields := TStringList.Create;
417 if sort in [stIDAsc, stNameAsc, stExtAsc] then
418 for i := 0 to list.Count - 1 do
419 begin
420 getfields;
421 Result[i] := id + '-' + name + '.' + extension;
422 end
423 else
424 for i := list.Count - 1 downto 0 do
425 begin
426 getfields;
427 Result[list.Count - i - 1] := id + '-' + name + '.' + extension;
428 end;
429 fields.Free;
430 end;
431 list.Free;
432end;
433
434
435
436
437function TOniDataDat.GetFilesCount: LongWord;
438begin
439 Result := Fdat_header.Files;
440end;
441
442
443
444
445function TOniDataDat.GetExtensionsList: TStringArray;
446var
447 i: LongWord;
448begin
449 SetLength(Result, Fdat_header.Extensions);
450 for i := 0 to Fdat_header.Extensions - 1 do
451 begin
452 with Fdat_extensionsmap[i] do
453 begin
454 Result[i] := Extension[3] + Extension[2] + Extension[1] + Extension[0] +
455 ' (' + IntToStr(ExtCount) + ')';
456 end;
457 end;
458end;
459
460
461
462
463function TOniDataDat.GetExtendedExtensionsList: TExtensionsMap;
464var
465 i: LongWord;
466begin
467 SetLength(Result, Fdat_header.Extensions);
468 for i := 0 to Fdat_header.Extensions - 1 do
469 begin
470 Result[i] := Fdat_extensionsmap[i];
471 end;
472end;
473
474
475
476
477function TOniDataDat.LoadDatFile(fileid: LongWord): Tdata;
478begin
479 if fileid < Self.GetFilesCount then
480 begin
481 if FUnloadWhenUnused or not FDatOpened then
482 Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite);
483 Fdat_file.Seek(Fdat_files[fileid].DatAddr, soFromBeginning);
484 SetLength(Result, Fdat_files[fileid].Size);
485 Fdat_file.Read(Result[0], Fdat_files[fileid].Size);
486 if UnloadWhenUnused then
487 Fdat_file.Free
488 else
489 FDatOpened := True;
490 end;
491end;
492
493
494
495
496procedure TOniDataDat.UpdateDatFile(fileid: LongWord; Data: Tdata);
497begin
498 if fileid < Self.GetFilesCount then
499 begin
500 if FUnloadWhenUnused or not FDatOpened then
501 Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite);
502 Fdat_file.Seek(Fdat_files[fileid].DatAddr, soFromBeginning);
503 Fdat_file.Write(Data[0], Length(Data));
504 if UnloadWhenUnused then
505 Fdat_file.Free
506 else
507 FDatOpened := True;
508 end;
509end;
510
511
512
513
514procedure TOniDataDat.LoadDatFilePart(fileid, offset, size: LongWord; target: Pointer);
515begin
516 if fileid < Self.GetFilesCount then
517 begin
518 if FUnloadWhenUnused or not FDatOpened then
519 Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite);
520 Fdat_file.Seek(Fdat_files[fileid].DatAddr + offset, soFromBeginning);
521 Fdat_file.Read(target^, size);
522 if UnloadWhenUnused then
523 Fdat_file.Free
524 else
525 FDatOpened := True;
526 end;
527end;
528
529
530
531
532procedure TOniDataDat.UpdateDatFilePart(fileid, offset, size: LongWord; target: Pointer);
533begin
534 if fileid < Self.GetFilesCount then
535 begin
536 if FUnloadWhenUnused or not FDatOpened then
537 Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite);
538 Fdat_file.Seek(Fdat_files[fileid].DatAddr + offset, soFromBeginning);
539 Fdat_file.Write(target^, size);
540 if UnloadWhenUnused then
541 Fdat_file.Free
542 else
543 FDatOpened := True;
544 end;
545end;
546
547
548
549
550function TOniDataDat.GetRawList(fileid: LongWord): TRawList;
551var
552 i: LongWord;
553begin
554 SetLength(Result, 0);
555 for i := 0 to High(RawListHandlers) do
556 if UpperCase(RawListHandlers[i].Ext) = UpperCase(Fdat_files[fileid].extension) then
557 if RawListHandlers[i].needed then
558 begin
559 Result := RawListHandlers[i].Handler(fileid);
560 Break;
561 end
562 else
563 Break;
564end;
565
566
567
568
569procedure TOniDataDat.LoadRawOffset(loc_sep: Boolean; raw_addr, size: LongWord;
570 target: Pointer);
571begin
572 if not loc_sep then
573 begin
574 if FUnloadWhenUnused or not FRawOpened then
575 Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
576 fmOpenReadWrite);
577 if raw_addr <= Fraw_file.Size then
578 begin
579 Fraw_file.Seek(raw_addr, soFromBeginning);
580 Fraw_file.Read(target^, size);
581 end;
582 if UnloadWhenUnused then
583 Fraw_file.Free
584 else
585 FRawOpened := True;
586 end
587 else
588 begin
589 if FUnloadWhenUnused or not FSepOpened then
590 Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
591 fmOpenReadWrite);
592 if raw_addr <= Fsep_file.Size then
593 begin
594 Fsep_file.Seek(raw_addr, soFromBeginning);
595 Fsep_file.Read(target^, size);
596 end;
597 if UnloadWhenUnused then
598 Fsep_file.Free
599 else
600 FSepOpened := True;
601 end;
602end;
603
604
605
606
607procedure TOniDataDat.LoadRawFile(fileid, dat_offset: LongWord; target: Pointer);
608var
609 raw_info: TRawInfo;
610begin
611 if fileid < Self.GetFilesCount then
612 begin
613 raw_info := Self.GetRawInfo(fileid, dat_offset);
614 if not raw_info.loc_sep then
615 begin
616 if FUnloadWhenUnused or not FRawOpened then
617 Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
618 fmOpenReadWrite);
619 Fraw_file.Seek(raw_info.raw_addr, soFromBeginning);
620 Fraw_file.Read(target^, raw_info.raw_size);
621 if UnloadWhenUnused then
622 Fraw_file.Free
623 else
624 FRawOpened := True;
625 end
626 else
627 begin
628 if FUnloadWhenUnused or not FSepOpened then
629 Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
630 fmOpenReadWrite);
631 Fsep_file.Seek(raw_info.raw_addr, soFromBeginning);
632 Fsep_file.Read(target^, raw_info.raw_size);
633 if UnloadWhenUnused then
634 Fsep_file.Free
635 else
636 FSepOpened := True;
637 end;
638 end;
639end;
640
641
642
643
644procedure TOniDataDat.UpdateRawFile(fileid, dat_offset: LongWord;
645 size: LongWord; target: Pointer);
646var
647 raw_info: TRawInfo;
648begin
649 if fileid < Self.GetFilesCount then
650 begin
651 raw_info := Self.GetRawInfo(fileid, dat_offset);
652 if not raw_info.loc_sep then
653 begin
654 if FUnloadWhenUnused or not FRawOpened then
655 Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
656 fmOpenReadWrite);
657 Fraw_file.Seek(raw_info.raw_addr, soFromBeginning);
658 Fraw_file.Write(target^, raw_info.raw_size);
659 if UnloadWhenUnused then
660 Fraw_file.Free
661 else
662 FRawOpened := True;
663 end
664 else
665 begin
666 if FUnloadWhenUnused or not FSepOpened then
667 Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
668 fmOpenReadWrite);
669 Fsep_file.Seek(raw_info.raw_addr, soFromBeginning);
670 Fsep_file.Write(target^, raw_info.raw_size);
671 if UnloadWhenUnused then
672 Fsep_file.Free
673 else
674 FSepOpened := True;
675 end;
676 end;
677end;
678
679
680
681
682procedure TOniDataDat.LoadRawFilePart(fileid, dat_offset: LongWord;
683 offset, size: LongWord; target: Pointer);
684var
685 raw_info: TRawInfo;
686 Data: Tdata;
687 mem: TMemoryStream;
688begin
689 if fileid < Self.GetFilesCount then
690 begin
691 raw_info := Self.GetRawInfo(fileid, dat_offset);
692 SetLength(Data, raw_info.raw_size);
693 Self.LoadRawFile(fileid, dat_offset, @Data[0]);
694 mem := TMemoryStream.Create;
695 mem.Write(Data[offset], size);
696 mem.Read(target^, size);
697 mem.Free;
698 end;
699end;
700
701
702
703
704procedure TOniDataDat.UpdateRawFilePart(fileid, dat_offset: LongWord;
705 offset, size: LongWord; target: Pointer);
706var
707 raw_info: TRawInfo;
708begin
709 if fileid < Self.GetFilesCount then
710 begin
711 raw_info := Self.GetRawInfo(fileid, dat_offset);
712 if not raw_info.loc_sep then
713 begin
714 if FUnloadWhenUnused or not FRawOpened then
715 Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
716 fmOpenReadWrite);
717 Fraw_file.Seek(raw_info.raw_addr + offset, soFromBeginning);
718 Fraw_file.Write(target^, raw_info.raw_size);
719 if UnloadWhenUnused then
720 Fraw_file.Free
721 else
722 FRawOpened := True;
723 end
724 else
725 begin
726 if FUnloadWhenUnused or not FSepOpened then
727 Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
728 fmOpenReadWrite);
729 Fsep_file.Seek(raw_info.raw_addr + offset, soFromBeginning);
730 Fsep_file.Write(target^, raw_info.raw_size);
731 if UnloadWhenUnused then
732 Fsep_file.Free
733 else
734 FSepOpened := True;
735 end;
736 end;
737end;
738
739
740
741
742function TOniDataDat.AppendRawFile(loc_sep: Boolean; size: LongWord;
743 target: Pointer): LongWord; //Returns new Address
744begin
745 if not loc_sep then
746 begin
747 if FUnloadWhenUnused or not FRawOpened then
748 Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
749 fmOpenReadWrite);
750 Result := Fraw_file.Size;
751 Fraw_file.Seek(0, soFromEnd);
752 Fraw_file.Write(target^, size);
753 if UnloadWhenUnused then
754 Fraw_file.Free
755 else
756 FRawOpened := True;
757 end
758 else
759 begin
760 if FUnloadWhenUnused or not FSepOpened then
761 Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
762 fmOpenReadWrite);
763 Result := Fsep_file.Size;
764 Fsep_file.Seek(0, soFromEnd);
765 Fsep_file.Write(target^, size);
766 if UnloadWhenUnused then
767 Fsep_file.Free
768 else
769 FSepOpened := True;
770 end;
771end;
772
773
774
775
776
777
778
779
780
781
782
783(*
784================================================================================
785 Implementation of TOniDataADB
786*)
787
788constructor TOniDataADB.Create(OLDBFilename: String; var Result: Boolean);
789var
790 i, j: Byte;
791 temps: String;
792begin
793 if not FileExists(OLDBFilename) then
794 begin
795 ShowMessage('File doesn''t exist!!!');
796 Result := False;
797 Exit;
798 end;
799 FFileName := OLDBFilename;
800 FDatabase := TABSDatabase.Create(nil);
801 FDatabase.DatabaseName := 'OLDBcon';
802 FDatabase.DatabaseFileName := OLDBFilename;
803 FDatabase.Open;
804 FQuery := TABSQuery.Create(FDatabase);
805 FQuery.DatabaseName := 'OLDBcon';
806 FQuery.SQL.Text := 'SELECT [name],[value] FROM globals ORDER BY [name] ASC';
807 FQuery.Open;
808 FQuery.First;
809 repeat
810 if FQuery.FieldByName('name').AsString = 'dbversion' then
811 begin
812 if FQuery.FieldByName('value').AsString <> DBversion then
813 begin
814 ShowMessage('Database-file ' + #13 + #10 +
815 '"' + OLDBFilename + '"' + #13 + #10 +
816 'has wrong version. (Required: ' + DBversion + '; found: ' +
817 FQuery.FieldByName('value').AsString + ')');
818 FQuery.Close;
819 Result := False;
820 Exit;
821 end;
822 end;
823 if FQuery.FieldByName('name').AsString = 'lvl' then
824 begin
825 FLevelInfo.LevelNumber := StrToInt(FQuery.FieldByName('value').AsString);
826 end;
827 if FQuery.FieldByName('name').AsString = 'ident' then
828 begin
829 temps := FQuery.FieldByName('value').AsString;
830 for i := 0 to High(FLevelInfo.Ident) do
831 begin
832 j := i * 2 + 1;
833 case temps[j] of
834 '0'..'9':
835 FLevelInfo.Ident[i] := Ord(temps[j]) - 48;
836 'A'..'F':
837 FLevelInfo.Ident[i] := Ord(temps[j]) - 55;
838 end;
839 FLevelInfo.Ident[i] := FLevelInfo.Ident[i] * 16;
840 case temps[j + 1] of
841 '0'..'9':
842 FLevelInfo.Ident[i] := FLevelInfo.Ident[i] + Ord(temps[j + 1]) - 48;
843 'A'..'F':
844 FLevelInfo.Ident[i] := FLevelInfo.Ident[i] + Ord(temps[j + 1]) - 55;
845 end;
846 end;
847 end;
848 if FQuery.FieldByName('name').AsString = 'ident' then
849 begin
850 temps := FQuery.FieldByName('value').AsString;
851 Fos_mac := temps = 'MAC';
852 end;
853 FQuery.Next;
854 until FQuery.EOF;
855 FQuery.Close;
856
857 UpdateListCache;
858
859 Result := True;
860 FBackend := ODB_ADB;
861end;
862
863
864
865
866procedure TOniDataADB.Close;
867begin
868 FDatabase.Close;
869 FDatabase.Free;
870 Self.Free;
871end;
872
873
874
875procedure TOniDataADB.UpdateListCache;
876var
877 i: LongWord;
878 temps: String;
879begin
880 FQuery.SQL.Text := 'SELECT id,name,extension,[size],contenttype FROM datfiles ORDER BY id ASC;';
881 FQuery.Open;
882 if FQuery.RecordCount > 0 then
883 begin
884 FQuery.First;
885 SetLength(Fdat_files, FQuery.RecordCount);
886 i := 0;
887 repeat
888 Fdat_files[i].ID := FQuery.FieldByName('id').AsInteger;
889 Fdat_files[i].Name := FQuery.FieldByName('name').AsString;
890 Fdat_files[i].Extension := FQuery.FieldByName('extension').AsString;
891 Fdat_files[i].FileName := FormatNumber(Fdat_files[i].ID, 5, '0') + '-' +
892 Fdat_files[i].Name + '.' + Fdat_files[0].Extension;
893 Fdat_files[i].FileNameHex := IntToHex(Fdat_files[i].ID, 4) + '-' +
894 Fdat_files[i].Name + '.' + Fdat_files[0].Extension;
895 Fdat_files[i].Size := FQuery.FieldByName('size').AsInteger;
896 Fdat_files[i].FileType := HexToLong(FQuery.FieldByName('contenttype').AsString);
897 Fdat_files[i].DatAddr := 0;
898 Fdat_files[i].opened := False;
899 Inc(i);
900 FQuery.Next;
901 until FQuery.EOF;
902 end;
903 FQuery.Close;
904
905 SetLength(Fdat_extensionsmap, 0);
906 FQuery.SQL.Text :=
907 'SELECT extension,count(extension) AS x FROM datfiles GROUP BY extension ORDER BY extension ASC;';
908 FQuery.Open;
909 if FQuery.RecordCount > 0 then
910 begin
911 SetLength(Fdat_extensionsmap, FQuery.RecordCount);
912 i := 0;
913 repeat
914 temps := FQuery.FieldByName('extension').AsString[1];
915 Fdat_extensionsmap[i].Extension[3] := temps[1];
916 Fdat_extensionsmap[i].Extension[2] := temps[2];
917 Fdat_extensionsmap[i].Extension[1] := temps[3];
918 Fdat_extensionsmap[i].Extension[0] := temps[4];
919 Fdat_extensionsmap[i].ExtCount := FQuery.FieldByName('x').AsInteger;
920 Inc(i);
921 FQuery.Next;
922 until FQuery.EOF;
923 end;
924 FQuery.Close;
925end;
926
927
928function TOniDataADB.GetFileInfo(fileid: LongWord): TFileInfo;
929var
930 i: Integer;
931begin
932 if fileid < Self.GetFilesCount then
933 begin
934 for i := 0 to High(Fdat_files) do
935 if Fdat_files[i].ID = fileid then
936 Break;
937 if i < Length(Fdat_files) then
938 Result := Fdat_files[i]
939 else
940 Result.ID := -1;
941 end
942 else
943 begin
944 Result.ID := -1;
945 end;
946end;
947
948
949
950
951function TOniDataADB.GetFilesList(ext: String; pattern: String;
952 NoEmptyFiles: Boolean; sort: TSortType): TStringArray;
953var
954 i: LongWord;
955 list: TStringList;
956 id, name, extension: String;
957 fields: TStrings;
958
959 procedure getfields;
960 begin
961 fields.CommaText := StringReplace(AnsiQuotedStr(list.Strings[i], '"'), ';', '","', [rfReplaceAll]);
962 if sort in [stIDAsc, stIDDesc] then
963 begin
964 id := fields.Strings[0];
965 name := fields.Strings[1];
966 extension := fields.Strings[2];
967 end;
968 if sort in [stNameAsc, stNameDesc] then
969 begin
970 id := fields.Strings[1];
971 name := fields.Strings[0];
972 extension := fields.Strings[2];
973 end;
974 if sort in [stExtAsc, stExtDesc] then
975 begin
976 id := fields.Strings[1];
977 name := fields.Strings[2];
978 extension := fields.Strings[0];
979 end;
980 end;
981
982begin
983 list := TStringList.Create;
984 list.Sorted := True;
985 for i := 0 to High(Fdat_files) do
986 begin
987 if ((Length(ext) = 0) or (Pos(Fdat_files[i].Extension, ext) > 0)) and
988 ((Length(pattern) = 0) or
989 (Pos(UpperCase(pattern), UpperCase(Fdat_files[i].Name)) > 0)) then
990 begin
991 if (NoEmptyFiles = False) or ((Fdat_files[i].FileType and $02) = 0) then
992 begin
993 if AppSettings.FilenumbersAsHex then
994 id := IntToHex(Fdat_files[i].ID, 4)
995 else
996 id := FormatNumber(Fdat_files[i].ID, 5, '0');
997 name := Fdat_files[i].Name;
998 extension := Fdat_files[i].Extension;
999
1000 case sort of
1001 stIDAsc, stIDDesc: list.Add(id + ';' + name + ';' + extension);
1002 stNameAsc, stNameDesc: list.Add(name + ';' + id + ';' + extension);
1003 stExtAsc, stExtDesc: list.Add(extension + ';' + id + ';' + name);
1004 end;
1005 end;
1006 end;
1007 end;
1008 SetLength(Result, list.Count);
1009 fields := TStringList.Create;
1010 if sort in [stIDAsc, stNameAsc, stExtAsc] then
1011 for i := 0 to list.Count - 1 do
1012 begin
1013 getfields;
1014 Result[i] := id + '-' + name + '.' + extension;
1015 end
1016 else
1017 for i := list.Count - 1 downto 0 do
1018 begin
1019 getfields;
1020 Result[list.Count - i - 1] := id + '-' + name + '.' + extension;
1021 end;
1022 list.Free;
1023 fields.Free;
1024end;
1025
1026
1027
1028
1029function TOniDataADB.GetFilesCount: LongWord;
1030begin
1031 Result := Length(Fdat_files);
1032end;
1033
1034
1035
1036
1037function TOniDataADB.GetExtensionsList: TStringArray;
1038var
1039 i: LongWord;
1040begin
1041 SetLength(Result, Length(Fdat_extensionsmap));
1042 for i := 0 to High(Result) do
1043 begin
1044 with Fdat_extensionsmap[i] do
1045 begin
1046 Result[i] := Extension[3] + Extension[2] + Extension[1] + Extension[0] +
1047 ' (' + IntToStr(ExtCount) + ')';
1048 end;
1049 end;
1050end;
1051
1052
1053
1054
1055function TOniDataADB.GetExtendedExtensionsList: TExtensionsMap;
1056var
1057 i, j: LongWord;
1058 temps: String;
1059 Data: Tdata;
1060begin
1061 SetLength(Result, 0);
1062 FQuery.SQL.Text := 'SELECT ext,ident FROM extlist ORDER BY ext ASC;';
1063 FQuery.Open;
1064 if FQuery.RecordCount > 0 then
1065 begin
1066 SetLength(Result, FQuery.RecordCount);
1067 i := 0;
1068 repeat
1069 temps := FQuery.FieldByName('ext').AsString;
1070 for j := 0 to 3 do
1071 Result[i].Extension[j] := temps[4 - j];
1072 Data := DecodeHexString(FQuery.FieldByName('ident').AsString);
1073 for j := 0 to 7 do
1074 Result[i].Ident[j] := Data[j];
1075 Inc(i);
1076 FQuery.Next;
1077 until FQuery.EOF;
1078 end;
1079 FQuery.Close;
1080end;
1081
1082
1083
1084
1085function TOniDataADB.GetNamedFilesMap: TNamedFilesMap;
1086var
1087 i: LongWord;
1088 temp: Integer;
1089 temps: String;
1090 temparray: array of record
1091 id: Integer;
1092 fullname: String[50];
1093 end;
1094begin
1095 SetLength(temparray, 0);
1096 FQuery.SQL.Text :=
1097 'SELECT id,(extension+name) AS xname FROM datfiles WHERE Length(name)>0 ORDER BY extension,name ASC;';
1098 FQuery.Open;
1099 if FQuery.RecordCount > 0 then
1100 begin
1101 repeat
1102 temp := FQuery.FieldByName('id').AsInteger;
1103 temps := FQuery.FieldByName('xname').AsString;
1104
1105 SetLength(temparray, Length(temparray) + 1);
1106 if Length(temparray) > 1 then
1107 begin
1108 for i := High(temparray) - 1 downto 0 do
1109 begin
1110 if StringSmaller(temps, temparray[i].fullname) then
1111 begin
1112 temparray[i + 1] := temparray[i];
1113 if i = 0 then
1114 begin
1115 temparray[i].id := temp;
1116 temparray[i].fullname := temps;
1117 end;
1118 end
1119 else
1120 begin
1121 temparray[i + 1].id := temp;
1122 temparray[i + 1].fullname := temps;
1123 Break;
1124 end;
1125 end;
1126 end
1127 else
1128 begin
1129 temparray[0].id := temp;
1130 temparray[0].fullname := temps;
1131 end;
1132 FQuery.Next;
1133 until FQuery.EOF;
1134 end;
1135 FQuery.Close;
1136 SetLength(Result, Length(temparray));
1137 for i := 0 to High(temparray) do
1138 begin
1139 Result[i].FileNumber := temparray[i].id;
1140 Result[i].blubb := 0;
1141 end;
1142end;
1143
1144
1145
1146
1147function TOniDataADB.LoadDatFile(fileid: LongWord): Tdata;
1148var
1149 mem: TStream;
1150begin
1151 if fileid < Self.GetFilesCount then
1152 begin
1153 FQuery.SQL.Text := 'SELECT data FROM datfiles WHERE id=' + IntToStr(fileid) + ';';
1154 FQuery.Open;
1155 if FQuery.RecordCount > 0 then
1156 begin
1157 mem := FQuery.CreateBlobStream(FQuery.FieldByName('data'), bmRead);
1158 SetLength(Result, mem.Size);
1159 mem.Seek(0, soFromBeginning);
1160 mem.Read(Result[0], mem.Size);
1161 mem.Free;
1162 end;
1163 FQuery.Close;
1164 end;
1165end;
1166
1167
1168
1169
1170procedure TOniDataADB.UpdateDatFile(fileid: LongWord; Data: Tdata);
1171var
1172 MimeCoder: TStringFormat_MIME64;
1173 mem: TMemoryStream;
1174begin
1175 if fileid < Self.GetFilesCount then
1176 begin
1177 mimecoder := TStringFormat_MIME64.Create;
1178 mem := TMemoryStream.Create;
1179 mem.Write(Data[0], Length(Data));
1180 mem.Seek(0, soFromBeginning);
1181 FQuery.SQL.Text := 'UPDATE datfiles SET data=MimeToBin("' +
1182 MimeCoder.StrTo(mem.Memory, mem.Size) + '"), size=' + IntToStr(mem.Size) +
1183 ' WHERE id=' + IntToStr(fileid) + ';';
1184 FQuery.ExecSQL;
1185 mem.Free;
1186 mimecoder.Free;
1187 end;
1188 UpdateListCache;
1189end;
1190
1191
1192
1193
1194procedure TOniDataADB.LoadDatFilePart(fileid, offset, size: LongWord; target: Pointer);
1195var
1196 mem: TStream;
1197begin
1198 if fileid < Self.GetFilesCount then
1199 begin
1200 FQuery.SQL.Text := 'SELECT data FROM datfiles WHERE id=' + IntToStr(fileid) + ';';
1201 FQuery.Open;
1202 if FQuery.RecordCount > 0 then
1203 begin
1204 mem := FQuery.CreateBlobStream(FQuery.FieldByName('data'), bmRead);
1205 mem.Seek(offset, soFromBeginning);
1206 mem.Read(target^, size);
1207 mem.Free;
1208 end;
1209 FQuery.Close;
1210 end;
1211end;
1212
1213
1214
1215
1216procedure TOniDataADB.UpdateDatFilePart(fileid, offset, size: LongWord; target: Pointer);
1217var
1218 MimeCoder: TStringFormat_MIME64;
1219 mem: TMemoryStream;
1220 Data: Tdata;
1221begin
1222 if fileid < Self.GetFilesCount then
1223 begin
1224 Data := Self.LoadDatFile(fileid);
1225 mimecoder := TStringFormat_MIME64.Create;
1226 mem := TMemoryStream.Create;
1227 mem.Write(Data[0], Length(Data));
1228 mem.Seek(offset, soFromBeginning);
1229 mem.Write(target^, size);
1230 mem.Seek(0, soFromBeginning);
1231 FQuery.SQL.Text := 'UPDATE datfiles SET data=MimeToBin("' +
1232 MimeCoder.StrTo(mem.Memory, mem.Size) + '") WHERE id=' + IntToStr(fileid) + ';';
1233 FQuery.ExecSQL;
1234 mem.Free;
1235 mimecoder.Free;
1236 end;
1237end;
1238
1239
1240
1241
1242function TOniDataADB.GetRawList(fileid: LongWord): TRawList;
1243var
1244 i: LongWord;
1245begin
1246 SetLength(Result, 0);
1247 FQuery.SQL.Text := 'SELECT [src_link_offset],[size],[sep] FROM rawmap WHERE [src_id]=' +
1248 IntToStr(fileid) + ' ORDER BY src_link_offset ASC;';
1249 FQuery.Open;
1250 if FQuery.RecordCount > 0 then
1251 begin
1252 FQuery.First;
1253 SetLength(Result, FQuery.RecordCount);
1254 i := 0;
1255 repeat
1256 Result[i].src_id := fileid;
1257 Result[i].src_offset := FQuery.FieldByName('src_link_offset').AsInteger;
1258 Result[i].raw_addr := 0;
1259 Result[i].raw_size := FQuery.FieldByName('size').AsInteger;
1260 Result[i].loc_sep := FQuery.FieldByName('sep').AsBoolean;
1261 Inc(i);
1262 FQuery.Next;
1263 until FQuery.EOF;
1264 end;
1265 FQuery.Close;
1266end;
1267
1268
1269
1270
1271procedure TOniDataADB.LoadRawFile(fileid, dat_offset: LongWord; target: Pointer);
1272var
1273 mem: TStream;
1274begin
1275 if fileid < Self.GetFilesCount then
1276 begin
1277 FQuery.SQL.Text := 'SELECT data FROM rawmap WHERE (src_id=' +
1278 IntToStr(fileid) + ') AND (src_link_offset=' + IntToStr(dat_offset) + ');';
1279 FQuery.Open;
1280 if FQuery.RecordCount > 0 then
1281 begin
1282 mem := FQuery.CreateBlobStream(FQuery.FieldByName('data'), bmRead);
1283 mem.Seek(0, soFromBeginning);
1284 mem.Read(target^, mem.size);
1285 mem.Free;
1286 end;
1287 FQuery.Close;
1288 end;
1289end;
1290
1291
1292
1293
1294procedure TOniDataADB.UpdateRawFile(fileid, dat_offset: LongWord;
1295 size: LongWord; target: Pointer);
1296var
1297 MimeCoder: TStringFormat_MIME64;
1298 mem: TMemoryStream;
1299begin
1300 if fileid < Self.GetFilesCount then
1301 begin
1302 mimecoder := TStringFormat_MIME64.Create;
1303 mem := TMemoryStream.Create;
1304 mem.Write(target^, size);
1305 mem.Seek(0, soFromBeginning);
1306 FQuery.SQL.Text := 'UPDATE rawmap SET data=MimeToBin("' + MimeCoder.StrTo(
1307 mem.Memory, mem.Size) + '") WHERE (src_id=' + IntToStr(fileid) +
1308 ') AND (src_link_offset=' + IntToStr(dat_offset) + ');';
1309 FQuery.ExecSQL;
1310 mem.Free;
1311 mimecoder.Free;
1312 end;
1313end;
1314
1315
1316
1317
1318procedure TOniDataADB.LoadRawFilePart(fileid, dat_offset: LongWord;
1319 offset, size: LongWord; target: Pointer);
1320var
1321 Data: Tdata;
1322 mem: TMemoryStream;
1323begin
1324 if fileid < Self.GetFilesCount then
1325 begin
1326 SetLength(Data, Self.GetRawInfo(fileid, dat_offset).raw_size);
1327 Self.LoadRawFile(fileid, dat_offset, @Data[0]);
1328 mem := TMemoryStream.Create;
1329 mem.Write(Data[offset], size);
1330 mem.Read(target^, size);
1331 mem.Free;
1332 end;
1333end;
1334
1335
1336
1337
1338procedure TOniDataADB.UpdateRawFilePart(fileid, dat_offset: LongWord;
1339 offset, size: LongWord; target: Pointer);
1340var
1341 MimeCoder: TStringFormat_MIME64;
1342 mem: TMemoryStream;
1343 Data: Tdata;
1344begin
1345 if fileid < Self.GetFilesCount then
1346 begin
1347 SetLength(Data, Self.GetRawInfo(fileid, offset).raw_size);
1348 Self.LoadRawFile(fileid, offset, @Data[0]);
1349 mimecoder := TStringFormat_MIME64.Create;
1350 mem := TMemoryStream.Create;
1351 mem.Write(Data[0], Length(Data));
1352 mem.Seek(offset, soFromBeginning);
1353 mem.Write(target^, size);
1354 mem.Seek(0, soFromBeginning);
1355 FQuery.SQL.Text := 'UPDATE rawmap SET data=MimeToBin("' + MimeCoder.StrTo(
1356 mem.Memory, mem.Size) + '") WHERE (src_id=' + IntToStr(fileid) +
1357 ') AND (src_link_offset=' + IntToStr(dat_offset) + ');';
1358 FQuery.ExecSQL;
1359 mem.Free;
1360 mimecoder.Free;
1361 end;
1362end;
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374function CreateDataConnection(filename: String; backend: Integer): Boolean;
1375var
1376 answer: Boolean;
1377begin
1378 if Assigned(OniDataConnection) then
1379 begin
1380 OniDataConnection.Close;
1381 OniDataConnection.Free;
1382 OniDataConnection := nil;
1383 end;
1384 case backend of
1385 ODB_Dat:
1386 OniDataConnection := TOniDataDat.Create(filename, answer);
1387 ODB_ADB:
1388 OniDataConnection := TOniDataADB.Create(filename, answer);
1389 else
1390 ShowMessage('Unknown Backend');
1391 Result := False;
1392 Exit;
1393 end;
1394
1395 if answer then
1396 begin
1397 // ShowMessage('file loaded');
1398 // ShowMessage('Files: '+IntToStr(OniDataConnection.GetFilesCount));
1399 Result := True;
1400 end
1401 else
1402 begin
1403 ShowMessage('File not loaded');
1404 OniDataConnection.Close;
1405 OniDataConnection.Free;
1406 Result := False;
1407 end;
1408end;
1409
1410
1411
1412
1413procedure CloseDataConnection;
1414begin
1415 if Assigned(OniDataConnection) then
1416 begin
1417 OniDataConnection.Close;
1418 OniDataConnection := nil;
1419 end;
1420end;
1421
1422end.
Note: See TracBrowser for help on using the repository browser.