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 113 by alloc, Sun Feb 25 17:20:22 2007 UTC vs.
Revision 132 by alloc, Wed Mar 28 01:41: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 78 | Line 75 | var
75    Connection: TDataAccess;
76    ConRepMsg:  TStatusMessages;
77  
78 +  FileID:     Integer;
79 +
80    Strings:    TStrings;
81    i, j:       Integer;
82    temps:      String;
83 +  tempi:      Integer;
84 +  tempb:      Byte;
85    FileInfo:   TFileInfo;
86 +  DatLinks:   TDatLinkList;
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 145 | Line 154 | begin
154        begin
155          ShowMessage('Couldn''t delete file. Aborting');
156          Exit;
148      end else if not DeleteFile(AnsiReplaceStr(Target, '.dat', '.raw')) then
149      begin
150        ShowMessage('Couldn''t delete file. Aborting');
151        Exit;
152      end else if not DeleteFile(AnsiReplaceStr(Target, '.dat', '.sep')) then
153      begin
154        ShowMessage('Couldn''t delete file. Aborting');
155        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 269 | 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 i := 0 to DatHeader.Files - 1 do
292 >  for FileID := 0 to DatHeader.Files - 1 do
293    begin
294 <    FileInfo := Connection.GetFileInfo(i);
294 >    FileInfo := Connection.GetFileInfo(FileID);
295      for j := 0 to 3 do
296 <      FilesHeader[i].Extension[j] := FileInfo.Extension[4 - j];
296 >      FilesHeader[FileID].Extension[j] := FileInfo.Extension[4 - j];
297      if FileInfo.Size > 0 then
298      begin
299 <      //        DatLinks:=;
300 <      FilesHeader[i].DataAddr := Stream_Body.Size + 8;
299 >      QueryPerformanceCounter(tempticks1);
300 >
301 >      FilesHeader[FileID].DataAddr := Stream_Body.Size + 8;
302        DatFileStream := TMemoryStream.Create;
303 <      Connection.LoadDatFile(i, DatFileStream);
303 >      Connection.LoadDatFile(FileID, TStream(DatFileStream));
304        DatFileStream.Seek(4, soFromBeginning);
305        DatFileStream.Write(LevelID, 4);
306  
307 <      if (Pos(UpperCase(fileinfo.Extension), UpperCase(raws)) mod 4) = 1 then
307 >      QueryPerformanceCounter(tempticks2);
308 >      datsum := datsum + (tempticks2 - tempticks1);
309 >
310 >      DatLinks := Connection.GetDatLinks(FileID);
311 >      if Length(DatLinks) > 0 then
312        begin
313 <        rawlist := OniDataConnection.GetRawList(i);
290 <        if Length(rawlist) > 0 then
313 >        for i := 0 to High(DatLinks) do
314          begin
315 <          for j := 0 to High(rawlist) do
315 >          DatFileStream.Seek(DatLinks[i].SrcOffset, soFromBeginning);
316 >          if DatLinks[i].DestID < 0 then
317 >            tempi := 0
318 >          else
319 >            tempi := DatLinks[i].DestID * 256 + 1;
320 >          DatFileStream.Write(tempi, 4);
321 >        end;
322 >      end;
323 >
324 >      QueryPerformanceCounter(tempticks1);
325 >      linksum := linksum + (tempticks1 - tempticks2);
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;
306 <                    data[$89]:=(data[$89] and $CF) or $20;
307 <                  end;
308 < }                end
309 <              else
310 <              begin
311 <                SetLength(rawdata, rawlist[j].raw_size);
312 <                OniDataConnection.LoadRawFile(i, rawlist[j].src_offset, @rawdata[0]);
313 <              end;
314 <              //                data[$88]:=data[$88] and $FE;
315 <
316 <              if rawlist[j].loc_sep then
317 <              begin
318 <                rawlist[j].raw_addr := Stream_Sep.Size;
319 <                Stream_Sep.Write(rawdata[0], Length(rawdata));
320 <              end
321 <              else
322 <              begin
323 <                rawlist[j].raw_addr := Stream_Raw.Size;
324 <                Stream_Raw.Write(rawdata[0], Length(rawdata));
325 <              end;
326 <            end
327 <            else
328 <              rawlist[j].raw_addr := 0;
329 <            Data[rawlist[j].src_offset + 0] := (rawlist[j].raw_addr) and $FF;
330 <            Data[rawlist[j].src_offset + 1] := (rawlist[j].raw_addr shr 8) and $FF;
331 <            Data[rawlist[j].src_offset + 2] := (rawlist[j].raw_addr shr 16) and $FF;
332 <            Data[rawlist[j].src_offset + 3] := (rawlist[j].raw_addr shr 24) and $FF;
333 <          end;
339 >              RawLinks[i].RawAddr := Stream_Sep.Size;
340 >              Stream_sep.CopyFrom(RawFileStream, RawFileStream.Size);
341 >            end else begin
342 >              RawLinks[i].RawAddr := Stream_Raw.Size;
343 >              Stream_Raw.CopyFrom(RawFileStream, RawFileStream.Size);
344 >            end;
345 >          end else
346 >            RawLinks[i].RawAddr := 0;
347 >          DatFileStream.Seek(RawLinks[i].SrcOffset, soFromBeginning);
348 >          DatFileStream.Write(RawLinks[i].RawAddr, 4);
349          end;
350        end;
351 +      DatFileStream.Seek(0, soFromBeginning);
352 +      Stream_Body.CopyFrom(DatFileStream, DatFileStream.Size);
353  
354 <      Stream_Body.Write(Data[0], Length(Data));
355 <      //
354 >      QueryPerformanceCounter(tempticks2);
355 >      rawsum := rawsum + (tempticks2 - tempticks1);
356      end
357      else
358        FilesHeader[i].DataAddr := 0;
# Line 350 | Line 367 | begin
367      FilesHeader[i].FileSize := fileinfo.Size;
368      FilesHeader[i].FileType := fileinfo.FileType;
369  
370 <    if ((i mod 10) = 0) and (i >= 100) then
370 >    if ((FileID mod 10) = 0) and (FileID >= 100) then
371        lbl_estimation.Caption := 'Estimated time left: ' + TimeToStr(
372 <        (Time - FileTime) / i * (progress.Max - i + 1) * 1.1, TimeFormat );
373 <    progress.Position := i + 1;
374 <    lbl_progress.Caption := 'Files done: ' + IntToStr(i + 1) + '/' + IntToStr(progress.Max);
372 >        (Time - FileTime) / FileID * (progress.Max - FileID + 1) * 1.1, TimeFormat );
373 >    progress.Position := FileID + 1;
374 >    lbl_progress.Caption := 'Files done: ' + IntToStr(FileID + 1) + '/' + IntToStr(progress.Max);
375      Application.ProcessMessages;
376    end;
377  
378 +  ShowMessage('AvgDats: ' + FloatToStr((datsum / progress.Max) / freq) + #13#10 +
379 +      'AvgLinks: ' + FloatToStr((linksum / progress.Max) / freq) + #13#10 +
380 +      'AvgRaws: ' + FloatToStr((rawsum / progress.Max) / freq)
381 +   );
382 +
383    Stream_Dat.Write(DatHeader, SizeOf(DatHeader));
384    for i := 0 to High(FilesHeader) do
385      Stream_Dat.Write(FilesHeader[i], SizeOf(FilesHeader[i]));
# Line 382 | Line 404 | begin
404    Stream_Body.Free;
405    Stream_Names.Free;
406    Stream_Raw.Free;
407 <  if OniDataConnection.OSisMac then
407 >
408 >  if Connection.DataOS in [DOS_WINDEMO, DOS_MAC, DOS_MACBETA] then
409      Stream_Sep.Free;
410  
411    progress.Position      := progress.Max;
# Line 398 | Line 421 | begin
421  
422    converting := False;
423  
424 <  CloseDataConnection(DataConnections[conIndex]);
424 > //  CloseDataConnection(DataConnections[conIndex]);
425   end;
426  
427  
# Line 408 | Line 431 | procedure TForm_LevelDB.HandleFile;
431   var
432    i: Byte;
433   begin
434 <  for i := 1 to Length(ConvertHandlers) do
434 > {  for i := 1 to Length(ConvertHandlers) do
435      if UpperCase(ConvertHandlers[i].Ext) = UpperCase(ext) then
436        if ConvertHandlers[i].needed then
437        begin
# Line 417 | Line 440 | begin
440        end
441        else
442          Break;
443 < end;
443 > }end;
444  
445  
446  
447  
448   procedure TForm_LevelDB.CreateDatabase(Source, target: String);
449 + {
450   var
451    DataBase:    TABSDatabase;
452    Query:       TABSQuery;
# Line 454 | Line 478 | const
478      else
479        group_progress.Caption := 'Creating DB (FINISHED)';
480    end;
481 + }
482  
483   begin
484 <  if CreateDataConnection(Source, ODB_Dat) = nil then
484 > {  if CreateDataConnection(Source, ODB_Dat) = nil then
485    begin
486      ShowMessage('Could not connect to .dat-file');
487      Exit;
# Line 659 | Line 684 | begin
684    database.Free;
685  
686    CloseDataConnection(DataConnections[conIndex]);
687 + }
688   end;
689  
690  
691  
692  
693 < procedure TForm_LevelDB.stop_convert;
693 > procedure TForm_LevelDB.StopConvert;
694   begin
695 <  btn_abortok.Caption := '&Close';
695 > {  btn_abortok.Caption := '&Close';
696    btn_abortok.Default := True;
697    converting := False;
698    lbl_estimation.Caption := 'ABORTED';
# Line 677 | Line 703 | begin
703    begin
704      DeleteFile(loaded_filename);
705    end;
706 < end;
706 > }end;
707  
708  
709  
# Line 700 | Line 726 | end;
726  
727  
728  
729 <
729 > {
730   procedure InsertDatLinkToDB(fileid: LongWord; offset: LongWord);
731   var
732    link: LongWord;
# Line 1732 | Line 1758 | begin
1758    begin
1759    end;
1760   end;
1761 + }
1762  
1763  
1764 <
1738 <
1764 > {
1765   procedure InsertHandler(ext: String; needed: Boolean; handler: THandler);
1766   begin
1767    SetLength(ConvertHandlers, Length(ConvertHandlers) + 1);
# Line 1743 | Line 1769 | begin
1769    ConvertHandlers[High(ConvertHandlers)].needed  := needed;
1770    ConvertHandlers[High(ConvertHandlers)].handler := handler;
1771   end;
1772 <
1772 > }
1773   begin
1774 <  InsertHandler('ABNA', False, nil);
1774 > {  InsertHandler('ABNA', False, nil);
1775    //  InsertHandler('AGDB',True,AGDB);
1776    InsertHandler('AGDB', False, nil);
1777    InsertHandler('AGQC', False, nil);
# Line 1843 | Line 1869 | begin
1869    InsertHandler('WMM_', False, nil);
1870    InsertHandler('WMMB', True, WMMB);
1871    InsertHandler('WPGE', True, WPGE);
1872 < end.
1872 > }end.

Diff Legend

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