| 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 | FFileID: Integer;
|
|---|
| 14 | FFileName: String;
|
|---|
| 15 | FFileExt: String;
|
|---|
| 16 | FFileSize: Integer;
|
|---|
| 17 | FFileStream: TMemoryStream;
|
|---|
| 18 |
|
|---|
| 19 | FCached: Boolean;
|
|---|
| 20 | FChanged: Boolean;
|
|---|
| 21 |
|
|---|
| 22 | FDatLinks: TDatLinkList;
|
|---|
| 23 | FDataFields: TBlock;
|
|---|
| 24 | FRawParts: TRawDataList;
|
|---|
| 25 |
|
|---|
| 26 | FEditor: TFrame;
|
|---|
| 27 | FOpened: Boolean;
|
|---|
| 28 |
|
|---|
| 29 | procedure InitDatLinks;
|
|---|
| 30 | procedure InitRawList;
|
|---|
| 31 |
|
|---|
| 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;
|
|---|
| 38 | function GetChildCount: Integer;
|
|---|
| 39 | public
|
|---|
| 40 | constructor Create(ConnectionID, FileID: Integer); virtual;
|
|---|
| 41 | procedure Free;
|
|---|
| 42 |
|
|---|
| 43 | procedure InitDataFields; virtual;
|
|---|
| 44 | procedure InitEditor; virtual;
|
|---|
| 45 |
|
|---|
| 46 | property FileStream: TMemoryStream read FFileStream;
|
|---|
| 47 | property FileID: Integer read FFileID;
|
|---|
| 48 | property FileName: String read FFileName;
|
|---|
| 49 | property FileExt: String read FFileExt;
|
|---|
| 50 | property FileSize: Integer read FFileSize;
|
|---|
| 51 | property ConnectionID: Integer read FConnectionID;
|
|---|
| 52 |
|
|---|
| 53 | property Cached: Boolean read FCached;
|
|---|
| 54 | property Changed: Boolean read FChanged write FChanged;
|
|---|
| 55 |
|
|---|
| 56 | property Editor: TFrame read FEditor;
|
|---|
| 57 | property Opened: Boolean read FOpened write FOpened;
|
|---|
| 58 |
|
|---|
| 59 | property ChildCount: Integer read GetChildCount;
|
|---|
| 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;
|
|---|
| 68 | end;
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 | TFileType = class of TFile;
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 | function GetDatLinkValue(stream: TStream; offset: Integer): Integer;
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 | implementation
|
|---|
| 79 |
|
|---|
| 80 | uses
|
|---|
| 81 | DatLinks, RawList, ConnectionManager, Dialogs, _EmptyFile;
|
|---|
| 82 |
|
|---|
| 83 | { TFileType }
|
|---|
| 84 |
|
|---|
| 85 | constructor TFile.Create(ConnectionID, FileID: Integer);
|
|---|
| 86 | var
|
|---|
| 87 | fileinfo: TFileInfo;
|
|---|
| 88 | begin
|
|---|
| 89 | FConnectionID := ConnectionID;
|
|---|
| 90 | FFileID := FileID;
|
|---|
| 91 | fileinfo := ConManager.Connection[ConnectionID].GetFileInfo(FileID);
|
|---|
| 92 | FFileName := fileinfo.Name;
|
|---|
| 93 | FFileExt := fileinfo.Extension;
|
|---|
| 94 | FFileSize := fileinfo.Size;
|
|---|
| 95 |
|
|---|
| 96 | FCached := False;
|
|---|
| 97 | FChanged := False;
|
|---|
| 98 |
|
|---|
| 99 | if not (Self is TFile_Empty) then
|
|---|
| 100 | begin
|
|---|
| 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;
|
|---|
| 112 | end;
|
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 | procedure TFile.Free;
|
|---|
| 116 | begin
|
|---|
| 117 | FDataFields.Free;
|
|---|
| 118 | end;
|
|---|
| 119 |
|
|---|
| 120 | function TFile.GetDatLinkByIndex(ID: Integer): TDatLink;
|
|---|
| 121 | var
|
|---|
| 122 | i: Integer;
|
|---|
| 123 | valids: Integer;
|
|---|
| 124 | begin
|
|---|
| 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
|
|---|
| 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;
|
|---|
| 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 |
|
|---|
| 165 |
|
|---|
| 166 | function TFile.GetFieldByIndex(ID: Integer): TDataField;
|
|---|
| 167 | begin
|
|---|
| 168 | Result := FDataFields.FieldByIndex[ID];
|
|---|
| 169 | end;
|
|---|
| 170 |
|
|---|
| 171 | function TFile.GetFieldByOffset(Offset: Integer): TDataField;
|
|---|
| 172 | begin
|
|---|
| 173 | Result := FDataFields.FieldByOffset[Offset];
|
|---|
| 174 | end;
|
|---|
| 175 |
|
|---|
| 176 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 227 |
|
|---|
| 228 |
|
|---|
| 229 | procedure TFile.InitDataFields;
|
|---|
| 230 | begin
|
|---|
| 231 | if Assigned(FDataFields) then
|
|---|
| 232 | Exit;
|
|---|
| 233 | end;
|
|---|
| 234 |
|
|---|
| 235 | procedure TFile.InitDatLinks;
|
|---|
| 236 | begin
|
|---|
| 237 | FDatLinks := ConManager.Connection[FConnectionID].GetDatLinks(FFileID);
|
|---|
| 238 | end;
|
|---|
| 239 |
|
|---|
| 240 | procedure TFile.InitEditor;
|
|---|
| 241 | begin
|
|---|
| 242 | Exit;
|
|---|
| 243 | end;
|
|---|
| 244 |
|
|---|
| 245 | procedure TFile.InitRawList;
|
|---|
| 246 | begin
|
|---|
| 247 | FRawParts := ConManager.Connection[FConnectionID].GetRawList(FFileID);
|
|---|
| 248 | end;
|
|---|
| 249 |
|
|---|
| 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 |
|
|---|
| 260 | end.
|
|---|