ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/oup/current/Helper/LevelDB.pas
(Generate patch)

Comparing oup/current/Helper/LevelDB.pas (file contents):
Revision 112 by alloc, Thu Feb 22 00:37:39 2007 UTC vs.
Revision 141 by alloc, Fri Mar 30 01:16:54 2007 UTC

# Line 1 | Line 1
1   unit LevelDB;
2
2   interface
4
3   uses
4    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
5    Dialogs, ComCtrls, StdCtrls, StrUtils;
# Line 14 | Line 12 | type
12      btn_abortok:  TButton;
13      lbl_estimation: TLabel;
14      procedure btn_abortokClick(Sender: TObject);
17  private
18    procedure HandleFile(Ext: String; FileID: Integer);
19    procedure StopConvert;
15    public
16      procedure CreateDatabase(Source, Target: String);
17      procedure CreateLevel(Source, Target: String);
# Line 27 | Line 22 | var
22    Form_LevelDB: TForm_LevelDB;
23  
24   implementation
30
25   {$R *.dfm}
32
26   uses ABSMain, ABSDecUtil, Main,
27 <    ConnectionManager, TypeDefs, DataAccess, OniImgClass;
35 <
36 < type
37 <  THandler = procedure(FileID: Integer);
38 <  TConvertHandler = record
39 <    Ext:     String[4];
40 <    Handler: THandler;
41 <  end;
27 >    ConnectionManager, TypeDefs, DataAccess, OniImgClass, Data, RawList;
28  
29   var
44  ConvertHandlers: array of TConvertHandler;
45 //  loaded_filename: String;
30    Converting:  Boolean = False;
31    Abort:       Boolean = False;
32  
# Line 69 | Line 53 | var
53    Stream_Body, Stream_Names:          TMemoryStream;
54    Stream_Dat, Stream_Raw, Stream_Sep: TFileStream;
55  
72 //  FileCount: Integer;
73 //  temps, temps2: String;
74 //  Data, rawdata: Tdata;
56    BeginTime, FileTime: Double;
57    Step:     Integer;
77 //  rawlist:  TRawDataList;
78 //  extlist:  TExtensionsMap;
79 //  fileinfo: TFileInfo;
80 //  datlinks: TDatLinks;
81  OniImage:   TOniImage;
58    LevelID:    Integer;
59    TimeFormat: TFormatSettings;
60  
# Line 86 | Line 62 | var
62    Connection: TDataAccess;
63    ConRepMsg:  TStatusMessages;
64  
65 +  FileID:     Integer;
66 +
67    Strings:    TStrings;
68    i, j:       Integer;
69 +  temps:      String;
70 +  tempi:      Integer;
71 +  tempb:      Byte;
72 +  FileInfo:   TFileInfo;
73 +  DatLinks:   TDatLinkList;
74 +  RawLinks:   TRawDataList;
75 +
76 +  DatFileStream, RawFileStream: TMemoryStream;
77 +
78 + // ###########################
79 +  datsum, linksum, rawsum: Int64;
80 +  freq: Int64;
81 +  tempticks1, tempticks2: Int64;
82 + // ###########################
83   const
84    Steps: Byte = 3;
85  
# Line 102 | Line 94 | const
94        group_progress.Caption := 'Creating Dat (FINISHED)';
95    end;
96  
97 +  procedure StopConvert;
98 +  begin
99 +    btn_abortok.Caption := '&Close';
100 +    btn_abortok.Default := True;
101 +    converting := False;
102 +    lbl_estimation.Caption := 'ABORTED';
103 +    group_progress.Caption := 'Creating Level (ABORTED)';
104 +
105 +    Stream_Body.Free;
106 +    Stream_Names.Free;
107 +    DatFileStream.Free;
108 +    RawFileStream.Free;
109 +    
110 +    Stream_Dat.Free;
111 +    Stream_Raw.Free;
112 +    if Connection.DataOS in [DOS_WINDEMO, DOS_MAC, DOS_MACBETA] then
113 +      Stream_Sep.Free;
114 +    
115 +    if MessageBox(Self.Handle, PChar('Delete the unfinished level-files?'),
116 +      PChar('Delete files?'), MB_YESNO) = idYes then
117 +    begin
118 +      DeleteFile(target);
119 +      DeleteFile(AnsiReplaceStr(Target, '.dat', '.raw'));
120 +      if Connection.DataOS in [DOS_WINDEMO, DOS_MAC, DOS_MACBETA] then
121 +        DeleteFile(AnsiReplaceStr(Target, '.dat', '.sep'));
122 +    end;
123 +  end;
124 +
125   begin
126  
127    //
# Line 149 | Line 169 | begin
169        begin
170          ShowMessage('Couldn''t delete file. Aborting');
171          Exit;
152      end else if not DeleteFile(AnsiReplaceStr(Target, '.dat', '.raw')) then
153      begin
154        ShowMessage('Couldn''t delete file. Aborting');
155        Exit;
156      end else if not DeleteFile(AnsiReplaceStr(Target, '.dat', '.sep')) then
157      begin
158        ShowMessage('Couldn''t delete file. Aborting');
159        Exit;
172        end;
173 +      if FileExists(AnsiReplaceStr(Target, '.dat', '.raw')) then
174 +        if not DeleteFile(AnsiReplaceStr(Target, '.dat', '.raw')) then
175 +        begin
176 +          ShowMessage('Couldn''t delete file. Aborting');
177 +          Exit;
178 +        end;
179 +      if FileExists(AnsiReplaceStr(Target, '.dat', '.sep')) then
180 +        if Connection.DataOS in [DOS_WINDEMO, DOS_MAC, DOS_MACBETA] then
181 +          if not DeleteFile(AnsiReplaceStr(Target, '.dat', '.sep')) then
182 +          begin
183 +            ShowMessage('Couldn''t delete file. Aborting');
184 +            Exit;
185 +          end;
186      end else begin
187        ShowMessage('Aborting');
188        Exit;
# Line 166 | Line 191 | begin
191  
192    LevelID  := Connection.LevelNumber;
193    LevelID  := (LevelID * 2) * 256 * 256 * 256 + $01;
169  OniImage := TOniImage.Create;
194  
195    Self.Visible := True;
196    Form_Main.Visible := False;
# Line 208 | Line 232 | begin
232      end;
233    end;
234  
235 <  
236 <  extlist := OniDataConnection.GetExtendedExtensionsList;
237 <  for i := 0 to High(DatHeader.Ident) do
238 <    DatHeader.Ident[i] := OniDataConnection.LevelInfo.Ident[i];
239 <  DatHeader.Files := OniDataConnection.GetFilesCount;
235 >  for i := 0 to High(DatHeader.OSIdent) do
236 >    case Connection.DataOS of
237 >      DOS_WIN: DatHeader.OSIdent[i] := HeaderOSIdentWin[i];
238 >      DOS_MAC: DatHeader.OSIdent[i] := HeaderOSIdentMac[i];
239 >      DOS_MACBETA: DatHeader.OSIdent[i] := HeaderOSIdentMacBeta[i];
240 >    end;
241 >  for i := 0 to High(DatHeader.GlobalIdent) do
242 >    DatHeader.GlobalIdent[i] := HeaderGlobalIdent[i];
243 >  DatHeader.Files := Connection.GetFileCount;
244    DatHeader.NamedFiles := Length(NamedFilesHeader);
245 <  DatHeader.Extensions := Length(extlist);
245 >
246 >  Strings := Connection.GetExtensionsList(EF_ExtCount);
247 >
248 >  DatHeader.Extensions := Strings.Count;
249    DatHeader.DataAddr   := 0;
250    DatHeader.DataSize   := 0;
251    DatHeader.NamesAddr  := 0;
# Line 226 | Line 257 | begin
257  
258  
259    DoStep('Writing extensions-header');
260 <  progress.Max := Length(OniDataConnection.GetExtensionsList);
260 >  progress.Max := Strings.Count;
261    Application.ProcessMessages;
262 <
232 <  for i := 0 to High(ExtensionsHeader) do
262 >  for i := 0 to Strings.Count - 1 do
263    begin
264 <    ExtensionsHeader[i].Ident     := extlist[i].Ident;
265 <    ExtensionsHeader[i].Extension := extlist[i].Extension;
266 <    SetLength(temps, 4);
264 >    temps := Strings.Strings[i];
265 >    ExtensionsHeader[i].ExtCount := StrToInt( MidStr(
266 >            temps,
267 >            Pos('(', temps) + 1,
268 >            Pos(')', temps) - Pos('(', temps) - 1 ) );
269 >    temps := MidStr(temps, 1, 4);
270      for j := 0 to 3 do
271 <      temps[j + 1] := ExtensionsHeader[i].Extension[3 - j];
272 <    ExtensionsHeader[i].ExtCount :=
273 <      Length(OniDataConnection.GetFilesList(temps, '', False, stIDAsc));
271 >      ExtensionsHeader[i].Extension[j] := temps[4-j];
272 >    for j := 0 to High(FileTypes) do
273 >      if FileTypes[j].Extension = temps then
274 >        Break;
275 >    if j < Length(FileTypes) then
276 >    begin
277 >      case Connection.DataOS of
278 >        DOS_WIN:     ExtensionsHeader[i].Ident := FileTypes[j].IdentWin;
279 >        DOS_WINDEMO: ExtensionsHeader[i].Ident := FileTypes[j].IdentMac;
280 >        DOS_MAC:     ExtensionsHeader[i].Ident := FileTypes[j].IdentMac;
281 >        DOS_MACBETA: ExtensionsHeader[i].Ident := FileTypes[j].IdentMac;
282 >      end;
283 >    end else begin
284 >      ShowMessage('Unknown Extension: ' + Strings.Strings[i]);
285 >      Exit;
286 >    end;
287      progress.Position    := i + 1;
288      lbl_progress.Caption := 'Extensions done: ' + IntToStr(i + 1) + '/' +
289 <      IntToStr(Length(extlist));
289 >      IntToStr(Strings.Count);
290      Application.ProcessMessages;
291    end;
292  
247
293    DoStep('Storing files-data');
294    progress.Position := 0;
295    progress.Max      := DatHeader.Files;
# Line 252 | Line 297 | begin
297    lbl_estimation.Caption := 'Estimated finishing time: unknown';
298    Application.ProcessMessages;
299  
300 <  begintime := Time;
301 <  for i := 0 to DatHeader.Files - 1 do
300 >  QueryPerformanceFrequency(freq);
301 >  datsum := 0;
302 >  linksum := 0;
303 >  rawsum := 0;
304 >
305 >  FileTime := Time;
306 >  for FileID := 0 to DatHeader.Files - 1 do
307    begin
308 <    fileinfo := OniDataConnection.GetFileInfo(i);
308 >    FileInfo := Connection.GetFileInfo(FileID);
309      for j := 0 to 3 do
310 <      FilesHeader[i].Extension[j] := fileinfo.Extension[4 - j];
311 <    if fileinfo.Size > 0 then
310 >      FilesHeader[FileID].Extension[j] := FileInfo.Extension[4 - j];
311 >    if FileInfo.Size > 0 then
312      begin
313 <      //        DatLinks:=;
314 <      FilesHeader[i].DataAddr := Stream_Body.Size + 8;
315 <      Data    := OniDataConnection.LoadDatFile(i);
316 <      Data[4] := (levelid) and $FF;
317 <      Data[5] := (levelid shr 8) and $FF;
318 <      Data[6] := (levelid shr 16) and $FF;
319 <      Data[7] := (levelid shr 24) and $FF;
313 >      QueryPerformanceCounter(tempticks1);
314 >
315 >      FilesHeader[FileID].DataAddr := Stream_Body.Size + 8;
316 >      DatFileStream := TMemoryStream.Create;
317 >      Connection.LoadDatFile(FileID, TStream(DatFileStream));
318 >      DatFileStream.Seek(0, soFromBeginning);
319 >      tempi := FileID * 256 + 1;
320 >      DatFileStream.Write(tempi, 4);
321 >      DatFileStream.Write(LevelID, 4);
322 >
323 >      QueryPerformanceCounter(tempticks2);
324 >      datsum := datsum + (tempticks2 - tempticks1);
325 >
326 >      DatLinks := Connection.GetDatLinks(FileID);
327 >      if Length(DatLinks) > 0 then
328 >      begin
329 >        for i := 0 to High(DatLinks) do
330 >        begin
331 >          DatFileStream.Seek(DatLinks[i].SrcOffset, soFromBeginning);
332 >          if DatLinks[i].DestID < 0 then
333 >            tempi := 0
334 >          else
335 >            tempi := DatLinks[i].DestID * 256 + 1;
336 >          DatFileStream.Write(tempi, 4);
337 >        end;
338 >      end;
339 >
340 >      QueryPerformanceCounter(tempticks1);
341 >      linksum := linksum + (tempticks1 - tempticks2);
342  
343 <      if (Pos(UpperCase(fileinfo.Extension), UpperCase(raws)) mod 4) = 1 then
343 >      RawLinks := Connection.GetRawList(FileID);
344 >      if Length(RawLinks) > 0 then
345        begin
346 <        rawlist := OniDataConnection.GetRawList(i);
274 <        if Length(rawlist) > 0 then
346 >        for i := 0 to High(RawLinks) do
347          begin
348 <          for j := 0 to High(rawlist) do
348 >          if RawLinks[i].RawSize > 0 then
349            begin
350 <            if rawlist[j].raw_size > 0 then
350 >            RawFileStream := TMemoryStream.Create;
351 >            Connection.LoadRawFile(FileID, RawLinks[i].SrcOffset, TStream(RawFileStream));
352 >            RawFileStream.Seek(0, soFromBeginning);
353 >            if RawLinks[i].LocSep then
354              begin
355 <              if (UpperCase(fileinfo.Extension) = 'TXMP') and
356 <                ((Data[$88] and $01) > 0) then
357 <              begin
358 <                OniImage.LoadFromTXMP(Connection, i);
359 <                OniImage.GetMipMappedImage(rawdata);
360 <                rawlist[j].raw_size := OniImage.GetImageDataSize(True);
361 <                Data[$90] := $08;
362 <                Data[$89] := 32;
363 < {                  if data[$90]<>OniImage.StoreType then begin
364 <                    data[$90]:=OniImage.StoreType;
290 <                    data[$89]:=(data[$89] and $CF) or $20;
291 <                  end;
292 < }                end
293 <              else
294 <              begin
295 <                SetLength(rawdata, rawlist[j].raw_size);
296 <                OniDataConnection.LoadRawFile(i, rawlist[j].src_offset, @rawdata[0]);
297 <              end;
298 <              //                data[$88]:=data[$88] and $FE;
299 <
300 <              if rawlist[j].loc_sep then
301 <              begin
302 <                rawlist[j].raw_addr := Stream_Sep.Size;
303 <                Stream_Sep.Write(rawdata[0], Length(rawdata));
304 <              end
305 <              else
306 <              begin
307 <                rawlist[j].raw_addr := Stream_Raw.Size;
308 <                Stream_Raw.Write(rawdata[0], Length(rawdata));
309 <              end;
310 <            end
311 <            else
312 <              rawlist[j].raw_addr := 0;
313 <            Data[rawlist[j].src_offset + 0] := (rawlist[j].raw_addr) and $FF;
314 <            Data[rawlist[j].src_offset + 1] := (rawlist[j].raw_addr shr 8) and $FF;
315 <            Data[rawlist[j].src_offset + 2] := (rawlist[j].raw_addr shr 16) and $FF;
316 <            Data[rawlist[j].src_offset + 3] := (rawlist[j].raw_addr shr 24) and $FF;
317 <          end;
355 >              RawLinks[i].RawAddr := Stream_Sep.Size;
356 >              Stream_sep.CopyFrom(RawFileStream, RawFileStream.Size);
357 >            end else begin
358 >              RawLinks[i].RawAddr := Stream_Raw.Size;
359 >              Stream_Raw.CopyFrom(RawFileStream, RawFileStream.Size);
360 >            end;
361 >          end else
362 >            RawLinks[i].RawAddr := 0;
363 >          DatFileStream.Seek(RawLinks[i].SrcOffset, soFromBeginning);
364 >          DatFileStream.Write(RawLinks[i].RawAddr, 4);
365          end;
366        end;
367 +      DatFileStream.Seek(0, soFromBeginning);
368 +      Stream_Body.CopyFrom(DatFileStream, DatFileStream.Size);
369  
370 <      Stream_Body.Write(Data[0], Length(Data));
371 <      //
370 >      QueryPerformanceCounter(tempticks2);
371 >      rawsum := rawsum + (tempticks2 - tempticks1);
372      end
373      else
374 <      FilesHeader[i].DataAddr := 0;
374 >      FilesHeader[FileID].DataAddr := 0;
375      if Length(fileinfo.Name) > 0 then
376      begin
377 <      FilesHeader[i].NameAddr := Stream_Names.Size;
377 >      FilesHeader[FileID].NameAddr := Stream_Names.Size;
378        temps := fileinfo.Extension + fileinfo.Name + Chr(0);
379        Stream_Names.Write(temps[1], Length(temps));
380      end
381      else
382 <      FilesHeader[i].NameAddr := 0;
383 <    FilesHeader[i].FileSize := fileinfo.Size;
384 <    FilesHeader[i].FileType := fileinfo.FileType;
382 >      FilesHeader[FileID].NameAddr := 0;
383 >    FilesHeader[FileID].FileSize := fileinfo.Size;
384 >    FilesHeader[FileID].FileType := fileinfo.FileType;
385  
386 <    if ((i mod 10) = 0) and (i >= 100) then
386 >    if ((FileID mod 10) = 0) and (FileID >= 100) then
387        lbl_estimation.Caption := 'Estimated time left: ' + TimeToStr(
388 <        (Time - begintime) / i * (progress.Max - i + 1) * 1.1, timeformat );
389 <    progress.Position := i + 1;
390 <    lbl_progress.Caption := 'Files done: ' + IntToStr(i + 1) + '/' + IntToStr(progress.Max);
388 >        (Time - FileTime) / FileID * (progress.Max - FileID + 1) * 1.1, TimeFormat );
389 >    progress.Position := FileID + 1;
390 >    lbl_progress.Caption := 'Files done: ' + IntToStr(FileID + 1) + '/' + IntToStr(progress.Max);
391      Application.ProcessMessages;
392    end;
393  
394 +  ShowMessage('AvgDats: ' + FloatToStr((datsum / progress.Max) / freq) + #13#10 +
395 +      'AvgLinks: ' + FloatToStr((linksum / progress.Max) / freq) + #13#10 +
396 +      'AvgRaws: ' + FloatToStr((rawsum / progress.Max) / freq)
397 +   );
398 +
399    Stream_Dat.Write(DatHeader, SizeOf(DatHeader));
400    for i := 0 to High(FilesHeader) do
401      Stream_Dat.Write(FilesHeader[i], SizeOf(FilesHeader[i]));
# Line 353 | Line 407 | begin
407    DatHeader.DataSize  := Stream_Body.Size;
408    DatHeader.NamesSize := Stream_Names.Size;
409    DatHeader.DataAddr  := Stream_Dat.Size;
410 +
411    Stream_Body.Seek(0, soFromBeginning);
412    Stream_Dat.CopyFrom(Stream_Body, Stream_Body.Size);
413    DatHeader.NamesAddr := Stream_Dat.Size;
# Line 366 | Line 421 | begin
421    Stream_Body.Free;
422    Stream_Names.Free;
423    Stream_Raw.Free;
424 <  if OniDataConnection.OSisMac then
424 >
425 >  if Connection.DataOS in [DOS_WINDEMO, DOS_MAC, DOS_MACBETA] then
426      Stream_Sep.Free;
427  
428    progress.Position      := progress.Max;
429    lbl_progress.Caption   := 'Files done: ' + IntToStr(progress.Max) + '/' +
430      IntToStr(progress.Max);
431 <  lbl_estimation.Caption := 'FINISHED (duration: ' + TimeToStr(Time - absolutebegintime, timeformat) + ')';
431 >  lbl_estimation.Caption := 'FINISHED (duration: ' + TimeToStr(Time - Begintime, TimeFormat) + ')';
432  
433    DoStep('FIN');
434    btn_abortok.Caption := '&OK';
435    btn_abortok.Default := True;
436  
381  OniImage.Free;
382
437    converting := False;
438  
439 <  CloseDataConnection(DataConnections[conIndex]);
386 < end;
387 <
388 <
389 <
390 <
391 < procedure TForm_LevelDB.HandleFile;
392 < var
393 <  i: Byte;
394 < begin
395 <  for i := 1 to Length(ConvertHandlers) do
396 <    if UpperCase(ConvertHandlers[i].Ext) = UpperCase(ext) then
397 <      if ConvertHandlers[i].needed then
398 <      begin
399 <        ConvertHandlers[i].Handler(fileid, dir_dat2db);
400 <        Break;
401 <      end
402 <      else
403 <        Break;
439 > //  CloseDataConnection(DataConnections[conIndex]);
440   end;
441  
442  
# Line 408 | Line 444 | end;
444  
445   procedure TForm_LevelDB.CreateDatabase(Source, target: String);
446   var
447 <  DataBase:    TABSDatabase;
448 <  Query:       TABSQuery;
449 <  MimeCoder:   TStringFormat_MIME64;
414 <
415 <  i, j:     LongWord;
416 <  temps, temps2: String;
417 <  Data:     Tdata;
418 <  absolutebegintime, begintime: Double;
419 <  step:     Byte;
420 <  rawlist:  TRawList;
421 <  extlist:  TExtensionsMap;
422 <  fileinfo: TFileInfo;
423 <  timeformat: TFormatSettings;
447 >  DataBase:  TABSDatabase;
448 >  Query:     TABSQuery;
449 >  MimeCoder: TStringFormat_MIME64;
450  
451 <  conIndex: Integer;
452 < const
453 <  steps: Byte = 4;
451 >  BeginTime, FileTime: Double;
452 >  Step:       Integer;
453 >  LevelID:    Integer;
454 >  TimeFormat: TFormatSettings;
455  
456 +  ConID:      Integer;
457 +  Connection: TDataAccess;
458 +  ConRepMsg:  TStatusMessages;
459  
460 +  FileID:     Integer;
461  
462 +  Strings:    TStrings;
463 +  i:          Integer;
464 +  temps:      String;
465 +  tempi:      Integer;
466 +  tempb:      Byte;
467 +  tempdata:   TByteData;
468 +  FileInfo:   TFileInfo;
469 +  DatLinks:   TDatLinkList;
470 +  RawLinks:   TRawDataList;
471 + const
472 +  steps: Byte = 2;
473  
474    procedure DoStep(stepname: String);
475    begin
# Line 439 | Line 481 | const
481        group_progress.Caption := 'Creating DB (FINISHED)';
482    end;
483  
484 +  procedure StopConvert;
485 +  begin
486 +    btn_abortok.Caption := '&Close';
487 +    btn_abortok.Default := True;
488 +    converting := False;
489 +    lbl_estimation.Caption := 'ABORTED';
490 +    group_progress.Caption := 'Creating DB (ABORTED)';
491 +    DataBase.Close;
492 +    if MessageBox(Self.Handle, PChar('Delete the unfinished DB-file?'),
493 +      PChar('Delete file?'), MB_YESNO) = idYes then
494 +    begin
495 +      DeleteFile(target);
496 +    end;
497 + end;
498 +
499 +
500 +
501   begin
502 <  if CreateDataConnection(Source, ODB_Dat) = nil then
502 >
503 >  //
504 >  // FILE EXISTS CHECK FÜR DAT/RAW/SEP!!!
505 >  //
506 >
507 >  TimeFormat.ShortTimeFormat := 'hh:nn:ss';
508 >  TimeFormat.LongTimeFormat  := 'hh:nn:ss';
509 >  TimeFormat.TimeSeparator   := ':';
510 >
511 >  ConID := ConManager.OpenConnection(Source, ConRepMsg);
512 >  if not (ConRepMsg in [SM_OK, SM_AlreadyOpened]) then
513    begin
514 <    ShowMessage('Could not connect to .dat-file');
514 >    ShowMessage('Source-file couldn''t be opened! Aborting' + CrLf + GetOpenMsg(ConRepMsg));
515      Exit;
516 <  end
517 <  else
516 >  end else
517 >    Connection := ConManager.Connection[ConID];
518 >
519 >  ConID := ConManager.FileOpened(Target);
520 >  if ConID >= 0 then
521    begin
522 <    TOniDataDat(OniDataConnection).UnloadWhenUnused := False;
522 >    if MessageBox(Self.Handle, PChar('Destination-file is opened, close it in ' +
523 >          'order to proceed conversion?'), PChar('Destination-file opened'),
524 >          MB_YESNO + MB_ICONQUESTION) = ID_YES then
525 >    begin
526 >      if Form_Main.CheckConnectionCloseable(ConID) then
527 >        if not ConManager.CloseConnection(ConID, ConRepMsg) then
528 >        begin
529 >          ShowMessage('Couldn''t close destination-file. Aborting');
530 >          Exit;
531 >        end;
532 >    end else begin
533 >      ShowMessage('Aborting');
534 >      Exit;
535 >    end;
536    end;
537  
538 <  timeformat.LongTimeFormat := 'hh:nn:ss';
539 <  timeformat.ShortTimeFormat := 'hh:nn:ss';
540 <  timeformat.TimeSeparator := ':';
538 >  if FileExists(Target) then
539 >  begin
540 >    if MessageBox(Self.Handle, PChar('Destination-file exists. ' +
541 >          'Overwrite it?'), PChar('Destination-file exists'),
542 >          MB_YESNO + MB_ICONWARNING) = ID_YES then
543 >    begin
544 >      if not DeleteFile(Target) then
545 >      begin
546 >        ShowMessage('Couldn''t delete file. Aborting');
547 >        Exit;
548 >      end;
549 >    end else begin
550 >      ShowMessage('Aborting');
551 >      Exit;
552 >    end;
553 >  end;
554  
555    Self.Visible := True;
556    Form_Main.Visible := False;
# Line 461 | Line 559 | begin
559    abort := False;
560    btn_abortok.Caption := '&Abort...';
561    btn_abortok.Default := False;
464  loaded_filename := target;
562  
563 <  absolutebegintime := Time;
563 >  BeginTime := Time;
564  
565    DataBase := TABSDatabase.Create(Self);
566 +  DataBase.MaxConnections := 1;
567 +  DataBase.PageSize := 8112;
568 +  DataBase.PageCountInExtent := 8;
569 +
570    DataBase.DatabaseName := 'OLDB';
571    DataBase.DatabaseFileName := target;
572    DataBase.CreateDatabase;
# Line 479 | Line 580 | begin
580    Query := TABSQuery.Create(Self);
581    Query.DatabaseName := 'OLDB';
582    Query.SQL.Text :=
583 <    'CREATE TABLE globals  ( id AUTOINC PRIMARY KEY, name STRING(128), value STRING(128) );';
583 >    'CREATE TABLE globals  ( id AUTOINC PRIMARY KEY, name STRING(128), ' +
584 >    'value STRING(128) );';
585    Query.ExecSQL;
586    Query.SQL.Text :=
587 <    'CREATE TABLE linkmap  ( id AUTOINC PRIMARY KEY, src_id INTEGER, src_link_offset INTEGER, target_id INTEGER );';
587 >    'CREATE TABLE linkmap  ( id AUTOINC PRIMARY KEY, src_id INTEGER, ' +
588 >    'src_link_offset INTEGER, target_id INTEGER);';
589 >  Query.ExecSQL;
590 >  Query.SQL.Text := 'CREATE INDEX idsrcid ON linkmap (src_id);';
591 >  Query.ExecSQL;
592 >  Query.SQL.Text := 'CREATE INDEX idtargetid ON linkmap (target_id);';
593    Query.ExecSQL;
594    Query.SQL.Text :=
595 <    'CREATE TABLE rawmap  ( id AUTOINC PRIMARY KEY, src_id INTEGER, src_link_offset INTEGER, sep BOOLEAN, size INTEGER, data BLOB BlobCompressionMode 9 BlobBlockSize 1024 BlobCompressionAlgorithm ZLib );';
595 >    'CREATE TABLE rawmap  ( id AUTOINC PRIMARY KEY, src_id INTEGER, ' +
596 >    'src_link_offset INTEGER, sep BOOLEAN, size INTEGER, ' +
597 >    'data BLOB BlobCompressionMode 9 BlobBlockSize 1024 BlobCompressionAlgorithm ZLib);';
598    //    Query.SQL.Text:='CREATE TABLE rawmap  ( id AUTOINC PRIMARY KEY, src_id INTEGER, src_link_offset INTEGER, size INTEGER, data BLOB BlobCompressionAlgorithm None );';
599    Query.ExecSQL;
600 <  Query.SQL.Text :=
492 <    'CREATE TABLE datfiles  ( id INTEGER PRIMARY KEY, extension CHAR(4), name STRING(128), contenttype INTEGER, size INTEGER, data BLOB BlobCompressionMode 9 BlobBlockSize 1024 BlobCompressionAlgorithm ZLib );';
493 <  //    Query.SQL.Text:='CREATE TABLE datfiles  ( id INTEGER PRIMARY KEY, extension CHAR(4), name STRING(128), contenttype INTEGER, size INTEGER, data BLOB BlobCompressionAlgorithm None );';
600 >  Query.SQL.Text := 'CREATE INDEX idsrcid ON rawmap (src_id);';
601    Query.ExecSQL;
602    Query.SQL.Text :=
603 <    'CREATE TABLE extlist  ( id AUTOINC PRIMARY KEY, ext CHAR(4), ident CHAR(16) );';
603 >    'CREATE TABLE datfiles  ( id INTEGER PRIMARY KEY, extension CHAR(4), ' +
604 >    'name STRING(128), contenttype INTEGER, size INTEGER, ' +
605 >    'data BLOB BlobCompressionMode 9 BlobBlockSize 1024 BlobCompressionAlgorithm ZLib );';
606 >  //    Query.SQL.Text:='CREATE TABLE datfiles  ( id INTEGER PRIMARY KEY, extension CHAR(4), name STRING(128), contenttype INTEGER, size INTEGER, data BLOB BlobCompressionAlgorithm None );';
607    Query.ExecSQL;
608 + //  Query.SQL.Text :=
609 + //    'CREATE TABLE extlist  ( id AUTOINC PRIMARY KEY, ext CHAR(4), ident CHAR(16) );';
610 + //  Query.ExecSQL;
611  
612    Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("dbversion","' +
613      dbversion + '");';
614    Query.ExecSQL;
615 <  SetLength(Data, Length(OniDataConnection.LevelInfo.Ident));
503 <  for i := 0 to High(OniDataConnection.LevelInfo.Ident) do
504 <    Data[i] := OniDataConnection.LevelInfo.Ident[i];
505 <  temps := CreateHexString(Data, True);
506 <  Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("ident","' + temps + '");';
507 <  Query.ExecSQL;
615 >
616    Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("lvl","' +
617 <    IntToStr(OniDataConnection.LevelInfo.LevelNumber) + '");';
617 >    IntToStr(Connection.LevelNumber) + '");';
618    Query.ExecSQL;
619 <  if OniDataConnection.OSisMAC then
620 <    Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("os","MAC");'
621 <  else
622 <    Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("os","PC");';
623 <  Query.ExecSQL;
516 <
517 <  DoStep('Writing extensionslist');
518 <  progress.Max := Length(OniDataConnection.GetExtensionsList);
519 <  Application.ProcessMessages;
520 <
521 <  extlist := OniDataConnection.GetExtendedExtensionsList;
522 <  for i := 0 to High(extlist) do
523 <  begin
524 <    SetLength(Data, Length(extlist[i].Ident));
525 <    for j := 0 to High(extlist[i].Ident) do
526 <      Data[j] := extlist[i].Ident[j];
527 <    temps := CreateHexString(Data, True);
528 <    temps2 := extlist[i].Extension[3] + extlist[i].Extension[2] +
529 <      extlist[i].Extension[1] + extlist[i].Extension[0];
530 <    Query.SQL.Text := 'INSERT INTO extlist (ext,ident) VALUES ("' +
531 <      temps2 + '","' + temps + '");';
532 <    Query.ExecSQL;
533 <    progress.Position    := i;
534 <    lbl_progress.Caption := 'Extensions done: ' + IntToStr(i) + '/' +
535 <      IntToStr(Length(extlist));
536 <    Application.ProcessMessages;
537 <    if abort then
538 <    begin
539 <      stop_convert;
540 <      Exit;
541 <    end;
619 >  case Connection.DataOS of
620 >    DOS_WIN: temps := 'WIN';
621 >    DOS_WINDEMO: temps := 'WINDEMO';
622 >    DOS_MAC: temps := 'MAC';
623 >    DOS_MACBETA: temps := 'MACBETA';
624    end;
625 <  lbl_progress.Caption := '';
625 >  Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("os","' + temps + '");';
626 >  Query.ExecSQL;
627  
628    progress.Position      := 0;
629    lbl_progress.Caption   := 'Files done: ' + IntToStr(0) + '/' + IntToStr(
630 <    OniDataConnection.GetFilesCount);
630 >    Connection.GetFileCount);
631    lbl_estimation.Caption := 'Estimated finishing time: unknown';
632  
633 <  DoStep('Loading .dat into memory');
551 <  Application.ProcessMessages;
552 <
553 <  progress.Max := OniDataConnection.GetFilesCount;
633 >  progress.Max := Connection.GetFileCount;
634    begintime    := Time;
635    DoStep('Writing .dat-fileslist');
636    Application.ProcessMessages;
637  
638    Database.StartTransaction;
639 <  for i := 0 to OniDataConnection.GetFilesCount - 1 do
639 >  for FileID := 0 to Connection.GetFileCount - 1 do
640    begin
641 <    fileinfo := OniDataConnection.GetFileInfo(i);
641 >    fileinfo := Connection.GetFileInfo(FileID);
642      if (fileinfo.FileType and $02) = 0 then
643      begin
644        mimecoder := TStringFormat_MIME64.Create;
645 <      Data      := OniDataConnection.LoadDatFile(i);
645 >      Connection.LoadDatFile(FileID, tempdata);
646        Query.SQL.Text :=
647          'INSERT INTO datfiles (id,extension,name,contenttype,size,data) VALUES (' +
648 <        IntToStr(i) + ',"' + fileinfo.Extension + '","' + fileinfo.Name + '","' + IntToHex(
648 >        IntToStr(FileID) + ',"' + fileinfo.Extension + '","' + fileinfo.Name + '","' + IntToHex(
649          fileinfo.FileType, 8) + '",' + IntToStr(fileinfo.Size) + ',MimeToBin("' +
650 <        MimeCoder.StrTo(@Data[0], Length(Data)) + '") );';
650 >        MimeCoder.StrTo(@tempdata[0], Length(tempdata)) + '") );';
651        Query.ExecSQL;
652        mimecoder.Free;
653  
654 <      rawlist := OniDataConnection.GetRawList(i);
655 <      if Length(rawlist) > 0 then
654 >      RawLinks := Connection.GetRawList(FileID);
655 >      if Length(RawLinks) > 0 then
656        begin
657 <        for j := 0 to High(rawlist) do
657 >        for i := 0 to High(RawLinks) do
658          begin
659 <          if rawlist[j].raw_size > 0 then
659 >          if RawLinks[i].RawSize > 0 then
660            begin
661 <            SetLength(Data, rawlist[j].raw_size);
662 <            OniDataConnection.LoadRawFile(i, rawlist[j].src_offset, Data);
661 >            SetLength(tempdata, RawLinks[i].RawSize);
662 >            Connection.LoadRawFile(FileID, RawLinks[i].SrcOffset, tempdata);
663              mimecoder      := TStringFormat_MIME64.Create;
664              Query.SQL.Text :=
665                'INSERT INTO rawmap (src_id,src_link_offset,sep,size,data) VALUES (' +
666 <              IntToStr(i) + ',' + IntToStr(rawlist[j].src_offset) + ',' + BoolToStr(
667 <              rawlist[j].loc_sep) + ',' + IntToStr(rawlist[j].raw_size) + ',MimeToBin("' +
668 <              MimeCoder.StrTo(@Data[0], rawlist[j].raw_size) + '") );';
666 >              IntToStr(FileID) + ', ' + IntToStr(RawLinks[i].SrcOffset) + ',' +
667 >              BoolToStr(RawLinks[i].LocSep) + ', ' +
668 >              IntToStr(RawLinks[i].RawSize) + ', ' +
669 >              'MimeToBin("' + MimeCoder.StrTo(@tempdata[0], RawLinks[i].RawSize) + '") );';
670              Query.ExecSQL;
671              mimecoder.Free;
672            end
# Line 593 | Line 674 | begin
674            begin
675              Query.SQL.Text :=
676                'INSERT INTO rawmap (src_id,src_link_offset,sep,size) VALUES (' +
677 <              IntToStr(i) + ',' + IntToStr(rawlist[j].src_offset) + ',' + BoolToStr(rawlist[j].loc_sep) + ',0);';
677 >              IntToStr(FileID) + ', ' + IntToStr(RawLinks[i].SrcOffset) + ', ' +
678 >              BoolToStr(RawLinks[i].LocSep) + ', 0);';
679              Query.ExecSQL;
680            end;
681          end;
682        end;
683  
684 <      HandleFile(fileinfo.Extension, i, True);
684 >      DatLinks := Connection.GetDatLinks(FileID);
685 >      if Length(DatLinks) > 0 then
686 >      begin
687 >        for i := 0 to High(DatLinks) do
688 >        begin
689 >          Query.SQL.Text :=
690 >            'INSERT INTO linkmap (src_id, src_link_offset, target_id) VALUES (' +
691 >            IntToStr(FileID) + ', ' + IntToStr(DatLinks[i].SrcOffset) + ', ' +
692 >            IntToStr(DatLinks[i].DestID) + ');';
693 >          Query.ExecSQL;
694 >        end;
695 >      end;
696      end
697      else
698      begin
699        Query.SQL.Text :=
700          'INSERT INTO datfiles (id,extension,name,contenttype,size) VALUES (' +
701 <        IntToStr(i) + ',"' + fileinfo.Extension + '","' + fileinfo.Name + '","' + IntToHex(
702 <        fileinfo.FileType, 8) + '",0);';
701 >        IntToStr(FileID) + ', "' + fileinfo.Extension + '", ' +
702 >        '"' + fileinfo.Name + '", "' + IntToHex(fileinfo.FileType, 8) + '", 0);';
703        Query.ExecSQL;
704      end;
705 <    if ((i mod 100) = 0) and (i > 0) then
705 >    if ((FileID mod 100) = 0) and (FileID > 0) then
706      begin
707        Database.Commit(False);
708        Database.StartTransaction;
709      end;
710 <    if ((i mod 10) = 0) and (i >= 100) then
710 >    if ((FileID mod 10) = 0) and (FileID >= 100) then
711        lbl_estimation.Caption := 'Estimated time left: ' + TimeToStr(
712 <        (Time - begintime) / i * (progress.Max - i + 1) * 1.1, timeformat );
713 <    progress.Position := i;
714 <    lbl_progress.Caption := 'Files done: ' + IntToStr(i) + '/' + IntToStr(progress.Max);
712 >        (Time - BeginTime) / FileID * (progress.Max - FileID + 1) * 1.1, timeformat );
713 >    progress.Position := FileID;
714 >    lbl_progress.Caption := 'Files done: ' + IntToStr(FileID) + '/' + IntToStr(progress.Max);
715      Application.ProcessMessages;
716      if abort then
717      begin
718 <      stop_convert;
718 >      StopConvert;
719        Exit;
720      end;
721    end;
# Line 631 | Line 724 | begin
724    lbl_progress.Caption   := 'Files done: ' + IntToStr(progress.Max) + '/' +
725      IntToStr(progress.Max);
726  
727 <  lbl_estimation.Caption := 'FINISHED (duration: ' + TimeToStr(Time - absolutebegintime, timeformat) + ')';
727 >  lbl_estimation.Caption := 'FINISHED (duration: ' + TimeToStr(Time - BeginTime, timeformat) + ')';
728  
729    DoStep('FIN');
730    btn_abortok.Caption := '&OK';
# Line 639 | Line 732 | begin
732  
733    converting := False;
734  
735 <  database.Close;
736 <  database.Free;
644 <
645 <  CloseDataConnection(DataConnections[conIndex]);
646 < end;
647 <
648 <
649 <
650 <
651 < procedure TForm_LevelDB.stop_convert;
652 < begin
653 <  btn_abortok.Caption := '&Close';
654 <  btn_abortok.Default := True;
655 <  converting := False;
656 <  lbl_estimation.Caption := 'ABORTED';
657 <  group_progress.Caption := 'Creating DB (ABORTED)';
735 >  Query.Close;
736 >  Query.Free;
737    DataBase.Close;
738 <  if MessageBox(Self.Handle, PChar('Delete the unfinished DB-file?'),
660 <    PChar('Delete file?'), MB_YESNO) = idYes then
661 <  begin
662 <    DeleteFile(loaded_filename);
663 <  end;
738 >  DataBase.Free;
739   end;
740  
741  
# Line 683 | Line 758 | begin
758   end;
759  
760  
686
687
688 procedure InsertDatLinkToDB(fileid: LongWord; offset: LongWord);
689 var
690  link: LongWord;
691 begin
692  OniDataConnection.LoadDatFilePart(fileid, offset, 4, @link);
693  if link = 0 then
694    link := $FFFFFFFF
695  else
696    link := link div 256;
697  Query.SQL.Text := 'INSERT INTO linkmap (src_id,src_link_offset,target_id) VALUES (' +
698    IntToStr(fileid) + ',' + IntToStr(offset) + ',' + IntToStr(link) + ');';
699  Query.ExecSQL;
700 end;
701
702
703
704
705 procedure AISA(fileid: LongWord; dir_dat2db: Boolean);
706 var
707  packages: Word;
708  i: LongWord;
709 begin
710  if dir_dat2db then
711  begin
712    OniDataConnection.LoadDatFilePart(fileid, $1E, 2, @packages);
713    if packages > 0 then
714    begin
715      for i := 0 to packages - 1 do
716        InsertDatLinkToDB(fileid, $20 + i * $160 + $28);
717      for i := 0 to packages - 1 do
718        InsertDatLinkToDB(fileid, $20 + i * $160 + $150);
719    end;
720  end
721  else
722  begin
723  end;
724 end;
725
726
727
728
729 procedure AKEV(fileid: LongWord; dir_dat2db: Boolean);
730 var
731  i: LongWord;
732 begin
733  if dir_dat2db then
734  begin
735    for i := 0 to 16 do
736      InsertDatLinkToDB(fileid, $8 + i * 4);
737  end
738  else
739  begin
740  end;
741 end;
742
743
744
745
746 procedure AKOT(fileid: LongWord; dir_dat2db: Boolean);
747 var
748  i: LongWord;
749 begin
750  if dir_dat2db then
751  begin
752    for i := 0 to 4 do
753      InsertDatLinkToDB(fileid, $8 + i * 4);
754  end
755  else
756  begin
757  end;
758 end;
759
760
761
762
763 procedure CBPI(fileid: LongWord; dir_dat2db: Boolean);
764 var
765  i: LongWord;
766 begin
767  if dir_dat2db then
768  begin
769    for i := 0 to 56 do
770      InsertDatLinkToDB(fileid, $8 + i * 4);
771  end
772  else
773  begin
774  end;
775 end;
776
777
778
779
780 procedure CBPM(fileid: LongWord; dir_dat2db: Boolean);
781 var
782  i: LongWord;
783 begin
784  if dir_dat2db then
785  begin
786    for i := 0 to 18 do
787      InsertDatLinkToDB(fileid, $8 + i * 4);
788  end
789  else
790  begin
791  end;
792 end;
793
794
795
796
797 procedure CONS(fileid: LongWord; dir_dat2db: Boolean);
798 var
799  i: LongWord;
800 begin
801  if dir_dat2db then
802  begin
803    for i := 0 to 1 do
804      InsertDatLinkToDB(fileid, $24 + i * 4);
805  end
806  else
807  begin
808  end;
809 end;
810
811
812
813
814 procedure CRSA(fileid: LongWord; dir_dat2db: Boolean);
815 var
816  packages: LongWord;
817  i: LongWord;
818 begin
819  if dir_dat2db then
820  begin
821    OniDataConnection.LoadDatFilePart(fileid, $14, 4, @packages);
822    if packages > 0 then
823      for i := 0 to packages - 1 do
824        InsertDatLinkToDB(fileid, $20 + i * 1100 + $A0);
825  end
826  else
827  begin
828  end;
829 end;
830
831
832
833
834 procedure DOOR(fileid: LongWord; dir_dat2db: Boolean);
835 begin
836  if dir_dat2db then
837  begin
838    InsertDatLinkToDB(fileid, $08);
839    InsertDatLinkToDB(fileid, $10);
840  end
841  else
842  begin
843  end;
844 end;
845
846
847
848
849 procedure DPGE(fileid: LongWord; dir_dat2db: Boolean);
850 begin
851  if dir_dat2db then
852  begin
853    InsertDatLinkToDB(fileid, $40);
854  end
855  else
856  begin
857  end;
858 end;
859
860
861
862
863 procedure HPGE(fileid: LongWord; dir_dat2db: Boolean);
864 begin
865  if dir_dat2db then
866  begin
867    InsertDatLinkToDB(fileid, $0C);
868  end
869  else
870  begin
871  end;
872 end;
873
874
875
876
877 procedure IGHH(fileid: LongWord; dir_dat2db: Boolean);
878 begin
879  if dir_dat2db then
880  begin
881    InsertDatLinkToDB(fileid, $24);
882    InsertDatLinkToDB(fileid, $28);
883  end
884  else
885  begin
886  end;
887 end;
888
889
890
891
892 procedure IGPA(fileid: LongWord; dir_dat2db: Boolean);
893 var
894  links: LongWord;
895  i:     LongWord;
896 begin
897  if dir_dat2db then
898  begin
899    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @links);
900    if links > 0 then
901      for i := 0 to links - 1 do
902        InsertDatLinkToDB(fileid, $20 + i * 4);
903  end
904  else
905  begin
906  end;
907 end;
908
909
910
911
912 procedure IGPG(fileid: LongWord; dir_dat2db: Boolean);
913 var
914  i: LongWord;
915 begin
916  if dir_dat2db then
917  begin
918    for i := 0 to 1 do
919      InsertDatLinkToDB(fileid, $1C + i * 4);
920  end
921  else
922  begin
923  end;
924 end;
925
926
927
928
929 procedure IGSA(fileid: LongWord; dir_dat2db: Boolean);
930 var
931  links: LongWord;
932  i:     LongWord;
933 begin
934  if dir_dat2db then
935  begin
936    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @links);
937    if links > 0 then
938      for i := 0 to links - 1 do
939        InsertDatLinkToDB(fileid, $20 + i * 4);
940  end
941  else
942  begin
943  end;
944 end;
945
946
947
948
949 procedure IMPT(fileid: LongWord; dir_dat2db: Boolean);
950 begin
951  if dir_dat2db then
952  begin
953    InsertDatLinkToDB(fileid, $10);
954  end
955  else
956  begin
957  end;
958 end;
959
960
961
962
963 procedure IPGE(fileid: LongWord; dir_dat2db: Boolean);
964 begin
965  if dir_dat2db then
966  begin
967    InsertDatLinkToDB(fileid, $0C);
968  end
969  else
970  begin
971  end;
972 end;
973
974
975
976
977 procedure KEYI(fileid: LongWord; dir_dat2db: Boolean);
978 var
979  i: LongWord;
980 begin
981  if dir_dat2db then
982  begin
983    for i := 0 to 9 do
984      InsertDatLinkToDB(fileid, $08 + i * 4);
985  end
986  else
987  begin
988  end;
989 end;
990
991
992
993
994 procedure M3GA(fileid: LongWord; dir_dat2db: Boolean);
995 var
996  links: LongWord;
997  i:     LongWord;
998 begin
999  if dir_dat2db then
1000  begin
1001    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @links);
1002    if links > 0 then
1003      for i := 0 to links - 1 do
1004        InsertDatLinkToDB(fileid, $20 + i * 4);
1005  end
1006  else
1007  begin
1008  end;
1009 end;
1010
1011
1012
1013
1014 procedure M3GM(fileid: LongWord; dir_dat2db: Boolean);
1015 var
1016  i: LongWord;
1017 begin
1018  if dir_dat2db then
1019  begin
1020    for i := 0 to 6 do
1021      InsertDatLinkToDB(fileid, $0C + i * 4);
1022  end
1023  else
1024  begin
1025  end;
1026 end;
1027
1028
1029
1030
1031 procedure MTRL(fileid: LongWord; dir_dat2db: Boolean);
1032 begin
1033  if dir_dat2db then
1034  begin
1035    InsertDatLinkToDB(fileid, $10);
1036  end
1037  else
1038  begin
1039  end;
1040 end;
1041
1042
1043
1044
1045 procedure OBDC(fileid: LongWord; dir_dat2db: Boolean);
1046 var
1047  packages: Word;
1048  i: LongWord;
1049 begin
1050  if dir_dat2db then
1051  begin
1052    OniDataConnection.LoadDatFilePart(fileid, $1E, 2, @packages);
1053    if packages > 0 then
1054      for i := 0 to packages - 1 do
1055        InsertDatLinkToDB(fileid, $20 + i * $18 + $4);
1056  end
1057  else
1058  begin
1059  end;
1060 end;
1061
1062
1063
1064
1065 procedure OBOA(fileid: LongWord; dir_dat2db: Boolean);
1066 var
1067  packages: Word;
1068  i: LongWord;
1069 begin
1070  if dir_dat2db then
1071  begin
1072    OniDataConnection.LoadDatFilePart(fileid, $1E, 2, @packages);
1073    if packages > 0 then
1074      for i := 0 to packages - 1 do
1075      begin
1076        InsertDatLinkToDB(fileid, $20 + i * 240 + $0);
1077        InsertDatLinkToDB(fileid, $20 + i * 240 + $4);
1078        InsertDatLinkToDB(fileid, $20 + i * 240 + $8);
1079      end;
1080  end
1081  else
1082  begin
1083  end;
1084 end;
1085
1086
1087
1088
1089 procedure OFGA(fileid: LongWord; dir_dat2db: Boolean);
1090 var
1091  packages: LongWord;
1092  i: LongWord;
1093 begin
1094  if dir_dat2db then
1095  begin
1096    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
1097    if packages > 0 then
1098      for i := 0 to packages - 1 do
1099        InsertDatLinkToDB(fileid, $20 + i * 12 + $04);
1100  end
1101  else
1102  begin
1103  end;
1104 end;
1105
1106
1107
1108
1109 procedure ONCC(fileid: LongWord; dir_dat2db: Boolean);
1110 var
1111  i: LongWord;
1112 begin
1113  if dir_dat2db then
1114  begin
1115    InsertDatLinkToDB(fileid, $28);
1116    InsertDatLinkToDB(fileid, $434);
1117    InsertDatLinkToDB(fileid, $438);
1118    InsertDatLinkToDB(fileid, $43C);
1119    InsertDatLinkToDB(fileid, $C3C);
1120    InsertDatLinkToDB(fileid, $C40);
1121    InsertDatLinkToDB(fileid, $C44);
1122    InsertDatLinkToDB(fileid, $C48);
1123    InsertDatLinkToDB(fileid, $C88);
1124    InsertDatLinkToDB(fileid, $C8C);
1125  end
1126  else
1127  begin
1128  end;
1129 end;
1130
1131
1132
1133
1134 procedure ONCV(fileid: LongWord; dir_dat2db: Boolean);
1135 begin
1136  if dir_dat2db then
1137  begin
1138    InsertDatLinkToDB(fileid, $08);
1139  end
1140  else
1141  begin
1142  end;
1143 end;
1144
1145
1146
1147
1148 procedure ONLV(fileid: LongWord; dir_dat2db: Boolean);
1149 var
1150  i: LongWord;
1151 begin
1152  if dir_dat2db then
1153  begin
1154    for i := 0 to 5 do
1155      InsertDatLinkToDB(fileid, $48 + i * 4);
1156    for i := 0 to 5 do
1157      InsertDatLinkToDB(fileid, $64 + i * 4);
1158    InsertDatLinkToDB(fileid, $300);
1159  end
1160  else
1161  begin
1162  end;
1163 end;
1164
1165
1166
1167
1168 procedure ONOA(fileid: LongWord; dir_dat2db: Boolean);
1169 var
1170  packages: LongWord;
1171  i: LongWord;
1172 begin
1173  if dir_dat2db then
1174  begin
1175    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
1176    if packages > 0 then
1177      for i := 0 to packages - 1 do
1178        InsertDatLinkToDB(fileid, $20 + i * 8 + $04);
1179  end
1180  else
1181  begin
1182  end;
1183 end;
1184
1185
1186
1187
1188 procedure ONSK(fileid: LongWord; dir_dat2db: Boolean);
1189 begin
1190  if dir_dat2db then
1191  begin
1192    InsertDatLinkToDB(fileid, $08);
1193    InsertDatLinkToDB(fileid, $0C);
1194    InsertDatLinkToDB(fileid, $10);
1195    InsertDatLinkToDB(fileid, $14);
1196    InsertDatLinkToDB(fileid, $18);
1197    InsertDatLinkToDB(fileid, $20);
1198    InsertDatLinkToDB(fileid, $44);
1199  end
1200  else
1201  begin
1202  end;
1203 end;
1204
1205
1206
1207
1208 procedure ONVL(fileid: LongWord; dir_dat2db: Boolean);
1209 var
1210  packages: LongWord;
1211  i: LongWord;
1212 begin
1213  if dir_dat2db then
1214  begin
1215    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
1216    if packages > 0 then
1217      for i := 0 to packages - 1 do
1218        InsertDatLinkToDB(fileid, $20 + i * 4);
1219  end
1220  else
1221  begin
1222  end;
1223 end;
1224
1225
1226
1227
1228 procedure ONWC(fileid: LongWord; dir_dat2db: Boolean);
1229 begin
1230  if dir_dat2db then
1231  begin
1232    InsertDatLinkToDB(fileid, $28);
1233    InsertDatLinkToDB(fileid, $34);
1234    InsertDatLinkToDB(fileid, $40);
1235    InsertDatLinkToDB(fileid, $54);
1236    InsertDatLinkToDB(fileid, $58);
1237    InsertDatLinkToDB(fileid, $5C);
1238    InsertDatLinkToDB(fileid, $60);
1239    InsertDatLinkToDB(fileid, $6FC);
1240    InsertDatLinkToDB(fileid, $700);
1241  end
1242  else
1243  begin
1244  end;
1245 end;
1246
1247
1248
1249
1250 procedure OPGE(fileid: LongWord; dir_dat2db: Boolean);
1251 begin
1252  if dir_dat2db then
1253  begin
1254    InsertDatLinkToDB(fileid, $0C);
1255  end
1256  else
1257  begin
1258  end;
1259 end;
1260
1261
1262
1263
1264 procedure PSPC(fileid: LongWord; dir_dat2db: Boolean);
1265 begin
1266  if dir_dat2db then
1267  begin
1268    InsertDatLinkToDB(fileid, $50);
1269  end
1270  else
1271  begin
1272  end;
1273 end;
1274
1275
1276
1277
1278 procedure PSPL(fileid: LongWord; dir_dat2db: Boolean);
1279 var
1280  packages: LongWord;
1281  i: LongWord;
1282 begin
1283  if dir_dat2db then
1284  begin
1285    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
1286    if packages > 0 then
1287      for i := 0 to packages - 1 do
1288        InsertDatLinkToDB(fileid, $20 + i * 8 + $4);
1289  end
1290  else
1291  begin
1292  end;
1293 end;
1294
1295
1296
1297
1298 procedure PSUI(fileid: LongWord; dir_dat2db: Boolean);
1299 var
1300  i: LongWord;
1301 begin
1302  if dir_dat2db then
1303  begin
1304    for i := 0 to 43 do
1305      InsertDatLinkToDB(fileid, $08 + i * 4);
1306  end
1307  else
1308  begin
1309  end;
1310 end;
1311
1312
1313
1314
1315 procedure STNA(fileid: LongWord; dir_dat2db: Boolean);
1316 var
1317  packages: Word;
1318  i: LongWord;
1319 begin
1320  if dir_dat2db then
1321  begin
1322    OniDataConnection.LoadDatFilePart(fileid, $1E, 2, @packages);
1323    if packages > 0 then
1324      for i := 0 to packages - 1 do
1325        InsertDatLinkToDB(fileid, $20 + i * 4);
1326  end
1327  else
1328  begin
1329  end;
1330 end;
1331
1332
1333
1334
1335 procedure TRAC(fileid: LongWord; dir_dat2db: Boolean);
1336 var
1337  packages: Word;
1338  i: LongWord;
1339 begin
1340  if dir_dat2db then
1341  begin
1342    InsertDatLinkToDB(fileid, $18);
1343    OniDataConnection.LoadDatFilePart(fileid, $1E, 2, @packages);
1344    if packages > 0 then
1345      for i := 0 to packages - 1 do
1346        InsertDatLinkToDB(fileid, $20 + i * 12 + 8);
1347  end
1348  else
1349  begin
1350  end;
1351 end;
1352
1353
1354
1355
1356 procedure TRAM(fileid: LongWord; dir_dat2db: Boolean);
1357 begin
1358  if dir_dat2db then
1359  begin
1360    InsertDatLinkToDB(fileid, $40);
1361    InsertDatLinkToDB(fileid, $44);
1362  end
1363  else
1364  begin
1365  end;
1366 end;
1367
1368
1369
1370
1371 procedure TRAS(fileid: LongWord; dir_dat2db: Boolean);
1372 begin
1373  if dir_dat2db then
1374  begin
1375    InsertDatLinkToDB(fileid, $08);
1376  end
1377  else
1378  begin
1379  end;
1380 end;
1381
1382
1383
1384
1385 procedure TRBS(fileid: LongWord; dir_dat2db: Boolean);
1386 var
1387  i: LongWord;
1388 begin
1389  if dir_dat2db then
1390  begin
1391    for i := 0 to 4 do
1392      InsertDatLinkToDB(fileid, $08 + i * 4);
1393  end
1394  else
1395  begin
1396  end;
1397 end;
1398
1399
1400
1401
1402 procedure TRCM(fileid: LongWord; dir_dat2db: Boolean);
1403 var
1404  i: LongWord;
1405 begin
1406  if dir_dat2db then
1407  begin
1408    for i := 0 to 2 do
1409      InsertDatLinkToDB(fileid, $5C + i * 4);
1410  end
1411  else
1412  begin
1413  end;
1414 end;
1415
1416
1417
1418
1419 procedure TRGA(fileid: LongWord; dir_dat2db: Boolean);
1420 var
1421  i: LongWord;
1422  packages: Word;
1423 begin
1424  if dir_dat2db then
1425  begin
1426    OniDataConnection.LoadDatFilePart(fileid, $1E, 2, @packages);
1427    if packages > 0 then
1428      for i := 0 to packages - 1 do
1429        InsertDatLinkToDB(fileid, $20 + i * 4);
1430  end
1431  else
1432  begin
1433  end;
1434 end;
1435
1436
1437
1438
1439 procedure TRGE(fileid: LongWord; dir_dat2db: Boolean);
1440 begin
1441  if dir_dat2db then
1442  begin
1443    InsertDatLinkToDB(fileid, $20);
1444  end
1445  else
1446  begin
1447  end;
1448 end;
1449
1450
1451
1452
1453 procedure TRIG(fileid: LongWord; dir_dat2db: Boolean);
1454 begin
1455  if dir_dat2db then
1456  begin
1457    InsertDatLinkToDB(fileid, $18);
1458    InsertDatLinkToDB(fileid, $24);
1459    InsertDatLinkToDB(fileid, $28);
1460  end
1461  else
1462  begin
1463  end;
1464 end;
1465
1466
1467
1468
1469 procedure TRMA(fileid: LongWord; dir_dat2db: Boolean);
1470 var
1471  i: LongWord;
1472  packages: Word;
1473 begin
1474  if dir_dat2db then
1475  begin
1476    OniDataConnection.LoadDatFilePart(fileid, $1E, 2, @packages);
1477    if packages > 0 then
1478      for i := 0 to packages - 1 do
1479        InsertDatLinkToDB(fileid, $20 + i * 4);
1480  end
1481  else
1482  begin
1483  end;
1484 end;
1485
1486
1487
1488
1489 procedure TRSC(fileid: LongWord; dir_dat2db: Boolean);
1490 var
1491  i: LongWord;
1492  packages: Word;
1493 begin
1494  if dir_dat2db then
1495  begin
1496    OniDataConnection.LoadDatFilePart(fileid, $1E, 2, @packages);
1497    if packages > 0 then
1498      for i := 0 to packages - 1 do
1499        InsertDatLinkToDB(fileid, $20 + i * 4);
1500  end
1501  else
1502  begin
1503  end;
1504 end;
1505
1506
1507
1508
1509 procedure TSFF(fileid: LongWord; dir_dat2db: Boolean);
1510 var
1511  i: LongWord;
1512  packages: LongWord;
1513 begin
1514  if dir_dat2db then
1515  begin
1516    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
1517    if packages > 0 then
1518      for i := 0 to packages - 1 do
1519        InsertDatLinkToDB(fileid, $20 + i * 4);
1520  end
1521  else
1522  begin
1523  end;
1524 end;
1525
1526
1527
1528
1529 procedure TSFT(fileid: LongWord; dir_dat2db: Boolean);
1530 begin
1531  if dir_dat2db then
1532  begin
1533    InsertDatLinkToDB(fileid, $1C);
1534  end
1535  else
1536  begin
1537  end;
1538 end;
1539
1540
1541
1542
1543 procedure TURR(fileid: LongWord; dir_dat2db: Boolean);
1544 begin
1545  if dir_dat2db then
1546  begin
1547    InsertDatLinkToDB(fileid, $60);
1548    InsertDatLinkToDB(fileid, $6C);
1549    InsertDatLinkToDB(fileid, $74);
1550  end
1551  else
1552  begin
1553  end;
1554 end;
1555
1556
1557
1558
1559 procedure TXAN(fileid: LongWord; dir_dat2db: Boolean);
1560 var
1561  i: LongWord;
1562  packages: LongWord;
1563 begin
1564  if dir_dat2db then
1565  begin
1566    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
1567    if packages > 0 then
1568      for i := 0 to packages - 1 do
1569        InsertDatLinkToDB(fileid, $20 + i * 4);
1570  end
1571  else
1572  begin
1573  end;
1574 end;
1575
1576
1577
1578
1579 procedure TXMA(fileid: LongWord; dir_dat2db: Boolean);
1580 var
1581  i: LongWord;
1582  packages: LongWord;
1583 begin
1584  if dir_dat2db then
1585  begin
1586    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
1587    if packages > 0 then
1588      for i := 0 to packages - 1 do
1589        InsertDatLinkToDB(fileid, $20 + i * 4);
1590  end
1591  else
1592  begin
1593  end;
1594 end;
1595
1596
1597
1598
1599 procedure TXMB(fileid: LongWord; dir_dat2db: Boolean);
1600 var
1601  i: LongWord;
1602  packages: LongWord;
1603 begin
1604  if dir_dat2db then
1605  begin
1606    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
1607    if packages > 0 then
1608      for i := 0 to packages - 1 do
1609        InsertDatLinkToDB(fileid, $20 + i * 4);
1610  end
1611  else
1612  begin
1613  end;
1614 end;
1615
1616
1617
1618
1619 procedure TXMP(fileid: LongWord; dir_dat2db: Boolean);
1620 begin
1621  if dir_dat2db then
1622  begin
1623    InsertDatLinkToDB(fileid, $94);
1624    InsertDatLinkToDB(fileid, $98);
1625  end
1626  else
1627  begin
1628  end;
1629 end;
1630
1631
1632
1633
1634 procedure TXTC(fileid: LongWord; dir_dat2db: Boolean);
1635 begin
1636  if dir_dat2db then
1637  begin
1638    InsertDatLinkToDB(fileid, $08);
1639  end
1640  else
1641  begin
1642  end;
1643 end;
1644
1645
1646
1647
1648 procedure WMCL(fileid: LongWord; dir_dat2db: Boolean);
1649 var
1650  i: LongWord;
1651  packages: LongWord;
1652 begin
1653  if dir_dat2db then
1654  begin
1655    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
1656    if packages > 0 then
1657      for i := 0 to packages - 1 do
1658        InsertDatLinkToDB(fileid, $20 + i * 8 + $4);
1659  end
1660  else
1661  begin
1662  end;
1663 end;
1664
1665
1666
1667
1668 procedure WMDD(fileid: LongWord; dir_dat2db: Boolean);
1669 var
1670  i: LongWord;
1671  packages: LongWord;
1672 begin
1673  if dir_dat2db then
1674  begin
1675    OniDataConnection.LoadDatFilePart(fileid, $11C, 4, @packages);
1676    if packages > 0 then
1677      for i := 0 to packages - 1 do
1678        InsertDatLinkToDB(fileid, $120 + i * $124 + $114);
1679  end
1680  else
1681  begin
1682  end;
1683 end;
1684
1685
1686
1687
1688 procedure WMMB(fileid: LongWord; dir_dat2db: Boolean);
1689 var
1690  i: LongWord;
1691  packages: LongWord;
1692 begin
1693  if dir_dat2db then
1694  begin
1695    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
1696    if packages > 0 then
1697      for i := 0 to packages - 1 do
1698        InsertDatLinkToDB(fileid, $20 + i * 4);
1699  end
1700  else
1701  begin
1702  end;
1703 end;
1704
1705
1706
1707
1708 procedure WPGE(fileid: LongWord; dir_dat2db: Boolean);
1709 begin
1710  if dir_dat2db then
1711  begin
1712    InsertDatLinkToDB(fileid, $08);
1713    InsertDatLinkToDB(fileid, $0C);
1714  end
1715  else
1716  begin
1717  end;
1718 end;
1719
1720
1721
1722
1723 procedure InsertHandler(ext: String; needed: Boolean; handler: THandler);
1724 begin
1725  SetLength(ConvertHandlers, Length(ConvertHandlers) + 1);
1726  ConvertHandlers[High(ConvertHandlers)].Ext     := ext;
1727  ConvertHandlers[High(ConvertHandlers)].needed  := needed;
1728  ConvertHandlers[High(ConvertHandlers)].handler := handler;
1729 end;
1730
1731 begin
1732  InsertHandler('ABNA', False, nil);
1733  //  InsertHandler('AGDB',True,AGDB);
1734  InsertHandler('AGDB', False, nil);
1735  InsertHandler('AGQC', False, nil);
1736  InsertHandler('AGQG', False, nil);
1737  InsertHandler('AGQR', False, nil);
1738  InsertHandler('AISA', True, AISA);
1739  InsertHandler('AITR', False, nil);
1740  InsertHandler('AKAA', False, nil);
1741  InsertHandler('AKBA', False, nil);
1742  InsertHandler('AKBP', False, nil);
1743  InsertHandler('AKDA', False, nil);
1744  InsertHandler('AKEV', True, AKEV);
1745  InsertHandler('AKOT', True, AKOT);
1746  InsertHandler('AKVA', False, nil);
1747  InsertHandler('BINA', False, nil);
1748  InsertHandler('CBPI', True, CBPI);
1749  InsertHandler('CBPM', True, CBPM);
1750  InsertHandler('CONS', True, CONS);
1751  InsertHandler('CRSA', True, CRSA);
1752  InsertHandler('DOOR', True, DOOR);
1753  InsertHandler('DPGE', True, DPGE);
1754  InsertHandler('ENVP', False, nil);
1755  InsertHandler('FILM', False, nil);
1756  InsertHandler('HPGE', True, HPGE);
1757  InsertHandler('IDXA', False, nil);
1758  InsertHandler('IGHH', True, IGHH);
1759  InsertHandler('IGPA', True, IGPA);
1760  InsertHandler('IGPG', True, IGPG);
1761  InsertHandler('IGSA', True, IGSA);
1762  InsertHandler('IMPT', True, IMPT);
1763  InsertHandler('IPGE', True, IPGE);
1764  InsertHandler('KEYI', True, KEYI);
1765  InsertHandler('M3GA', True, M3GA);
1766  InsertHandler('M3GM', True, M3GM);
1767  InsertHandler('MTRL', True, MTRL);
1768  InsertHandler('OBAN', False, nil);
1769  InsertHandler('OBDC', True, OBDC);
1770  InsertHandler('OBOA', True, OBOA);
1771  InsertHandler('OFGA', True, OFGA);
1772  InsertHandler('ONCC', True, ONCC);
1773  InsertHandler('ONCP', False, nil);
1774  InsertHandler('ONCV', True, ONCV);
1775  InsertHandler('ONFA', False, nil);
1776  InsertHandler('ONGS', False, nil);
1777  InsertHandler('ONIA', False, nil);
1778  InsertHandler('ONLD', False, nil);
1779  InsertHandler('ONLV', True, ONLV);
1780  InsertHandler('ONMA', False, nil);
1781  InsertHandler('ONOA', True, ONOA);
1782  InsertHandler('ONSA', False, nil);
1783  InsertHandler('ONSK', True, ONSK);
1784  InsertHandler('ONTA', False, nil);
1785  InsertHandler('ONVL', True, ONVL);
1786  InsertHandler('ONWC', True, ONWC);
1787  InsertHandler('OPGE', True, OPGE);
1788  InsertHandler('OSBD', False, nil);
1789  InsertHandler('OTIT', False, nil);
1790  InsertHandler('OTLF', False, nil);
1791  InsertHandler('PLEA', False, nil);
1792  InsertHandler('PNTA', False, nil);
1793  InsertHandler('PSPC', True, PSPC);
1794  InsertHandler('PSPL', True, PSPL);
1795  InsertHandler('PSUI', True, PSUI);
1796  InsertHandler('QTNA', False, nil);
1797  InsertHandler('SNDD', False, nil);
1798  InsertHandler('STNA', True, STNA);
1799  InsertHandler('SUBT', False, nil);
1800  InsertHandler('TRAC', True, TRAC);
1801  InsertHandler('TRAM', True, TRAM);
1802  InsertHandler('TRAS', True, TRAS);
1803  InsertHandler('TRBS', True, TRBS);
1804  InsertHandler('TRCM', True, TRCM);
1805  InsertHandler('TRGA', True, TRGA);
1806  InsertHandler('TRGE', True, TRGE);
1807  InsertHandler('TRIA', False, nil);
1808  InsertHandler('TRIG', True, TRIG);
1809  InsertHandler('TRMA', True, TRMA);
1810  InsertHandler('TRSC', True, TRSC);
1811  InsertHandler('TRTA', False, nil);
1812  InsertHandler('TSFF', True, TSFF);
1813  InsertHandler('TSFL', False, nil);
1814  InsertHandler('TSFT', True, TSFT);
1815  InsertHandler('TSGA', False, nil);
1816  InsertHandler('TSTR', False, nil);
1817  InsertHandler('TURR', True, TURR);
1818  InsertHandler('TXAN', True, TXAN);
1819  InsertHandler('TXCA', False, nil);
1820  InsertHandler('TXMA', True, TXMA);
1821  InsertHandler('TXMB', True, TXMB);
1822  InsertHandler('TXMP', True, TXMP);
1823  InsertHandler('TXTC', True, TXTC);
1824  InsertHandler('VCRA', False, nil);
1825  InsertHandler('WMCL', True, WMCL);
1826  InsertHandler('WMDD', True, WMDD);
1827  InsertHandler('WMM_', False, nil);
1828  InsertHandler('WMMB', True, WMMB);
1829  InsertHandler('WPGE', True, WPGE);
761   end.

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)