source: oup/current/FileClasses/_FileTypes.pas@ 243

Last change on this file since 243 was 241, checked in by alloc, 17 years ago
File size: 4.8 KB
Line 
1unit _FileTypes;
2
3interface
4
5uses
6 TypeDefs, _TreeElement, Classes, Forms, _DataTypes;
7
8
9type
10 TFile = class(TTreeElement)
11 protected
12 FFileInfo: TFileInfo;
13 FFileStream: TMemoryStream;
14 FRawCaches: array of TMemoryStream;
15
16 FCached: Boolean;
17 FChanged: Boolean;
18
19 FDataFields: TBlock;
20
21 FEditor: TFrame;
22 FOpened: Boolean;
23
24 function GetChildCount: Integer; override;
25 function GetChild(ID: Integer): TTreeElement; override;
26 function GetCaption: String; override;
27 function GetType: String; override;
28 function GetEditor: TFrame;
29 function GetFieldByOffset(Offset: Integer): TDataField;
30 procedure SetOpened(Opened: Boolean); virtual;
31 published
32 public
33 constructor Create(ConnectionID, FileID: Integer); virtual;
34 procedure Free;
35
36 procedure InitDataFields; virtual;
37 procedure InitEditor; virtual;
38
39 procedure ReCreateFile(fs: TStream);
40
41 procedure CacheFile;
42 procedure CacheRawFile(Offset: Integer);
43
44 property FileStream: TMemoryStream read FFileStream;
45 property FileInfo: TFileInfo read FFileInfo;
46
47 property Cached: Boolean read FCached;
48 property Changed: Boolean read FChanged write FChanged;
49
50 property Editor: TFrame read GetEditor;
51 property Opened: Boolean read FOpened write SetOpened;
52
53 property FieldByOffset[Offset: Integer]: TDataField read GetFieldByOffset;
54 end;
55
56
57 TFileType = class of TFile;
58
59
60
61implementation
62
63uses
64 DatLinks, RawList, ConnectionManager, Dialogs, _MetaTypes, _MetaManager,
65 SysUtils;
66
67{ TFileType }
68
69procedure TFile.CacheFile;
70begin
71 if not Assigned(FFileStream) then
72 begin
73 FFileStream := TMemoryStream.Create;
74 ConManager.Connection[FConnectionID].LoadDatFile(FFileInfo.ID, TStream(FFileStream));
75 end;
76end;
77
78
79procedure TFile.CacheRawFile(Offset: Integer);
80var
81 rawlist: TRawDataList;
82 i: Integer;
83begin
84 rawlist := ConManager.Connection[ConnectionID].GetRawList(FFileInfo.ID);
85 if Length(rawlist) > 0 then
86 begin
87 for i := 0 to High(rawlist) do
88 begin
89 if rawlist[i].SrcOffset = Offset then
90 begin
91 if not Assigned(FRawCaches[i]) then
92 begin
93 FRawCaches[i] := TMemoryStream.Create;
94 ConManager.Connection[ConnectionID].LoadRawFile(FFileInfo.ID, Offset, TStream(FRawCaches[i]));
95 end;
96 end;
97 end;
98 end;
99end;
100
101
102procedure TFile.SetOpened(Opened: Boolean);
103begin
104 FOpened := Opened;
105end;
106
107
108constructor TFile.Create(ConnectionID, FileID: Integer);
109begin
110 FConnectionID := ConnectionID;
111 FFileInfo := ConManager.Connection[ConnectionID].GetFileInfo(FileID);
112
113 SetLength(FRawCaches, Length(ConManager.Connection[ConnectionID].GetRawList(FileID)));
114
115 FCached := False;
116 FChanged := False;
117
118 FDataFields := nil;
119 FEditor := nil;
120
121 if not (Self is TFile_Empty) then
122 InitDataFields;
123end;
124
125
126procedure TFile.Free;
127begin
128 FDataFields.Free;
129end;
130
131
132function TFile.GetFieldByOffset(Offset: Integer): TDataField;
133begin
134 Result := FDataFields.FieldByOffset[Offset];
135end;
136
137
138function TFile.GetType: String;
139begin
140 Result := FFileInfo.Extension;
141end;
142
143function TFile.GetCaption: String;
144begin
145 Result := FFileInfo.Name;
146 if Result = '' then
147 Result := 'Unnamed';
148 Result := Result + ' (' + IntToStr(FFileInfo.ID) + ')';
149end;
150
151function TFile.GetChild(ID: Integer): TTreeElement;
152begin
153 Result := FDataFields.Child[ID];
154end;
155
156function TFile.GetChildCount: Integer;
157begin
158 if FDataFields <> nil then
159 Result := FDataFields.ChildCount
160 else
161 Result := 0;
162end;
163
164
165function TFile.GetEditor: TFrame;
166begin
167 if not Assigned(FEditor) then
168 InitEditor;
169 Result := FEditor;
170end;
171
172
173procedure TFile.InitDataFields;
174begin
175 if Assigned(FDataFields) then
176 Exit;
177 FFileStream := TMemoryStream.Create;
178 ConManager.Connection[FConnectionID].LoadDatFile(FFileInfo.ID, TStream(FFileStream));
179end;
180
181
182procedure TFile.InitEditor;
183begin
184 Exit;
185end;
186
187
188//*********************************************************
189//*********************************************************
190//*********************************************************
191procedure TFile.ReCreateFile(fs: TStream);
192const
193 temp0: array[0..31] of Byte =
194 ($AD,$DE,$AD,$DE,$AD,$DE,$AD,$DE,
195 $AD,$DE,$AD,$DE,$AD,$DE,$AD,$DE,
196 $AD,$DE,$AD,$DE,$AD,$DE,$AD,$DE,
197 $AD,$DE,$AD,$DE,$AD,$DE,$AD,$DE);
198var
199 count: Integer;
200begin
201 FDataFields.WriteData(fs);
202 count := fs.Size mod 32;
203 if count > 0 then
204 fs.Write(temp0[count], 32 - count);
205end;
206//*********************************************************
207//*********************************************************
208//*********************************************************
209
210end.
Note: See TracBrowser for help on using the repository browser.