source: oup/current/Code/OniDataClass.pas@ 53

Last change on this file since 53 was 51, 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 fields := TStringList.Create;
415 if sort in [stIDAsc, stNameAsc, stExtAsc] then
416 for i := 0 to list.Count - 1 do
417 begin
418 getfields;
419 Result[i] := id + '-' + name + '.' + extension;
420 end
421 else
422 for i := list.Count - 1 downto 0 do
423 begin
424 getfields;
425 Result[list.Count - i - 1] := id + '-' + name + '.' + extension;
426 end;
427 list.Free;
428 fields.Free;
429end;
430
431
432
433
434function TOniDataDat.GetFilesCount: LongWord;
435begin
436 Result := Fdat_header.Files;
437end;
438
439
440
441
442function TOniDataDat.GetExtensionsList: TStringArray;
443var
444 i: LongWord;
445begin
446 SetLength(Result, Fdat_header.Extensions);
447 for i := 0 to Fdat_header.Extensions - 1 do
448 begin
449 with Fdat_extensionsmap[i] do
450 begin
451 Result[i] := Extension[3] + Extension[2] + Extension[1] + Extension[0] +
452 ' (' + IntToStr(ExtCount) + ')';
453 end;
454 end;
455end;
456
457
458
459
460function TOniDataDat.GetExtendedExtensionsList: TExtensionsMap;
461var
462 i: LongWord;
463begin
464 SetLength(Result, Fdat_header.Extensions);
465 for i := 0 to Fdat_header.Extensions - 1 do
466 begin
467 Result[i] := Fdat_extensionsmap[i];
468 end;
469end;
470
471
472
473
474function TOniDataDat.LoadDatFile(fileid: LongWord): Tdata;
475begin
476 if fileid < Self.GetFilesCount then
477 begin
478 if FUnloadWhenUnused or not FDatOpened then
479 Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite);
480 Fdat_file.Seek(Fdat_files[fileid].DatAddr, soFromBeginning);
481 SetLength(Result, Fdat_files[fileid].Size);
482 Fdat_file.Read(Result[0], Fdat_files[fileid].Size);
483 if UnloadWhenUnused then
484 Fdat_file.Free
485 else
486 FDatOpened := True;
487 end;
488end;
489
490
491
492
493procedure TOniDataDat.UpdateDatFile(fileid: LongWord; Data: Tdata);
494begin
495 if fileid < Self.GetFilesCount then
496 begin
497 if FUnloadWhenUnused or not FDatOpened then
498 Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite);
499 Fdat_file.Seek(Fdat_files[fileid].DatAddr, soFromBeginning);
500 Fdat_file.Write(Data[0], Length(Data));
501 if UnloadWhenUnused then
502 Fdat_file.Free
503 else
504 FDatOpened := True;
505 end;
506end;
507
508
509
510
511procedure TOniDataDat.LoadDatFilePart(fileid, offset, size: LongWord; target: Pointer);
512begin
513 if fileid < Self.GetFilesCount then
514 begin
515 if FUnloadWhenUnused or not FDatOpened then
516 Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite);
517 Fdat_file.Seek(Fdat_files[fileid].DatAddr + offset, soFromBeginning);
518 Fdat_file.Read(target^, size);
519 if UnloadWhenUnused then
520 Fdat_file.Free
521 else
522 FDatOpened := True;
523 end;
524end;
525
526
527
528
529procedure TOniDataDat.UpdateDatFilePart(fileid, offset, size: LongWord; target: Pointer);
530begin
531 if fileid < Self.GetFilesCount then
532 begin
533 if FUnloadWhenUnused or not FDatOpened then
534 Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite);
535 Fdat_file.Seek(Fdat_files[fileid].DatAddr + offset, soFromBeginning);
536 Fdat_file.Write(target^, size);
537 if UnloadWhenUnused then
538 Fdat_file.Free
539 else
540 FDatOpened := True;
541 end;
542end;
543
544
545
546
547function TOniDataDat.GetRawList(fileid: LongWord): TRawList;
548var
549 i: LongWord;
550begin
551 SetLength(Result, 0);
552 for i := 0 to High(RawListHandlers) do
553 if UpperCase(RawListHandlers[i].Ext) = UpperCase(Fdat_files[fileid].extension) then
554 if RawListHandlers[i].needed then
555 begin
556 Result := RawListHandlers[i].Handler(fileid);
557 Break;
558 end
559 else
560 Break;
561end;
562
563
564
565
566procedure TOniDataDat.LoadRawOffset(loc_sep: Boolean; raw_addr, size: LongWord;
567 target: Pointer);
568begin
569 if not loc_sep then
570 begin
571 if FUnloadWhenUnused or not FRawOpened then
572 Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
573 fmOpenReadWrite);
574 if raw_addr <= Fraw_file.Size then
575 begin
576 Fraw_file.Seek(raw_addr, soFromBeginning);
577 Fraw_file.Read(target^, size);
578 end;
579 if UnloadWhenUnused then
580 Fraw_file.Free
581 else
582 FRawOpened := True;
583 end
584 else
585 begin
586 if FUnloadWhenUnused or not FSepOpened then
587 Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
588 fmOpenReadWrite);
589 if raw_addr <= Fsep_file.Size then
590 begin
591 Fsep_file.Seek(raw_addr, soFromBeginning);
592 Fsep_file.Read(target^, size);
593 end;
594 if UnloadWhenUnused then
595 Fsep_file.Free
596 else
597 FSepOpened := True;
598 end;
599end;
600
601
602
603
604procedure TOniDataDat.LoadRawFile(fileid, dat_offset: LongWord; target: Pointer);
605var
606 raw_info: TRawInfo;
607begin
608 if fileid < Self.GetFilesCount then
609 begin
610 raw_info := Self.GetRawInfo(fileid, dat_offset);
611 if not raw_info.loc_sep then
612 begin
613 if FUnloadWhenUnused or not FRawOpened then
614 Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
615 fmOpenReadWrite);
616 Fraw_file.Seek(raw_info.raw_addr, soFromBeginning);
617 Fraw_file.Read(target^, raw_info.raw_size);
618 if UnloadWhenUnused then
619 Fraw_file.Free
620 else
621 FRawOpened := True;
622 end
623 else
624 begin
625 if FUnloadWhenUnused or not FSepOpened then
626 Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
627 fmOpenReadWrite);
628 Fsep_file.Seek(raw_info.raw_addr, soFromBeginning);
629 Fsep_file.Read(target^, raw_info.raw_size);
630 if UnloadWhenUnused then
631 Fsep_file.Free
632 else
633 FSepOpened := True;
634 end;
635 end;
636end;
637
638
639
640
641procedure TOniDataDat.UpdateRawFile(fileid, dat_offset: LongWord;
642 size: LongWord; target: Pointer);
643var
644 raw_info: TRawInfo;
645begin
646 if fileid < Self.GetFilesCount then
647 begin
648 raw_info := Self.GetRawInfo(fileid, dat_offset);
649 if not raw_info.loc_sep then
650 begin
651 if FUnloadWhenUnused or not FRawOpened then
652 Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
653 fmOpenReadWrite);
654 Fraw_file.Seek(raw_info.raw_addr, soFromBeginning);
655 Fraw_file.Write(target^, raw_info.raw_size);
656 if UnloadWhenUnused then
657 Fraw_file.Free
658 else
659 FRawOpened := True;
660 end
661 else
662 begin
663 if FUnloadWhenUnused or not FSepOpened then
664 Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
665 fmOpenReadWrite);
666 Fsep_file.Seek(raw_info.raw_addr, soFromBeginning);
667 Fsep_file.Write(target^, raw_info.raw_size);
668 if UnloadWhenUnused then
669 Fsep_file.Free
670 else
671 FSepOpened := True;
672 end;
673 end;
674end;
675
676
677
678
679procedure TOniDataDat.LoadRawFilePart(fileid, dat_offset: LongWord;
680 offset, size: LongWord; target: Pointer);
681var
682 raw_info: TRawInfo;
683 Data: Tdata;
684 mem: TMemoryStream;
685begin
686 if fileid < Self.GetFilesCount then
687 begin
688 raw_info := Self.GetRawInfo(fileid, dat_offset);
689 SetLength(Data, raw_info.raw_size);
690 Self.LoadRawFile(fileid, dat_offset, @Data[0]);
691 mem := TMemoryStream.Create;
692 mem.Write(Data[offset], size);
693 mem.Read(target^, size);
694 mem.Free;
695 end;
696end;
697
698
699
700
701procedure TOniDataDat.UpdateRawFilePart(fileid, dat_offset: LongWord;
702 offset, size: LongWord; target: Pointer);
703var
704 raw_info: TRawInfo;
705begin
706 if fileid < Self.GetFilesCount then
707 begin
708 raw_info := Self.GetRawInfo(fileid, dat_offset);
709 if not raw_info.loc_sep then
710 begin
711 if FUnloadWhenUnused or not FRawOpened then
712 Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
713 fmOpenReadWrite);
714 Fraw_file.Seek(raw_info.raw_addr + offset, soFromBeginning);
715 Fraw_file.Write(target^, raw_info.raw_size);
716 if UnloadWhenUnused then
717 Fraw_file.Free
718 else
719 FRawOpened := True;
720 end
721 else
722 begin
723 if FUnloadWhenUnused or not FSepOpened then
724 Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
725 fmOpenReadWrite);
726 Fsep_file.Seek(raw_info.raw_addr + offset, soFromBeginning);
727 Fsep_file.Write(target^, raw_info.raw_size);
728 if UnloadWhenUnused then
729 Fsep_file.Free
730 else
731 FSepOpened := True;
732 end;
733 end;
734end;
735
736
737
738
739function TOniDataDat.AppendRawFile(loc_sep: Boolean; size: LongWord;
740 target: Pointer): LongWord; //Returns new Address
741begin
742 if not loc_sep then
743 begin
744 if FUnloadWhenUnused or not FRawOpened then
745 Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
746 fmOpenReadWrite);
747 Result := Fraw_file.Size;
748 Fraw_file.Seek(0, soFromEnd);
749 Fraw_file.Write(target^, size);
750 if UnloadWhenUnused then
751 Fraw_file.Free
752 else
753 FRawOpened := True;
754 end
755 else
756 begin
757 if FUnloadWhenUnused or not FSepOpened then
758 Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
759 fmOpenReadWrite);
760 Result := Fsep_file.Size;
761 Fsep_file.Seek(0, soFromEnd);
762 Fsep_file.Write(target^, size);
763 if UnloadWhenUnused then
764 Fsep_file.Free
765 else
766 FSepOpened := True;
767 end;
768end;
769
770
771
772
773
774
775
776
777
778
779
780(*
781================================================================================
782 Implementation of TOniDataADB
783*)
784
785constructor TOniDataADB.Create(OLDBFilename: String; var Result: Boolean);
786var
787 i, j: Byte;
788 temps: String;
789begin
790 if not FileExists(OLDBFilename) then
791 begin
792 ShowMessage('File doesn''t exist!!!');
793 Result := False;
794 Exit;
795 end;
796 FFileName := OLDBFilename;
797 FDatabase := TABSDatabase.Create(nil);
798 FDatabase.DatabaseName := 'OLDBcon';
799 FDatabase.DatabaseFileName := OLDBFilename;
800 FDatabase.Open;
801 FQuery := TABSQuery.Create(FDatabase);
802 FQuery.DatabaseName := 'OLDBcon';
803 FQuery.SQL.Text := 'SELECT [name],[value] FROM globals ORDER BY [name] ASC';
804 FQuery.Open;
805 FQuery.First;
806 repeat
807 if FQuery.FieldByName('name').AsString = 'dbversion' then
808 begin
809 if FQuery.FieldByName('value').AsString <> DBversion then
810 begin
811 ShowMessage('Database-file ' + #13 + #10 +
812 '"' + OLDBFilename + '"' + #13 + #10 +
813 'has wrong version. (Required: ' + DBversion + '; found: ' +
814 FQuery.FieldByName('value').AsString + ')');
815 FQuery.Close;
816 Result := False;
817 Exit;
818 end;
819 end;
820 if FQuery.FieldByName('name').AsString = 'lvl' then
821 begin
822 FLevelInfo.LevelNumber := StrToInt(FQuery.FieldByName('value').AsString);
823 end;
824 if FQuery.FieldByName('name').AsString = 'ident' then
825 begin
826 temps := FQuery.FieldByName('value').AsString;
827 for i := 0 to High(FLevelInfo.Ident) do
828 begin
829 j := i * 2 + 1;
830 case temps[j] of
831 '0'..'9':
832 FLevelInfo.Ident[i] := Ord(temps[j]) - 48;
833 'A'..'F':
834 FLevelInfo.Ident[i] := Ord(temps[j]) - 55;
835 end;
836 FLevelInfo.Ident[i] := FLevelInfo.Ident[i] * 16;
837 case temps[j + 1] of
838 '0'..'9':
839 FLevelInfo.Ident[i] := FLevelInfo.Ident[i] + Ord(temps[j + 1]) - 48;
840 'A'..'F':
841 FLevelInfo.Ident[i] := FLevelInfo.Ident[i] + Ord(temps[j + 1]) - 55;
842 end;
843 end;
844 end;
845 if FQuery.FieldByName('name').AsString = 'ident' then
846 begin
847 temps := FQuery.FieldByName('value').AsString;
848 Fos_mac := temps = 'MAC';
849 end;
850 FQuery.Next;
851 until FQuery.EOF;
852 FQuery.Close;
853
854 UpdateListCache;
855
856 Result := True;
857 FBackend := ODB_ADB;
858end;
859
860
861
862
863procedure TOniDataADB.Close;
864begin
865 FDatabase.Close;
866 FDatabase.Free;
867 Self.Free;
868end;
869
870
871
872procedure TOniDataADB.UpdateListCache;
873var
874 i: LongWord;
875 temps: String;
876begin
877 FQuery.SQL.Text := 'SELECT id,name,extension,[size],contenttype FROM datfiles ORDER BY id ASC;';
878 FQuery.Open;
879 if FQuery.RecordCount > 0 then
880 begin
881 FQuery.First;
882 SetLength(Fdat_files, FQuery.RecordCount);
883 i := 0;
884 repeat
885 Fdat_files[i].ID := FQuery.FieldByName('id').AsInteger;
886 Fdat_files[i].Name := FQuery.FieldByName('name').AsString;
887 Fdat_files[i].Extension := FQuery.FieldByName('extension').AsString;
888 Fdat_files[i].FileName := FormatNumber(Fdat_files[i].ID, 5, '0') + '-' +
889 Fdat_files[i].Name + '.' + Fdat_files[0].Extension;
890 Fdat_files[i].FileNameHex := IntToHex(Fdat_files[i].ID, 4) + '-' +
891 Fdat_files[i].Name + '.' + Fdat_files[0].Extension;
892 Fdat_files[i].Size := FQuery.FieldByName('size').AsInteger;
893 Fdat_files[i].FileType := HexToLong(FQuery.FieldByName('contenttype').AsString);
894 Fdat_files[i].DatAddr := 0;
895 Fdat_files[i].opened := False;
896 Inc(i);
897 FQuery.Next;
898 until FQuery.EOF;
899 end;
900 FQuery.Close;
901
902 SetLength(Fdat_extensionsmap, 0);
903 FQuery.SQL.Text :=
904 'SELECT extension,count(extension) AS x FROM datfiles GROUP BY extension ORDER BY extension ASC;';
905 FQuery.Open;
906 if FQuery.RecordCount > 0 then
907 begin
908 SetLength(Fdat_extensionsmap, FQuery.RecordCount);
909 i := 0;
910 repeat
911 temps := FQuery.FieldByName('extension').AsString[1];
912 Fdat_extensionsmap[i].Extension[3] := temps[1];
913 Fdat_extensionsmap[i].Extension[2] := temps[2];
914 Fdat_extensionsmap[i].Extension[1] := temps[3];
915 Fdat_extensionsmap[i].Extension[0] := temps[4];
916 Fdat_extensionsmap[i].ExtCount := FQuery.FieldByName('x').AsInteger;
917 Inc(i);
918 FQuery.Next;
919 until FQuery.EOF;
920 end;
921 FQuery.Close;
922end;
923
924
925function TOniDataADB.GetFileInfo(fileid: LongWord): TFileInfo;
926var
927 i: Integer;
928begin
929 if fileid < Self.GetFilesCount then
930 begin
931 for i := 0 to High(Fdat_files) do
932 if Fdat_files[i].ID = fileid then
933 Break;
934 if i < Length(Fdat_files) then
935 Result := Fdat_files[i]
936 else
937 Result.ID := -1;
938 end
939 else
940 begin
941 Result.ID := -1;
942 end;
943end;
944
945
946
947
948function TOniDataADB.GetFilesList(ext: String; pattern: String;
949 NoEmptyFiles: Boolean; sort: TSortType): TStringArray;
950var
951 i: LongWord;
952 list: TStringList;
953 id, name, extension: String;
954 fields: TStrings;
955
956 procedure getfields;
957 begin
958 fields.CommaText := StringReplace(AnsiQuotedStr(list.Strings[i], '"'), ';', '","', [rfReplaceAll]);
959 if sort in [stIDAsc, stIDDesc] then
960 begin
961 id := fields.Strings[0];
962 name := fields.Strings[1];
963 extension := fields.Strings[2];
964 end;
965 if sort in [stNameAsc, stNameDesc] then
966 begin
967 id := fields.Strings[1];
968 name := fields.Strings[0];
969 extension := fields.Strings[2];
970 end;
971 if sort in [stExtAsc, stExtDesc] then
972 begin
973 id := fields.Strings[1];
974 name := fields.Strings[2];
975 extension := fields.Strings[0];
976 end;
977 end;
978
979begin
980 list := TStringList.Create;
981 list.Sorted := True;
982 for i := 0 to High(Fdat_files) do
983 begin
984 if ((Length(ext) = 0) or (Pos(Fdat_files[i].Extension, ext) > 0)) and
985 ((Length(pattern) = 0) or
986 (Pos(UpperCase(pattern), UpperCase(Fdat_files[i].Name)) > 0)) then
987 begin
988 if (NoEmptyFiles = False) or ((Fdat_files[i].FileType and $02) = 0) then
989 begin
990 if AppSettings.FilenumbersAsHex then
991 id := IntToHex(Fdat_files[i].ID, 4)
992 else
993 id := FormatNumber(Fdat_files[i].ID, 5, '0');
994 name := Fdat_files[i].Name;
995 extension := Fdat_files[i].Extension;
996
997 case sort of
998 stIDAsc, stIDDesc: list.Add(id + ';' + name + ';' + extension);
999 stNameAsc, stNameDesc: list.Add(name + ';' + id + ';' + extension);
1000 stExtAsc, stExtDesc: list.Add(extension + ';' + id + ';' + name);
1001 end;
1002 end;
1003 end;
1004 end;
1005 SetLength(Result, list.Count);
1006 fields := TStringList.Create;
1007 if sort in [stIDAsc, stNameAsc, stExtAsc] then
1008 for i := 0 to list.Count - 1 do
1009 begin
1010 getfields;
1011 Result[i] := id + '-' + name + '.' + extension;
1012 end
1013 else
1014 for i := list.Count - 1 downto 0 do
1015 begin
1016 getfields;
1017 Result[list.Count - i - 1] := id + '-' + name + '.' + extension;
1018 end;
1019 list.Free;
1020 fields.Free;
1021end;
1022
1023
1024
1025
1026function TOniDataADB.GetFilesCount: LongWord;
1027begin
1028 Result := Length(Fdat_files);
1029end;
1030
1031
1032
1033
1034function TOniDataADB.GetExtensionsList: TStringArray;
1035var
1036 i: LongWord;
1037begin
1038 SetLength(Result, Length(Fdat_extensionsmap));
1039 for i := 0 to High(Result) do
1040 begin
1041 with Fdat_extensionsmap[i] do
1042 begin
1043 Result[i] := Extension[3] + Extension[2] + Extension[1] + Extension[0] +
1044 ' (' + IntToStr(ExtCount) + ')';
1045 end;
1046 end;
1047end;
1048
1049
1050
1051
1052function TOniDataADB.GetExtendedExtensionsList: TExtensionsMap;
1053var
1054 i, j: LongWord;
1055 temps: String;
1056 Data: Tdata;
1057begin
1058 SetLength(Result, 0);
1059 FQuery.SQL.Text := 'SELECT ext,ident FROM extlist ORDER BY ext ASC;';
1060 FQuery.Open;
1061 if FQuery.RecordCount > 0 then
1062 begin
1063 SetLength(Result, FQuery.RecordCount);
1064 i := 0;
1065 repeat
1066 temps := FQuery.FieldByName('ext').AsString;
1067 for j := 0 to 3 do
1068 Result[i].Extension[j] := temps[4 - j];
1069 Data := DecodeHexString(FQuery.FieldByName('ident').AsString);
1070 for j := 0 to 7 do
1071 Result[i].Ident[j] := Data[j];
1072 Inc(i);
1073 FQuery.Next;
1074 until FQuery.EOF;
1075 end;
1076 FQuery.Close;
1077end;
1078
1079
1080
1081
1082function TOniDataADB.GetNamedFilesMap: TNamedFilesMap;
1083var
1084 i: LongWord;
1085 temp: Integer;
1086 temps: String;
1087 temparray: array of record
1088 id: Integer;
1089 fullname: String[50];
1090 end;
1091begin
1092 SetLength(temparray, 0);
1093 FQuery.SQL.Text :=
1094 'SELECT id,(extension+name) AS xname FROM datfiles WHERE Length(name)>0 ORDER BY extension,name ASC;';
1095 FQuery.Open;
1096 if FQuery.RecordCount > 0 then
1097 begin
1098 repeat
1099 temp := FQuery.FieldByName('id').AsInteger;
1100 temps := FQuery.FieldByName('xname').AsString;
1101
1102 SetLength(temparray, Length(temparray) + 1);
1103 if Length(temparray) > 1 then
1104 begin
1105 for i := High(temparray) - 1 downto 0 do
1106 begin
1107 if StringSmaller(temps, temparray[i].fullname) then
1108 begin
1109 temparray[i + 1] := temparray[i];
1110 if i = 0 then
1111 begin
1112 temparray[i].id := temp;
1113 temparray[i].fullname := temps;
1114 end;
1115 end
1116 else
1117 begin
1118 temparray[i + 1].id := temp;
1119 temparray[i + 1].fullname := temps;
1120 Break;
1121 end;
1122 end;
1123 end
1124 else
1125 begin
1126 temparray[0].id := temp;
1127 temparray[0].fullname := temps;
1128 end;
1129 FQuery.Next;
1130 until FQuery.EOF;
1131 end;
1132 FQuery.Close;
1133 SetLength(Result, Length(temparray));
1134 for i := 0 to High(temparray) do
1135 begin
1136 Result[i].FileNumber := temparray[i].id;
1137 Result[i].blubb := 0;
1138 end;
1139end;
1140
1141
1142
1143
1144function TOniDataADB.LoadDatFile(fileid: LongWord): Tdata;
1145var
1146 mem: TStream;
1147begin
1148 if fileid < Self.GetFilesCount then
1149 begin
1150 FQuery.SQL.Text := 'SELECT data FROM datfiles WHERE id=' + IntToStr(fileid) + ';';
1151 FQuery.Open;
1152 if FQuery.RecordCount > 0 then
1153 begin
1154 mem := FQuery.CreateBlobStream(FQuery.FieldByName('data'), bmRead);
1155 SetLength(Result, mem.Size);
1156 mem.Seek(0, soFromBeginning);
1157 mem.Read(Result[0], mem.Size);
1158 mem.Free;
1159 end;
1160 FQuery.Close;
1161 end;
1162end;
1163
1164
1165
1166
1167procedure TOniDataADB.UpdateDatFile(fileid: LongWord; Data: Tdata);
1168var
1169 MimeCoder: TStringFormat_MIME64;
1170 mem: TMemoryStream;
1171begin
1172 if fileid < Self.GetFilesCount then
1173 begin
1174 mimecoder := TStringFormat_MIME64.Create;
1175 mem := TMemoryStream.Create;
1176 mem.Write(Data[0], Length(Data));
1177 mem.Seek(0, soFromBeginning);
1178 FQuery.SQL.Text := 'UPDATE datfiles SET data=MimeToBin("' +
1179 MimeCoder.StrTo(mem.Memory, mem.Size) + '"), size=' + IntToStr(mem.Size) +
1180 ' WHERE id=' + IntToStr(fileid) + ';';
1181 FQuery.ExecSQL;
1182 mem.Free;
1183 mimecoder.Free;
1184 end;
1185 UpdateListCache;
1186end;
1187
1188
1189
1190
1191procedure TOniDataADB.LoadDatFilePart(fileid, offset, size: LongWord; target: Pointer);
1192var
1193 mem: TStream;
1194begin
1195 if fileid < Self.GetFilesCount then
1196 begin
1197 FQuery.SQL.Text := 'SELECT data FROM datfiles WHERE id=' + IntToStr(fileid) + ';';
1198 FQuery.Open;
1199 if FQuery.RecordCount > 0 then
1200 begin
1201 mem := FQuery.CreateBlobStream(FQuery.FieldByName('data'), bmRead);
1202 mem.Seek(offset, soFromBeginning);
1203 mem.Read(target^, size);
1204 mem.Free;
1205 end;
1206 FQuery.Close;
1207 end;
1208end;
1209
1210
1211
1212
1213procedure TOniDataADB.UpdateDatFilePart(fileid, offset, size: LongWord; target: Pointer);
1214var
1215 MimeCoder: TStringFormat_MIME64;
1216 mem: TMemoryStream;
1217 Data: Tdata;
1218begin
1219 if fileid < Self.GetFilesCount then
1220 begin
1221 Data := Self.LoadDatFile(fileid);
1222 mimecoder := TStringFormat_MIME64.Create;
1223 mem := TMemoryStream.Create;
1224 mem.Write(Data[0], Length(Data));
1225 mem.Seek(offset, soFromBeginning);
1226 mem.Write(target^, size);
1227 mem.Seek(0, soFromBeginning);
1228 FQuery.SQL.Text := 'UPDATE datfiles SET data=MimeToBin("' +
1229 MimeCoder.StrTo(mem.Memory, mem.Size) + '") WHERE id=' + IntToStr(fileid) + ';';
1230 FQuery.ExecSQL;
1231 mem.Free;
1232 mimecoder.Free;
1233 end;
1234end;
1235
1236
1237
1238
1239function TOniDataADB.GetRawList(fileid: LongWord): TRawList;
1240var
1241 i: LongWord;
1242begin
1243 SetLength(Result, 0);
1244 FQuery.SQL.Text := 'SELECT [src_link_offset],[size],[sep] FROM rawmap WHERE [src_id]=' +
1245 IntToStr(fileid) + ' ORDER BY src_link_offset ASC;';
1246 FQuery.Open;
1247 if FQuery.RecordCount > 0 then
1248 begin
1249 FQuery.First;
1250 SetLength(Result, FQuery.RecordCount);
1251 i := 0;
1252 repeat
1253 Result[i].src_id := fileid;
1254 Result[i].src_offset := FQuery.FieldByName('src_link_offset').AsInteger;
1255 Result[i].raw_addr := 0;
1256 Result[i].raw_size := FQuery.FieldByName('size').AsInteger;
1257 Result[i].loc_sep := FQuery.FieldByName('sep').AsBoolean;
1258 Inc(i);
1259 FQuery.Next;
1260 until FQuery.EOF;
1261 end;
1262 FQuery.Close;
1263end;
1264
1265
1266
1267
1268procedure TOniDataADB.LoadRawFile(fileid, dat_offset: LongWord; target: Pointer);
1269var
1270 mem: TStream;
1271begin
1272 if fileid < Self.GetFilesCount then
1273 begin
1274 FQuery.SQL.Text := 'SELECT data FROM rawmap WHERE (src_id=' +
1275 IntToStr(fileid) + ') AND (src_link_offset=' + IntToStr(dat_offset) + ');';
1276 FQuery.Open;
1277 if FQuery.RecordCount > 0 then
1278 begin
1279 mem := FQuery.CreateBlobStream(FQuery.FieldByName('data'), bmRead);
1280 mem.Seek(0, soFromBeginning);
1281 mem.Read(target^, mem.size);
1282 mem.Free;
1283 end;
1284 FQuery.Close;
1285 end;
1286end;
1287
1288
1289
1290
1291procedure TOniDataADB.UpdateRawFile(fileid, dat_offset: LongWord;
1292 size: LongWord; target: Pointer);
1293var
1294 MimeCoder: TStringFormat_MIME64;
1295 mem: TMemoryStream;
1296begin
1297 if fileid < Self.GetFilesCount then
1298 begin
1299 mimecoder := TStringFormat_MIME64.Create;
1300 mem := TMemoryStream.Create;
1301 mem.Write(target^, size);
1302 mem.Seek(0, soFromBeginning);
1303 FQuery.SQL.Text := 'UPDATE rawmap SET data=MimeToBin("' + MimeCoder.StrTo(
1304 mem.Memory, mem.Size) + '") WHERE (src_id=' + IntToStr(fileid) +
1305 ') AND (src_link_offset=' + IntToStr(dat_offset) + ');';
1306 FQuery.ExecSQL;
1307 mem.Free;
1308 mimecoder.Free;
1309 end;
1310end;
1311
1312
1313
1314
1315procedure TOniDataADB.LoadRawFilePart(fileid, dat_offset: LongWord;
1316 offset, size: LongWord; target: Pointer);
1317var
1318 Data: Tdata;
1319 mem: TMemoryStream;
1320begin
1321 if fileid < Self.GetFilesCount then
1322 begin
1323 SetLength(Data, Self.GetRawInfo(fileid, dat_offset).raw_size);
1324 Self.LoadRawFile(fileid, dat_offset, @Data[0]);
1325 mem := TMemoryStream.Create;
1326 mem.Write(Data[offset], size);
1327 mem.Read(target^, size);
1328 mem.Free;
1329 end;
1330end;
1331
1332
1333
1334
1335procedure TOniDataADB.UpdateRawFilePart(fileid, dat_offset: LongWord;
1336 offset, size: LongWord; target: Pointer);
1337var
1338 MimeCoder: TStringFormat_MIME64;
1339 mem: TMemoryStream;
1340 Data: Tdata;
1341begin
1342 if fileid < Self.GetFilesCount then
1343 begin
1344 SetLength(Data, Self.GetRawInfo(fileid, offset).raw_size);
1345 Self.LoadRawFile(fileid, offset, @Data[0]);
1346 mimecoder := TStringFormat_MIME64.Create;
1347 mem := TMemoryStream.Create;
1348 mem.Write(Data[0], Length(Data));
1349 mem.Seek(offset, soFromBeginning);
1350 mem.Write(target^, size);
1351 mem.Seek(0, soFromBeginning);
1352 FQuery.SQL.Text := 'UPDATE rawmap SET data=MimeToBin("' + MimeCoder.StrTo(
1353 mem.Memory, mem.Size) + '") WHERE (src_id=' + IntToStr(fileid) +
1354 ') AND (src_link_offset=' + IntToStr(dat_offset) + ');';
1355 FQuery.ExecSQL;
1356 mem.Free;
1357 mimecoder.Free;
1358 end;
1359end;
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371function CreateDataConnection(filename: String; backend: Integer): Boolean;
1372var
1373 answer: Boolean;
1374begin
1375 if Assigned(OniDataConnection) then
1376 begin
1377 OniDataConnection.Close;
1378 OniDataConnection.Free;
1379 OniDataConnection := nil;
1380 end;
1381 case backend of
1382 ODB_Dat:
1383 OniDataConnection := TOniDataDat.Create(filename, answer);
1384 ODB_ADB:
1385 OniDataConnection := TOniDataADB.Create(filename, answer);
1386 else
1387 ShowMessage('Unknown Backend');
1388 Result := False;
1389 Exit;
1390 end;
1391
1392 if answer then
1393 begin
1394 // ShowMessage('file loaded');
1395 // ShowMessage('Files: '+IntToStr(OniDataConnection.GetFilesCount));
1396 Result := True;
1397 end
1398 else
1399 begin
1400 ShowMessage('File not loaded');
1401 OniDataConnection.Close;
1402 OniDataConnection.Free;
1403 Result := False;
1404 end;
1405end;
1406
1407
1408
1409
1410procedure CloseDataConnection;
1411begin
1412 if Assigned(OniDataConnection) then
1413 begin
1414 OniDataConnection.Close;
1415 OniDataConnection := nil;
1416 end;
1417end;
1418
1419end.
Note: See TracBrowser for help on using the repository browser.