[93] | 1 | unit DataAccess;
|
---|
| 2 | interface
|
---|
| 3 |
|
---|
[227] | 4 | uses TypeDefs, Classes, StrUtils, SysUtils, _MetaManager;
|
---|
[93] | 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;
|
---|
[227] | 16 | FMeta: TMetaManager;
|
---|
[97] | 17 | procedure SetDataOS(DataOS: TDataOS);
|
---|
[93] | 18 | public
|
---|
| 19 | property ConnectionID: Integer read FConnectionID;
|
---|
[97] | 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;
|
---|
[101] | 24 | property ChangeRights: TChangeRights read FChangeRights;
|
---|
[227] | 25 | property MetaData: TMetaManager read FMeta;
|
---|
[93] | 26 |
|
---|
[229] | 27 | constructor Create(FileName: String; ConnectionID: Integer; var Msg: TStatusMessages); virtual;
|
---|
[93] | 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;
|
---|
[101] | 39 | procedure LoadDatFile(FileID: Integer; var Target: TByteData); overload;
|
---|
[93] | 40 | procedure UpdateDatFile(FileID: Integer; Src: TStream); overload; virtual; abstract;
|
---|
[101] | 41 | procedure UpdateDatFile(FileID: Integer; Src: TByteData); overload;
|
---|
[93] | 42 | procedure LoadDatFilePart(FileID, Offset, Size: Integer; var Target: TStream); overload; virtual; abstract;
|
---|
[101] | 43 | procedure LoadDatFilePart(FileID, Offset, Size: Integer; var Target: TByteData); overload;
|
---|
| 44 | procedure LoadDatFilePart(FileID, Offset, Size: Integer; Target: Pointer); overload;
|
---|
[93] | 45 | procedure UpdateDatFilePart(FileID, Offset, Size: Integer; Src: TStream); overload; virtual; abstract;
|
---|
[101] | 46 | procedure UpdateDatFilePart(FileID, Offset, Size: Integer; Src: Pointer); overload;
|
---|
[93] | 47 |
|
---|
[113] | 48 | function GetDatLinks(FileID: Integer): TDatLinkList; virtual; abstract;
|
---|
[116] | 49 | function GetDatLink(FileID, DatOffset: Integer): TDatLink; virtual; abstract;
|
---|
[93] | 50 | function GetRawList(FileID: Integer): TRawDataList; virtual; abstract;
|
---|
[101] | 51 | function GetRawInfo(FileID, DatOffset: Integer): TRawDataInfo; virtual; abstract;
|
---|
[93] | 52 |
|
---|
| 53 | procedure LoadRawFile(FileID, DatOffset: Integer; var Target: TStream); overload; virtual; abstract;
|
---|
[101] | 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;
|
---|
[93] | 57 | procedure LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; var Target: TStream); overload; virtual; abstract;
|
---|
[101] | 58 | procedure LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; var Target: TByteData); overload;
|
---|
| 59 | procedure LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; Target: Pointer); overload;
|
---|
[93] | 60 | procedure UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: TStream); overload; virtual; abstract;
|
---|
[101] | 61 | procedure UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: Pointer); overload;
|
---|
[93] | 62 |
|
---|
[105] | 63 | function AppendRawFile(LocSep: Boolean; Src: TStream): Integer; overload; virtual;
|
---|
| 64 | function AppendRawFile(LocSep: Boolean; Src: TByteData): Integer; overload;
|
---|
[193] | 65 | // function AppendRawFile(LocSep: Boolean; Size: Integer; Src: Pointer): Integer; overload;
|
---|
[93] | 66 | published
|
---|
| 67 | end;
|
---|
| 68 |
|
---|
| 69 |
|
---|
| 70 |
|
---|
| 71 | implementation
|
---|
| 72 |
|
---|
| 73 |
|
---|
| 74 | (*
|
---|
| 75 | Implementation of TDataAccess
|
---|
| 76 | *)
|
---|
| 77 |
|
---|
[229] | 78 | constructor TDataAccess.Create(FileName: String; ConnectionID: Integer;
|
---|
| 79 | var Msg: TStatusMessages);
|
---|
| 80 | begin
|
---|
| 81 | FMeta := TMetaManager.Create(FConnectionID, Self);
|
---|
| 82 | end;
|
---|
| 83 |
|
---|
| 84 |
|
---|
| 85 |
|
---|
[93] | 86 | function TDataAccess.ExtractFileIDOfName(Name: String): Integer;
|
---|
| 87 | begin
|
---|
| 88 | if Name[5] = '-' then
|
---|
| 89 | Result := StrToInt(MidStr(Name, 1, 4))
|
---|
| 90 | else
|
---|
| 91 | Result := StrToInt(MidStr(Name, 1, 5));
|
---|
| 92 | end;
|
---|
| 93 |
|
---|
| 94 |
|
---|
| 95 | function TDataAccess.GetFileInfo(FileID: Integer): TFileInfo;
|
---|
| 96 | begin
|
---|
| 97 | Result.ID := -1;
|
---|
| 98 | Result.Name := '';
|
---|
| 99 | Result.Extension := '';
|
---|
| 100 | Result.Size := -1;
|
---|
| 101 | Result.FileType := 0;
|
---|
| 102 | Result.DatAddr := -1;
|
---|
| 103 | end;
|
---|
| 104 |
|
---|
| 105 |
|
---|
| 106 | function TDataAccess.GetFileInfoByName(Name: String): TFileInfo;
|
---|
| 107 | var
|
---|
| 108 | i: Integer;
|
---|
| 109 | files: TStrings;
|
---|
| 110 | begin
|
---|
| 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;
|
---|
| 127 | end;
|
---|
| 128 |
|
---|
| 129 |
|
---|
[101] | 130 | procedure TDataAccess.LoadDatFile(FileID: Integer; var Target: TByteData);
|
---|
[93] | 131 | var
|
---|
[101] | 132 | data: TStream;
|
---|
[93] | 133 | begin
|
---|
[101] | 134 | if fileid < GetFileCount then
|
---|
[93] | 135 | begin
|
---|
[101] | 136 | data := nil;
|
---|
| 137 | LoadDatFile(FileID, data);
|
---|
| 138 | SetLength(Target, data.Size);
|
---|
| 139 | data.Read(Target[0], data.Size);
|
---|
| 140 | data.Free;
|
---|
[93] | 141 | end;
|
---|
| 142 | end;
|
---|
| 143 |
|
---|
[101] | 144 | procedure TDataAccess.UpdateDatFile(FileID: Integer; Src: TByteData);
|
---|
| 145 | var
|
---|
| 146 | data: TStream;
|
---|
| 147 | begin
|
---|
| 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;
|
---|
| 156 | end;
|
---|
[93] | 157 |
|
---|
[101] | 158 | procedure TDataAccess.LoadDatFilePart(FileID, Offset, Size: Integer; var Target: TByteData);
|
---|
| 159 | var
|
---|
| 160 | data: TStream;
|
---|
| 161 | begin
|
---|
| 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;
|
---|
| 170 | end;
|
---|
| 171 |
|
---|
| 172 | procedure TDataAccess.LoadDatFilePart(FileID, Offset, Size: Integer; Target: Pointer);
|
---|
| 173 | var
|
---|
| 174 | data: TStream;
|
---|
| 175 | begin
|
---|
| 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;
|
---|
| 183 | end;
|
---|
| 184 |
|
---|
| 185 | procedure TDataAccess.UpdateDatFilePart(FileID, Offset, Size: Integer; Src: Pointer);
|
---|
| 186 | var
|
---|
| 187 | data: TStream;
|
---|
| 188 | begin
|
---|
| 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;
|
---|
| 197 | end;
|
---|
| 198 |
|
---|
| 199 |
|
---|
| 200 |
|
---|
| 201 | procedure TDataAccess.LoadRawFile(FileID, DatOffset: Integer; var Target: TByteData);
|
---|
| 202 | var
|
---|
| 203 | data: TStream;
|
---|
| 204 | begin
|
---|
| 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;
|
---|
| 213 | end;
|
---|
| 214 |
|
---|
| 215 | procedure TDataAccess.UpdateRawFile(FileID, DatOffset: Integer; Src: TByteData);
|
---|
| 216 | var
|
---|
| 217 | data: TStream;
|
---|
| 218 | begin
|
---|
| 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;
|
---|
| 227 | end;
|
---|
| 228 |
|
---|
| 229 | procedure TDataAccess.LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; var Target: TByteData);
|
---|
| 230 | var
|
---|
| 231 | data: TStream;
|
---|
| 232 | begin
|
---|
| 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;
|
---|
| 242 | end;
|
---|
| 243 |
|
---|
| 244 | procedure TDataAccess.LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; Target: Pointer);
|
---|
| 245 | var
|
---|
| 246 | data: TStream;
|
---|
| 247 | begin
|
---|
| 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;
|
---|
| 256 | end;
|
---|
| 257 |
|
---|
| 258 | procedure TDataAccess.UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: Pointer);
|
---|
| 259 | var
|
---|
| 260 | data: TStream;
|
---|
| 261 | begin
|
---|
| 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;
|
---|
| 270 | end;
|
---|
| 271 |
|
---|
| 272 |
|
---|
[105] | 273 | function TDataAccess.AppendRawFile(LocSep: Boolean; Src: TStream): Integer;
|
---|
[101] | 274 | begin
|
---|
| 275 | raise ENotImplemented.Create('ERROR: AppendRawFile not implemented here!!!');
|
---|
| 276 | end;
|
---|
| 277 |
|
---|
| 278 |
|
---|
[105] | 279 | function TDataAccess.AppendRawFile(LocSep: Boolean; Src: TByteData): Integer;
|
---|
[101] | 280 | var
|
---|
| 281 | data: TStream;
|
---|
| 282 | begin
|
---|
| 283 | data := TMemoryStream.Create;
|
---|
[105] | 284 | data.Write(Src[0], Length(Src));
|
---|
| 285 | data.Seek(0, soFromBeginning);
|
---|
[113] | 286 | Result := AppendRawFile(LocSep, data);
|
---|
[101] | 287 | data.Free;
|
---|
| 288 | end;
|
---|
[193] | 289 | {
|
---|
[101] | 290 | function TDataAccess.AppendRawFile(LocSep: Boolean; Size: Integer; Src: Pointer): Integer;
|
---|
| 291 | var
|
---|
| 292 | data: TStream;
|
---|
| 293 | begin
|
---|
| 294 | data := TMemoryStream.Create;
|
---|
| 295 | data.Write(Src^, Size);
|
---|
[105] | 296 | data.Seek(0, soFromBeginning);
|
---|
[113] | 297 | Result := AppendRawFile(LocSep, data);
|
---|
[101] | 298 | data.Free;
|
---|
| 299 | end;
|
---|
[193] | 300 | }
|
---|
[101] | 301 |
|
---|
| 302 |
|
---|
[97] | 303 | procedure TDataAccess.SetDataOS(DataOS: TDataOS);
|
---|
| 304 | begin
|
---|
| 305 | raise ENotImplemented.Create('TDataAccess.SetDataOS: TBD!');
|
---|
| 306 | end;
|
---|
[93] | 307 |
|
---|
| 308 | end.
|
---|