1 | unit _FileTypes;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | TypeDefs, _DataTypes, Classes;
|
---|
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 | FDatLinks: TDatLinkList;
|
---|
20 | FDataFields: TBlock;
|
---|
21 | FRawParts: TRawDataList;
|
---|
22 |
|
---|
23 | procedure InitDatLinks; virtual; abstract;
|
---|
24 | procedure InitDataFields; virtual; abstract;
|
---|
25 | procedure InitRawList; virtual; abstract;
|
---|
26 |
|
---|
27 | function GetDatLinkByOffset(Offset: Integer): TDatLink;
|
---|
28 | function GetDatLinkByIndex(ID: Integer): TDatLink;
|
---|
29 | function GetFieldByOffset(Offset: Integer): TDataField;
|
---|
30 | function GetFieldByIndex(ID: Integer): TDataField;
|
---|
31 | function GetRawPartByOffset(Offset: Integer): TRawDataInfo;
|
---|
32 | function GetRawPartByIndex(ID: Integer): TRawDataInfo;
|
---|
33 | public
|
---|
34 | constructor Create(ConnectionID, FileID: Integer); virtual;
|
---|
35 | procedure Free;
|
---|
36 |
|
---|
37 | property FileStream: TMemoryStream read FFileStream;
|
---|
38 | property FileID: Integer read FFileID;
|
---|
39 | property FileName: String read FFileName;
|
---|
40 | property FileExt: String read FFileExt;
|
---|
41 | property FileSize: Integer read FFileSize;
|
---|
42 | property ConnectionID: Integer read FConnectionID;
|
---|
43 |
|
---|
44 | property LinkByOffset[Offset: Integer]: TDatLink read GetDatLinkByOffset;
|
---|
45 | property LinkByIndex[ID: Integer]: TDatLink read GetDatLinkByIndex;
|
---|
46 |
|
---|
47 | property FieldByOffset[Offset: Integer]: TDataField read GetFieldByOffset;
|
---|
48 | property FieldByIndex[ID: Integer]: TDataField read GetFieldByIndex;
|
---|
49 |
|
---|
50 | property RawPartByOffset[Offset: Integer]: TRawDataInfo read GetRawPartByOffset;
|
---|
51 | property RawPartByIndex[ID: Integer]: TRawDataInfo read GetRawPartByIndex;
|
---|
52 | end;
|
---|
53 |
|
---|
54 |
|
---|
55 | TFileType = class of TFile;
|
---|
56 |
|
---|
57 |
|
---|
58 | function GetDatLinkValue(stream: TStream; offset: Integer): Integer;
|
---|
59 |
|
---|
60 |
|
---|
61 |
|
---|
62 | implementation
|
---|
63 |
|
---|
64 | uses
|
---|
65 | DatLinks, RawList, ConnectionManager, Dialogs;
|
---|
66 |
|
---|
67 | { TFileType }
|
---|
68 |
|
---|
69 | constructor TFile.Create(ConnectionID, FileID: Integer);
|
---|
70 | var
|
---|
71 | i: Integer;
|
---|
72 | fileinfo: TFileInfo;
|
---|
73 | begin
|
---|
74 | FConnectionID := ConnectionID;
|
---|
75 | FFileID := FileID;
|
---|
76 | fileinfo := ConManager.Connection[ConnectionID].GetFileInfo(FileID);
|
---|
77 | FFileName := fileinfo.Name;
|
---|
78 | FFileExt := fileinfo.Extension;
|
---|
79 | FFileSize := fileinfo.Size;
|
---|
80 |
|
---|
81 | FFileStream := TMemoryStream.Create;
|
---|
82 | ConManager.Connection[ConnectionID].LoadDatFile(FileID, TStream(FFileStream));
|
---|
83 |
|
---|
84 | InitDatLinks();
|
---|
85 | InitDataFields();
|
---|
86 | InitRawList();
|
---|
87 |
|
---|
88 | FFileStream.Free;
|
---|
89 | FFileStream := nil;
|
---|
90 | end;
|
---|
91 |
|
---|
92 |
|
---|
93 | procedure TFile.Free;
|
---|
94 | begin
|
---|
95 | FDataFields.Free;
|
---|
96 | end;
|
---|
97 |
|
---|
98 | function TFile.GetDatLinkByIndex(ID: Integer): TDatLink;
|
---|
99 | begin
|
---|
100 | if ID < Length(FDatLinks) then
|
---|
101 | Result := FDatLinks[ID]
|
---|
102 | else
|
---|
103 | with Result do
|
---|
104 | begin
|
---|
105 | SrcOffset := -1;
|
---|
106 | DestID := -1;
|
---|
107 | PosDestExts := '';
|
---|
108 | end;
|
---|
109 | end;
|
---|
110 |
|
---|
111 | function TFile.GetDatLinkByOffset(Offset: Integer): TDatLink;
|
---|
112 | var
|
---|
113 | i: Integer;
|
---|
114 | begin
|
---|
115 | Result.SrcOffset := -1;
|
---|
116 | Result.DestID := -1;
|
---|
117 | Result.PosDestExts := '';
|
---|
118 |
|
---|
119 | if Length(FDatLinks) > 0 then
|
---|
120 | begin
|
---|
121 | for i := 0 to High(FDatLinks) do
|
---|
122 | if FDatLinks[i].SrcOffset = Offset then
|
---|
123 | break;
|
---|
124 | if i < Length(FDatLinks) then
|
---|
125 | Result := FDatLinks[i];
|
---|
126 | end;
|
---|
127 | end;
|
---|
128 |
|
---|
129 |
|
---|
130 | function TFile.GetFieldByIndex(ID: Integer): TDataField;
|
---|
131 | begin
|
---|
132 | Result := FDataFields.FieldByIndex[ID];
|
---|
133 | end;
|
---|
134 |
|
---|
135 | function TFile.GetFieldByOffset(Offset: Integer): TDataField;
|
---|
136 | var
|
---|
137 | i: Integer;
|
---|
138 | begin
|
---|
139 | Result := FDataFields.FieldByOffset[Offset];
|
---|
140 | end;
|
---|
141 |
|
---|
142 |
|
---|
143 | function TFile.GetRawPartByIndex(ID: Integer): TRawDataInfo;
|
---|
144 | begin
|
---|
145 | if ID < Length(FRawParts) then
|
---|
146 | Result := FRawParts[ID]
|
---|
147 | else
|
---|
148 | with Result do
|
---|
149 | begin
|
---|
150 | SrcID := -1;
|
---|
151 | SrcOffset := -1;
|
---|
152 | RawAddr := -1;
|
---|
153 | RawSize := -1;
|
---|
154 | end;
|
---|
155 | end;
|
---|
156 |
|
---|
157 | function TFile.GetRawPartByOffset(Offset: Integer): TRawDataInfo;
|
---|
158 | var
|
---|
159 | i: Integer;
|
---|
160 | begin
|
---|
161 | with Result do
|
---|
162 | begin
|
---|
163 | SrcID := -1;
|
---|
164 | SrcOffset := -1;
|
---|
165 | RawAddr := -1;
|
---|
166 | RawSize := -1;
|
---|
167 | end;
|
---|
168 |
|
---|
169 | if Length(FRawParts) > 0 then
|
---|
170 | begin
|
---|
171 | for i := 0 to High(FRawParts) do
|
---|
172 | if FRawParts[i].SrcOffset = Offset then
|
---|
173 | break;
|
---|
174 | if i < Length(FRawParts) then
|
---|
175 | Result := FRawParts[i];
|
---|
176 | end;
|
---|
177 | end;
|
---|
178 |
|
---|
179 |
|
---|
180 |
|
---|
181 | function GetDatLinkValue(stream: TStream; offset: Integer): Integer;
|
---|
182 | begin
|
---|
183 | stream.Seek(Offset, soFromBeginning);
|
---|
184 | stream.Read(Result, 4);
|
---|
185 | if Result > 0 then
|
---|
186 | Result := Result div 256
|
---|
187 | else
|
---|
188 | Result := -1;
|
---|
189 | end;
|
---|
190 |
|
---|
191 | end.
|
---|