Ignore:
Timestamp:
Jun 12, 2007, 6:42:53 PM (18 years ago)
Author:
alloc
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • oup/current/FileClasses/_FileTypes.pas

    r210 r212  
    1717      FFileStream: TMemoryStream;
    1818
     19      FCached: Boolean;
     20      FChanged: Boolean;
     21
    1922      FDatLinks: TDatLinkList;
    2023      FDataFields: TBlock;
     
    3134      function GetRawPartByOffset(Offset: Integer): TRawDataInfo;
    3235      function GetRawPartByIndex(ID: Integer): TRawDataInfo;
     36      function GetChildCount: Integer;
    3337    public
    3438      constructor Create(ConnectionID, FileID: Integer); virtual;
     
    4246      property ConnectionID: Integer read FConnectionID;
    4347
     48      property Cached: Boolean read FCached;
     49      property Changed: Boolean read FChanged write FChanged;
     50
     51      property ChildCount: Integer read GetChildCount;
    4452      property LinkByOffset[Offset: Integer]: TDatLink read GetDatLinkByOffset;
    4553      property LinkByIndex[ID: Integer]: TDatLink read GetDatLinkByIndex;
     
    6371
    6472uses
    65   DatLinks, RawList, ConnectionManager, Dialogs;
     73  DatLinks, RawList, ConnectionManager, Dialogs, _EmptyFile;
    6674
    6775{ TFileType }
     
    7987  FFileSize := fileinfo.Size;
    8088
    81   FFileStream := TMemoryStream.Create;
    82   ConManager.Connection[ConnectionID].LoadDatFile(FileID, TStream(FFileStream));
     89  FCached := False;
     90  FChanged := False;
     91
     92  if not (Self is TFile_Empty) then
     93  begin
     94    FFileStream := TMemoryStream.Create;
     95    ConManager.Connection[ConnectionID].LoadDatFile(FileID, TStream(FFileStream));
     96  end;
    8397
    8498  InitDatLinks();
     
    86100  InitRawList();
    87101
    88   FFileStream.Free;
     102  if not (Self is TFile_Empty) then
     103    FFileStream.Free;
    89104  FFileStream := nil;
    90105end;
     
    97112
    98113function TFile.GetDatLinkByIndex(ID: Integer): TDatLink;
    99 begin
    100   if ID < Length(FDatLinks) then
    101     Result := FDatLinks[ID]
     114var
     115  i: Integer;
     116  valids: Integer;
     117begin
     118  if ID < GetChildCount then
     119  begin
     120    valids := 0;
     121    i := 0;
     122    repeat
     123      if FDatLinks[i].DestID >= 0 then
     124      begin
     125        Inc(valids);
     126      end;
     127      Inc(i);
     128    until valids > ID;
     129    Result := FDatLinks[i - 1];
     130  end
    102131  else
    103132    with Result do
     
    140169end;
    141170
     171
     172function TFile.GetChildCount: Integer;
     173var
     174  i: Integer;
     175begin
     176  Result := Length(FDatLinks);
     177  if Result > 0 then
     178  begin
     179    Result := 0;
     180    for i := 0 to High(FDatLinks) do
     181      if FDatLinks[i].DestID >= 0 then
     182        Inc(Result);
     183  end;
     184end;
    142185
    143186function TFile.GetRawPartByIndex(ID: Integer): TRawDataInfo;
Note: See TracChangeset for help on using the changeset viewer.