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 130 by alloc, Wed Mar 28 01:17:24 2007 UTC

# Line 78 | Line 78 | var
78    Connection: TDataAccess;
79    ConRepMsg:  TStatusMessages;
80  
81 +  FileID:     Integer;
82 +
83    Strings:    TStrings;
84    i, j:       Integer;
85    temps:      String;
86 +  tempi:      Integer;
87 +  tempb:      Byte;
88    FileInfo:   TFileInfo;
89 +  DatLinks:   TDatLinkList;
90 +  RawLinks:   TRawDataList;
91  
92    DatFileStream, RawFileStream: TMemoryStream;
93   const
# Line 149 | Line 155 | begin
155        begin
156          ShowMessage('Couldn''t delete file. Aborting');
157          Exit;
158 <      end else if not DeleteFile(AnsiReplaceStr(Target, '.dat', '.sep')) then
158 >      end else if Connection.DataOS in [DOS_WINDEMO, DOS_MAC, DOS_MACBETA] then
159        begin
160 <        ShowMessage('Couldn''t delete file. Aborting');
161 <        Exit;
160 >        if not DeleteFile(AnsiReplaceStr(Target, '.dat', '.sep')) then
161 >        begin
162 >          ShowMessage('Couldn''t delete file. Aborting');
163 >          Exit;
164 >        end;
165        end;
166      end else begin
167        ShowMessage('Aborting');
# Line 270 | Line 279 | begin
279    Application.ProcessMessages;
280  
281    FileTime := Time;
282 <  for i := 0 to DatHeader.Files - 1 do
282 >  for FileID := 0 to DatHeader.Files - 1 do
283    begin
284 <    FileInfo := Connection.GetFileInfo(i);
284 >    FileInfo := Connection.GetFileInfo(FileID);
285      for j := 0 to 3 do
286 <      FilesHeader[i].Extension[j] := FileInfo.Extension[4 - j];
286 >      FilesHeader[FileID].Extension[j] := FileInfo.Extension[4 - j];
287      if FileInfo.Size > 0 then
288      begin
289 <      //        DatLinks:=;
281 <      FilesHeader[i].DataAddr := Stream_Body.Size + 8;
289 >      FilesHeader[FileID].DataAddr := Stream_Body.Size + 8;
290        DatFileStream := TMemoryStream.Create;
291 <      Connection.LoadDatFile(i, DatFileStream);
291 >      Connection.LoadDatFile(FileID, TStream(DatFileStream));
292        DatFileStream.Seek(4, soFromBeginning);
293        DatFileStream.Write(LevelID, 4);
294  
295 <      if (Pos(UpperCase(fileinfo.Extension), UpperCase(raws)) mod 4) = 1 then
295 >      DatLinks := Connection.GetDatLinks(FileID);
296 >      if Length(DatLinks) > 0 then
297 >      begin
298 >        for i := 0 to High(DatLinks) do
299 >        begin
300 >          DatFileStream.Seek(DatLinks[i].SrcOffset, soFromBeginning);
301 >          if DatLinks[i].DestID < 0 then
302 >            tempi := 0
303 >          else
304 >            tempi := DatLinks[i].DestID * 256 + 1;
305 >          DatFileStream.Write(tempi, 4);
306 >        end;
307 >      end;
308 >
309 >      RawLinks := Connection.GetRawList(FileID);
310 >      if Length(RawLinks) > 0 then
311        begin
312 <        rawlist := OniDataConnection.GetRawList(i);
290 <        if Length(rawlist) > 0 then
312 >        for i := 0 to High(RawLinks) do
313          begin
314 <          for j := 0 to High(rawlist) do
314 >          if RawLinks[i].RawSize > 0 then
315            begin
316 <            if rawlist[j].raw_size > 0 then
316 >            RawFileStream := TMemoryStream.Create;
317 >            Connection.LoadRawFile(FileID, RawLinks[i].SrcOffset, TStream(RawFileStream));
318 >            RawFileStream.Seek(0, soFromBeginning);
319 >            if RawLinks[i].LocSep then
320              begin
321 <              if (UpperCase(fileinfo.Extension) = 'TXMP') and
322 <                ((Data[$88] and $01) > 0) then
323 <              begin
324 <                OniImage.LoadFromTXMP(Connection, i);
325 <                OniImage.GetMipMappedImage(rawdata);
326 <                rawlist[j].raw_size := OniImage.GetImageDataSize(True);
327 <                Data[$90] := $08;
328 <                Data[$89] := 32;
329 < {                  if data[$90]<>OniImage.StoreType then begin
330 <                    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;
321 >              RawLinks[i].RawAddr := Stream_Sep.Size;
322 >              Stream_sep.CopyFrom(RawFileStream, RawFileStream.Size);
323 >            end else begin
324 >              RawLinks[i].RawAddr := Stream_Raw.Size;
325 >              Stream_Raw.CopyFrom(RawFileStream, RawFileStream.Size);
326 >            end;
327 >          end else
328 >            RawLinks[i].RawAddr := 0;
329 >          DatFileStream.Seek(RawLinks[i].SrcOffset, soFromBeginning);
330 >          DatFileStream.Write(RawLinks[i].RawAddr, 4);
331          end;
332        end;
333 <
334 <      Stream_Body.Write(Data[0], Length(Data));
338 <      //
333 >      DatFileStream.Seek(0, soFromBeginning);
334 >      Stream_Body.CopyFrom(DatFileStream, DatFileStream.Size);
335      end
336      else
337        FilesHeader[i].DataAddr := 0;
# Line 350 | Line 346 | begin
346      FilesHeader[i].FileSize := fileinfo.Size;
347      FilesHeader[i].FileType := fileinfo.FileType;
348  
349 <    if ((i mod 10) = 0) and (i >= 100) then
349 >    if ((FileID mod 10) = 0) and (FileID >= 100) then
350        lbl_estimation.Caption := 'Estimated time left: ' + TimeToStr(
351 <        (Time - FileTime) / i * (progress.Max - i + 1) * 1.1, TimeFormat );
352 <    progress.Position := i + 1;
353 <    lbl_progress.Caption := 'Files done: ' + IntToStr(i + 1) + '/' + IntToStr(progress.Max);
351 >        (Time - FileTime) / FileID * (progress.Max - FileID + 1) * 1.1, TimeFormat );
352 >    progress.Position := FileID + 1;
353 >    lbl_progress.Caption := 'Files done: ' + IntToStr(FileID + 1) + '/' + IntToStr(progress.Max);
354      Application.ProcessMessages;
355    end;
356  
# Line 382 | Line 378 | begin
378    Stream_Body.Free;
379    Stream_Names.Free;
380    Stream_Raw.Free;
381 <  if OniDataConnection.OSisMac then
381 >
382 >  if Connection.DataOS in [DOS_WINDEMO, DOS_MAC, DOS_MACBETA] then
383      Stream_Sep.Free;
384  
385    progress.Position      := progress.Max;
# Line 398 | Line 395 | begin
395  
396    converting := False;
397  
398 <  CloseDataConnection(DataConnections[conIndex]);
398 > //  CloseDataConnection(DataConnections[conIndex]);
399   end;
400  
401  
# Line 408 | Line 405 | procedure TForm_LevelDB.HandleFile;
405   var
406    i: Byte;
407   begin
408 <  for i := 1 to Length(ConvertHandlers) do
408 > {  for i := 1 to Length(ConvertHandlers) do
409      if UpperCase(ConvertHandlers[i].Ext) = UpperCase(ext) then
410        if ConvertHandlers[i].needed then
411        begin
# Line 417 | Line 414 | begin
414        end
415        else
416          Break;
417 < end;
417 > }end;
418  
419  
420  
421  
422   procedure TForm_LevelDB.CreateDatabase(Source, target: String);
423 + {
424   var
425    DataBase:    TABSDatabase;
426    Query:       TABSQuery;
# Line 454 | Line 452 | const
452      else
453        group_progress.Caption := 'Creating DB (FINISHED)';
454    end;
455 + }
456  
457   begin
458 <  if CreateDataConnection(Source, ODB_Dat) = nil then
458 > {  if CreateDataConnection(Source, ODB_Dat) = nil then
459    begin
460      ShowMessage('Could not connect to .dat-file');
461      Exit;
# Line 659 | Line 658 | begin
658    database.Free;
659  
660    CloseDataConnection(DataConnections[conIndex]);
661 + }
662   end;
663  
664  
665  
666  
667 < procedure TForm_LevelDB.stop_convert;
667 > procedure TForm_LevelDB.StopConvert;
668   begin
669 <  btn_abortok.Caption := '&Close';
669 > {  btn_abortok.Caption := '&Close';
670    btn_abortok.Default := True;
671    converting := False;
672    lbl_estimation.Caption := 'ABORTED';
# Line 677 | Line 677 | begin
677    begin
678      DeleteFile(loaded_filename);
679    end;
680 < end;
680 > }end;
681  
682  
683  
# Line 700 | Line 700 | end;
700  
701  
702  
703 <
703 > {
704   procedure InsertDatLinkToDB(fileid: LongWord; offset: LongWord);
705   var
706    link: LongWord;
# Line 1732 | Line 1732 | begin
1732    begin
1733    end;
1734   end;
1735 + }
1736  
1737  
1738 <
1738 <
1738 > {
1739   procedure InsertHandler(ext: String; needed: Boolean; handler: THandler);
1740   begin
1741    SetLength(ConvertHandlers, Length(ConvertHandlers) + 1);
# Line 1743 | Line 1743 | begin
1743    ConvertHandlers[High(ConvertHandlers)].needed  := needed;
1744    ConvertHandlers[High(ConvertHandlers)].handler := handler;
1745   end;
1746 <
1746 > }
1747   begin
1748 <  InsertHandler('ABNA', False, nil);
1748 > {  InsertHandler('ABNA', False, nil);
1749    //  InsertHandler('AGDB',True,AGDB);
1750    InsertHandler('AGDB', False, nil);
1751    InsertHandler('AGQC', False, nil);
# Line 1843 | Line 1843 | begin
1843    InsertHandler('WMM_', False, nil);
1844    InsertHandler('WMMB', True, WMMB);
1845    InsertHandler('WPGE', True, WPGE);
1846 < end.
1846 > }end.

Diff Legend

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