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