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 133 by alloc, Wed Mar 28 02:23:44 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 27 | Line 25 | var
25    Form_LevelDB: TForm_LevelDB;
26  
27   implementation
30
28   {$R *.dfm}
32
29   uses ABSMain, ABSDecUtil, Main,
30 <    ConnectionManager, TypeDefs, DataAccess, OniImgClass;
30 >    ConnectionManager, TypeDefs, DataAccess, OniImgClass, Data;
31  
32   type
33    THandler = procedure(FileID: Integer);
# Line 69 | Line 65 | var
65    Stream_Body, Stream_Names:          TMemoryStream;
66    Stream_Dat, Stream_Raw, Stream_Sep: TFileStream;
67  
72 //  FileCount: Integer;
73 //  temps, temps2: String;
74 //  Data, rawdata: Tdata;
68    BeginTime, FileTime: Double;
69    Step:     Integer;
77 //  rawlist:  TRawDataList;
78 //  extlist:  TExtensionsMap;
79 //  fileinfo: TFileInfo;
80 //  datlinks: TDatLinks;
70    OniImage:   TOniImage;
71    LevelID:    Integer;
72    TimeFormat: TFormatSettings;
# Line 86 | 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 149 | Line 154 | begin
154        begin
155          ShowMessage('Couldn''t delete file. Aborting');
156          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;
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 208 | Line 218 | begin
218      end;
219    end;
220  
221 <  
222 <  extlist := OniDataConnection.GetExtendedExtensionsList;
223 <  for i := 0 to High(DatHeader.Ident) do
224 <    DatHeader.Ident[i] := OniDataConnection.LevelInfo.Ident[i];
225 <  DatHeader.Files := OniDataConnection.GetFilesCount;
221 >  for i := 0 to High(DatHeader.OSIdent) do
222 >    case Connection.DataOS of
223 >      DOS_WIN: DatHeader.OSIdent[i] := HeaderOSIdentWin[i];
224 >      DOS_MAC: DatHeader.OSIdent[i] := HeaderOSIdentMac[i];
225 >      DOS_MACBETA: DatHeader.OSIdent[i] := HeaderOSIdentMacBeta[i];
226 >    end;
227 >  for i := 0 to High(DatHeader.GlobalIdent) do
228 >    DatHeader.GlobalIdent[i] := HeaderGlobalIdent[i];
229 >  DatHeader.Files := Connection.GetFileCount;
230    DatHeader.NamedFiles := Length(NamedFilesHeader);
231 <  DatHeader.Extensions := Length(extlist);
231 >
232 >  Strings := Connection.GetExtensionsList(EF_ExtCount);
233 >
234 >  DatHeader.Extensions := Strings.Count;
235    DatHeader.DataAddr   := 0;
236    DatHeader.DataSize   := 0;
237    DatHeader.NamesAddr  := 0;
# Line 226 | Line 243 | begin
243  
244  
245    DoStep('Writing extensions-header');
246 <  progress.Max := Length(OniDataConnection.GetExtensionsList);
246 >  progress.Max := Strings.Count;
247    Application.ProcessMessages;
248 <
232 <  for i := 0 to High(ExtensionsHeader) do
248 >  for i := 0 to Strings.Count - 1 do
249    begin
250 <    ExtensionsHeader[i].Ident     := extlist[i].Ident;
251 <    ExtensionsHeader[i].Extension := extlist[i].Extension;
252 <    SetLength(temps, 4);
250 >    temps := Strings.Strings[i];
251 >    ExtensionsHeader[i].ExtCount := StrToInt( MidStr(
252 >            temps,
253 >            Pos('(', temps) + 1,
254 >            Pos(')', temps) - Pos('(', temps) - 1 ) );
255 >    temps := MidStr(temps, 1, 4);
256      for j := 0 to 3 do
257 <      temps[j + 1] := ExtensionsHeader[i].Extension[3 - j];
258 <    ExtensionsHeader[i].ExtCount :=
259 <      Length(OniDataConnection.GetFilesList(temps, '', False, stIDAsc));
257 >      ExtensionsHeader[i].Extension[j] := temps[4-j];
258 >    for j := 0 to High(FileTypes) do
259 >      if FileTypes[j].Extension = temps then
260 >        Break;
261 >    if j < Length(FileTypes) then
262 >    begin
263 >      case Connection.DataOS of
264 >        DOS_WIN:     ExtensionsHeader[i].Ident := FileTypes[j].IdentWin;
265 >        DOS_WINDEMO: ExtensionsHeader[i].Ident := FileTypes[j].IdentMac;
266 >        DOS_MAC:     ExtensionsHeader[i].Ident := FileTypes[j].IdentMac;
267 >        DOS_MACBETA: ExtensionsHeader[i].Ident := FileTypes[j].IdentMac;
268 >      end;
269 >    end else begin
270 >      ShowMessage('Unknown Extension: ' + Strings.Strings[i]);
271 >      Exit;
272 >    end;
273      progress.Position    := i + 1;
274      lbl_progress.Caption := 'Extensions done: ' + IntToStr(i + 1) + '/' +
275 <      IntToStr(Length(extlist));
275 >      IntToStr(Strings.Count);
276      Application.ProcessMessages;
277    end;
278  
247
279    DoStep('Storing files-data');
280    progress.Position := 0;
281    progress.Max      := DatHeader.Files;
# Line 252 | Line 283 | begin
283    lbl_estimation.Caption := 'Estimated finishing time: unknown';
284    Application.ProcessMessages;
285  
286 <  begintime := Time;
287 <  for i := 0 to DatHeader.Files - 1 do
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
294 <    fileinfo := OniDataConnection.GetFileInfo(i);
294 >    FileInfo := Connection.GetFileInfo(FileID);
295      for j := 0 to 3 do
296 <      FilesHeader[i].Extension[j] := fileinfo.Extension[4 - j];
297 <    if fileinfo.Size > 0 then
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;
301 <      Data    := OniDataConnection.LoadDatFile(i);
302 <      Data[4] := (levelid) and $FF;
303 <      Data[5] := (levelid shr 8) and $FF;
304 <      Data[6] := (levelid shr 16) and $FF;
305 <      Data[7] := (levelid shr 24) and $FF;
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(0, soFromBeginning);
305 >      DatFileStream.Write(FileID, 4);
306 >      DatFileStream.Write(LevelID, 4);
307  
308 <      if (Pos(UpperCase(fileinfo.Extension), UpperCase(raws)) mod 4) = 1 then
308 >      QueryPerformanceCounter(tempticks2);
309 >      datsum := datsum + (tempticks2 - tempticks1);
310 >
311 >      DatLinks := Connection.GetDatLinks(FileID);
312 >      if Length(DatLinks) > 0 then
313        begin
314 <        rawlist := OniDataConnection.GetRawList(i);
274 <        if Length(rawlist) > 0 then
314 >        for i := 0 to High(DatLinks) do
315          begin
316 <          for j := 0 to High(rawlist) do
316 >          DatFileStream.Seek(DatLinks[i].SrcOffset, soFromBeginning);
317 >          if DatLinks[i].DestID < 0 then
318 >            tempi := 0
319 >          else
320 >            tempi := DatLinks[i].DestID * 256 + 1;
321 >          DatFileStream.Write(tempi, 4);
322 >        end;
323 >      end;
324 >
325 >      QueryPerformanceCounter(tempticks1);
326 >      linksum := linksum + (tempticks1 - tempticks2);
327 >
328 >      RawLinks := Connection.GetRawList(FileID);
329 >      if Length(RawLinks) > 0 then
330 >      begin
331 >        for i := 0 to High(RawLinks) do
332 >        begin
333 >          if RawLinks[i].RawSize > 0 then
334            begin
335 <            if rawlist[j].raw_size > 0 then
335 >            RawFileStream := TMemoryStream.Create;
336 >            Connection.LoadRawFile(FileID, RawLinks[i].SrcOffset, TStream(RawFileStream));
337 >            RawFileStream.Seek(0, soFromBeginning);
338 >            if RawLinks[i].LocSep then
339              begin
340 <              if (UpperCase(fileinfo.Extension) = 'TXMP') and
341 <                ((Data[$88] and $01) > 0) then
342 <              begin
343 <                OniImage.LoadFromTXMP(Connection, i);
344 <                OniImage.GetMipMappedImage(rawdata);
345 <                rawlist[j].raw_size := OniImage.GetImageDataSize(True);
346 <                Data[$90] := $08;
347 <                Data[$89] := 32;
348 < {                  if data[$90]<>OniImage.StoreType then begin
349 <                    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;
340 >              RawLinks[i].RawAddr := Stream_Sep.Size;
341 >              Stream_sep.CopyFrom(RawFileStream, RawFileStream.Size);
342 >            end else begin
343 >              RawLinks[i].RawAddr := Stream_Raw.Size;
344 >              Stream_Raw.CopyFrom(RawFileStream, RawFileStream.Size);
345 >            end;
346 >          end else
347 >            RawLinks[i].RawAddr := 0;
348 >          DatFileStream.Seek(RawLinks[i].SrcOffset, soFromBeginning);
349 >          DatFileStream.Write(RawLinks[i].RawAddr, 4);
350          end;
351        end;
352 +      DatFileStream.Seek(0, soFromBeginning);
353 +      Stream_Body.CopyFrom(DatFileStream, DatFileStream.Size);
354  
355 <      Stream_Body.Write(Data[0], Length(Data));
356 <      //
355 >      QueryPerformanceCounter(tempticks2);
356 >      rawsum := rawsum + (tempticks2 - tempticks1);
357      end
358      else
359        FilesHeader[i].DataAddr := 0;
# Line 334 | Line 368 | begin
368      FilesHeader[i].FileSize := fileinfo.Size;
369      FilesHeader[i].FileType := fileinfo.FileType;
370  
371 <    if ((i mod 10) = 0) and (i >= 100) then
371 >    if ((FileID mod 10) = 0) and (FileID >= 100) then
372        lbl_estimation.Caption := 'Estimated time left: ' + TimeToStr(
373 <        (Time - begintime) / i * (progress.Max - i + 1) * 1.1, timeformat );
374 <    progress.Position := i + 1;
375 <    lbl_progress.Caption := 'Files done: ' + IntToStr(i + 1) + '/' + IntToStr(progress.Max);
373 >        (Time - FileTime) / FileID * (progress.Max - FileID + 1) * 1.1, TimeFormat );
374 >    progress.Position := FileID + 1;
375 >    lbl_progress.Caption := 'Files done: ' + IntToStr(FileID + 1) + '/' + IntToStr(progress.Max);
376      Application.ProcessMessages;
377    end;
378  
379 +  ShowMessage('AvgDats: ' + FloatToStr((datsum / progress.Max) / freq) + #13#10 +
380 +      'AvgLinks: ' + FloatToStr((linksum / progress.Max) / freq) + #13#10 +
381 +      'AvgRaws: ' + FloatToStr((rawsum / progress.Max) / freq)
382 +   );
383 +
384    Stream_Dat.Write(DatHeader, SizeOf(DatHeader));
385    for i := 0 to High(FilesHeader) do
386      Stream_Dat.Write(FilesHeader[i], SizeOf(FilesHeader[i]));
# Line 353 | Line 392 | begin
392    DatHeader.DataSize  := Stream_Body.Size;
393    DatHeader.NamesSize := Stream_Names.Size;
394    DatHeader.DataAddr  := Stream_Dat.Size;
395 +
396    Stream_Body.Seek(0, soFromBeginning);
397    Stream_Dat.CopyFrom(Stream_Body, Stream_Body.Size);
398    DatHeader.NamesAddr := Stream_Dat.Size;
# Line 366 | Line 406 | begin
406    Stream_Body.Free;
407    Stream_Names.Free;
408    Stream_Raw.Free;
409 <  if OniDataConnection.OSisMac then
409 >
410 >  if Connection.DataOS in [DOS_WINDEMO, DOS_MAC, DOS_MACBETA] then
411      Stream_Sep.Free;
412  
413    progress.Position      := progress.Max;
414    lbl_progress.Caption   := 'Files done: ' + IntToStr(progress.Max) + '/' +
415      IntToStr(progress.Max);
416 <  lbl_estimation.Caption := 'FINISHED (duration: ' + TimeToStr(Time - absolutebegintime, timeformat) + ')';
416 >  lbl_estimation.Caption := 'FINISHED (duration: ' + TimeToStr(Time - Begintime, TimeFormat) + ')';
417  
418    DoStep('FIN');
419    btn_abortok.Caption := '&OK';
# Line 382 | Line 423 | begin
423  
424    converting := False;
425  
426 <  CloseDataConnection(DataConnections[conIndex]);
426 > //  CloseDataConnection(DataConnections[conIndex]);
427   end;
428  
429  
# Line 392 | Line 433 | procedure TForm_LevelDB.HandleFile;
433   var
434    i: Byte;
435   begin
436 <  for i := 1 to Length(ConvertHandlers) do
436 > {  for i := 1 to Length(ConvertHandlers) do
437      if UpperCase(ConvertHandlers[i].Ext) = UpperCase(ext) then
438        if ConvertHandlers[i].needed then
439        begin
# Line 401 | Line 442 | begin
442        end
443        else
444          Break;
445 < end;
445 > }end;
446  
447  
448  
449  
450   procedure TForm_LevelDB.CreateDatabase(Source, target: String);
451 + {
452   var
453    DataBase:    TABSDatabase;
454    Query:       TABSQuery;
# Line 438 | Line 480 | const
480      else
481        group_progress.Caption := 'Creating DB (FINISHED)';
482    end;
483 + }
484  
485   begin
486 <  if CreateDataConnection(Source, ODB_Dat) = nil then
486 > {  if CreateDataConnection(Source, ODB_Dat) = nil then
487    begin
488      ShowMessage('Could not connect to .dat-file');
489      Exit;
# Line 643 | Line 686 | begin
686    database.Free;
687  
688    CloseDataConnection(DataConnections[conIndex]);
689 + }
690   end;
691  
692  
693  
694  
695 < procedure TForm_LevelDB.stop_convert;
695 > procedure TForm_LevelDB.StopConvert;
696   begin
697 <  btn_abortok.Caption := '&Close';
697 > {  btn_abortok.Caption := '&Close';
698    btn_abortok.Default := True;
699    converting := False;
700    lbl_estimation.Caption := 'ABORTED';
# Line 661 | Line 705 | begin
705    begin
706      DeleteFile(loaded_filename);
707    end;
708 < end;
708 > }end;
709  
710  
711  
# Line 684 | Line 728 | end;
728  
729  
730  
731 <
731 > {
732   procedure InsertDatLinkToDB(fileid: LongWord; offset: LongWord);
733   var
734    link: LongWord;
# Line 1716 | Line 1760 | begin
1760    begin
1761    end;
1762   end;
1763 + }
1764  
1765  
1766 <
1722 <
1766 > {
1767   procedure InsertHandler(ext: String; needed: Boolean; handler: THandler);
1768   begin
1769    SetLength(ConvertHandlers, Length(ConvertHandlers) + 1);
# Line 1727 | Line 1771 | begin
1771    ConvertHandlers[High(ConvertHandlers)].needed  := needed;
1772    ConvertHandlers[High(ConvertHandlers)].handler := handler;
1773   end;
1774 <
1774 > }
1775   begin
1776 <  InsertHandler('ABNA', False, nil);
1776 > {  InsertHandler('ABNA', False, nil);
1777    //  InsertHandler('AGDB',True,AGDB);
1778    InsertHandler('AGDB', False, nil);
1779    InsertHandler('AGQC', False, nil);
# Line 1827 | Line 1871 | begin
1871    InsertHandler('WMM_', False, nil);
1872    InsertHandler('WMMB', True, WMMB);
1873    InsertHandler('WPGE', True, WPGE);
1874 < end.
1874 > }end.

Diff Legend

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