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 150 by alloc, Sun Apr 1 18:26:35 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 60 | Line 44 | end;
44  
45  
46   procedure TForm_LevelDB.CreateLevel(Source, Target: String);
47 + const
48 +  EmptyBytes: Array[0..31] of Byte = (
49 +      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 );
50   var
51    DatHeader:        THeader;
52    FilesHeader:      TFilesMap;
# Line 69 | Line 56 | var
56    Stream_Body, Stream_Names:          TMemoryStream;
57    Stream_Dat, Stream_Raw, Stream_Sep: TFileStream;
58  
72 //  FileCount: Integer;
73 //  temps, temps2: String;
74 //  Data, rawdata: Tdata;
59    BeginTime, FileTime: Double;
60    Step:     Integer;
77 //  rawlist:  TRawDataList;
78 //  extlist:  TExtensionsMap;
79 //  fileinfo: TFileInfo;
80 //  datlinks: TDatLinks;
81  OniImage:   TOniImage;
61    LevelID:    Integer;
62    TimeFormat: TFormatSettings;
63  
# Line 86 | Line 65 | var
65    Connection: TDataAccess;
66    ConRepMsg:  TStatusMessages;
67  
68 +  FileID:     Integer;
69 +
70    Strings:    TStrings;
71    i, j:       Integer;
72 +  temps:      String;
73 +  tempi:      Integer;
74 +  tempb:      Byte;
75 +  FileInfo:   TFileInfo;
76 +  DatLinks:   TDatLinkList;
77 +  RawLinks:   TRawDataList;
78 +
79 +  DatFileStream, RawFileStream: TMemoryStream;
80   const
81    Steps: Byte = 3;
82  
# Line 102 | Line 91 | const
91        group_progress.Caption := 'Creating Dat (FINISHED)';
92    end;
93  
94 +  procedure StopConvert;
95 +  begin
96 +    btn_abortok.Caption := '&Close';
97 +    btn_abortok.Default := True;
98 +    converting := False;
99 +    lbl_estimation.Caption := 'ABORTED';
100 +    group_progress.Caption := 'Creating Level (ABORTED)';
101 +
102 +    Stream_Body.Free;
103 +    Stream_Names.Free;
104 +    DatFileStream.Free;
105 +    RawFileStream.Free;
106 +    
107 +    Stream_Dat.Free;
108 +    Stream_Raw.Free;
109 +    if Connection.DataOS in [DOS_WINDEMO, DOS_MAC, DOS_MACBETA] then
110 +      Stream_Sep.Free;
111 +    
112 +    if MessageBox(Self.Handle, PChar('Delete the unfinished level-files?'),
113 +      PChar('Delete files?'), MB_YESNO) = idYes then
114 +    begin
115 +      DeleteFile(target);
116 +      DeleteFile(AnsiReplaceStr(Target, '.dat', '.raw'));
117 +      if Connection.DataOS in [DOS_WINDEMO, DOS_MAC, DOS_MACBETA] then
118 +        DeleteFile(AnsiReplaceStr(Target, '.dat', '.sep'));
119 +    end;
120 +  end;
121 +
122   begin
123  
124    //
# Line 149 | Line 166 | begin
166        begin
167          ShowMessage('Couldn''t delete file. Aborting');
168          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;
169        end;
170 +      if FileExists(AnsiReplaceStr(Target, '.dat', '.raw')) then
171 +        if not DeleteFile(AnsiReplaceStr(Target, '.dat', '.raw')) then
172 +        begin
173 +          ShowMessage('Couldn''t delete file. Aborting');
174 +          Exit;
175 +        end;
176 +      if FileExists(AnsiReplaceStr(Target, '.dat', '.sep')) then
177 +        if Connection.DataOS in [DOS_WINDEMO, DOS_MAC, DOS_MACBETA] then
178 +          if not DeleteFile(AnsiReplaceStr(Target, '.dat', '.sep')) then
179 +          begin
180 +            ShowMessage('Couldn''t delete file. Aborting');
181 +            Exit;
182 +          end;
183      end else begin
184        ShowMessage('Aborting');
185        Exit;
# Line 166 | Line 188 | begin
188  
189    LevelID  := Connection.LevelNumber;
190    LevelID  := (LevelID * 2) * 256 * 256 * 256 + $01;
169  OniImage := TOniImage.Create;
191  
192    Self.Visible := True;
193    Form_Main.Visible := False;
# Line 208 | Line 229 | begin
229      end;
230    end;
231  
232 <  
233 <  extlist := OniDataConnection.GetExtendedExtensionsList;
234 <  for i := 0 to High(DatHeader.Ident) do
235 <    DatHeader.Ident[i] := OniDataConnection.LevelInfo.Ident[i];
236 <  DatHeader.Files := OniDataConnection.GetFilesCount;
232 >  for i := 0 to High(DatHeader.OSIdent) do
233 >    case Connection.DataOS of
234 >      DOS_WIN: DatHeader.OSIdent[i] := HeaderOSIdentWin[i];
235 >      DOS_MAC: DatHeader.OSIdent[i] := HeaderOSIdentMac[i];
236 >      DOS_MACBETA: DatHeader.OSIdent[i] := HeaderOSIdentMacBeta[i];
237 >    end;
238 >  for i := 0 to High(DatHeader.GlobalIdent) do
239 >    DatHeader.GlobalIdent[i] := HeaderGlobalIdent[i];
240 >  DatHeader.Files := Connection.GetFileCount;
241    DatHeader.NamedFiles := Length(NamedFilesHeader);
242 <  DatHeader.Extensions := Length(extlist);
242 >
243 >  Strings := Connection.GetExtensionsList(EF_ExtCount);
244 >
245 >  DatHeader.Extensions := Strings.Count;
246    DatHeader.DataAddr   := 0;
247    DatHeader.DataSize   := 0;
248    DatHeader.NamesAddr  := 0;
# Line 226 | Line 254 | begin
254  
255  
256    DoStep('Writing extensions-header');
257 <  progress.Max := Length(OniDataConnection.GetExtensionsList);
257 >  progress.Max := Strings.Count;
258    Application.ProcessMessages;
259 <
232 <  for i := 0 to High(ExtensionsHeader) do
259 >  for i := 0 to Strings.Count - 1 do
260    begin
261 <    ExtensionsHeader[i].Ident     := extlist[i].Ident;
262 <    ExtensionsHeader[i].Extension := extlist[i].Extension;
263 <    SetLength(temps, 4);
261 >    temps := Strings.Strings[i];
262 >    ExtensionsHeader[i].ExtCount := StrToInt( MidStr(
263 >            temps,
264 >            Pos('(', temps) + 1,
265 >            Pos(')', temps) - Pos('(', temps) - 1 ) );
266 >    temps := MidStr(temps, 1, 4);
267      for j := 0 to 3 do
268 <      temps[j + 1] := ExtensionsHeader[i].Extension[3 - j];
269 <    ExtensionsHeader[i].ExtCount :=
270 <      Length(OniDataConnection.GetFilesList(temps, '', False, stIDAsc));
268 >      ExtensionsHeader[i].Extension[j] := temps[4-j];
269 >    for j := 0 to High(FileTypes) do
270 >      if FileTypes[j].Extension = temps then
271 >        Break;
272 >    if j < Length(FileTypes) then
273 >    begin
274 >      case Connection.DataOS of
275 >        DOS_WIN:     ExtensionsHeader[i].Ident := FileTypes[j].IdentWin;
276 >        DOS_WINDEMO: ExtensionsHeader[i].Ident := FileTypes[j].IdentMac;
277 >        DOS_MAC:     ExtensionsHeader[i].Ident := FileTypes[j].IdentMac;
278 >        DOS_MACBETA: ExtensionsHeader[i].Ident := FileTypes[j].IdentMac;
279 >      end;
280 >    end else begin
281 >      ShowMessage('Unknown Extension: ' + Strings.Strings[i]);
282 >      Exit;
283 >    end;
284      progress.Position    := i + 1;
285      lbl_progress.Caption := 'Extensions done: ' + IntToStr(i + 1) + '/' +
286 <      IntToStr(Length(extlist));
286 >      IntToStr(Strings.Count);
287      Application.ProcessMessages;
288    end;
289  
247
290    DoStep('Storing files-data');
291    progress.Position := 0;
292    progress.Max      := DatHeader.Files;
# Line 252 | Line 294 | begin
294    lbl_estimation.Caption := 'Estimated finishing time: unknown';
295    Application.ProcessMessages;
296  
297 <  begintime := Time;
298 <  for i := 0 to DatHeader.Files - 1 do
297 >  FileTime := Time;
298 >  for FileID := 0 to DatHeader.Files - 1 do
299    begin
300 <    fileinfo := OniDataConnection.GetFileInfo(i);
300 >    FileInfo := Connection.GetFileInfo(FileID);
301      for j := 0 to 3 do
302 <      FilesHeader[i].Extension[j] := fileinfo.Extension[4 - j];
303 <    if fileinfo.Size > 0 then
302 >      FilesHeader[FileID].Extension[j] := FileInfo.Extension[4 - j];
303 >    if FileInfo.Size > 0 then
304      begin
305 <      //        DatLinks:=;
306 <      FilesHeader[i].DataAddr := Stream_Body.Size + 8;
307 <      Data    := OniDataConnection.LoadDatFile(i);
308 <      Data[4] := (levelid) and $FF;
309 <      Data[5] := (levelid shr 8) and $FF;
310 <      Data[6] := (levelid shr 16) and $FF;
311 <      Data[7] := (levelid shr 24) and $FF;
305 >      FilesHeader[FileID].DataAddr := Stream_Body.Size + 8;
306 >      DatFileStream := TMemoryStream.Create;
307 >      Connection.LoadDatFile(FileID, TStream(DatFileStream));
308 >      DatFileStream.Seek(0, soFromBeginning);
309 >      tempi := FileID * 256 + 1;
310 >      DatFileStream.Write(tempi, 4);
311 >      DatFileStream.Write(LevelID, 4);
312  
313 <      if (Pos(UpperCase(fileinfo.Extension), UpperCase(raws)) mod 4) = 1 then
313 >      DatLinks := Connection.GetDatLinks(FileID);
314 >      if Length(DatLinks) > 0 then
315        begin
316 <        rawlist := OniDataConnection.GetRawList(i);
274 <        if Length(rawlist) > 0 then
316 >        for i := 0 to High(DatLinks) do
317          begin
318 <          for j := 0 to High(rawlist) do
318 >          DatFileStream.Seek(DatLinks[i].SrcOffset, soFromBeginning);
319 >          if DatLinks[i].DestID < 0 then
320 >            tempi := 0
321 >          else
322 >            tempi := DatLinks[i].DestID * 256 + 1;
323 >          DatFileStream.Write(tempi, 4);
324 >        end;
325 >      end;
326 >
327 >      RawLinks := Connection.GetRawList(FileID);
328 >      if Length(RawLinks) > 0 then
329 >      begin
330 >        for i := 0 to High(RawLinks) do
331 >        begin
332 >          if RawLinks[i].RawSize > 0 then
333            begin
334 <            if rawlist[j].raw_size > 0 then
334 >            RawFileStream := TMemoryStream.Create;
335 >            Connection.LoadRawFile(FileID, RawLinks[i].SrcOffset, TStream(RawFileStream));
336 >            RawFileStream.Seek(0, soFromBeginning);
337 >            if RawLinks[i].LocSep then
338              begin
339 <              if (UpperCase(fileinfo.Extension) = 'TXMP') and
340 <                ((Data[$88] and $01) > 0) then
341 <              begin
342 <                OniImage.LoadFromTXMP(Connection, i);
343 <                OniImage.GetMipMappedImage(rawdata);
344 <                rawlist[j].raw_size := OniImage.GetImageDataSize(True);
345 <                Data[$90] := $08;
346 <                Data[$89] := 32;
347 < {                  if data[$90]<>OniImage.StoreType then begin
348 <                    data[$90]:=OniImage.StoreType;
349 <                    data[$89]:=(data[$89] and $CF) or $20;
350 <                  end;
351 < }                end
352 <              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;
339 >              RawLinks[i].RawAddr := Stream_Sep.Size;
340 >              Stream_sep.CopyFrom(RawFileStream, RawFileStream.Size);
341 >              if (Stream_Sep.Size mod 32) > 0 then
342 >                Stream_Sep.Write(EmptyBytes[0], 32 - (Stream_Sep.Size mod 32));
343 >            end else begin
344 >              RawLinks[i].RawAddr := Stream_Raw.Size;
345 >              Stream_Raw.CopyFrom(RawFileStream, RawFileStream.Size);
346 >              if (Stream_Raw.Size mod 32) > 0 then
347 >                Stream_Raw.Write(EmptyBytes[0], 32 - (Stream_Raw.Size mod 32));
348 >            end;
349 >          end else
350 >            RawLinks[i].RawAddr := 0;
351 >          DatFileStream.Seek(RawLinks[i].SrcOffset, soFromBeginning);
352 >          DatFileStream.Write(RawLinks[i].RawAddr, 4);
353          end;
354        end;
355 <
356 <      Stream_Body.Write(Data[0], Length(Data));
357 <      //
355 >      DatFileStream.Seek(0, soFromBeginning);
356 >      Stream_Body.CopyFrom(DatFileStream, DatFileStream.Size);
357 >      if (Stream_Body.Size mod 32) > 0 then
358 >      begin
359 >        ShowMessage(
360 >            IntToStr(FileID) + '-' + FileInfo.Name + '.' + FileInfo.Extension + #13#10 +
361 >            IntToStr(Stream_Body.Size));
362 >        Stream_Body.Write(EmptyBytes[0], 32 - (Stream_Body.Size mod 32));
363 >      end;
364      end
365      else
366 <      FilesHeader[i].DataAddr := 0;
366 >      FilesHeader[FileID].DataAddr := 0;
367      if Length(fileinfo.Name) > 0 then
368      begin
369 <      FilesHeader[i].NameAddr := Stream_Names.Size;
369 >      FilesHeader[FileID].NameAddr := Stream_Names.Size;
370        temps := fileinfo.Extension + fileinfo.Name + Chr(0);
371        Stream_Names.Write(temps[1], Length(temps));
372      end
373      else
374 <      FilesHeader[i].NameAddr := 0;
375 <    FilesHeader[i].FileSize := fileinfo.Size;
376 <    FilesHeader[i].FileType := fileinfo.FileType;
374 >      FilesHeader[FileID].NameAddr := 0;
375 >    FilesHeader[FileID].FileSize := fileinfo.Size;
376 >    FilesHeader[FileID].FileType := fileinfo.FileType;
377  
378 <    if ((i mod 10) = 0) and (i >= 100) then
378 >    if ((FileID mod 10) = 0) and (FileID >= 100) then
379        lbl_estimation.Caption := 'Estimated time left: ' + TimeToStr(
380 <        (Time - begintime) / i * (progress.Max - i + 1) * 1.1, timeformat );
381 <    progress.Position := i + 1;
382 <    lbl_progress.Caption := 'Files done: ' + IntToStr(i + 1) + '/' + IntToStr(progress.Max);
380 >        (Time - FileTime) / FileID * (progress.Max - FileID + 1) * 1.1, TimeFormat );
381 >    progress.Position := FileID + 1;
382 >    lbl_progress.Caption := 'Files done: ' + IntToStr(FileID + 1) + '/' + IntToStr(progress.Max);
383      Application.ProcessMessages;
384    end;
385  
# Line 350 | Line 391 | begin
391    for i := 0 to High(ExtensionsHeader) do
392      Stream_Dat.Write(ExtensionsHeader[i], SizeOf(ExtensionsHeader[i]));
393  
394 +  if (Stream_Dat.Size mod 32) > 0 then
395 +    Stream_Dat.Write(EmptyBytes[0], 32 - (Stream_Dat.Size mod 32));
396 +
397    DatHeader.DataSize  := Stream_Body.Size;
398    DatHeader.NamesSize := Stream_Names.Size;
399    DatHeader.DataAddr  := Stream_Dat.Size;
400 +
401    Stream_Body.Seek(0, soFromBeginning);
402    Stream_Dat.CopyFrom(Stream_Body, Stream_Body.Size);
403 +
404 +  if (Stream_Dat.Size mod 32) > 0 then
405 +    Stream_Dat.Write(EmptyBytes[0], 32 - (Stream_Dat.Size mod 32));
406 +
407    DatHeader.NamesAddr := Stream_Dat.Size;
408    Stream_Names.Seek(0, soFromBeginning);
409    Stream_Dat.CopyFrom(Stream_Names, Stream_Names.Size);
# Line 366 | Line 415 | begin
415    Stream_Body.Free;
416    Stream_Names.Free;
417    Stream_Raw.Free;
418 <  if OniDataConnection.OSisMac then
418 >
419 >  if Connection.DataOS in [DOS_WINDEMO, DOS_MAC, DOS_MACBETA] then
420      Stream_Sep.Free;
421  
422    progress.Position      := progress.Max;
423    lbl_progress.Caption   := 'Files done: ' + IntToStr(progress.Max) + '/' +
424      IntToStr(progress.Max);
425 <  lbl_estimation.Caption := 'FINISHED (duration: ' + TimeToStr(Time - absolutebegintime, timeformat) + ')';
425 >  lbl_estimation.Caption := 'FINISHED (duration: ' + TimeToStr(Time - Begintime, TimeFormat) + ')';
426  
427    DoStep('FIN');
428    btn_abortok.Caption := '&OK';
429    btn_abortok.Default := True;
430  
381  OniImage.Free;
382
431    converting := False;
432  
433 <  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;
433 > //  CloseDataConnection(DataConnections[conIndex]);
434   end;
435  
436  
# Line 408 | Line 438 | end;
438  
439   procedure TForm_LevelDB.CreateDatabase(Source, target: String);
440   var
441 <  DataBase:    TABSDatabase;
442 <  Query:       TABSQuery;
443 <  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;
441 >  DataBase:  TABSDatabase;
442 >  Query:     TABSQuery;
443 >  MimeCoder: TStringFormat_MIME64;
444  
445 <  conIndex: Integer;
446 < const
447 <  steps: Byte = 4;
445 >  BeginTime, FileTime: Double;
446 >  Step:       Integer;
447 >  TimeFormat: TFormatSettings;
448  
449 +  ConID:      Integer;
450 +  Connection: TDataAccess;
451 +  ConRepMsg:  TStatusMessages;
452  
453 +  FileID:     Integer;
454  
455 +  i:          Integer;
456 +  temps:      String;
457 +  tempdata:   TByteData;
458 +  FileInfo:   TFileInfo;
459 +  DatLinks:   TDatLinkList;
460 +  RawLinks:   TRawDataList;
461 + const
462 +  steps: Byte = 2;
463  
464    procedure DoStep(stepname: String);
465    begin
# Line 439 | Line 471 | const
471        group_progress.Caption := 'Creating DB (FINISHED)';
472    end;
473  
474 +  procedure StopConvert;
475 +  begin
476 +    btn_abortok.Caption := '&Close';
477 +    btn_abortok.Default := True;
478 +    converting := False;
479 +    lbl_estimation.Caption := 'ABORTED';
480 +    group_progress.Caption := 'Creating DB (ABORTED)';
481 +    DataBase.Close;
482 +    if MessageBox(Self.Handle, PChar('Delete the unfinished DB-file?'),
483 +      PChar('Delete file?'), MB_YESNO) = idYes then
484 +    begin
485 +      DeleteFile(target);
486 +    end;
487 + end;
488 +
489 +
490 +
491   begin
492 <  if CreateDataConnection(Source, ODB_Dat) = nil then
492 >
493 >  //
494 >  // FILE EXISTS CHECK FÜR DAT/RAW/SEP!!!
495 >  //
496 >
497 >  TimeFormat.ShortTimeFormat := 'hh:nn:ss';
498 >  TimeFormat.LongTimeFormat  := 'hh:nn:ss';
499 >  TimeFormat.TimeSeparator   := ':';
500 >
501 >  ConID := ConManager.OpenConnection(Source, ConRepMsg);
502 >  if not (ConRepMsg in [SM_OK, SM_AlreadyOpened]) then
503    begin
504 <    ShowMessage('Could not connect to .dat-file');
504 >    ShowMessage('Source-file couldn''t be opened! Aborting' + CrLf + GetOpenMsg(ConRepMsg));
505      Exit;
506 <  end
507 <  else
506 >  end else
507 >    Connection := ConManager.Connection[ConID];
508 >
509 >  ConID := ConManager.FileOpened(Target);
510 >  if ConID >= 0 then
511    begin
512 <    TOniDataDat(OniDataConnection).UnloadWhenUnused := False;
512 >    if MessageBox(Self.Handle, PChar('Destination-file is opened, close it in ' +
513 >          'order to proceed conversion?'), PChar('Destination-file opened'),
514 >          MB_YESNO + MB_ICONQUESTION) = ID_YES then
515 >    begin
516 >      if Form_Main.CheckConnectionCloseable(ConID) then
517 >        if not ConManager.CloseConnection(ConID, ConRepMsg) then
518 >        begin
519 >          ShowMessage('Couldn''t close destination-file. Aborting');
520 >          Exit;
521 >        end;
522 >    end else begin
523 >      ShowMessage('Aborting');
524 >      Exit;
525 >    end;
526    end;
527  
528 <  timeformat.LongTimeFormat := 'hh:nn:ss';
529 <  timeformat.ShortTimeFormat := 'hh:nn:ss';
530 <  timeformat.TimeSeparator := ':';
528 >  if FileExists(Target) then
529 >  begin
530 >    if MessageBox(Self.Handle, PChar('Destination-file exists. ' +
531 >          'Overwrite it?'), PChar('Destination-file exists'),
532 >          MB_YESNO + MB_ICONWARNING) = ID_YES then
533 >    begin
534 >      if not DeleteFile(Target) then
535 >      begin
536 >        ShowMessage('Couldn''t delete file. Aborting');
537 >        Exit;
538 >      end;
539 >    end else begin
540 >      ShowMessage('Aborting');
541 >      Exit;
542 >    end;
543 >  end;
544  
545    Self.Visible := True;
546    Form_Main.Visible := False;
# Line 461 | Line 549 | begin
549    abort := False;
550    btn_abortok.Caption := '&Abort...';
551    btn_abortok.Default := False;
464  loaded_filename := target;
552  
553 <  absolutebegintime := Time;
553 >  BeginTime := Time;
554  
555    DataBase := TABSDatabase.Create(Self);
556 +  DataBase.MaxConnections := 1;
557 +  DataBase.PageSize := 8112;
558 +  DataBase.PageCountInExtent := 8;
559 +
560    DataBase.DatabaseName := 'OLDB';
561    DataBase.DatabaseFileName := target;
562    DataBase.CreateDatabase;
# Line 479 | Line 570 | begin
570    Query := TABSQuery.Create(Self);
571    Query.DatabaseName := 'OLDB';
572    Query.SQL.Text :=
573 <    'CREATE TABLE globals  ( id AUTOINC PRIMARY KEY, name STRING(128), value STRING(128) );';
573 >    'CREATE TABLE globals  ( id AUTOINC PRIMARY KEY, name STRING(128), ' +
574 >    'value STRING(128) );';
575    Query.ExecSQL;
576    Query.SQL.Text :=
577 <    'CREATE TABLE linkmap  ( id AUTOINC PRIMARY KEY, src_id INTEGER, src_link_offset INTEGER, target_id INTEGER );';
577 >    'CREATE TABLE linkmap  ( id AUTOINC PRIMARY KEY, src_id INTEGER, ' +
578 >    'src_link_offset INTEGER, target_id INTEGER);';
579 >  Query.ExecSQL;
580 >  Query.SQL.Text := 'CREATE INDEX idsrcid ON linkmap (src_id);';
581 >  Query.ExecSQL;
582 >  Query.SQL.Text := 'CREATE INDEX idtargetid ON linkmap (target_id);';
583    Query.ExecSQL;
584    Query.SQL.Text :=
585 <    '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 );';
585 >    'CREATE TABLE rawmap  ( id AUTOINC PRIMARY KEY, src_id INTEGER, ' +
586 >    'src_link_offset INTEGER, sep BOOLEAN, size INTEGER, ' +
587 >    'data BLOB BlobCompressionMode 9 BlobBlockSize 1024 BlobCompressionAlgorithm ZLib);';
588    //    Query.SQL.Text:='CREATE TABLE rawmap  ( id AUTOINC PRIMARY KEY, src_id INTEGER, src_link_offset INTEGER, size INTEGER, data BLOB BlobCompressionAlgorithm None );';
589    Query.ExecSQL;
590 <  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 );';
590 >  Query.SQL.Text := 'CREATE INDEX idsrcid ON rawmap (src_id);';
591    Query.ExecSQL;
592    Query.SQL.Text :=
593 <    'CREATE TABLE extlist  ( id AUTOINC PRIMARY KEY, ext CHAR(4), ident CHAR(16) );';
593 >    'CREATE TABLE datfiles  ( id INTEGER PRIMARY KEY, extension CHAR(4), ' +
594 >    'name STRING(128), contenttype INTEGER, size INTEGER, ' +
595 >    'data BLOB BlobCompressionMode 9 BlobBlockSize 1024 BlobCompressionAlgorithm ZLib );';
596 >  //    Query.SQL.Text:='CREATE TABLE datfiles  ( id INTEGER PRIMARY KEY, extension CHAR(4), name STRING(128), contenttype INTEGER, size INTEGER, data BLOB BlobCompressionAlgorithm None );';
597    Query.ExecSQL;
598 + //  Query.SQL.Text :=
599 + //    'CREATE TABLE extlist  ( id AUTOINC PRIMARY KEY, ext CHAR(4), ident CHAR(16) );';
600 + //  Query.ExecSQL;
601  
602    Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("dbversion","' +
603      dbversion + '");';
604    Query.ExecSQL;
605 <  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;
605 >
606    Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("lvl","' +
607 <    IntToStr(OniDataConnection.LevelInfo.LevelNumber) + '");';
607 >    IntToStr(Connection.LevelNumber) + '");';
608    Query.ExecSQL;
609 <  if OniDataConnection.OSisMAC then
610 <    Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("os","MAC");'
611 <  else
612 <    Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("os","PC");';
613 <  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;
609 >  case Connection.DataOS of
610 >    DOS_WIN: temps := 'WIN';
611 >    DOS_WINDEMO: temps := 'WINDEMO';
612 >    DOS_MAC: temps := 'MAC';
613 >    DOS_MACBETA: temps := 'MACBETA';
614    end;
615 <  lbl_progress.Caption := '';
615 >  Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("os","' + temps + '");';
616 >  Query.ExecSQL;
617  
618    progress.Position      := 0;
619    lbl_progress.Caption   := 'Files done: ' + IntToStr(0) + '/' + IntToStr(
620 <    OniDataConnection.GetFilesCount);
620 >    Connection.GetFileCount);
621    lbl_estimation.Caption := 'Estimated finishing time: unknown';
622  
623 <  DoStep('Loading .dat into memory');
551 <  Application.ProcessMessages;
552 <
553 <  progress.Max := OniDataConnection.GetFilesCount;
623 >  progress.Max := Connection.GetFileCount;
624    begintime    := Time;
625    DoStep('Writing .dat-fileslist');
626    Application.ProcessMessages;
627  
628 +  FileTime := Time;
629    Database.StartTransaction;
630 <  for i := 0 to OniDataConnection.GetFilesCount - 1 do
630 >  for FileID := 0 to Connection.GetFileCount - 1 do
631    begin
632 <    fileinfo := OniDataConnection.GetFileInfo(i);
632 >    fileinfo := Connection.GetFileInfo(FileID);
633      if (fileinfo.FileType and $02) = 0 then
634      begin
635        mimecoder := TStringFormat_MIME64.Create;
636 <      Data      := OniDataConnection.LoadDatFile(i);
636 >      Connection.LoadDatFile(FileID, tempdata);
637        Query.SQL.Text :=
638          'INSERT INTO datfiles (id,extension,name,contenttype,size,data) VALUES (' +
639 <        IntToStr(i) + ',"' + fileinfo.Extension + '","' + fileinfo.Name + '","' + IntToHex(
639 >        IntToStr(FileID) + ',"' + fileinfo.Extension + '","' + fileinfo.Name + '","' + IntToHex(
640          fileinfo.FileType, 8) + '",' + IntToStr(fileinfo.Size) + ',MimeToBin("' +
641 <        MimeCoder.StrTo(@Data[0], Length(Data)) + '") );';
641 >        MimeCoder.StrTo(@tempdata[0], Length(tempdata)) + '") );';
642        Query.ExecSQL;
643        mimecoder.Free;
644  
645 <      rawlist := OniDataConnection.GetRawList(i);
646 <      if Length(rawlist) > 0 then
645 >      RawLinks := Connection.GetRawList(FileID);
646 >      if Length(RawLinks) > 0 then
647        begin
648 <        for j := 0 to High(rawlist) do
648 >        for i := 0 to High(RawLinks) do
649          begin
650 <          if rawlist[j].raw_size > 0 then
650 >          if RawLinks[i].RawSize > 0 then
651            begin
652 <            SetLength(Data, rawlist[j].raw_size);
653 <            OniDataConnection.LoadRawFile(i, rawlist[j].src_offset, Data);
652 >            SetLength(tempdata, RawLinks[i].RawSize);
653 >            Connection.LoadRawFile(FileID, RawLinks[i].SrcOffset, tempdata);
654              mimecoder      := TStringFormat_MIME64.Create;
655              Query.SQL.Text :=
656                'INSERT INTO rawmap (src_id,src_link_offset,sep,size,data) VALUES (' +
657 <              IntToStr(i) + ',' + IntToStr(rawlist[j].src_offset) + ',' + BoolToStr(
658 <              rawlist[j].loc_sep) + ',' + IntToStr(rawlist[j].raw_size) + ',MimeToBin("' +
659 <              MimeCoder.StrTo(@Data[0], rawlist[j].raw_size) + '") );';
657 >              IntToStr(FileID) + ', ' + IntToStr(RawLinks[i].SrcOffset) + ',' +
658 >              BoolToStr(RawLinks[i].LocSep) + ', ' +
659 >              IntToStr(RawLinks[i].RawSize) + ', ' +
660 >              'MimeToBin("' + MimeCoder.StrTo(@tempdata[0], RawLinks[i].RawSize) + '") );';
661              Query.ExecSQL;
662              mimecoder.Free;
663            end
# Line 593 | Line 665 | begin
665            begin
666              Query.SQL.Text :=
667                'INSERT INTO rawmap (src_id,src_link_offset,sep,size) VALUES (' +
668 <              IntToStr(i) + ',' + IntToStr(rawlist[j].src_offset) + ',' + BoolToStr(rawlist[j].loc_sep) + ',0);';
668 >              IntToStr(FileID) + ', ' + IntToStr(RawLinks[i].SrcOffset) + ', ' +
669 >              BoolToStr(RawLinks[i].LocSep) + ', 0);';
670              Query.ExecSQL;
671            end;
672          end;
673        end;
674  
675 <      HandleFile(fileinfo.Extension, i, True);
675 >      DatLinks := Connection.GetDatLinks(FileID);
676 >      if Length(DatLinks) > 0 then
677 >      begin
678 >        for i := 0 to High(DatLinks) do
679 >        begin
680 >          Query.SQL.Text :=
681 >            'INSERT INTO linkmap (src_id, src_link_offset, target_id) VALUES (' +
682 >            IntToStr(FileID) + ', ' + IntToStr(DatLinks[i].SrcOffset) + ', ' +
683 >            IntToStr(DatLinks[i].DestID) + ');';
684 >          Query.ExecSQL;
685 >        end;
686 >      end;
687      end
688      else
689      begin
690        Query.SQL.Text :=
691          'INSERT INTO datfiles (id,extension,name,contenttype,size) VALUES (' +
692 <        IntToStr(i) + ',"' + fileinfo.Extension + '","' + fileinfo.Name + '","' + IntToHex(
693 <        fileinfo.FileType, 8) + '",0);';
692 >        IntToStr(FileID) + ', "' + fileinfo.Extension + '", ' +
693 >        '"' + fileinfo.Name + '", "' + IntToHex(fileinfo.FileType, 8) + '", 0);';
694        Query.ExecSQL;
695      end;
696 <    if ((i mod 100) = 0) and (i > 0) then
696 >    if ((FileID mod 100) = 0) and (FileID > 0) then
697      begin
698        Database.Commit(False);
699        Database.StartTransaction;
700      end;
701 <    if ((i mod 10) = 0) and (i >= 100) then
701 >    if ((FileID mod 10) = 0) and (FileID >= 100) then
702        lbl_estimation.Caption := 'Estimated time left: ' + TimeToStr(
703 <        (Time - begintime) / i * (progress.Max - i + 1) * 1.1, timeformat );
704 <    progress.Position := i;
705 <    lbl_progress.Caption := 'Files done: ' + IntToStr(i) + '/' + IntToStr(progress.Max);
703 >        (Time - FileTime) / FileID * (progress.Max - FileID + 1) * 1.1, timeformat );
704 >    progress.Position := FileID;
705 >    lbl_progress.Caption := 'Files done: ' + IntToStr(FileID) + '/' + IntToStr(progress.Max);
706      Application.ProcessMessages;
707      if abort then
708      begin
709 <      stop_convert;
709 >      StopConvert;
710        Exit;
711      end;
712    end;
# Line 631 | Line 715 | begin
715    lbl_progress.Caption   := 'Files done: ' + IntToStr(progress.Max) + '/' +
716      IntToStr(progress.Max);
717  
718 <  lbl_estimation.Caption := 'FINISHED (duration: ' + TimeToStr(Time - absolutebegintime, timeformat) + ')';
718 >  lbl_estimation.Caption := 'FINISHED (duration: ' + TimeToStr(Time - BeginTime, timeformat) + ')';
719  
720    DoStep('FIN');
721    btn_abortok.Caption := '&OK';
# Line 639 | Line 723 | begin
723  
724    converting := False;
725  
726 <  database.Close;
727 <  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)';
726 >  Query.Close;
727 >  Query.Free;
728    DataBase.Close;
729 <  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;
729 >  DataBase.Free;
730   end;
731  
732  
# Line 683 | Line 749 | begin
749   end;
750  
751  
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);
752   end.

Diff Legend

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