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