| 1 | unit _FileTypes;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | TypeDefs, _DataTypes, Classes, Forms;
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 | type
|
|---|
| 10 | TFile = class
|
|---|
| 11 | protected
|
|---|
| 12 | FConnectionID: Integer;
|
|---|
| 13 | FFileInfo: TFileInfo;
|
|---|
| 14 | FFileStream: TMemoryStream;
|
|---|
| 15 |
|
|---|
| 16 | FCached: Boolean;
|
|---|
| 17 | FChanged: Boolean;
|
|---|
| 18 |
|
|---|
| 19 | FDatLinks: TDatLinkList;
|
|---|
| 20 | FDataFields: TBlock;
|
|---|
| 21 | FRawParts: TRawDataList;
|
|---|
| 22 |
|
|---|
| 23 | FEditor: TFrame;
|
|---|
| 24 | FOpened: Boolean;
|
|---|
| 25 |
|
|---|
| 26 | procedure InitDatLinks;
|
|---|
| 27 | procedure InitRawList;
|
|---|
| 28 |
|
|---|
| 29 | function GetDatLinkByOffset(Offset: Integer): TDatLink;
|
|---|
| 30 | function GetDatLinkByIndex(ID: Integer): TDatLink;
|
|---|
| 31 | function GetFieldByOffset(Offset: Integer): TDataField;
|
|---|
| 32 | function GetFieldByIndex(ID: Integer): TDataField;
|
|---|
| 33 | function GetRawPartByOffset(Offset: Integer): TRawDataInfo;
|
|---|
| 34 | function GetRawPartByIndex(ID: Integer): TRawDataInfo;
|
|---|
| 35 | function GetChildCount: Integer;
|
|---|
| 36 | public
|
|---|
| 37 | constructor Create(ConnectionID, FileID: Integer); virtual;
|
|---|
| 38 | procedure Free;
|
|---|
| 39 |
|
|---|
| 40 | procedure InitDataFields; virtual;
|
|---|
| 41 | procedure InitEditor; virtual;
|
|---|
| 42 |
|
|---|
| 43 | property FileStream: TMemoryStream read FFileStream;
|
|---|
| 44 | property FileInfo: TFileInfo read FFileInfo;
|
|---|
| 45 | property ConnectionID: Integer read FConnectionID;
|
|---|
| 46 |
|
|---|
| 47 | property Cached: Boolean read FCached;
|
|---|
| 48 | property Changed: Boolean read FChanged write FChanged;
|
|---|
| 49 |
|
|---|
| 50 | property Editor: TFrame read FEditor;
|
|---|
| 51 | property Opened: Boolean read FOpened write FOpened;
|
|---|
| 52 |
|
|---|
| 53 | property ChildCount: Integer read GetChildCount;
|
|---|
| 54 | property LinkByOffset[Offset: Integer]: TDatLink read GetDatLinkByOffset;
|
|---|
| 55 | property LinkByIndex[ID: Integer]: TDatLink read GetDatLinkByIndex;
|
|---|
| 56 |
|
|---|
| 57 | property FieldByOffset[Offset: Integer]: TDataField read GetFieldByOffset;
|
|---|
| 58 | property FieldByIndex[ID: Integer]: TDataField read GetFieldByIndex;
|
|---|
| 59 |
|
|---|
| 60 | property RawPartByOffset[Offset: Integer]: TRawDataInfo read GetRawPartByOffset;
|
|---|
| 61 | property RawPartByIndex[ID: Integer]: TRawDataInfo read GetRawPartByIndex;
|
|---|
| 62 | end;
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 | TFileType = class of TFile;
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 | function GetDatLinkValue(stream: TStream; offset: Integer): Integer;
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 | implementation
|
|---|
| 73 |
|
|---|
| 74 | uses
|
|---|
| 75 | DatLinks, RawList, ConnectionManager, Dialogs, _EmptyFile;
|
|---|
| 76 |
|
|---|
| 77 | { TFileType }
|
|---|
| 78 |
|
|---|
| 79 | constructor TFile.Create(ConnectionID, FileID: Integer);
|
|---|
| 80 | begin
|
|---|
| 81 | FConnectionID := ConnectionID;
|
|---|
| 82 | FFileInfo := ConManager.Connection[ConnectionID].GetFileInfo(FileID);
|
|---|
| 83 |
|
|---|
| 84 | FCached := False;
|
|---|
| 85 | FChanged := False;
|
|---|
| 86 |
|
|---|
| 87 | if not (Self is TFile_Empty) then
|
|---|
| 88 | begin
|
|---|
| 89 | InitDatLinks();
|
|---|
| 90 | InitRawList();
|
|---|
| 91 | FDataFields := nil;
|
|---|
| 92 | FEditor := nil;
|
|---|
| 93 | end
|
|---|
| 94 | else
|
|---|
| 95 | begin
|
|---|
| 96 | SetLength(FDatLinks, 0);
|
|---|
| 97 | SetLength(FRawParts, 0);
|
|---|
| 98 | FEditor := nil;
|
|---|
| 99 | end;
|
|---|
| 100 | end;
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 | procedure TFile.Free;
|
|---|
| 104 | begin
|
|---|
| 105 | FDataFields.Free;
|
|---|
| 106 | end;
|
|---|
| 107 |
|
|---|
| 108 | function TFile.GetDatLinkByIndex(ID: Integer): TDatLink;
|
|---|
| 109 | var
|
|---|
| 110 | i: Integer;
|
|---|
| 111 | valids: Integer;
|
|---|
| 112 | begin
|
|---|
| 113 | if ID < GetChildCount then
|
|---|
| 114 | begin
|
|---|
| 115 | valids := 0;
|
|---|
| 116 | i := 0;
|
|---|
| 117 | repeat
|
|---|
| 118 | if FDatLinks[i].DestID >= 0 then
|
|---|
| 119 | begin
|
|---|
| 120 | Inc(valids);
|
|---|
| 121 | end;
|
|---|
| 122 | Inc(i);
|
|---|
| 123 | until valids > ID;
|
|---|
| 124 | Result := FDatLinks[i - 1];
|
|---|
| 125 | end
|
|---|
| 126 | else
|
|---|
| 127 | with Result do
|
|---|
| 128 | begin
|
|---|
| 129 | SrcOffset := -1;
|
|---|
| 130 | DestID := -1;
|
|---|
| 131 | PosDestExts := '';
|
|---|
| 132 | end;
|
|---|
| 133 | end;
|
|---|
| 134 |
|
|---|
| 135 | function TFile.GetDatLinkByOffset(Offset: Integer): TDatLink;
|
|---|
| 136 | var
|
|---|
| 137 | i: Integer;
|
|---|
| 138 | begin
|
|---|
| 139 | Result.SrcOffset := -1;
|
|---|
| 140 | Result.DestID := -1;
|
|---|
| 141 | Result.PosDestExts := '';
|
|---|
| 142 |
|
|---|
| 143 | if Length(FDatLinks) > 0 then
|
|---|
| 144 | begin
|
|---|
| 145 | for i := 0 to High(FDatLinks) do
|
|---|
| 146 | if FDatLinks[i].SrcOffset = Offset then
|
|---|
| 147 | break;
|
|---|
| 148 | if i < Length(FDatLinks) then
|
|---|
| 149 | Result := FDatLinks[i];
|
|---|
| 150 | end;
|
|---|
| 151 | end;
|
|---|
| 152 |
|
|---|
| 153 |
|
|---|
| 154 | function TFile.GetFieldByIndex(ID: Integer): TDataField;
|
|---|
| 155 | begin
|
|---|
| 156 | Result := FDataFields.FieldByIndex[ID];
|
|---|
| 157 | end;
|
|---|
| 158 |
|
|---|
| 159 | function TFile.GetFieldByOffset(Offset: Integer): TDataField;
|
|---|
| 160 | begin
|
|---|
| 161 | Result := FDataFields.FieldByOffset[Offset];
|
|---|
| 162 | end;
|
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 | function TFile.GetChildCount: Integer;
|
|---|
| 166 | var
|
|---|
| 167 | i: Integer;
|
|---|
| 168 | begin
|
|---|
| 169 | Result := Length(FDatLinks);
|
|---|
| 170 | if Result > 0 then
|
|---|
| 171 | begin
|
|---|
| 172 | Result := 0;
|
|---|
| 173 | for i := 0 to High(FDatLinks) do
|
|---|
| 174 | if FDatLinks[i].DestID >= 0 then
|
|---|
| 175 | Inc(Result);
|
|---|
| 176 | end;
|
|---|
| 177 | end;
|
|---|
| 178 |
|
|---|
| 179 | function TFile.GetRawPartByIndex(ID: Integer): TRawDataInfo;
|
|---|
| 180 | begin
|
|---|
| 181 | if ID < Length(FRawParts) then
|
|---|
| 182 | Result := FRawParts[ID]
|
|---|
| 183 | else
|
|---|
| 184 | with Result do
|
|---|
| 185 | begin
|
|---|
| 186 | SrcID := -1;
|
|---|
| 187 | SrcOffset := -1;
|
|---|
| 188 | RawAddr := -1;
|
|---|
| 189 | RawSize := -1;
|
|---|
| 190 | end;
|
|---|
| 191 | end;
|
|---|
| 192 |
|
|---|
| 193 | function TFile.GetRawPartByOffset(Offset: Integer): TRawDataInfo;
|
|---|
| 194 | var
|
|---|
| 195 | i: Integer;
|
|---|
| 196 | begin
|
|---|
| 197 | with Result do
|
|---|
| 198 | begin
|
|---|
| 199 | SrcID := -1;
|
|---|
| 200 | SrcOffset := -1;
|
|---|
| 201 | RawAddr := -1;
|
|---|
| 202 | RawSize := -1;
|
|---|
| 203 | end;
|
|---|
| 204 |
|
|---|
| 205 | if Length(FRawParts) > 0 then
|
|---|
| 206 | begin
|
|---|
| 207 | for i := 0 to High(FRawParts) do
|
|---|
| 208 | if FRawParts[i].SrcOffset = Offset then
|
|---|
| 209 | break;
|
|---|
| 210 | if i < Length(FRawParts) then
|
|---|
| 211 | Result := FRawParts[i];
|
|---|
| 212 | end;
|
|---|
| 213 | end;
|
|---|
| 214 |
|
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 | procedure TFile.InitDataFields;
|
|---|
| 218 | begin
|
|---|
| 219 | if Assigned(FDataFields) then
|
|---|
| 220 | Exit;
|
|---|
| 221 | end;
|
|---|
| 222 |
|
|---|
| 223 | procedure TFile.InitDatLinks;
|
|---|
| 224 | begin
|
|---|
| 225 | FDatLinks := ConManager.Connection[FConnectionID].GetDatLinks(FFileInfo.ID);
|
|---|
| 226 | end;
|
|---|
| 227 |
|
|---|
| 228 | procedure TFile.InitEditor;
|
|---|
| 229 | begin
|
|---|
| 230 | Exit;
|
|---|
| 231 | end;
|
|---|
| 232 |
|
|---|
| 233 | procedure TFile.InitRawList;
|
|---|
| 234 | begin
|
|---|
| 235 | FRawParts := ConManager.Connection[FConnectionID].GetRawList(FFileInfo.ID);
|
|---|
| 236 | end;
|
|---|
| 237 |
|
|---|
| 238 | function GetDatLinkValue(stream: TStream; offset: Integer): Integer;
|
|---|
| 239 | begin
|
|---|
| 240 | stream.Seek(Offset, soFromBeginning);
|
|---|
| 241 | stream.Read(Result, 4);
|
|---|
| 242 | if Result > 0 then
|
|---|
| 243 | Result := Result div 256
|
|---|
| 244 | else
|
|---|
| 245 | Result := -1;
|
|---|
| 246 | end;
|
|---|
| 247 |
|
|---|
| 248 | end.
|
|---|