source: oup/rewrite/DataAccess/DataAccess.pas@ 104

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