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 120 by alloc, Fri Mar 23 00:59:01 2007 UTC vs.
Revision 134 by alloc, Wed Mar 28 17:53:54 2007 UTC

# Line 1 | Line 1
1 {$A8,B-,C+,D+,E-,F-,G+,H+,I+,J-,K-,L+,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y+,Z1}
2 {$MINSTACKSIZE $00004000}
3 {$MAXSTACKSIZE $00100000}
4 {$IMAGEBASE $00400000}
5 {$APPTYPE GUI}
6 {$WARN SYMBOL_DEPRECATED ON}
7 {$WARN SYMBOL_LIBRARY ON}
8 {$WARN SYMBOL_PLATFORM ON}
9 {$WARN SYMBOL_EXPERIMENTAL ON}
10 {$WARN UNIT_LIBRARY ON}
11 {$WARN UNIT_PLATFORM ON}
12 {$WARN UNIT_DEPRECATED ON}
13 {$WARN UNIT_EXPERIMENTAL ON}
14 {$WARN HRESULT_COMPAT ON}
15 {$WARN HIDING_MEMBER ON}
16 {$WARN HIDDEN_VIRTUAL ON}
17 {$WARN GARBAGE ON}
18 {$WARN BOUNDS_ERROR ON}
19 {$WARN ZERO_NIL_COMPAT ON}
20 {$WARN STRING_CONST_TRUNCED ON}
21 {$WARN FOR_LOOP_VAR_VARPAR ON}
22 {$WARN TYPED_CONST_VARPAR ON}
23 {$WARN ASG_TO_TYPED_CONST ON}
24 {$WARN CASE_LABEL_RANGE ON}
25 {$WARN FOR_VARIABLE ON}
26 {$WARN CONSTRUCTING_ABSTRACT ON}
27 {$WARN COMPARISON_FALSE ON}
28 {$WARN COMPARISON_TRUE ON}
29 {$WARN COMPARING_SIGNED_UNSIGNED ON}
30 {$WARN COMBINING_SIGNED_UNSIGNED ON}
31 {$WARN UNSUPPORTED_CONSTRUCT ON}
32 {$WARN FILE_OPEN ON}
33 {$WARN FILE_OPEN_UNITSRC ON}
34 {$WARN BAD_GLOBAL_SYMBOL ON}
35 {$WARN DUPLICATE_CTOR_DTOR ON}
36 {$WARN INVALID_DIRECTIVE ON}
37 {$WARN PACKAGE_NO_LINK ON}
38 {$WARN PACKAGED_THREADVAR ON}
39 {$WARN IMPLICIT_IMPORT ON}
40 {$WARN HPPEMIT_IGNORED ON}
41 {$WARN NO_RETVAL ON}
42 {$WARN USE_BEFORE_DEF ON}
43 {$WARN FOR_LOOP_VAR_UNDEF ON}
44 {$WARN UNIT_NAME_MISMATCH ON}
45 {$WARN NO_CFG_FILE_FOUND ON}
46 {$WARN IMPLICIT_VARIANTS ON}
47 {$WARN UNICODE_TO_LOCALE ON}
48 {$WARN LOCALE_TO_UNICODE ON}
49 {$WARN IMAGEBASE_MULTIPLE ON}
50 {$WARN SUSPICIOUS_TYPECAST ON}
51 {$WARN PRIVATE_PROPACCESSOR ON}
52 {$WARN UNSAFE_TYPE OFF}
53 {$WARN UNSAFE_CODE OFF}
54 {$WARN UNSAFE_CAST OFF}
55 {$WARN OPTION_TRUNCATED ON}
56 {$WARN WIDECHAR_REDUCED ON}
57 {$WARN DUPLICATES_IGNORED ON}
58 {$WARN UNIT_INIT_SEQ ON}
59 {$WARN LOCAL_PINVOKE ON}
60 {$WARN MESSAGE_DIRECTIVE ON}
1   unit LevelDB;
2   interface
3   uses
# Line 125 | Line 65 | var
65    Stream_Body, Stream_Names:          TMemoryStream;
66    Stream_Dat, Stream_Raw, Stream_Sep: TFileStream;
67  
128 //  Data, rawdata: Tdata;
68    BeginTime, FileTime: Double;
69    Step:     Integer;
131 //  rawlist:  TRawDataList;
132 //  datlinks: TDatLinks;
70    OniImage:   TOniImage;
71    LevelID:    Integer;
72    TimeFormat: TFormatSettings;
# Line 150 | 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 211 | Line 154 | begin
154        begin
155          ShowMessage('Couldn''t delete file. Aborting');
156          Exit;
214      end else if not DeleteFile(AnsiReplaceStr(Target, '.dat', '.raw')) then
215      begin
216        ShowMessage('Couldn''t delete file. Aborting');
217        Exit;
218      end else if not DeleteFile(AnsiReplaceStr(Target, '.dat', '.sep')) then
219      begin
220        ShowMessage('Couldn''t delete file. Aborting');
221        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 335 | 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 343 | 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 >      DatFileStream.Write(FileID, 4);
306        DatFileStream.Write(LevelID, 4);
307  
308 +      QueryPerformanceCounter(tempticks2);
309 +      datsum := datsum + (tempticks2 - tempticks1);
310 +
311        DatLinks := Connection.GetDatLinks(FileID);
312        if Length(DatLinks) > 0 then
313        begin
# Line 363 | Line 322 | begin
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
# Line 371 | Line 333 | begin
333            if RawLinks[i].RawSize > 0 then
334            begin
335              RawFileStream := TMemoryStream.Create;
336 <            if UpperCase(fileinfo.Extension) = 'TXMP' then
336 >            Connection.LoadRawFile(FileID, RawLinks[i].SrcOffset, TStream(RawFileStream));
337 >            RawFileStream.Seek(0, soFromBeginning);
338 >            if RawLinks[i].LocSep then
339              begin
340 <              DatFileStream.Seek($88, soFromBeginning);
341 <              DatFileStream.Read(tempb, 1);
378 <              if (tempb and $01) > 0 then
379 <              begin
380 <                OniImage.Load(Connection.ConnectionID, FileID);
381 <                if not OniImage.GetMipMappedImage(TStream(RawFileStream)) then
382 <                begin
383 <                  ShowMessage('MipMapping-Error');
384 <                  RawFileStream.Seek(0, soFromBeginning);
385 <                  tempb := tempb and $FE;
386 <                  DatFileStream.Seek($88, soFromBeginning);
387 <                  DatFileStream.Write(tempb, 1);
388 <                  OniImage.Load(Connection.ConnectionID, FileID);
389 <                  OniImage.GetAsData(TStream(RawFileStream));
390 <                end else
391 <                begin
392 <                  // Change of Depth($89), Storetype ($90)
393 <                  DatFileStream.Seek($89, soFromBeginning);
394 <                  DatFileStream.Read(tempb, 1);
395 <
396 <                  DatFileStream.Seek($90, soFromBeginning);
397 <                  DatFileStream.Read(tempb, 1);
398 <                  Exit;
399 <                end;
400 <              end else
401 <                OniImage.GetAsData(TStream(RawFileStream));
340 >              RawLinks[i].RawAddr := Stream_Sep.Size;
341 >              Stream_sep.CopyFrom(RawFileStream, RawFileStream.Size);
342              end else begin
343 <              Connection.LoadRawFile(FileID, RawLinks[i].SrcOffset, TStream(RawFileStream));
343 >              RawLinks[i].RawAddr := Stream_Raw.Size;
344 >              Stream_Raw.CopyFrom(RawFileStream, RawFileStream.Size);
345              end;
405            RawFileStream.Seek(0, soFromBeginning);
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 < {
356 <            if rawlist[j].raw_size > 0 then
413 <            begin
414 <              if (UpperCase(fileinfo.Extension) = 'TXMP') and
415 <                ((Data[$88] and $01) > 0) then
416 <              begin
417 <                OniImage.LoadFromTXMP(Connection, i);
418 <                OniImage.GetMipMappedImage(rawdata);
419 <                rawlist[j].raw_size := OniImage.GetImageDataSize(True);
420 <                Data[$90] := $08;
421 <                Data[$89] := 32;
422 < (*                  if data[$90]<>OniImage.StoreType then begin
423 <                    data[$90]:=OniImage.StoreType;
424 <                    data[$89]:=(data[$89] and $CF) or $20;
425 <                  end;
426 < *)                end
427 <              else
428 <              begin
429 <                SetLength(rawdata, rawlist[j].raw_size);
430 <                OniDataConnection.LoadRawFile(i, rawlist[j].src_offset, @rawdata[0]);
431 <              end;
432 <              //                data[$88]:=data[$88] and $FE;
433 <
434 <              if rawlist[j].loc_sep then
435 <              begin
436 <                rawlist[j].raw_addr := Stream_Sep.Size;
437 <                Stream_Sep.Write(rawdata[0], Length(rawdata));
438 <              end
439 <              else
440 <              begin
441 <                rawlist[j].raw_addr := Stream_Raw.Size;
442 <                Stream_Raw.Write(rawdata[0], Length(rawdata));
443 <              end;
444 <            end
445 <            else
446 <              rawlist[j].raw_addr := 0;
447 <            Data[rawlist[j].src_offset + 0] := (rawlist[j].raw_addr) and $FF;
448 <            Data[rawlist[j].src_offset + 1] := (rawlist[j].raw_addr shr 8) and $FF;
449 <            Data[rawlist[j].src_offset + 2] := (rawlist[j].raw_addr shr 16) and $FF;
450 <            Data[rawlist[j].src_offset + 3] := (rawlist[j].raw_addr shr 24) and $FF;
451 < }
452 <      Stream_Body.Write(Data[0], Length(Data));
453 <      //
355 >      QueryPerformanceCounter(tempticks2);
356 >      rawsum := rawsum + (tempticks2 - tempticks1);
357      end
358      else
359 <      FilesHeader[i].DataAddr := 0;
359 >      FilesHeader[FileID].DataAddr := 0;
360      if Length(fileinfo.Name) > 0 then
361      begin
362 <      FilesHeader[i].NameAddr := Stream_Names.Size;
362 >      FilesHeader[FileID].NameAddr := Stream_Names.Size;
363        temps := fileinfo.Extension + fileinfo.Name + Chr(0);
364        Stream_Names.Write(temps[1], Length(temps));
365      end
366      else
367 <      FilesHeader[i].NameAddr := 0;
368 <    FilesHeader[i].FileSize := fileinfo.Size;
369 <    FilesHeader[i].FileType := fileinfo.FileType;
367 >      FilesHeader[FileID].NameAddr := 0;
368 >    FilesHeader[FileID].FileSize := fileinfo.Size;
369 >    FilesHeader[FileID].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 - FileTime) / 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 484 | 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 497 | 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;
# Line 513 | Line 423 | begin
423  
424    converting := False;
425  
426 <  CloseDataConnection(DataConnections[conIndex]);
426 > //  CloseDataConnection(DataConnections[conIndex]);
427   end;
428  
429  
# Line 523 | 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 532 | 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   var
452 +  DataBase:  TABSDatabase;
453 + {
454 + var
455    DataBase:    TABSDatabase;
456    Query:       TABSQuery;
457    MimeCoder:   TStringFormat_MIME64;
# Line 569 | Line 482 | const
482      else
483        group_progress.Caption := 'Creating DB (FINISHED)';
484    end;
485 + }
486  
487   begin
488 <  if CreateDataConnection(Source, ODB_Dat) = nil then
488 > {  if CreateDataConnection(Source, ODB_Dat) = nil then
489    begin
490      ShowMessage('Could not connect to .dat-file');
491      Exit;
# Line 597 | Line 511 | begin
511    absolutebegintime := Time;
512  
513    DataBase := TABSDatabase.Create(Self);
514 + }
515 +  DataBase.MaxConnections := 1;
516 + {
517    DataBase.DatabaseName := 'OLDB';
518    DataBase.DatabaseFileName := target;
519    DataBase.CreateDatabase;
# Line 774 | Line 691 | begin
691    database.Free;
692  
693    CloseDataConnection(DataConnections[conIndex]);
694 + }
695   end;
696  
697  
698  
699  
700 < procedure TForm_LevelDB.stop_convert;
700 > procedure TForm_LevelDB.StopConvert;
701   begin
702 <  btn_abortok.Caption := '&Close';
702 > {  btn_abortok.Caption := '&Close';
703    btn_abortok.Default := True;
704    converting := False;
705    lbl_estimation.Caption := 'ABORTED';
# Line 792 | Line 710 | begin
710    begin
711      DeleteFile(loaded_filename);
712    end;
713 < end;
713 > }end;
714  
715  
716  
# Line 815 | Line 733 | end;
733  
734  
735  
736 <
736 > {
737   procedure InsertDatLinkToDB(fileid: LongWord; offset: LongWord);
738   var
739    link: LongWord;
# Line 1847 | Line 1765 | begin
1765    begin
1766    end;
1767   end;
1768 + }
1769  
1770  
1771 <
1853 <
1771 > {
1772   procedure InsertHandler(ext: String; needed: Boolean; handler: THandler);
1773   begin
1774    SetLength(ConvertHandlers, Length(ConvertHandlers) + 1);
# Line 1858 | Line 1776 | begin
1776    ConvertHandlers[High(ConvertHandlers)].needed  := needed;
1777    ConvertHandlers[High(ConvertHandlers)].handler := handler;
1778   end;
1779 <
1779 > }
1780   begin
1781 <  InsertHandler('ABNA', False, nil);
1781 > {  InsertHandler('ABNA', False, nil);
1782    //  InsertHandler('AGDB',True,AGDB);
1783    InsertHandler('AGDB', False, nil);
1784    InsertHandler('AGQC', False, nil);
# Line 1958 | Line 1876 | begin
1876    InsertHandler('WMM_', False, nil);
1877    InsertHandler('WMMB', True, WMMB);
1878    InsertHandler('WPGE', True, WPGE);
1879 < end.
1879 > }end.

Diff Legend

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