| 18 |
|
procedure UpdateListCache; |
| 19 |
|
|
| 20 |
|
function GetLinksToFile(FileID: Integer): TLinks; |
| 21 |
– |
function GetLinksFromFile(FileID: Integer): TLinks; |
| 21 |
|
|
| 22 |
|
function GetFileInfo(FileID: Integer): TFileInfo; override; |
| 23 |
|
function GetFilesList(Ext: String; Pattern: String; |
| 30 |
|
procedure LoadDatFilePart(FileID, Offset, Size: Integer; var Target: TStream); overload; override; |
| 31 |
|
procedure UpdateDatFilePart(FileID, Offset, Size: Integer; Src: TStream); overload; override; |
| 32 |
|
|
| 33 |
+ |
function GetDatLinks(FileID: Integer): TDatLinkList; override; |
| 34 |
+ |
function GetDatLink(FileID, DatOffset: Integer): TDatLink; override; |
| 35 |
|
function GetRawList(FileID: Integer): TRawDataList; override; |
| 36 |
|
function GetRawInfo(FileID, DatOffset: Integer): TRawDataInfo; override; |
| 37 |
+ |
function GetRawsForType(RawType: String): TRawDataList; override; |
| 38 |
|
|
| 39 |
|
procedure LoadRawFile(FileID, DatOffset: Integer; var Target: TStream); overload; override; |
| 40 |
|
procedure UpdateRawFile(FileID, DatOffset: Integer; Src: TStream); overload; override; |
| 47 |
|
implementation |
| 48 |
|
|
| 49 |
|
uses |
| 50 |
< |
SysUtils, Data, Functions, ABSDecUtil, DB; |
| 50 |
> |
SysUtils, Data, Functions, ABSDecUtil, DB, DatLinks, StrUtils; |
| 51 |
|
|
| 52 |
|
|
| 53 |
|
(* |
| 57 |
|
|
| 58 |
|
|
| 59 |
|
constructor TAccess_OUP_ADB.Create(DBFilename: String; ConnectionID: Integer; var Msg: TStatusMessages); |
| 58 |
– |
var |
| 59 |
– |
i: Integer; |
| 60 |
|
begin |
| 61 |
|
Msg := SM_UnknownError; |
| 62 |
|
if not FileExists(DBFilename) then |
| 67 |
|
FFileName := DBFilename; |
| 68 |
|
|
| 69 |
|
FDatabase := TABSDatabase.Create(nil); |
| 70 |
+ |
FDatabase.Exclusive := True; |
| 71 |
+ |
FDatabase.MultiUser := False; |
| 72 |
|
FDatabase.DatabaseName := 'OLDBcon' + IntToStr(ConnectionID); |
| 73 |
|
FDatabase.DatabaseFileName := DBFilename; |
| 74 |
|
FDatabase.Open; |
| 75 |
|
FQuery := TABSQuery.Create(FDatabase); |
| 76 |
+ |
FQuery.DisableControls; |
| 77 |
+ |
FQuery.RequestLive := False; |
| 78 |
|
FQuery.DatabaseName := 'OLDBcon' + IntToStr(ConnectionID); |
| 79 |
|
FQuery.SQL.Text := 'SELECT [name],[value] FROM globals ORDER BY [name] ASC'; |
| 80 |
|
FQuery.Open; |
| 91 |
|
end; |
| 92 |
|
if FQuery.FieldByName('name').AsString = 'lvl' then |
| 93 |
|
FLevelNumber := StrToInt(FQuery.FieldByName('value').AsString); |
| 94 |
< |
if FQuery.FieldByName('name').AsString = 'DataOS' then |
| 94 |
> |
if FQuery.FieldByName('name').AsString = 'os' then |
| 95 |
|
begin |
| 96 |
|
if FQuery.FieldByName('value').AsString = 'WIN' then |
| 97 |
|
FDataOS := DOS_WIN |
| 113 |
|
FChangeRights := [CR_EditDat, CR_EditRaw, CR_ResizeDat, CR_ResizeRaw]; |
| 114 |
|
|
| 115 |
|
UpdateListCache; |
| 116 |
+ |
|
| 117 |
+ |
inherited; |
| 118 |
|
end; |
| 119 |
|
|
| 120 |
|
|
| 147 |
|
Fdat_files[i].Name := FQuery.FieldByName('name').AsString; |
| 148 |
|
Fdat_files[i].Extension := FQuery.FieldByName('extension').AsString; |
| 149 |
|
Fdat_files[i].Size := FQuery.FieldByName('size').AsInteger; |
| 150 |
< |
Fdat_files[i].FileType := HexToLong(FQuery.FieldByName('contenttype').AsString); |
| 150 |
> |
Fdat_files[i].FileType := StrToInt('$'+FQuery.FieldByName('contenttype').AsString); |
| 151 |
|
Fdat_files[i].DatAddr := 0; |
| 152 |
|
Inc(i); |
| 153 |
|
FQuery.Next; |
| 199 |
|
FQuery.Close; |
| 200 |
|
end; |
| 201 |
|
|
| 196 |
– |
function TAccess_OUP_ADB.GetLinksFromFile(FileID: Integer): TLinks; |
| 197 |
– |
var |
| 198 |
– |
i: Integer; |
| 199 |
– |
begin |
| 200 |
– |
SetLength(Result.ByName, 0); |
| 201 |
– |
FQuery.SQL.Text := 'SELECT src_link_offset, target_id FROM linkmap WHERE src_id = ' + IntToStr(FileID) + ' ORDER BY target_id ASC;'; |
| 202 |
– |
FQuery.Open; |
| 203 |
– |
SetLength(Result.ByID, FQuery.RecordCount); |
| 204 |
– |
if FQuery.RecordCount > 0 then |
| 205 |
– |
begin |
| 206 |
– |
i := 0; |
| 207 |
– |
repeat |
| 208 |
– |
Result.ByID[i].SrcOffset := FQuery.FieldByName('src_link_offset').AsInteger; |
| 209 |
– |
Result.ByID[i].Destination := FQuery.FieldByName('target_id').AsInteger; |
| 210 |
– |
Inc(i); |
| 211 |
– |
FQuery.Next; |
| 212 |
– |
until FQuery.EOF; |
| 213 |
– |
end; |
| 214 |
– |
FQuery.Close; |
| 215 |
– |
end; |
| 216 |
– |
|
| 202 |
|
|
| 203 |
|
|
| 204 |
|
function TAccess_OUP_ADB.GetFileInfo(fileid: Integer): TFileInfo; |
| 216 |
|
|
| 217 |
|
|
| 218 |
|
|
| 219 |
+ |
function CompareItems(List: TStringList; I1, I2: Integer): Integer; |
| 220 |
+ |
var |
| 221 |
+ |
s1, s2: String; |
| 222 |
+ |
begin |
| 223 |
+ |
s1 := MidStr(List[I1], 1, PosEx(';', List[I1], 6) - 1); |
| 224 |
+ |
s2 := MidStr(List[I2], 1, PosEx(';', List[I2], 6) - 1); |
| 225 |
+ |
Result := CompareStr(s1, s2); |
| 226 |
+ |
end; |
| 227 |
|
|
| 228 |
|
function TAccess_OUP_ADB.GetFilesList(ext: String; pattern: String; |
| 229 |
|
NoEmptyFiles: Boolean; SortType: TSortType): TStrings; |
| 264 |
|
|
| 265 |
|
begin |
| 266 |
|
list := TStringList.Create; |
| 267 |
< |
list.Sorted := True; |
| 267 |
> |
if SortType in [ST_ExtNameAsc, ST_ExtNameDesc] then |
| 268 |
> |
list.Sorted := False |
| 269 |
> |
else |
| 270 |
> |
list.Sorted := True; |
| 271 |
> |
if ext = '*' then |
| 272 |
> |
ext := ''; |
| 273 |
|
for i := 0 to GetFileCount - 1 do |
| 274 |
|
begin |
| 275 |
|
if ((Length(ext) = 0) or (Pos(Fdat_files[i].Extension, ext) > 0)) and |
| 286 |
|
ST_IDAsc, ST_IDDesc: list.Add(id + ';' + name + ';' + extension); |
| 287 |
|
ST_NameAsc, ST_NameDesc: list.Add(name + ';' + id + ';' + extension); |
| 288 |
|
ST_ExtAsc, ST_ExtDesc: list.Add(extension + ';' + id + ';' + name); |
| 289 |
< |
ST_ExtNameAsc, ST_ExtNameDesc: list.Add(name + ';' + extension + ';' + id); |
| 289 |
> |
ST_ExtNameAsc, ST_ExtNameDesc: list.Add(extension + ';' + name + ';' + id); |
| 290 |
|
end; |
| 291 |
|
end; |
| 292 |
|
end; |
| 293 |
|
end; |
| 294 |
< |
Result := TStringList.Create; |
| 294 |
> |
if SortType in [ST_ExtNameAsc, ST_ExtNameDesc] then |
| 295 |
> |
list.CustomSort(CompareItems); |
| 296 |
> |
if not Assigned(Result) then |
| 297 |
> |
Result := TStringList.Create; |
| 298 |
|
if list.Count > 0 then |
| 299 |
|
begin |
| 300 |
|
fields := TStringList.Create; |
| 328 |
|
var |
| 329 |
|
i: Integer; |
| 330 |
|
begin |
| 331 |
< |
Result := TStringList.Create; |
| 331 |
> |
if not Assigned(Result) then |
| 332 |
> |
Result := TStringList.Create; |
| 333 |
> |
if Result is TStringList then |
| 334 |
> |
TStringList(Result).Sorted := True; |
| 335 |
|
for i := 0 to Length(Fdat_extensionsmap) - 1 do |
| 336 |
|
begin |
| 337 |
|
with Fdat_extensionsmap[i] do |
| 445 |
|
end; |
| 446 |
|
|
| 447 |
|
|
| 448 |
+ |
|
| 449 |
+ |
function TAccess_OUP_ADB.GetDatLink(FileID, DatOffset: Integer): TDatLink; |
| 450 |
+ |
begin |
| 451 |
+ |
Result := DatLinksManager.GetDatLink(FConnectionID, FileID, DatOffset); |
| 452 |
+ |
FQuery.SQL.Text := 'SELECT target_id FROM linkmap WHERE src_id = ' + IntToStr(FileID) + ' and src_link_offset = ' + IntToStr(DatOffset) + ';'; |
| 453 |
+ |
FQuery.Open; |
| 454 |
+ |
if FQuery.RecordCount > 0 then |
| 455 |
+ |
Result.DestID := FQuery.FieldByName('target_id').AsInteger; |
| 456 |
+ |
FQuery.Close; |
| 457 |
+ |
end; |
| 458 |
+ |
|
| 459 |
+ |
|
| 460 |
+ |
function TAccess_OUP_ADB.GetDatLinks(FileID: Integer): TDatLinkList; |
| 461 |
+ |
var |
| 462 |
+ |
i: Integer; |
| 463 |
+ |
SrcOffset, DestID: Integer; |
| 464 |
+ |
begin |
| 465 |
+ |
Result := DatLinksManager.GetDatLinks(FConnectionID, FileID); |
| 466 |
+ |
if Length(Result) > 0 then |
| 467 |
+ |
begin |
| 468 |
+ |
FQuery.SQL.Text := 'SELECT src_link_offset, target_id FROM linkmap WHERE src_id = ' + IntToStr(FileID) + ' ORDER BY src_link_offset ASC;'; |
| 469 |
+ |
FQuery.Open; |
| 470 |
+ |
if FQuery.RecordCount > 0 then |
| 471 |
+ |
begin |
| 472 |
+ |
repeat |
| 473 |
+ |
SrcOffset := FQuery.FieldByName('src_link_offset').AsInteger; |
| 474 |
+ |
DestID := FQuery.FieldByName('target_id').AsInteger; |
| 475 |
+ |
for i := 0 to High(Result) do |
| 476 |
+ |
if Result[i].SrcOffset = SrcOffset then |
| 477 |
+ |
Break; |
| 478 |
+ |
if i < Length(Result) then |
| 479 |
+ |
Result[i].DestID := DestID |
| 480 |
+ |
else |
| 481 |
+ |
Result[i].DestID := -1; |
| 482 |
+ |
FQuery.Next; |
| 483 |
+ |
until FQuery.EOF; |
| 484 |
+ |
end; |
| 485 |
+ |
FQuery.Close; |
| 486 |
+ |
end; |
| 487 |
+ |
end; |
| 488 |
+ |
|
| 489 |
+ |
|
| 490 |
|
function TAccess_OUP_ADB.GetRawList(FileID: Integer): TRawDataList; |
| 491 |
|
var |
| 492 |
|
i: Integer; |
| 493 |
|
begin |
| 494 |
|
SetLength(Result, 0); |
| 495 |
< |
FQuery.SQL.Text := 'SELECT [src_link_offset],[size],[sep] FROM rawmap WHERE [src_id]=' + |
| 495 |
> |
FQuery.SQL.Text := 'SELECT [src_link_offset],[name],[size],[sep],[type] FROM rawmap WHERE [src_id]=' + |
| 496 |
|
IntToStr(fileid) + ' ORDER BY src_link_offset ASC;'; |
| 497 |
|
FQuery.Open; |
| 498 |
|
if FQuery.RecordCount > 0 then |
| 501 |
|
SetLength(Result, FQuery.RecordCount); |
| 502 |
|
i := 0; |
| 503 |
|
repeat |
| 504 |
+ |
Result[i].Name := FQuery.FieldByName('name').AsString; |
| 505 |
|
Result[i].SrcID := fileid; |
| 506 |
|
Result[i].SrcOffset := FQuery.FieldByName('src_link_offset').AsInteger; |
| 507 |
|
Result[i].RawAddr := 0; |
| 508 |
|
Result[i].RawSize := FQuery.FieldByName('size').AsInteger; |
| 509 |
|
Result[i].LocSep := FQuery.FieldByName('sep').AsBoolean; |
| 510 |
+ |
Result[i].RawType := FQuery.FieldByName('type').AsString; |
| 511 |
|
Inc(i); |
| 512 |
|
FQuery.Next; |
| 513 |
|
until FQuery.EOF; |
| 530 |
|
if i < Length(rawlist) then |
| 531 |
|
Result := rawlist[i] |
| 532 |
|
else begin |
| 533 |
+ |
Result.Name := ''; |
| 534 |
|
Result.SrcID := -1; |
| 535 |
|
Result.SrcOffset := -1; |
| 536 |
|
Result.RawAddr := -1; |
| 537 |
|
Result.RawSize := -1; |
| 538 |
+ |
Result.RawType := ''; |
| 539 |
|
end; |
| 540 |
|
end; |
| 541 |
|
end; |
| 542 |
|
|
| 543 |
|
|
| 544 |
+ |
function TAccess_OUP_ADB.GetRawsForType(RawType: String): TRawDataList; |
| 545 |
+ |
var |
| 546 |
+ |
i: Integer; |
| 547 |
+ |
begin |
| 548 |
+ |
SetLength(Result, 0); |
| 549 |
+ |
FQuery.SQL.Text := 'SELECT [src_id],[src_link_offset],[name],[size],[sep] FROM rawmap ' + |
| 550 |
+ |
'WHERE [type]="' + RawType + '" and [size]>0 ORDER BY src_id ASC, src_link_offset ASC;'; |
| 551 |
+ |
FQuery.Open; |
| 552 |
+ |
if FQuery.RecordCount > 0 then |
| 553 |
+ |
begin |
| 554 |
+ |
FQuery.First; |
| 555 |
+ |
SetLength(Result, FQuery.RecordCount); |
| 556 |
+ |
i := 0; |
| 557 |
+ |
repeat |
| 558 |
+ |
Result[i].Name := FQuery.FieldByName('name').AsString; |
| 559 |
+ |
Result[i].SrcID := FQuery.FieldByName('src_id').AsInteger; |
| 560 |
+ |
Result[i].SrcOffset := FQuery.FieldByName('src_link_offset').AsInteger; |
| 561 |
+ |
Result[i].RawAddr := 0; |
| 562 |
+ |
Result[i].RawSize := FQuery.FieldByName('size').AsInteger; |
| 563 |
+ |
Result[i].LocSep := FQuery.FieldByName('sep').AsBoolean; |
| 564 |
+ |
Result[i].RawType := RawType; |
| 565 |
+ |
Inc(i); |
| 566 |
+ |
FQuery.Next; |
| 567 |
+ |
until FQuery.EOF; |
| 568 |
+ |
end; |
| 569 |
+ |
FQuery.Close; |
| 570 |
+ |
end; |
| 571 |
+ |
|
| 572 |
+ |
|
| 573 |
+ |
|
| 574 |
|
|
| 575 |
|
procedure TAccess_OUP_ADB.LoadRawFile(FileID, DatOffset: Integer; var Target: TStream); |
| 576 |
|
var |