[93] | 1 | unit Access_OUP_ADB;
|
---|
| 2 | interface
|
---|
| 3 |
|
---|
[101] | 4 | uses DataAccess, ABSMain, TypeDefs, Classes;
|
---|
[93] | 5 |
|
---|
| 6 | type
|
---|
| 7 | TAccess_OUP_ADB = class(TDataAccess)
|
---|
| 8 | private
|
---|
[101] | 9 | FDatabase: TABSDatabase;
|
---|
| 10 | FQuery: TABSQuery;
|
---|
| 11 | Fdat_files: TFiles;
|
---|
[93] | 12 | Fdat_extensionsmap: TExtensionsMap;
|
---|
| 13 | protected
|
---|
| 14 | public
|
---|
[101] | 15 | constructor Create(DBFilename: String; ConnectionID: Integer; var Msg: TStatusMessages); override;
|
---|
[93] | 16 | procedure Close; override;
|
---|
| 17 |
|
---|
| 18 | procedure UpdateListCache;
|
---|
| 19 |
|
---|
[106] | 20 | function GetLinksToFile(FileID: Integer): TLinks;
|
---|
| 21 |
|
---|
[101] | 22 | function GetFileInfo(FileID: Integer): TFileInfo; override;
|
---|
| 23 | function GetFilesList(Ext: String; Pattern: String;
|
---|
| 24 | NoEmptyFiles: Boolean; SortType: TSortType): TStrings; override;
|
---|
| 25 | function GetFileCount: Integer; override;
|
---|
| 26 | function GetExtensionsList(ExtListFormat: TExtensionFormat): TStrings; override;
|
---|
[93] | 27 |
|
---|
[101] | 28 | procedure LoadDatFile(FileID: Integer; var Target: TStream); overload; override;
|
---|
| 29 | procedure UpdateDatFile(FileID: Integer; Src: TStream); overload; override;
|
---|
| 30 | procedure LoadDatFilePart(FileID, Offset, Size: Integer; var Target: TStream); overload; override;
|
---|
| 31 | procedure UpdateDatFilePart(FileID, Offset, Size: Integer; Src: TStream); overload; override;
|
---|
| 32 |
|
---|
[113] | 33 | function GetDatLinks(FileID: Integer): TDatLinkList; override;
|
---|
[116] | 34 | function GetDatLink(FileID, DatOffset: Integer): TDatLink; override;
|
---|
[101] | 35 | function GetRawList(FileID: Integer): TRawDataList; override;
|
---|
| 36 | function GetRawInfo(FileID, DatOffset: Integer): TRawDataInfo; override;
|
---|
| 37 |
|
---|
| 38 | procedure LoadRawFile(FileID, DatOffset: Integer; var Target: TStream); overload; override;
|
---|
| 39 | procedure UpdateRawFile(FileID, DatOffset: Integer; Src: TStream); overload; override;
|
---|
| 40 | procedure LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; var Target: TStream); overload; override;
|
---|
| 41 | procedure UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: TStream); overload; override;
|
---|
[93] | 42 | published
|
---|
[101] | 43 | end;
|
---|
[93] | 44 |
|
---|
| 45 |
|
---|
| 46 | implementation
|
---|
| 47 |
|
---|
[101] | 48 | uses
|
---|
[156] | 49 | SysUtils, Data, Functions, ABSDecUtil, DB, DatLinks, StrUtils;
|
---|
[93] | 50 |
|
---|
[101] | 51 |
|
---|
[93] | 52 | (*
|
---|
| 53 | ================================================================================
|
---|
| 54 | Implementation of TOniDataADB
|
---|
| 55 | *)
|
---|
| 56 |
|
---|
[101] | 57 |
|
---|
| 58 | constructor TAccess_OUP_ADB.Create(DBFilename: String; ConnectionID: Integer; var Msg: TStatusMessages);
|
---|
[93] | 59 | begin
|
---|
[101] | 60 | Msg := SM_UnknownError;
|
---|
| 61 | if not FileExists(DBFilename) then
|
---|
[93] | 62 | begin
|
---|
[101] | 63 | Msg := SM_FileNotFound;
|
---|
[93] | 64 | Exit;
|
---|
| 65 | end;
|
---|
[101] | 66 | FFileName := DBFilename;
|
---|
| 67 |
|
---|
[93] | 68 | FDatabase := TABSDatabase.Create(nil);
|
---|
[134] | 69 | FDatabase.Exclusive := True;
|
---|
| 70 | FDatabase.MultiUser := False;
|
---|
[101] | 71 | FDatabase.DatabaseName := 'OLDBcon' + IntToStr(ConnectionID);
|
---|
| 72 | FDatabase.DatabaseFileName := DBFilename;
|
---|
[93] | 73 | FDatabase.Open;
|
---|
| 74 | FQuery := TABSQuery.Create(FDatabase);
|
---|
[134] | 75 | FQuery.DisableControls;
|
---|
[135] | 76 | FQuery.RequestLive := False;
|
---|
[101] | 77 | FQuery.DatabaseName := 'OLDBcon' + IntToStr(ConnectionID);
|
---|
[93] | 78 | FQuery.SQL.Text := 'SELECT [name],[value] FROM globals ORDER BY [name] ASC';
|
---|
| 79 | FQuery.Open;
|
---|
| 80 | FQuery.First;
|
---|
| 81 | repeat
|
---|
| 82 | if FQuery.FieldByName('name').AsString = 'dbversion' then
|
---|
| 83 | begin
|
---|
| 84 | if FQuery.FieldByName('value').AsString <> DBversion then
|
---|
| 85 | begin
|
---|
[101] | 86 | Msg := SM_IncompatibleDBVersion;
|
---|
[93] | 87 | FQuery.Close;
|
---|
| 88 | Exit;
|
---|
| 89 | end;
|
---|
| 90 | end;
|
---|
| 91 | if FQuery.FieldByName('name').AsString = 'lvl' then
|
---|
[101] | 92 | FLevelNumber := StrToInt(FQuery.FieldByName('value').AsString);
|
---|
| 93 | if FQuery.FieldByName('name').AsString = 'DataOS' then
|
---|
[93] | 94 | begin
|
---|
[101] | 95 | if FQuery.FieldByName('value').AsString = 'WIN' then
|
---|
| 96 | FDataOS := DOS_WIN
|
---|
| 97 | else if FQuery.FieldByName('value').AsString = 'WINDEMO' then
|
---|
| 98 | FDataOS := DOS_WINDEMO
|
---|
| 99 | else if FQuery.FieldByName('value').AsString = 'MAC' then
|
---|
| 100 | FDataOS := DOS_MAC
|
---|
| 101 | else if FQuery.FieldByName('value').AsString = 'MACBETA' then
|
---|
| 102 | FDataOS := DOS_MACBETA;
|
---|
[93] | 103 | end;
|
---|
| 104 | FQuery.Next;
|
---|
| 105 | until FQuery.EOF;
|
---|
| 106 | FQuery.Close;
|
---|
| 107 |
|
---|
[101] | 108 | Msg := SM_OK;
|
---|
| 109 | FBackend := DB_ADB;
|
---|
| 110 |
|
---|
[105] | 111 | FConnectionID := ConnectionID;
|
---|
[101] | 112 | FChangeRights := [CR_EditDat, CR_EditRaw, CR_ResizeDat, CR_ResizeRaw];
|
---|
| 113 |
|
---|
[93] | 114 | UpdateListCache;
|
---|
| 115 | end;
|
---|
| 116 |
|
---|
| 117 |
|
---|
| 118 |
|
---|
| 119 |
|
---|
[101] | 120 | procedure TAccess_OUP_ADB.Close;
|
---|
[93] | 121 | begin
|
---|
[101] | 122 | FQuery.Free;
|
---|
[93] | 123 | FDatabase.Close;
|
---|
| 124 | FDatabase.Free;
|
---|
| 125 | Self.Free;
|
---|
| 126 | end;
|
---|
| 127 |
|
---|
| 128 |
|
---|
| 129 |
|
---|
[101] | 130 | procedure TAccess_OUP_ADB.UpdateListCache;
|
---|
[93] | 131 | var
|
---|
[101] | 132 | i: Integer;
|
---|
[93] | 133 | temps: String;
|
---|
| 134 | begin
|
---|
| 135 | FQuery.SQL.Text := 'SELECT id,name,extension,[size],contenttype FROM datfiles ORDER BY id ASC;';
|
---|
| 136 | FQuery.Open;
|
---|
[101] | 137 | SetLength(Fdat_files, FQuery.RecordCount);
|
---|
[93] | 138 | if FQuery.RecordCount > 0 then
|
---|
| 139 | begin
|
---|
| 140 | FQuery.First;
|
---|
| 141 | i := 0;
|
---|
| 142 | repeat
|
---|
| 143 | Fdat_files[i].ID := FQuery.FieldByName('id').AsInteger;
|
---|
| 144 | Fdat_files[i].Name := FQuery.FieldByName('name').AsString;
|
---|
| 145 | Fdat_files[i].Extension := FQuery.FieldByName('extension').AsString;
|
---|
| 146 | Fdat_files[i].Size := FQuery.FieldByName('size').AsInteger;
|
---|
[113] | 147 | Fdat_files[i].FileType := StrToInt('$'+FQuery.FieldByName('contenttype').AsString);
|
---|
[93] | 148 | Fdat_files[i].DatAddr := 0;
|
---|
| 149 | Inc(i);
|
---|
| 150 | FQuery.Next;
|
---|
| 151 | until FQuery.EOF;
|
---|
| 152 | end;
|
---|
| 153 | FQuery.Close;
|
---|
| 154 |
|
---|
| 155 | FQuery.SQL.Text :=
|
---|
| 156 | 'SELECT extension,count(extension) AS x FROM datfiles GROUP BY extension ORDER BY extension ASC;';
|
---|
| 157 | FQuery.Open;
|
---|
[101] | 158 | SetLength(Fdat_extensionsmap, FQuery.RecordCount);
|
---|
[93] | 159 | if FQuery.RecordCount > 0 then
|
---|
| 160 | begin
|
---|
| 161 | i := 0;
|
---|
| 162 | repeat
|
---|
[101] | 163 | temps := FQuery.FieldByName('extension').AsString;
|
---|
[93] | 164 | Fdat_extensionsmap[i].Extension[3] := temps[1];
|
---|
| 165 | Fdat_extensionsmap[i].Extension[2] := temps[2];
|
---|
| 166 | Fdat_extensionsmap[i].Extension[1] := temps[3];
|
---|
| 167 | Fdat_extensionsmap[i].Extension[0] := temps[4];
|
---|
| 168 | Fdat_extensionsmap[i].ExtCount := FQuery.FieldByName('x').AsInteger;
|
---|
| 169 | Inc(i);
|
---|
| 170 | FQuery.Next;
|
---|
| 171 | until FQuery.EOF;
|
---|
| 172 | end;
|
---|
| 173 | FQuery.Close;
|
---|
| 174 | end;
|
---|
| 175 |
|
---|
| 176 |
|
---|
[106] | 177 |
|
---|
| 178 | function TAccess_OUP_ADB.GetLinksToFile(FileID: Integer): TLinks;
|
---|
| 179 | var
|
---|
| 180 | i: Integer;
|
---|
| 181 | begin
|
---|
| 182 | SetLength(Result.ByName, 0);
|
---|
| 183 | FQuery.SQL.Text := 'SELECT src_link_offset, src_id FROM linkmap WHERE target_id = ' + IntToStr(FileID) + ' ORDER BY src_id ASC;';
|
---|
| 184 | FQuery.Open;
|
---|
| 185 | SetLength(Result.ByID, FQuery.RecordCount);
|
---|
| 186 | if FQuery.RecordCount > 0 then
|
---|
| 187 | begin
|
---|
| 188 | i := 0;
|
---|
| 189 | repeat
|
---|
| 190 | Result.ByID[i].SrcOffset := FQuery.FieldByName('src_link_offset').AsInteger;
|
---|
| 191 | Result.ByID[i].Destination := FQuery.FieldByName('src_id').AsInteger;
|
---|
| 192 | Inc(i);
|
---|
| 193 | FQuery.Next;
|
---|
| 194 | until FQuery.EOF;
|
---|
| 195 | end;
|
---|
| 196 | FQuery.Close;
|
---|
| 197 | end;
|
---|
| 198 |
|
---|
| 199 |
|
---|
| 200 |
|
---|
[101] | 201 | function TAccess_OUP_ADB.GetFileInfo(fileid: Integer): TFileInfo;
|
---|
[93] | 202 | begin
|
---|
| 203 | if fileid = -1 then
|
---|
| 204 | begin
|
---|
| 205 | Result := inherited GetFileInfo(fileid);
|
---|
| 206 | Exit;
|
---|
| 207 | end;
|
---|
[101] | 208 | if fileid < Self.GetFileCount then
|
---|
| 209 | Result := Fdat_files[fileid]
|
---|
[93] | 210 | else
|
---|
| 211 | Result.ID := -1;
|
---|
| 212 | end;
|
---|
| 213 |
|
---|
| 214 |
|
---|
| 215 |
|
---|
[159] | 216 | function CompareItems(List: TStringList; I1, I2: Integer): Integer;
|
---|
| 217 | var
|
---|
| 218 | s1, s2: String;
|
---|
| 219 | begin
|
---|
| 220 | s1 := MidStr(List[I1], 1, PosEx(';', List[I1], 6) - 1);
|
---|
| 221 | s2 := MidStr(List[I2], 1, PosEx(';', List[I2], 6) - 1);
|
---|
| 222 | Result := CompareStr(s1, s2);
|
---|
| 223 | end;
|
---|
| 224 |
|
---|
[101] | 225 | function TAccess_OUP_ADB.GetFilesList(ext: String; pattern: String;
|
---|
| 226 | NoEmptyFiles: Boolean; SortType: TSortType): TStrings;
|
---|
[93] | 227 | var
|
---|
[101] | 228 | i: Integer;
|
---|
| 229 | list: TStringList;
|
---|
[93] | 230 | id, name, extension: String;
|
---|
| 231 | fields: TStrings;
|
---|
| 232 |
|
---|
| 233 | procedure getfields;
|
---|
| 234 | begin
|
---|
[101] | 235 | fields.CommaText := StringReplace(AnsiQuotedStr(list.Strings[i], '"'), ';', '","', [rfReplaceAll]);
|
---|
| 236 | if SortType in [ST_IDAsc, ST_IDDesc] then
|
---|
[93] | 237 | begin
|
---|
| 238 | id := fields.Strings[0];
|
---|
| 239 | name := fields.Strings[1];
|
---|
| 240 | extension := fields.Strings[2];
|
---|
| 241 | end;
|
---|
[101] | 242 | if SortType in [ST_NameAsc, ST_NameDesc] then
|
---|
[93] | 243 | begin
|
---|
| 244 | id := fields.Strings[1];
|
---|
| 245 | name := fields.Strings[0];
|
---|
| 246 | extension := fields.Strings[2];
|
---|
| 247 | end;
|
---|
[101] | 248 | if SortType in [ST_ExtAsc, ST_ExtDesc] then
|
---|
[93] | 249 | begin
|
---|
| 250 | id := fields.Strings[1];
|
---|
| 251 | name := fields.Strings[2];
|
---|
| 252 | extension := fields.Strings[0];
|
---|
| 253 | end;
|
---|
[112] | 254 | if SortType in [ST_ExtNameAsc, ST_ExtNameDesc] then
|
---|
| 255 | begin
|
---|
| 256 | id := fields.Strings[2];
|
---|
| 257 | name := fields.Strings[1];
|
---|
| 258 | extension := fields.Strings[0];
|
---|
| 259 | end;
|
---|
[93] | 260 | end;
|
---|
| 261 |
|
---|
| 262 | begin
|
---|
[159] | 263 | list := TStringList.Create;
|
---|
| 264 | if SortType in [ST_ExtNameAsc, ST_ExtNameDesc] then
|
---|
| 265 | list.Sorted := False
|
---|
| 266 | else
|
---|
| 267 | list.Sorted := True;
|
---|
| 268 | for i := 0 to GetFileCount - 1 do
|
---|
[157] | 269 | begin
|
---|
[159] | 270 | if ((Length(ext) = 0) or (Pos(Fdat_files[i].Extension, ext) > 0)) and
|
---|
| 271 | ((Length(pattern) = 0) or
|
---|
| 272 | (Pos(UpperCase(pattern), UpperCase(Fdat_files[i].Name)) > 0)) then
|
---|
[93] | 273 | begin
|
---|
[159] | 274 | if (NoEmptyFiles = False) or ((Fdat_files[i].FileType and $02) = 0) then
|
---|
[93] | 275 | begin
|
---|
[159] | 276 | id := FormatNumber(Fdat_files[i].ID, 5, '0');
|
---|
| 277 | name := Fdat_files[i].Name;
|
---|
| 278 | extension := Fdat_files[i].Extension;
|
---|
[93] | 279 |
|
---|
[159] | 280 | case SortType of
|
---|
| 281 | ST_IDAsc, ST_IDDesc: list.Add(id + ';' + name + ';' + extension);
|
---|
| 282 | ST_NameAsc, ST_NameDesc: list.Add(name + ';' + id + ';' + extension);
|
---|
| 283 | ST_ExtAsc, ST_ExtDesc: list.Add(extension + ';' + id + ';' + name);
|
---|
| 284 | ST_ExtNameAsc, ST_ExtNameDesc: list.Add(extension + ';' + name + ';' + id);
|
---|
[93] | 285 | end;
|
---|
| 286 | end;
|
---|
| 287 | end;
|
---|
[159] | 288 | end;
|
---|
| 289 | if SortType in [ST_ExtNameAsc, ST_ExtNameDesc] then
|
---|
| 290 | list.CustomSort(CompareItems);
|
---|
| 291 | if not Assigned(Result) then
|
---|
| 292 | Result := TStringList.Create;
|
---|
| 293 | if list.Count > 0 then
|
---|
[101] | 294 | begin
|
---|
[159] | 295 | fields := TStringList.Create;
|
---|
| 296 | if SortType in [ST_IDAsc, ST_NameAsc, ST_ExtAsc, ST_ExtNameAsc] then
|
---|
| 297 | for i := 0 to list.Count - 1 do
|
---|
| 298 | begin
|
---|
| 299 | getfields;
|
---|
| 300 | Result.Add(id + '-' + name + '.' + extension);
|
---|
| 301 | end
|
---|
| 302 | else
|
---|
| 303 | for i := list.Count - 1 downto 0 do
|
---|
| 304 | begin
|
---|
| 305 | getfields;
|
---|
| 306 | Result.Add(id + '-' + name + '.' + extension);
|
---|
| 307 | end;
|
---|
| 308 | fields.Free;
|
---|
[101] | 309 | end;
|
---|
[159] | 310 | list.Free;
|
---|
[93] | 311 | end;
|
---|
| 312 |
|
---|
| 313 |
|
---|
| 314 |
|
---|
| 315 |
|
---|
[101] | 316 | function TAccess_OUP_ADB.GetFileCount: Integer;
|
---|
[93] | 317 | begin
|
---|
| 318 | Result := Length(Fdat_files);
|
---|
| 319 | end;
|
---|
| 320 |
|
---|
| 321 |
|
---|
[101] | 322 | function TAccess_OUP_ADB.GetExtensionsList(ExtListFormat: TExtensionFormat): TStrings;
|
---|
[93] | 323 | var
|
---|
[101] | 324 | i: Integer;
|
---|
[93] | 325 | begin
|
---|
[113] | 326 | if not Assigned(Result) then
|
---|
| 327 | Result := TStringList.Create;
|
---|
| 328 | if Result is TStringList then
|
---|
| 329 | TStringList(Result).Sorted := True;
|
---|
[101] | 330 | for i := 0 to Length(Fdat_extensionsmap) - 1 do
|
---|
[93] | 331 | begin
|
---|
| 332 | with Fdat_extensionsmap[i] do
|
---|
| 333 | begin
|
---|
[101] | 334 | case ExtListFormat of
|
---|
| 335 | EF_ExtOnly:
|
---|
| 336 | Result.Add(Extension[3] + Extension[2] + Extension[1] + Extension[0]);
|
---|
| 337 | EF_ExtCount:
|
---|
| 338 | Result.Add(Extension[3] + Extension[2] + Extension[1] + Extension[0] +
|
---|
| 339 | ' (' + IntToStr(ExtCount) + ')');
|
---|
| 340 | end;
|
---|
[93] | 341 | end;
|
---|
| 342 | end;
|
---|
| 343 | end;
|
---|
| 344 |
|
---|
| 345 |
|
---|
[101] | 346 | procedure TAccess_OUP_ADB.LoadDatFile(FileID: Integer; var Target: TStream);
|
---|
[93] | 347 | var
|
---|
[101] | 348 | mem: TStream;
|
---|
| 349 | streampos: Integer;
|
---|
[93] | 350 | begin
|
---|
[101] | 351 | if fileid < GetFileCount then
|
---|
[93] | 352 | begin
|
---|
[101] | 353 | if not Assigned(Target) then
|
---|
| 354 | Target := TMemoryStream.Create;
|
---|
[93] | 355 |
|
---|
[101] | 356 | streampos := Target.Position;
|
---|
[93] | 357 |
|
---|
| 358 | FQuery.SQL.Text := 'SELECT data FROM datfiles WHERE id=' + IntToStr(fileid) + ';';
|
---|
| 359 | FQuery.Open;
|
---|
| 360 | if FQuery.RecordCount > 0 then
|
---|
| 361 | begin
|
---|
| 362 | mem := FQuery.CreateBlobStream(FQuery.FieldByName('data'), bmRead);
|
---|
| 363 | mem.Seek(0, soFromBeginning);
|
---|
[101] | 364 | Target.CopyFrom(mem, mem.Size);
|
---|
[93] | 365 | mem.Free;
|
---|
| 366 | end;
|
---|
| 367 | FQuery.Close;
|
---|
[101] | 368 |
|
---|
| 369 | Target.Seek(streampos, soFromBeginning);
|
---|
[93] | 370 | end;
|
---|
| 371 | end;
|
---|
| 372 |
|
---|
[101] | 373 | procedure TAccess_OUP_ADB.UpdateDatFile(FileID: Integer; Src: TStream);
|
---|
[93] | 374 | var
|
---|
| 375 | MimeCoder: TStringFormat_MIME64;
|
---|
| 376 | mem: TMemoryStream;
|
---|
| 377 | begin
|
---|
[101] | 378 | if fileid < GetFileCount then
|
---|
[93] | 379 | begin
|
---|
| 380 | mimecoder := TStringFormat_MIME64.Create;
|
---|
| 381 | mem := TMemoryStream.Create;
|
---|
[101] | 382 | mem.CopyFrom(Src, Src.Size);
|
---|
[93] | 383 | FQuery.SQL.Text := 'UPDATE datfiles SET data=MimeToBin("' +
|
---|
| 384 | MimeCoder.StrTo(mem.Memory, mem.Size) + '"), size=' + IntToStr(mem.Size) +
|
---|
| 385 | ' WHERE id=' + IntToStr(fileid) + ';';
|
---|
| 386 | FQuery.ExecSQL;
|
---|
| 387 | mem.Free;
|
---|
| 388 | mimecoder.Free;
|
---|
| 389 | end;
|
---|
| 390 | end;
|
---|
| 391 |
|
---|
| 392 |
|
---|
| 393 |
|
---|
[101] | 394 | procedure TAccess_OUP_ADB.LoadDatFilePart(FileID, Offset, Size: Integer; var Target: TStream);
|
---|
[93] | 395 | var
|
---|
[101] | 396 | streampos: Integer;
|
---|
[93] | 397 | mem: TStream;
|
---|
| 398 | begin
|
---|
[101] | 399 | if fileid < GetFileCount then
|
---|
[93] | 400 | begin
|
---|
[101] | 401 | if not Assigned(Target) then
|
---|
| 402 | Target := TMemoryStream.Create;
|
---|
| 403 | streampos := Target.Position;
|
---|
| 404 |
|
---|
[93] | 405 | FQuery.SQL.Text := 'SELECT data FROM datfiles WHERE id=' + IntToStr(fileid) + ';';
|
---|
| 406 | FQuery.Open;
|
---|
| 407 | if FQuery.RecordCount > 0 then
|
---|
| 408 | begin
|
---|
| 409 | mem := FQuery.CreateBlobStream(FQuery.FieldByName('data'), bmRead);
|
---|
| 410 | mem.Seek(offset, soFromBeginning);
|
---|
[101] | 411 | Target.CopyFrom(mem, size);
|
---|
[93] | 412 | mem.Free;
|
---|
| 413 | end;
|
---|
| 414 | FQuery.Close;
|
---|
[101] | 415 | Target.Seek(streampos, soFromBeginning);
|
---|
[93] | 416 | end;
|
---|
| 417 | end;
|
---|
| 418 |
|
---|
| 419 |
|
---|
| 420 |
|
---|
[101] | 421 | procedure TAccess_OUP_ADB.UpdateDatFilePart(FileID, Offset, Size: Integer; Src: TStream);
|
---|
[93] | 422 | var
|
---|
| 423 | MimeCoder: TStringFormat_MIME64;
|
---|
| 424 | mem: TMemoryStream;
|
---|
| 425 | begin
|
---|
[101] | 426 | if fileid < GetFileCount then
|
---|
[93] | 427 | begin
|
---|
[101] | 428 | mem := nil;
|
---|
| 429 | LoadDatFile(fileid, TStream(mem));
|
---|
| 430 | mem.Seek(Offset, soFromBeginning);
|
---|
| 431 | mem.CopyFrom(Src, Size);
|
---|
| 432 | mem.Seek(0, soFromBeginning);
|
---|
[93] | 433 | mimecoder := TStringFormat_MIME64.Create;
|
---|
| 434 | FQuery.SQL.Text := 'UPDATE datfiles SET data=MimeToBin("' +
|
---|
| 435 | MimeCoder.StrTo(mem.Memory, mem.Size) + '") WHERE id=' + IntToStr(fileid) + ';';
|
---|
| 436 | FQuery.ExecSQL;
|
---|
| 437 | mem.Free;
|
---|
| 438 | mimecoder.Free;
|
---|
| 439 | end;
|
---|
| 440 | end;
|
---|
| 441 |
|
---|
| 442 |
|
---|
[116] | 443 |
|
---|
| 444 | function TAccess_OUP_ADB.GetDatLink(FileID, DatOffset: Integer): TDatLink;
|
---|
| 445 | begin
|
---|
| 446 | Result := DatLinksManager.GetDatLink(FConnectionID, FileID, DatOffset);
|
---|
| 447 | FQuery.SQL.Text := 'SELECT target_id FROM linkmap WHERE src_id = ' + IntToStr(FileID) + ' and src_link_offset = ' + IntToStr(DatOffset) + ';';
|
---|
| 448 | FQuery.Open;
|
---|
| 449 | if FQuery.RecordCount > 0 then
|
---|
| 450 | Result.DestID := FQuery.FieldByName('target_id').AsInteger;
|
---|
| 451 | FQuery.Close;
|
---|
| 452 | end;
|
---|
| 453 |
|
---|
| 454 |
|
---|
| 455 | function TAccess_OUP_ADB.GetDatLinks(FileID: Integer): TDatLinkList;
|
---|
| 456 | var
|
---|
| 457 | i: Integer;
|
---|
| 458 | SrcOffset, DestID: Integer;
|
---|
| 459 | begin
|
---|
| 460 | Result := DatLinksManager.GetDatLinks(FConnectionID, FileID);
|
---|
| 461 | if Length(Result) > 0 then
|
---|
| 462 | begin
|
---|
| 463 | FQuery.SQL.Text := 'SELECT src_link_offset, target_id FROM linkmap WHERE src_id = ' + IntToStr(FileID) + ' ORDER BY src_link_offset ASC;';
|
---|
| 464 | FQuery.Open;
|
---|
| 465 | if FQuery.RecordCount > 0 then
|
---|
| 466 | begin
|
---|
| 467 | repeat
|
---|
| 468 | SrcOffset := FQuery.FieldByName('src_link_offset').AsInteger;
|
---|
| 469 | DestID := FQuery.FieldByName('target_id').AsInteger;
|
---|
| 470 | for i := 0 to High(Result) do
|
---|
| 471 | if Result[i].SrcOffset = SrcOffset then
|
---|
| 472 | Break;
|
---|
| 473 | if i < Length(Result) then
|
---|
| 474 | Result[i].DestID := DestID
|
---|
| 475 | else
|
---|
| 476 | Result[i].DestID := -1;
|
---|
| 477 | FQuery.Next;
|
---|
| 478 | until FQuery.EOF;
|
---|
| 479 | end;
|
---|
| 480 | FQuery.Close;
|
---|
| 481 | end;
|
---|
| 482 | end;
|
---|
| 483 |
|
---|
| 484 |
|
---|
[101] | 485 | function TAccess_OUP_ADB.GetRawList(FileID: Integer): TRawDataList;
|
---|
[93] | 486 | var
|
---|
[101] | 487 | i: Integer;
|
---|
[93] | 488 | begin
|
---|
| 489 | SetLength(Result, 0);
|
---|
| 490 | FQuery.SQL.Text := 'SELECT [src_link_offset],[size],[sep] FROM rawmap WHERE [src_id]=' +
|
---|
| 491 | IntToStr(fileid) + ' ORDER BY src_link_offset ASC;';
|
---|
| 492 | FQuery.Open;
|
---|
| 493 | if FQuery.RecordCount > 0 then
|
---|
| 494 | begin
|
---|
| 495 | FQuery.First;
|
---|
| 496 | SetLength(Result, FQuery.RecordCount);
|
---|
| 497 | i := 0;
|
---|
| 498 | repeat
|
---|
[101] | 499 | Result[i].SrcID := fileid;
|
---|
| 500 | Result[i].SrcOffset := FQuery.FieldByName('src_link_offset').AsInteger;
|
---|
| 501 | Result[i].RawAddr := 0;
|
---|
| 502 | Result[i].RawSize := FQuery.FieldByName('size').AsInteger;
|
---|
| 503 | Result[i].LocSep := FQuery.FieldByName('sep').AsBoolean;
|
---|
[93] | 504 | Inc(i);
|
---|
| 505 | FQuery.Next;
|
---|
| 506 | until FQuery.EOF;
|
---|
| 507 | end;
|
---|
| 508 | FQuery.Close;
|
---|
| 509 | end;
|
---|
| 510 |
|
---|
| 511 |
|
---|
[101] | 512 | function TAccess_OUP_ADB.GetRawInfo(FileID, DatOffset: Integer): TRawDataInfo;
|
---|
| 513 | var
|
---|
| 514 | i: Integer;
|
---|
| 515 | rawlist: TRawDataList;
|
---|
| 516 | begin
|
---|
| 517 | rawlist := GetRawList(FileID);
|
---|
| 518 | if Length(rawlist) > 0 then
|
---|
| 519 | begin
|
---|
| 520 | for i := 0 to High(rawlist) do
|
---|
| 521 | if rawlist[i].SrcOffset = DatOffset then
|
---|
| 522 | Break;
|
---|
| 523 | if i < Length(rawlist) then
|
---|
| 524 | Result := rawlist[i]
|
---|
| 525 | else begin
|
---|
| 526 | Result.SrcID := -1;
|
---|
| 527 | Result.SrcOffset := -1;
|
---|
| 528 | Result.RawAddr := -1;
|
---|
| 529 | Result.RawSize := -1;
|
---|
| 530 | end;
|
---|
| 531 | end;
|
---|
| 532 | end;
|
---|
[93] | 533 |
|
---|
| 534 |
|
---|
[101] | 535 |
|
---|
| 536 | procedure TAccess_OUP_ADB.LoadRawFile(FileID, DatOffset: Integer; var Target: TStream);
|
---|
[93] | 537 | var
|
---|
| 538 | mem: TStream;
|
---|
[101] | 539 | streampos: Integer;
|
---|
[93] | 540 | begin
|
---|
[101] | 541 | if fileid < GetFileCount then
|
---|
[93] | 542 | begin
|
---|
[101] | 543 | if not Assigned(Target) then
|
---|
| 544 | Target := TMemoryStream.Create;
|
---|
| 545 | streampos := Target.Position;
|
---|
[93] | 546 | FQuery.SQL.Text := 'SELECT data FROM rawmap WHERE (src_id=' +
|
---|
[101] | 547 | IntToStr(FileID) + ') AND (src_link_offset=' + IntToStr(DatOffset) + ');';
|
---|
[93] | 548 | FQuery.Open;
|
---|
| 549 | if FQuery.RecordCount > 0 then
|
---|
| 550 | begin
|
---|
| 551 | mem := FQuery.CreateBlobStream(FQuery.FieldByName('data'), bmRead);
|
---|
| 552 | mem.Seek(0, soFromBeginning);
|
---|
[101] | 553 | Target.CopyFrom(mem, mem.Size);
|
---|
[93] | 554 | mem.Free;
|
---|
| 555 | end;
|
---|
| 556 | FQuery.Close;
|
---|
[101] | 557 | Target.Seek(streampos, soFromBeginning);
|
---|
[93] | 558 | end;
|
---|
| 559 | end;
|
---|
| 560 |
|
---|
| 561 |
|
---|
[101] | 562 | procedure TAccess_OUP_ADB.UpdateRawFile(FileID, DatOffset: Integer; Src: TStream);
|
---|
[93] | 563 | var
|
---|
| 564 | MimeCoder: TStringFormat_MIME64;
|
---|
| 565 | mem: TMemoryStream;
|
---|
| 566 | begin
|
---|
[101] | 567 | if fileid < GetFileCount then
|
---|
[93] | 568 | begin
|
---|
| 569 | mimecoder := TStringFormat_MIME64.Create;
|
---|
| 570 | mem := TMemoryStream.Create;
|
---|
[101] | 571 | mem.CopyFrom(Src, Src.Size);
|
---|
[93] | 572 | mem.Seek(0, soFromBeginning);
|
---|
| 573 | FQuery.SQL.Text := 'UPDATE rawmap SET data=MimeToBin("' + MimeCoder.StrTo(
|
---|
[101] | 574 | mem.Memory, mem.Size) + '") WHERE (src_id=' + IntToStr(FileID) +
|
---|
| 575 | ') AND (src_link_offset=' + IntToStr(DatOffset) + ');';
|
---|
[93] | 576 | FQuery.ExecSQL;
|
---|
| 577 | mem.Free;
|
---|
| 578 | mimecoder.Free;
|
---|
| 579 | end;
|
---|
| 580 | end;
|
---|
| 581 |
|
---|
| 582 |
|
---|
| 583 |
|
---|
| 584 |
|
---|
[101] | 585 | procedure TAccess_OUP_ADB.LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; var Target: TStream);
|
---|
[93] | 586 | var
|
---|
| 587 | mem: TMemoryStream;
|
---|
[101] | 588 | streampos: Integer;
|
---|
[93] | 589 | begin
|
---|
[101] | 590 | if fileid < GetFileCount then
|
---|
[93] | 591 | begin
|
---|
[101] | 592 | if not Assigned(Target) then
|
---|
| 593 | Target := TMemoryStream.Create;
|
---|
| 594 | streampos := Target.Position;
|
---|
| 595 | mem := nil;
|
---|
| 596 | LoadRawFile(FileID, DatOffset, TStream(mem));
|
---|
| 597 | mem.Seek(Offset, soFromBeginning);
|
---|
| 598 | Target.CopyFrom(mem, Size);
|
---|
[93] | 599 | mem.Free;
|
---|
[101] | 600 | Target.Seek(streampos, soFromBeginning);
|
---|
[93] | 601 | end;
|
---|
| 602 | end;
|
---|
| 603 |
|
---|
| 604 |
|
---|
| 605 |
|
---|
| 606 |
|
---|
[101] | 607 | procedure TAccess_OUP_ADB.UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: TStream);
|
---|
[93] | 608 | var
|
---|
| 609 | MimeCoder: TStringFormat_MIME64;
|
---|
| 610 | mem: TMemoryStream;
|
---|
| 611 | begin
|
---|
[101] | 612 | if fileid < GetFileCount then
|
---|
[93] | 613 | begin
|
---|
[101] | 614 | mem := nil;
|
---|
| 615 | LoadRawFile(fileid, offset, TStream(mem));
|
---|
[93] | 616 | mem.Seek(offset, soFromBeginning);
|
---|
[101] | 617 | mem.CopyFrom(Src, Size);
|
---|
[93] | 618 | mem.Seek(0, soFromBeginning);
|
---|
[101] | 619 | mimecoder := TStringFormat_MIME64.Create;
|
---|
[93] | 620 | FQuery.SQL.Text := 'UPDATE rawmap SET data=MimeToBin("' + MimeCoder.StrTo(
|
---|
| 621 | mem.Memory, mem.Size) + '") WHERE (src_id=' + IntToStr(fileid) +
|
---|
[101] | 622 | ') AND (src_link_offset=' + IntToStr(DatOffset) + ');';
|
---|
[93] | 623 | FQuery.ExecSQL;
|
---|
| 624 | mem.Free;
|
---|
| 625 | mimecoder.Free;
|
---|
| 626 | end;
|
---|
| 627 | end;
|
---|
| 628 |
|
---|
| 629 |
|
---|
| 630 |
|
---|
[101] | 631 |
|
---|
[93] | 632 | end.
|
---|