ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/oup/current/DataAccess/Access_OUP_ADB.pas
(Generate patch)

Comparing oup/current/DataAccess/Access_OUP_ADB.pas (file contents):
Revision 113 by alloc, Sun Feb 25 17:20:22 2007 UTC vs.
Revision 321 by alloc, Wed May 6 13:47:23 2009 UTC

# Line 18 | Line 18 | type
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;
# Line 32 | Line 31 | type
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;
# Line 46 | Line 47 | type
47   implementation
48  
49   uses
50 <  SysUtils, Data, Functions, ABSDecUtil, DB;
50 >  SysUtils, Data, Functions, ABSDecUtil, DB, DatLinks, StrUtils;
51  
52  
53   (*
# Line 66 | Line 67 | begin
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;
# Line 86 | Line 91 | begin
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
# Line 108 | Line 113 | begin
113    FChangeRights := [CR_EditDat, CR_EditRaw, CR_ResizeDat, CR_ResizeRaw];
114  
115    UpdateListCache;
116 +
117 +  inherited;
118   end;
119  
120  
# Line 192 | Line 199 | begin
199    FQuery.Close;
200   end;
201  
195 function TAccess_OUP_ADB.GetLinksFromFile(FileID: Integer): TLinks;
196 var
197  i: Integer;
198 begin
199  SetLength(Result.ByName, 0);
200  FQuery.SQL.Text := 'SELECT src_link_offset, target_id FROM linkmap WHERE src_id = ' + IntToStr(FileID) + ' ORDER BY target_id ASC;';
201  FQuery.Open;
202  SetLength(Result.ByID, FQuery.RecordCount);
203  if FQuery.RecordCount > 0 then
204  begin
205    i := 0;
206    repeat
207      Result.ByID[i].SrcOffset := FQuery.FieldByName('src_link_offset').AsInteger;
208      Result.ByID[i].Destination := FQuery.FieldByName('target_id').AsInteger;
209      Inc(i);
210      FQuery.Next;
211    until FQuery.EOF;
212  end;
213  FQuery.Close;
214 end;
215
202  
203  
204   function TAccess_OUP_ADB.GetFileInfo(fileid: Integer): TFileInfo;
# Line 230 | Line 216 | end;
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;
# Line 270 | Line 264 | var
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
# Line 287 | Line 286 | begin
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 +  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
# Line 444 | Line 445 | begin
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
# Line 458 | Line 501 | begin
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;
# Line 485 | Line 530 | begin
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

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)