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

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