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 127 by alloc, Fri Mar 23 17:14:40 2007 UTC vs.
Revision 137 by alloc, Fri Mar 30 00:00:10 2007 UTC

# Line 65 | Line 65 | var
65    Stream_Body, Stream_Names:          TMemoryStream;
66    Stream_Dat, Stream_Raw, Stream_Sep: TFileStream;
67  
68 //  Data, rawdata: Tdata;
68    BeginTime, FileTime: Double;
69    Step:     Integer;
71 //  rawlist:  TRawDataList;
72 //  datlinks: TDatLinks;
70    OniImage:   TOniImage;
71    LevelID:    Integer;
72    TimeFormat: TFormatSettings;
# Line 90 | Line 87 | var
87    RawLinks:   TRawDataList;
88  
89    DatFileStream, RawFileStream: TMemoryStream;
90 +
91 + // ###########################
92 +  datsum, linksum, rawsum: Int64;
93 +  freq: Int64;
94 +  tempticks1, tempticks2: Int64;
95 + // ###########################
96   const
97    Steps: Byte = 3;
98  
# Line 151 | Line 154 | begin
154        begin
155          ShowMessage('Couldn''t delete file. Aborting');
156          Exit;
154      end else if not DeleteFile(AnsiReplaceStr(Target, '.dat', '.raw')) then
155      begin
156        ShowMessage('Couldn''t delete file. Aborting');
157        Exit;
158      end else if not DeleteFile(AnsiReplaceStr(Target, '.dat', '.sep')) then
159      begin
160        ShowMessage('Couldn''t delete file. Aborting');
161        Exit;
157        end;
158 +      if FileExists(AnsiReplaceStr(Target, '.dat', '.raw')) then
159 +        if not DeleteFile(AnsiReplaceStr(Target, '.dat', '.raw')) then
160 +        begin
161 +          ShowMessage('Couldn''t delete file. Aborting');
162 +          Exit;
163 +        end;
164 +      if FileExists(AnsiReplaceStr(Target, '.dat', '.sep')) then
165 +        if Connection.DataOS in [DOS_WINDEMO, DOS_MAC, DOS_MACBETA] then
166 +          if not DeleteFile(AnsiReplaceStr(Target, '.dat', '.sep')) then
167 +          begin
168 +            ShowMessage('Couldn''t delete file. Aborting');
169 +            Exit;
170 +          end;
171      end else begin
172        ShowMessage('Aborting');
173        Exit;
# Line 275 | Line 283 | begin
283    lbl_estimation.Caption := 'Estimated finishing time: unknown';
284    Application.ProcessMessages;
285  
286 +  QueryPerformanceFrequency(freq);
287 +  datsum := 0;
288 +  linksum := 0;
289 +  rawsum := 0;
290 +
291    FileTime := Time;
292    for FileID := 0 to DatHeader.Files - 1 do
293    begin
# Line 283 | Line 296 | begin
296        FilesHeader[FileID].Extension[j] := FileInfo.Extension[4 - j];
297      if FileInfo.Size > 0 then
298      begin
299 +      QueryPerformanceCounter(tempticks1);
300 +
301        FilesHeader[FileID].DataAddr := Stream_Body.Size + 8;
302        DatFileStream := TMemoryStream.Create;
303        Connection.LoadDatFile(FileID, TStream(DatFileStream));
304 <      DatFileStream.Seek(4, soFromBeginning);
304 >      DatFileStream.Seek(0, soFromBeginning);
305 >      tempi := FileID * 256 + 1;
306 >      DatFileStream.Write(tempi, 4);
307        DatFileStream.Write(LevelID, 4);
308  
309 +      QueryPerformanceCounter(tempticks2);
310 +      datsum := datsum + (tempticks2 - tempticks1);
311 +
312        DatLinks := Connection.GetDatLinks(FileID);
313        if Length(DatLinks) > 0 then
314        begin
# Line 303 | Line 323 | begin
323          end;
324        end;
325  
326 +      QueryPerformanceCounter(tempticks1);
327 +      linksum := linksum + (tempticks1 - tempticks2);
328 +
329        RawLinks := Connection.GetRawList(FileID);
330        if Length(RawLinks) > 0 then
331        begin
# Line 323 | Line 346 | begin
346              end;
347            end else
348              RawLinks[i].RawAddr := 0;
349 +          DatFileStream.Seek(RawLinks[i].SrcOffset, soFromBeginning);
350 +          DatFileStream.Write(RawLinks[i].RawAddr, 4);
351          end;
352        end;
353 +      DatFileStream.Seek(0, soFromBeginning);
354 +      Stream_Body.CopyFrom(DatFileStream, DatFileStream.Size);
355  
356 < {
357 <            Data[rawlist[j].src_offset + 0] := (rawlist[j].raw_addr) and $FF;
331 <            Data[rawlist[j].src_offset + 1] := (rawlist[j].raw_addr shr 8) and $FF;
332 <            Data[rawlist[j].src_offset + 2] := (rawlist[j].raw_addr shr 16) and $FF;
333 <            Data[rawlist[j].src_offset + 3] := (rawlist[j].raw_addr shr 24) and $FF;
334 < }
335 <      Stream_Body.Write(Data[0], Length(Data));
336 <      //
356 >      QueryPerformanceCounter(tempticks2);
357 >      rawsum := rawsum + (tempticks2 - tempticks1);
358      end
359      else
360 <      FilesHeader[i].DataAddr := 0;
360 >      FilesHeader[FileID].DataAddr := 0;
361      if Length(fileinfo.Name) > 0 then
362      begin
363 <      FilesHeader[i].NameAddr := Stream_Names.Size;
363 >      FilesHeader[FileID].NameAddr := Stream_Names.Size;
364        temps := fileinfo.Extension + fileinfo.Name + Chr(0);
365        Stream_Names.Write(temps[1], Length(temps));
366      end
367      else
368 <      FilesHeader[i].NameAddr := 0;
369 <    FilesHeader[i].FileSize := fileinfo.Size;
370 <    FilesHeader[i].FileType := fileinfo.FileType;
368 >      FilesHeader[FileID].NameAddr := 0;
369 >    FilesHeader[FileID].FileSize := fileinfo.Size;
370 >    FilesHeader[FileID].FileType := fileinfo.FileType;
371  
372 <    if ((i mod 10) = 0) and (i >= 100) then
372 >    if ((FileID mod 10) = 0) and (FileID >= 100) then
373        lbl_estimation.Caption := 'Estimated time left: ' + TimeToStr(
374 <        (Time - FileTime) / i * (progress.Max - i + 1) * 1.1, TimeFormat );
375 <    progress.Position := i + 1;
376 <    lbl_progress.Caption := 'Files done: ' + IntToStr(i + 1) + '/' + IntToStr(progress.Max);
374 >        (Time - FileTime) / FileID * (progress.Max - FileID + 1) * 1.1, TimeFormat );
375 >    progress.Position := FileID + 1;
376 >    lbl_progress.Caption := 'Files done: ' + IntToStr(FileID + 1) + '/' + IntToStr(progress.Max);
377      Application.ProcessMessages;
378    end;
379  
380 +  ShowMessage('AvgDats: ' + FloatToStr((datsum / progress.Max) / freq) + #13#10 +
381 +      'AvgLinks: ' + FloatToStr((linksum / progress.Max) / freq) + #13#10 +
382 +      'AvgRaws: ' + FloatToStr((rawsum / progress.Max) / freq)
383 +   );
384 +
385    Stream_Dat.Write(DatHeader, SizeOf(DatHeader));
386    for i := 0 to High(FilesHeader) do
387      Stream_Dat.Write(FilesHeader[i], SizeOf(FilesHeader[i]));
# Line 367 | Line 393 | begin
393    DatHeader.DataSize  := Stream_Body.Size;
394    DatHeader.NamesSize := Stream_Names.Size;
395    DatHeader.DataAddr  := Stream_Dat.Size;
396 +
397    Stream_Body.Seek(0, soFromBeginning);
398    Stream_Dat.CopyFrom(Stream_Body, Stream_Body.Size);
399    DatHeader.NamesAddr := Stream_Dat.Size;
# Line 380 | Line 407 | begin
407    Stream_Body.Free;
408    Stream_Names.Free;
409    Stream_Raw.Free;
410 <  if OniDataConnection.OSisMac then
410 >
411 >  if Connection.DataOS in [DOS_WINDEMO, DOS_MAC, DOS_MACBETA] then
412      Stream_Sep.Free;
413  
414    progress.Position      := progress.Max;
# Line 396 | Line 424 | begin
424  
425    converting := False;
426  
427 <  CloseDataConnection(DataConnections[conIndex]);
427 > //  CloseDataConnection(DataConnections[conIndex]);
428   end;
429  
430  
# Line 406 | Line 434 | procedure TForm_LevelDB.HandleFile;
434   var
435    i: Byte;
436   begin
437 <  for i := 1 to Length(ConvertHandlers) do
437 > {  for i := 1 to Length(ConvertHandlers) do
438      if UpperCase(ConvertHandlers[i].Ext) = UpperCase(ext) then
439        if ConvertHandlers[i].needed then
440        begin
# Line 415 | Line 443 | begin
443        end
444        else
445          Break;
446 < end;
446 > }end;
447  
448  
449  
450  
451   procedure TForm_LevelDB.CreateDatabase(Source, target: String);
452   var
453 +  DataBase:  TABSDatabase;
454 + {
455 + var
456    DataBase:    TABSDatabase;
457    Query:       TABSQuery;
458    MimeCoder:   TStringFormat_MIME64;
# Line 452 | Line 483 | const
483      else
484        group_progress.Caption := 'Creating DB (FINISHED)';
485    end;
486 + }
487  
488   begin
489 <  if CreateDataConnection(Source, ODB_Dat) = nil then
489 > {  if CreateDataConnection(Source, ODB_Dat) = nil then
490    begin
491      ShowMessage('Could not connect to .dat-file');
492      Exit;
# Line 480 | Line 512 | begin
512    absolutebegintime := Time;
513  
514    DataBase := TABSDatabase.Create(Self);
515 + }
516 +  DataBase.MaxConnections := 1;
517 +  DataBase.PageSize := 8112;
518 +  DataBase.PageCountInExtent := 8;
519 + {
520    DataBase.DatabaseName := 'OLDB';
521    DataBase.DatabaseFileName := target;
522    DataBase.CreateDatabase;
# Line 493 | Line 530 | begin
530    Query := TABSQuery.Create(Self);
531    Query.DatabaseName := 'OLDB';
532    Query.SQL.Text :=
533 <    'CREATE TABLE globals  ( id AUTOINC PRIMARY KEY, name STRING(128), value STRING(128) );';
533 >    'CREATE TABLE globals  ( id AUTOINC PRIMARY KEY, name STRING(128), ' +
534 >    'value STRING(128) );';
535    Query.ExecSQL;
536    Query.SQL.Text :=
537 <    'CREATE TABLE linkmap  ( id AUTOINC PRIMARY KEY, src_id INTEGER, src_link_offset INTEGER, target_id INTEGER );';
537 >    'CREATE TABLE linkmap  ( id AUTOINC PRIMARY KEY, src_id INTEGER, ' +
538 >    'src_link_offset INTEGER, target_id INTEGER,  INDEX idsrcid src_id, ' +
539 >    'INDEX iddestid target_id);';
540    Query.ExecSQL;
541    Query.SQL.Text :=
542 <    '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 );';
542 >    'CREATE TABLE rawmap  ( id AUTOINC PRIMARY KEY, src_id INTEGER, ' +
543 >    'src_link_offset INTEGER, sep BOOLEAN, size INTEGER, ' +
544 >    'data BLOB BlobCompressionMode 9 BlobBlockSize 1024 BlobCompressionAlgorithm ZLib, ' +
545 >    'INDEX idsrcid src_id);';
546    //    Query.SQL.Text:='CREATE TABLE rawmap  ( id AUTOINC PRIMARY KEY, src_id INTEGER, src_link_offset INTEGER, size INTEGER, data BLOB BlobCompressionAlgorithm None );';
547    Query.ExecSQL;
548    Query.SQL.Text :=
549 <    '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 );';
549 >    'CREATE TABLE datfiles  ( id INTEGER PRIMARY KEY, extension CHAR(4), ' +
550 >    'name STRING(128), contenttype INTEGER, size INTEGER, ' +
551 >    'data BLOB BlobCompressionMode 9 BlobBlockSize 1024 BlobCompressionAlgorithm ZLib );';
552    //    Query.SQL.Text:='CREATE TABLE datfiles  ( id INTEGER PRIMARY KEY, extension CHAR(4), name STRING(128), contenttype INTEGER, size INTEGER, data BLOB BlobCompressionAlgorithm None );';
553    Query.ExecSQL;
554 <  Query.SQL.Text :=
555 <    'CREATE TABLE extlist  ( id AUTOINC PRIMARY KEY, ext CHAR(4), ident CHAR(16) );';
556 <  Query.ExecSQL;
554 > //  Query.SQL.Text :=
555 > //    'CREATE TABLE extlist  ( id AUTOINC PRIMARY KEY, ext CHAR(4), ident CHAR(16) );';
556 > //  Query.ExecSQL;
557  
558    Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("dbversion","' +
559      dbversion + '");';
# Line 517 | Line 562 | begin
562    for i := 0 to High(OniDataConnection.LevelInfo.Ident) do
563      Data[i] := OniDataConnection.LevelInfo.Ident[i];
564    temps := CreateHexString(Data, True);
565 <  Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("ident","' + temps + '");';
566 <  Query.ExecSQL;
565 > //  Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("ident","' + temps + '");';
566 > //  Query.ExecSQL;
567    Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("lvl","' +
568      IntToStr(OniDataConnection.LevelInfo.LevelNumber) + '");';
569    Query.ExecSQL;
# Line 657 | Line 702 | begin
702    database.Free;
703  
704    CloseDataConnection(DataConnections[conIndex]);
705 + }
706   end;
707  
708  
709  
710  
711 < procedure TForm_LevelDB.stop_convert;
711 > procedure TForm_LevelDB.StopConvert;
712   begin
713 <  btn_abortok.Caption := '&Close';
713 > {  btn_abortok.Caption := '&Close';
714    btn_abortok.Default := True;
715    converting := False;
716    lbl_estimation.Caption := 'ABORTED';
# Line 675 | Line 721 | begin
721    begin
722      DeleteFile(loaded_filename);
723    end;
724 < end;
724 > }end;
725  
726  
727  
# Line 698 | Line 744 | end;
744  
745  
746  
747 <
747 > {
748   procedure InsertDatLinkToDB(fileid: LongWord; offset: LongWord);
749   var
750    link: LongWord;
# Line 1730 | Line 1776 | begin
1776    begin
1777    end;
1778   end;
1779 + }
1780  
1781  
1782 <
1736 <
1782 > {
1783   procedure InsertHandler(ext: String; needed: Boolean; handler: THandler);
1784   begin
1785    SetLength(ConvertHandlers, Length(ConvertHandlers) + 1);
# Line 1741 | Line 1787 | begin
1787    ConvertHandlers[High(ConvertHandlers)].needed  := needed;
1788    ConvertHandlers[High(ConvertHandlers)].handler := handler;
1789   end;
1790 <
1790 > }
1791   begin
1792 <  InsertHandler('ABNA', False, nil);
1792 > {  InsertHandler('ABNA', False, nil);
1793    //  InsertHandler('AGDB',True,AGDB);
1794    InsertHandler('AGDB', False, nil);
1795    InsertHandler('AGQC', False, nil);
# Line 1841 | Line 1887 | begin
1887    InsertHandler('WMM_', False, nil);
1888    InsertHandler('WMMB', True, WMMB);
1889    InsertHandler('WPGE', True, WPGE);
1890 < end.
1890 > }end.

Diff Legend

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