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 127 by alloc, Fri Mar 23 17:14:40 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;
68   //  Data, rawdata: Tdata;
69    BeginTime, FileTime: Double;
70    Step:     Integer;
71   //  rawlist:  TRawDataList;
78 //  extlist:  TExtensionsMap;
79 //  fileinfo: TFileInfo;
72   //  datlinks: TDatLinks;
73    OniImage:   TOniImage;
74    LevelID:    Integer;
# Line 86 | 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
94    Steps: Byte = 3;
95  
# Line 208 | Line 210 | begin
210      end;
211    end;
212  
213 <  
214 <  extlist := OniDataConnection.GetExtendedExtensionsList;
215 <  for i := 0 to High(DatHeader.Ident) do
216 <    DatHeader.Ident[i] := OniDataConnection.LevelInfo.Ident[i];
217 <  DatHeader.Files := OniDataConnection.GetFilesCount;
213 >  for i := 0 to High(DatHeader.OSIdent) do
214 >    case Connection.DataOS of
215 >      DOS_WIN: DatHeader.OSIdent[i] := HeaderOSIdentWin[i];
216 >      DOS_MAC: DatHeader.OSIdent[i] := HeaderOSIdentMac[i];
217 >      DOS_MACBETA: DatHeader.OSIdent[i] := HeaderOSIdentMacBeta[i];
218 >    end;
219 >  for i := 0 to High(DatHeader.GlobalIdent) do
220 >    DatHeader.GlobalIdent[i] := HeaderGlobalIdent[i];
221 >  DatHeader.Files := Connection.GetFileCount;
222    DatHeader.NamedFiles := Length(NamedFilesHeader);
223 <  DatHeader.Extensions := Length(extlist);
223 >
224 >  Strings := Connection.GetExtensionsList(EF_ExtCount);
225 >
226 >  DatHeader.Extensions := Strings.Count;
227    DatHeader.DataAddr   := 0;
228    DatHeader.DataSize   := 0;
229    DatHeader.NamesAddr  := 0;
# Line 226 | Line 235 | begin
235  
236  
237    DoStep('Writing extensions-header');
238 <  progress.Max := Length(OniDataConnection.GetExtensionsList);
238 >  progress.Max := Strings.Count;
239    Application.ProcessMessages;
240 <
232 <  for i := 0 to High(ExtensionsHeader) do
240 >  for i := 0 to Strings.Count - 1 do
241    begin
242 <    ExtensionsHeader[i].Ident     := extlist[i].Ident;
243 <    ExtensionsHeader[i].Extension := extlist[i].Extension;
244 <    SetLength(temps, 4);
242 >    temps := Strings.Strings[i];
243 >    ExtensionsHeader[i].ExtCount := StrToInt( MidStr(
244 >            temps,
245 >            Pos('(', temps) + 1,
246 >            Pos(')', temps) - Pos('(', temps) - 1 ) );
247 >    temps := MidStr(temps, 1, 4);
248      for j := 0 to 3 do
249 <      temps[j + 1] := ExtensionsHeader[i].Extension[3 - j];
250 <    ExtensionsHeader[i].ExtCount :=
251 <      Length(OniDataConnection.GetFilesList(temps, '', False, stIDAsc));
249 >      ExtensionsHeader[i].Extension[j] := temps[4-j];
250 >    for j := 0 to High(FileTypes) do
251 >      if FileTypes[j].Extension = temps then
252 >        Break;
253 >    if j < Length(FileTypes) then
254 >    begin
255 >      case Connection.DataOS of
256 >        DOS_WIN:     ExtensionsHeader[i].Ident := FileTypes[j].IdentWin;
257 >        DOS_WINDEMO: ExtensionsHeader[i].Ident := FileTypes[j].IdentMac;
258 >        DOS_MAC:     ExtensionsHeader[i].Ident := FileTypes[j].IdentMac;
259 >        DOS_MACBETA: ExtensionsHeader[i].Ident := FileTypes[j].IdentMac;
260 >      end;
261 >    end else begin
262 >      ShowMessage('Unknown Extension: ' + Strings.Strings[i]);
263 >      Exit;
264 >    end;
265      progress.Position    := i + 1;
266      lbl_progress.Caption := 'Extensions done: ' + IntToStr(i + 1) + '/' +
267 <      IntToStr(Length(extlist));
267 >      IntToStr(Strings.Count);
268      Application.ProcessMessages;
269    end;
270  
247
271    DoStep('Storing files-data');
272    progress.Position := 0;
273    progress.Max      := DatHeader.Files;
# Line 252 | Line 275 | begin
275    lbl_estimation.Caption := 'Estimated finishing time: unknown';
276    Application.ProcessMessages;
277  
278 <  begintime := Time;
279 <  for i := 0 to DatHeader.Files - 1 do
278 >  FileTime := Time;
279 >  for FileID := 0 to DatHeader.Files - 1 do
280    begin
281 <    fileinfo := OniDataConnection.GetFileInfo(i);
281 >    FileInfo := Connection.GetFileInfo(FileID);
282      for j := 0 to 3 do
283 <      FilesHeader[i].Extension[j] := fileinfo.Extension[4 - j];
284 <    if fileinfo.Size > 0 then
283 >      FilesHeader[FileID].Extension[j] := FileInfo.Extension[4 - j];
284 >    if FileInfo.Size > 0 then
285      begin
286 <      //        DatLinks:=;
287 <      FilesHeader[i].DataAddr := Stream_Body.Size + 8;
288 <      Data    := OniDataConnection.LoadDatFile(i);
289 <      Data[4] := (levelid) and $FF;
290 <      Data[5] := (levelid shr 8) and $FF;
291 <      Data[6] := (levelid shr 16) and $FF;
292 <      Data[7] := (levelid shr 24) and $FF;
286 >      FilesHeader[FileID].DataAddr := Stream_Body.Size + 8;
287 >      DatFileStream := TMemoryStream.Create;
288 >      Connection.LoadDatFile(FileID, TStream(DatFileStream));
289 >      DatFileStream.Seek(4, soFromBeginning);
290 >      DatFileStream.Write(LevelID, 4);
291 >
292 >      DatLinks := Connection.GetDatLinks(FileID);
293 >      if Length(DatLinks) > 0 then
294 >      begin
295 >        for i := 0 to High(DatLinks) do
296 >        begin
297 >          DatFileStream.Seek(DatLinks[i].SrcOffset, soFromBeginning);
298 >          if DatLinks[i].DestID < 0 then
299 >            tempi := 0
300 >          else
301 >            tempi := DatLinks[i].DestID * 256 + 1;
302 >          DatFileStream.Write(tempi, 4);
303 >        end;
304 >      end;
305  
306 <      if (Pos(UpperCase(fileinfo.Extension), UpperCase(raws)) mod 4) = 1 then
306 >      RawLinks := Connection.GetRawList(FileID);
307 >      if Length(RawLinks) > 0 then
308        begin
309 <        rawlist := OniDataConnection.GetRawList(i);
274 <        if Length(rawlist) > 0 then
309 >        for i := 0 to High(RawLinks) do
310          begin
311 <          for j := 0 to High(rawlist) do
311 >          if RawLinks[i].RawSize > 0 then
312            begin
313 <            if rawlist[j].raw_size > 0 then
313 >            RawFileStream := TMemoryStream.Create;
314 >            Connection.LoadRawFile(FileID, RawLinks[i].SrcOffset, TStream(RawFileStream));
315 >            RawFileStream.Seek(0, soFromBeginning);
316 >            if RawLinks[i].LocSep then
317              begin
318 <              if (UpperCase(fileinfo.Extension) = 'TXMP') and
319 <                ((Data[$88] and $01) > 0) then
320 <              begin
321 <                OniImage.LoadFromTXMP(Connection, i);
322 <                OniImage.GetMipMappedImage(rawdata);
323 <                rawlist[j].raw_size := OniImage.GetImageDataSize(True);
324 <                Data[$90] := $08;
325 <                Data[$89] := 32;
326 < {                  if data[$90]<>OniImage.StoreType then begin
327 <                    data[$90]:=OniImage.StoreType;
328 <                    data[$89]:=(data[$89] and $CF) or $20;
329 <                  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;
318 >              RawLinks[i].RawAddr := Stream_Sep.Size;
319 >              Stream_sep.CopyFrom(RawFileStream, RawFileStream.Size);
320 >            end else begin
321 >              RawLinks[i].RawAddr := Stream_Raw.Size;
322 >              Stream_Raw.CopyFrom(RawFileStream, RawFileStream.Size);
323 >            end;
324 >          end else
325 >            RawLinks[i].RawAddr := 0;
326 >        end;
327 >      end;
328 >
329 > {
330              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 <          end;
318 <        end;
319 <      end;
320 <
334 > }
335        Stream_Body.Write(Data[0], Length(Data));
336        //
337      end
# Line 336 | Line 350 | begin
350  
351      if ((i mod 10) = 0) and (i >= 100) then
352        lbl_estimation.Caption := 'Estimated time left: ' + TimeToStr(
353 <        (Time - begintime) / i * (progress.Max - i + 1) * 1.1, timeformat );
353 >        (Time - FileTime) / i * (progress.Max - i + 1) * 1.1, TimeFormat );
354      progress.Position := i + 1;
355      lbl_progress.Caption := 'Files done: ' + IntToStr(i + 1) + '/' + IntToStr(progress.Max);
356      Application.ProcessMessages;
# Line 372 | Line 386 | begin
386    progress.Position      := progress.Max;
387    lbl_progress.Caption   := 'Files done: ' + IntToStr(progress.Max) + '/' +
388      IntToStr(progress.Max);
389 <  lbl_estimation.Caption := 'FINISHED (duration: ' + TimeToStr(Time - absolutebegintime, timeformat) + ')';
389 >  lbl_estimation.Caption := 'FINISHED (duration: ' + TimeToStr(Time - Begintime, TimeFormat) + ')';
390  
391    DoStep('FIN');
392    btn_abortok.Caption := '&OK';

Diff Legend

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