source: oup/current/DataAccess/DataAccess.pas@ 238

Last change on this file since 238 was 229, checked in by alloc, 17 years ago
File size: 9.1 KB
Line 
1unit DataAccess;
2interface
3
4uses TypeDefs, Classes, StrUtils, SysUtils, _MetaManager;
5
6type
7 TDataAccess = class
8 private
9 protected
10 FConnectionID: Integer;
11 FFileName: String;
12 FBackend: TDataBackend;
13 FDataOS: TDataOS;
14 FLevelNumber: Integer;
15 FChangeRights: TChangeRights;
16 FMeta: TMetaManager;
17 procedure SetDataOS(DataOS: TDataOS);
18 public
19 property ConnectionID: Integer read FConnectionID;
20 property FileName: String read FFileName;
21 property Backend: TDataBackend read FBackend;
22 property DataOS: TDataOS read FDataOS write SetDataOS;
23 property LevelNumber: Integer read FLevelNumber;
24 property ChangeRights: TChangeRights read FChangeRights;
25 property MetaData: TMetaManager read FMeta;
26
27 constructor Create(FileName: String; ConnectionID: Integer; var Msg: TStatusMessages); virtual;
28 procedure Close; virtual; abstract;
29
30 function ExtractFileIDOfName(Name: String): Integer; virtual;
31 function GetFileInfo(FileID: Integer): TFileInfo; virtual;
32 function GetFileInfoByName(Name: String): TFileInfo; virtual;
33 function GetFilesList(Ext: String; Pattern: String;
34 NoEmptyFiles: Boolean; SortType: TSortType): TStrings; virtual; abstract;
35 function GetFileCount: Integer; virtual; abstract;
36 function GetExtensionsList(ExtListFormat: TExtensionFormat): TStrings; virtual; abstract;
37
38 procedure LoadDatFile(FileID: Integer; var Target: TStream); overload; virtual; abstract;
39 procedure LoadDatFile(FileID: Integer; var Target: TByteData); overload;
40 procedure UpdateDatFile(FileID: Integer; Src: TStream); overload; virtual; abstract;
41 procedure UpdateDatFile(FileID: Integer; Src: TByteData); overload;
42 procedure LoadDatFilePart(FileID, Offset, Size: Integer; var Target: TStream); overload; virtual; abstract;
43 procedure LoadDatFilePart(FileID, Offset, Size: Integer; var Target: TByteData); overload;
44 procedure LoadDatFilePart(FileID, Offset, Size: Integer; Target: Pointer); overload;
45 procedure UpdateDatFilePart(FileID, Offset, Size: Integer; Src: TStream); overload; virtual; abstract;
46 procedure UpdateDatFilePart(FileID, Offset, Size: Integer; Src: Pointer); overload;
47
48 function GetDatLinks(FileID: Integer): TDatLinkList; virtual; abstract;
49 function GetDatLink(FileID, DatOffset: Integer): TDatLink; virtual; abstract;
50 function GetRawList(FileID: Integer): TRawDataList; virtual; abstract;
51 function GetRawInfo(FileID, DatOffset: Integer): TRawDataInfo; virtual; abstract;
52
53 procedure LoadRawFile(FileID, DatOffset: Integer; var Target: TStream); overload; virtual; abstract;
54 procedure LoadRawFile(FileID, DatOffset: Integer; var Target: TByteData); overload;
55 procedure UpdateRawFile(FileID, DatOffset: Integer; Src: TStream); overload; virtual; abstract;
56 procedure UpdateRawFile(FileID, DatOffset: Integer; Src: TByteData); overload;
57 procedure LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; var Target: TStream); overload; virtual; abstract;
58 procedure LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; var Target: TByteData); overload;
59 procedure LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; Target: Pointer); overload;
60 procedure UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: TStream); overload; virtual; abstract;
61 procedure UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: Pointer); overload;
62
63 function AppendRawFile(LocSep: Boolean; Src: TStream): Integer; overload; virtual;
64 function AppendRawFile(LocSep: Boolean; Src: TByteData): Integer; overload;
65// function AppendRawFile(LocSep: Boolean; Size: Integer; Src: Pointer): Integer; overload;
66 published
67 end;
68
69
70
71implementation
72
73
74(*
75 Implementation of TDataAccess
76*)
77
78constructor TDataAccess.Create(FileName: String; ConnectionID: Integer;
79 var Msg: TStatusMessages);
80begin
81 FMeta := TMetaManager.Create(FConnectionID, Self);
82end;
83
84
85
86function TDataAccess.ExtractFileIDOfName(Name: String): Integer;
87begin
88 if Name[5] = '-' then
89 Result := StrToInt(MidStr(Name, 1, 4))
90 else
91 Result := StrToInt(MidStr(Name, 1, 5));
92end;
93
94
95function TDataAccess.GetFileInfo(FileID: Integer): TFileInfo;
96begin
97 Result.ID := -1;
98 Result.Name := '';
99 Result.Extension := '';
100 Result.Size := -1;
101 Result.FileType := 0;
102 Result.DatAddr := -1;
103end;
104
105
106function TDataAccess.GetFileInfoByName(Name: String): TFileInfo;
107var
108 i: Integer;
109 files: TStrings;
110begin
111 Result := GetFileInfo(-1);
112 files := GetFilesList('', Name, False, ST_IDAsc);
113 if files.Count = 0 then
114 else
115 begin
116 for i := 0 to files.Count - 1 do
117 begin
118 if MidStr(files.Strings[i], Pos('-', files.Strings[i]) + 1,
119 Length(files.Strings[i]) - Pos('-', files.Strings[i]) - 5) = name then
120 begin
121 Result := GetFileInfo(ExtractFileIDOfName(files.Strings[i]));
122 Break;
123 end;
124 end;
125 end;
126 files.Free;
127end;
128
129
130procedure TDataAccess.LoadDatFile(FileID: Integer; var Target: TByteData);
131var
132 data: TStream;
133begin
134 if fileid < GetFileCount then
135 begin
136 data := nil;
137 LoadDatFile(FileID, data);
138 SetLength(Target, data.Size);
139 data.Read(Target[0], data.Size);
140 data.Free;
141 end;
142end;
143
144procedure TDataAccess.UpdateDatFile(FileID: Integer; Src: TByteData);
145var
146 data: TStream;
147begin
148 if fileid < GetFileCount then
149 begin
150 data := TMemoryStream.Create;
151 data.Write(Src[0], Length(Src));
152 data.Seek(0, soFromBeginning);
153 UpdateDatFile(FileID, data);
154 data.Free;
155 end;
156end;
157
158procedure TDataAccess.LoadDatFilePart(FileID, Offset, Size: Integer; var Target: TByteData);
159var
160 data: TStream;
161begin
162 if fileid < GetFileCount then
163 begin
164 data := nil;
165 LoadDatFilePart(FileID, offset, size, data);
166 SetLength(Target, data.Size);
167 data.Read(Target[0], data.Size);
168 data.Free;
169 end;
170end;
171
172procedure TDataAccess.LoadDatFilePart(FileID, Offset, Size: Integer; Target: Pointer);
173var
174 data: TStream;
175begin
176 if fileid < GetFileCount then
177 begin
178 data := nil;
179 LoadDatFilePart(FileID, offset, size, data);
180 data.Read(Target^, data.Size);
181 data.Free;
182 end;
183end;
184
185procedure TDataAccess.UpdateDatFilePart(FileID, Offset, Size: Integer; Src: Pointer);
186var
187 data: TStream;
188begin
189 if fileid < GetFileCount then
190 begin
191 data := TMemoryStream.Create;
192 data.Write(Src^, Size);
193 data.Seek(0, soFromBeginning);
194 UpdateDatFilePart(FileID, offset, size, data);
195 data.Free;
196 end;
197end;
198
199
200
201procedure TDataAccess.LoadRawFile(FileID, DatOffset: Integer; var Target: TByteData);
202var
203 data: TStream;
204begin
205 if fileid < GetFileCount then
206 begin
207 data := nil;
208 LoadRawFile(FileID, DatOffset, data);
209 SetLength(Target, data.Size);
210 data.Read(Target[0], data.Size);
211 data.Free;
212 end;
213end;
214
215procedure TDataAccess.UpdateRawFile(FileID, DatOffset: Integer; Src: TByteData);
216var
217 data: TStream;
218begin
219 if fileid < GetFileCount then
220 begin
221 data := TMemoryStream.Create;
222 data.Write(Src[0], Length(Src));
223 data.Seek(0, soFromBeginning);
224 UpdateRawFile(FileID, DatOffset, data);
225 data.Free;
226 end;
227end;
228
229procedure TDataAccess.LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; var Target: TByteData);
230var
231 data: TStream;
232begin
233 if fileid < GetFileCount then
234 begin
235 data := nil;
236 SetLength(Target, Size);
237 LoadRawFile(FileID, DatOffset, Data);
238 Data.Seek(Offset, soFromBeginning);
239 Data.Read(Target[0], Size);
240 Data.Free;
241 end;
242end;
243
244procedure TDataAccess.LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; Target: Pointer);
245var
246 data: TStream;
247begin
248 if fileid < GetFileCount then
249 begin
250 data := nil;
251 LoadRawFile(FileID, DatOffset, Data);
252 Data.Seek(Offset, soFromBeginning);
253 Data.Read(Target^, Size);
254 Data.Free;
255 end;
256end;
257
258procedure TDataAccess.UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: Pointer);
259var
260 data: TStream;
261begin
262 if fileid < GetFileCount then
263 begin
264 data := TMemoryStream.Create;
265 data.Write(Src^, Size);
266 data.Seek(0, soFromBeginning);
267 UpdateRawFilePart(FileID, DatOffset, Offset, Size, data);
268 data.Free;
269 end;
270end;
271
272
273function TDataAccess.AppendRawFile(LocSep: Boolean; Src: TStream): Integer;
274begin
275 raise ENotImplemented.Create('ERROR: AppendRawFile not implemented here!!!');
276end;
277
278
279function TDataAccess.AppendRawFile(LocSep: Boolean; Src: TByteData): Integer;
280var
281 data: TStream;
282begin
283 data := TMemoryStream.Create;
284 data.Write(Src[0], Length(Src));
285 data.Seek(0, soFromBeginning);
286 Result := AppendRawFile(LocSep, data);
287 data.Free;
288end;
289{
290function TDataAccess.AppendRawFile(LocSep: Boolean; Size: Integer; Src: Pointer): Integer;
291var
292 data: TStream;
293begin
294 data := TMemoryStream.Create;
295 data.Write(Src^, Size);
296 data.Seek(0, soFromBeginning);
297 Result := AppendRawFile(LocSep, data);
298 data.Free;
299end;
300}
301
302
303procedure TDataAccess.SetDataOS(DataOS: TDataOS);
304begin
305 raise ENotImplemented.Create('TDataAccess.SetDataOS: TBD!');
306end;
307
308end.
Note: See TracBrowser for help on using the repository browser.