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

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